OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / git / gitorious / gitorious.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef GITORIOUS_H
35 #define GITORIOUS_H
36
37 #include <QtCore/QStringList>
38 #include <QtCore/QSharedPointer>
39 #include <QtCore/QUrl>
40 #include <QtCore/QObject>
41
42 QT_BEGIN_NAMESPACE
43 class QNetworkAccessManager;
44 class QNetworkReply;
45 class QDebug;
46 class QUrl;
47 class QSettings;
48 QT_END_NAMESPACE
49
50 namespace Gitorious {
51 namespace Internal {
52
53 struct GitoriousRepository
54 {
55     enum Type {
56         MainLineRepository,
57         CloneRepository,
58         BaselineRepository, // Nokia extension
59         SharedRepository,   // Nokia extension
60         PersonalRepository // Nokia extension
61     };
62
63     GitoriousRepository();
64
65     QString name;
66     QString owner;
67     QUrl pushUrl;
68     QUrl cloneUrl;
69     QString description;
70     Type type;
71     int id;
72 };
73
74 struct GitoriousProject
75 {
76     QString name;
77     QString description;
78     QList<GitoriousRepository> repositories;
79 };
80
81 struct GitoriousCategory
82 {
83     typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
84
85     GitoriousCategory(const QString &name = QString());
86
87     QString name;
88 };
89
90 struct GitoriousHost
91 {
92     enum State { ProjectsQueryRunning, ProjectsComplete, Error };
93     typedef QList<QSharedPointer<GitoriousCategory> > CategoryList;
94     typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
95
96     GitoriousHost(const QString &hostName = QString(), const QString &description = QString());
97     int findCategory(const QString &) const;
98
99     QString hostName;
100     QString description;
101     CategoryList categories;
102     ProjectList projects;
103     State state;
104 };
105
106 QDebug operator<<(QDebug d, const GitoriousRepository &r);
107 QDebug operator<<(QDebug d, const GitoriousProject &p);
108 QDebug operator<<(QDebug d, const GitoriousCategory &p);
109 QDebug operator<<(QDebug d, const GitoriousHost &p);
110
111 /* Singleton that manages a list of gitorious hosts, running network queries
112  * in the background. It models hosts with a flat list of projects (Gitorious
113  * has a concept of categories, but this is not enforced, and there is no
114  * way to query them).
115  * As 24.07.2009, the only supported XML request of the host is a paginated
116  * "list-all-projects".  */
117
118 class Gitorious : public QObject
119 {
120     Q_DISABLE_COPY(Gitorious)
121     Q_OBJECT
122
123 public:
124     static Gitorious &instance();
125
126     const QList<GitoriousHost> &hosts() const { return m_hosts; }
127     int hostCount() const                     { return m_hosts.size(); }
128     int categoryCount(int hostIndex) const    { return m_hosts.at(hostIndex).categories.size(); }
129     int projectCount(int hostIndex) const     { return m_hosts.at(hostIndex).projects.size(); }
130     GitoriousHost::State hostState(int hostIndex) const { return m_hosts.at(hostIndex).state; }
131
132     // If no projects are set, start an asynchronous request querying
133     // the projects/categories  of the host.
134     void addHost(const QString &addr, const QString &description = QString());
135     void addHost(const GitoriousHost &host);
136     void removeAt(int index);
137
138     int findByHostName(const QString &hostName) const;
139     QString hostName(int i) const              { return m_hosts.at(i).hostName; }
140     QString categoryName(int hostIndex, int categoryIndex) const { return m_hosts.at(hostIndex).categories.at(categoryIndex)->name; }
141
142     QString hostDescription(int index) const;
143     void setHostDescription(int index, const QString &s);
144
145     void saveSettings(const QString &group, QSettings *s);
146     void restoreSettings(const QString &group, const QSettings *s);
147
148     // Return predefined entry for "gitorious.org".
149     static GitoriousHost gitoriousOrg();
150
151 signals:
152     void error(const QString &);
153     void projectListReceived(int hostIndex);
154     void projectListPageReceived(int hostIndex, int page);
155     void categoryListReceived(int index);
156     void hostAdded(int index);
157     void hostRemoved(int index);
158
159 public slots:
160     void updateProjectList(int hostIndex);
161     void updateCategories(int index);
162
163 private slots:
164     void slotReplyFinished();
165
166 private:
167     Gitorious();
168     void listProjectsReply(int hostIndex, int page, const QByteArray &data);
169     void listCategoriesReply(int index, QByteArray data);
170     void emitError(const QString &e);
171     QNetworkReply *createRequest(const QUrl &url, int protocol, int hostIndex, int page = -1);
172     void startProjectsRequest(int index, int page = 1);
173
174     QList<GitoriousHost> m_hosts;
175     QNetworkAccessManager *m_networkManager;
176 };
177
178 } // namespace Internal
179 } // namespace Gitorious
180
181 #endif // GITORIOUS_H