Change the newRepoDownloaded signal.
[meego-garage:garage-client-services.git] / src / catalog.h
1 #ifndef CATALOG_H
2 #define CATALOG_H
3
4 #include <QObject>
5 #include <QNetworkAccessManager>
6 #include <QNetworkProxy>
7 #include <QNetworkReply>
8 #include <QDateTime>
9 #include <QStringList>
10 #include "baseobject.h"
11 #include "application.h"
12
13 namespace MeeGoGarage {
14
15 class Application;
16 class Category;
17
18 class Catalog : public QObject, BaseObject
19 {
20 Q_OBJECT
21 public:
22     enum CatalogSourceType {WebService, RemoteXml, StaticXml};
23
24     class CatalogSetting {
25     public:
26         int id;
27         bool enabled;
28         CatalogSourceType sourceType;
29         QUrl remoteXmlUrl;
30         QUrl repoUrl;
31         QString staticXmlFilePath;
32         QNetworkProxy remoteXmlProxy;
33         QNetworkProxy metadataProxy;
34         QNetworkProxy repoProxy;
35         QDateTime repoTimestamp;
36         QString repoLocalFilePath;
37
38         void dumpCatalogSetting();
39     };
40
41     int id();
42     //Combine catalogs
43     bool add(Catalog*);
44
45     //The list of all categories
46     const QList<Category*> getCategoryList () const;
47     void requestCategoryList();
48     bool isCategoryListReady();
49     const QList<Application*> getApplicationList() const;
50     bool isApplicationListReady();
51
52     //Search in all applications
53     //Search in a specific category or in all catalog
54     void requestSearchApplications (QStringList keywords, MeeGoGarage::SearchType type, MeeGoGarage::SearchMode mode);
55     bool cancelSearchApplications ();
56
57     //Dump functions for debugging
58     void dumpCategoryList();
59     void dumpFullApplicationList();
60     static void dumpApplicationList(QList<Application*> apps);
61     static QString applicationListAsString(QList<Application*> applicationList);
62
63     //Parse the xml file
64     bool loadGarageSource(const QString& xmlFile);
65     bool loadXmlNode (xmlNodePtr node);
66
67     enum xmlNodeType {TYPE_APP, TYPE_CAT, TYPE_RAT, TYPE_USER, TYPE_FEATURE, TYPE_TXN, TYPE_REPO, TYPE_NONE};
68     int getXmlNodeType (xmlNodePtr node);
69
70     QNetworkAccessManager* getNetworkAccessManager();
71
72     friend class GarageClientServices;
73
74 signals:
75
76     void catalogInitialized(bool);
77     void categoryListReady(Catalog*);
78     void categoryListUpdate();
79     void applicationListReady(Catalog*);
80     void applicationListUpdate();
81     void searchApplicationsReady(QStringList, QList<Application*>);
82
83     void newRepoDownloaded(QUrl, QString);
84
85 public slots:
86
87     void catalogXmlFileDownloaded();
88     void xmlDownloadReplyError(QNetworkReply::NetworkError errorCode);
89
90     void categoryListDownloaded();
91     void loadStaticGarageSource();
92
93     void repoFilesDownloaded();
94     void repoDownloadReplyError(QNetworkReply::NetworkError errorCode);
95
96 private:
97
98     friend class Application;
99
100     static const char XML_APP[];
101     static const char XML_RAT[];
102     static const char XML_CAT[];
103     static const char XML_USER[];
104     static const char XML_FEATURE[];
105     static const char XML_TXN[];
106     static const char XML_REPO[];
107
108     Catalog(QObject *parent = 0);
109     Catalog(const CatalogSetting& setting, QObject *parent = 0);
110     QString catalogSource;
111     CatalogSetting catalogSetting;
112
113     QList<Category*> categoryList;
114     bool categoryListIsReady;
115
116     //All applications
117     QList<Application*> applicationList;
118     bool applicationListIsReady;
119
120     QUrl newRepoUrl;
121     QDateTime newRepoTimestamp;
122     void downloadRepoFiles();
123
124     void updateCatalogData();
125     void updateRepoData();
126
127     QNetworkAccessManager* networkAccessManager;
128
129 };
130
131 } //MeeGoGarage namespace
132 #endif // CATALOG_H