Fix Copy/Upload buttons not working in ScreenshotsPage (#5387)

This commit is contained in:
Alexandru Ionut Tripon 2026-04-14 16:26:12 +00:00 committed by GitHub
commit fbec685eb5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 133 additions and 111 deletions

View file

@ -45,7 +45,6 @@
#include <QFileSystemModel> #include <QFileSystemModel>
#include <QKeyEvent> #include <QKeyEvent>
#include <QLineEdit> #include <QLineEdit>
#include <QMap>
#include <QMenu> #include <QMenu>
#include <QModelIndex> #include <QModelIndex>
#include <QMutableListIterator> #include <QMutableListIterator>
@ -53,6 +52,8 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QSet> #include <QSet>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <memory>
#include <utility>
#include <Application.h> #include <Application.h>
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
@ -70,9 +71,14 @@
#include "RWStorage.h" #include "RWStorage.h"
class ScreenshotsFSModel : public QFileSystemModel { class ScreenshotsFSModel : public QFileSystemModel {
bool canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const override public:
bool canDropMimeData(const QMimeData* data,
const Qt::DropAction action,
const int row,
const int column,
const QModelIndex& parent) const override
{ {
QUrl root = QUrl::fromLocalFile(rootPath()); const QUrl root = QUrl::fromLocalFile(rootPath());
// this disables reordering items inside the model // this disables reordering items inside the model
// by rejecting drops if the file is already inside the folder // by rejecting drops if the file is already inside the folder
if (data->hasUrls()) { if (data->hasUrls()) {
@ -92,8 +98,8 @@ using SharedIconCachePtr = std::shared_ptr<SharedIconCache>;
class ThumbnailingResult : public QObject { class ThumbnailingResult : public QObject {
Q_OBJECT Q_OBJECT
public slots: public slots:
inline void emitResultsReady(const QString& path) { emit resultsReady(path); } void emitResultsReady(const QString& path) { emit resultsReady(path); }
inline void emitResultsFailed(const QString& path) { emit resultsFailed(path); } void emitResultsFailed(const QString& path) { emit resultsFailed(path); }
signals: signals:
void resultsReady(const QString& path); void resultsReady(const QString& path);
void resultsFailed(const QString& path); void resultsFailed(const QString& path);
@ -101,32 +107,32 @@ class ThumbnailingResult : public QObject {
class ThumbnailRunnable : public QRunnable { class ThumbnailRunnable : public QRunnable {
public: public:
ThumbnailRunnable(QString path, SharedIconCachePtr cache) ThumbnailRunnable(QString path, SharedIconCachePtr cache) : m_path(std::move(path)), m_cache(std::move(cache)) {}
void run() override
{ {
m_path = path; const QFileInfo info(m_path);
m_cache = cache; if (info.isDir()) {
}
void run()
{
QFileInfo info(m_path);
if (info.isDir())
return; return;
if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0)) }
if (info.suffix().compare("png", Qt::CaseInsensitive) != 0) {
return; return;
if (!m_cache->stale(m_path)) }
if (!m_cache->stale(m_path)) {
return; return;
QImage image(m_path); }
const QImage image(m_path);
if (image.isNull()) { if (image.isNull()) {
m_resultEmitter.emitResultsFailed(m_path); m_resultEmitter.emitResultsFailed(m_path);
qDebug() << "Error loading screenshot (perhaps too large?):" + m_path; qDebug() << "Error loading screenshot (perhaps too large?):" + m_path;
return; return;
} }
QImage small; QImage small;
if (image.width() > image.height()) if (image.width() > image.height()) {
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
else } else {
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); }
const QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
QImage square(QSize(256, 256), QImage::Format_ARGB32); QImage square(QSize(256, 256), QImage::Format_ARGB32);
square.fill(Qt::transparent); square.fill(Qt::transparent);
@ -134,7 +140,7 @@ class ThumbnailRunnable : public QRunnable {
painter.drawImage(offset, small); painter.drawImage(offset, small);
painter.end(); painter.end();
QIcon icon(QPixmap::fromImage(square)); const QIcon icon(QPixmap::fromImage(square));
m_cache->add(m_path, icon); m_cache->add(m_path, icon);
m_resultEmitter.emitResultsReady(m_path); m_resultEmitter.emitResultsReady(m_path);
} }
@ -148,59 +154,62 @@ class ThumbnailRunnable : public QRunnable {
class FilterModel : public QIdentityProxyModel { class FilterModel : public QIdentityProxyModel {
Q_OBJECT Q_OBJECT
public: public:
explicit FilterModel(QObject* parent = 0) : QIdentityProxyModel(parent) explicit FilterModel(QObject* parent = nullptr) : QIdentityProxyModel(parent)
{ {
m_thumbnailingPool.setMaxThreadCount(4); m_thumbnailingPool.setMaxThreadCount(4);
m_thumbnailCache = std::make_shared<SharedIconCache>(); m_thumbnailCache = std::make_shared<SharedIconCache>();
m_thumbnailCache->add("placeholder", QIcon::fromTheme("screenshot-placeholder")); m_thumbnailCache->add("placeholder", QIcon::fromTheme("screenshot-placeholder"));
connect(&watcher, &QFileSystemWatcher::fileChanged, this, &FilterModel::fileChanged); connect(&watcher, &QFileSystemWatcher::fileChanged, this, &FilterModel::fileChanged);
} }
virtual ~FilterModel() ~FilterModel() override
{ {
m_thumbnailingPool.clear(); m_thumbnailingPool.clear();
if (!m_thumbnailingPool.waitForDone(500)) if (!m_thumbnailingPool.waitForDone(500)) {
qDebug() << "Thumbnail pool took longer than 500ms to finish"; qDebug() << "Thumbnail pool took longer than 500ms to finish";
}
} }
virtual QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const QVariant data(const QModelIndex& proxyIndex, const int role = Qt::DisplayRole) const override // NOLINT(*-default-arguments)
{ {
auto model = sourceModel(); const auto* model = sourceModel();
if (!model) if (!model) {
return QVariant(); return {};
}
if (role == Qt::DisplayRole || role == Qt::EditRole) { if (role == Qt::DisplayRole || role == Qt::EditRole) {
QVariant result = sourceModel()->data(mapToSource(proxyIndex), role); const QVariant result = model->data(mapToSource(proxyIndex), role);
static const QRegularExpression s_removeChars("\\.png$"); static const QRegularExpression s_removeChars("\\.png$");
return result.toString().remove(s_removeChars); return result.toString().remove(s_removeChars);
} }
if (role == Qt::DecorationRole) { if (role == Qt::DecorationRole) {
QVariant result = sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole); const QVariant result = model->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole);
QString filePath = result.toString(); const QString filePath = result.toString();
QIcon temp;
if (!watched.contains(filePath)) { if (!watched.contains(filePath)) {
((QFileSystemWatcher&)watcher).addPath(filePath); const_cast<QFileSystemWatcher&>(watcher).addPath(filePath);
((QSet<QString>&)watched).insert(filePath); const_cast<QSet<QString>&>(watched).insert(filePath);
} }
if (m_thumbnailCache->get(filePath, temp)) { if (QIcon temp; m_thumbnailCache->get(filePath, temp)) {
return temp; return temp;
} }
if (!m_failed.contains(filePath)) { if (!m_failed.contains(filePath)) {
((FilterModel*)this)->thumbnailImage(filePath); const_cast<FilterModel*>(this)->thumbnailImage(filePath);
} }
return (m_thumbnailCache->get("placeholder")); return (m_thumbnailCache->get("placeholder"));
} }
return sourceModel()->data(mapToSource(proxyIndex), role); return model->data(mapToSource(proxyIndex), role);
} }
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) bool setData(const QModelIndex& index, const QVariant& value, const int role = Qt::EditRole) override // NOLINT(*-default-arguments)
{ {
auto model = sourceModel(); auto* model = sourceModel();
if (!model) if (!model) {
return false; return false;
if (role != Qt::EditRole) }
if (role != Qt::EditRole) {
return false; return false;
}
// FIXME: this is a workaround for a bug in QFileSystemModel, where it doesn't // FIXME: this is a workaround for a bug in QFileSystemModel, where it doesn't
// sort after renames // sort after renames
{ {
((QFileSystemModel*)model)->setNameFilterDisables(true); static_cast<QFileSystemModel*>(model)->setNameFilterDisables(true);
((QFileSystemModel*)model)->setNameFilterDisables(false); static_cast<QFileSystemModel*>(model)->setNameFilterDisables(false);
} }
return model->setData(mapToSource(index), value.toString() + ".png", role); return model->setData(mapToSource(index), value.toString() + ".png", role);
} }
@ -208,15 +217,15 @@ class FilterModel : public QIdentityProxyModel {
private: private:
void thumbnailImage(QString path) void thumbnailImage(QString path)
{ {
auto runnable = new ThumbnailRunnable(path, m_thumbnailCache); auto* runnable = new ThumbnailRunnable(std::move(path), m_thumbnailCache);
connect(&runnable->m_resultEmitter, &ThumbnailingResult::resultsReady, this, &FilterModel::thumbnailReady); connect(&runnable->m_resultEmitter, &ThumbnailingResult::resultsReady, this, &FilterModel::thumbnailReady);
connect(&runnable->m_resultEmitter, &ThumbnailingResult::resultsFailed, this, &FilterModel::thumbnailFailed); connect(&runnable->m_resultEmitter, &ThumbnailingResult::resultsFailed, this, &FilterModel::thumbnailFailed);
m_thumbnailingPool.start(runnable); m_thumbnailingPool.start(runnable);
} }
private slots: private slots:
void thumbnailReady(QString path) { emit layoutChanged(); } void thumbnailReady(const QString& /*path*/) { emit layoutChanged(); }
void thumbnailFailed(QString path) { m_failed.insert(path); } void thumbnailFailed(const QString& path) { m_failed.insert(path); }
void fileChanged(QString filepath) void fileChanged(const QString& filepath)
{ {
m_thumbnailCache->setStale(filepath); m_thumbnailCache->setStale(filepath);
// reinsert the path... // reinsert the path...
@ -237,13 +246,12 @@ class FilterModel : public QIdentityProxyModel {
class CenteredEditingDelegate : public QStyledItemDelegate { class CenteredEditingDelegate : public QStyledItemDelegate {
public: public:
explicit CenteredEditingDelegate(QObject* parent = 0) : QStyledItemDelegate(parent) {} explicit CenteredEditingDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {}
virtual ~CenteredEditingDelegate() {} ~CenteredEditingDelegate() override = default;
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override
{ {
auto widget = QStyledItemDelegate::createEditor(parent, option, index); auto* widget = QStyledItemDelegate::createEditor(parent, option, index);
auto foo = dynamic_cast<QLineEdit*>(widget); if (auto* foo = dynamic_cast<QLineEdit*>(widget)) {
if (foo) {
foo->setAlignment(Qt::AlignHCenter); foo->setAlignment(Qt::AlignHCenter);
foo->setFrame(true); foo->setFrame(true);
foo->setMaximumWidth(192); foo->setMaximumWidth(192);
@ -252,10 +260,11 @@ class CenteredEditingDelegate : public QStyledItemDelegate {
} }
}; };
ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent) : QMainWindow(parent), ui(new Ui::ScreenshotsPage) ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent)
: QMainWindow(parent), ui(new Ui::ScreenshotsPage), m_folder(std::move(path))
{ {
m_model.reset(new ScreenshotsFSModel()); m_model = std::make_shared<ScreenshotsFSModel>();
m_filterModel.reset(new FilterModel()); m_filterModel = std::make_shared<FilterModel>();
m_filterModel->setSourceModel(m_model.get()); m_filterModel->setSourceModel(m_model.get());
m_model->setFilter(QDir::Files); m_model->setFilter(QDir::Files);
m_model->setReadOnly(false); m_model->setReadOnly(false);
@ -266,7 +275,6 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent) : QMainWindow(pa
constexpr int file_modified_column_index = 3; constexpr int file_modified_column_index = 3;
m_model->sort(file_modified_column_index, Qt::DescendingOrder); m_model->sort(file_modified_column_index, Qt::DescendingOrder);
m_folder = path;
m_valid = FS::ensureFolderPathExists(m_folder); m_valid = FS::ensureFolderPathExists(m_folder);
ui->setupUi(this); ui->setupUi(this);
@ -283,18 +291,19 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent) : QMainWindow(pa
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->listView->setItemDelegate(new CenteredEditingDelegate(this)); ui->listView->setItemDelegate(new CenteredEditingDelegate(this));
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->listView, &QListView::customContextMenuRequested, this, &ScreenshotsPage::ShowContextMenu); connect(ui->listView, &QListView::customContextMenuRequested, this, &ScreenshotsPage::showContextMenu);
connect(ui->listView, &QAbstractItemView::activated, this, &ScreenshotsPage::onItemActivated); connect(ui->listView, &QAbstractItemView::activated, this, &ScreenshotsPage::onItemActivated);
} }
bool ScreenshotsPage::eventFilter(QObject* obj, QEvent* evt) bool ScreenshotsPage::eventFilter(QObject* obj, QEvent* evt)
{ {
if (obj != ui->listView) if (obj != ui->listView) {
return QWidget::eventFilter(obj, evt); return QWidget::eventFilter(obj, evt);
}
if (evt->type() != QEvent::KeyPress) { if (evt->type() != QEvent::KeyPress) {
return QWidget::eventFilter(obj, evt); return QWidget::eventFilter(obj, evt);
} }
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(evt); const auto* keyEvent = static_cast<QKeyEvent*>(evt);
if (keyEvent->matches(QKeySequence::Copy)) { if (keyEvent->matches(QKeySequence::Copy)) {
on_actionCopy_File_s_triggered(); on_actionCopy_File_s_triggered();
@ -324,11 +333,11 @@ ScreenshotsPage::~ScreenshotsPage()
delete ui; delete ui;
} }
void ScreenshotsPage::ShowContextMenu(const QPoint& pos) void ScreenshotsPage::showContextMenu(const QPoint& pos)
{ {
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu")); auto* menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
if (ui->listView->selectionModel()->selectedRows().size() > 1) { if (ui->listView->selectionModel()->selectedIndexes().size() > 1) {
menu->removeAction(ui->actionCopy_Image); menu->removeAction(ui->actionCopy_Image);
} }
@ -343,66 +352,75 @@ QMenu* ScreenshotsPage::createPopupMenu()
return filteredMenu; return filteredMenu;
} }
void ScreenshotsPage::onItemActivated(QModelIndex index) void ScreenshotsPage::onItemActivated(QModelIndex index) const
{ {
if (!index.isValid()) if (!index.isValid()) {
return; return;
auto info = m_model->fileInfo(index); }
const auto info = m_model->fileInfo(index);
DesktopServices::openPath(info); DesktopServices::openPath(info);
} }
void ScreenshotsPage::onCurrentSelectionChanged(const QItemSelection& selected) void ScreenshotsPage::onCurrentSelectionChanged(const QItemSelection& /*selected*/) const
{ {
const auto selected = ui->listView->selectionModel()->selectedIndexes();
bool allReadable = !selected.isEmpty(); bool allReadable = !selected.isEmpty();
bool allWritable = !selected.isEmpty(); bool allWritable = !selected.isEmpty();
for (auto index : selected.indexes()) { for (auto index : selected) {
if (!index.isValid()) if (!index.isValid()) {
break; break;
}
auto info = m_model->fileInfo(index); auto info = m_model->fileInfo(index);
if (!info.isReadable()) if (!info.isReadable()) {
allReadable = false; allReadable = false;
if (!info.isWritable()) }
if (!info.isWritable()) {
allWritable = false; allWritable = false;
}
} }
ui->actionUpload->setEnabled(allReadable); ui->actionUpload->setEnabled(allReadable);
ui->actionCopy_Image->setEnabled(allReadable); ui->actionCopy_Image->setEnabled(allReadable && selected.size() == 1);
ui->actionCopy_File_s->setEnabled(allReadable); ui->actionCopy_File_s->setEnabled(allReadable);
ui->actionDelete->setEnabled(allWritable); ui->actionDelete->setEnabled(allWritable);
ui->actionRename->setEnabled(allWritable); ui->actionRename->setEnabled(allWritable);
} }
void ScreenshotsPage::on_actionView_Folder_triggered() void ScreenshotsPage::on_actionView_Folder_triggered() const
{ {
DesktopServices::openPath(m_folder, true); DesktopServices::openPath(m_folder, true);
} }
void ScreenshotsPage::on_actionUpload_triggered() void ScreenshotsPage::on_actionUpload_triggered()
{ {
auto selection = ui->listView->selectionModel()->selectedRows(); auto selection = ui->listView->selectionModel()->selectedIndexes();
if (selection.isEmpty()) if (selection.isEmpty()) {
return; return;
}
QString text; QString text;
QUrl baseUrl(BuildConfig.IMGUR_BASE_URL); const QUrl baseUrl(BuildConfig.IMGUR_BASE_URL);
if (selection.size() > 1) if (selection.size() > 1) {
text = tr("You are about to upload %1 screenshots to %2.\n" text = tr("You are about to upload %1 screenshots to %2.\n"
"You should double-check for personal information.\n\n" "You should double-check for personal information.\n\n"
"Are you sure?") "Are you sure?")
.arg(QString::number(selection.size()), baseUrl.host()); .arg(QString::number(selection.size()), baseUrl.host());
else } else {
text = tr("You are about to upload the selected screenshot to %1.\n" text = tr("You are about to upload the selected screenshot to %1.\n"
"You should double-check for personal information.\n\n" "You should double-check for personal information.\n\n"
"Are you sure?") "Are you sure?")
.arg(baseUrl.host()); .arg(baseUrl.host());
}
auto response = CustomMessageBox::selectable(this, "Confirm Upload", text, QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, auto response = CustomMessageBox::selectable(this, "Confirm Upload", text, QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) QMessageBox::No)
->exec(); ->exec();
if (response != QMessageBox::Yes) if (response != QMessageBox::Yes) {
return; return;
}
QList<ScreenShot::Ptr> uploaded; QList<ScreenShot::Ptr> uploaded;
auto job = NetJob::Ptr(new NetJob("Screenshot Upload", APPLICATION->network())); auto job = NetJob::Ptr(new NetJob("Screenshot Upload", APPLICATION->network()));
@ -416,7 +434,7 @@ void ScreenshotsPage::on_actionUpload_triggered()
auto screenshot = std::make_shared<ScreenShot>(info); auto screenshot = std::make_shared<ScreenShot>(info);
job->addNetAction(ImgurUpload::make(screenshot)); job->addNetAction(ImgurUpload::make(screenshot));
connect(job.get(), &Task::failed, [this](QString reason) { connect(job.get(), &Task::failed, [this](const QString& reason) {
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), reason, QMessageBox::Critical)->show(); CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), reason, QMessageBox::Critical)->show();
}); });
connect(job.get(), &Task::aborted, [this] { connect(job.get(), &Task::aborted, [this] {
@ -457,7 +475,7 @@ void ScreenshotsPage::on_actionUpload_triggered()
task.addTask(job); task.addTask(job);
task.addTask(albumTask); task.addTask(albumTask);
connect(&task, &Task::failed, [this](QString reason) { connect(&task, &Task::failed, [this](const QString& reason) {
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), reason, QMessageBox::Critical)->show(); CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), reason, QMessageBox::Critical)->show();
}); });
connect(&task, &Task::aborted, [this] { connect(&task, &Task::aborted, [this] {
@ -485,24 +503,24 @@ void ScreenshotsPage::on_actionUpload_triggered()
m_uploadActive = false; m_uploadActive = false;
} }
void ScreenshotsPage::on_actionCopy_Image_triggered() void ScreenshotsPage::on_actionCopy_Image_triggered() const
{ {
auto selection = ui->listView->selectionModel()->selectedRows(); auto selection = ui->listView->selectionModel()->selectedIndexes();
if (selection.size() < 1) { if (selection.size() < 1) {
return; return;
} }
// You can only copy one image to the clipboard. In the case of multiple selected files, only the first one gets copied. // You can only copy one image to the clipboard. In the case of multiple selected files, only the first one gets copied.
auto item = selection[0]; const auto item = selection.first();
auto info = m_model->fileInfo(item); const auto info = m_model->fileInfo(item);
QImage image(info.absoluteFilePath()); const QImage image(info.absoluteFilePath());
Q_ASSERT(!image.isNull()); Q_ASSERT(!image.isNull());
QApplication::clipboard()->setImage(image, QClipboard::Clipboard); QApplication::clipboard()->setImage(image, QClipboard::Clipboard);
} }
void ScreenshotsPage::on_actionCopy_File_s_triggered() void ScreenshotsPage::on_actionCopy_File_s_triggered() const
{ {
auto selection = ui->listView->selectionModel()->selectedRows(); auto selection = ui->listView->selectionModel()->selectedIndexes();
if (selection.size() < 1) { if (selection.size() < 1) {
// Don't do anything so we don't empty the users clipboard // Don't do anything so we don't empty the users clipboard
return; return;
@ -513,7 +531,7 @@ void ScreenshotsPage::on_actionCopy_File_s_triggered()
auto info = m_model->fileInfo(item); auto info = m_model->fileInfo(item);
buf += "file:///" + info.absoluteFilePath() + "\r\n"; buf += "file:///" + info.absoluteFilePath() + "\r\n";
} }
QMimeData* mimeData = new QMimeData(); auto* mimeData = new QMimeData();
mimeData->setData("text/uri-list", buf.toLocal8Bit()); mimeData->setData("text/uri-list", buf.toLocal8Bit());
QApplication::clipboard()->setMimeData(mimeData); QApplication::clipboard()->setMimeData(mimeData);
} }
@ -522,39 +540,43 @@ void ScreenshotsPage::on_actionDelete_triggered()
{ {
auto selected = ui->listView->selectionModel()->selectedIndexes(); auto selected = ui->listView->selectionModel()->selectedIndexes();
int count = ui->listView->selectionModel()->selectedRows().size(); const qsizetype count = selected.size();
QString text; QString text;
if (count > 1) if (count > 1) {
text = tr("You are about to delete %1 screenshots.\n" text = tr("You are about to delete %1 screenshots.\n"
"This may be permanent and they will be gone from the folder.\n\n" "This may be permanent and they will be gone from the folder.\n\n"
"Are you sure?") "Are you sure?")
.arg(count); .arg(count);
else } else {
text = tr("You are about to delete the selected screenshot.\n" text =
"This may be permanent and it will be gone from the folder.\n\n" tr("You are about to delete the selected screenshot.\n"
"Are you sure?") "This may be permanent and it will be gone from the folder.\n\n"
.arg(count); "Are you sure?");
}
auto response = const auto response =
CustomMessageBox::selectable(this, tr("Confirm Deletion"), text, QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No)->exec(); CustomMessageBox::selectable(this, tr("Confirm Deletion"), text, QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No)->exec();
if (response != QMessageBox::Yes) if (response != QMessageBox::Yes) {
return; return;
}
for (auto item : selected) { for (auto item : selected) {
if (FS::trash(m_model->filePath(item))) if (FS::trash(m_model->filePath(item))) {
continue; continue;
}
m_model->remove(item); m_model->remove(item);
} }
} }
void ScreenshotsPage::on_actionRename_triggered() void ScreenshotsPage::on_actionRename_triggered() const
{ {
auto selection = ui->listView->selectionModel()->selectedIndexes(); auto selection = ui->listView->selectionModel()->selectedIndexes();
if (selection.isEmpty()) if (selection.isEmpty()) {
return; return;
ui->listView->edit(selection[0]); }
ui->listView->edit(selection.first());
// TODO: mass renaming // TODO: mass renaming
} }
@ -564,8 +586,8 @@ void ScreenshotsPage::openedImpl()
m_valid = FS::ensureFolderPathExists(m_folder); m_valid = FS::ensureFolderPathExists(m_folder);
} }
if (m_valid) { if (m_valid) {
QString path = QDir(m_folder).absolutePath(); const QString path = QDir(m_folder).absolutePath();
auto idx = m_model->setRootPath(path); const auto idx = m_model->setRootPath(path);
if (idx.isValid()) { if (idx.isValid()) {
ui->listView->setModel(m_filterModel.get()); ui->listView->setModel(m_filterModel.get());
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
@ -577,7 +599,7 @@ void ScreenshotsPage::openedImpl()
} }
} }
auto const setting_name = QString("WideBarVisibility_%1").arg(id()); const auto setting_name = QString("WideBarVisibility_%1").arg(id());
m_wide_bar_setting = APPLICATION->settings()->getOrRegisterSetting(setting_name); m_wide_bar_setting = APPLICATION->settings()->getOrRegisterSetting(setting_name);
ui->toolBar->setVisibilityState(QByteArray::fromBase64(m_wide_bar_setting->get().toString().toUtf8())); ui->toolBar->setVisibilityState(QByteArray::fromBase64(m_wide_bar_setting->get().toString().toUtf8()));

View file

@ -78,14 +78,14 @@ class ScreenshotsPage : public QMainWindow, public BasePage {
private slots: private slots:
void on_actionUpload_triggered(); void on_actionUpload_triggered();
void on_actionCopy_Image_triggered(); void on_actionCopy_Image_triggered() const;
void on_actionCopy_File_s_triggered(); void on_actionCopy_File_s_triggered() const;
void on_actionDelete_triggered(); void on_actionDelete_triggered();
void on_actionRename_triggered(); void on_actionRename_triggered() const;
void on_actionView_Folder_triggered(); void on_actionView_Folder_triggered() const;
void onItemActivated(QModelIndex); void onItemActivated(QModelIndex) const;
void onCurrentSelectionChanged(const QItemSelection& selected); void onCurrentSelectionChanged(const QItemSelection& selected) const;
void ShowContextMenu(const QPoint& pos); void showContextMenu(const QPoint& pos);
private: private:
Ui::ScreenshotsPage* ui; Ui::ScreenshotsPage* ui;