Turn screenshot management into a page.
This commit is contained in:
parent
30b1f5e5cf
commit
e8731c5d01
@ -309,6 +309,8 @@ SET(MULTIMC_SOURCES
|
|||||||
gui/pages/LegacyJarModPage.h
|
gui/pages/LegacyJarModPage.h
|
||||||
gui/pages/InstanceSettingsPage.cpp
|
gui/pages/InstanceSettingsPage.cpp
|
||||||
gui/pages/InstanceSettingsPage.h
|
gui/pages/InstanceSettingsPage.h
|
||||||
|
gui/pages/ScreenshotsPage.cpp
|
||||||
|
gui/pages/ScreenshotsPage.h
|
||||||
|
|
||||||
# GUI - dialogs
|
# GUI - dialogs
|
||||||
gui/dialogs/AboutDialog.cpp
|
gui/dialogs/AboutDialog.cpp
|
||||||
@ -337,8 +339,6 @@ SET(MULTIMC_SOURCES
|
|||||||
gui/dialogs/NotificationDialog.h
|
gui/dialogs/NotificationDialog.h
|
||||||
gui/dialogs/ProgressDialog.cpp
|
gui/dialogs/ProgressDialog.cpp
|
||||||
gui/dialogs/ProgressDialog.h
|
gui/dialogs/ProgressDialog.h
|
||||||
gui/dialogs/ScreenshotDialog.cpp
|
|
||||||
gui/dialogs/ScreenshotDialog.h
|
|
||||||
gui/dialogs/SettingsDialog.cpp
|
gui/dialogs/SettingsDialog.cpp
|
||||||
gui/dialogs/SettingsDialog.h
|
gui/dialogs/SettingsDialog.h
|
||||||
gui/dialogs/UpdateDialog.cpp
|
gui/dialogs/UpdateDialog.cpp
|
||||||
@ -529,9 +529,6 @@ SET(MULTIMC_SOURCES
|
|||||||
|
|
||||||
# the screenshots feature
|
# the screenshots feature
|
||||||
logic/screenshots/Screenshot.h
|
logic/screenshots/Screenshot.h
|
||||||
logic/screenshots/Screenshot.cpp
|
|
||||||
logic/screenshots/ScreenshotList.h
|
|
||||||
logic/screenshots/ScreenshotList.cpp
|
|
||||||
logic/screenshots/ImgurUpload.h
|
logic/screenshots/ImgurUpload.h
|
||||||
logic/screenshots/ImgurUpload.cpp
|
logic/screenshots/ImgurUpload.cpp
|
||||||
logic/screenshots/ImgurAlbumCreation.h
|
logic/screenshots/ImgurAlbumCreation.h
|
||||||
@ -616,6 +613,7 @@ SET(MULTIMC_UIS
|
|||||||
gui/pages/LegacyJarModPage.ui
|
gui/pages/LegacyJarModPage.ui
|
||||||
gui/pages/InstanceSettingsPage.ui
|
gui/pages/InstanceSettingsPage.ui
|
||||||
gui/pages/NotesPage.ui
|
gui/pages/NotesPage.ui
|
||||||
|
gui/pages/ScreenshotsPage.ui
|
||||||
|
|
||||||
# Dialogs
|
# Dialogs
|
||||||
gui/dialogs/SettingsDialog.ui
|
gui/dialogs/SettingsDialog.ui
|
||||||
@ -631,7 +629,6 @@ SET(MULTIMC_UIS
|
|||||||
gui/dialogs/EditAccountDialog.ui
|
gui/dialogs/EditAccountDialog.ui
|
||||||
gui/dialogs/LoginDialog.ui
|
gui/dialogs/LoginDialog.ui
|
||||||
gui/dialogs/UpdateDialog.ui
|
gui/dialogs/UpdateDialog.ui
|
||||||
gui/dialogs/ScreenshotDialog.ui
|
|
||||||
gui/dialogs/NotificationDialog.ui
|
gui/dialogs/NotificationDialog.ui
|
||||||
|
|
||||||
# Widgets/other
|
# Widgets/other
|
||||||
|
@ -138,10 +138,10 @@ void openDirInDefaultProgram(QString path, bool ensureExists)
|
|||||||
{
|
{
|
||||||
parentPath.mkpath(dir.absolutePath());
|
parentPath.mkpath(dir.absolutePath());
|
||||||
}
|
}
|
||||||
QDesktopServices::openUrl("file:///" + dir.absolutePath());
|
QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void openFileInDefaultProgram(QString filename)
|
void openFileInDefaultProgram(QString filename)
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl("file:///" + QFileInfo(filename).absolutePath());
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <gui/Platform.h>
|
#include <gui/Platform.h>
|
||||||
#include <gui/dialogs/CustomMessageBox.h>
|
#include <gui/dialogs/CustomMessageBox.h>
|
||||||
#include <gui/dialogs/ProgressDialog.h>
|
#include <gui/dialogs/ProgressDialog.h>
|
||||||
#include "dialogs/ScreenshotDialog.h"
|
|
||||||
|
|
||||||
#include "logic/net/PasteUpload.h"
|
#include "logic/net/PasteUpload.h"
|
||||||
#include "logic/icons/IconList.h"
|
#include "logic/icons/IconList.h"
|
||||||
@ -174,22 +173,6 @@ void ConsoleWindow::on_closeButton_clicked()
|
|||||||
|
|
||||||
void ConsoleWindow::on_btnScreenshots_clicked()
|
void ConsoleWindow::on_btnScreenshots_clicked()
|
||||||
{
|
{
|
||||||
ScreenshotList *list = new ScreenshotList(proc->instance());
|
|
||||||
Task *task = list->load();
|
|
||||||
ProgressDialog prog(this);
|
|
||||||
prog.exec(task);
|
|
||||||
if (!task->successful())
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
|
|
||||||
task->failReason(), QMessageBox::Warning)->exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ScreenshotDialog dialog(list, this);
|
|
||||||
if (dialog.exec() == ScreenshotDialog::Accepted)
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(),
|
|
||||||
QMessageBox::Information)->exec();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleWindow::setMayClose(bool mayclose)
|
void ConsoleWindow::setMayClose(bool mayclose)
|
||||||
|
@ -63,7 +63,6 @@
|
|||||||
#include "gui/dialogs/UpdateDialog.h"
|
#include "gui/dialogs/UpdateDialog.h"
|
||||||
#include "gui/dialogs/EditAccountDialog.h"
|
#include "gui/dialogs/EditAccountDialog.h"
|
||||||
#include "gui/dialogs/NotificationDialog.h"
|
#include "gui/dialogs/NotificationDialog.h"
|
||||||
#include "dialogs/ScreenshotDialog.h"
|
|
||||||
|
|
||||||
#include "gui/ConsoleWindow.h"
|
#include "gui/ConsoleWindow.h"
|
||||||
#include "pagedialog/PageDialog.h"
|
#include "pagedialog/PageDialog.h"
|
||||||
@ -969,6 +968,12 @@ void MainWindow::on_actionEditInstance_triggered()
|
|||||||
ShowPageDialog(m_selectedInstance, this);
|
ShowPageDialog(m_selectedInstance, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionScreenshots_triggered()
|
||||||
|
{
|
||||||
|
ShowPageDialog(m_selectedInstance, this, "screenshots");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionManageAccounts_triggered()
|
void MainWindow::on_actionManageAccounts_triggered()
|
||||||
{
|
{
|
||||||
AccountListDialog dialog(this);
|
AccountListDialog dialog(this);
|
||||||
@ -1510,25 +1515,3 @@ void MainWindow::checkSetDefaultJava()
|
|||||||
MMC->settings()->set("JavaPath", QString("java"));
|
MMC->settings()->set("JavaPath", QString("java"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionScreenshots_triggered()
|
|
||||||
{
|
|
||||||
if (!m_selectedInstance)
|
|
||||||
return;
|
|
||||||
ScreenshotList *list = new ScreenshotList(m_selectedInstance);
|
|
||||||
Task *task = list->load();
|
|
||||||
ProgressDialog prog(this);
|
|
||||||
prog.exec(task);
|
|
||||||
if (!task->successful())
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
|
|
||||||
task->failReason(), QMessageBox::Warning)->exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ScreenshotDialog dialog(list, this);
|
|
||||||
if (dialog.exec() == ScreenshotDialog::Accepted)
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(),
|
|
||||||
QMessageBox::Information)->exec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
#include "ScreenshotDialog.h"
|
|
||||||
#include "ui_ScreenshotDialog.h"
|
|
||||||
|
|
||||||
#include <QModelIndex>
|
|
||||||
#include <QMutableListIterator>
|
|
||||||
|
|
||||||
#include "ProgressDialog.h"
|
|
||||||
#include "CustomMessageBox.h"
|
|
||||||
#include "logic/net/NetJob.h"
|
|
||||||
#include "logic/screenshots/ImgurUpload.h"
|
|
||||||
#include "logic/screenshots/ImgurAlbumCreation.h"
|
|
||||||
#include "logic/tasks/SequentialTask.h"
|
|
||||||
|
|
||||||
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent)
|
|
||||||
: QDialog(parent), ui(new Ui::ScreenshotDialog), m_list(list)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
|
||||||
ui->listView->setModel(m_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenshotDialog::~ScreenshotDialog()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ScreenshotDialog::message() const
|
|
||||||
{
|
|
||||||
return tr("<a href=\"https://imgur.com/a/%1\">Visit album</a><br/>Delete hash: %2 (save "
|
|
||||||
"this if you want to be able to edit/delete the album)")
|
|
||||||
.arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash());
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<ScreenshotPtr> ScreenshotDialog::selected() const
|
|
||||||
{
|
|
||||||
QList<ScreenshotPtr> list;
|
|
||||||
QList<ScreenshotPtr> first = m_list->screenshots();
|
|
||||||
for (QModelIndex index : ui->listView->selectionModel()->selectedRows())
|
|
||||||
{
|
|
||||||
list.append(first.at(index.row()));
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenshotDialog::on_uploadBtn_clicked()
|
|
||||||
{
|
|
||||||
m_uploaded = selected();
|
|
||||||
if (m_uploaded.isEmpty())
|
|
||||||
{
|
|
||||||
done(NothingDone);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SequentialTask *task = new SequentialTask(this);
|
|
||||||
NetJob *job = new NetJob("Screenshot Upload");
|
|
||||||
for (auto shot : m_uploaded)
|
|
||||||
{
|
|
||||||
job->addNetAction(ImgurUpload::make(shot));
|
|
||||||
}
|
|
||||||
NetJob *albumTask = new NetJob("Imgur Album Creation");
|
|
||||||
albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded));
|
|
||||||
task->addTask(NetJobPtr(job));
|
|
||||||
task->addTask(NetJobPtr(albumTask));
|
|
||||||
ProgressDialog prog(this);
|
|
||||||
if (prog.exec(task) == QDialog::Accepted)
|
|
||||||
{
|
|
||||||
accept();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
|
|
||||||
tr("Unknown error"), QMessageBox::Warning)->exec();
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenshotDialog::on_deleteBtn_clicked()
|
|
||||||
{
|
|
||||||
m_list->deleteSelected(this);
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include "logic/screenshots/ScreenshotList.h"
|
|
||||||
|
|
||||||
class ImgurAlbumCreation;
|
|
||||||
|
|
||||||
namespace Ui
|
|
||||||
{
|
|
||||||
class ScreenshotDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ScreenshotDialog : public QDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0);
|
|
||||||
~ScreenshotDialog();
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
NothingDone = 0x42
|
|
||||||
};
|
|
||||||
|
|
||||||
QString message() const;
|
|
||||||
QList<ScreenshotPtr> selected() const;
|
|
||||||
|
|
||||||
private
|
|
||||||
slots:
|
|
||||||
void on_uploadBtn_clicked();
|
|
||||||
|
|
||||||
void on_deleteBtn_clicked();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::ScreenshotDialog *ui;
|
|
||||||
ScreenshotList *m_list;
|
|
||||||
QList<ScreenshotPtr> m_uploaded;
|
|
||||||
std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum;
|
|
||||||
};
|
|
@ -1,110 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>ScreenshotDialog</class>
|
|
||||||
<widget class="QDialog" name="ScreenshotDialog">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>470</width>
|
|
||||||
<height>300</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Screenshot Manager</string>
|
|
||||||
</property>
|
|
||||||
<property name="windowIcon">
|
|
||||||
<iconset resource="../../resources/multimc/multimc.qrc">
|
|
||||||
<normaloff>:/icons/multimc/scalable/apps/multimc.svg</normaloff>:/icons/multimc/scalable/apps/multimc.svg</iconset>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QListView" name="listView">
|
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="selectionBehavior">
|
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize">
|
|
||||||
<size>
|
|
||||||
<width>120</width>
|
|
||||||
<height>90</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="flow">
|
|
||||||
<enum>QListView::LeftToRight</enum>
|
|
||||||
</property>
|
|
||||||
<property name="isWrapping" stdset="0">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="resizeMode">
|
|
||||||
<enum>QListView::Adjust</enum>
|
|
||||||
</property>
|
|
||||||
<property name="viewMode">
|
|
||||||
<enum>QListView::IconMode</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="uploadBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Upload</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="deleteBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Delete</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="closeBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Close</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources>
|
|
||||||
<include location="../../resources/multimc/multimc.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections>
|
|
||||||
<connection>
|
|
||||||
<sender>closeBtn</sender>
|
|
||||||
<signal>clicked()</signal>
|
|
||||||
<receiver>ScreenshotDialog</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>315</x>
|
|
||||||
<y>272</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>271</x>
|
|
||||||
<y>258</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
</ui>
|
|
@ -159,6 +159,7 @@ void PageDialog::showPage(int row)
|
|||||||
m_pageStack->setCurrentIndex(m_currentPage->stackIndex);
|
m_pageStack->setCurrentIndex(m_currentPage->stackIndex);
|
||||||
m_header->setText(m_currentPage->displayName());
|
m_header->setText(m_currentPage->displayName());
|
||||||
m_iconHeader->setIcon(m_currentPage->icon());
|
m_iconHeader->setIcon(m_currentPage->icon());
|
||||||
|
m_currentPage->opened();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,10 @@ public:
|
|||||||
virtual QString helpPage()
|
virtual QString helpPage()
|
||||||
{
|
{
|
||||||
return QString();
|
return QString();
|
||||||
|
}
|
||||||
|
virtual void opened()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
int stackIndex = -1;
|
int stackIndex = -1;
|
||||||
int listIndex = -1;
|
int listIndex = -1;
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <gui/pages/TexturePackPage.h>
|
#include <gui/pages/TexturePackPage.h>
|
||||||
#include <gui/pages/InstanceSettingsPage.h>
|
#include <gui/pages/InstanceSettingsPage.h>
|
||||||
#include <gui/pages/NotesPage.h>
|
#include <gui/pages/NotesPage.h>
|
||||||
|
#include <gui/pages/ScreenshotsPage.h>
|
||||||
|
|
||||||
LegacyInstance::LegacyInstance(const QString &rootDir, SettingsObject *settings,
|
LegacyInstance::LegacyInstance(const QString &rootDir, SettingsObject *settings,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
@ -57,6 +58,7 @@ QList<BasePage *> LegacyInstance::getPages()
|
|||||||
"Core-mods"));
|
"Core-mods"));
|
||||||
values.append(new TexturePackPage(this));
|
values.append(new TexturePackPage(this));
|
||||||
values.append(new NotesPage(this));
|
values.append(new NotesPage(this));
|
||||||
|
values.append(new ScreenshotsPage(this));
|
||||||
values.append(new InstanceSettingsPage(&settings()));
|
values.append(new InstanceSettingsPage(&settings()));
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <gui/pages/TexturePackPage.h>
|
#include <gui/pages/TexturePackPage.h>
|
||||||
#include <gui/pages/InstanceSettingsPage.h>
|
#include <gui/pages/InstanceSettingsPage.h>
|
||||||
#include <gui/pages/NotesPage.h>
|
#include <gui/pages/NotesPage.h>
|
||||||
|
#include <gui/pages/ScreenshotsPage.h>
|
||||||
|
|
||||||
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
|
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
@ -69,6 +70,7 @@ QList<BasePage *> OneSixInstance::getPages()
|
|||||||
values.append(new ResourcePackPage(this));
|
values.append(new ResourcePackPage(this));
|
||||||
values.append(new TexturePackPage(this));
|
values.append(new TexturePackPage(this));
|
||||||
values.append(new NotesPage(this));
|
values.append(new NotesPage(this));
|
||||||
|
values.append(new ScreenshotsPage(this));
|
||||||
values.append(new InstanceSettingsPage(&settings()));
|
values.append(new InstanceSettingsPage(&settings()));
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "logic/screenshots//ScreenshotList.h"
|
|
||||||
#include "logic/net/URLConstants.h"
|
#include "logic/net/URLConstants.h"
|
||||||
#include "MultiMC.h"
|
#include "MultiMC.h"
|
||||||
#include "logger/QsLog.h"
|
#include "logger/QsLog.h"
|
||||||
@ -28,7 +27,7 @@ void ImgurAlbumCreation::start()
|
|||||||
QStringList ids;
|
QStringList ids;
|
||||||
for (auto shot : m_screenshots)
|
for (auto shot : m_screenshots)
|
||||||
{
|
{
|
||||||
ids.append(shot->imgurId);
|
ids.append(shot->m_imgurId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
|
const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "logic/screenshots/ScreenshotList.h"
|
|
||||||
#include "logic/net/URLConstants.h"
|
#include "logic/net/URLConstants.h"
|
||||||
#include "MultiMC.h"
|
#include "MultiMC.h"
|
||||||
#include "logger/QsLog.h"
|
#include "logger/QsLog.h"
|
||||||
@ -27,7 +26,7 @@ void ImgurUpload::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);
|
QFile f(m_shot->m_file.absoluteFilePath());
|
||||||
if (!f.open(QFile::ReadOnly))
|
if (!f.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
emit failed(m_index_within_job);
|
emit failed(m_index_within_job);
|
||||||
@ -46,7 +45,7 @@ void ImgurUpload::start()
|
|||||||
multipart->append(typePart);
|
multipart->append(typePart);
|
||||||
QHttpPart namePart;
|
QHttpPart namePart;
|
||||||
namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\"");
|
namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\"");
|
||||||
namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8());
|
namePart.setBody(m_shot->m_file.baseName().toUtf8());
|
||||||
multipart->append(namePart);
|
multipart->append(namePart);
|
||||||
|
|
||||||
auto worker = MMC->qnam();
|
auto worker = MMC->qnam();
|
||||||
@ -84,8 +83,8 @@ void ImgurUpload::downloadFinished()
|
|||||||
emit failed(m_index_within_job);
|
emit failed(m_index_within_job);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_shot->imgurId = object.value("data").toObject().value("id").toString();
|
m_shot->m_imgurId = object.value("data").toObject().value("id").toString();
|
||||||
m_shot->url = object.value("data").toObject().value("link").toString();
|
m_shot->m_url = object.value("data").toObject().value("link").toString();
|
||||||
m_status = Job_Finished;
|
m_status = Job_Finished;
|
||||||
emit succeeded(m_index_within_job);
|
emit succeeded(m_index_within_job);
|
||||||
return;
|
return;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#include "Screenshot.h"
|
|
||||||
#include <QImage>
|
|
||||||
#include <QIcon>
|
|
||||||
QIcon ScreenShot::getImage()
|
|
||||||
{
|
|
||||||
if(!imageloaded)
|
|
||||||
{
|
|
||||||
QImage image(file);
|
|
||||||
QImage thumbnail = image.scaledToWidth(256, Qt::SmoothTransformation);
|
|
||||||
m_image = QIcon(QPixmap::fromImage(thumbnail));
|
|
||||||
imageloaded = true;
|
|
||||||
}
|
|
||||||
return m_image;
|
|
||||||
}
|
|
@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QIcon>
|
|
||||||
|
|
||||||
struct ScreenShot
|
struct ScreenShot
|
||||||
{
|
{
|
||||||
QIcon getImage();
|
ScreenShot(QFileInfo file)
|
||||||
QIcon m_image;
|
{
|
||||||
bool imageloaded = false;
|
m_file = file;
|
||||||
QDateTime timestamp;
|
}
|
||||||
QString file;
|
QFileInfo m_file;
|
||||||
QString url;
|
QString m_url;
|
||||||
QString imgurId;
|
QString m_imgurId;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<ScreenShot> ScreenshotPtr;
|
typedef std::shared_ptr<ScreenShot> ScreenshotPtr;
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
#include "ScreenshotList.h"
|
|
||||||
#include "gui/dialogs/ScreenshotDialog.h"
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QList>
|
|
||||||
#include "gui/dialogs/ProgressDialog.h"
|
|
||||||
#include "gui/dialogs/CustomMessageBox.h"
|
|
||||||
|
|
||||||
ScreenshotList::ScreenshotList(InstancePtr instance, QObject *parent)
|
|
||||||
: QAbstractListModel(parent), m_instance(instance)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int ScreenshotList::rowCount(const QModelIndex &) const
|
|
||||||
{
|
|
||||||
return m_screenshots.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ScreenshotList::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (index.row() >= m_screenshots.size() || index.row() < 0)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
switch (role)
|
|
||||||
{
|
|
||||||
case Qt::DecorationRole:
|
|
||||||
return m_screenshots.at(index.row())->getImage();
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
|
|
||||||
case Qt::TextAlignmentRole:
|
|
||||||
return (int)(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
Task *ScreenshotList::load()
|
|
||||||
{
|
|
||||||
return new ScreenshotLoadTask(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenshotLoadTask::ScreenshotLoadTask(ScreenshotList *list) : m_list(list)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenshotLoadTask::~ScreenshotLoadTask()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenshotLoadTask::executeTask()
|
|
||||||
{
|
|
||||||
auto dir = QDir(m_list->instance()->minecraftRoot());
|
|
||||||
if (!dir.cd("screenshots"))
|
|
||||||
{
|
|
||||||
emitFailed("Selected instance does not have any screenshots!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dir.setNameFilters(QStringList() << "*.png");
|
|
||||||
this->m_results.clear();
|
|
||||||
for (auto file : dir.entryList())
|
|
||||||
{
|
|
||||||
ScreenShot *shot = new ScreenShot();
|
|
||||||
shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
|
|
||||||
shot->file = dir.absoluteFilePath(file);
|
|
||||||
m_results.append(ScreenshotPtr(shot));
|
|
||||||
}
|
|
||||||
m_list->loadShots(m_results);
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
|
|
||||||
{
|
|
||||||
auto screens = dialog->selected();
|
|
||||||
if (screens.isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
beginResetModel();
|
|
||||||
QList<std::shared_ptr<ScreenShot>>::const_iterator it;
|
|
||||||
for (it = screens.cbegin(); it != screens.cend(); it++)
|
|
||||||
{
|
|
||||||
auto shot = *it;
|
|
||||||
if (!QFile(shot->file).remove())
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(dialog, tr("Error!"),
|
|
||||||
tr("Failed to delete screenshots!"),
|
|
||||||
QMessageBox::Warning)->exec();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ProgressDialog refresh(dialog);
|
|
||||||
Task *t = load();
|
|
||||||
if (refresh.exec(t) != QDialog::Accepted)
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(dialog, tr("Error!"),
|
|
||||||
tr("Unable to refresh list: %1").arg(t->failReason()),
|
|
||||||
QMessageBox::Warning)->exec();
|
|
||||||
}
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include "logic/BaseInstance.h"
|
|
||||||
#include "logic/tasks/Task.h"
|
|
||||||
|
|
||||||
#include "Screenshot.h"
|
|
||||||
|
|
||||||
class ScreenshotList : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ScreenshotList(InstancePtr instance, QObject *parent = 0);
|
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const;
|
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
||||||
|
|
||||||
Task *load();
|
|
||||||
|
|
||||||
void loadShots(QList<ScreenshotPtr> shots)
|
|
||||||
{
|
|
||||||
m_screenshots = shots;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<ScreenshotPtr> screenshots() const
|
|
||||||
{
|
|
||||||
return m_screenshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
InstancePtr instance() const
|
|
||||||
{
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteSelected(class ScreenshotDialog *dialog);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public
|
|
||||||
slots:
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<ScreenshotPtr> m_screenshots;
|
|
||||||
InstancePtr m_instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ScreenshotLoadTask : public Task
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ScreenshotLoadTask(ScreenshotList *list);
|
|
||||||
~ScreenshotLoadTask();
|
|
||||||
|
|
||||||
QList<ScreenshotPtr> screenShots() const
|
|
||||||
{
|
|
||||||
return m_results;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void executeTask();
|
|
||||||
|
|
||||||
private:
|
|
||||||
ScreenshotList *m_list;
|
|
||||||
QList<ScreenshotPtr> m_results;
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user