Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
uaareport.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 "uaareport.hpp"
12 #include "ui_uaareport.h"
13 
14 using namespace Huggle;
15 
16 UAAReport::UAAReport(QWidget *parent) : QDialog(parent), ui(new Ui::UAAReport)
17 {
18  ui->setupUi(this);
19  this->User = NULL;
20  this->contentsOfUAA = "";
21  this->qUAApage = NULL;
22  this->page = NULL;
23  this->uT = NULL;
24  this->qChUAApage = NULL;
25  this->cuT = NULL;
26  this->dr = "";
27  this->optionalreason = "";
28  this->ta = "";
29  this->uaaReportReason = "";
30 
31 }
32 
33 UAAReport::~UAAReport()
34 {
35  delete ui;
36  delete User;
37  delete uT;
38  delete page;
39 }
40 
42 {
43  this->User = user;
44 }
45 
47 {
48  this->qUAApage = new ApiQuery();
49  qUAApage->SetAction(ActionQuery);
50  qUAApage->Parameters = "prop=revisions&rvprop=content&titles=" + QUrl::toPercentEncoding(Configuration::LocalConfig_UAAPath);
51  /// \todo LOCALIZE THIS
52  qUAApage->Target = "Getting content of UAA";
53  qUAApage->RegisterConsumer("UAAReport::getPageContents()");
55  qUAApage->Process();
56 
57  if (this->uT != NULL)
58  {
59  delete this->uT;
60  }
61  this->uT = new QTimer(this);
62  connect(this->uT, SIGNAL(timeout()), this, SLOT(onTick()));
63  this->uT->start(200);
64 }
65 
67 {
68  if (this->qUAApage == NULL)
69  {
70  return;
71  }
72 
73  if (!this->qUAApage->Processed())
74  {
75  return;
76  }
77  QDomDocument r;
78  r.setContent(this->qUAApage->Result->Data);
79  QDomNodeList l = r.elementsByTagName("rev");
80  if (l.count() == 0)
81  {
82  /// \todo LOCALIZE ME
83  this->failed("the query for the page contents returned no data.");
84  this->qUAApage->UnregisterConsumer("UAAReport::getPageContents()");
85  return;
86  }
87  QDomElement element = l.at(0).toElement();
88 
89  if (element.text() == "")
90  {
91  /// \todo LOCALIZE ME
92  this->failed("the page contents weren't available.");
93  this->qUAApage->UnregisterConsumer("UAAReport::getPageContents()");
94  return;
95  }
96 
97  this->uT->stop();
98  this->dr = element.text();
99  this->qUAApage->UnregisterConsumer("UAAReport::getPageContents()");
100  /// \todo Check if user isn't already reported
101  this->qUAApage = NULL;
102  Core::DebugLog("Contents of UAA: " + this->dr);
103  /// \todo LOCALIZE ME
104  QString uaasum = "Reporting " + this->User->Username + " to UAA " + Configuration::EditSuffixOfHuggle;
105  this->whatToReport();
106  this->insertUsername();
107  Core::EditPage(Core::UAAP, dr, uaasum, true);
108  /// \todo LOCALIZE ME
109  Core::Log("Reporting" + this->User->Username + " to UAA" );
110  this->ui->pushButton->setText("Reported");
111 
112 }
114 {
115  ta = Configuration::LocalConfig_UAATemplate;
116  ta.replace("$1", this->User->Username);
117  ta.replace("$2", uaaReportReason + optionalreason);
118  contentsOfUAA = ta + uaaReportReason + optionalreason;
119  dr = dr + "\n" + contentsOfUAA;
120 }
121 
123 {
124  optionalreason = this->ui->lineEdit->text();
125  if (this->ui->checkBox->isChecked())
126  {
127  uaaReportReason = "Username is a policy violation because it is disruptive.";
128  }
129  if (this->ui->checkBox_2->isChecked())
130  {
131  uaaReportReason = "Username is a policy violation because it is offensive.";
132  }
133  if (this->ui->checkBox_3->isChecked())
134  {
135  uaaReportReason = "Username is a policy violation because it is a promotional username.";
136  }
137  if (this->ui->checkBox_4->isChecked())
138  {
139  uaaReportReason = "Username is a policy violation because it is a misleading username.";
140  }
141 
142 }
143 
144 void UAAReport::failed(QString reason)
145 {
146  QMessageBox *_b = new QMessageBox();
147  _b->setWindowTitle("Unable to report user to UAA");
148  _b->setText("Unable to report the user because " + reason);
149  _b->setAttribute(Qt::WA_DeleteOnClose);
150  _b->exec();
151  this->uT->stop();
152  return;
153 }
154 
156 {
157  if (!this->ui->checkBox->isChecked() && !this->ui->checkBox_2->isChecked() &&
158  !this->ui->checkBox_3->isChecked() && !this->ui->checkBox_4->isChecked()
159  && this->ui->lineEdit->text().isEmpty())
160  {
161  QMessageBox *g = new QMessageBox();
162  /// \todo LOCALIZE ME
163  g->setWindowTitle("No reason specified");
164  /// \todo LOCALIZE ME
165  g->setText("You didn't specify a reason as to why the username is a policy violation. "\
166  "Please specify a reason.");
167  g->setAttribute(Qt::WA_DeleteOnClose);
168  g->exec();
169 
170  return;
171  }
172  ui->pushButton->setEnabled(false);
173  this->getPageContents();
174 }
175 
176 void UAAReport::on_pushButton_2_clicked()
177 {
178  this->hide();
179 }
180 
181 void UAAReport::on_pushButton_3_clicked()
182 {
183  this->qChUAApage = new ApiQuery();
184  qChUAApage->SetAction(ActionQuery);
185  qChUAApage->Parameters = "prop=revisons&rvprop=" + QUrl::toPercentEncoding("timestamp|user|comment|content") + "titles="
186  + QUrl::toPercentEncoding(Configuration::LocalConfig_UAAPath);
187  qChUAApage->RegisterConsumer("UAAReport::checkIfReported()");
189  qChUAApage->Process();
190 
191  this->cuT = new QTimer(this);
192  connect(this->cuT, SIGNAL(timeout()), this, SLOT(onStartOfSearch()));
193  cuT->start(100);
194 }
195 
197 {
198  if (dr.contains(this->User->Username))
199  {
200  return false;
201  }
202  return true;
203 }
204 
205 void UAAReport::onStartOfSearch()
206 {
207  if (qChUAApage == NULL)
208  {
209  return;
210  }
211  if (!qChUAApage->Processed())
212  {
213  return;
214  }
215  QDomDocument tj;
216  tj.setContent(qChUAApage->Result->Data);
217  QDomNodeList chkusr = tj.elementsByTagName("rev");
218  if (chkusr.count() == 0)
219  {
220  QMessageBox *msgb = new QMessageBox();
221  msgb->setWindowTitle("Cannot retrieve page");
222  msgb->setIcon(QMessageBox::Critical);
223  msgb->setText("Retrieving the page " + Configuration::LocalConfig_UAAPath + " failed.");
224  msgb->setAttribute(Qt::WA_DeleteOnClose);
225  msgb->exec();
226  qChUAApage->UnregisterConsumer("UAAReport::on_pushButton_3_clicked()");
227  this->cuT->stop();
228  return;
229  }
230  QDomElement h = chkusr.at(0).toElement();
231  dr = h.text();
232  if (!this->checkIfReported())
233  {
234  QMessageBox *msg = new QMessageBox();
235  msg->setWindowTitle("User is already reported");
236  msg->setText("This user has already been reported to UAA.");
237  msg->setAttribute(Qt::WA_DeleteOnClose);
238  msg->exec();
239  qChUAApage->UnregisterConsumer("UAAReport::on_pushButton_3_clicked()");
240  this->cuT->stop();
241  return;
242  }else
243  {
244  QMessageBox *msga = new QMessageBox();
245  msga->setWindowTitle("User is not reported");
246  msga->setText("This user is not reported to UAA.");
247  msga->setAttribute(Qt::WA_DeleteOnClose);
248  msga->exec();
249  qChUAApage->UnregisterConsumer("UAAReport::on_pushButton_3_clicked()");
250  this->cuT->stop();
251  return;
252  }
253 }
QString dr
Whole contents of UAA page.
Definition: uaareport.hpp:55
bool checkIfReported()
Check if user is reported.
Definition: uaareport.cpp:196
static void Log(QString Message)
Write text to terminal as well as ring log.
Definition: core.cpp:563
QTimer * uT
Timer pointer that allows us to do magical things.
Definition: uaareport.hpp:67
QString Target
This is optional property which contains a label of target this query is for.
Definition: apiquery.hpp:98
static WikiPage * UAAP
Pointer to UAA page.
Definition: core.hpp:135
void setUserForUAA(WikiUser *user)
I don't have much of a clue why this is here lol, but I know the dialog can't be initialised from mai...
Definition: uaareport.cpp:41
virtual bool Processed()
Returns true in case that query is processed.
Definition: query.cpp:45
void UnregisterConsumer(const int consumer)
This function will remove a string which prevent the object from being removed.
Definition: collectable.cpp:68
void RegisterConsumer(const int consumer)
Registers a consumer.
Definition: collectable.cpp:57
static void AppendQuery(Query *item)
Insert a query to internal list of running queries, so that they can be watched This will insert it t...
Definition: core.cpp:557
void failed(QString reason)
Message box, if anything fails.
Definition: uaareport.cpp:144
QString Username
Username.
Definition: wikiuser.hpp:52
void Process()
Run.
Definition: apiquery.cpp:138
void on_pushButton_clicked()
Definition: uaareport.cpp:155
QString optionalreason
String that represents what is in the line edit.
Definition: uaareport.hpp:57
ApiQuery * qUAApage
Pointer to get UAA contents (we don't want replace the page with our content, do we?)
Definition: uaareport.hpp:65
void whatToReport()
Function to decide what we are reporting.
Definition: uaareport.cpp:122
QString uaaReportReason
Reason for report.
Definition: uaareport.hpp:61
void SetAction(const Action action)
Change the action type.
Definition: apiquery.cpp:185
void getPageContents()
Get page contents (reason for this is above)
Definition: uaareport.cpp:46
ApiQuery * qChUAApage
Pointer that also gets UAA contents; this time it is used for checking if a user is reported or not...
Definition: uaareport.hpp:71
QString ta
UAA template.
Definition: uaareport.hpp:59
static QString EditSuffixOfHuggle
Suffix used by huggle.
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
Definition: core.cpp:641
QString Parameters
Parameters for action, for example page title.
Definition: apiquery.hpp:84
Form to report users to UAA.
Definition: uaareport.hpp:36
WikiPage * page
Pointer to WikiUser.
Definition: uaareport.hpp:63
This class can be used to execute any kind of api query on any wiki.
Definition: apiquery.hpp:55
QTimer * cuT
Timer that does other magical things.
Definition: uaareport.hpp:69
void insertUsername()
Function to that allows us to properly insert what we need to insert.
Definition: uaareport.cpp:113
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