Initial checkin
[opensuse:qtobs.git] / obsaccess.h
1 /*
2  *  Qt OBS - A Qt based OBS client
3  *
4  *  Copyright (C) 2010 Novell Inc, Klaas Freitag <freitag@suse.de>
5  *
6  *  This program is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 2 of the License, or
9  *  (at your option) version 3.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  --
20  *  Written by Klaas Freitag <freitag@suse.de>
21  *  Contributors:
22  */
23
24 #ifndef OBSACCESS_H
25 #define OBSACCESS_H
26
27 #include <QObject>
28 #include <QNetworkAccessManager>
29 #include <QUrl>
30 #include <QNetworkReply>
31 #include <QSslError>
32 #include <QDomDocument>
33
34 #include "obsxmlreader.h"
35
36 class QNetworkReply;
37
38
39 class OBSAccess : public QObject
40 {
41   Q_OBJECT
42 public:
43   // OBSAccess();
44   OBSAccess( const QUrl& url = QUrl("https://api.opensuse.org") );
45   void getPath( const QString& );
46   void setCredentials( const QString&, const QString& );
47   void setXmlReadHandler( OBSXmlReader* );
48   QXmlStreamReader* xmlReadHandler();
49
50 signals:
51   void replyContent( const QString& );
52   void parsingOk();
53   void parsingFailed();
54
55 protected slots:
56   void authenticate( QNetworkReply* , QAuthenticator* );
57   void replyFinished(QNetworkReply*);
58   void slotNetworkError( QNetworkReply::NetworkError );
59   void slotReadyRead();
60   void slotSSLErrors( QList<QSslError> );
61   void slotProxyAuthenticate( const QNetworkProxy&, QAuthenticator* );
62   void slotReplyFinished();
63
64 private:
65   QUrl redirectUrl(const QUrl&, const QUrl&) const;
66
67   QNetworkAccessManager *mManager;
68
69   QUrl mOBSBase;
70   QUrl mUrlRedirectedTo;
71   QString mOBSUser;
72   QString mOBSPasswd;
73
74   QNetworkReply *mReply;
75   OBSXmlReader *mXmlStreamReader;
76 };
77
78 #endif // OBSACCESS_H