summaryrefslogtreecommitdiffstats
path: root/shemovcleaner.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-08-17 19:16:49 +0200
committerArno <arno@disconnect.de>2016-08-17 19:16:49 +0200
commitcead61f9598302a83fa72e99f82f7bfa2c0b19cb (patch)
tree92be5b14e1e985a31914746446110309d9f9f4e2 /shemovcleaner.cpp
parenta5191b5d12791981d16da3b4154b7fb29f1c01db (diff)
downloadShemovCleaner-cead61f9598302a83fa72e99f82f7bfa2c0b19cb.tar.gz
ShemovCleaner-cead61f9598302a83fa72e99f82f7bfa2c0b19cb.tar.bz2
ShemovCleaner-cead61f9598302a83fa72e99f82f7bfa2c0b19cb.zip
Implemented MoveFiles and a status bar
Should be 2 commits, but who cares?
Diffstat (limited to 'shemovcleaner.cpp')
-rw-r--r--shemovcleaner.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp
index 21f2337..9625db1 100644
--- a/shemovcleaner.cpp
+++ b/shemovcleaner.cpp
@@ -15,6 +15,7 @@
#include <QDateTime>
#include <QSettings>
#include <QHeaderView>
+#include <QStatusBar>
#include <QApplication>
#include <QDebug>
@@ -91,6 +92,17 @@ void ShemovCleaner::setupGui(){
setMinimumWidth(800);
setMinimumHeight(600);
setCentralWidget(mainWidget);
+
+ createStatusbar();
+ connect(mFileView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection)));
+}
+
+void ShemovCleaner::createStatusbar(){
+ QLabel *l1 = new QLabel(tr("Sel."));
+ mSelected = new QLabel("000/000");
+ mSelected->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ statusBar()->addPermanentWidget(l1);
+ statusBar()->addPermanentWidget(mSelected);
}
void ShemovCleaner::gatherData(){
@@ -149,6 +161,8 @@ void ShemovCleaner::deleteFiles(){
QMessageBox::critical(this, tr("Error"), msg);
}
}
+ QString msg = QString(tr("Successfully deleted %1 of %2 file(s)")).arg(QString::number(ctr)).arg(QString::number(sel.count()));
+ statusBar()->showMessage(msg);
gatherData();
}
}
@@ -159,10 +173,19 @@ void ShemovCleaner::moveFiles(){
return;
}
QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory"), QDir::homePath());
- foreach(QModelIndex i, sel){
- QFileInfo fp(i.data(Qt::UserRole + 1).toString());
- QString newfn = QString("%1/%2").arg(dir).arg(fp.fileName());
- qDebug() << "Would move" << fp.absoluteFilePath()<< "to" << newfn;
+ if(!dir.isEmpty()){
+ int ctr = 0;
+ foreach(QModelIndex i, sel){
+ QFileInfo fp(i.data(Qt::UserRole + 1).toString());
+ QString newfn = QString("%1/%2").arg(dir).arg(fp.fileName());
+ bool ok = QFile::rename(fp.absoluteFilePath(), newfn);
+ if(ok){
+ ++ctr;
+ }
+ }
+ QString msg = QString(tr("Successfully moved %1 of %2 file(s)")).arg(QString::number(ctr)).arg(QString::number(sel.count()));
+ statusBar()->showMessage(msg);
+ gatherData();
}
}
@@ -171,6 +194,15 @@ void ShemovCleaner::selectDir(){
mDir->setText(QDir::toNativeSeparators(dir));
}
+void ShemovCleaner::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){
+ Q_UNUSED(selected);
+ Q_UNUSED(deselected);
+ int count = mFileView->selectionModel()->selectedRows().count();
+ int total = mModel->rowCount();
+ QString msg = QString("%1/%2").arg(QString::number(count)).arg(QString::number(total));
+ mSelected->setText(msg);
+}
+
void ShemovCleaner::readSettings(){
QSettings s;
QString dir = s.value("searchdir", QDir::toNativeSeparators(QDir::homePath())).toString();