Add HAVE_NO_PACKAGEKIT for better UI dev.
[meego-garage:garage-client-services.git] / src / applicationmanager.h
1 #ifndef APPLICATIONMANAGER_H
2 #define APPLICATIONMANAGER_H
3
4 #include <QObject>
5
6 #ifndef HAVE_NO_PACKAGEKIT
7 #include <QPackageKit>
8 #endif
9
10 namespace MeeGoGarage {
11
12 class Application;
13 class ApplicationStatusStorage;
14
15 class ApplicationManager : public QObject
16 {
17 Q_OBJECT
18 public:
19
20     typedef enum {
21         /// No action runnig
22         NoAction,
23         /// Resolve running
24         ResolveAction,
25         /// Installing package
26         InstallAction,
27         /// Removing package
28         RemoveAction,
29         /// Updatig package
30         UpdateAction
31     } ActionType;
32
33     /// access to singleton object
34     static ApplicationManager* instance();
35
36     explicit ApplicationManager(QObject *parent = 0);
37     ~ApplicationManager();
38
39     void install(Application * app);
40     void install(QList<Application*> apps);
41
42     void remove(Application * app);
43     void remove(QList<Application*> apps);
44
45     void update(Application * app);
46     void update(QList<Application*> apps);
47
48     void resolve(Application * app);
49     void resolve(QList<Application*> apps);
50
51     bool canCancel() const;
52     void cancelAll();
53
54     int numActionsTotal() const;
55     int numActionsDone() const;
56
57     ActionType applicationQueuedForAction(Application * app) const;
58
59     ActionType currentActionType() const;
60     QList<Application*> currentApplicationList() const;
61
62     int percentage() const;
63     int elapsedTime() const;
64     int remainingTime() const;
65
66     static QString actionTypeAsString(ActionType actionType);
67
68     void saveStatus();
69     void loadStatus();
70     void registerApplications(QList<Application*> appList);
71     void resolveOldOrUnknownApps();
72
73 signals:
74
75     /// Signaled every time there is a progress update
76     void progressUpdated(QString str);
77     /// Signaled for every error
78     void applicationActionError(ApplicationManager::ActionType action, QList<Application*> apps, QString error);
79     /// Signaled when the whole operation is finished (either successfully or not)
80     void applicationActionCompleted(ApplicationManager::ActionType action, QList<Application*> apps, bool success);
81
82 private slots:
83
84 #ifndef HAVE_NO_PACKAGEKIT
85     void onPackageResolved(QSharedPointer<PackageKit::Package>);
86     void onTransactionChanged();
87     void onTransactionError(PackageKit::Enum::Error, const QString&);
88     void onTransactionFinished(PackageKit::Enum::Exit,uint);
89     void onMessage(PackageKit::Enum::Message,QString);
90 #endif
91
92 private:
93
94     friend class Category;
95
96     ActionType applicationQueuedForAction(QList<Application *> apps) const;
97     void queueAction(ActionType actionType, Application * application);
98     void queueAction(ActionType actionType, QList<Application*> applicationList);
99 #ifndef HAVE_NO_PACKAGEKIT
100     void processQueue();
101 #endif
102     void resolveIfNeeded(QList<Application*> appList);
103
104     Application * getApplicationByName(QList<Application*> applicationList, QString str) const;
105     Application * getApplicationByPackageName(QList<Application*> applicationList,  QString str) const;
106
107     Application *findApplicationContainedInString(
108             QList<Application*> applicationList,
109             QString string) const;
110
111     QList<Application*> findApplicationsContainedInString(
112             QList<Application*> applicationList,
113             QString string) const;
114
115     static QList<Application*> filterAppsToResolve(QList<Application*> applicationList);
116
117     typedef struct {
118         ActionType actionType;
119         QList<Application*> applicationList;
120     } Action;
121
122     /// pointer to singleton instance
123     static ApplicationManager* m_instance;
124
125     QList<Action> m_actionList;
126     Action m_currentAction;
127     QList<Application*> m_appsInProcess;
128 #ifndef HAVE_NO_PACKAGEKIT
129     PackageKit::Transaction * m_currentTransaction;
130 #else
131     void* m_currentTransaction;
132 #endif
133     // number of total actions, it gets reseted when the whole queue is empty
134     int m_numActionsTotal;
135
136     // storage of application status
137     ApplicationStatusStorage * m_statusStorage;
138
139 };
140
141 } // MeeGoGarage
142
143 #endif // APPLICATIONMANAGER_H