Changeset 2 for libQtGdata/trunk/qtgdata.cpp
- Timestamp:
- 02/03/10 22:06:42 (2 years ago)
- File:
-
- 1 edited
-
libQtGdata/trunk/qtgdata.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libQtGdata/trunk/qtgdata.cpp
r1 r2 4 4 #include <QStringList> 5 5 6 #include <QNetworkAccessManager> 6 //#include <QNetworkAccessManager> 7 #include "helper/syncnetworkaccessmanager.h" 7 8 #include <QNetworkReply> 8 9 9 10 #include <QDebug> 10 11 11 QtGdata::QtGdata(const QString email, const QString password, 12 const QString appString, 13 const GDATA_ACCOUNT_TYPE type = GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE) 12 /** 13 * Constructor 14 * 15 * @param email E-mail (account name) 16 * @param password Password for this account 17 * @param service String decribing the service to connect to 18 * @param accountType How to connect to google 19 * 20 */ 21 QtGdata::QtGdata(const QString email, 22 const QString password, 23 const QString service, 24 const QString loginURL, 25 const GDATA_ACCOUNT_TYPE accountType) 14 26 { 15 QNetworkAccessManager *manager = new QNetworkAccessManager(); 27 login(email, password, service, loginURL, accountType); 28 } 29 30 /** 31 * @param email E-mail (account name) 32 * @param password Password for this account 33 * @param service String describing the server you want to connect to 34 * @param accountType How to connect 35 * @param loginToken The captcha token 36 * @param loginCaptcha The text in the captcha (according to the user) 37 */ 38 void QtGdata::login(const QString email, 39 const QString password, 40 const QString service, 41 const QString loginURL, 42 const GDATA_ACCOUNT_TYPE accountType, 43 const QString loginToken, 44 const QString loginCaptcha) 45 { 46 this->email = email; 47 this->password = password; 48 49 SyncNetworkAccessManager manager; 16 50 QNetworkRequest request; 17 request.setUrl(QUrl( "https://www.google.com/accounts/ClientLogin"));51 request.setUrl(QUrl(loginURL)); 18 52 request.setRawHeader("User-Agent", "QtGdata 0.0.1"); 19 53 request.setRawHeader("Content-type", "application/x-www-form-urlencoded"); … … 22 56 QString data = ""; 23 57 24 switch(type) { 58 /* Request the right access */ 59 switch(accountType) { 25 60 case QtGdata::GDATA_ACCOUNT_TYPE_GOOGLE: 26 61 data = "accountType=GOOGLE"; … … 36 71 data += "&Email=" + email; 37 72 data += "&Passwd=" + password; 38 data += "&service=" + appString;73 data += "&service=" + service; 39 74 data += "&source=QtGdata-0.0.1"; 40 75 41 connect(manager, SIGNAL(finished(QNetworkReply*)), 42 this, SLOT(finished(QNetworkReply*))); 76 /* Check for captcha stuff */ 77 if (!loginToken.isNull() && !loginCaptcha.isNull()) { 78 data += "&logintoken=" + loginToken; 79 data += "&logincaptcha=" + loginCaptcha; 80 } 43 81 44 manager->post(request, data.toAscii()); 45 } 46 47 48 void QtGdata::finished(QNetworkReply *reply) 49 { 82 /* Get response */ 83 QNetworkReply *reply = manager.syncPost(request, data.toAscii()); 50 84 int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); 51 85 … … 64 98 } 65 99 } 66 emit loginSucces();100 this->valid = 0; 67 101 break; 68 102 case 403: … … 70 104 break; 71 105 default: 72 qDebug() << reply->readAll();73 106 break; 74 107 } 108 75 109 } 110 111 bool QtGdata::isValid() 112 { 113 return valid; 114 } 115 116 QByteArray QtGdata::getFeed(const QString url) 117 { 118 QNetworkRequest request; 119 request.setUrl(QUrl(url)); 120 request.setRawHeader("User-Agent", "QtGdata 0.0.1"); 121 request.setRawHeader("GData-Version", "2"); 122 123 QString authHeader = "GoogleLogin auth=" + Auth; 124 request.setRawHeader("Authorization", authHeader.toAscii()); 125 126 SyncNetworkAccessManager manager; 127 QNetworkReply * reply = manager.syncGet(request); 128 129 return reply->readAll(); 130 }
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)