Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/quickengine.cpp
Show All 15 Lines | |||||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | 17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "quickengine.h" | 22 | #include "quickengine.h" | ||
23 | 23 | | |||
24 | #include <kauthorized.h> | ||||
25 | | ||||
26 | #include "categoriesmodel.h" | ||||
27 | #include "quickquestionlistener.h" | ||||
28 | | ||||
24 | #include "engine.h" | 29 | #include "engine.h" | ||
25 | 30 | | |||
26 | class Engine::Private | 31 | class Engine::Private | ||
27 | { | 32 | { | ||
28 | public: | 33 | public: | ||
29 | Private() | 34 | Private() | ||
30 | : engine(nullptr) | 35 | : engine(nullptr) | ||
36 | , categoriesModel(nullptr) | ||||
31 | {} | 37 | {} | ||
32 | KNSCore::Engine* engine; | 38 | KNSCore::Engine* engine; | ||
39 | CategoriesModel* categoriesModel; | ||||
33 | QString configFile; | 40 | QString configFile; | ||
41 | KNSCore::EntryInternal::List changedEntries; | ||||
34 | }; | 42 | }; | ||
35 | 43 | | |||
36 | Engine::Engine(QObject* parent) | 44 | Engine::Engine(QObject* parent) | ||
37 | : QObject(parent) | 45 | : QObject(parent) | ||
38 | , d(new Private) | 46 | , d(new Private) | ||
39 | { | 47 | { | ||
40 | } | 48 | } | ||
41 | 49 | | |||
42 | Engine::~Engine() | 50 | Engine::~Engine() | ||
43 | { | 51 | { | ||
44 | delete d; | 52 | delete d; | ||
45 | } | 53 | } | ||
46 | 54 | | |||
55 | bool Engine::allowedByKiosk() const | ||||
56 | { | ||||
57 | return KAuthorized::authorize(QStringLiteral("ghns")); | ||||
58 | } | ||||
59 | | ||||
47 | QString Engine::configFile() const | 60 | QString Engine::configFile() const | ||
48 | { | 61 | { | ||
49 | return d->configFile; | 62 | return d->configFile; | ||
50 | } | 63 | } | ||
51 | 64 | | |||
52 | void Engine::setConfigFile(const QString& newFile) | 65 | void Engine::setConfigFile(const QString& newFile) | ||
53 | { | 66 | { | ||
54 | d->configFile = newFile; | 67 | d->configFile = newFile; | ||
55 | emit configFileChanged(); | 68 | emit configFileChanged(); | ||
56 | 69 | | |||
70 | if (allowedByKiosk()) { | ||||
57 | if(!d->engine) { | 71 | if (!d->engine) { | ||
58 | d->engine = new KNSCore::Engine(this); | 72 | d->engine = new KNSCore::Engine(this); | ||
59 | connect(d->engine, &KNSCore::Engine::signalMessage, this, &Engine::message); | 73 | connect(d->engine, &KNSCore::Engine::signalMessage, this, &Engine::message); | ||
60 | connect(d->engine, &KNSCore::Engine::signalIdle, this, &Engine::idleMessage); | 74 | connect(d->engine, &KNSCore::Engine::signalIdle, this, &Engine::idleMessage); | ||
61 | connect(d->engine, &KNSCore::Engine::signalBusy, this, &Engine::busyMessage); | 75 | connect(d->engine, &KNSCore::Engine::signalBusy, this, &Engine::busyMessage); | ||
62 | connect(d->engine, &KNSCore::Engine::signalError, this, &Engine::errorMessage); | 76 | connect(d->engine, &KNSCore::Engine::signalError, this, &Engine::errorMessage); | ||
77 | connect(d->engine, &KNSCore::Engine::signalEntryChanged, this, [this](const KNSCore::EntryInternal& entry){ | ||||
78 | d->changedEntries << entry; | ||||
79 | emit changedEntriesChanged(); | ||||
80 | }); | ||||
63 | emit engineChanged(); | 81 | emit engineChanged(); | ||
82 | KNewStuffQuick::QuickQuestionListener::instance(); | ||||
83 | d->categoriesModel = new CategoriesModel(this); | ||||
84 | emit categoriesChanged(); | ||||
64 | } | 85 | } | ||
65 | d->engine->init(d->configFile); | 86 | d->engine->init(d->configFile); | ||
87 | d->engine->setSortMode(KNSCore::Provider::Downloads); | ||||
88 | emit engineInitialized(); | ||||
89 | } | ||||
66 | } | 90 | } | ||
67 | 91 | | |||
68 | QObject * Engine::engine() const | 92 | QObject * Engine::engine() const | ||
69 | { | 93 | { | ||
70 | return d->engine; | 94 | return d->engine; | ||
71 | } | 95 | } | ||
96 | | ||||
97 | bool Engine::hasAdoptionCommand() const | ||||
98 | { | ||||
99 | if (d->engine) { | ||||
100 | return d->engine->hasAdoptionCommand(); | ||||
101 | } | ||||
102 | return false; | ||||
103 | } | ||||
104 | | ||||
105 | QString Engine::name() const | ||||
106 | { | ||||
107 | if (d->engine) { | ||||
108 | return d->engine->name(); | ||||
109 | } | ||||
110 | return QString{}; | ||||
111 | } | ||||
112 | | ||||
113 | QObject* Engine::categories() const | ||||
114 | { | ||||
115 | return d->categoriesModel; | ||||
116 | } | ||||
117 | | ||||
118 | QStringList Engine::categoriesFilter() const | ||||
119 | { | ||||
120 | if (d->engine) { | ||||
121 | return d->engine->categoriesFilter(); | ||||
122 | } | ||||
123 | return QStringList{}; | ||||
124 | } | ||||
125 | | ||||
126 | void Engine::setCategoriesFilter(const QStringList& newCategoriesFilter) | ||||
127 | { | ||||
128 | if (d->engine) { | ||||
129 | // This ensures that if we somehow end up with any empty entries (such as the default | ||||
130 | // option in the categories dropdowns), our list will remain empty. | ||||
131 | QStringList filter{newCategoriesFilter}; | ||||
132 | filter.removeAll({}); | ||||
133 | d->engine->setCategoriesFilter(filter); | ||||
134 | emit categoriesFilterChanged(); | ||||
135 | } | ||||
136 | } | ||||
137 | | ||||
138 | void Engine::resetCategoriesFilter() | ||||
139 | { | ||||
140 | if (d->engine) { | ||||
141 | d->engine->setCategoriesFilter(d->engine->categories()); | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | int Engine::filter() const | ||||
146 | { | ||||
147 | if (d->engine) { | ||||
148 | d->engine->filter(); | ||||
149 | } | ||||
150 | return 0; | ||||
151 | } | ||||
152 | | ||||
153 | void Engine::setFilter(int newFilter) | ||||
154 | { | ||||
155 | if (d->engine) { | ||||
156 | d->engine->setFilter(static_cast<KNSCore::Provider::Filter>(newFilter)); | ||||
157 | emit filterChanged(); | ||||
158 | } | ||||
159 | } | ||||
160 | | ||||
161 | int Engine::sortOrder() const | ||||
162 | { | ||||
163 | if (d->engine) { | ||||
164 | return d->engine->sortMode(); | ||||
165 | } | ||||
166 | return 0; | ||||
167 | } | ||||
168 | | ||||
169 | void Engine::setSortOrder(int newSortOrder) | ||||
170 | { | ||||
171 | if (d->engine) { | ||||
172 | d->engine->setSortMode(static_cast<KNSCore::Provider::SortMode>(newSortOrder)); | ||||
173 | emit sortOrderChanged(); | ||||
174 | } | ||||
175 | } | ||||
176 | | ||||
177 | QString Engine::searchTerm() const | ||||
178 | { | ||||
179 | if (d->engine) { | ||||
180 | return d->engine->searchTerm(); | ||||
181 | } | ||||
182 | return QString{}; | ||||
183 | } | ||||
184 | | ||||
185 | void Engine::setSearchTerm(const QString& newSearchTerm) | ||||
186 | { | ||||
187 | if (d->engine) { | ||||
188 | d->engine->setSearchTerm(newSearchTerm); | ||||
189 | emit searchTermChanged(); | ||||
190 | } | ||||
191 | } | ||||
192 | | ||||
193 | void Engine::resetSearchTerm() | ||||
194 | { | ||||
195 | setSearchTerm(QString{}); | ||||
196 | } | ||||
197 | | ||||
198 | KNSCore::EntryInternal::List Engine::changedEntries() const | ||||
199 | { | ||||
200 | return d->changedEntries; | ||||
201 | } | ||||
202 | | ||||
203 | void Engine::resetChangedEntries() | ||||
204 | { | ||||
205 | d->changedEntries.clear(); | ||||
206 | emit changedEntriesChanged(); | ||||
207 | } |