From 01344d41b3abb7bc486aa69a67dfc78abf36fe80 Mon Sep 17 00:00:00 2001 From: DOOMer Date: Fri, 27 Jul 2012 10:03:43 +0400 Subject: [PATCH] Remaked uploader module (base functions) Add ability to upload to imgur.com (issue #4) --- src/core/core.cpp | 8 +- src/modules/uploader/CMakeLists.txt | 15 +- src/modules/uploader/dialoguploader.cpp | 200 ++++++ .../{uploaderdialog.h => dialoguploader.h} | 59 +- src/modules/uploader/dialoguploader.ui | 263 +++++++ .../uploader/imgshack/uploader_imgshack.cpp | 180 +++++ .../uploader/imgshack/uploader_imgshack.h | 28 + src/modules/uploader/imgur/uploader_imgur.cpp | 90 +++ src/modules/uploader/imgur/uploader_imgur.h | 38 ++ src/modules/uploader/moduleuploader.cpp | 33 + src/modules/uploader/moduleuploader.h | 32 + src/modules/uploader/uploader.cpp | 354 ++++------ src/modules/uploader/uploader.h | 71 +- src/modules/uploader/uploaderconfig.cpp | 72 +- src/modules/uploader/uploaderconfig.h | 14 +- src/modules/uploader/uploaderdialog.cpp | 281 -------- src/modules/uploader/uploaderdialog.ui | 639 ------------------ 17 files changed, 1095 insertions(+), 1282 deletions(-) create mode 100644 src/modules/uploader/dialoguploader.cpp rename src/modules/uploader/{uploaderdialog.h => dialoguploader.h} (65%) create mode 100644 src/modules/uploader/dialoguploader.ui create mode 100644 src/modules/uploader/imgshack/uploader_imgshack.cpp create mode 100644 src/modules/uploader/imgshack/uploader_imgshack.h create mode 100644 src/modules/uploader/imgur/uploader_imgur.cpp create mode 100644 src/modules/uploader/imgur/uploader_imgur.h create mode 100644 src/modules/uploader/moduleuploader.cpp create mode 100644 src/modules/uploader/moduleuploader.h delete mode 100644 src/modules/uploader/uploaderdialog.cpp delete mode 100644 src/modules/uploader/uploaderdialog.ui diff --git a/src/core/core.cpp b/src/core/core.cpp index be7665d..4e8aa1e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -23,7 +23,7 @@ #include #include -#include "src/modules/uploader/uploader.h" +#include "src/modules/uploader/moduleuploader.h" #include #include #include @@ -453,8 +453,10 @@ void Core::autoSave() void Core::upload() { - Uploader *upl = new Uploader; - Q_UNUSED(upl) + // Uploader *upl = new Uploader; + // Q_UNUSED(upl) + ModuleUploader uploader; + uploader.init(); } diff --git a/src/modules/uploader/CMakeLists.txt b/src/modules/uploader/CMakeLists.txt index d27e40b..6c06c79 100644 --- a/src/modules/uploader/CMakeLists.txt +++ b/src/modules/uploader/CMakeLists.txt @@ -6,17 +6,24 @@ include_directories(${SG_INCLUDE}) message(STATUS "SG_CORE_INCLUDE-2: " ${SG_INCLUDE}) -set (uploader_SRC uploader.cpp - uploaderdialog.cpp +set (uploader_SRC + moduleuploader.cpp + uploader.cpp + imgshack/uploader_imgshack.cpp + imgur/uploader_imgur.cpp uploaderconfig.cpp + dialoguploader.cpp ) set (uploader_HDR uploader.h - uploaderdialog.h + imgshack/uploader_imgshack.h + + imgur/uploader_imgur.h + dialoguploader.h ) -set(uploader_UI uploaderdialog.ui) +set(uploader_UI dialoguploader.ui) qt4_wrap_cpp(uploader_SRC_MOC ${uploader_HDR}) diff --git a/src/modules/uploader/dialoguploader.cpp b/src/modules/uploader/dialoguploader.cpp new file mode 100644 index 0000000..191c9da --- /dev/null +++ b/src/modules/uploader/dialoguploader.cpp @@ -0,0 +1,200 @@ +/*************************************************************************** + * Copyright (C) 2009 - 2012 by Artem 'DOOMer' Galichkin * + * doomer3d@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "dialoguploader.h" +#include "ui_dialoguploader.h" + +#include "imgshack/uploader_imgshack.h" +#include "imgur/uploader_imgur.h" +#include + +#include + +#include + +DialogUploader::DialogUploader(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogUploader) +{ + ui->setupUi(this); + ui->stackedWidget->setCurrentIndex(0); + uploader = 0; + + ui->cbxUploaderList->addItems(UplConf.labelsList()); + selectedHost = 0; + + // load ishot preview + QSize imgSize = Core::instance()->getPixmap().size(); + QString pixmapSize = tr("Size: ") + QString::number(imgSize.width()) + "x" + QString::number(imgSize.height()) + tr(" pixel"); + ui->labImgSize->setText(pixmapSize); + + ui->labImage->setFixedWidth(256); + ui->labImage->setFixedHeight(192); + ui->labImage->setPixmap(Core::instance()->getPixmap().scaled(ui->labImage->sizeHint())); + + // progressbar + ui->progressBar->setVisible(false); + ui->progressBar->setFormat(tr("Uploaded ") + "%p%" + " (" + "%v" + " of " + "%m bytes"); + + // upload staus labelsList + ui->labUploadStatus->setText(tr("Ready to upload")); + + connect(ui->butClose, SIGNAL(clicked(bool)), this, SLOT(close())); + connect(ui->butUpload, SIGNAL(clicked(bool)), this, SLOT(slotUploadStart())); + connect(ui->cbxUploaderList, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSeletHost(int))); +} + +DialogUploader::~DialogUploader() +{ + qDebug() << "delete dialog upload"; + + if (uploader != 0) + { + delete uploader; + } + + delete ui; +} + +void DialogUploader::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +void DialogUploader::slotUploadStart() +{ + qDebug() << "Upload slot call"; + ui->progressBar->setVisible(true); + ui->butUpload->setEnabled(false); + ui->labUploadStatus->setText(tr("Upload preocessing... Please wait")); + + switch(selectedHost) + { + case 0: + uploader = new Uploader_ImgUr; + break; + case 1: + uploader = new Uploader_ImgShack; + break; + default: + uploader = new Uploader_ImgShack; + } + + // start uploading process + connect(uploader, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64))); + uploader->startUploading(); + connect(uploader, SIGNAL(uploadDone()) , this, SLOT(slotUploadDone())); + connect(uploader, SIGNAL(uploadFail(QByteArray)), this, SLOT(slotUploadFail(QByteArray))); + connect(ui->cbxExtCode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeExtCode(int))); + connect(ui->butCopyLink, SIGNAL(clicked(bool)), this, SLOT(slotCopyLink())); + connect(ui->butCopyExtCode, SIGNAL(clicked(bool)), this, SLOT(slotCopyLink())); +} + +void DialogUploader::slotSeletHost(int type) +{ + selectedHost = type; +} + +void DialogUploader::slotUploadProgress(qint64 bytesSent, qint64 bytesTotal) +{ + qDebug() << "-- progress update" << bytesSent; + ui->progressBar->setMaximum(bytesTotal); + ui->progressBar->setValue(bytesSent); + + if (bytesSent == bytesTotal) + { + qDebug() << "all is send!!!!"; + ui->progressBar->setFormat(tr("Receiving a response from the server")); + } +} + +void DialogUploader::slotUploadDone() +{ + QMap links = uploader->parsedLinks(); + + QMap::const_iterator iter; + for (iter = links.constBegin(); iter != links.constEnd(); ++iter) + { + if (iter.key() == "direct_link") + { + ui->editDirectLink->setText(iter.value().first); + } + else + { + ui->cbxExtCode->addItem(iter.value().second); + } + } + + ui->stackedWidget->setCurrentIndex(1); + ui->labUploadStatus->setText(tr("Upload completed")); + ui->progressBar->setVisible(false); + ui->cbxUploaderList->setEnabled(false); + qDebug() << "upload is done"; +} + +void DialogUploader::slotUploadFail(const QByteArray& error) +{ + qDebug() << "upload failure"; + QMessageBox msg(this); + msg.setText(tr("Error uploading screenshot")); + msg.setWindowTitle(tr("Error")); + msg.setIcon(QMessageBox::Critical); + msg.exec(); + ui->stackedWidget->setCurrentIndex(0); + ui->progressBar->setVisible(false); + ui->labUploadStatus->setText(tr("Ready to upload")); + ui->butUpload->setEnabled(true ); +} + +void DialogUploader::slotChangeExtCode(int code) +{ + QMap links = uploader->parsedLinks(); + links.remove("direct_link"); + QList keys = links.keys(); + QByteArray selKey = keys.at(code); + ui->editExtCode->setText(links[selKey].first); +} + +void DialogUploader::slotCopyLink() +{ + QString objName = sender()->objectName(); + QString copyText; + + if (objName == "butCopyLink") + { + copyText = ui->editDirectLink->text(); + } + + if (objName == "butCopyExtCode") + { + copyText = ui->editExtCode->text(); + } + + qApp->clipboard()->setText(copyText); +} + diff --git a/src/modules/uploader/uploaderdialog.h b/src/modules/uploader/dialoguploader.h similarity index 65% rename from src/modules/uploader/uploaderdialog.h rename to src/modules/uploader/dialoguploader.h index 155ce40..4f04bd3 100644 --- a/src/modules/uploader/uploaderdialog.h +++ b/src/modules/uploader/dialoguploader.h @@ -18,53 +18,46 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef UPLOADERDIALOG_H -#define UPLOADERDIALOG_H - -#include -#include -#include +#ifndef DIALOGUPLOADER_H +#define DIALOGUPLOADER_H #include "uploader.h" +#include "uploaderconfig.h" -class Uploader; +#include namespace Ui { - class UploaderDialog; +class DialogUploader; } -class UploaderDialog : public QDialog +class DialogUploader : public QDialog { Q_OBJECT + public: - explicit UploaderDialog(Uploader *uploader, QWidget* parent = 0); - ~UploaderDialog(); - -protected: - void closeEvent ( QCloseEvent *e); - -private: - Ui::UploaderDialog *ui; - Uploader *loader; - QVector extCodes; + explicit DialogUploader(QWidget *parent = 0); + ~DialogUploader(); - void loadSettings(); - inline void copyLink(const QString& link); - -public Q_SLOTS: - void updateProgerssbar(qint64 bytesSent, qint64 bytesTotal); +protected: + void changeEvent(QEvent *e); private Q_SLOTS: - void uploadStart(); - void uploadDone(const QVector& resultStrings); - void uploadFailed(const QByteArray& errorCode); + void slotUploadStart(); + void slotSeletHost(int type); + void slotUploadProgress(qint64 bytesSent, qint64 bytesTotal); + void slotUploadDone(); + void slotUploadFail(const QByteArray &error); + void slotChangeExtCode(int code); + void slotCopyLink(); + +private: + Ui::DialogUploader *ui; - void copyDirectLink(); - void copyExtCode(); - void changeExtCode(int code); - void showSettings(); + Uploader* uploader; - void useAccount(bool use); + // storage id curren selected img sho + quint8 selectedHost; + UploaderConfig UplConf; }; -#endif // UPLOADERDIALOG_H +#endif // DIALOGUPLOADER_H diff --git a/src/modules/uploader/dialoguploader.ui b/src/modules/uploader/dialoguploader.ui new file mode 100644 index 0000000..60452b0 --- /dev/null +++ b/src/modules/uploader/dialoguploader.ui @@ -0,0 +1,263 @@ + + + DialogUploader + + + + 0 + 0 + 841 + 314 + + + + Publish to internet + + + + + + + + Upload to + + + + + + + + + + + + + + + + QFrame::Panel + + + QFrame::Raised + + + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + 1 + + + + + + + + Direct link: + + + + + + + + + true + + + + + + + + 112 + 0 + + + + Copy + + + + + + + + + + + Extended preformed html or bb codes: + + + + + + + + + + + + + + true + + + + + + + + 112 + 0 + + + + Copy + + + + + + + + + Qt::Vertical + + + + 20 + 34 + + + + + + labDirectLink + verticalSpacer_2 + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 96 + 20 + + + + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + 24 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 96 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Upload + + + + + + + Close + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/src/modules/uploader/imgshack/uploader_imgshack.cpp b/src/modules/uploader/imgshack/uploader_imgshack.cpp new file mode 100644 index 0000000..ac10f9a --- /dev/null +++ b/src/modules/uploader/imgshack/uploader_imgshack.cpp @@ -0,0 +1,180 @@ + + +#include "uploader_imgshack.h" + +#include + +#include + +Uploader_ImgShack::Uploader_ImgShack(QObject* parent): Uploader(parent) +{ + qDebug() << " create imageshack uploader"; +} + +Uploader_ImgShack::~Uploader_ImgShack() +{ + qDebug() << " kill imageshack uploader"; +} + +/*! + * Start upload process + */ +void Uploader_ImgShack::startUploading() +{ + createData(); + createRequest(imageData, apiUrl()); + + _request.setRawHeader("Host", "imageshack.us"); + _request.setRawHeader("Content-Type", "multipart/form-data; boundary=" + boundary(true)); + _request.setRawHeader("Connection", "Keep-Alive"); + _request.setRawHeader("User-Agent", "My User-Agent"); + _request.setRawHeader("Content-Length", QByteArray::number(imageData.size())); + + Uploader::startUploading(); +} + +/*! + * Return url for upload image + */ +QUrl Uploader_ImgShack::apiUrl() +{ + return QUrl("http://imageshack.us/upload_api.php"); +} + +/*! + * Prepare image datafor uploading + */ +void Uploader_ImgShack::createData() +{ + Uploader::createData(); + + // create data for upload + QByteArray uploadData; + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"public\"\r\n"); + uploadData.append("\r\n"); + uploadData.append("yes"); + uploadData.append("\r\n"); + +/* not worked in current + // resize image + if (selectedSize != -1) + { + QByteArray newSize = QByteArray::number(sizes[selectedSize].width()) + "x" + QByteArray::number(sizes[selectedSize].height()); + + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"optimage\"\r\n"); + uploadData.append("\r\n"); + uploadData.append("1"); + uploadData.append("\r\n"); + + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"optsize\"\r\n"); + uploadData.append("\r\n"); + uploadData.append(newSize); + uploadData.append("\r\n"); +} + +if (_useAccount == true) +{ + + qDebug() << "use acc" << _useAccount; + qDebug() << "use acc" << _username; + qDebug() << "use acc" << _password; + + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"a_username\"\r\n"); + uploadData.append("\r\n"); + uploadData.append(_username); + uploadData.append("\r\n"); + + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"a_password\"\r\n"); + uploadData.append("\r\n"); + uploadData.append(_password); + uploadData.append("\r\n"); +} +**************/ + // key field + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name=\"key\"\r\n"); + uploadData.append("\r\n"); + uploadData.append("BXT1Z35V8f6ee0522939d8d7852dbe67b1eb9595"); + uploadData.append("\r\n"); + + //fileupload + uploadData.append(boundary()); + uploadData.append("content-disposition: "); + uploadData.append("form-data; name='fileupload'; "); + uploadData.append("filename='" + _uploadFilename + "'\r\n"); + + if (_formatString == "jpg") + { + uploadData.append("Content-Type: image/jpeg\r\n"); + } + else + { + uploadData.append("Content-Type: image/" + _formatString + "\r\n"); + } + + uploadData.append("\r\n"); + uploadData.append(imageData); + uploadData.append("\r\n"); + + uploadData.append(boundary()); + + imageData = uploadData; +} + +/*! + * Process server reply data + */ +void Uploader_ImgShack::replyFinished(QNetworkReply* reply) +{ + qDebug() << "reply finished ImgShack"; + + if (reply->error() == QNetworkReply::NoError) + { + QByteArray replyXmalText = reply->readAll(); + + // error parsing + if (replyXmalText.contains("error id=") == true) + { + qDebug() << "error"; + QRegExp err(" listXmlNodes; + listXmlNodes << "image_link" << "image_html" << "image_bb2" << "thumb_html" << "thumb_bb2"; + + QMap replyXmlMap = parseResultStrings(listXmlNodes, replyXmalText); + + this->_uploadedStrings[UL_DIRECT_LINK].first = replyXmlMap["image_link"]; + this->_uploadedStrings[UL_HTML_CODE].first = replyXmlMap["image_html"]; + this->_uploadedStrings[UL_BB_CODE].first = replyXmlMap["image_bb2"]; + this->_uploadedStrings[UL_HTML_CODE_THUMB].first = replyXmlMap["thumb_htm"]; + this->_uploadedStrings[UL_BB_CODE_THUMB].first = replyXmlMap["thumb_bb2"]; + + Q_EMIT uploadDone(); + } + else + { + Q_EMIT uploadFail(reply->errorString().toAscii()); + } + + reply->deleteLater(); +} diff --git a/src/modules/uploader/imgshack/uploader_imgshack.h b/src/modules/uploader/imgshack/uploader_imgshack.h new file mode 100644 index 0000000..11aa551 --- /dev/null +++ b/src/modules/uploader/imgshack/uploader_imgshack.h @@ -0,0 +1,28 @@ + + +#ifndef UPLOADER_IMGSHACK_H +#define UPLOADER_IMGSHACK_H + +#include + +#include + +class Uploader_ImgShack : public Uploader +{ + Q_OBJECT +public: + explicit Uploader_ImgShack(QObject* parent = 0); + virtual ~Uploader_ImgShack(); + + virtual void startUploading(); + +protected: + virtual QUrl apiUrl(); +// virtual QByteArray createData(); + void createData(); + +protected Q_SLOTS: + virtual void replyFinished(QNetworkReply* reply); +}; + +#endif // UPLOADER_IMGSHACK_H diff --git a/src/modules/uploader/imgur/uploader_imgur.cpp b/src/modules/uploader/imgur/uploader_imgur.cpp new file mode 100644 index 0000000..02e67ba --- /dev/null +++ b/src/modules/uploader/imgur/uploader_imgur.cpp @@ -0,0 +1,90 @@ + + + +#include "uploader_imgur.h" + +#include + +Uploader_ImgUr::Uploader_ImgUr(QObject* parent): Uploader(parent) +{ + qDebug() << " create img Ur uploader"; +} + +Uploader_ImgUr::~Uploader_ImgUr() +{ + qDebug() << " kill img Ur uploader"; +} + +/*! + * Start upload process + */ +void Uploader_ImgUr::startUploading() +{ + createData(); + createRequest(imageData, apiUrl()); + + this->_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + Uploader::startUploading(); +} + +/*! + * Return url for upload image + */ +QUrl Uploader_ImgUr::apiUrl() +{ + return QUrl("http://api.imgur.com/2/upload"); +} + +/*! + * Prepare image datafor uploading + */ +void Uploader_ImgUr::createData() +{ + qDebug() << "create data in imagUR"; + bool toBase64 = true; + Uploader::createData(toBase64); + + // create data for upload + QByteArray uploadData; + + uploadData.append(QString("key=").toUtf8()); + uploadData.append(QUrl::toPercentEncoding("6920a141451d125b3e1357ce0e432409")); + uploadData.append(QString("&image=").toUtf8()); + uploadData.append(QUrl::toPercentEncoding(this->imageData)); + + this->imageData = uploadData; +} + +/*! + * Process server reply data + */ +void Uploader_ImgUr::replyFinished(QNetworkReply* reply) +{ + if (reply->error() == QNetworkReply::NoError) + { + QByteArray replyXmalText = reply->readAll(); + + // creating list of element names + QVector listXmlNodes; + listXmlNodes << "original" << "imgur_page" << "large_thumbnail" << "small_square"; + + QMap replyXmlMap = parseResultStrings(listXmlNodes, replyXmalText); + qDebug() << "original "; + qDebug() << replyXmlMap["original"]; + + this->_uploadedStrings[UL_DIRECT_LINK].first = replyXmlMap["original"]; + this->_uploadedStrings[UL_HTML_CODE].first = ""; + this->_uploadedStrings[UL_BB_CODE].first = "[img]" + replyXmlMap["original"] +"[/img]"; + this->_uploadedStrings[UL_HTML_CODE_THUMB].first = ""; + this->_uploadedStrings[UL_BB_CODE_THUMB].first = "[url=" + replyXmlMap["original"] + "][img]"+ replyXmlMap["original"] +"[/img][/url]"; + + Q_EMIT uploadDone(); + } + else + { + Q_EMIT uploadFail(reply->errorString().toAscii()); + } + + reply->deleteLater(); +} diff --git a/src/modules/uploader/imgur/uploader_imgur.h b/src/modules/uploader/imgur/uploader_imgur.h new file mode 100644 index 0000000..64eb7a4 --- /dev/null +++ b/src/modules/uploader/imgur/uploader_imgur.h @@ -0,0 +1,38 @@ + + +#ifndef UPLOADER_IMGUR_H +#define UPLOADER_IMGUR_H + +#include + +#include + +namespace UploadImgUr { + enum Error { + ErrorFile, + ErrorNetwork, + ErrorCredits, + ErrorUpload, + ErrorCancel, + }; +}; + +class Uploader_ImgUr : public Uploader +{ + Q_OBJECT +public: + explicit Uploader_ImgUr(QObject* parent = 0); + virtual ~Uploader_ImgUr(); + + virtual void startUploading(); + +protected: + virtual QUrl apiUrl(); + virtual void createData(); + +protected Q_SLOTS: + virtual void replyFinished(QNetworkReply* reply); +}; + +#endif // UPLOADER_IMGUR_H + diff --git a/src/modules/uploader/moduleuploader.cpp b/src/modules/uploader/moduleuploader.cpp new file mode 100644 index 0000000..fd5936f --- /dev/null +++ b/src/modules/uploader/moduleuploader.cpp @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2009 - 2012 by Artem 'DOOMer' Galichkin * + * doomer3d@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "moduleuploader.h" +#include "dialoguploader.h" + +ModuleUploader::ModuleUploader() +{ + +} + +void ModuleUploader::init() +{ + DialogUploader *ui = new DialogUploader(); + ui->exec(); +} diff --git a/src/modules/uploader/moduleuploader.h b/src/modules/uploader/moduleuploader.h new file mode 100644 index 0000000..e7f69bd --- /dev/null +++ b/src/modules/uploader/moduleuploader.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * Copyright (C) 2009 - 2012 by Artem 'DOOMer' Galichkin * + * doomer3d@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef MODULEUPLOADER_H +#define MODULEUPLOADER_H + +class ModuleUploader +{ +public: + ModuleUploader(); + + void init(); +}; + +#endif // MODULEUPLOADER_H diff --git a/src/modules/uploader/uploader.cpp b/src/modules/uploader/uploader.cpp index 05f9cb9..7721fbf 100644 --- a/src/modules/uploader/uploader.cpp +++ b/src/modules/uploader/uploader.cpp @@ -18,70 +18,37 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include - #include "uploader.h" -#include "uploaderdialog.h" +#include "core/core.h" -#include -#include #include -#include -#include -#include #include -#include -#include +#include #include -Uploader::Uploader() +Uploader::Uploader(QObject *parent) : + QObject(parent) { - strBoundary = "uploadbound"; - sizes << QSize(100,75) << QSize(150,112) << QSize(320,240) << QSize(640,480) << QSize(800,600) << QSize(1024,768) << QSize(1280,1024) << QSize(1600,1200);; - selectedSize = -1; - - net = new QNetworkAccessManager(this); - UploaderDialog *dlg = new UploaderDialog(this); - dlg->show(); + qDebug() << "creating base uploader"; + _strBoundary = "uploadbound"; + _net = new QNetworkAccessManager(this); + serverReply = 0; + initUploadedStrList(); } Uploader::~Uploader() { - qDebug() << "kill uploader"; -} - -void Uploader::setUsername(const QString& name) -{ - _username = name; -} - -void Uploader::setPassword(const QString& pass) -{ - _password = pass; -} - -void Uploader::useAccount(bool use) -{ - _useAccount = use; -} - - -void Uploader::uploadScreen() -{ - qDebug() << "upload screen slot"; - - QByteArray data = createUploadData(); - QNetworkRequest request = createRequest(data); - - connect(net, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); - serverReply = net->post(request, data); - connect(serverReply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(replyProgress(qint64,qint64))); + qDebug() << " base uploader killed"; } +/*! + * Create boundary string + * \param cleared -detect for strt boyndary lin in httpRequest + */ QByteArray Uploader::boundary(bool cleared) { - QByteArray retBoundary = strBoundary; + QByteArray retBoundary = _strBoundary; if (cleared == false) { @@ -92,200 +59,139 @@ QByteArray Uploader::boundary(bool cleared) return retBoundary; } -QByteArray Uploader::createUploadData() -{ - QByteArray uploadData; - - Core *core = Core::instance(); - QString format = core->conf->getSaveFormat(); - QString tmpFileName = createFilename(format); - core->writeScreen(tmpFileName, format , true); - - QByteArray screenData; - screenData = core->getScreen(); - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"public\"\r\n"); - uploadData.append("\r\n"); - uploadData.append("yes"); - uploadData.append("\r\n"); - - qDebug() << "USERNAME " << _username; - qDebug() << "PASSWORD " << _password; - - // resize image - if (selectedSize != -1) - { - QByteArray newSize = QByteArray::number(sizes[selectedSize].width()) + "x" + QByteArray::number(sizes[selectedSize].height()); - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"optimage\"\r\n"); - uploadData.append("\r\n"); - uploadData.append("1"); - uploadData.append("\r\n"); - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"optsize\"\r\n"); - uploadData.append("\r\n"); - uploadData.append(newSize); - uploadData.append("\r\n"); - } - - if (_useAccount == true) - { - - qDebug() << "use acc" << _useAccount; - qDebug() << "use acc" << _username; - qDebug() << "use acc" << _password; - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"a_username\"\r\n"); - uploadData.append("\r\n"); - uploadData.append(_username); - uploadData.append("\r\n"); - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"a_password\"\r\n"); - uploadData.append("\r\n"); - uploadData.append(_password); - uploadData.append("\r\n"); - } - - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name=\"key\"\r\n"); - uploadData.append("\r\n"); - uploadData.append("BXT1Z35V8f6ee0522939d8d7852dbe67b1eb9595"); - uploadData.append("\r\n"); - - //fileupload - uploadData.append(boundary()); - uploadData.append("content-disposition: "); - uploadData.append("form-data; name='fileupload'; "); - uploadData.append("filename='" + tmpFileName + "'\r\n"); +/*! + * Generate filename for upload file + */ +QString Uploader::createFilename(QString& format) +{ + QString tmpFileName = QUuid::createUuid().toString(); + int size = tmpFileName.size() - 2; + tmpFileName = tmpFileName.mid(1, size).left(8); - if (format == "jpg") - { - uploadData.append("Content-Type: image/jpeg\r\n"); - } - else - { - uploadData.append("Content-Type: image/" + format + "\r\n"); - } + tmpFileName = QDir::tempPath() + QDir::separator() + "screenshot-" + tmpFileName + "." + format; + return tmpFileName; +} + +void Uploader::replyProgress(qint64 bytesSent, qint64 bytesTotal) +{ + Q_EMIT uploadProgress(bytesSent, bytesTotal); +} - uploadData.append("\r\n"); - uploadData.append(screenData); - uploadData.append("\r\n"); +/*! + * Start uploadingin base class + */ +void Uploader::startUploading() +{ + connect(_net, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); + serverReply = _net->post(_request, imageData); - uploadData.append(boundary()); + connect(serverReply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(replyProgress(qint64,qint64))); +} - return uploadData; +QMap< QByteArray, ResultString_t > Uploader::parsedLinks() +{ + return _uploadedStrings; } -QNetworkRequest Uploader::createRequest(const QByteArray& requestData) + +/*! + * Return url for upload image + */ +QUrl Uploader::apiUrl() { - QNetworkRequest request; - - request.setUrl(QUrl("http://imageshack.us/upload_api.php")); - request.setRawHeader("Host", "imageshack.us"); - request.setRawHeader("Content-Type", "multipart/form-data; boundary=" + boundary(true)); - request.setRawHeader("Connection", "Keep-Alive"); - request.setRawHeader("User-Agent", "My User-Agent"); - request.setRawHeader("Content-Length", QByteArray::number(requestData.size())); - - return request; + return QUrl(); } -void Uploader::replyFinished(QNetworkReply* reply) +/*! + * Prepare image datafor uploading + */ +void Uploader::createData(bool inBase64) { - if (reply->error() == QNetworkReply::NoError) - { - QByteArray replyXmalText = reply->readAll(); - - // error parsing - if (replyXmalText.contains("error id=") == true) - { - qDebug() << "error"; - - // TODO -- emiting error signal (rerror type == errList(0)) - - QRegExp err(" listXmlNodes; - QRegExp re; - QRegExp re2; - - // creating list of element names - listXmlNodes << "image_link" << "image_html" << "image_bb" << "image_bb2" << "thumb_html" << "thumb_bb" << "thumb_bb2"; - int inStart = 0; - int outStart = 0; - int len = 0; - - // parsing xml - for (int i = 0; i < listXmlNodes.count(); ++i) - { - // FIXME -- dirty hack for capture link text without right unversal regexp - // set patterns for full lenght item - re.setPattern("<"+listXmlNodes[i]+">"); // open tag - re2.setPattern(""); //close tag - - // get start pos and lenght ite in xml - inStart = re.indexIn(replyXmalText); // ops open tag start - outStart = re2.indexIn(replyXmalText); // pos close tag start - len = outStart - inStart + re2.matchedLength(); // length of full string - - // extract item and replase spec html sumbols - QByteArray extractedText = replyXmalText.mid(inStart, len); - extractedText = extractedText.replace(""","'"); - extractedText = extractedText.replace("<","<"); - extractedText = extractedText.replace(">",">"); - extractedText = extractedText.replace("<"+listXmlNodes[i]+">",""); - extractedText = extractedText.replace("",""); - - listXmlNodes[i] = extractedText; - } - - Q_EMIT uploadDone(listXmlNodes); - } - else - { - qDebug() << "reply error" ; - } - reply->deleteLater(); + Core *core = Core::instance(); + _formatString = core->conf->getSaveFormat(); + _uploadFilename = createFilename(_formatString); + core->writeScreen(_uploadFilename, _formatString , true); + + if (inBase64 == false) + { + imageData = core->getScreen(); + } + else + { + imageData = core->getScreen().toBase64(); + } } -void Uploader::replyProgress(qint64 bytesSent, qint64 bytesTotal) +/*! + * Create request for send to server. + * this method called from subclasses. + */ +void Uploader::createRequest(const QByteArray& requestData, const QUrl url) { - Q_EMIT uploadProgress(bytesSent, bytesTotal); + _request.setUrl(url); } -QString Uploader::createFilename(QString& format) +/*! + * Parsing server reply and get map with server returned links + * \param keytags List of tags for parsing + * \param result String wuth server reply + */ +QMap Uploader::parseResultStrings(const QVector< QByteArray >& keytags, const QByteArray& result) { - QString tmpFileName = QUuid::createUuid().toString(); - int size = tmpFileName.size() - 2; - tmpFileName = tmpFileName.mid(1, size).left(8); - - tmpFileName = QDir::tempPath() + QDir::separator() + "screenshot-" + tmpFileName + "." + format; - - return tmpFileName; + QMap replyMap; + + QRegExp re; + QRegExp re2; + + int inStart = 0; + int outStart = 0; + int len = 0; + + // parsing xml + for (int i = 0; i < keytags.count(); ++i) + { + // set patterns for full lenght item + re.setPattern("<"+keytags[i]+">"); // open tag + re2.setPattern(""); //close tag + + // get start pos and lenght ite in xml + inStart = re.indexIn(result); // ops open tag start + outStart = re2.indexIn(result); // pos close tag start + len = outStart - inStart + re2.matchedLength(); // length of full string + + // extract item and replase spec html sumbols + QByteArray extractedText = result.mid(inStart, len); + extractedText = extractedText.replace(""","'"); + extractedText = extractedText.replace("<","<"); + extractedText = extractedText.replace(">",">"); + extractedText = extractedText.replace("<"+keytags[i]+">",""); + extractedText = extractedText.replace("",""); + + // to map + replyMap.insert(keytags[i], extractedText); + +// keytags[i] = extractedText; + } + + return replyMap; } -void Uploader::selectResizeMode(int mode) +void Uploader::initUploadedStrList() { - selectedSize = mode-1; - qDebug() << "mode " << selectedSize; + qDebug() << "initialize final strings list"; + ResultString_t strPair = qMakePair(QByteArray(), tr("Direct link")); + this->_uploadedStrings.insert(UL_DIRECT_LINK, strPair); + + strPair = qMakePair(QByteArray(), tr("HTML code")); + this->_uploadedStrings.insert(UL_HTML_CODE ,strPair); + + strPair = qMakePair(QByteArray(), tr("BB code")); + this->_uploadedStrings.insert(UL_BB_CODE, strPair); + + strPair = qMakePair(QByteArray(), tr("HTML code with thumb image")); + this->_uploadedStrings.insert(UL_HTML_CODE_THUMB ,strPair); + + strPair = qMakePair(QByteArray("bb_code_thumb"), tr("BB code with thumb image")); + this->_uploadedStrings.insert(UL_BB_CODE_THUMB, strPair); } diff --git a/src/modules/uploader/uploader.h b/src/modules/uploader/uploader.h index 8ed701d..a687311 100644 --- a/src/modules/uploader/uploader.h +++ b/src/modules/uploader/uploader.h @@ -23,53 +23,66 @@ #include #include -#include -#include +#include +#include #include #include +#include + +typedef QPair ResultString_t; + +const QByteArray UL_DIRECT_LINK = "direct_link"; +const QByteArray UL_HTML_CODE = "html_code"; +const QByteArray UL_BB_CODE = "bb_code"; +const QByteArray UL_HTML_CODE_THUMB = "html_code_thumb"; +const QByteArray UL_BB_CODE_THUMB = "bb_code_thumb"; class Uploader : public QObject { Q_OBJECT public: - Uploader(); + explicit Uploader(QObject *parent = 0); virtual ~Uploader(); - void setUsername(const QString& name); - void setPassword(const QString& pass); - void useAccount(bool use); - -public Q_SLOTS: - void uploadScreen(); - void selectResizeMode(int mode); - -private Q_SLOTS: - void replyFinished(QNetworkReply* reply); - void replyProgress(qint64 bytesSent, qint64 bytesTotal); + // overriding methods + virtual void startUploading(); + QMap parsedLinks(); Q_SIGNALS: void uploadStart(); void uploadFail(const QByteArray &error); - void uploadDone(const QVector& resultStrings); - void uploadProgress(qint64 bytesSent, qint64 bytesTotal); +// void uploadDone(const QVector& resultStrings); + void uploadDone(); + void uploadProgress(qint64 bytesSent, qint64 bytesTotal); -private: +public Q_SLOTS: + +protected Q_SLOTS: + virtual void replyFinished(QNetworkReply* reply) {}; + void replyProgress(qint64 bytesSent, qint64 bytesTotal); + +protected: + // methods QByteArray boundary(bool cleared = false); - QByteArray createUploadData(); - QNetworkRequest createRequest(const QByteArray& requestData); + QString createFilename(QString& format); + QMap parseResultStrings(const QVector& keytags, const QByteArray& result); + + virtual QUrl apiUrl(); + virtual void createData(bool inBase64 = false); + virtual void createRequest(const QByteArray& requestData, const QUrl url); + // vars QByteArray imageData; - QByteArray strBoundary; - QNetworkAccessManager *net; + QString _uploadFilename; + QString _formatString; + QByteArray _strBoundary; + QMap _uploadedStrings; + QNetworkAccessManager *_net; + QNetworkRequest _request; QNetworkReply *serverReply; - - QString createFilename(QString& format); - QVector sizes; - qint8 selectedSize; - - bool _useAccount; - QString _username; - QString _password; + +private: + void initUploadedStrList(); }; #endif // UPLOADER_H diff --git a/src/modules/uploader/uploaderconfig.cpp b/src/modules/uploader/uploaderconfig.cpp index a8093a3..1ae59df 100644 --- a/src/modules/uploader/uploaderconfig.cpp +++ b/src/modules/uploader/uploaderconfig.cpp @@ -20,8 +20,6 @@ #include "uploaderconfig.h" #include -#include -#include #include "core/config.h" @@ -30,81 +28,27 @@ const QString groupName = "imageshack.us"; UploaderConfig::UploaderConfig() -{ +{ QString configFile = Config::getConfigDir(); -#ifdef Q_WS_X11 +#ifdef Q_WS_X11 configFile += "uploader.conf"; - #ifdef SG_XDG_CONFIG_SUPPORT - // old style config settings storage - QString oldConfigFile = QDir::homePath()+ QDir::separator()+".screengrab"+ QDir::separator() + "uploader.conf"; - - // move config file to new location - if (QFile::exists(oldConfigFile) == true && QFile::exists(configFile) == false) - { - QFile::rename(oldConfigFile, configFile); - } - #endif #endif - + #ifdef Q_WS_WIN configFile += "uploader.ini"; #endif _settings = new QSettings(configFile, QSettings::IniFormat); - _settingsList << "username" << "password"; + + _labelsList << "ImgUr" << "ImageShack" ; + _groupsList << "imgur.com" << "imageshack.us"; } - UploaderConfig::~UploaderConfig() { delete _settings; } - -QStringList UploaderConfig::loadSettings() -{ - QStringList retList; - - _settings->beginGroup(groupName); - - for (int i = 0; i < _settingsList.count(); ++i) - { - retList << _settings->value(_settingsList.at(i)).toString(); - } - - _settings->endGroup(); - - return retList; -} - - -void UploaderConfig::saveSettings(const QStringList& settings) -{ - _settings->beginGroup(groupName); - - qDebug() << "list " << settings; - - for (int i = 0; i < _settingsList.count(); ++i) - { - QVariant val = settings.at(i); - _settings->setValue(_settingsList.at(i), val); - } - - _settings->endGroup(); -} - -QVariant UploaderConfig::loadparam(const QString& param) -{ - QVariant retVal; - _settings->beginGroup(groupName); - retVal = _settings->value(param); - _settings->endGroup(); - - return retVal; -} - -void UploaderConfig::saveParameter(const QString& param, const QVariant& val) +QStringList UploaderConfig::labelsList() const { - _settings->beginGroup(groupName); - _settings->setValue(param, val); - _settings->endGroup(); + return _labelsList; } diff --git a/src/modules/uploader/uploaderconfig.h b/src/modules/uploader/uploaderconfig.h index b07dad1..fbe06d3 100644 --- a/src/modules/uploader/uploaderconfig.h +++ b/src/modules/uploader/uploaderconfig.h @@ -24,6 +24,7 @@ #include #include #include +#include class UploaderConfig { @@ -32,14 +33,17 @@ class UploaderConfig UploaderConfig(); ~UploaderConfig(); - void saveSettings(const QStringList& settings); - QStringList loadSettings(); - void saveParameter(const QString& param, const QVariant& val); - QVariant loadparam(const QString& param); + QStringList labelsList() const; + + // load settings + // на вход методу даем стринглист ключей параметров + // на выходе получаем мап кувариантов - ключ параметр private: QSettings *_settings; - QStringList _settingsList; + + QStringList _groupsList; + QStringList _labelsList; }; #endif // UPLOADERCONFIG_H diff --git a/src/modules/uploader/uploaderdialog.cpp b/src/modules/uploader/uploaderdialog.cpp deleted file mode 100644 index 4b4087e..0000000 --- a/src/modules/uploader/uploaderdialog.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 - 20112 by Artem 'DOOMer' Galichkin * - * doomer3d@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "uploaderdialog.h" -#include "ui_uploaderdialog.h" -#include "uploaderconfig.h" -#include "core/core.h" - -#include -#include - -UploaderDialog::UploaderDialog(Uploader* uploader, QWidget* parent) - :QDialog(parent), ui(new Ui::UploaderDialog), loader(uploader) -{ - ui->setupUi(this); - - ui->shotLabel->setFixedWidth(150); - ui->shotLabel->setFixedHeight(128); - - ui->shotLabel->setPixmap(Core::instance()->getPixmap().scaled(ui->shotLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - - // set suze to tooltip for preview pixmap - int width = Core::instance()->getPixmap().width(); - int height = Core::instance()->getPixmap().height(); - QString pixmapSize = QString::number(width) + "x" + QString::number(height) + tr(" pixel"); - ui->shotLabel->setToolTip(pixmapSize); - ui->butUpload->setFixedWidth(ui->shotLabel->geometry().width()); - - QString warningTitle = tr("Warning!"); - QString warningText = tr("Resize makes on servers imageshack.us"); - - ui->labResizeWarning->setText("" + warningTitle + "
" + warningText); - - connect(ui->butClose, SIGNAL(clicked(bool)), this, SLOT(close())); - connect(ui->butSettings, SIGNAL(clicked(bool)), this, SLOT(showSettings())); - connect(ui->butUpload, SIGNAL(clicked(bool)), this, SLOT(uploadStart())); - connect(ui->checkUseAccount, SIGNAL(toggled(bool)), this, SLOT(useAccount(bool))); - - connect(loader, SIGNAL(uploadDone(QVector)), this, SLOT(uploadDone(QVector))); - connect(loader, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(updateProgerssbar(qint64,qint64))); - connect(loader, SIGNAL(uploadFail(QByteArray)), this, SLOT(uploadFailed(QByteArray))); - - connect(ui->butCopyLink, SIGNAL(clicked(bool)), this, SLOT(copyDirectLink())); - connect(ui->butCopyExtCode, SIGNAL(clicked(bool)), this, SLOT(copyExtCode())); - connect(ui->cbxExtCode, SIGNAL(currentIndexChanged(int)), this, SLOT(changeExtCode(int))); - connect(ui->cbxResize, SIGNAL(currentIndexChanged(int)), loader, SLOT(selectResizeMode(int))); - - qDebug() << "Core::instance()->getPixmap().width() " << Core::instance()->getPixmap().width(); - - ui->progressBar->setFormat(tr("Uploaded ") + "%p%" + " (" + "%v" + " of " + "%m bytes"); - ui->progressBar->setVisible(false); - ui->labStatus->setVisible(false); - - // load settings - loadSettings(); - - ui->stackedWidget->setCurrentIndex(0); -} - -UploaderDialog::~UploaderDialog() -{ - -} - -void UploaderDialog::loadSettings() -{ - UploaderConfig conf; - - QStringList settingsList = conf.loadSettings(); - ui->editUsername->setText(settingsList.at(0)); - ui->editPassword->setText(settingsList.at(1)); - - bool copyLink = conf.loadparam("autoCopyDirectLink").toBool(); - qDebug() << "copylin " << copyLink; - ui->checkCopyDirectLink->setChecked(copyLink); - - bool useAcc = conf.loadparam("useAccount").toBool(); - ui->checkUseAccount->setChecked(useAcc); - loader->useAccount(useAcc); - - useAccount(useAcc); -} - - -void UploaderDialog::closeEvent(QCloseEvent* e) -{ - if (ui->stackedWidget->currentIndex() == 2) - { - ui->stackedWidget->setCurrentIndex(0); - ui->butClose->setText(tr("Close")); - ui->butSettings->setVisible(true); - ui->butUpload->setVisible(true); - ui->butSettings->setText(tr("Settings")); - - // return original dialpog ttitle - setWindowTitle(tr("Upload screenshot")); - e->ignore(); - } - else - { - qDebug() << "loader ;" << loader; - - delete loader; - loader = 0; - - QDialog::closeEvent(e); - } -} - -void UploaderDialog::updateProgerssbar(qint64 bytesSent, qint64 bytesTotal) -{ - ui->progressBar->setMaximum(bytesTotal); - ui->progressBar->setValue(bytesSent); - - if (bytesSent == bytesTotal) - { - qDebug() << "all is send!!!!"; - ui->progressBar->setFormat(tr("Upload completed!")); - ui->labStatus->setText(tr("Receiving a response from the server")); - } -} - -void UploaderDialog::uploadStart() -{ - ui->butSettings->setVisible(false); - ui->butClose->setEnabled(false); -// ui->butUpload->setEnabled(false); - ui->butUpload->setVisible(false); - ui->cbxResize->setEnabled(false); - ui->progressBar->setVisible(true); - ui->labStatus->setVisible(true); - ui->labStatus->setText(tr("Sending screenshot on the server")); - - loader->setUsername(ui->editUsername->text()); - loader->setPassword(ui->editPassword->text()); - - ui->labUsername->setVisible(false); - ui->labPassword->setVisible(false); - ui->editUsername->setVisible(false); - ui->editPassword->setVisible(false); - ui->checkUseAccount->setVisible(false); - - loader->uploadScreen(); -} - -void UploaderDialog::uploadDone(const QVector< QByteArray >& resultStrings) -{ - ui->labSuccessfully->setText(tr("Screenshot uploaded successfully!")); - ui->butClose->setEnabled(true); - ui->butUpload->setVisible(false); - - ui->editDirectLink->setText(resultStrings.at(0)); - - extCodes.resize(resultStrings.count() - 1); - for (int i = 1; i < resultStrings.count(); i++) - { - extCodes[i-1] = resultStrings[i]; - } - - ui->editExtCode->setText(extCodes[ui->cbxExtCode->currentIndex()]); - - // check autocopy direct link - UploaderConfig conf; - bool copyLink = conf.loadparam("autoCopyDirectLink").toBool(); - - if (copyLink == true) - { - copyDirectLink(); - } - - ui->stackedWidget->setCurrentIndex(1); -} - -void UploaderDialog::uploadFailed(const QByteArray& errorCode) -{ - qDebug() << "upload screenshot is failed - " << errorCode; - - // genetate messagebox text - QString errorMessageText; - QString errorMessageTitle = tr("Error uploading screenshot!"); - - if (errorCode == "wrong_file_type" ) - { - errorMessageText = tr("Server is not support this image type"); - } - - // show messagebox - QMessageBox msg; - msg.setWindowTitle(errorMessageTitle); - msg.setText(errorMessageText); - msg.setIcon(QMessageBox::Warning); - msg.exec(); - - close(); -} - - -inline void UploaderDialog::copyLink(const QString& link) -{ - qApp->clipboard()->setText(link); -} - -void UploaderDialog::copyDirectLink() -{ - copyLink(ui->editDirectLink->text()); -} - -void UploaderDialog::copyExtCode() -{ - copyLink(ui->editExtCode->text()); -} - - -void UploaderDialog::changeExtCode(int code) -{ - ui->editExtCode->setText(extCodes[code]); -} - -void UploaderDialog::showSettings() -{ - if (ui->stackedWidget->currentIndex() == 2) - { - //saveSettings - UploaderConfig conf; - - QStringList settingsList; - settingsList << ui->editUsername->text(); - settingsList << ui->editPassword->text(); - - conf.saveSettings(settingsList); - - bool copyLink = ui->checkCopyDirectLink->isChecked(); - conf.saveParameter("autoCopyDirectLink", copyLink); - - bool useAcc = ui->checkUseAccount->isChecked(); - conf.saveParameter("useAccount", useAcc); - ui->butSettings->setText(tr("Settings")); - setWindowTitle(tr("Upload screenshot")); - ui->stackedWidget->setCurrentIndex(0); - ui->butClose->setText(tr("Close")); - ui->butUpload->setVisible(true); - loader->useAccount(useAcc); - } - else - { - ui->stackedWidget->setCurrentIndex(2); - ui->butClose->setText(tr("Cancel")); - ui->butSettings->setText(tr("Save")); - ui->butUpload->setVisible(false); - setWindowTitle(tr("Settings upload screenshot")); - - loadSettings(); - } -} - - -void UploaderDialog::useAccount(bool use) -{ - ui->labUsername->setVisible(use); - ui->labPassword->setVisible(use); - ui->editUsername->setVisible(use); - ui->editPassword->setVisible(use); -// loader->useAccount(use); -} diff --git a/src/modules/uploader/uploaderdialog.ui b/src/modules/uploader/uploaderdialog.ui deleted file mode 100644 index 0610331..0000000 --- a/src/modules/uploader/uploaderdialog.ui +++ /dev/null @@ -1,639 +0,0 @@ - - - UploaderDialog - - - - 0 - 0 - 497 - 287 - - - - Upload screenshot - - - - QLayout::SetFixedSize - - - - - 1 - - - - - - - - - - - - 0 - 0 - - - - QFrame::Panel - - - QFrame::Sunken - - - TextLabel - - - - - - - - - - 0 - 0 - - - - - 112 - 0 - - - - Ulpload - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - - - - - - 0 - 0 - - - - This dialog for upload your screenshot on imageshack.us image hosting. - - - true - - - - - - - - 0 - 0 - - - - Resize uploaded image - - - - - - - - No resize - - - - - 100x75 - - - - - 150x112 - - - - - 320x240 - - - - - 640x480 - - - - - 800x600 - - - - - 1024x768 - - - - - 1280x1024 - - - - - 1600x1200 - - - - - Custom - - - - - - - - - 0 - 0 - - - - Resize makes on servers imageshack.us - - - Qt::AlignCenter - - - false - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - Qt::AlignCenter - - - - - - - 0 - - - true - - - - - - - - - - - - - - - - Qt::AlignCenter - - - - - - - Direct link: - - - - - - - - - true - - - - - - - - 112 - 0 - - - - Copy - - - - - - - - - More - - - - - - - - Extended preformed html or bb codes: - - - - - - - - HTML Code - - - - - Bb Code - - - - - Bb Code 2 - - - - - Thumbnail HTML - - - - - Thumbnail BB Code - - - - - Thumbnail Bb Code 2 - - - - - - - - - - - - true - - - - - - - - 112 - 0 - - - - Copy - - - - - - - - - Qt::Vertical - - - - 20 - 54 - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Minimum - - - - 20 - 32 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Use your imageshack.us account - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - Username - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - editUsername - - - - - - - - 0 - 0 - - - - - 336 - 0 - - - - - - - - - - - - - 0 - 0 - - - - Password - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - editPassword - - - - - - - - 0 - 0 - - - - - 336 - 0 - - - - QLineEdit::Password - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Copy direct link to clipboard - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 97 - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 96 - 0 - - - - Settings - - - - - - - - 0 - 0 - - - - - 96 - 0 - - - - Close - - - - - - - - - -