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

KNewStuff

  • sources
  • kde-4.14
  • kdelibs
  • knewstuff
  • knewstuff3
downloadmanager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Frederik Gladhorn <gladhorn@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "downloadmanager.h"
19 
20 #include <kcomponentdata.h>
21 #include <kglobal.h>
22 #include <kdebug.h>
23 
24 #include "core/engine.h"
25 
26 namespace KNS3 {
27 class DownloadManager::Private
28 {
29 public:
30  DownloadManager* q;
31  Engine* engine;
32 
33  Private(DownloadManager* q)
34  : q(q)
35  , engine(new Engine)
36  , isInitialized(false)
37  , checkForUpdates(false)
38  , doSearch(false)
39  , page(0)
40  , pageSize(100)
41  {}
42  ~Private() { delete engine; }
43 
44  bool isInitialized;
45  bool checkForUpdates;
46  bool doSearch;
47 
48  int page;
49  int pageSize;
50 
51  void init(const QString& configFile);
52  void _k_slotProvidersLoaded();
53  void _k_slotUpdatesLoaded(const KNS3::EntryInternal::List& entries);
54  void _k_slotEntryStatusChanged(const KNS3::EntryInternal& entry);
55  void _k_slotEntriesLoaded(const KNS3::EntryInternal::List& entries);
56 };
57 }
58 
59 using namespace KNS3;
60 
61 DownloadManager::DownloadManager(QObject* parent)
62  : QObject(parent)
63  , d(new Private(this))
64 {
65  KComponentData component = KGlobal::activeComponent();
66  QString name = component.componentName();
67  d->init(name + ".knsrc");
68 }
69 
70 DownloadManager::DownloadManager(const QString& configFile, QObject * parent)
71  : QObject(parent)
72  , d(new Private(this))
73 {
74  d->init(configFile);
75 }
76 
77 void DownloadManager::Private::init(const QString& configFile)
78 {
79  q->connect(engine, SIGNAL(signalProvidersLoaded()), q, SLOT(_k_slotProvidersLoaded()));
80  q->connect(engine, SIGNAL(signalUpdateableEntriesLoaded(KNS3::EntryInternal::List)), q, SLOT(_k_slotEntriesLoaded(KNS3::EntryInternal::List)));
81  q->connect(engine, SIGNAL(signalEntriesLoaded(KNS3::EntryInternal::List)), q, SLOT(_k_slotEntriesLoaded(KNS3::EntryInternal::List)));
82  q->connect(engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)), q, SLOT(_k_slotEntryStatusChanged(KNS3::EntryInternal)));
83  engine->init(configFile);
84 }
85 
86 DownloadManager::~DownloadManager()
87 {
88  delete d;
89 }
90 
91 void DownloadManager::Private::_k_slotProvidersLoaded()
92 {
93  kDebug() << "providers loaded";
94  isInitialized = true;
95  if (checkForUpdates) {
96  engine->checkForUpdates();
97  } else if (doSearch) {
98  engine->requestData(page, pageSize);
99  }
100 }
101 
102 void DownloadManager::checkForUpdates()
103 {
104  if (d->isInitialized) {
105  d->engine->checkForUpdates();
106  } else {
107  d->checkForUpdates = true;
108  }
109 }
110 
111 void DownloadManager::Private::_k_slotEntriesLoaded(const KNS3::EntryInternal::List& entries)
112 {
113  KNS3::Entry::List result;
114  foreach (const KNS3::EntryInternal& entry, entries) {
115  result.append(entry.toEntry());
116  }
117  emit q->searchResult(result);
118 }
119 
120 void KNS3::DownloadManager::Private::_k_slotEntryStatusChanged(const KNS3::EntryInternal& entry)
121 {
122  emit q->entryStatusChanged(entry.toEntry());
123 }
124 
125 void DownloadManager::installEntry(const KNS3::Entry& entry)
126 {
127  KNS3::EntryInternal entryInternal = EntryInternal::fromEntry(entry);
128  if (entryInternal.isValid()) {
129  d->engine->install(entryInternal);
130  }
131 }
132 
133 void DownloadManager::uninstallEntry(const KNS3::Entry& entry)
134 {
135  KNS3::EntryInternal entryInternal = EntryInternal::fromEntry(entry);
136  if (entryInternal.isValid()) {
137  d->engine->uninstall(entryInternal);
138  }
139 }
140 
141 void DownloadManager::search(int page, int pageSize)
142 {
143  d->page = page;
144  d->pageSize = pageSize;
145 
146  if (d->isInitialized) {
147  d->engine->requestData(page, pageSize);
148  } else {
149  d->doSearch = true;
150  }
151 }
152 
153 void DownloadManager::setSearchOrder(DownloadManager::SortOrder order)
154 {
155  switch (order) {
156  case Newest:
157  d->engine->setSortMode(Provider::Newest);
158  break;
159  case Rating:
160  d->engine->setSortMode(Provider::Rating);
161  break;
162  case Alphabetical:
163  d->engine->setSortMode(Provider::Alphabetical);
164  break;
165  case Downloads:
166  d->engine->setSortMode(Provider::Downloads);
167  break;
168  }
169 }
170 
171 void DownloadManager::setSearchTerm(const QString& searchTerm)
172 {
173  d->engine->setSearchTerm(searchTerm);
174 }
175 
176 
177 #include "downloadmanager.moc"
kdebug.h
KNS3::EntryInternal
KNewStuff data entry container.
Definition: entryinternal.h:54
KNS3::EntryInternal::isValid
bool isValid() const
Definition: entryinternal.cpp:119
KNS3::Engine
KNewStuff engine.
Definition: knewstuff3/core/engine.h:52
KNS3::DownloadManager::Rating
Definition: downloadmanager.h:42
KNS3::Provider::Downloads
Definition: knewstuff3/core/provider.h:56
KNS3::EntryInternal::toEntry
Entry toEntry() const
Definition: entryinternal.cpp:574
KNS3::DownloadManager
KNewStuff update checker.
Definition: downloadmanager.h:34
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KNS3::DownloadManager::Newest
Definition: downloadmanager.h:40
QObject::name
const char * name() const
KNS3::Provider::Newest
Definition: knewstuff3/core/provider.h:53
kglobal.h
KNS3::Provider::Alphabetical
Definition: knewstuff3/core/provider.h:54
QList::append
void append(const T &value)
KNS3::DownloadManager::uninstallEntry
void uninstallEntry(const KNS3::Entry &entry)
Uninstalls the given entry.
Definition: downloadmanager.cpp:133
KNS3::DownloadManager::installEntry
void installEntry(const KNS3::Entry &entry)
Installs or updates an entry.
Definition: downloadmanager.cpp:125
KNS3::DownloadManager::SortOrder
SortOrder
Definition: downloadmanager.h:39
KNS3::Entry
KNewStuff information about changed entries.
Definition: knewstuff3/entry.h:44
QObject
KNS3::DownloadManager::DownloadManager
DownloadManager(QObject *parent=0)
Create a DownloadManager It will try to find a appname.knsrc file (using KComponentData).
Definition: downloadmanager.cpp:61
KNS3::DownloadManager::search
void search(int page=0, int pageSize=100)
Search for a list of entries.
Definition: downloadmanager.cpp:141
KGlobal::activeComponent
KComponentData activeComponent()
KNS3::Provider::Rating
Definition: knewstuff3/core/provider.h:55
KComponentData::componentName
QString componentName() const
QString
QList
KNS3::DownloadManager::~DownloadManager
~DownloadManager()
destructor
Definition: downloadmanager.cpp:86
KNS3::DownloadManager::Alphabetical
Definition: downloadmanager.h:41
KNS3::DownloadManager::Downloads
Definition: downloadmanager.h:43
KNS3::DownloadManager::setSearchOrder
void setSearchOrder(SortOrder order)
Set the sort order of the results.
Definition: downloadmanager.cpp:153
downloadmanager.h
KNS3::EntryInternal::fromEntry
static KNS3::EntryInternal fromEntry(const KNS3::Entry &entry)
Definition: entryinternal.cpp:581
KNS3::DownloadManager::setSearchTerm
void setSearchTerm(const QString &searchTerm)
Sets the search term to filter the results on the server.
Definition: downloadmanager.cpp:171
engine.h
KNS3::DownloadManager::checkForUpdates
void checkForUpdates()
Check for available updates.
Definition: downloadmanager.cpp:102
kcomponentdata.h
KComponentData
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal