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