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#ifndef KNEWSTUFF3_UI_DownloadManager_H
19#define KNEWSTUFF3_UI_DownloadManager_H
20
21#include "knewstuff_export.h"
22#include "entry.h"
23
24namespace KNS3
25{
26
27/**
28 * KNewStuff update checker.
29 * This class can be used to search for KNewStuff items
30 * without using the widgets and to look for updates of
31 * already installed items without showing the dialog.
32 * @since 4.5
33 */
34class KNEWSTUFF_EXPORT DownloadManager :public QObject
35{
36 Q_OBJECT
37
38public:
39 enum SortOrder {
40 Newest,
41 Alphabetical,
42 Rating,
43 Downloads
44 };
45
46 /**
47 * Create a DownloadManager
48 * It will try to find a appname.knsrc file (using KComponentData).
49 * Appname is the name of your application as provided in the about data->
50 *
51 * @param parent the parent of the dialog
52 */
53 explicit DownloadManager(QObject * parent = 0);
54
55 /**
56 * Create a DownloadManager. Manually specifying the name of the .knsrc file.
57 *
58 * @param configFile the name of the configuration file
59 * @param parent
60 */
61 explicit DownloadManager(const QString& configFile, QObject * parent = 0);
62
63 /**
64 * destructor
65 */
66 ~DownloadManager();
67
68 /**
69 Search for a list of entries. searchResult will be emitted with the requested list.
70 */
71 void search(int page = 0, int pageSize = 100);
72
73 /**
74 Check for available updates.
75 Use searchResult to get notified as soon as an update has been found.
76 */
77 void checkForUpdates();
78
79 /**
80 Installs or updates an entry
81 @param entry
82 */
83 void installEntry(const KNS3::Entry& entry);
84
85 /**
86 * Uninstalls the given entry.
87 * @param entry The entry which will be uninstalled.
88 * @since 4.7
89 */
90 void uninstallEntry(const KNS3::Entry& entry);
91
92 /**
93 Sets the search term to filter the results on the server.
94 Note that this function does not trigger a search. Use search after setting this.
95 @param searchTerm
96 */
97 void setSearchTerm(const QString& searchTerm);
98
99 /**
100 Set the sort order of the results. This depends on the server.
101 Note that this function does not trigger a search. Use search after setting this.
102 @see SortOrder
103 @param order
104 */
105 void setSearchOrder(SortOrder order);
106
107Q_SIGNALS:
108 /**
109 Returns the search result.
110 This can be the list of updates after checkForUpdates or the result of a search.
111 @param entries the list of results. entries is empty when nothing was found.
112 */
113 void searchResult(const KNS3::Entry::List& entries);
114
115 /**
116 The entry status has changed: emitted when the entry has been installed, updated or removed.
117 Use KNS3::Entry::status() to check the current status.
118 @param entry the item that has been updated.
119 */
120 void entryStatusChanged(const KNS3::Entry& entry);
121
122private:
123 Q_PRIVATE_SLOT( d, void _k_slotProvidersLoaded() )
124 Q_PRIVATE_SLOT( d, void _k_slotEntryStatusChanged(const KNS3::EntryInternal& entry) )
125 Q_PRIVATE_SLOT( d, void _k_slotEntriesLoaded(const KNS3::EntryInternal::List& entries) )
126 class Private;
127 Private *const d;
128 Q_DISABLE_COPY(DownloadManager)
129};
130
131}
132
133#endif
134