1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2011-03-22
* Description : a MediaWiki C++ interface
*
* SPDX-FileCopyrightText: 2011-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
* SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com>
* SPDX-FileCopyrightText: 2011 by Hormiere Guillaume <hormiere dot guillaume at gmail dot com>
* SPDX-FileCopyrightText: 2011 by Manuel Campomanes <campomanes dot manuel at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget* const parent)
: QMainWindow(parent),
ui (new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
delete mwIface;
}
// Load page
void MainWindow::slot_pushButton2_clicked()
{
mwIface = new Iface(QUrl(this->ui->mWikiEdit->text()));
QueryRevision* const queryrevision(new QueryRevision(*mwIface));
queryrevision->setPageName(this->ui->mPageEdit->text());
queryrevision->setProperties(QueryRevision::Content);
queryrevision->setExpandTemplates(true);
queryrevision->setLimit(1);
connect(queryrevision, SIGNAL(revision(QList<Revision>)),
this, SLOT(revisionHandle(QList<Revision>)));
connect(queryrevision, SIGNAL(result(KJob*)),
this, SLOT(revisionError(KJob*)));
queryrevision->start();
}
void MainWindow::revisionHandle(const QList<Revision>& revisions)
{
if (revisions.isEmpty())
{
QMessageBox popup;
popup.setText(QLatin1String("This page does not exist."));
popup.exec();
return;
}
this->ui->plainTextEdit->setPlainText(revisions[0].content());
}
// Send page
void MainWindow::slot_pushButton1_clicked()
{
Login* const login = new Login(*mwIface, this->ui->mLoginEdit->text(), this->ui->mMdpEdit->text());
connect(login, SIGNAL(result(KJob*)),
this, SLOT(loginHandle(KJob*)));
login->start();
}
void MainWindow::loginHandle(KJob* login)
{
if (login->error()!= 0)
{
QMessageBox popup;
popup.setText(QLatin1String("Wrong authentication."));
popup.exec();
}
else
{
Edit* const job = new Edit(*mwIface, nullptr);
job->setPageName(this->ui->mPageEdit->text());
job->setText(this->ui->plainTextEdit->toPlainText());
connect(job, SIGNAL(result(KJob*)),
this, SLOT(editError(KJob*)));
job->start();
}
}
void MainWindow::editError(KJob* job)
{
QString errorMessage;
if (job->error() == 0)
{
errorMessage = QLatin1String("The Wiki page modified successfully.");
}
else
{
errorMessage = QLatin1String("The Wiki page cannot be modified.");
}
QMessageBox popup;
popup.setText(errorMessage);
popup.exec();
}
void MainWindow::revisionError(KJob* job)
{
if (job->error() != 0)
{
QMessageBox popup;
popup.setText(QLatin1String("The Wiki page cannot be loaded."));
popup.exec();
}
}
void MainWindow::slot_mPageEdit_textChanged(const QString& text)
{
this->ui->pushButton2->setEnabled(!text.isEmpty() && !text.isNull() && !this->ui->mWikiEdit->text().isEmpty());<--- Condition '!text.isNull()' is always true<--- Assuming that condition 'text.isEmpty()' is not redundant
}
void MainWindow::slot_mWikiEdit_textChanged(const QString& text)
{
this->ui->pushButton2->setEnabled(!text.isEmpty() && !text.isNull() && !this->ui->mPageEdit->text().isEmpty());<--- Condition '!text.isNull()' is always true<--- Assuming that condition 'text.isEmpty()' is not redundant
}
void MainWindow::slot_plainTextEdit_textChanged()
{
QString text = this->ui->plainTextEdit->toPlainText();
this->ui->pushButton1->setEnabled(!text.isEmpty() && !text.isNull());<--- Condition '!text.isNull()' is always true<--- Assuming that condition 'text.isEmpty()' is not redundant
}
#include "moc_mainwindow.cpp"
|