From 4a77524b059c12165e20b38de6c0d4ed08e56419 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Sun, 23 Feb 2014 16:14:24 -0500 Subject: Initial stuff. It doesnt work. --- gui/MainWindow.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'gui/MainWindow.h') diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 4d9e165d..b57afcf5 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -138,7 +138,9 @@ slots: // called when an icon is changed in the icon model. void iconUpdated(QString); - void showInstanceContextMenu(const QPoint&); + void showInstanceContextMenu(const QPoint &); + + void on_actionScreenshots_triggered(); public slots: @@ -167,11 +169,15 @@ slots: void updateStatusFailedUI(); void reloadStatus(); - + + void screenshotsUploaded(QList screenshots); + + void screenShotsGotten(QList screenshots); + /*! * Runs the DownloadUpdateTask and installs updates. */ - void downloadUpdates(QString repo, int versionId, bool installOnExit=false); + void downloadUpdates(QString repo, int versionId, bool installOnExit = false); protected: bool eventFilter(QObject *obj, QEvent *ev); @@ -188,7 +194,7 @@ private: ConsoleWindow *console; LabeledToolButton *renameButton; QToolButton *changeIconButton; - QToolButton* newsLabel; + QToolButton *newsLabel; BaseInstance *m_selectedInstance; QString m_currentInstIcon; -- cgit From 5e33da258c3b5159dba854eb4792d0852a1ca363 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Sun, 23 Feb 2014 19:45:59 -0500 Subject: Close to finished. Need to fix the upload part. Viewing works (in grayscale) --- gui/MainWindow.cpp | 19 -------- gui/MainWindow.h | 2 - gui/dialogs/ScreenshotDialog.cpp | 2 +- gui/dialogs/ScreenshotDialog.ui | 21 +++++--- logic/lists/ScreenshotList.cpp | 12 ++--- logic/lists/ScreenshotList.h | 4 +- logic/net/ScreenshotUploader.cpp | 101 ++++++++++++--------------------------- logic/net/ScreenshotUploader.h | 23 --------- logic/net/URLConstants.h | 3 +- 9 files changed, 53 insertions(+), 134 deletions(-) (limited to 'gui/MainWindow.h') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 5a22f678..87c65601 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1538,25 +1538,6 @@ void MainWindow::on_actionScreenshots_triggered() void MainWindow::screenshotsUploaded(QList screenshots) { - NetJob *job2 = new NetJob("Screenshot Data"); - for (ScreenShot *shot : screenshots) - { - job2->addNetAction(ScreenShotGet::make(shot)); - } - ProgressDialog prog3(this); - prog3.exec(job2); - connect(job2, &NetJob::failed, [this] - { - CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), - tr("Unknown error"), QMessageBox::Warning)->exec(); - }); - connect(job2, &NetJob::succeeded, [this, screenshots] - { screenShotsGotten(screenshots); }); -} - -void MainWindow::screenShotsGotten(QList screenshots) -{ - QStringList urls; for (ScreenShot *shot : screenshots) { diff --git a/gui/MainWindow.h b/gui/MainWindow.h index b57afcf5..0a474ef1 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -172,8 +172,6 @@ slots: void screenshotsUploaded(QList screenshots); - void screenShotsGotten(QList screenshots); - /*! * Runs the DownloadUpdateTask and installs updates. */ diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 662c9e84..8900f15b 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -20,7 +20,7 @@ QList ScreenshotDialog::selected() { QList list; QList first = m_list->screenshots(); - for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes()) + for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) { list.append(first.at(index.row())); } diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index c912dffe..af73e5ec 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -11,7 +11,11 @@ - Dialog + Screenshots + + + + :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg @@ -36,12 +40,15 @@ - QAbstractItemView::MultiSelection + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectItems - 480 - 360 + 120 + 90 @@ -51,11 +58,13 @@ true - QListView::ListMode + QListView::IconMode - + + + buttonBox diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index ff37a092..e955f121 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,6 +1,6 @@ #include "ScreenshotList.h" #include "QDir" -#include "QPixmap" +#include "QIcon" ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -20,11 +20,7 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const switch (role) { case Qt::DecorationRole: - { - QPixmap map; - map.loadFromData(m_screenshots.at(index.row())->file); - return map; - } + return QIcon(m_screenshots.at(index.row())->file); case Qt::DisplayRole: return m_screenshots.at(index.row())->timestamp; case Qt::ToolTipRole: @@ -43,7 +39,7 @@ QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, in Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const { - return Qt::NoItemFlags; + return Qt::ItemIsSelectable; } Task *ScreenshotList::load() @@ -73,7 +69,7 @@ void ScreenshotLoadTask::executeTask() { ScreenShot *shot = new ScreenShot(); shot->timestamp = file.left(file.length() - 4); - shot->file = QFile(file).readAll(); + shot->file = dir.absoluteFilePath(file); m_results.append(shot); } m_list->loadShots(m_results); diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index 4011c1bd..08c968f1 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -8,9 +8,9 @@ class ScreenShot { public: QString timestamp; - QByteArray file; - int imgurIndex; + QString file; QString url; + int imgurIndex; }; class ScreenshotList : public QAbstractListModel diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index 03ea1cb4..c1f62243 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -1,32 +1,48 @@ #include "ScreenshotUploader.h" #include "logic/lists/ScreenshotList.h" #include -#include +#include #include +#include +#include +#include +#include #include "URLConstants.h" #include "MultiMC.h" +#include "logger/QsLog.h" ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot) { + m_url = URLConstants::IMGUR_UPLOAD_URL; m_status = Job_NotStarted; } void ScreenShotUpload::start() { m_status = Job_InProgress; - QNetworkRequest request(URLConstants::IMGUR_UPLOAD_URL); + QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); + request.setRawHeader("Accept", "application/json"); - QJsonObject object; - object.insert("image", QJsonValue::fromVariant(m_shot->file.toBase64())); - object.insert("type", QJsonValue::fromVariant("base64")); - object.insert("name", QJsonValue::fromVariant(m_shot->timestamp)); - QJsonDocument doc; - doc.setObject(object); + QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpPart filePart; + filePart.setBody(QFile(m_shot->file).readAll().toBase64()); + filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png"); + filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\""); + multipart->append(filePart); + QHttpPart typePart; + typePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"type\""); + typePart.setBody("base64"); + multipart->append(typePart); + QHttpPart namePart; + namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\""); + namePart.setBody(m_shot->timestamp.toUtf8()); + multipart->append(namePart); auto worker = MMC->qnam(); - QNetworkReply *rep = worker->post(request, doc.toJson()); + QNetworkReply *rep = worker->post(request, multipart); m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), @@ -38,6 +54,7 @@ void ScreenShotUpload::start() } void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error) { + QLOG_DEBUG() << m_reply->errorString(); m_status = Job_Failed; } void ScreenShotUpload::downloadFinished() @@ -50,16 +67,19 @@ void ScreenShotUpload::downloadFinished() QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); if (jsonError.error != QJsonParseError::NoError) { + QLOG_DEBUG() << jsonError.errorString(); emit failed(m_index_within_job); return; } auto object = doc.object(); if (!object.value("success").toBool()) { + QLOG_DEBUG() << doc.toJson(); emit failed(m_index_within_job); return; } - m_shot->imgurIndex = object.value("data").toVariant().toInt(); + m_shot->imgurIndex = object.value("data").toObject().value("id").toVariant().toInt(); + m_shot->url = "https://imgur.com/gallery/" + QString::number(m_shot->imgurIndex); m_status = Job_Finished; emit succeeded(m_index_within_job); return; @@ -81,64 +101,3 @@ void ScreenShotUpload::downloadReadyRead() { // noop } -ScreenShotGet::ScreenShotGet(ScreenShot *shot) : m_shot(shot) -{ - m_status = Job_NotStarted; -} -void ScreenShotGet::start() -{ - m_status = Job_InProgress; - QNetworkRequest request(URLConstants::IMGUR_GET_BASE + m_shot->imgurIndex + ".json"); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); - request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); - - auto worker = MMC->qnam(); - QNetworkReply *rep = worker->get(request); - - m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(downloadProgress(qint64, qint64))); - connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); - connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), - SLOT(downloadError(QNetworkReply::NetworkError))); - connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); -} -void ScreenShotGet::downloadError(QNetworkReply::NetworkError error) -{ - m_status = Job_Failed; -} -void ScreenShotGet::downloadFinished() -{ -} -void ScreenShotGet::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) -{ - m_total_progress = bytesTotal; - m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); -} -void ScreenShotGet::downloadReadyRead() -{ - if (m_status != Job_Failed) - { - QByteArray data = m_reply->readAll(); - m_reply.reset(); - QJsonParseError jsonError; - QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - emit failed(m_index_within_job); - return; - } - auto object = doc.object(); - m_shot->url = object.value("link").toString(); - m_status = Job_Finished; - emit succeeded(m_index_within_job); - return; - } - else - { - m_reply.reset(); - emit failed(m_index_within_job); - return; - } -} diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ScreenshotUploader.h index 09e58677..d5d1cef3 100644 --- a/logic/net/ScreenshotUploader.h +++ b/logic/net/ScreenshotUploader.h @@ -27,26 +27,3 @@ slots: private: ScreenShot *m_shot; }; -class ScreenShotGet : public NetAction -{ -public: - explicit ScreenShotGet(ScreenShot *shot); - static ScreenShotGetPtr make(ScreenShot *shot) - { - return ScreenShotGetPtr(new ScreenShotGet(shot)); - } - -protected -slots: - virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); - virtual void downloadError(QNetworkReply::NetworkError error); - virtual void downloadFinished(); - virtual void downloadReadyRead(); - -public -slots: - virtual void start(); - -private: - ScreenShot *m_shot; -}; diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h index 3e21d21e..f2a943bf 100644 --- a/logic/net/URLConstants.h +++ b/logic/net/URLConstants.h @@ -33,6 +33,5 @@ const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/j const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json"); const QString MOJANG_STATUS_URL("http://status.mojang.com/check"); const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news"); -const QString IMGUR_UPLOAD_URL("https://api.imgur.com/3/image.json"); -const QString IMGUR_GET_BASE("https://api.imgur.com/3/image/"); +const QString IMGUR_UPLOAD_URL("https://api.imgur.com/3/upload.json"); } -- cgit From 226c1bdae5ec615381965b6731f6496dffa3299e Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 24 Feb 2014 09:34:21 +0100 Subject: Screenshot fixes, move some code around, fix some stuff --- gui/ConsoleWindow.cpp | 3 +++ gui/ConsoleWindow.h | 1 + gui/ConsoleWindow.ui | 7 +++++++ gui/MainWindow.cpp | 36 +++++++++------------------------- gui/MainWindow.h | 2 -- gui/dialogs/ScreenshotDialog.cpp | 42 ++++++++++++++++++++++++++++++++++++++-- gui/dialogs/ScreenshotDialog.h | 11 ++++++++++- gui/dialogs/ScreenshotDialog.ui | 16 --------------- logic/lists/ScreenshotList.cpp | 6 +++--- logic/net/ScreenshotUploader.cpp | 26 ++++++++++++++----------- logic/net/ScreenshotUploader.h | 4 +++- 11 files changed, 91 insertions(+), 63 deletions(-) (limited to 'gui/MainWindow.h') diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index ccc037f2..d11e8aff 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -42,6 +42,8 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this, SLOT(onLaunchFailed(BaseInstance *))); + connect(ui->btnScreenshots, &QPushButton::clicked, this, &ConsoleWindow::uploadScreenshots); + restoreState( QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray())); restoreGeometry( @@ -52,6 +54,7 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) auto icon = MMC->icons()->getIcon(iconKey); setWindowIcon(icon); m_trayIcon = new QSystemTrayIcon(icon, this); + // TODO add screenshot upload as a menu item in the tray icon QString consoleTitle = tr("Console window for ") + name; m_trayIcon->setToolTip(consoleTitle); setWindowTitle(consoleTitle); diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h index 7fe90c52..e21da33c 100644 --- a/gui/ConsoleWindow.h +++ b/gui/ConsoleWindow.h @@ -51,6 +51,7 @@ private: signals: void isClosing(); + void uploadScreenshots(); public slots: diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui index c2307ecc..e50fb520 100644 --- a/gui/ConsoleWindow.ui +++ b/gui/ConsoleWindow.ui @@ -49,6 +49,13 @@ + + + + Upload Screenshots + + + diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 87c65601..f79b981a 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1235,6 +1235,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session) console = new ConsoleWindow(proc); connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); + connect(console, &ConsoleWindow::uploadScreenshots, this, &MainWindow::on_actionScreenshots_triggered); proc->setLogin(session); proc->launch(); @@ -1516,34 +1517,15 @@ void MainWindow::on_actionScreenshots_triggered() return; } ScreenshotDialog dialog(list, this); - if (dialog.exec() == QDialog::Accepted) + if (dialog.exec() == ScreenshotDialog::Accepted) { - QList screenshots = dialog.selected(); - if (screenshots.size() == 0) - return; - NetJob *job = new NetJob("Screenshot Upload"); - for (ScreenShot *shot : screenshots) - job->addNetAction(ScreenShotUpload::make(shot)); - ProgressDialog prog2(this); - prog2.exec(job); - connect(job, &NetJob::failed, [this] + QStringList urls; + for (ScreenShot *shot : dialog.uploaded()) { - CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), - tr("Unknown error"), QMessageBox::Warning)->exec(); - }); - connect(job, &NetJob::succeeded, [this, screenshots] - { screenshotsUploaded(screenshots); }); - } -} - -void MainWindow::screenshotsUploaded(QList screenshots) -{ - QStringList urls; - for (ScreenShot *shot : screenshots) - { - urls << QString("url + "\">Image %s") - .arg(QString::number(shot->imgurIndex)); + urls << QString("url + "\">Image %s") + .arg(QString::number(shot->imgurIndex)); + } + CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), + QMessageBox::Information)->exec(); } - CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), - QMessageBox::Information)->exec(); } diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 0a474ef1..5911d175 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -170,8 +170,6 @@ slots: void reloadStatus(); - void screenshotsUploaded(QList screenshots); - /*! * Runs the DownloadUpdateTask and installs updates. */ diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 8900f15b..02764fa3 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -1,6 +1,13 @@ #include "ScreenshotDialog.h" #include "ui_ScreenshotDialog.h" -#include "QModelIndex" + +#include +#include + +#include "ProgressDialog.h" +#include "CustomMessageBox.h" +#include "logic/net/NetJob.h" +#include "logic/net/ScreenshotUploader.h" ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) : QDialog(parent), @@ -16,7 +23,12 @@ ScreenshotDialog::~ScreenshotDialog() delete ui; } -QList ScreenshotDialog::selected() +QList ScreenshotDialog::uploaded() const +{ + return m_uploaded; +} + +QList ScreenshotDialog::selected() const { QList list; QList first = m_list->screenshots(); @@ -26,3 +38,29 @@ QList ScreenshotDialog::selected() } return list; } + +void ScreenshotDialog::on_buttonBox_accepted() +{ + QList screenshots = selected(); + if (screenshots.isEmpty()) + { + done(NothingDone); + return; + } + NetJob *job = new NetJob("Screenshot Upload"); + for (ScreenShot *shot : screenshots) + { + qDebug() << shot->file; + job->addNetAction(ScreenShotUpload::make(shot)); + } + ProgressDialog prog(this); + prog.exec(job); + connect(job, &NetJob::failed, [this] + { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), + tr("Unknown error"), QMessageBox::Warning)->exec(); + reject(); + }); + m_uploaded = screenshots; + connect(job, &NetJob::succeeded, this, &ScreenshotDialog::accept); +} diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index d3f629e7..1ca27bdd 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -18,12 +18,21 @@ public: explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0); ~ScreenshotDialog(); - QList selected(); + enum + { + NothingDone = 0x42 + }; + + QList uploaded() const; private slots: + void on_buttonBox_accepted(); private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; + QList m_uploaded; + + QList selected() const; }; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index af73e5ec..7eeab859 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -66,22 +66,6 @@ - - buttonBox - accepted() - ScreenshotDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - buttonBox rejected() diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index e955f121..0565d0a4 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,6 +1,6 @@ #include "ScreenshotList.h" -#include "QDir" -#include "QIcon" +#include +#include ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -39,7 +39,7 @@ QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, in Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const { - return Qt::ItemIsSelectable; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } Task *ScreenshotList::load() diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index c1f62243..829a0815 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -1,5 +1,5 @@ #include "ScreenshotUploader.h" -#include "logic/lists/ScreenshotList.h" + #include #include #include @@ -7,11 +7,13 @@ #include #include #include + +#include "logic/lists/ScreenshotList.h" #include "URLConstants.h" #include "MultiMC.h" #include "logger/QsLog.h" -ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot) +ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : NetAction(), m_shot(shot) { m_url = URLConstants::IMGUR_UPLOAD_URL; m_status = Job_NotStarted; @@ -26,9 +28,16 @@ void ScreenShotUpload::start() request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); + QFile f(m_shot->file); + if (!f.open(QFile::ReadOnly)) + { + emit failed(m_index_within_job); + return; + } + QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart filePart; - filePart.setBody(QFile(m_shot->file).readAll().toBase64()); + filePart.setBody(f.readAll().toBase64()); filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png"); filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\""); multipart->append(filePart); @@ -45,12 +54,10 @@ void ScreenShotUpload::start() QNetworkReply *rep = worker->post(request, multipart); m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(downloadProgress(qint64, qint64))); - connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); + connect(rep, &QNetworkReply::uploadProgress, this, &ScreenShotUpload::downloadProgress); + connect(rep, &QNetworkReply::finished, this, &ScreenShotUpload::downloadFinished); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); - connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); } void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error) { @@ -86,6 +93,7 @@ void ScreenShotUpload::downloadFinished() } else { + QLOG_DEBUG() << m_reply->readAll(); m_reply.reset(); emit failed(m_index_within_job); return; @@ -97,7 +105,3 @@ void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) m_progress = bytesReceived; emit progress(m_index_within_job, bytesReceived, bytesTotal); } -void ScreenShotUpload::downloadReadyRead() -{ - // noop -} diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ScreenshotUploader.h index d5d1cef3..c1c9db6f 100644 --- a/logic/net/ScreenshotUploader.h +++ b/logic/net/ScreenshotUploader.h @@ -18,7 +18,9 @@ slots: virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); virtual void downloadError(QNetworkReply::NetworkError error); virtual void downloadFinished(); - virtual void downloadReadyRead(); + virtual void downloadReadyRead() + { + } public slots: -- cgit