1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include <QtCore/QStringList>
37 #include <QtCore/QSharedPointer>
38 #include <QtCore/QUrl>
39 #include <QtCore/QObject>
42 class QNetworkAccessManager;
52 struct GitoriousRepository
57 BaselineRepository, // Nokia extension
58 SharedRepository, // Nokia extension
59 PersonalRepository // Nokia extension
62 GitoriousRepository();
73 struct GitoriousProject
77 QList<GitoriousRepository> repositories;
80 struct GitoriousCategory
82 typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
84 GitoriousCategory(const QString &name = QString());
91 enum State { ProjectsQueryRunning, ProjectsComplete, Error };
92 typedef QList<QSharedPointer<GitoriousCategory> > CategoryList;
93 typedef QList<QSharedPointer<GitoriousProject > > ProjectList;
95 GitoriousHost(const QString &hostName = QString(), const QString &description = QString());
96 int findCategory(const QString &) const;
100 CategoryList categories;
101 ProjectList projects;
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);
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". */
117 class Gitorious : public QObject
119 Q_DISABLE_COPY(Gitorious)
123 static Gitorious &instance();
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; }
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);
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; }
141 QString hostDescription(int index) const;
142 void setHostDescription(int index, const QString &s);
144 void saveSettings(const QString &group, QSettings *s);
145 void restoreSettings(const QString &group, const QSettings *s);
147 // Return predefined entry for "gitorious.org".
148 static GitoriousHost gitoriousOrg();
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);
159 void updateProjectList(int hostIndex);
160 void updateCategories(int index);
163 void slotReplyFinished();
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);
173 QList<GitoriousHost> m_hosts;
174 QNetworkAccessManager *m_networkManager;
177 } // namespace Internal
178 } // namespace Gitorious
180 #endif // GITORIOUS_H