From ce925bc73e077fea813e509af4e9ad19f4306960 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sun, 26 Apr 2015 09:44:57 +0100 Subject: Allows drag-and-drop into the download tab --- src/mainwindow.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1566bc8a..945b258c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -110,6 +110,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include #else @@ -4547,3 +4548,119 @@ void MainWindow::on_manageArchivesBox_toggled(bool) { m_OrganizerCore.refreshBSAList(); } + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + //Accept copy or move drags to the download window. Link drags are not + //meaningful (Well, they are - we could drop a link in the download folder, + //but you need privileges to do that). + if (ui->downloadTab->isVisible() && + (event->proposedAction() == Qt::CopyAction || + event->proposedAction() == Qt::MoveAction) && + event->answerRect().intersects(ui->downloadTab->rect())) { + + //If I read the documentation right, this won't work under a motif windows + //manager and the check needs to be done at the drop. However, that means + //the user might be allowed to drop things which we can't sanely process + QMimeData const *data = event->mimeData(); + + if (data->hasUrls()) { + QStringList extensions = + m_OrganizerCore.installationManager()->getSupportedExtensions(); + + //This is probably OK - scan to see if these are moderately sane archive + //types + QList urls = data->urls(); + bool ok = true; + for (auto url : urls) { + if (url.isLocalFile()) { + QString local = url.toLocalFile(); + bool fok = false; + for (auto ext : extensions) { + if (local.endsWith(ext, Qt::CaseInsensitive)) { + fok = true; + break; + } + } + if (! fok) { + ok = false; + break; + } + } + //We should probably allow the user to drop urls here and remember the + //url for installing later. + } + if (ok) { + event->accept(); + } + } + } +} + +void MainWindow::dropEvent(QDropEvent *event) +{ + Qt::DropAction action = event->proposedAction(); + QString output_dir = m_OrganizerCore.downloadManager()->getOutputDirectory(); + if (action == Qt::MoveAction) { + //Tell windows I'm taking control and will delete the source of a move. + event->setDropAction(Qt::TargetMoveAction); + } + for (auto url : event->mimeData()->urls()) { + QFileInfo file(url.toLocalFile()); + QString target = output_dir + "/" + file.fileName(); + //FIXME: Check here if the file exists and offer a rename + if (QFile::exists(target)) { + //Make this box have 2 buttons: + //'overwrite' and 'rename' + //for copy it's ok to add a 'do nothing' button + QMessageBox box(QMessageBox::Question, + file.fileName(), + tr("A file with the same name has already been downloaded. " + "What would you like to do?")); + box.addButton(tr("Overwrite"), QMessageBox::ActionRole); + box.addButton(tr("Rename new file"), QMessageBox::YesRole); + box.addButton(tr("Ignore file"), QMessageBox::RejectRole); + + box.exec(); + QMessageBox::ButtonRole role = box.buttonRole(box.clickedButton()); + switch (role) + { + case QMessageBox::RejectRole: + continue; + + case QMessageBox::ActionRole: + break; + + default: + case QMessageBox::YesRole: + target = m_OrganizerCore.downloadManager()->getDownloadFileName(file.fileName()); + break; + + } + } + + //We should really show progress and add a cancel button for these in case + //the operation takes a long time. + if (action == Qt::MoveAction) { + if (MoveFileExW(file.absoluteFilePath().toStdWString().c_str(), + target.toStdWString().c_str(), + MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) != 0) { + continue; + } + } + else { + if (CopyFileW(file.absoluteFilePath().toStdWString().c_str(), + target.toStdWString().c_str(), + FALSE) != 0) { + continue; + } + } + //Something has gone horribly wrong here + qDebug("error %d", GetLastError()); + if (action == Qt::MoveAction) { + //Don't let the original source get deleted on a move + event->setDropAction(Qt::TargetMoveAction); + } + } + event->accept(); +} -- cgit v1.3.1 From c909f8ce4fa8d800a9cf5c0aafb5d8a3f577fcf9 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Wed, 29 Apr 2015 21:14:46 +0100 Subject: remove redundant comments/code from drag'n'drop stuff --- src/mainwindow.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 945b258c..cadd935c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4610,9 +4610,6 @@ void MainWindow::dropEvent(QDropEvent *event) QString target = output_dir + "/" + file.fileName(); //FIXME: Check here if the file exists and offer a rename if (QFile::exists(target)) { - //Make this box have 2 buttons: - //'overwrite' and 'rename' - //for copy it's ok to add a 'do nothing' button QMessageBox box(QMessageBox::Question, file.fileName(), tr("A file with the same name has already been downloaded. " @@ -4657,10 +4654,6 @@ void MainWindow::dropEvent(QDropEvent *event) } //Something has gone horribly wrong here qDebug("error %d", GetLastError()); - if (action == Qt::MoveAction) { - //Don't let the original source get deleted on a move - event->setDropAction(Qt::TargetMoveAction); - } } event->accept(); } -- cgit v1.3.1 From 5f399f6a39c24cac66e572f1f78aea5703130dea Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Wed, 29 Apr 2015 21:18:43 +0100 Subject: Another removal of redundant commentary --- src/mainwindow.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cadd935c..755b5469 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4608,7 +4608,6 @@ void MainWindow::dropEvent(QDropEvent *event) for (auto url : event->mimeData()->urls()) { QFileInfo file(url.toLocalFile()); QString target = output_dir + "/" + file.fileName(); - //FIXME: Check here if the file exists and offer a rename if (QFile::exists(target)) { QMessageBox box(QMessageBox::Question, file.fileName(), -- cgit v1.3.1 From 89eabf3c4df39f918fae9414d26a4cf5459f2047 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sun, 3 May 2015 09:51:01 +0100 Subject: added a 'yes to all' shellMove and made the drag-and-drop code use shellMove/shellCopy --- src/mainwindow.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 755b5469..578d4419 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4635,19 +4635,13 @@ void MainWindow::dropEvent(QDropEvent *event) } } - //We should really show progress and add a cancel button for these in case - //the operation takes a long time. if (action == Qt::MoveAction) { - if (MoveFileExW(file.absoluteFilePath().toStdWString().c_str(), - target.toStdWString().c_str(), - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) != 0) { + if (shellMove(file.absoluteFilePath(), target, true, this)) { continue; } } else { - if (CopyFileW(file.absoluteFilePath().toStdWString().c_str(), - target.toStdWString().c_str(), - FALSE) != 0) { + if (shellCopy(file.absoluteFilePath(), target, true, this)) { continue; } } -- cgit v1.3.1