KNewStuff

enginebase.h
1/*
2 SPDX-FileCopyrightText: 2007 Josef Spillner <spillner@kde.org>
3 SPDX-FileCopyrightText: 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
4 SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#ifndef KNEWSTUFF3_ENGINEBASE_H
10#define KNEWSTUFF3_ENGINEBASE_H
11
12#include <QHash>
13#include <QObject>
14#include <QSharedPointer>
15#include <QString>
16
17#include "entry.h"
18#include "errorcode.h"
19#include "provider.h"
20
21#include "knewstuffcore_export.h"
22
23#include <memory>
24
25class KJob;
26class EnginePrivate;
27class QDomDocument;
28
29namespace Attica
30{
31class Provider;
32}
33
34namespace KNSCore
35{
36class Cache;
37class CommentsModel;
38class ResultsStream;
40class Installation;
41
42/**
43 * KNewStuff engine.
44 * An engine keeps track of data which is available locally and remote
45 * and offers high-level synchronization calls as well as upload and download
46 * primitives using an underlying GHNS protocol.
47 *
48 * This is a base class for different engine implementations
49 */
51{
52 Q_OBJECT
53
54 /**
55 * Text that should be displayed for the adoption button, this defaults to "Use"
56 * @since 5.77
57 */
58 Q_PROPERTY(QString useLabel READ useLabel NOTIFY useLabelChanged)
59
60 /**
61 * Whether or not the configuration says that the providers are expected to support uploading.
62 * As it stands, this is used to determine whether or not to show the Upload... action where
63 * that is displayed (primarily NewStuff.Page).
64 * @since 5.85
65 */
66 Q_PROPERTY(bool uploadEnabled READ uploadEnabled NOTIFY uploadEnabledChanged)
67
68 /**
69 * @since 5.85
70 */
71 Q_PROPERTY(QStringList providerIDs READ providerIDs NOTIFY providersChanged)
72
73public:
74 EngineBase(QObject *parent = nullptr);
75 ~EngineBase();
76
77 /**
78 * List of all available config files. This list will contain no duplicated filenames.
79 * The returned file paths are absolute.
80 * @since 5.83
81 */
82 static QStringList availableConfigFiles();
83
84 /**
85 * Initializes the engine. This step is application-specific and relies
86 * on an external configuration file, which determines all the details
87 * about the initialization.
88 *
89 * @param configfile KNewStuff2 configuration file (*.knsrc)
90 * @return \b true if any valid configuration was found, \b false otherwise
91 * @see KNS3::DownloadDialog
92 */
93 virtual bool init(const QString &configfile);
94
95 /**
96 * The name as defined by the knsrc file
97 * @return The name associated with the engine's configuration file
98 * @since 5.63
99 */
100 QString name() const;
101
102 /**
103 * Text that should be displayed for the adoption button, this defaults to i18n("Use")
104 * @since 5.77
105 */
106 QString useLabel() const;
107
108 /**
109 * Signal gets emitted when the useLabel property changes
110 * @since 5.77
111 */
112 Q_SIGNAL void useLabelChanged();
113
114 /**
115 * Whether or not the configuration says that the providers are expected to support uploading.
116 * @return True if the providers are expected to support uploading
117 * @since 5.85
118 */
119 bool uploadEnabled() const;
120
121 /**
122 * Fired when the uploadEnabled property changes
123 * @since 5.85
124 */
125 Q_SIGNAL void uploadEnabledChanged();
126
127 /**
128 * The list of the server-side names of the categories handled by this
129 * engine instance. This corresponds directly to the list of categories
130 * in your knsrc file. This is not supposed to be used as user-facing
131 * strings - @see categoriesMetadata() for that.
132 *
133 * @return The categories which this instance of Engine handles
134 */
135 QStringList categories() const;
136
137 /**
138 * Get the entries cache for this engine (note that it may be null if the engine is
139 * not yet initialized).
140 * @return The cache for this engine (or null if the engine is not initialized)
141 * @since 5.74
142 */
143 QSharedPointer<Cache> cache() const;
144
145 /**
146 * The list of metadata for the categories handled by this engine instance.
147 * If you wish to show the categories to the user, this is the data to use.
148 * The category name is the string used to set categories for the filter,
149 * and also what is returned by both categories() and categoriesFilter().
150 * The human-readable name is displayName, and the only thing which should
151 * be shown to the user.
152 *
153 * @return The metadata for all categories handled by this engine
154 */
155 QList<Provider::CategoryMetadata> categoriesMetadata();
156
157 QList<Provider::SearchPreset> searchPresets();
158
159 /**
160 * @returns the list of attica (OCS) providers this engine is connected to
161 * @since 5.92
162 */
163 QList<Attica::Provider *> atticaProviders() const;
164
165 /**
166 * Set a filter for results, which filters out all entries which do not match
167 * the filter, as applied to the tags for the entry. This filters only on the
168 * tags specified for the entry itself. To filter the downloadlinks, use
169 * setDownloadTagFilter(QStringList).
170 *
171 * @note The default filter if one is not set from your knsrc file will filter
172 * out entries marked as ghns_excluded=1. To retain this when setting a custom
173 * filter, add "ghns_excluded!=1" as one of the filters.
174 *
175 * @note Some tags provided by OCS do not supply a value (and are simply passed
176 * as a key). These will be interpreted as having the value 1 for filtering
177 * purposes. An example of this might be ghns_excluded, which in reality will
178 * generally be passed through ocs as "ghns_excluded" rather than "ghns_excluded=1"
179 *
180 * @note As tags are metadata, they are provided in the form of adjectives. They
181 * are never supplied as action verbs or instructions (as an example, a good tag
182 * to suggest that for example a wallpaper is painted would be "painted" as opposed
183 * to "paint", and another example might be that an item should be "excluded" as
184 * opposed to "exclude").
185 *
186 * == Examples of use ==
187 * Value for tag "tagname" must be exactly "tagdata":
188 * tagname==tagdata
189 *
190 * Value for tag "tagname" must be different from "tagdata":
191 * tagname!=tagdata
192 *
193 * == KNSRC entry ==
194 * A tag filter line in a .knsrc file, which is a comma separated list of
195 * tag/value pairs, might look like:
196 *
197 * TagFilter=ghns_excluded!=1,data##mimetype==application/cbr+zip,data##mimetype==application/cbr+rar
198 * which would honour the exclusion and filter out anything that does not
199 * include a comic book archive in either zip or rar format in one or more
200 * of the download items.
201 * Notice in particular that there are two data##mimetype entries. Use this
202 * for when a tag may have multiple values.
203 *
204 * TagFilter=application##architecture==x86_64
205 * which would not honour the exclusion, and would filter out all entries
206 * which do not mark themselves as having a 64bit application binary in at
207 * least one download item.
208 *
209 * The value does not current support wildcards. The list should be considered
210 * a binary AND operation (that is, all filter entries must match for the data
211 * entry to be included in the return data)
212 *
213 * @param filter The filter in the form of a list of strings
214 * @see setDownloadTagFilter(QStringList)
215 * @since 5.51
216 */
217 void setTagFilter(const QStringList &filter);
218 /**
219 * Gets the current tag filter list
220 * @see setTagFilter(QStringList)
221 * @since 5.51
222 */
223 QStringList tagFilter() const;
224 /**
225 * Add a single filter entry to the entry tag filter. The filter should be in
226 * the same form as the filter lines in the list used by setTagFilter(QStringList)
227 * @param filter The filter in the form of a string
228 * @see setTagFilter(QStringList)
229 * @since 5.51
230 */
231 void addTagFilter(const QString &filter);
232 /**
233 * Sets a filter to be applied to the downloads for an entry. The logic is the
234 * same as used in setTagFilter(QStringList), but vitally, only one downloadlink
235 * is required to match the filter for the list to be valid. If you do not wish
236 * to show the others in your client, you must hide them yourself.
237 *
238 * For an entry to be accepted when a download tag filter is set, it must also
239 * be accepted by the entry filter (so, for example, while a list of downloads
240 * might be accepted, if the entry has ghns_excluded set, and the default entry
241 * filter is set, the entry will still be filtered out).
242 *
243 * In your knsrc file, set DownloadTagFilter to the filter you wish to apply,
244 * using the same logic as described for the entry tagfilter.
245 *
246 * @param filter The filter in the form of a list of strings
247 * @see setTagFilter(QStringList)
248 * @since 5.51
249 */
250 void setDownloadTagFilter(const QStringList &filter);
251 /**
252 * Gets the current downloadlink tag filter list
253 * @see setDownloadTagFilter(QStringList)
254 * @since 5.51
255 */
256 QStringList downloadTagFilter() const;
257 /**
258 * Add a single filter entry to the download tag filter. The filter should be in
259 * the same form as the filter lines in the list used by setDownloadsTagFilter(QStringList)
260 * @param filter The filter in the form of a string
261 * @see setTagFilter(QStringList)
262 * @see setDownloadTagFilter(QStringList)
263 * @since 5.51
264 */
265 void addDownloadTagFilter(const QString &filter);
266
267 /**
268 * Whether or not a user is able to vote on the passed entry.
269 *
270 * @param entry The entry to check votability on
271 * @return True if the user is able to vote on the entry
272 */
273 bool userCanVote(const Entry &entry);
274 /**
275 * Cast a vote on the passed entry.
276 *
277 * @param entry The entry to vote on
278 * @param rating A number from 0 to 100, 50 being neutral, 0 being most negative and 100 being most positive.
279 */
280 void vote(const Entry &entry, uint rating);
281
282 /**
283 * Whether or not the user is allowed to become a fan of
284 * a particular entry.
285 * Not all providers (and consequently entries) support the fan functionality
286 * and you can use this function to determine this ability.
287 * @param entry The entry the user might wish to be a fan of
288 * @return Whether or not it is possible for the user to become a fan of that entry
289 */
290 bool userCanBecomeFan(const Entry &entry);
291 /**
292 * This will mark the user who is currently authenticated as a fan
293 * of the entry passed to the function.
294 * @param entry The entry the user wants to be a fan of
295 */
296 void becomeFan(const Entry &entry);
297 // FIXME There is currently no exposed API to remove the fan status
298
299 /**
300 * The Provider instance with the passed ID
301 *
302 * @param providerId The ID of the Provider to fetch
303 * @return The Provider with the passed ID, or null if non such Provider exists
304 * @since 5.63
305 */
306 QSharedPointer<Provider> provider(const QString &providerId) const;
307
308 /**
309 * Return the first provider in the providers list (usually the default provider)
310 * @return The first Provider (or null if the engine is not initialized)
311 * @since 5.63
312 */
313 QSharedPointer<Provider> defaultProvider() const;
314
315 /**
316 * The IDs of all providers known by this engine. Use this in combination with
317 * provider(const QString&) to iterate over all providers.
318 * @return The string IDs of all known providers
319 * @since 5.85
320 */
321 QStringList providerIDs() const;
322
323 /**
324 * Whether or not an adoption command exists for this engine
325 *
326 * @see adoptionCommand(KNSCore::Entry)
327 * @return True if an adoption command exists
328 */
329 bool hasAdoptionCommand() const;
330
331 /**
332 * Returns a stream object that will fulfill the @p request.
333 *
334 * @since 6.0
335 */
336 ResultsStream *search(const KNSCore::Provider::SearchRequest &request);
337
338Q_SIGNALS:
339 /**
340 * Indicates a message to be added to the ui's log, or sent to a messagebox
341 */
342 void signalMessage(const QString &message);
343
344 void signalProvidersLoaded();
345
346 /**
347 * Fires in the case of any critical or serious errors, such as network or API problems.
348 * @param errorCode Represents the specific type of error which has occurred
349 * @param message A human-readable message which can be shown to the end user
350 * @param metadata Any additional data which might be hepful to further work out the details of the error (see KNSCore::Entry::ErrorCode for the
351 * metadata details)
352 * @see KNSCore::Entry::ErrorCode
353 * @since 5.53
354 */
355 void signalErrorCode(KNSCore::ErrorCode::ErrorCode errorCode, const QString &message, const QVariant &metadata);
356
357 void signalCategoriesMetadataLoded(const QList<Provider::CategoryMetadata> &categories);
358
359 /**
360 * Fires when the engine has loaded search presets. These represent interesting
361 * searches for the user, such as recommendations.
362 * @since 5.83
363 */
364 void signalSearchPresetsLoaded(const QList<Provider::SearchPreset> &presets);
365
366 /**
367 * Fired whenever the list of providers changes
368 * @since 5.85
369 */
370 void providersChanged();
371
372 void loadingProvider();
373
374private:
375 // the .knsrc file was loaded
376 void slotProviderFileLoaded(const QDomDocument &doc);
377 // instead of getting providers from knsrc, use what was configured in ocs systemsettings
378 void atticaProviderLoaded(const Attica::Provider &provider);
379 // called when a provider is ready to work
380 void providerInitialized(KNSCore::Provider *);
381
382 // loading the .knsrc file failed
383 void slotProvidersFailed();
384
385 /**
386 * load providers from the providersurl in the knsrc file
387 * creates providers based on their type and adds them to the list of providers
388 */
389 void loadProviders();
390
392 /**
393 Add a provider and connect it to the right slots
394 */
395 virtual void addProvider(QSharedPointer<KNSCore::Provider> provider);
396 virtual void updateStatus();
397
398 friend class ResultsStream;
399 friend class Transaction;
400 Installation *installation() const; // Needed for quick engine
401 QList<QSharedPointer<Provider>> providers() const;
403};
404
405}
406
407#endif
KNewStuff engine.
Definition enginebase.h:51
KNewStuff data entry container.
Definition entry.h:48
KNewStuff Base Provider class.
Definition provider.h:41
The ResultsStream is returned by EngineBase::search.
KNewStuff Transaction.
Definition transaction.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.