From d8e62dd6e715fcc19b7e7d4d466a586c62ccc4e6 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 13 Oct 2018 06:10:11 +0200 Subject: Actually do something when calling CopyDialg::copy() Implement copying files. The GUI is quite slow when copying to a device mounted with flush, eg. an USB-Stick, but that's to be expected... --- copydialog.cpp | 23 +++++++++++++++++++++++ copydialog.h | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/copydialog.cpp b/copydialog.cpp index 0ae2f73..957dfe5 100644 --- a/copydialog.cpp +++ b/copydialog.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "copydialog.h" @@ -45,6 +47,7 @@ CopyDialog::CopyDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) resultGB->setLayout(resultL); QHBoxLayout *buttonL = new QHBoxLayout; QPushButton *copyB = new QPushButton(tr("Copy!")); + connect(copyB, &QPushButton::clicked, this, &CopyDialog::copy); buttonL->addStretch(); buttonL->addWidget(copyB); QPushButton *closeB = new QPushButton(tr("Close")); @@ -96,6 +99,26 @@ void CopyDialog::refresh(){ mResultTE->setText(res); } +void CopyDialog::copy(){ + QString destDir = QString("%1/%2").arg(mDstE->text()).arg(mFolderE->text()); + QFile destF(destDir); + if(destF.exists()){ + QMessageBox::critical(this, tr("Error"), tr("Destination directory already exists!")); + return; + } + QDir ddir(mDstE->text()); + ddir.mkdir(mFolderE->text()); + QProgressDialog progress(tr("Copying files..."), tr("Cancel"), 0, mSources.count(), this); + progress.setWindowModality(Qt::WindowModal); + for(int i = 0; i < mSources.count(); ++i){ + progress.setValue(i); + QString dest = getDestinationFile(mSources.at(i)); + QFile::copy(mSources.at(i), dest); + } + progress.setValue(mSources.count()); + close(); +} + QString CopyDialog::getDestinationFile(const QString &srcFn){ QFileInfo fi(srcFn); if(fi.exists()){ diff --git a/copydialog.h b/copydialog.h index 10d46b9..563a5c8 100644 --- a/copydialog.h +++ b/copydialog.h @@ -17,7 +17,7 @@ class CopyDialog : public QDialog { void setDestFolder(const QString &dst); void setSources(const QStringList &sources); void refresh(); - + void copy(); protected: QString getDestinationFile(const QString &srcFn); -- cgit v1.2.3-70-g09d2