KNewStuff
coreengine.h
Go to the documentation of this file.
00001 /* 00002 This file is part of KNewStuff2. 00003 Copyright (c) 2007 Josef Spillner <spillner@kde.org> 00004 Copyright (c) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 #ifndef KNEWSTUFF2_COREENGINE_H 00020 #define KNEWSTUFF2_COREENGINE_H 00021 00022 #include <knewstuff2/core/provider.h> 00023 #include <knewstuff2/core/entry.h> 00024 00025 #include <knewstuff2/knewstuff_export.h> 00026 00027 #include <QtCore/QObject> 00028 #include <QtCore/QString> 00029 #include <QtCore/QMap> 00030 00031 class KJob; 00032 class KArchiveDirectory; 00033 00034 namespace KNS 00035 { 00036 00037 class Installation; 00038 00047 class KNEWSTUFF_EXPORT CoreEngine : public QObject 00048 { 00049 Q_OBJECT 00050 public: 00054 CoreEngine(QObject* parent); 00055 00060 ~CoreEngine(); 00061 00075 enum CachePolicy { 00077 CacheNever, 00079 CacheReplaceable, 00081 CacheResident, 00083 CacheOnly 00084 }; 00085 00098 enum AutomationPolicy { 00100 AutomationOn, 00102 AutomationOff 00103 }; 00104 00105 void setAutomationPolicy(AutomationPolicy policy); 00106 void setCachePolicy(CachePolicy policy); 00107 00116 bool init(const QString &configfile); 00117 00142 void start(); 00143 00159 void loadEntries(Provider *provider); 00160 //void loadProvider(); // FIXME: for consistency? 00161 00173 void downloadPreview(Entry *entry); 00174 00186 void downloadPayload(Entry *entry); 00187 00203 bool uploadEntry(Provider *provider, Entry *entry); 00204 00221 bool install(const QString& payloadfile); 00222 00233 bool uninstall(KNS::Entry *entry); 00234 00239 QString componentName() const; 00240 00241 Q_SIGNALS: 00247 void signalProviderLoaded(KNS::Provider *provider); 00248 void signalProviderChanged(KNS::Provider *provider); 00249 void signalProvidersFailed(); 00250 00251 void signalEntryLoaded(KNS::Entry *entry, const KNS::Feed *feed, const KNS::Provider *provider); 00252 void signalEntryRemoved(KNS::Entry *entry, const KNS::Feed *feed); 00253 void signalEntryChanged(KNS::Entry *entry); 00254 void signalEntriesFailed(); 00255 00256 void signalPreviewLoaded(KUrl preview); // FIXME: return Entry 00257 void signalPreviewFailed(); 00258 00259 void signalPayloadLoaded(KUrl payload); // FIXME: return Entry 00260 void signalPayloadFailed(KNS::Entry *entry); 00261 00262 void signalEntryUploaded(); // FIXME: rename to signalEntryUploadFinished? 00263 void signalEntryFailed(); // FIXME: rename to signalEntryUploadFailed? 00264 00265 void signalProvidersFinished(); 00266 void signalEntriesFinished(); 00267 void signalEntriesFeedFinished(const KNS::Feed *feed); 00268 00269 void signalInstallationFinished(); 00270 void signalInstallationFailed(); 00271 00272 void signalProgress(const QString & message, int percentage); 00273 00274 void signalDownloadDialogDone(KNS::Entry::List); 00275 protected: 00276 void mergeEntries(Entry::List entries, Feed *feed, const Provider *provider); 00277 private Q_SLOTS: 00278 void slotProvidersLoaded(KNS::Provider::List list); 00279 void slotProvidersFailed(); 00280 00281 void slotEntriesLoaded(KNS::Entry::List list); 00282 void slotEntriesFailed(); 00283 00284 void slotPayloadResult(KJob *job); 00285 void slotPreviewResult(KJob *job); 00286 00287 void slotUploadPayloadResult(KJob *job); 00288 void slotUploadPreviewResult(KJob *job); 00289 void slotUploadMetaResult(KJob *job); 00290 00291 void slotProgress(KJob *job, unsigned long percent); 00292 00293 void slotInstallationVerification(int result); 00294 00295 private: 00296 void loadRegistry(); 00297 void loadProvidersCache(); 00298 KNS::Entry *loadEntryCache(const QString& filepath); 00299 #if 0 00300 void loadEntriesCache(); 00301 #endif 00302 void loadFeedCache(Provider *provider); 00303 void cacheProvider(Provider *provider); 00304 void cacheEntry(Entry *entry); 00305 00313 void cacheFeed(const Provider *provider, const QString & feedname, const Feed *feed, Entry::List entries); 00314 void registerEntry(Entry *entry); 00315 void unregisterEntry(Entry *entry); 00316 void mergeProviders(Provider::List providers); 00317 void shutdown(); 00318 00319 bool entryCached(Entry *entry); 00320 bool entryChanged(Entry *oldentry, Entry *entry); 00321 bool providerCached(Provider *provider); 00322 bool providerChanged(Provider *oldprovider, Provider *provider); 00323 00324 static QStringList archiveEntries(const QString& path, const KArchiveDirectory * dir); 00325 00326 QString id(Entry *e); 00327 QString pid(const Provider *p); 00328 00329 QList<Provider*> m_provider_cache; 00330 00331 // holds all the entries 00332 QList<Entry*> m_entry_cache; 00333 00334 // holds the registered entries mapped by their id 00335 QMap<QString, Entry*> m_entry_registry; 00336 00337 QMap<QString, Provider*> m_provider_index; 00338 QMap<QString, Entry*> m_entry_index; 00339 00340 Entry *m_uploadedentry; 00341 Provider *m_uploadprovider; 00342 00343 QString m_providersurl; 00344 QString m_componentname; 00345 00346 QMap<Entry*, QString> m_previewfiles; 00347 QMap<Entry*, QString> m_payloadfiles; 00348 00349 QMap<KJob*, Entry*> m_entry_jobs; 00350 00351 Installation *m_installation; 00352 00353 int m_activefeeds; 00354 00355 bool m_initialized; 00356 CachePolicy m_cachepolicy; 00357 AutomationPolicy m_automationpolicy; 00358 }; 00359 00360 } 00361 00362 #endif
KDE 4.6 API Reference