From cead61f9598302a83fa72e99f82f7bfa2c0b19cb Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 17 Aug 2016 19:16:49 +0200 Subject: Implemented MoveFiles and a status bar Should be 2 commits, but who cares? --- shemovcleaner.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'shemovcleaner.cpp') diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp index 21f2337..9625db1 100644 --- a/shemovcleaner.cpp +++ b/shemovcleaner.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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(); -- cgit v1.2.3-70-g09d2