diff options
| author | Arno <arno@disconnect.de> | 2018-08-25 03:58:36 +0200 | 
|---|---|---|
| committer | Arno <arno@disconnect.de> | 2018-08-25 03:58:36 +0200 | 
| commit | 295114f77a4ed6ed8957485c0ceaf5c6d38b3485 (patch) | |
| tree | 6352330ad4712b583724834cf9ba79914b0d39fb /collectionfoldersview.cpp | |
| parent | 63f968ae97dc70b7ad436eab2adfaa1e983005f7 (diff) | |
| download | BeetPlayer-295114f77a4ed6ed8957485c0ceaf5c6d38b3485.tar.gz BeetPlayer-295114f77a4ed6ed8957485c0ceaf5c6d38b3485.tar.bz2 BeetPlayer-295114f77a4ed6ed8957485c0ceaf5c6d38b3485.zip | |
Add delete to CollectionFoldersView
Diffstat (limited to 'collectionfoldersview.cpp')
| -rw-r--r-- | collectionfoldersview.cpp | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/collectionfoldersview.cpp b/collectionfoldersview.cpp index 2dfb32f..e1a96b2 100644 --- a/collectionfoldersview.cpp +++ b/collectionfoldersview.cpp @@ -2,10 +2,13 @@  #include <QStandardItem>  #include <QDir>  #include <QMimeDatabase> +#include <QMessageBox> +#include <QFileInfo>  #include <taglib/fileref.h>  #include "collectionfoldersview.h" +#include "collectionwidgetproxy.h"  CollectionFoldersView::CollectionFoldersView(QWidget *parent) : CollectionWidget(parent){      readSettings(); @@ -71,3 +74,28 @@ void CollectionFoldersView::itemDoubleCliced(const QModelIndex &idx){      mCurrentFolder = d.absolutePath();      populate();  } + +void CollectionFoldersView::deleteCurrent(){ +    QString toDel = QDir::toNativeSeparators(mCurrentFolder); +    toDel.append(QDir::separator()); +    toDel.append(view()->currentIndex().data().toString()); +    QString msg = QString(tr("Really delete %1?")).arg(toDel); +    CollectionWidgetProxy *proxy = static_cast<CollectionWidgetProxy*>(view()->model()); +    int retval = QMessageBox::question(this, tr("Delete"), msg); +    if(retval == QMessageBox::Yes){ +        QFileInfo fi(toDel); +        bool success = false; +        if(fi.isDir()){ +            QDir d(toDel); +            success = d.removeRecursively(); +        }else if(fi.isFile()){ +            success = QFile::remove(toDel); +        } +        if(success){ +            proxy->removeRow(view()->currentIndex().row()); +        }else{ +            QString msg = QString(tr("Deleting %1 failed!")).arg(toDel); +            QMessageBox::critical(this, tr("Error"), msg); +        } +    } +} | 
