Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
wlquery.cpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #include "wlquery.hpp"
12 using namespace Huggle;
13 
14 WLQuery::WLQuery()
15 {
16  this->Result = NULL;
17  Save = false;
18 }
19 
20 WLQuery::~WLQuery()
21 {
22  delete Result;
23  this->Result = NULL;
24 }
25 
27 {
28  this->StartTime = QDateTime::currentDateTime();
29  this->Status = StatusProcessing;
30  this->Result = new QueryResult();
31  QUrl url("http://huggle.wmflabs.org/data/wl.php?action=read&wp=" + Configuration::Project.WhiteList);
32  QString params = "";
33  if (Save)
34  {
35  url = QUrl("http://huggle.wmflabs.org/data/wl.php?action=save&wp=" + Configuration::Project.WhiteList);
36  QString whitelist = "";
37  int p = 0;
39  while (p < Configuration::WhiteList.count())
40  {
41  if (Configuration::WhiteList.at(p) != "")
42  {
43  whitelist += Configuration::WhiteList.at(p) + "|";
44  }
45  p++;
46  }
47  if (whitelist.endsWith("|"))
48  {
49  whitelist = whitelist.mid(0, whitelist.length() - 1);
50  }
51  whitelist += "||EOW||";
52  params = "wl=" + QUrl::toPercentEncoding(whitelist);
53  }
54  QNetworkRequest request(url);
55  if (!Save)
56  {
57  this->r = Query::NetworkManager.get(request);
58  } else
59  {
60  request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
61  this->r = Query::NetworkManager.post(request, params.toUtf8());
62  }
63  QObject::connect(this->r, SIGNAL(finished()), this, SLOT(Finished()));
64  QObject::connect(this->r, SIGNAL(readyRead()), this, SLOT(ReadData()));
65 }
66 
67 void WLQuery::ReadData()
68 {
69  this->Result->Data += QString(this->r->readAll());
70 }
71 
72 void WLQuery::Finished()
73 {
74  this->Result->Data += QString(this->r->readAll());
75  // now we need to check if request was successful or not
76  if (this->r->error())
77  {
78  this->Result->ErrorMessage = r->errorString();
79  this->Result->Failed = true;
80  this->r->deleteLater();
81  this->r = NULL;
82  return;
83  }
84  this->r->deleteLater();
85  this->r = NULL;
86  this->Status = StatusDone;
87 }
void Process()
Execute query.
Definition: wlquery.cpp:26
Result of query.
Definition: queryresult.hpp:19
static QStringList WhiteList
Data of wl.
static WikiSite Project
currently selected project
QString ErrorMessage
If query is in error the reason for error is stored here.
Definition: queryresult.hpp:27
QString Data
Data retrieved by query.
Definition: queryresult.hpp:25
QueryResult * Result
Result of query, see documentation of QueryResult for more.
Definition: query.hpp:68