2014-02-24 02:44:24 +05:30
|
|
|
#include "ScreenshotDialog.h"
|
|
|
|
#include "ui_ScreenshotDialog.h"
|
2014-02-24 14:04:21 +05:30
|
|
|
|
|
|
|
#include <QModelIndex>
|
2014-02-25 04:10:05 +05:30
|
|
|
#include <QMutableListIterator>
|
2014-02-24 14:04:21 +05:30
|
|
|
|
|
|
|
#include "ProgressDialog.h"
|
|
|
|
#include "CustomMessageBox.h"
|
|
|
|
#include "logic/net/NetJob.h"
|
2014-02-24 16:00:27 +05:30
|
|
|
#include "logic/net/ImgurUpload.h"
|
|
|
|
#include "logic/net/ImgurAlbumCreation.h"
|
|
|
|
#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 14:04:21 +05:30
|
|
|
{
|
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-24 14:04:21 +05:30
|
|
|
}
|
|
|
|
|
2014-02-24 16:00:27 +05:30
|
|
|
QList<ScreenShot *> ScreenshotDialog::selected() const
|
2014-02-24 02:44:24 +05:30
|
|
|
{
|
2014-02-25 04:19:18 +05:30
|
|
|
QList<std::shared_ptr<ScreenShot>> list;
|
|
|
|
QList<std::shared_ptr<ScreenShot>> first = m_list->screenshots();
|
2014-02-24 06:15:59 +05:30
|
|
|
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 14:04:21 +05:30
|
|
|
|
2014-02-24 15:04:51 +05:30
|
|
|
void ScreenshotDialog::on_uploadBtn_clicked()
|
2014-02-24 14:04:21 +05:30
|
|
|
{
|
2014-02-24 16:00:27 +05:30
|
|
|
m_uploaded = selected();
|
|
|
|
if (m_uploaded.isEmpty())
|
2014-02-24 14:04:21 +05:30
|
|
|
{
|
|
|
|
done(NothingDone);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 16:00:27 +05:30
|
|
|
SequentialTask *task = new SequentialTask(this);
|
2014-02-24 14:04:21 +05:30
|
|
|
NetJob *job = new NetJob("Screenshot Upload");
|
2014-02-25 04:19:18 +05:30
|
|
|
for (std::shared_ptr<ScreenShot> shot : m_uploaded)
|
2014-02-24 14:04:21 +05:30
|
|
|
{
|
2014-02-24 16:00:27 +05:30
|
|
|
job->addNetAction(ImgurUpload::make(shot));
|
2014-02-24 14:04:21 +05:30
|
|
|
}
|
2014-02-24 16:00:27 +05:30
|
|
|
NetJob *albumTask = new NetJob("Imgur Album Creation");
|
|
|
|
albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded));
|
|
|
|
task->addTask(std::shared_ptr<NetJob>(job));
|
|
|
|
task->addTask(std::shared_ptr<NetJob>(albumTask));
|
2014-02-24 14:04:21 +05:30
|
|
|
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
|
2014-02-24 14:04:21 +05:30
|
|
|
{
|
|
|
|
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-24 14:04:21 +05:30
|
|
|
}
|
2014-02-25 04:10:05 +05:30
|
|
|
|
|
|
|
void ScreenshotDialog::on_deleteBtn_clicked()
|
|
|
|
{
|
|
|
|
m_list->deleteSelected(this);
|
|
|
|
}
|