Screenshot fixes, move some code around, fix some stuff
This commit is contained in:
parent
5e33da258c
commit
226c1bdae5
@ -42,6 +42,8 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
|
|||||||
connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this,
|
connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this,
|
||||||
SLOT(onLaunchFailed(BaseInstance *)));
|
SLOT(onLaunchFailed(BaseInstance *)));
|
||||||
|
|
||||||
|
connect(ui->btnScreenshots, &QPushButton::clicked, this, &ConsoleWindow::uploadScreenshots);
|
||||||
|
|
||||||
restoreState(
|
restoreState(
|
||||||
QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray()));
|
QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray()));
|
||||||
restoreGeometry(
|
restoreGeometry(
|
||||||
@ -52,6 +54,7 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
|
|||||||
auto icon = MMC->icons()->getIcon(iconKey);
|
auto icon = MMC->icons()->getIcon(iconKey);
|
||||||
setWindowIcon(icon);
|
setWindowIcon(icon);
|
||||||
m_trayIcon = new QSystemTrayIcon(icon, this);
|
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;
|
QString consoleTitle = tr("Console window for ") + name;
|
||||||
m_trayIcon->setToolTip(consoleTitle);
|
m_trayIcon->setToolTip(consoleTitle);
|
||||||
setWindowTitle(consoleTitle);
|
setWindowTitle(consoleTitle);
|
||||||
|
@ -51,6 +51,7 @@ private:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void isClosing();
|
void isClosing();
|
||||||
|
void uploadScreenshots();
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
|
@ -49,6 +49,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnScreenshots">
|
||||||
|
<property name="text">
|
||||||
|
<string>Upload Screenshots</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -1235,6 +1235,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session)
|
|||||||
|
|
||||||
console = new ConsoleWindow(proc);
|
console = new ConsoleWindow(proc);
|
||||||
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
|
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
|
||||||
|
connect(console, &ConsoleWindow::uploadScreenshots, this, &MainWindow::on_actionScreenshots_triggered);
|
||||||
|
|
||||||
proc->setLogin(session);
|
proc->setLogin(session);
|
||||||
proc->launch();
|
proc->launch();
|
||||||
@ -1516,34 +1517,15 @@ void MainWindow::on_actionScreenshots_triggered()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ScreenshotDialog dialog(list, this);
|
ScreenshotDialog dialog(list, this);
|
||||||
if (dialog.exec() == QDialog::Accepted)
|
if (dialog.exec() == ScreenshotDialog::Accepted)
|
||||||
{
|
{
|
||||||
QList<ScreenShot *> 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]
|
|
||||||
{
|
|
||||||
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<ScreenShot *> screenshots)
|
|
||||||
{
|
|
||||||
QStringList urls;
|
QStringList urls;
|
||||||
for (ScreenShot *shot : screenshots)
|
for (ScreenShot *shot : dialog.uploaded())
|
||||||
{
|
{
|
||||||
urls << QString("<a href=\"" + shot->url + "\">Image %s</a>")
|
urls << QString("<a href=\"" + shot->url + "\">Image %s</a>")
|
||||||
.arg(QString::number(shot->imgurIndex));
|
.arg(QString::number(shot->imgurIndex));
|
||||||
}
|
}
|
||||||
CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"),
|
CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"),
|
||||||
QMessageBox::Information)->exec();
|
QMessageBox::Information)->exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,6 @@ slots:
|
|||||||
|
|
||||||
void reloadStatus();
|
void reloadStatus();
|
||||||
|
|
||||||
void screenshotsUploaded(QList<class ScreenShot*> screenshots);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Runs the DownloadUpdateTask and installs updates.
|
* Runs the DownloadUpdateTask and installs updates.
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
#include "ScreenshotDialog.h"
|
#include "ScreenshotDialog.h"
|
||||||
#include "ui_ScreenshotDialog.h"
|
#include "ui_ScreenshotDialog.h"
|
||||||
#include "QModelIndex"
|
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "ProgressDialog.h"
|
||||||
|
#include "CustomMessageBox.h"
|
||||||
|
#include "logic/net/NetJob.h"
|
||||||
|
#include "logic/net/ScreenshotUploader.h"
|
||||||
|
|
||||||
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) :
|
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@ -16,7 +23,12 @@ ScreenshotDialog::~ScreenshotDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ScreenShot*> ScreenshotDialog::selected()
|
QList<ScreenShot *> ScreenshotDialog::uploaded() const
|
||||||
|
{
|
||||||
|
return m_uploaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ScreenShot*> ScreenshotDialog::selected() const
|
||||||
{
|
{
|
||||||
QList<ScreenShot*> list;
|
QList<ScreenShot*> list;
|
||||||
QList<ScreenShot*> first = m_list->screenshots();
|
QList<ScreenShot*> first = m_list->screenshots();
|
||||||
@ -26,3 +38,29 @@ QList<ScreenShot*> ScreenshotDialog::selected()
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenshotDialog::on_buttonBox_accepted()
|
||||||
|
{
|
||||||
|
QList<ScreenShot *> 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);
|
||||||
|
}
|
||||||
|
@ -18,12 +18,21 @@ public:
|
|||||||
explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0);
|
explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0);
|
||||||
~ScreenshotDialog();
|
~ScreenshotDialog();
|
||||||
|
|
||||||
QList<ScreenShot *> selected();
|
enum
|
||||||
|
{
|
||||||
|
NothingDone = 0x42
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<ScreenShot *> uploaded() const;
|
||||||
|
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
|
void on_buttonBox_accepted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ScreenshotDialog *ui;
|
Ui::ScreenshotDialog *ui;
|
||||||
ScreenshotList *m_list;
|
ScreenshotList *m_list;
|
||||||
|
QList<ScreenShot *> m_uploaded;
|
||||||
|
|
||||||
|
QList<ScreenShot *> selected() const;
|
||||||
};
|
};
|
||||||
|
@ -66,22 +66,6 @@
|
|||||||
<include location="../../resources/multimc/multimc.qrc"/>
|
<include location="../../resources/multimc/multimc.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>accepted()</signal>
|
|
||||||
<receiver>ScreenshotDialog</receiver>
|
|
||||||
<slot>accept()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>248</x>
|
|
||||||
<y>254</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>157</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ScreenshotList.h"
|
#include "ScreenshotList.h"
|
||||||
#include "QDir"
|
#include <QDir>
|
||||||
#include "QIcon"
|
#include <QIcon>
|
||||||
|
|
||||||
ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
|
ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
|
||||||
: QAbstractListModel(parent), m_instance(instance)
|
: 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
|
Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return Qt::ItemIsSelectable;
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task *ScreenshotList::load()
|
Task *ScreenshotList::load()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "ScreenshotUploader.h"
|
#include "ScreenshotUploader.h"
|
||||||
#include "logic/lists/ScreenshotList.h"
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -7,11 +7,13 @@
|
|||||||
#include <QHttpPart>
|
#include <QHttpPart>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "logic/lists/ScreenshotList.h"
|
||||||
#include "URLConstants.h"
|
#include "URLConstants.h"
|
||||||
#include "MultiMC.h"
|
#include "MultiMC.h"
|
||||||
#include "logger/QsLog.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_url = URLConstants::IMGUR_UPLOAD_URL;
|
||||||
m_status = Job_NotStarted;
|
m_status = Job_NotStarted;
|
||||||
@ -26,9 +28,16 @@ void ScreenShotUpload::start()
|
|||||||
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||||
request.setRawHeader("Accept", "application/json");
|
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);
|
QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||||
QHttpPart filePart;
|
QHttpPart filePart;
|
||||||
filePart.setBody(QFile(m_shot->file).readAll().toBase64());
|
filePart.setBody(f.readAll().toBase64());
|
||||||
filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png");
|
filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png");
|
||||||
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\"");
|
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\"");
|
||||||
multipart->append(filePart);
|
multipart->append(filePart);
|
||||||
@ -45,12 +54,10 @@ void ScreenShotUpload::start()
|
|||||||
QNetworkReply *rep = worker->post(request, multipart);
|
QNetworkReply *rep = worker->post(request, multipart);
|
||||||
|
|
||||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||||
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
|
connect(rep, &QNetworkReply::uploadProgress, this, &ScreenShotUpload::downloadProgress);
|
||||||
SLOT(downloadProgress(qint64, qint64)));
|
connect(rep, &QNetworkReply::finished, this, &ScreenShotUpload::downloadFinished);
|
||||||
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
|
|
||||||
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||||
SLOT(downloadError(QNetworkReply::NetworkError)));
|
SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||||
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
|
|
||||||
}
|
}
|
||||||
void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error)
|
void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error)
|
||||||
{
|
{
|
||||||
@ -86,6 +93,7 @@ void ScreenShotUpload::downloadFinished()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QLOG_DEBUG() << m_reply->readAll();
|
||||||
m_reply.reset();
|
m_reply.reset();
|
||||||
emit failed(m_index_within_job);
|
emit failed(m_index_within_job);
|
||||||
return;
|
return;
|
||||||
@ -97,7 +105,3 @@ void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
|||||||
m_progress = bytesReceived;
|
m_progress = bytesReceived;
|
||||||
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
||||||
}
|
}
|
||||||
void ScreenShotUpload::downloadReadyRead()
|
|
||||||
{
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
|
@ -18,7 +18,9 @@ slots:
|
|||||||
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
virtual void downloadError(QNetworkReply::NetworkError error);
|
virtual void downloadError(QNetworkReply::NetworkError error);
|
||||||
virtual void downloadFinished();
|
virtual void downloadFinished();
|
||||||
virtual void downloadReadyRead();
|
virtual void downloadReadyRead()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
|
Loading…
Reference in New Issue
Block a user