Fix the QTM_USE_NAMESPACE for Qt 4.7.
[meego-garage:garage-client-services.git] / src / applicationmanager.h
1 #ifndef APPLICATIONMANAGER_H
2 #define APPLICATIONMANAGER_H
3
4 #include <QObject>
5 #include <qnetworkconfigmanager.h>
6
7 #ifndef HAVE_NO_PACKAGEKIT
8 #include <QPackageKit>
9 #endif
10
11 #if QT_VERSION >= 040700
12 #else
13 QTM_USE_NAMESPACE
14 #endif
15
16 namespace MeeGoGarage {
17
18 class Application;
19 class ApplicationStatusStorage;
20
21 class ApplicationManager : public QObject
22 {
23 Q_OBJECT
24 public:
25
26     typedef enum {
27         /// No action runnig
28         NoAction,
29         /// Resolve running
30         ResolveAction,
31         /// Installing package
32         InstallAction,
33         /// Removing package
34         RemoveAction,
35         /// Updatig package
36         UpdateAction
37     } ActionType;
38
39     /// access to singleton object
40     static ApplicationManager* instance();
41
42     explicit ApplicationManager(QObject *parent = 0);
43     ~ApplicationManager();
44
45     void install(Application * app);
46     void install(QList<Application*> apps);
47
48     void remove(Application * app);
49     void remove(QList<Application*> apps);
50
51     void update(Application * app);
52     void update(QList<Application*> apps);
53
54     void resolve(Application * app);
55     void resolve(QList<Application*> apps);
56
57     bool canCancel() const;
58     /// private actions are internal actions not reported to the user like resolve
59     void cancelAll(bool privateActionsToo = false);
60
61     int numActionsTotal() const;
62     int numActionsDone() const;
63     bool isActionQueueEmpty() const;
64
65     ActionType applicationQueuedForAction(Application * app) const;
66
67     ActionType currentActionType() const;
68     QList<Application*> currentApplicationList() const;
69     bool isCurrentActionPrivate() const;
70
71     int percentage() const;
72     int elapsedTime() const;
73     int remainingTime() const;
74
75     // @returns Installing, Removing, ...
76     static QString actionTypeAsString(ActionType actionType);
77
78     void saveStatus();
79     void loadStatus();
80     void registerApplications(QList<Application*> appList);
81     void resolveOldOrUnknownApps();
82
83     bool isOnline();
84
85 signals:
86
87     /// Online state changed
88     void onlineStateChanged(bool isOnline);
89
90     /// Signaled every time there is a progress update
91     void progressUpdated(QString str, bool privateAction);
92     /// Signaled for every error
93     void applicationActionError(ApplicationManager::ActionType action,
94                                 QList<Application*> apps,
95                                 QString error,
96                                 bool privateAction);
97     /// Signaled when the whole operation is finished (either successfully or not)
98     void applicationActionCompleted(ApplicationManager::ActionType action,
99                                     QList<Application*> apps,
100                                     bool success,
101                                     bool privateAction);
102
103 private slots:
104
105     void onOnlineStateChanged(bool isOnline);
106
107 #ifndef HAVE_NO_PACKAGEKIT
108     // signals received from transactions from package kit
109     void onPackageResolved(QSharedPointer<PackageKit::Package>);
110     void onTransactionChanged();
111     void onTransactionError(PackageKit::Enum::Error, const QString&);
112     void onTransactionFinished(PackageKit::Enum::Exit,uint);
113     void onMessage(PackageKit::Enum::Message,QString);
114 #endif
115
116 private:
117
118     friend class Category;
119
120     ActionType applicationQueuedForAction(QList<Application *> apps) const;
121     void queueAction(ActionType actionType, Application * application);
122     void queueAction(ActionType actionType, QList<Application*> applicationList);
123 #ifndef HAVE_NO_PACKAGEKIT
124     bool takeActionFromQueue();
125     void processQueue();
126 #endif
127     void resolveIfNeeded(QList<Application*> appList);
128
129     void dumpDaemon();
130 #ifndef HAVE_NO_PACKAGEKIT
131     void dumpTransaction(PackageKit::Transaction * transaction);
132     void dumpPackage(QSharedPointer<PackageKit::Package> package);
133 #endif
134
135     Application * getApplicationByName(QList<Application*> applicationList, QString str) const;
136     Application * getApplicationByPackageName(QList<Application*> applicationList,  QString str) const;
137
138     Application *findApplicationContainedInString(
139             QList<Application*> applicationList,
140             QString string) const;
141
142     QList<Application*> findApplicationsContainedInString(
143             QList<Application*> applicationList,
144             QString string) const;
145
146     static QList<Application*> filterAppsToResolve(QList<Application*> applicationList);
147
148     typedef struct {
149         ActionType actionType;
150         QList<Application*> applicationList;
151     } Action;
152
153     /// pointer to singleton instance
154     static ApplicationManager* m_instance;
155
156     /// following action list contains user actions like install, remove, update (not resolve)
157     QList<Action> m_actionList;
158     /// following list is for private stuff like resolve actions (more prioritary)
159     QList<Action> m_privateActionList;
160     /// current operation running
161     Action m_currentAction;
162     /// to know if the current action is private
163     bool m_isCurrentActionPrivate;
164     QList<Application*> m_appsInProcess;
165 #ifndef HAVE_NO_PACKAGEKIT
166     PackageKit::Transaction * m_currentTransaction;
167 #else
168     void* m_currentTransaction;
169 #endif
170     // number of total actions, it gets reseted when the whole queue is empty
171     int m_numActionsTotal;
172
173     // storage of application status
174     ApplicationStatusStorage * m_statusStorage;
175     QNetworkConfigurationManager   m_networkManager;
176
177 };
178
179 } // MeeGoGarage
180
181 #endif // APPLICATIONMANAGER_H