OSDN Git Service

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