KNewStuff

engine.h
1 /*
2  knewstuff3/engine.h.
3  Copyright (c) 2007 Josef Spillner <[email protected]>
4  Copyright (C) 2007-2010 Frederik Gladhorn <[email protected]>
5  Copyright (c) 2009 Jeremy Whiting <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
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/>.
19 */
20 
21 #ifndef KNEWSTUFF3_ENGINE_P_H
22 #define KNEWSTUFF3_ENGINE_P_H
23 
24 #include <QObject>
25 #include <QString>
26 #include <QSharedPointer>
27 #include <QHash>
28 
29 #include "provider.h"
30 #include "entryinternal.h"
31 #include "errorcode.h"
32 
33 #include "knewstuffcore_export.h"
34 
35 class QTimer;
36 class KJob;
37 class EnginePrivate;
38 
39 namespace Attica
40 {
41 class ProviderManager;
42 class Provider;
43 }
44 
58 namespace KNSCore
59 {
60 class Cache;
61 class CommentsModel;
62 class Installation;
63 
70 class KNEWSTUFFCORE_EXPORT Engine : public QObject
71 {
72  Q_OBJECT
73 public:
77  explicit Engine(QObject *parent = nullptr);
78 
83  ~Engine();
84 
94  bool init(const QString &configfile);
95 
101  QString name() const;
102 
113  void install(KNSCore::EntryInternal entry, int linkId = 1);
114 
121  void uninstall(KNSCore::EntryInternal entry);
122 
132  void loadPreview(const KNSCore::EntryInternal &entry, EntryInternal::PreviewType type);
140  void loadDetails(const KNSCore::EntryInternal &entry);
141 
153  void setSortMode(Provider::SortMode mode);
159  Provider::SortMode sortMode() const;
173  void setFilter(Provider::Filter filter);
179  Provider::Filter filter() const;
180 
190  void setCategoriesFilter(const QStringList &categories);
199  void setSearchTerm(const QString &searchString);
205  QString searchTerm() const;
206  void reloadEntries();
207  void requestMoreData();
208  void requestData(int page, int pageSize);
209 
262  void setTagFilter(const QStringList &filter);
268  QStringList tagFilter() const;
276  void addTagFilter(const QString &filter);
295  void setDownloadTagFilter(const QStringList &filter);
301  QStringList downloadTagFilter() const;
310  void addDownloadTagFilter(const QString &filter);
311 
317  void checkForUpdates();
318 
324  void checkForInstalled();
325 
333  void fetchEntryById(const QString &id);
334 
338  void contactAuthor(const EntryInternal &entry);
339 
346  bool userCanVote(const EntryInternal &entry);
353  void vote(const EntryInternal &entry, uint rating);
354 
363  bool userCanBecomeFan(const EntryInternal &entry);
369  void becomeFan(const EntryInternal &entry);
370  // FIXME There is currently no exposed API to remove the fan status
371 
380  QStringList categories() const;
387  QStringList categoriesFilter() const;
388 
399  QList<Provider::CategoryMetadata> categoriesMetadata();
400 
417  QString adoptionCommand(const KNSCore::EntryInternal &entry) const;
424  bool hasAdoptionCommand() const;
425 
431  void setPageSize(int pageSize);
432 
441  static QStringList configSearchLocations(bool includeFallbackLocations = false);
451  void setConfigLocationFallback(bool enableFallback);
452 
460  QSharedPointer<Provider> provider(const QString &providerId) const;
461 
468 
479  CommentsModel *commentsForEntry(const KNSCore::EntryInternal &entry);
480 
481 Q_SIGNALS:
485  void signalMessage(const QString &message);
486 
487  void signalProvidersLoaded();
488  void signalEntriesLoaded(const KNSCore::EntryInternal::List &entries);
489  void signalUpdateableEntriesLoaded(const KNSCore::EntryInternal::List &entries);
490  void signalEntryChanged(const KNSCore::EntryInternal &entry);
491  void signalEntryDetailsLoaded(const KNSCore::EntryInternal &entry);
492 
493  // a new search result is there, clear the list of items
494  void signalResetView();
495 
496  void signalEntryPreviewLoaded(const KNSCore::EntryInternal &, KNSCore::EntryInternal::PreviewType);
497  void signalPreviewFailed();
498 
499  void signalEntryUploadFinished();
500  void signalEntryUploadFailed();
501 
502  void signalDownloadDialogDone(KNSCore::EntryInternal::List);
503  void jobStarted(KJob *, const QString &);
504 
505 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 53)
506  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 53, "Use Engine::signalErrorCode(const KNSCore::ErrorCode &, const QString &, const QVariant &)")
507  void signalError(const QString &);
508 #endif
509  void signalBusy(const QString &);
510  void signalIdle(const QString &);
519  void signalErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata);
520 
521  void signalCategoriesMetadataLoded(const QList<Provider::CategoryMetadata> &categories);
522 
523 private Q_SLOTS:
524  // the .knsrc file was loaded
525  void slotProviderFileLoaded(const QDomDocument &doc);
526  // instead of getting providers from knsrc, use what was configured in ocs systemsettings
527  void atticaProviderLoaded(const Attica::Provider &provider);
528 
529  // loading the .knsrc file failed
530  void slotProvidersFailed();
531 
532  // called when a provider is ready to work
533  void providerInitialized(KNSCore::Provider *);
534 
535  void slotEntriesLoaded(const KNSCore::Provider::SearchRequest &, KNSCore::EntryInternal::List);
536  void slotEntryDetailsLoaded(const KNSCore::EntryInternal &entry);
537  void slotPreviewLoaded(const KNSCore::EntryInternal &entry, KNSCore::EntryInternal::PreviewType type);
538 
539  void slotSearchTimerExpired();
540 
541  void slotEntryChanged(const KNSCore::EntryInternal &entry);
542  void slotInstallationFinished();
543  void slotInstallationFailed(const QString &message);
544  void downloadLinkLoaded(const KNSCore::EntryInternal &entry);
545 
546  void providerJobStarted(KJob *);
547 
548 private:
553  void loadProviders();
554 
558  void addProvider(QSharedPointer<KNSCore::Provider> provider);
559 
560  void updateStatus();
561 
562  void doRequest();
563 
564  //FIXME KF6: move all of this in EnginePrivate
565  // handle installation of entries
566  Installation *m_installation;
567  // read/write cache of entries
568  QSharedPointer<Cache> m_cache;
569  QTimer *m_searchTimer;
570  // The url of the file containing information about content providers
571  QString m_providerFileUrl;
572  // Categories from knsrc file
573  QStringList m_categories;
574 
576 
577  QString m_adoptionCommand;
578 
579  // the current request from providers
580  Provider::SearchRequest m_currentRequest;
581 
582  EnginePrivate * const d;
583 
584  // the page that is currently displayed, so it is not requested repeatedly
585  int m_currentPage;
586 
587  // when requesting entries from a provider, how many to ask for
588  int m_pageSize;
589 
590  int m_numDataJobs;
591  int m_numPictureJobs;
592  int m_numInstallJobs;
593  // If the provider is ready to be used
594  bool m_initialized;
595 
596  Q_DISABLE_COPY(Engine)
597 };
598 
599 }
600 
601 #endif
Contains the core functionality for handling interaction with NewStuff providers. ...
used to keep track of a search
Definition: provider.h:77
ErrorCode
An enumeration of specific error conditions which might occur and which users of KNewStuff would want...
Definition: errorcode.h:35
QCA_EXPORT Provider * defaultProvider()
A model which takes care of the comments for a single EntryInternal.
KNewStuff Base Provider class.
Definition: provider.h:52
QCA_EXPORT void init()
KNewStuff data entry container.
Definition: entryinternal.h:60
KNewStuff engine.
Definition: engine.h:70
KNewStuff entry installation.
Definition: installation.h:48
Definition: engine.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.