sneedmc/gui/dialogs/ScreenshotDialog.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

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