summaryrefslogtreecommitdiffstats
path: root/filewidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-12-03 00:00:16 +0100
committerArno <arno@disconnect.de>2016-12-03 00:00:16 +0100
commit0432c09d7889009beb9557e0546d0c4f240bb37e (patch)
treeb401ce1815e4e33e4ef79b9a69727f70a80e6e1b /filewidget.cpp
parentc8d8c71460c7e7d403c9dba1addc850a361d3e9c (diff)
downloadShemovCleaner-0432c09d7889009beb9557e0546d0c4f240bb37e.tar.gz
ShemovCleaner-0432c09d7889009beb9557e0546d0c4f240bb37e.tar.bz2
ShemovCleaner-0432c09d7889009beb9557e0546d0c4f240bb37e.zip
Actually use Copy Files to...
Create a FileCopier and show a custom, non-modal progress dialog when we're copying files. Turns out that a QProgressDialog always shows when it's created. This is by design, so I had to implement one that fits my needs. Also, a buffer size of 32K (as used in MKVMerger) is way too small to max out the available bandwidth, so I set it to an (arbitrary) value of 16MB.
Diffstat (limited to 'filewidget.cpp')
-rw-r--r--filewidget.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/filewidget.cpp b/filewidget.cpp
index 30254d4..409c551 100644
--- a/filewidget.cpp
+++ b/filewidget.cpp
@@ -35,12 +35,21 @@
#include "filewidget.h"
#include "filesorter.h"
#include "filedisplay.h"
+#include "filecopier.h"
#include "origindialog.h"
#include "helper.h"
#include "globals.h"
#include "viewer.h"
+#include "progressdialog.h"
FileWidget::FileWidget(QWidget *parent) : QWidget(parent), mCopyToMenu(0), mCopyToMapper(0) {
+ mFileCopier = new FileCopier(this);
+ mCopyProgress = new ProgressDialog;
+ connect(mFileCopier, SIGNAL(newFile(QString,qint64)), this, SLOT(setupProgress(QString,qint64)));
+ connect(mFileCopier, SIGNAL(bytesRead(qint64)), this, SLOT(setCopyProgress(qint64)));
+ connect(mFileCopier, SIGNAL(finished()), this, SLOT(hideCopyProgress()));
+ connect(mFileCopier, SIGNAL(success(bool,QString)), this, SLOT(copySuccess(bool,QString)));
+ connect(mCopyProgress, SIGNAL(cancelled()), this, SLOT(hideCopyProgress()));
setupGui();
}
@@ -116,6 +125,7 @@ void FileWidget::setupGui(){
createActions();
mMimeData = new QMimeData;
mFileView->setFocus();
+ mCopyProgress->setVisible(false);
}
void FileWidget::createActions(){
@@ -501,6 +511,59 @@ void FileWidget::addAsOrigin(){
mOrignDlg->show();
}
+void FileWidget::setupProgress(QString file, qint64 size){
+ mCopyProgress->setMaximum(size / 1024 / 1024);
+ mCopyProgress->setValue(0);
+ QString progressLabel = QString(tr("Copying %1")).arg(file);
+ mCopyProgress->setLabelText(progressLabel);
+}
+
+void FileWidget::setCopyProgress(qint64 bytes){
+ int val = bytes / 1024 / 1024;
+ mCopyProgress->setValue(val);
+}
+
+void FileWidget::copyFiles(QString destDir){
+ QModelIndexList files = mFileView->selectionModel()->selectedRows();
+ if(!files.isEmpty()){
+ foreach(auto idx, files){
+ QString fp = idx.data(FullPathRole).toString();
+ QFileInfo fi(fp);
+ if(!fi.exists()){
+ continue;
+ }
+ QString destFile = QString("%1%2%3").arg(destDir).arg(QDir::separator()).arg(fi.fileName());
+ mFileCopier->addJob(fp, destFile);
+ }
+ mCopyProgress->show();
+ if(!mFileCopier->isRunning()){
+ mFileCopier->start();
+ }
+ }
+}
+
+void FileWidget::hideCopyProgress(){
+ if(mFileCopier->isRunning()){
+ mFileCopier->cancel();
+ }
+ mCopyProgress->hide();
+}
+
+void FileWidget::copySuccess(bool success, QString source){
+ if(success){
+ QFileInfo fi(source);
+ auto sourceFiles = mModel->findItems(fi.fileName(), Qt::MatchExactly, NameColumn);
+ if(!sourceFiles.isEmpty()){
+ QModelIndex idx = mModel->indexFromItem(sourceFiles.first());
+ if(idx.isValid()){
+ QModelIndex copyIdx = idx.sibling(idx.row(), CopiedColumn);
+ mModel->setData(copyIdx, QColor(Qt::blue), Qt::ForegroundRole);
+ mModel->setData(copyIdx, QChar(0x2642));
+ }
+ }
+ }
+}
+
void FileWidget::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){
Q_UNUSED(selected);
Q_UNUSED(deselected);
@@ -645,7 +708,9 @@ void FileWidget::contextMenuEvent(QContextMenuEvent *e){
mCopyToMenu->clear();
mCopyToMenu->setTitle(tr("Copy Files to..."));
mCopyToMenu->setIcon(QIcon(":/hourglass_figure.png"));
- mCopyToMapper->deleteLater();
+ if(mCopyToMapper){
+ mCopyToMapper->deleteLater();
+ }
mCopyToMapper = new QSignalMapper;
QStringList copyToDirs = s.value("copydirs").toStringList();
foreach(auto d, copyToDirs){
@@ -657,6 +722,7 @@ void FileWidget::contextMenuEvent(QContextMenuEvent *e){
mCopyToMenu->addAction(copyA);
}
}
+ connect(mCopyToMapper, SIGNAL(mapped(QString)), this, SLOT(copyFiles(QString)));
contextMenu.addMenu(mCopyToMenu);
contextMenu.addAction(createSeparator());
contextMenu.addActions(actions());