From c90f920ebc2dd3386d4f84df3ad25480fbaf616b Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 8 Sep 2012 11:38:09 +0200 Subject: Implement copy file from PictureViewer2 Add an action to PictureViewer2 for copying the current pic to another directory. When I tried to add the QAction to the context menu, I realized that I chose the variable names picView and picViewer in shemov.cpp very poorly. Took some time to sift though it. Eventually I shifted some code around to make it more readable. While at it I replaced the individual separators with createSeparator(). Other than adding the Copy To action no functional changes. --- pictureviewer2.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pictureviewer2.cpp') diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index eee77af..bf2dbce 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include "pictureviewer2.h" #include "pictureswidget.h" @@ -197,6 +200,24 @@ void PictureViewer2::initActions(){ } } +void PictureViewer2::copyCurrent(){ + QString fullPath = mFiles.at(mCurPos).at(PicFilesModel::FullPath).toString(); + QSettings s; + QString lastDir = s.value("ui/pvlastdir", QDir::homePath()).toString(); + QString destDir = QFileDialog::getExistingDirectory(this, tr("Copy picture"), lastDir); + if(!destDir.isEmpty()){ + QFileInfo fi(fullPath); + QString copyTo = QString("%1/%2").arg(destDir).arg(fi.fileName()); + bool success = QFile::copy(fullPath, copyTo); + if(!success){ + QString msg = QString(tr("File copy %1 -> %2 failed!")).arg(fullPath).arg(copyTo); + QMessageBox::critical(this, tr("Error"), msg); + }else{ + s.setValue("ui/pvlastdir", destDir); + } + } +} + void PictureViewer2::wheelEvent(QWheelEvent *event){ int steps = event->delta() / 8 / 15; if(steps < 0){ -- cgit v1.2.3-70-g09d2