summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/ScreenshotDialog.cpp
blob: 33e9316293c9fa0a90f8b32bfd4e81cf636dc966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "ScreenshotDialog.h"
#include "ui_ScreenshotDialog.h"

#include <QModelIndex>
#include <QDebug>

#include "ProgressDialog.h"
#include "CustomMessageBox.h"
#include "logic/net/NetJob.h"
#include "logic/net/ScreenshotUploader.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;
}

QList<ScreenShot *> ScreenshotDialog::uploaded() const
{
	return m_uploaded;
}

QList<ScreenShot*> ScreenshotDialog::selected() const
{
	QList<ScreenShot*> list;
	QList<ScreenShot*> first = m_list->screenshots();
	for (QModelIndex index : ui->listView->selectionModel()->selectedRows())
	{
		list.append(first.at(index.row()));
	}
	return list;
}

void ScreenshotDialog::on_uploadBtn_clicked()
{
	QList<ScreenShot *> screenshots = selected();
	if (screenshots.isEmpty())
	{
		done(NothingDone);
		return;
	}
	NetJob *job = new NetJob("Screenshot Upload");
	for (ScreenShot *shot : screenshots)
	{
		job->addNetAction(ScreenShotUpload::make(shot));
	}
	m_uploaded = screenshots;
	ProgressDialog prog(this);
	if (prog.exec(job) == QDialog::Accepted)
	{
		accept();
	}
	else
	{
		CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
									 tr("Unknown error"), QMessageBox::Warning)->exec();
		reject();
	}
}