1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include <QtCore/QStringList>
38 #include <QtCore/QSharedPointer>
39 #include <QtCore/QUrl>
40 #include <QtCore/QObject>
43 class QNetworkAccessManager;
53 struct GitoriousRepository
58 BaselineRepository, // Nokia extension
59 SharedRepository, // Nokia extension
60 PersonalRepository // Nokia extension
63 GitoriousRepository();
74 struct GitoriousProject
78 QList<GitoriousRepository> repositories;
81 struct GitoriousCategory
83 typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
85 GitoriousCategory(const QString &name = QString());
92 enum State { ProjectsQueryRunning, ProjectsComplete, Error };
93 typedef QList<QSharedPointer<GitoriousCategory> > CategoryList;
94 typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
96 GitoriousHost(const QString &hostName = QString(), const QString &description = QString());
97 int findCategory(const QString &) const;
101 CategoryList categories;
102 ProjectList projects;
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);
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". */
118 class Gitorious : public QObject
120 Q_DISABLE_COPY(Gitorious)
124 static Gitorious &instance();
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; }
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);
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; }
142 QString hostDescription(int index) const;
143 void setHostDescription(int index, const QString &s);
145 void saveSettings(const QString &group, QSettings *s);
146 void restoreSettings(const QString &group, const QSettings *s);
148 // Return predefined entry for "gitorious.org".
149 static GitoriousHost gitoriousOrg();
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);
160 void updateProjectList(int hostIndex);
161 void updateCategories(int index);
164 void slotReplyFinished();
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);
174 QList<GitoriousHost> m_hosts;
175 QNetworkAccessManager *m_networkManager;
178 } // namespace Internal
179 } // namespace Gitorious
181 #endif // GITORIOUS_H