Show "executable" screenshots in the screenshot manager

Since the readable/writable filter was removed to do this, extra code was added to enable/disable certain buttons based on whether the screenshot is readable or writable.
This commit is contained in:
Kenneth Chew 2022-05-09 00:54:47 -04:00
parent f7f39854f8
commit 40e0252d7d
No known key found for this signature in database
GPG Key ID: F17D3E14A07739DA
2 changed files with 27 additions and 1 deletions

View File

@ -251,7 +251,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent)
m_model.reset(new QFileSystemModel());
m_filterModel.reset(new FilterModel());
m_filterModel->setSourceModel(m_model.get());
m_model->setFilter(QDir::Files | QDir::Writable | QDir::Readable);
m_model->setFilter(QDir::Files);
m_model->setReadOnly(false);
m_model->setNameFilters({"*.png"});
m_model->setNameFilterDisables(false);
@ -343,6 +343,29 @@ void ScreenshotsPage::onItemActivated(QModelIndex index)
DesktopServices::openFile(info.absoluteFilePath());
}
void ScreenshotsPage::onCurrentSelectionChanged(const QItemSelection &selected)
{
bool allReadable = !selected.isEmpty();
bool allWritable = !selected.isEmpty();
for (auto index : selected.indexes())
{
if (!index.isValid())
break;
auto info = m_model->fileInfo(index);
if (!info.isReadable())
allReadable = false;
if (!info.isWritable())
allWritable = false;
}
ui->actionUpload->setEnabled(allReadable);
ui->actionCopy_Image->setEnabled(allReadable);
ui->actionCopy_File_s->setEnabled(allReadable);
ui->actionDelete->setEnabled(allWritable);
ui->actionRename->setEnabled(allWritable);
}
void ScreenshotsPage::on_actionView_Folder_triggered()
{
DesktopServices::openDirectory(m_folder, true);
@ -503,6 +526,8 @@ void ScreenshotsPage::openedImpl()
if(idx.isValid())
{
ui->listView->setModel(m_filterModel.get());
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ScreenshotsPage::onCurrentSelectionChanged);
onCurrentSelectionChanged(ui->listView->selectionModel()->selection()); // set initial button enable states
ui->listView->setRootIndex(m_filterModel->mapFromSource(idx));
}
else

View File

@ -100,6 +100,7 @@ private slots:
void on_actionRename_triggered();
void on_actionView_Folder_triggered();
void onItemActivated(QModelIndex);
void onCurrentSelectionChanged(const QItemSelection &selected);
void ShowContextMenu(const QPoint &pos);
private: