From 65cb7d95cd2b8e5d24f686fd22be7325e5a9d039 Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 4 Jan 2018 06:40:38 +0100 Subject: Add cache operations Implement functions to remove files from cached data, or clear it completely. This may be necessary if something happened without us knowing, e.g. a file was copied by another program. --- filewidget.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'filewidget.cpp') diff --git a/filewidget.cpp b/filewidget.cpp index e13fe77..3d2ff28 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -165,11 +165,20 @@ void FileWidget::createActions(){ connect(mPreviewA, SIGNAL(triggered()), this, SLOT(preview())); mAddAsOriginA = new QAction(QIcon(":/butt_plug.png"), tr("Add as Origin..."), this); connect(mAddAsOriginA, SIGNAL(triggered()), this, SLOT(addAsOrigin())); + mRemoveFromCacheA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Remove selected"), this); + connect(mRemoveFromCacheA, &QAction::triggered, this, &FileWidget::removeFromCache); + mClearCacheA = new QAction(QIcon(":/male_chastity_belt.png"), tr("Clear..."), this); + connect(mClearCacheA, &QAction::triggered, this, &FileWidget::clearCache); QMenu *fileMenu = new QMenu(tr("&File")); fileMenu->addAction(mSelDirA); fileMenu->addAction(mRefreshA); fileMenu->addSeparator(); + QMenu *cacheMenu = new QMenu(tr("Cache")); + cacheMenu->addAction(mRemoveFromCacheA); + cacheMenu->addAction(mClearCacheA); + fileMenu->addMenu(cacheMenu); + fileMenu->addSeparator(); fileMenu->addAction(Globals::instance()->action(Globals::QuitAction)); QMenu *editMenu = new QMenu(tr("&Edit")); @@ -633,6 +642,29 @@ void FileWidget::copySuccess(bool success, QString source){ } } +void FileWidget::removeFromCache(){ + QModelIndexList curSel = mFileView->selectionModel()->selectedRows(); + int count = 0; + for(const QModelIndex &i : curSel){ + QString fullPath = i.data(FullPathRole).toString(); + if(mFileCache.remove(fullPath)){ + ++count; + } + } + QString msg = QString(tr("Removed %1 files from cache")).arg(QString::number(count)); + gatherData(); + emit statusMessage(msg); +} + +void FileWidget::clearCache(){ + int retval = QMessageBox::question(this, tr("Clear cache"), tr("Really empty the cache?")); + if(retval == QMessageBox::Yes){ + mFileCache.clear(); + gatherData(); + emit statusMessage(tr("Cache cleared!")); + } +} + void FileWidget::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){ Q_UNUSED(selected); Q_UNUSED(deselected); -- cgit v1.2.3-70-g09d2