Merge branch 'master' of git@git.opensuse.org:projects/opensuse-updater-kde
[opensuse:kupdateapplet.git] / updater / packagekit / QPackageKitConnector.h
1 /*
2  * Copyright (C) 2007 Adrien Bustany <madcat@mymadcat.com>
3  *
4  * Licensed under the GNU General Public License Version 2
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2  See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14  *
15  */
16
17 #ifndef QPACKAGEKITCONNECTOR_H
18 #define QPACKAGEKITCONNECTOR_H
19
20 #include <QtCore>
21 #include <QtDBus>
22
23 #include "QPackageKitInterface.h"
24
25 #define PK_DBUS_SERVICE "org.freedesktop.PackageKit"
26 #define PK_DBUS_INTERFACE "org.freedesktop.PackageKit"
27 #define PK_DBUS_TRANSACTION_INTERFACE "org.freedesktop.PackageKit.Transaction"
28 #define PK_DBUS_PATH "/org/freedesktop/PackageKit"
29
30 //! Controls the PackageKit daemon
31 /*! This object uses a QPackageKitInterface (generated with qdbusxml2cpp) to control the PackageKit daemon.
32 It implements all the methods available in libpackagekit
33 */
34 class QPackageKitConnector : public QObject
35 {
36         Q_OBJECT;
37 public:
38         // Enums
39         class Role {
40         public:
41                 static void construct();
42
43                 //! What we asked to do
44                 typedef enum {
45                         Cancel,
46                         Resolve,
47                         Rollback,
48                         Get_depends,
49                         Get_update_detail,
50                         Get_description,
51                         Get_requires,
52                         Get_updates,
53                         Search_details,
54                         Search_file,
55                         Search_group,
56                         Search_name,
57                         Refresh_cache,
58                         Update_system,
59                         Remove_package,
60                         Install_package,
61                         Install_file,
62                         Update_package,
63                         Get_repo_list,
64                         Repo_enable,
65                         Repo_set_data,
66                         Unknown
67                 } RoleEnum;
68                 static QString toString(RoleEnum e);
69                 static RoleEnum fromString(QString s);
70
71         private:
72                 static QMap<int, QString> stringValues;
73         };
74
75         class Status {
76         public:
77                 static void construct();
78
79                 //! What we are doing
80                 typedef enum {
81                         Setup,
82                         Wait,
83                         Query,
84                         Remove,
85                         Refresh_cache,
86                         Download,
87                         Install,
88                         Update,
89                         Unknown
90                 } StatusEnum;
91                 static QString toString(StatusEnum e);
92                 static StatusEnum fromString(QString s);
93
94         private:
95                 static QMap<int, QString> stringValues;
96         };
97
98         class Exit {
99         public:
100                 static void construct();
101
102                 typedef enum {
103                         Success,
104                         Failed,
105                         Canceled,
106                         Unknown
107                 } ExitEnum;
108                 static QString toString(ExitEnum e);
109                 static ExitEnum fromString(QString s);
110
111         private:
112                 static QMap<int, QString> stringValues;
113         };
114
115         class Filter {
116         public:
117                 static void construct();
118
119                 typedef enum {
120                         Development,
121                         Installed,               
122                         Gui,
123                         Normal,          /* not development */
124                         Available,       /* not installed */
125                         Text,            /* not gui */
126                         Unknown
127                 } FilterEnum;
128                 static QString toString(FilterEnum e);
129                 static FilterEnum fromString(QString s);
130
131         private:
132                 static QMap<int, QString> stringValues;
133         };
134         // End Enums
135
136         //! QPackageKitConnector constructor
137         QPackageKitConnector(QObject *parent = 0);
138
139         //! Cancels the current transaction
140         void Cancel();
141
142         //! Searches for a package using its name
143         bool searchName(QString name, QList<Filter::FilterEnum> filters);
144
145         //! Orders the description of a package
146         bool getDescription(QString packageId);
147
148         //! Installs a package
149         bool installPackage(QString packageId);
150
151         //! Updates a list of packages
152         bool updatePackages(QStringList packageIds);
153
154         //! Orders a list of updates
155         bool getUpdates();
156
157         //! Refresh cache
158         bool refreshCache(bool force);
159
160         //! Accept an eule
161         bool acceptEula(QString eulaId);
162
163
164 signals:
165         //! Emitted when the daemon sends us a package
166         void Package(const QString &info, const QString &package_id, const QString &summary);
167
168         //! Emitted when the current transaction is finished
169         void Finished(QPackageKitConnector::Exit::ExitEnum exitCode, uint runtime);
170
171         //! Emitted when getUpdates transaction is finished
172         void UpdatesFinished();
173
174         //! Emitted when the current transaction's progress changes 
175         void ProgressChanged(uint percentage, uint subpercentage, uint elapsed, uint remaining);
176
177         //! Emitted when we cannot track the progress of the current transaction
178         void NoProgressUpdates();
179         
180         //! Emitted when the daemon sends us a package description
181         void Description(const QString &package_id, const QString &licence, const QString &group,
182                         const QString &detail, const QString &url, qulonglong size); 
183
184         //! Emitted when an error occures
185         void ErrorMessage(const QString &message);
186
187         //! Emittet when a signature is required
188         void RepoSignatureRequired(const QString &package_id, const QString &repository_name,
189                 const QString  &key_url, const QString &key_userid, const QString &key_id,
190                 const QString &key_fingerprint, const QString &key_timestamp, const QString &type);
191
192         //! Emitted when there is an eula to accept
193         void EulaRequired(const QString &eula_id, const QString &package_id, const QString vendor_name,
194                         const QString &license_agreement);
195         
196 public slots:
197         void proxy_Package(const QString &info, const QString &package_id, const QString &summary);
198         void proxy_Finished(const QString &status, uint runtime, QPackageKitInterface*);
199         void proxy_ProgressChanged(uint percentage, uint subpercentage, uint elapsed, uint remaining);
200         void proxy_Description(const QString &package_id, const QString &licence,
201                 const QString &group, const QString &detail, const QString &url, qulonglong size ); 
202         void Error(const QString&,const QString&);
203         void proxy_EulaRequired(const QString &eula_id, const QString &package_id,
204                         const QString &vendor_name, const QString &license_agreement);
205
206         void proxy_RepoSignatureRequired(const QString &package_id, const QString &repository_name,
207                 const QString &key_url, const QString &key_userid, const QString &key_id,
208                 const QString &key_fingerprint, const QString &key_timestamp, const QString &type);
209
210
211 private:
212         // Utility functions
213
214         // send error message 
215         void sendErrorMessage(QPackageKitInterface*);
216
217         //! Allocates a transaction id
218         QString allocateTid(QString type);
219
220         QString getTid();
221
222         void disconnectFromInterface(QPackageKitInterface*);
223         QPackageKitInterface* connectToInterface();
224
225 };
226
227 #endif