KNewStuff

engine.h
1 /*
2  knewstuff3/engine.h.
3  SPDX-FileCopyrightText: 2007 Josef Spillner <[email protected]>
4  SPDX-FileCopyrightText: 2007-2010 Frederik Gladhorn <[email protected]>
5  SPDX-FileCopyrightText: 2009 Jeremy Whiting <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9 
10 #ifndef KNEWSTUFF3_ENGINE_P_H
11 #define KNEWSTUFF3_ENGINE_P_H
12 
13 #include <QObject>
14 #include <QString>
15 #include <QSharedPointer>
16 #include <QHash>
17 
18 #include "provider.h"
19 #include "entryinternal.h"
20 #include "errorcode.h"
21 
22 #include "knewstuffcore_export.h"
23 
24 class QTimer;
25 class KJob;
26 class EnginePrivate;
27 
28 namespace Attica
29 {
30 class ProviderManager;
31 class Provider;
32 }
33 
47 namespace KNSCore
48 {
49 class Cache;
50 class CommentsModel;
51 class Installation;
52 
59 class KNEWSTUFFCORE_EXPORT Engine : public QObject
60 {
61  Q_OBJECT
62 
68  Q_PROPERTY(BusyState busyState READ busyState WRITE setBusyState NOTIFY busyStateChanged)
69 
70 
74  Q_PROPERTY(QString busyMessage READ busyMessage WRITE setBusyMessage NOTIFY busyMessageChanged)
75 
80  Q_PROPERTY(QString useLabel READ useLabel NOTIFY useLabelChanged)
81 
82 public:
86  explicit Engine(QObject *parent = nullptr);
87 
92  ~Engine();
93 
94  enum class BusyOperation {
95  Initializing,
96  LoadingData,
97  LoadingPreview,
98  InstallingEntry,
99  };
100  Q_DECLARE_FLAGS(BusyState, BusyOperation)
101 
102 
111  bool init(const QString &configfile);
112 
118  QString name() const;
119 
130  void install(KNSCore::EntryInternal entry, int linkId = 1);
131 
138  void uninstall(KNSCore::EntryInternal entry);
139 
149  void loadPreview(const KNSCore::EntryInternal &entry, EntryInternal::PreviewType type);
157  void loadDetails(const KNSCore::EntryInternal &entry);
158 
170  void setSortMode(Provider::SortMode mode);
176  Provider::SortMode sortMode() const;
190  void setFilter(Provider::Filter filter);
196  Provider::Filter filter() const;
197 
207  void setCategoriesFilter(const QStringList &categories);
216  void setSearchTerm(const QString &searchString);
222  QString searchTerm() const;
223  void reloadEntries();
224  void requestMoreData();
225  void requestData(int page, int pageSize);
226 
279  void setTagFilter(const QStringList &filter);
285  QStringList tagFilter() const;
293  void addTagFilter(const QString &filter);
312  void setDownloadTagFilter(const QStringList &filter);
318  QStringList downloadTagFilter() const;
327  void addDownloadTagFilter(const QString &filter);
328 
334  void checkForUpdates();
335 
341  void checkForInstalled();
342 
350  void fetchEntryById(const QString &id);
351 
355  void contactAuthor(const EntryInternal &entry);
356 
363  bool userCanVote(const EntryInternal &entry);
370  void vote(const EntryInternal &entry, uint rating);
371 
380  bool userCanBecomeFan(const EntryInternal &entry);
386  void becomeFan(const EntryInternal &entry);
387  // FIXME There is currently no exposed API to remove the fan status
388 
397  QStringList categories() const;
404  QStringList categoriesFilter() const;
405 
416  QList<Provider::CategoryMetadata> categoriesMetadata();
417 
418 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77)
419 
436  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::adoptEntry(const KNSCore::EntryInternal &entry) instead")
437  QString adoptionCommand(const KNSCore::EntryInternal &entry) const;
438 #endif
439 
446  bool hasAdoptionCommand() const;
447 
455  Q_INVOKABLE void adoptEntry(const KNSCore::EntryInternal &entry);
456 
461  QString useLabel() const;
462 
467  Q_SIGNAL void useLabelChanged();
468 
474  void setPageSize(int pageSize);
475 
484  static QStringList configSearchLocations(bool includeFallbackLocations = false);
494  void setConfigLocationFallback(bool enableFallback);
495 
503  QSharedPointer<Provider> provider(const QString &providerId) const;
504 
511 
522  CommentsModel *commentsForEntry(const KNSCore::EntryInternal &entry);
523 
528  QString busyMessage() const;
529 
535  void setBusyMessage(const QString &busyMessage);
536 
541  Q_SIGNAL void busyMessageChanged();
542 
547  BusyState busyState() const;
548 
555  void setBusyState(BusyState state);
556 
561  Q_SIGNAL void busyStateChanged();
562 
567  void setBusy(BusyState state, const QString &busyMessage);
568 
575  QSharedPointer<Cache> cache() const;
576 
583  Q_INVOKABLE void revalidateCacheEntries();
584 
585 Q_SIGNALS:
589  void signalMessage(const QString &message);
590 
591  void signalProvidersLoaded();
592  void signalEntriesLoaded(const KNSCore::EntryInternal::List &entries);
593  void signalUpdateableEntriesLoaded(const KNSCore::EntryInternal::List &entries);
594 
595 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77)
596  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::signalEntryEvent instead")
597  void signalEntryChanged(const KNSCore::EntryInternal &entry);
598 #endif
599 
600 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77)
601  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::signalEntryEvent instead")
602  void signalEntryDetailsLoaded(const KNSCore::EntryInternal &entry);
603 #endif
604 
605  // a new search result is there, clear the list of items
606  void signalResetView();
607 
608  void signalEntryPreviewLoaded(const KNSCore::EntryInternal &, KNSCore::EntryInternal::PreviewType);
609  void signalPreviewFailed();
610 
611  void signalEntryUploadFinished();
612  void signalEntryUploadFailed();
613 
614  void signalDownloadDialogDone(KNSCore::EntryInternal::List);
615  void jobStarted(KJob *, const QString &);
616 
617 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 53)
618  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 53, "Use Engine::signalErrorCode(const KNSCore::ErrorCode &, const QString &, const QVariant &)")
619  void signalError(const QString &);
620 #endif
621 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 74)
622  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 74, "Use Engine::busyStateChanged() and Engine::busyMessageChanged() instead")
623  void signalBusy(const QString &);
624 #endif
625 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 74)
626  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 74, "Use Engine::busyStateChanged() and Engine::busyMessageChanged() instead")
627  void signalIdle(const QString &);
628 #endif
629 
638  void signalErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata);
639 
640  void signalCategoriesMetadataLoded(const QList<Provider::CategoryMetadata> &categories);
641 
642  void signalEntryEvent(const EntryInternal &entry, EntryInternal::EntryEvent event);
643 
644 private Q_SLOTS:
645  // the .knsrc file was loaded
646  void slotProviderFileLoaded(const QDomDocument &doc);
647  // instead of getting providers from knsrc, use what was configured in ocs systemsettings
648  void atticaProviderLoaded(const Attica::Provider &provider);
649 
650  // loading the .knsrc file failed
651  void slotProvidersFailed();
652 
653  // called when a provider is ready to work
654  void providerInitialized(KNSCore::Provider *);
655 
656  void slotEntriesLoaded(const KNSCore::Provider::SearchRequest &, KNSCore::EntryInternal::List);
657  void slotEntryDetailsLoaded(const KNSCore::EntryInternal &entry);
658  void slotPreviewLoaded(const KNSCore::EntryInternal &entry, KNSCore::EntryInternal::PreviewType type);
659 
660  void slotSearchTimerExpired();
661 
662  void slotEntryChanged(const KNSCore::EntryInternal &entry);
663  void slotInstallationFinished();
664  void slotInstallationFailed(const QString &message);
665  void downloadLinkLoaded(const KNSCore::EntryInternal &entry);
666 
667  void providerJobStarted(KJob *);
668 
669 private:
674  void loadProviders();
675 
679  void addProvider(QSharedPointer<KNSCore::Provider> provider);
680 
681  void updateStatus();
682 
683  void doRequest();
684 
685  //FIXME KF6: move all of this in EnginePrivate
686  // handle installation of entries
687  Installation *m_installation;
688  // read/write cache of entries
689  QSharedPointer<Cache> m_cache;
690  QTimer *m_searchTimer;
691  // The url of the file containing information about content providers
692  QString m_providerFileUrl;
693  // Categories from knsrc file
694  QStringList m_categories;
695 
697 
698  QString m_adoptionCommand;
699 
700  // the current request from providers
701  Provider::SearchRequest m_currentRequest;
702 
703  EnginePrivate * const d;
704 
705  // the page that is currently displayed, so it is not requested repeatedly
706  int m_currentPage;
707 
708  // when requesting entries from a provider, how many to ask for
709  int m_pageSize;
710 
711  int m_numDataJobs;
712  int m_numPictureJobs;
713  int m_numInstallJobs;
714  // If the provider is ready to be used
715  bool m_initialized;
716 
717  Q_DISABLE_COPY(Engine)
718 };
719 
720 }
721 
722 #endif
Contains the core functionality for handling interaction with NewStuff providers. ...
used to keep track of a search
Definition: provider.h:67
ErrorCode
An enumeration of specific error conditions which might occur and which users of KNewStuff would want...
Definition: errorcode.h:25
QCA_EXPORT Provider * defaultProvider()
A model which takes care of the comments for a single EntryInternal.
KNewStuff Base Provider class.
Definition: provider.h:42
QCA_EXPORT void init()
KNewStuff data entry container.
Definition: entryinternal.h:49
KNewStuff engine.
Definition: engine.h:59
KNewStuff entry installation.
Definition: installation.h:38
Definition: engine.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.