Make sure we don't ignore hidden files.
[vng.git] / src / GenericCursor.cpp
blob50fb306578640bde31574f328dfa7dbb94c5b16b
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "GenericCursor.h"
21 #include <QDebug>
23 GenericCursor::GenericCursor(AcceptanceMode mode)
24 : InterviewCursor(),
25 m_curentIndex(0),
26 m_mode(mode),
27 m_oneAccepted(false)
29 switch (m_mode) {
30 case ExitOnAccept:
31 m_allowedOptions = QLatin1String("ynqjk");
32 break;
33 case ExitWhenDone:
34 m_allowedOptions = QLatin1String("ynqadjk");
35 break;
39 GenericCursor::~GenericCursor()
41 qDeleteAll(m_items);
44 int GenericCursor::forward(Scope scope, bool skipAnswered)
46 Q_UNUSED(scope);
47 do {
48 if (m_items.count() <= m_curentIndex + 1) {
49 if (m_mode == ExitWhenDone)
50 ++m_curentIndex;
51 return m_items.count();
53 ++m_curentIndex;
54 if (m_items[m_curentIndex]->m_acceptance == Vng::Undecided)
55 break;
56 } while (skipAnswered);
57 return m_curentIndex+1;
60 int GenericCursor::back(Scope scope)
62 Q_UNUSED(scope);
63 while (m_curentIndex > 0) {
64 m_curentIndex--;
65 if (m_items[m_curentIndex]->m_acceptance == Vng::Undecided)
66 break;
68 return m_curentIndex+1;
71 void GenericCursor::setResponse(bool response, Scope scope)
73 Q_UNUSED(scope);
74 if (m_curentIndex >= 0 && m_curentIndex < m_items.count()) {
75 m_items[m_curentIndex]->m_acceptance = response ? Vng::Accepted : Vng::Rejected;
76 if (response)
77 m_oneAccepted = true;
81 void GenericCursor::setAllowedOptions(QString &options)
83 m_allowedOptions = options;
86 QString GenericCursor::allowedOptions() const
88 return m_allowedOptions;
91 int GenericCursor::count()
93 return m_items.count();
96 void GenericCursor::forceCount()
100 QString GenericCursor::currentText() const
102 return m_items[m_curentIndex]->text();
105 void GenericCursor::setHelpMessage(const QString &message)
107 m_helpMessage = message;
110 QString GenericCursor::helpMessage() const
112 return m_helpMessage;
115 bool GenericCursor::isValid() const
117 if (m_mode == ExitOnAccept)
118 return !m_oneAccepted;
119 return m_curentIndex >= 0 && m_curentIndex < m_items.count();
122 int GenericCursor::addDataItem(const QString &text)
124 Item *item = new Item(text);
125 m_items << item;
126 return m_items.count();
129 QList<int> GenericCursor::selectedItems() const
131 int index = 0;
132 QList<int> answer;
133 foreach (Item *item, m_items) {
134 if (item->m_acceptance == Vng::Accepted)
135 answer << index;
136 ++index;
138 return answer;
142 GenericCursor::Item::Item(const QString &text)
143 : m_acceptance(Vng::Undecided),
144 m_text(text)
148 QString GenericCursor::Item::text() const
150 return m_text;