Reorganize all the screenshot files

This commit is contained in:
Petr Mrázek 2014-02-25 00:51:24 +01:00
parent b1cddb4600
commit cb5cfe7242
10 changed files with 60 additions and 49 deletions

View File

@ -372,10 +372,6 @@ logic/net/HttpMetaCache.cpp
logic/net/PasteUpload.h logic/net/PasteUpload.h
logic/net/PasteUpload.cpp logic/net/PasteUpload.cpp
logic/net/URLConstants.h logic/net/URLConstants.h
logic/net/ImgurUpload.h
logic/net/ImgurUpload.cpp
logic/net/ImgurAlbumCreation.h
logic/net/ImgurAlbumCreation.cpp
# Yggdrasil login stuff # Yggdrasil login stuff
logic/auth/AuthSession.h logic/auth/AuthSession.h
@ -466,8 +462,15 @@ logic/lists/ForgeVersionList.h
logic/lists/ForgeVersionList.cpp logic/lists/ForgeVersionList.cpp
logic/lists/JavaVersionList.h logic/lists/JavaVersionList.h
logic/lists/JavaVersionList.cpp logic/lists/JavaVersionList.cpp
logic/lists/ScreenshotList.h
logic/lists/ScreenshotList.cpp # the screenshots feature
logic/screenshots/Screenshot.h
logic/screenshots/ScreenshotList.h
logic/screenshots/ScreenshotList.cpp
logic/screenshots/ImgurUpload.h
logic/screenshots/ImgurUpload.cpp
logic/screenshots/ImgurAlbumCreation.h
logic/screenshots/ImgurAlbumCreation.cpp
# Icons # Icons
logic/icons/MMCIcon.h logic/icons/MMCIcon.h

View File

@ -7,8 +7,8 @@
#include "ProgressDialog.h" #include "ProgressDialog.h"
#include "CustomMessageBox.h" #include "CustomMessageBox.h"
#include "logic/net/NetJob.h" #include "logic/net/NetJob.h"
#include "logic/net/ImgurUpload.h" #include "logic/screenshots/ImgurUpload.h"
#include "logic/net/ImgurAlbumCreation.h" #include "logic/screenshots/ImgurAlbumCreation.h"
#include "logic/tasks/SequentialTask.h" #include "logic/tasks/SequentialTask.h"
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent)
@ -30,10 +30,10 @@ QString ScreenshotDialog::message() const
.arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash()); .arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash());
} }
QList<ScreenShot *> ScreenshotDialog::selected() const QList<ScreenshotPtr> ScreenshotDialog::selected() const
{ {
QList<std::shared_ptr<ScreenShot>> list; QList<ScreenshotPtr> list;
QList<std::shared_ptr<ScreenShot>> first = m_list->screenshots(); QList<ScreenshotPtr> first = m_list->screenshots();
for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) for (QModelIndex index : ui->listView->selectionModel()->selectedRows())
{ {
list.append(first.at(index.row())); list.append(first.at(index.row()));
@ -51,14 +51,14 @@ void ScreenshotDialog::on_uploadBtn_clicked()
} }
SequentialTask *task = new SequentialTask(this); SequentialTask *task = new SequentialTask(this);
NetJob *job = new NetJob("Screenshot Upload"); NetJob *job = new NetJob("Screenshot Upload");
for (std::shared_ptr<ScreenShot> shot : m_uploaded) for (auto shot : m_uploaded)
{ {
job->addNetAction(ImgurUpload::make(shot)); job->addNetAction(ImgurUpload::make(shot));
} }
NetJob *albumTask = new NetJob("Imgur Album Creation"); NetJob *albumTask = new NetJob("Imgur Album Creation");
albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded)); albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded));
task->addTask(std::shared_ptr<NetJob>(job)); task->addTask(NetJobPtr(job));
task->addTask(std::shared_ptr<NetJob>(albumTask)); task->addTask(NetJobPtr(albumTask));
ProgressDialog prog(this); ProgressDialog prog(this);
if (prog.exec(task) == QDialog::Accepted) if (prog.exec(task) == QDialog::Accepted)
{ {

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include "logic/lists/ScreenshotList.h" #include "logic/screenshots/ScreenshotList.h"
class ImgurAlbumCreation; class ImgurAlbumCreation;
@ -24,7 +24,7 @@ public:
}; };
QString message() const; QString message() const;
QList<std::shared_ptr<ScreenShot>> selected() const; QList<ScreenshotPtr> selected() const;
private private
slots: slots:
@ -35,6 +35,6 @@ slots:
private: private:
Ui::ScreenshotDialog *ui; Ui::ScreenshotDialog *ui;
ScreenshotList *m_list; ScreenshotList *m_list;
QList<std::shared_ptr<ScreenShot>> m_uploaded; QList<ScreenshotPtr> m_uploaded;
std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum; std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum;
}; };

View File

@ -5,12 +5,12 @@
#include <QJsonObject> #include <QJsonObject>
#include <QUrl> #include <QUrl>
#include "logic/lists/ScreenshotList.h" #include "logic/screenshots//ScreenshotList.h"
#include "URLConstants.h" #include "logic/net/URLConstants.h"
#include "MultiMC.h" #include "MultiMC.h"
#include "logger/QsLog.h" #include "logger/QsLog.h"
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenShot *> screenshots) : NetAction(), m_screenshots(screenshots) ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
{ {
m_url = URLConstants::IMGUR_BASE_URL + "album.json"; m_url = URLConstants::IMGUR_BASE_URL + "album.json";
m_status = Job_NotStarted; m_status = Job_NotStarted;

View File

@ -1,13 +1,13 @@
#pragma once #pragma once
#include "NetAction.h" #include "logic/net/NetAction.h"
#include "Screenshot.h"
class ScreenShot;
typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr; typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
class ImgurAlbumCreation : public NetAction class ImgurAlbumCreation : public NetAction
{ {
public: public:
explicit ImgurAlbumCreation(QList<ScreenShot *> screenshots); explicit ImgurAlbumCreation(QList<ScreenshotPtr> screenshots);
static ImgurAlbumCreationPtr make(QList<ScreenShot *> screenshots) static ImgurAlbumCreationPtr make(QList<ScreenshotPtr> screenshots)
{ {
return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots));
} }
@ -35,7 +35,7 @@ slots:
virtual void start(); virtual void start();
private: private:
QList<ScreenShot *> m_screenshots; QList<ScreenshotPtr> m_screenshots;
QString m_deleteHash; QString m_deleteHash;
QString m_id; QString m_id;

View File

@ -8,12 +8,12 @@
#include <QFile> #include <QFile>
#include <QUrl> #include <QUrl>
#include "logic/lists/ScreenshotList.h" #include "logic/screenshots/ScreenshotList.h"
#include "URLConstants.h" #include "logic/net/URLConstants.h"
#include "MultiMC.h" #include "MultiMC.h"
#include "logger/QsLog.h" #include "logger/QsLog.h"
ImgurUpload::ImgurUpload(ScreenShot *shot) : NetAction(), m_shot(shot) ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
{ {
m_url = URLConstants::IMGUR_BASE_URL + "upload.json"; m_url = URLConstants::IMGUR_BASE_URL + "upload.json";
m_status = Job_NotStarted; m_status = Job_NotStarted;

View File

@ -1,13 +1,13 @@
#pragma once #pragma once
#include "NetAction.h" #include "logic/net/NetAction.h"
#include "Screenshot.h"
class ScreenShot;
typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr; typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr;
class ImgurUpload : public NetAction class ImgurUpload : public NetAction
{ {
public: public:
explicit ImgurUpload(ScreenShot *shot); explicit ImgurUpload(ScreenshotPtr shot);
static ImgurUploadPtr make(ScreenShot *shot) static ImgurUploadPtr make(ScreenshotPtr shot)
{ {
return ImgurUploadPtr(new ImgurUpload(shot)); return ImgurUploadPtr(new ImgurUpload(shot));
} }
@ -26,5 +26,5 @@ slots:
virtual void start(); virtual void start();
private: private:
ScreenShot *m_shot; ScreenshotPtr m_shot;
}; };

View File

@ -0,0 +1,15 @@
#pragma once
#include <QDateTime>
#include <QString>
#include <memory>
struct ScreenShot
{
QDateTime timestamp;
QString file;
QString url;
QString imgurId;
};
typedef std::shared_ptr<ScreenShot> ScreenshotPtr;

View File

@ -69,13 +69,13 @@ void ScreenshotLoadTask::executeTask()
return; return;
} }
dir.setNameFilters(QStringList() << "*.png"); dir.setNameFilters(QStringList() << "*.png");
this->m_results = QList<ScreenShot *>(); this->m_results.clear();
for (auto file : dir.entryList()) for (auto file : dir.entryList())
{ {
ScreenShot *shot = new ScreenShot(); ScreenShot *shot = new ScreenShot();
shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png"); shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
shot->file = dir.absoluteFilePath(file); shot->file = dir.absoluteFilePath(file);
m_results.append(shot); m_results.append(ScreenshotPtr(shot));
} }
m_list->loadShots(m_results); m_list->loadShots(m_results);
emitSucceeded(); emitSucceeded();
@ -91,7 +91,7 @@ void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
QList<std::shared_ptr<ScreenShot>>::const_iterator it; QList<std::shared_ptr<ScreenShot>>::const_iterator it;
for (it = screens.cbegin(); it != screens.cend(); it++) for (it = screens.cbegin(); it != screens.cend(); it++)
{ {
std::shared_ptr<ScreenShot> = *it; auto shot = *it;
if (!QFile(shot->file).remove()) if (!QFile(shot->file).remove())
{ {
CustomMessageBox::selectable(dialog, tr("Error!"), CustomMessageBox::selectable(dialog, tr("Error!"),

View File

@ -4,14 +4,7 @@
#include "logic/BaseInstance.h" #include "logic/BaseInstance.h"
#include "logic/tasks/Task.h" #include "logic/tasks/Task.h"
class ScreenShot #include "Screenshot.h"
{
public:
QDateTime timestamp;
QString file;
QString url;
QString imgurId;
};
class ScreenshotList : public QAbstractListModel class ScreenshotList : public QAbstractListModel
{ {
@ -28,12 +21,12 @@ public:
Task *load(); Task *load();
void loadShots(QList<ScreenShot *> shots) void loadShots(QList<ScreenshotPtr> shots)
{ {
m_screenshots = shots; m_screenshots = shots;
} }
QList<ScreenShot *> screenshots() const QList<ScreenshotPtr> screenshots() const
{ {
return m_screenshots; return m_screenshots;
} }
@ -51,7 +44,7 @@ public
slots: slots:
private: private:
QList<ScreenShot *> m_screenshots; QList<ScreenshotPtr> m_screenshots;
BaseInstance *m_instance; BaseInstance *m_instance;
}; };
@ -63,7 +56,7 @@ public:
explicit ScreenshotLoadTask(ScreenshotList *list); explicit ScreenshotLoadTask(ScreenshotList *list);
~ScreenshotLoadTask(); ~ScreenshotLoadTask();
QList<ScreenShot *> screenShots() const QList<ScreenshotPtr> screenShots() const
{ {
return m_results; return m_results;
} }
@ -73,5 +66,5 @@ protected:
private: private:
ScreenshotList *m_list; ScreenshotList *m_list;
QList<ScreenShot *> m_results; QList<ScreenshotPtr> m_results;
}; };