Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
vandalnw.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 "vandalnw.hpp"
12 #include "ui_vandalnw.h"
13 
14 using namespace Huggle;
15 
16 VandalNw::VandalNw(QWidget *parent) : QDockWidget(parent), ui(new Ui::VandalNw)
17 {
18  this->Irc = new IRC::NetworkIrc(Configuration::VandalNw_Server, Configuration::UserName);
19  this->ui->setupUi(this);
20  this->pref = QString(QChar(001)) + QString(QChar(001));
21  this->tm = new QTimer(this);
22  this->JoinedMain = false;
23  connect(tm, SIGNAL(timeout()), this, SLOT(onTick()));
24  this->tm->start(200);
25  this->Irc->UserName = Configuration::HuggleVersion;
26 }
27 
28 VandalNw::~VandalNw()
29 {
30  delete this->ui;
31  delete this->tm;
32  delete this->Irc;
33 }
34 
36 {
37  if (!Configuration::VandalNw_Login)
38  {
39  /// \todo LOCALIZE ME
40  Core::Log("Vandalism network isn't allowed in options");
41  return;
42  } else
43  {
44  /// \todo LOCALIZE ME
45  this->Insert("Connecting to huggle anti vandalism network");
46  this->Irc->Connect();
47  }
48 }
49 
51 {
52  this->Irc->Disconnect();
53  /// \todo LOCALIZE ME
54  this->Insert("You are disconnected from HAN");
55 }
56 
58 {
59  this->Irc->Send(this->GetChannel(), this->pref + "GOOD " + QString::number(Edit->RevID));
60 }
61 
63 {
64  this->Irc->Send(this->GetChannel(), this->pref + "ROLLBACK " + QString::number(Edit->RevID));
65 }
66 
67 void VandalNw::SuspiciousWikiEdit(WikiEdit *Edit)
68 {
69  this->Irc->Send(this->GetChannel(), this->pref + "SUSPICIOUS " + QString::number(Edit->RevID));
70 }
71 
72 void VandalNw::WarningSent(WikiUser *user, int Level)
73 {
74  this->Irc->Send(this->GetChannel(), this->pref + "WARN " + QString::number(Level) + " " + QUrl::toPercentEncoding(user->Username));
75 }
76 
77 QString VandalNw::GetChannel()
78 {
79  return Configuration::Project.IRCChannel + ".huggle";
80 }
81 
83 {
84  if (!this->Irc->IsConnected())
85  {
86  /// \todo LOCALIZE ME
87  this->Insert("Lost connection to antivandalism network");
88  this->tm->stop();
89  return;
90  }
91  if (!this->JoinedMain && this->Irc->IsConnected())
92  {
93  this->JoinedMain = true;
94  /// \todo LOCALIZE ME
95  this->Insert("You are now connected to huggle antivandalism network");
96  this->Irc->Join(this->GetChannel());
97  }
98  Huggle::IRC::Message *m = this->Irc->GetMessage();
99  if (m != NULL)
100  {
101  if (m->Text.startsWith(pref))
102  {
103  QString Command = m->Text.mid(2);
104  if (m->Text.contains(" "))
105  {
106  Command = Command.mid(0, Command.indexOf(" "));
107  QString revid = m->Text.mid(m->Text.indexOf(" ") + 1);
108  if (Command == "GOOD")
109  {
110  int RevID = revid.toInt();
111  Core::Main->Queue1->DeleteByRevID(RevID);
112  this->Insert(m->user.Nick + " seen a good edit " + revid);
113  }
114  if (Command == "ROLLBACK")
115  {
116  int RevID = revid.toInt();
117  Core::Main->Queue1->DeleteByRevID(RevID);
118  this->Insert(m->user.Nick + " did a rollback of " + revid);
119  }
120  if (Command == "SUSPICIOUS")
121  {
122  /// \todo find and change the score of that edit, update queue and sort it.
123  this->Insert(m->user.Nick + " thinks that edit " + revid + " is likely a vandalism, but they didn't revert it");
124  }
125  }
126 
127  } else
128  {
129  this->Insert(m->user.Nick + ": " + m->Text);
130  }
131  delete m;
132  }
133 }
134 
135 void VandalNw::Insert(QString text)
136 {
137  QString t = ui->textEdit->toPlainText();
138  t.prepend(text + "\n");
139 
140  ui->textEdit->setPlainText(t);
141 }
142 
143 void Huggle::VandalNw::on_pushButton_clicked()
144 {
145  if (this->Irc->IsConnected())
146  {
147  this->Irc->Send(this->GetChannel(), this->ui->lineEdit->text());
148  this->Insert(Configuration::UserName + ": " + ui->lineEdit->text());
149  }
150  ui->lineEdit->setText("");
151 }
static QString HuggleVersion
Version.
static void Log(QString Message)
Write text to terminal as well as ring log.
Definition: core.cpp:563
static QString UserName
User name.
int RevID
Revision ID.
Definition: wikiedit.hpp:105
Represent a message on irc network sent either to a channel or to a user.
Definition: networkirc.hpp:53
void Rollback(WikiEdit *Edit)
Notify others about a rollback of edit.
Definition: vandalnw.cpp:62
void Good(WikiEdit *Edit)
This will deliver an edit to others as a good edit.
Definition: vandalnw.cpp:57
bool IsConnected()
IsConnected checks for connection.
Definition: networkirc.cpp:55
The NetworkIrc provides connection to IRC servers.
Definition: networkirc.hpp:94
QString Username
Username.
Definition: wikiuser.hpp:52
QString IRCChannel
IRC channel of this site, if it doesn't have a channel leave it empty.
Definition: wikisite.hpp:33
void Disconnect()
Definition: vandalnw.cpp:50
HuggleQueue * Queue1
Pointer to queue.
Definition: mainwindow.hpp:120
static WikiSite Project
currently selected project
VandalNw(QWidget *parent=0)
Definition: vandalnw.cpp:16
Wiki edit.
Definition: wikiedit.hpp:67
void Connect()
Connect to server.
Definition: networkirc.cpp:38
Vandalism network.
Definition: vandalnw.hpp:32
static MainWindow * Main
Pointer to main.
Definition: core.hpp:111
void Insert(QString text)
Insert text to window.
Definition: vandalnw.cpp:135