summaryrefslogtreecommitdiffstats
path: root/archivebrowser.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-03-04 20:06:35 +0100
committerArno <arno@disconnect.de>2016-03-04 20:06:35 +0100
commitdbe1e9b2fb16ebf25dcb829e066fd9f8690d4283 (patch)
treef4a0c5979a981a140572a8abfc5baa2f81b6f041 /archivebrowser.cpp
parent8cd9d32bb11a08ff4ff8265fe9309dda1c666856 (diff)
downloadSheMov-dbe1e9b2fb16ebf25dcb829e066fd9f8690d4283.tar.gz
SheMov-dbe1e9b2fb16ebf25dcb829e066fd9f8690d4283.tar.bz2
SheMov-dbe1e9b2fb16ebf25dcb829e066fd9f8690d4283.zip
Now MoveToUSB does something!
Make it work. Lessons learned: Don't keep a QProgressDialog around. Use it and delete it later. Otherwise it will show up spontaneously.
Diffstat (limited to 'archivebrowser.cpp')
-rw-r--r--archivebrowser.cpp104
1 files changed, 103 insertions, 1 deletions
diff --git a/archivebrowser.cpp b/archivebrowser.cpp
index 6b83d99..fbeb50d 100644
--- a/archivebrowser.cpp
+++ b/archivebrowser.cpp
@@ -18,9 +18,11 @@
#include <QProcess>
#include <QToolBar>
#include <QSplitter>
+#include <QProgressDialog>
#include "archivebrowser.h"
#include "archivebrowsermodel.h"
+#include "copyworker.h"
#include "smtreeview.h"
#include "smglobals.h"
#include "pictureviewer2.h"
@@ -74,6 +76,11 @@ ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent), mSelectedSize
mainLayout->addWidget(mTree);
setLayout(mainLayout);
mTree->setSortingEnabled(true);
+
+ //copyworker
+ mUSBProgress = 0;
+ mCopyWorker = new CopyWorker(this);
+
}
void ArchiveBrowser::browserSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
@@ -154,7 +161,67 @@ void ArchiveBrowser::moveToBurn() {
}
void ArchiveBrowser::moveToUSB(){
-
+ QModelIndexList sel = mTree->selectionModel()->selectedRows();
+ if(sel.isEmpty()){
+ return;
+ }
+ QSettings s;
+ QString destDirS = s.value("paths/usb").toString();
+ QFileInfo destFi(destDirS);
+ if(!destFi.exists() || !destFi.isDir()){
+ QString msg = QString(tr("%1 does not exist or isn't a directory!")).arg(destFi.absoluteFilePath());
+ QMessageBox::critical(this, tr("Error"), msg);
+ return;
+ }
+ int nextDVDNo = mModel->nextDVDNo();
+ QString dvdDirS = QString("DVD_%1").arg(QString::number(nextDVDNo));
+ QDir dest(destDirS);
+ if(dest.exists(dvdDirS)){
+ QString msg = QString(tr("Something fishy is going on: %1 already exists in %2!")).arg(dvdDirS).arg(destDirS);
+ QMessageBox::critical(this, tr("Error"), msg);
+ return;
+ }
+ bool mkdir = dest.mkdir(dvdDirS);
+ if(!mkdir){
+ QString msg = QString(tr("Failed to create %1 in %2!")).arg(dvdDirS).arg(destDirS);
+ QMessageBox::critical(this, tr("Error"), msg);
+ return;
+ }
+ // this one is .../DVD_123
+ QString finalDir = QString("%1/%2").arg(destDirS).arg(dvdDirS);
+ QString msg = QString(tr("<p>This will do the following:</p><p><ul><li>Move %1 file(s) to %2</li><li>Update the DVD no. for %1 files</li></ul></p><p>Continue?</p>")).arg(sel.size()).arg(finalDir);
+ int retval = QMessageBox::question(this, tr("Question"), msg, QMessageBox::Yes | QMessageBox::No);
+ if(retval == QMessageBox::Yes){
+ mCopyWorker->clear();
+ QDir finalD(finalDir);
+ foreach(QModelIndex idx, sel){
+ QString dirName = idx.data(ArchiveBrowserModel::NameRole).toString();
+ dirName.replace(' ', '.');
+ // this one .../DVD_123/series_name
+ // don't check for success, it may already exist!
+ finalD.mkdir(dirName);
+ QModelIndex real = mProxy->mapToSource(idx);
+ QModelIndexList children = mModel->children(real);
+ foreach(QModelIndex child, children){
+ QString source = child.data(ArchiveBrowserModel::FullPathRole).toString();
+ QFileInfo sFi(source);
+ QString destination = QString("%1/%2/%3").arg(finalDir).arg(dirName).arg(sFi.fileName());
+ mCopyWorker->enqueue(source, destination);
+ mCopyWorker->appendData(source, child.data(ArchiveBrowserModel::FileTypeRole));
+ mCopyWorker->appendData(source, child.data(ArchiveBrowserModel::GenericIdRole));
+ }
+ }
+ mUSBProgress = new QProgressDialog(this);
+ connect(mCopyWorker, SIGNAL(bytesRead(int)), mUSBProgress, SLOT(setValue(int)));
+ connect(mCopyWorker, SIGNAL(error(QString)), this, SLOT(copyError(QString)));
+ connect(mCopyWorker, SIGNAL(success(QString)), this, SLOT(copySuccess(QString)));
+ connect(mCopyWorker, SIGNAL(file(QString)), this, SLOT(setCopyFile(QString)));
+ mUSBProgress->setLabelText(tr("Copying files..."));
+ mUSBProgress->setMinimum(0);
+ mUSBProgress->setMaximum(mCopyWorker->max());
+ mUSBProgress->show();
+ mCopyWorker->start();
+ }
}
void ArchiveBrowser::refresh() {
@@ -219,6 +286,41 @@ void ArchiveBrowser::resetAll() {
emit itemCountChanged(0);
}
+void ArchiveBrowser::copyError(QString error){
+ mUSBProgress->hide();
+ QMessageBox::critical(this, tr("Copy Error"), error);
+ mUSBProgress->disconnect();
+ mUSBProgress->deleteLater();
+}
+
+void ArchiveBrowser::copySuccess(QString success){
+ mUSBProgress->hide();
+ QMessageBox::information(this, tr("Copy Success"), success);
+ mUSBProgress->disconnect();
+ mUSBProgress->deleteLater();
+ QString msg = QString(tr("Delete source files and update database?"));
+ int q = QMessageBox::question(this, tr("Question"), msg);
+ if(q == QMessageBox::Yes){
+ QHash<QString, QList<QVariant> > data = mCopyWorker->data();
+ QList<int> filesToUpdate;
+ foreach(QString source, data.keys()){
+ int ft = data.value(source).at(0).toInt();
+ if(ft == FT_MOVIE){
+ QFile::remove(source);
+ filesToUpdate << data.value(source).at(1).toInt();
+ }
+ }
+ mModel->updateDVDNo(filesToUpdate);
+ mModel->refresh();
+ mProxy->setBytesRemaining(0);
+ }
+}
+
+void ArchiveBrowser::setCopyFile(QString file){
+ QString msg = QString(tr("Copying %1")).arg(file);
+ mUSBProgress->setLabelText(msg);
+}
+
QModelIndexList ArchiveBrowser::selectedRows(const QItemSelection &sel){
QModelIndexList retval;
QModelIndexList selIdx = sel.indexes();