diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index f79b981a5..93608a0e8 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1522,8 +1522,8 @@ void MainWindow::on_actionScreenshots_triggered() QStringList urls; for (ScreenShot *shot : dialog.uploaded()) { - urls << QString("url + "\">Image %s") - .arg(QString::number(shot->imgurIndex)); + urls << QString("url + "\">Image %1") + .arg(shot->timestamp.toString()); } CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), QMessageBox::Information)->exec(); diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 02764fa38..33e931629 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -39,7 +39,7 @@ QList ScreenshotDialog::selected() const return list; } -void ScreenshotDialog::on_buttonBox_accepted() +void ScreenshotDialog::on_uploadBtn_clicked() { QList screenshots = selected(); if (screenshots.isEmpty()) @@ -50,17 +50,18 @@ void ScreenshotDialog::on_buttonBox_accepted() NetJob *job = new NetJob("Screenshot Upload"); for (ScreenShot *shot : screenshots) { - qDebug() << shot->file; job->addNetAction(ScreenShotUpload::make(shot)); } + m_uploaded = screenshots; ProgressDialog prog(this); - prog.exec(job); - connect(job, &NetJob::failed, [this] + if (prog.exec(job) == QDialog::Accepted) + { + accept(); + } + else { 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 1ca27bdd7..104814f16 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -27,7 +27,7 @@ public: private slots: - void on_buttonBox_accepted(); + void on_uploadBtn_clicked(); private: Ui::ScreenshotDialog *ui; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index 7eeab859c..9e4bd6f02 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -17,68 +17,82 @@ :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg - - - - 10 - 260 - 441 - 31 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 10 - 10 - 439 - 241 - - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::SelectItems - - - - 120 - 90 - - - - QListView::LeftToRight - - - true - - - QListView::IconMode - - + + + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectItems + + + + 120 + 90 + + + + QListView::LeftToRight + + + true + + + QListView::IconMode + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + Upload + + + + + + - buttonBox - rejected() + closeBtn + clicked() ScreenshotDialog reject() - 316 - 260 + 315 + 272 - 286 - 274 + 271 + 258 diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index 0565d0a46..6969549c6 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,4 +1,5 @@ #include "ScreenshotList.h" + #include #include @@ -22,9 +23,9 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const case Qt::DecorationRole: return QIcon(m_screenshots.at(index.row())->file); case Qt::DisplayRole: - return m_screenshots.at(index.row())->timestamp; + return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss"); case Qt::ToolTipRole: - return m_screenshots.at(index.row())->timestamp; + return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss"); case Qt::TextAlignmentRole: return (int)(Qt::AlignHCenter | Qt::AlignVCenter); default: @@ -68,7 +69,7 @@ void ScreenshotLoadTask::executeTask() for (auto file : dir.entryList()) { ScreenShot *shot = new ScreenShot(); - shot->timestamp = file.left(file.length() - 4); + shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png"); shot->file = dir.absoluteFilePath(file); m_results.append(shot); } diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index 08c968f12..dee74807b 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -7,10 +7,10 @@ class ScreenShot { public: - QString timestamp; + QDateTime timestamp; QString file; QString url; - int imgurIndex; + QString imgurIndex; }; class ScreenshotList : public QAbstractListModel diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index 829a08152..490c74b3f 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -24,7 +24,6 @@ void ScreenShotUpload::start() m_status = Job_InProgress; 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"); @@ -47,7 +46,7 @@ void ScreenShotUpload::start() multipart->append(typePart); QHttpPart namePart; namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\""); - namePart.setBody(m_shot->timestamp.toUtf8()); + namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8()); multipart->append(namePart); auto worker = MMC->qnam(); @@ -85,8 +84,8 @@ void ScreenShotUpload::downloadFinished() emit failed(m_index_within_job); return; } - m_shot->imgurIndex = object.value("data").toObject().value("id").toVariant().toInt(); - m_shot->url = "https://imgur.com/gallery/" + QString::number(m_shot->imgurIndex); + m_shot->imgurIndex = object.value("data").toObject().value("id").toString(); + m_shot->url = object.value("data").toObject().value("link").toString(); m_status = Job_Finished; emit succeeded(m_index_within_job); return;