File indexing completed on 2024-04-28 16:01:21
0001 /** =========================================================== 0002 * @file 0003 * 0004 * This file is a part of KDE project 0005 * <a href="https://commits.kde.org/libmediawiki">libmediawiki</a> 0006 * 0007 * @date 2011-03-22 0008 * @brief a MediaWiki C++ interface for KDE 0009 * 0010 * @author Copyright (C) 2011 by Gilles Caulier 0011 * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> 0012 * @author Copyright (C) 2010 by Alexandre Mendes 0013 * <a href="mailto:alex dot mendes1988 at gmail dot com">alex dot mendes1988 at gmail dot com</a> 0014 * 0015 * This program is free software; you can redistribute it 0016 * and/or modify it under the terms of the GNU General 0017 * Public License as published by the Free Software Foundation; 0018 * either version 2, or (at your option) 0019 * any later version. 0020 * 0021 * This program is distributed in the hope that it will be useful, 0022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0024 * GNU General Public License for more details. 0025 * 0026 * ============================================================ */ 0027 0028 #include "mainwindow.h" 0029 #include "ui_mainwindow.h" 0030 0031 #include <QFile> 0032 #include <QFileDialog> 0033 0034 MainWindow::MainWindow(QWidget *parent) 0035 : QMainWindow(parent), 0036 ui(new Ui::MainWindow), 0037 mediawiki(QUrl("https://test.wikipedia.org/w/api.php")) 0038 { 0039 ui->setupUi(this); 0040 init(); 0041 } 0042 0043 MainWindow::~MainWindow() 0044 { 0045 delete ui; 0046 } 0047 0048 void MainWindow::init() 0049 { 0050 this->ui->comboBox->addItem(QString("Own work, multi-license with CC-BY-SA-3.0 and GFDL"),QString("{{self|cc-by-sa-3.0|GFDL|migration=redundant}}")); 0051 this->ui->comboBox->addItem(QString("Own work, multi-license with CC-BY-SA-3.0 and older"),QString("{{self|cc-by-sa-3.0,2.5,2.0,1.0}}")); 0052 this->ui->comboBox->addItem(QString("Creative Commons Attribution-Share Alike 3.0"),QString("{{self|cc-by-sa-3.0}}")); 0053 this->ui->comboBox->addItem(QString("Own work, Creative Commons Attribution 3.0"),QString("{{self|cc-by-3.0}}")); 0054 this->ui->comboBox->addItem(QString("Own work, release into public domain under the CC-Zero license"),QString("{{self|cc-zero}}")); 0055 this->ui->comboBox->addItem(QString("Author died more than 100 years ago"),QString("{{PD-old}}")); 0056 this->ui->comboBox->addItem(QString("Photo of a two-dimensional work whose author died more than 100 years ago"),QString("{{PD-art}}")); 0057 this->ui->comboBox->addItem(QString("First published in the United States before 1923"),QString("{{PD-US}}")); 0058 this->ui->comboBox->addItem(QString("Work of a U.S. government agency"),QString("{{PD-USGov}}")); 0059 this->ui->comboBox->addItem(QString("Simple typefaces, individual words or geometric shapes"),QString("{{PD-text}}")); 0060 this->ui->comboBox->addItem(QString("Logos with only simple typefaces, individual words or geometric shapes"),QString("{{PD-textlogo}}")); 0061 } 0062 0063 void MainWindow::on_pushButton_clicked() 0064 { 0065 this->ui->progressBar->setValue(0); 0066 Login* login = new Login(mediawiki, this->ui->mLoginEdit->text(), this->ui->mMdpEdit->text()); 0067 connect(login, SIGNAL(result(KJob*)), 0068 this, SLOT(loginHandle(KJob*))); 0069 login->start(); 0070 } 0071 0072 void MainWindow::loginHandle(KJob* login) 0073 { 0074 if(login->error() != 0) 0075 { 0076 QMessageBox popup; 0077 popup.setText("Wrong authentication."); 0078 popup.exec(); 0079 } 0080 else 0081 { 0082 Upload* e1 = new Upload( mediawiki ); 0083 QFile* file = new QFile(this->ui->lineEdit->text()); 0084 file->open(QIODevice::ReadOnly); 0085 e1->setFile(file); 0086 e1->setFilename(this->ui->lineEdit_2->text()); 0087 0088 QString text("== {{int:filedesc}} == \n{{Information |Description="); 0089 text.append(this->ui->descriptionEdit->text()); 0090 text.append("\n|Source=").append(this->ui->sourceEdit->text()); 0091 text.append("\n|Date=").append(this->ui->dateEdit->text()); 0092 text.append("\n|Author=").append(this->ui->authorEdit->text()); 0093 text.append("\n|Permission=").append(this->ui->permissionEdit->text()); 0094 text.append("\n|other_versions=").append(this->ui->versionsEdit->text()); 0095 text.append("\n}}\n== {{int:license}} ==\n"); 0096 text.append(this->ui->comboBox->itemData(this->ui->comboBox->currentIndex()).toString()); 0097 0098 e1->setText(text); 0099 connect(e1, SIGNAL(result(KJob*)), 0100 this, SLOT(uploadHandle(KJob*))); 0101 0102 connect(e1,SIGNAL(processedSize(KJob*,qulonglong)), 0103 this, SLOT(processedUploadSize(KJob*,qulonglong))); 0104 0105 connect(e1,SIGNAL(totalSize(KJob*,qulonglong)), 0106 this,SLOT(TotalUploadSize(KJob*,qulonglong))); 0107 e1->start(); 0108 } 0109 } 0110 0111 void MainWindow::uploadHandle(KJob* job) 0112 { 0113 disconnect(this, SIGNAL(result(KJob*)), 0114 this, SLOT(uploadHandle(KJob*))); 0115 0116 disconnect(this, SIGNAL(processedSize(KJob*,qulonglong)), 0117 this, SLOT(processedUploadSize(KJob*,qulonglong))); 0118 0119 disconnect(this, SIGNAL(totalSize(KJob*,qulonglong)), 0120 this, SLOT(TotalUploadSize(KJob*,qulonglong))); 0121 0122 QString errorMessage; 0123 if(job->error() == 0) errorMessage = "Image uploaded successfully."; 0124 else errorMessage = "Image upload failed."; 0125 QMessageBox popup; 0126 popup.setText(errorMessage); 0127 popup.exec(); 0128 } 0129 0130 void MainWindow::processedUploadSize(KJob* job, qulonglong size) 0131 { 0132 Q_UNUSED(job) 0133 this->ui->progressBar->setValue(size); 0134 } 0135 0136 void MainWindow::TotalUploadSize(KJob* job, qulonglong size) 0137 { 0138 Q_UNUSED(job) 0139 this->ui->progressBar->setMaximum(size); 0140 } 0141 0142 void MainWindow::on_parcourir_clicked() 0143 { 0144 QString fileName = QFileDialog::getOpenFileName(this, QLatin1String("Open Image"), "~", QLatin1String("Image Files (*.png *.jpg *.bmp *.jpeg *.gif)")); 0145 if(fileName != nullptr) 0146 { 0147 QPixmap preview(fileName); 0148 QSize size(preview.size()); 0149 size.scale(400,200,Qt::KeepAspectRatio); 0150 preview = preview.scaled(size, Qt::KeepAspectRatio,Qt::FastTransformation); 0151 0152 this->ui->previewLabel->setPixmap(preview); 0153 this->ui->lineEdit->setText(fileName); 0154 } 0155 } 0156 0157 void MainWindow::on_lineEdit_textChanged(QString text) 0158 { 0159 this->ui->pushButton->setEnabled(!text.isEmpty() && !text.isNull()); 0160 }