• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KNewStuff

downloadmanager.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2010 Frederik Gladhorn <gladhorn@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "downloadmanager.h"
00019 
00020 #include <kcomponentdata.h>
00021 #include <kglobal.h>
00022 #include <kdebug.h>
00023 
00024 #include "core/engine.h"
00025 
00026 namespace KNS3 {
00027 class DownloadManager::Private
00028 {
00029 public:
00030     DownloadManager* q;
00031     Engine* engine;
00032 
00033     Private(DownloadManager* q)
00034         : q(q)
00035         , engine(new Engine)
00036         , isInitialized(false)
00037         , checkForUpdates(false)
00038         , doSearch(false)
00039         , page(0)
00040         , pageSize(100)
00041     {}
00042     ~Private() { delete engine; }
00043     
00044     bool isInitialized;
00045     bool checkForUpdates;
00046     bool doSearch;
00047     
00048     int page;
00049     int pageSize;
00050     
00051     void init(const QString& configFile);
00052     void _k_slotProvidersLoaded();
00053     void _k_slotUpdatesLoaded(const KNS3::EntryInternal::List& entries);
00054     void _k_slotEntryStatusChanged(const KNS3::EntryInternal& entry);
00055     void _k_slotEntriesLoaded(const KNS3::EntryInternal::List& entries);
00056 };
00057 }
00058 
00059 using namespace KNS3;
00060 
00061 DownloadManager::DownloadManager(QObject* parent)
00062     : QObject(parent)
00063     , d(new Private(this))
00064 {
00065     KComponentData component = KGlobal::activeComponent();
00066     QString name = component.componentName();
00067     d->init(name + ".knsrc");
00068 }
00069 
00070 DownloadManager::DownloadManager(const QString& configFile, QObject * parent)
00071         : QObject(parent)
00072         , d(new Private(this))
00073 {
00074     d->init(configFile);
00075 }
00076 
00077 void DownloadManager::Private::init(const QString& configFile)
00078 {
00079     q->connect(engine, SIGNAL(signalProvidersLoaded()), q, SLOT(_k_slotProvidersLoaded()));
00080     q->connect(engine, SIGNAL(signalUpdateableEntriesLoaded(KNS3::EntryInternal::List)), q, SLOT(_k_slotEntriesLoaded(KNS3::EntryInternal::List)));
00081     q->connect(engine, SIGNAL(signalEntriesLoaded(KNS3::EntryInternal::List)), q, SLOT(_k_slotEntriesLoaded(KNS3::EntryInternal::List)));
00082     q->connect(engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)), q, SLOT(_k_slotEntryStatusChanged(KNS3::EntryInternal)));
00083     engine->init(configFile);
00084 }
00085 
00086 DownloadManager::~DownloadManager()
00087 {
00088     delete d;
00089 }
00090 
00091 void DownloadManager::Private::_k_slotProvidersLoaded()
00092 {
00093     kDebug() << "providers loaded";
00094     isInitialized = true;
00095     if (checkForUpdates) {
00096         engine->checkForUpdates();
00097     } else if (doSearch) {
00098         engine->requestData(page, pageSize);
00099     }
00100 }
00101 
00102 void DownloadManager::checkForUpdates()
00103 {
00104     if (d->isInitialized) {
00105         d->engine->checkForUpdates();
00106     } else {
00107         d->checkForUpdates = true;
00108     }
00109 }
00110 
00111 void DownloadManager::Private::_k_slotEntriesLoaded(const KNS3::EntryInternal::List& entries)
00112 {
00113     KNS3::Entry::List result;
00114     foreach (const KNS3::EntryInternal& entry, entries) {
00115         result.append(entry.toEntry());
00116     }
00117     emit q->searchResult(result);
00118 }
00119 
00120 void KNS3::DownloadManager::Private::_k_slotEntryStatusChanged(const KNS3::EntryInternal& entry)
00121 {
00122     emit q->entryStatusChanged(entry.toEntry());
00123 }
00124 
00125 void DownloadManager::installEntry(const KNS3::Entry& entry)
00126 {
00127     KNS3::EntryInternal entryInternal = EntryInternal::fromEntry(entry);
00128     if (entryInternal.isValid()) {
00129         d->engine->install(entryInternal);
00130     }
00131 }
00132 
00133 void DownloadManager::search(int page, int pageSize)
00134 {
00135     d->page = page;
00136     d->pageSize = pageSize;
00137 
00138     if (d->isInitialized) {
00139         d->engine->requestData(page, pageSize);
00140     } else {
00141         d->doSearch = true;
00142     }
00143 }
00144 
00145 void DownloadManager::setSearchOrder(DownloadManager::SortOrder order)
00146 {
00147     switch (order) {
00148         case Newest:
00149             d->engine->setSortMode(Provider::Newest);
00150             break;
00151         case Rating:
00152             d->engine->setSortMode(Provider::Rating);
00153             break;
00154         case Alphabetical:
00155             d->engine->setSortMode(Provider::Alphabetical);
00156             break;
00157         case Downloads:
00158             d->engine->setSortMode(Provider::Downloads);
00159             break;
00160     }
00161 }
00162 
00163 void DownloadManager::setSearchTerm(const QString& searchTerm)
00164 {
00165     d->engine->setSearchTerm(searchTerm);
00166 }
00167 
00168 
00169 #include "downloadmanager.moc"

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal