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> | ||||
25 | #include <KLocalizedString> | ||||
26 | | ||||
27 | #include "categoriesmodel.h" | ||||
28 | #include "quickquestionlistener.h" | ||||
29 | | ||||
24 | #include "engine.h" | 30 | #include "engine.h" | ||
25 | 31 | | |||
26 | class Engine::Private | 32 | class Engine::Private | ||
27 | { | 33 | { | ||
28 | public: | 34 | public: | ||
29 | Private() | 35 | Private() | ||
30 | : engine(nullptr) | 36 | : engine(nullptr) | ||
37 | , categoriesModel(nullptr) | ||||
31 | {} | 38 | {} | ||
32 | KNSCore::Engine* engine; | 39 | KNSCore::Engine *engine; | ||
40 | CategoriesModel *categoriesModel; | ||||
33 | QString configFile; | 41 | QString configFile; | ||
42 | KNSCore::EntryInternal::List changedEntries; | ||||
34 | }; | 43 | }; | ||
35 | 44 | | |||
36 | Engine::Engine(QObject* parent) | 45 | Engine::Engine(QObject *parent) | ||
37 | : QObject(parent) | 46 | : QObject(parent) | ||
38 | , d(new Private) | 47 | , d(new Private) | ||
39 | { | 48 | { | ||
40 | } | 49 | } | ||
41 | 50 | | |||
42 | Engine::~Engine() | 51 | Engine::~Engine() | ||
43 | { | 52 | { | ||
44 | delete d; | 53 | delete d; | ||
45 | } | 54 | } | ||
46 | 55 | | |||
56 | bool Engine::allowedByKiosk() const | ||||
57 | { | ||||
58 | return KAuthorized::authorize(QStringLiteral("ghns")); | ||||
59 | } | ||||
60 | | ||||
47 | QString Engine::configFile() const | 61 | QString Engine::configFile() const | ||
48 | { | 62 | { | ||
49 | return d->configFile; | 63 | return d->configFile; | ||
50 | } | 64 | } | ||
51 | 65 | | |||
52 | void Engine::setConfigFile(const QString& newFile) | 66 | void Engine::setConfigFile(const QString &newFile) | ||
53 | { | 67 | { | ||
68 | if (d->configFile != newFile) { | ||||
54 | d->configFile = newFile; | 69 | d->configFile = newFile; | ||
55 | emit configFileChanged(); | 70 | emit configFileChanged(); | ||
56 | 71 | | |||
72 | if (allowedByKiosk()) { | ||||
57 | if(!d->engine) { | 73 | if (!d->engine) { | ||
58 | d->engine = new KNSCore::Engine(this); | 74 | d->engine = new KNSCore::Engine(this); | ||
59 | connect(d->engine, &KNSCore::Engine::signalMessage, this, &Engine::message); | 75 | connect(d->engine, &KNSCore::Engine::signalMessage, this, &Engine::message); | ||
60 | connect(d->engine, &KNSCore::Engine::signalIdle, this, &Engine::idleMessage); | 76 | connect(d->engine, &KNSCore::Engine::signalIdle, this, &Engine::idleMessage); | ||
61 | connect(d->engine, &KNSCore::Engine::signalBusy, this, &Engine::busyMessage); | 77 | connect(d->engine, &KNSCore::Engine::signalBusy, this, &Engine::busyMessage); | ||
62 | connect(d->engine, &KNSCore::Engine::signalError, this, &Engine::errorMessage); | 78 | connect(d->engine, &KNSCore::Engine::signalError, this, &Engine::errorMessage); | ||
79 | connect(d->engine, &KNSCore::Engine::signalErrorCode, this, [=](const KNSCore::ErrorCode &/*errorCode*/, const QString &message, const QVariant &/*metadata*/) { | ||||
80 | emit errorMessage(message); | ||||
81 | }); | ||||
82 | connect(d->engine, &KNSCore::Engine::signalEntryChanged, this, [this](const KNSCore::EntryInternal &entry){ | ||||
83 | d->changedEntries << entry; | ||||
84 | emit changedEntriesChanged(); | ||||
85 | }); | ||||
63 | emit engineChanged(); | 86 | emit engineChanged(); | ||
87 | KNewStuffQuick::QuickQuestionListener::instance(); | ||||
88 | d->categoriesModel = new CategoriesModel(this); | ||||
89 | emit categoriesChanged(); | ||||
64 | } | 90 | } | ||
65 | d->engine->init(d->configFile); | 91 | d->engine->init(d->configFile); | ||
92 | d->engine->setSortMode(KNSCore::Provider::Downloads); | ||||
93 | emit engineInitialized(); | ||||
94 | } else { | ||||
95 | // This is not an error message in the proper sense, and the message is not intended to look like an error (as there is really | ||||
96 | // nothing the user can do to fix it, and we just tell them so they're not wondering what's wrong) | ||||
97 | emit message(i18nc("An informational message which is shown to inform the user they are not authorized to use GetHotNewStuff functionality", "You are not authorized to Get Hot New Stuff. If you think this is in error, please contact the person in charge of your permissions.")); | ||||
98 | } | ||||
99 | } | ||||
66 | } | 100 | } | ||
67 | 101 | | |||
68 | QObject * Engine::engine() const | 102 | QObject *Engine::engine() const | ||
69 | { | 103 | { | ||
70 | return d->engine; | 104 | return d->engine; | ||
71 | } | 105 | } | ||
106 | | ||||
107 | bool Engine::hasAdoptionCommand() const | ||||
108 | { | ||||
109 | if (d->engine) { | ||||
110 | return d->engine->hasAdoptionCommand(); | ||||
111 | } | ||||
112 | return false; | ||||
113 | } | ||||
114 | | ||||
115 | QString Engine::name() const | ||||
116 | { | ||||
117 | if (d->engine) { | ||||
118 | return d->engine->name(); | ||||
119 | } | ||||
120 | return QString{}; | ||||
121 | } | ||||
122 | | ||||
123 | QObject *Engine::categories() const | ||||
124 | { | ||||
125 | return d->categoriesModel; | ||||
126 | } | ||||
127 | | ||||
128 | QStringList Engine::categoriesFilter() const | ||||
129 | { | ||||
130 | if (d->engine) { | ||||
131 | return d->engine->categoriesFilter(); | ||||
132 | } | ||||
133 | return QStringList{}; | ||||
134 | } | ||||
135 | | ||||
136 | void Engine::setCategoriesFilter(const QStringList &newCategoriesFilter) | ||||
137 | { | ||||
138 | if (d->engine) { | ||||
139 | // This ensures that if we somehow end up with any empty entries (such as the default | ||||
140 | // option in the categories dropdowns), our list will remain empty. | ||||
141 | QStringList filter{newCategoriesFilter}; | ||||
142 | filter.removeAll({}); | ||||
143 | if (d->engine->categoriesFilter() != filter) { | ||||
144 | d->engine->setCategoriesFilter(filter); | ||||
145 | emit categoriesFilterChanged(); | ||||
146 | } | ||||
147 | } | ||||
148 | } | ||||
149 | | ||||
150 | void Engine::resetCategoriesFilter() | ||||
151 | { | ||||
152 | if (d->engine) { | ||||
153 | d->engine->setCategoriesFilter(d->engine->categories()); | ||||
154 | } | ||||
155 | } | ||||
156 | | ||||
157 | int Engine::filter() const | ||||
158 | { | ||||
159 | if (d->engine) { | ||||
160 | d->engine->filter(); | ||||
161 | } | ||||
162 | return 0; | ||||
163 | } | ||||
164 | | ||||
165 | void Engine::setFilter(int newFilter) | ||||
166 | { | ||||
167 | if (d->engine && d->engine->filter() != newFilter) { | ||||
168 | d->engine->setFilter(static_cast<KNSCore::Provider::Filter>(newFilter)); | ||||
169 | emit filterChanged(); | ||||
170 | } | ||||
171 | } | ||||
172 | | ||||
173 | int Engine::sortOrder() const | ||||
174 | { | ||||
175 | if (d->engine) { | ||||
176 | return d->engine->sortMode(); | ||||
177 | } | ||||
178 | return 0; | ||||
179 | } | ||||
180 | | ||||
181 | void Engine::setSortOrder(int newSortOrder) | ||||
182 | { | ||||
183 | if (d->engine && d->engine->sortMode() != newSortOrder) { | ||||
184 | d->engine->setSortMode(static_cast<KNSCore::Provider::SortMode>(newSortOrder)); | ||||
185 | emit sortOrderChanged(); | ||||
186 | } | ||||
187 | } | ||||
188 | | ||||
189 | QString Engine::searchTerm() const | ||||
190 | { | ||||
191 | if (d->engine) { | ||||
192 | return d->engine->searchTerm(); | ||||
193 | } | ||||
194 | return QString{}; | ||||
195 | } | ||||
196 | | ||||
197 | void Engine::setSearchTerm(const QString &newSearchTerm) | ||||
198 | { | ||||
199 | if (d->engine && d->engine->searchTerm() != newSearchTerm) { | ||||
200 | d->engine->setSearchTerm(newSearchTerm); | ||||
201 | emit searchTermChanged(); | ||||
202 | } | ||||
203 | } | ||||
204 | | ||||
205 | void Engine::resetSearchTerm() | ||||
206 | { | ||||
207 | setSearchTerm(QString{}); | ||||
208 | } | ||||
209 | | ||||
210 | KNSCore::EntryInternal::List Engine::changedEntries() const | ||||
211 | { | ||||
212 | return d->changedEntries; | ||||
213 | } | ||||
214 | | ||||
215 | void Engine::resetChangedEntries() | ||||
216 | { | ||||
217 | d->changedEntries.clear(); | ||||
218 | emit changedEntriesChanged(); | ||||
219 | } |