pollymc/gui/dialogs/ScreenshotDialog.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

2014-02-24 02:44:24 +05:30
#include "ScreenshotDialog.h"
#include "ui_ScreenshotDialog.h"
#include <QModelIndex>
2014-02-25 04:10:05 +05:30
#include <QMutableListIterator>
#include "ProgressDialog.h"
#include "CustomMessageBox.h"
#include "logic/net/NetJob.h"
2014-02-25 05:21:24 +05:30
#include "logic/screenshots/ImgurUpload.h"
#include "logic/screenshots/ImgurAlbumCreation.h"
2014-02-24 16:00:27 +05:30
#include "logic/tasks/SequentialTask.h"
2014-02-24 02:44:24 +05:30
2014-02-24 16:00:27 +05:30
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent)
: QDialog(parent), ui(new Ui::ScreenshotDialog), m_list(list)
2014-02-24 02:44:24 +05:30
{
ui->setupUi(this);
ui->listView->setModel(m_list);
}
ScreenshotDialog::~ScreenshotDialog()
{
delete ui;
}
2014-02-24 16:00:27 +05:30
QString ScreenshotDialog::message() const
{
2014-02-24 16:00:27 +05:30
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());
}
2014-02-25 05:21:24 +05:30
QList<ScreenshotPtr> ScreenshotDialog::selected() const
2014-02-24 02:44:24 +05:30
{
2014-02-25 05:21:24 +05:30
QList<ScreenshotPtr> list;
QList<ScreenshotPtr> first = m_list->screenshots();
for (QModelIndex index : ui->listView->selectionModel()->selectedRows())
2014-02-24 02:44:24 +05:30
{
list.append(first.at(index.row()));
}
return list;
}
2014-02-24 15:04:51 +05:30
void ScreenshotDialog::on_uploadBtn_clicked()
{
2014-02-24 16:00:27 +05:30
m_uploaded = selected();
if (m_uploaded.isEmpty())
{
done(NothingDone);
return;
}
2014-02-24 16:00:27 +05:30
SequentialTask *task = new SequentialTask(this);
NetJob *job = new NetJob("Screenshot Upload");
2014-02-25 05:21:24 +05:30
for (auto shot : m_uploaded)
{
2014-02-24 16:00:27 +05:30
job->addNetAction(ImgurUpload::make(shot));
}
2014-02-24 16:00:27 +05:30
NetJob *albumTask = new NetJob("Imgur Album Creation");
albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded));
2014-02-25 05:21:24 +05:30
task->addTask(NetJobPtr(job));
task->addTask(NetJobPtr(albumTask));
ProgressDialog prog(this);
2014-02-24 16:00:27 +05:30
if (prog.exec(task) == QDialog::Accepted)
2014-02-24 15:04:51 +05:30
{
accept();
}
else
{
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
tr("Unknown error"), QMessageBox::Warning)->exec();
reject();
2014-02-24 15:04:51 +05:30
}
}
2014-02-25 04:10:05 +05:30
void ScreenshotDialog::on_deleteBtn_clicked()
{
m_list->deleteSelected(this);
}