Deleting screenshots. Needs fixing.

This commit is contained in:
robotbrain 2014-02-24 17:40:05 -05:00
parent da33fa4090
commit 55e21737dd
7 changed files with 56 additions and 7 deletions

View File

@ -52,7 +52,7 @@
<item> <item>
<widget class="QPushButton" name="btnScreenshots"> <widget class="QPushButton" name="btnScreenshots">
<property name="text"> <property name="text">
<string>Upload Screenshots</string> <string>Manage Screenshots</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -532,7 +532,7 @@
</action> </action>
<action name="actionScreenshots"> <action name="actionScreenshots">
<property name="text"> <property name="text">
<string>Upload Screenshots</string> <string>Manage Screenshots</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;View and upload screenshots for this instance&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;View and upload screenshots for this instance&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>

View File

@ -2,7 +2,7 @@
#include "ui_ScreenshotDialog.h" #include "ui_ScreenshotDialog.h"
#include <QModelIndex> #include <QModelIndex>
#include <QDebug> #include <QMutableListIterator>
#include "ProgressDialog.h" #include "ProgressDialog.h"
#include "CustomMessageBox.h" #include "CustomMessageBox.h"
@ -71,3 +71,8 @@ void ScreenshotDialog::on_uploadBtn_clicked()
reject(); reject();
} }
} }
void ScreenshotDialog::on_deleteBtn_clicked()
{
m_list->deleteSelected(this);
}

View File

@ -24,16 +24,17 @@ public:
}; };
QString message() const; QString message() const;
QList<ScreenShot *> selected() const;
private private
slots: slots:
void on_uploadBtn_clicked(); void on_uploadBtn_clicked();
void on_deleteBtn_clicked();
private: private:
Ui::ScreenshotDialog *ui; Ui::ScreenshotDialog *ui;
ScreenshotList *m_list; ScreenshotList *m_list;
QList<ScreenShot *> m_uploaded; QList<ScreenShot *> m_uploaded;
std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum; std::shared_ptr<ImgurAlbumCreation> m_imgurAlbum;
QList<ScreenShot *> selected() const;
}; };

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Screenshots</string> <string>Screenshot Manager</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../resources/multimc/multimc.qrc"> <iconset resource="../../resources/multimc/multimc.qrc">
@ -72,6 +72,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="deleteBtn">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -1,7 +1,11 @@
#include "ScreenshotList.h" #include "ScreenshotList.h"
#include "gui/dialogs/ScreenshotDialog.h"
#include <QDir> #include <QDir>
#include <QIcon> #include <QIcon>
#include <QList>
#include "gui/dialogs/ProgressDialog.h"
#include "gui/dialogs/CustomMessageBox.h"
ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
: QAbstractListModel(parent), m_instance(instance) : QAbstractListModel(parent), m_instance(instance)
@ -15,7 +19,7 @@ int ScreenshotList::rowCount(const QModelIndex &) const
QVariant ScreenshotList::data(const QModelIndex &index, int role) const QVariant ScreenshotList::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (index.row() >= m_screenshots.size() || index.row() < 0)
return QVariant(); return QVariant();
switch (role) switch (role)
@ -76,3 +80,33 @@ void ScreenshotLoadTask::executeTask()
m_list->loadShots(m_results); m_list->loadShots(m_results);
emitSucceeded(); emitSucceeded();
} }
void ScreenshotList::deleteSelected(ScreenshotDialog *dialog)
{
auto screens = dialog->selected();
if (screens.isEmpty())
{
return;
}
beginResetModel();
QList<ScreenShot *>::const_iterator it;
for (it = screens.cbegin(); it != screens.cend(); it++)
{
ScreenShot *shot = *it;
if (!QFile(shot->file).remove())
{
CustomMessageBox::selectable(dialog, tr("Error!"),
tr("Failed to delete screenshots!"),
QMessageBox::Warning)->exec();
break;
}
}
ProgressDialog refresh(dialog);
Task *t = load();
if (refresh.exec(t) != QDialog::Accepted)
{
CustomMessageBox::selectable(dialog, tr("Error!"),
tr("Unable to refresh list: %1").arg(t->failReason()),
QMessageBox::Warning)->exec();
}
endResetModel();
}

View File

@ -43,6 +43,8 @@ public:
return m_instance; return m_instance;
} }
void deleteSelected(class ScreenshotDialog *dialog);
signals: signals:
public public