summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2015-05-11 21:37:12 +0200
committerTannin <devnull@localhost>2015-05-11 21:37:12 +0200
commit5a908442d646b5f3dbf7d22fc2331c8cc2b0d15a (patch)
treeda512fa0d23e2e351104d6703d71d314b5423021 /src
parent328244692b9e4bd216be95edbb0d0f944dbcb34a (diff)
dropping an url on the download widget now attempts to download the url
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp7
-rw-r--r--src/mainwindow.cpp93
-rw-r--r--src/mainwindow.h2
3 files changed, 52 insertions, 50 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 81732f4d..e48d6bf1 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -358,7 +358,6 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
DownloadInfo *newDownload = DownloadInfo::createNew(fileInfo, URLs);
QString baseName = fileName;
-
if (!fileInfo->fileName.isEmpty()) {
baseName = fileInfo->fileName;
} else {
@@ -368,7 +367,6 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
baseName = dispoName;
}
}
-
if (QFile::exists(m_OutputDirectory + "/" + baseName) &&
(QMessageBox::question(nullptr, tr("Download again?"), tr("A file with the same name has already been downloaded. "
"Do you want to download it again? The new file will receive a different name."),
@@ -377,11 +375,9 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
delete newDownload;
return false;
}
-
newDownload->setName(getDownloadFileName(baseName), false);
startDownload(reply, newDownload, false);
-
// emit update(-1);
return true;
}
@@ -1234,7 +1230,8 @@ bool DownloadManager::ServerByPreference(const std::map<QString, int> &preferred
int DownloadManager::startDownloadURLs(const QStringList &urls)
{
- addDownload(urls, -1, -1, nullptr);
+ ModRepositoryFileInfo info;
+ addDownload(urls, -1, -1, &info);
return m_ActiveDownloads.size() - 1;
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f8b57a2c..10af1b27 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4606,7 +4606,7 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
//types
QList<QUrl> urls = data->urls();
bool ok = true;
- for (auto url : urls) {
+ for (const QUrl &url : urls) {
if (url.isLocalFile()) {
QString local = url.toLocalFile();
bool fok = false;
@@ -4621,8 +4621,6 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
break;
}
}
- //We should probably allow the user to drop urls here and remember the
- //url for installing later.
}
if (ok) {
event->accept();
@@ -4631,56 +4629,61 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
}
}
+void MainWindow::dropLocalFile(const QUrl &url, const QString &outputDir, bool move)
+{
+ QFileInfo file(url.toLocalFile());
+ if (!file.exists()) {
+ qWarning("invalid source file %s", qPrintable(file.absoluteFilePath()));
+ return;
+ }
+ QString target = outputDir + "/" + file.fileName();
+ if (QFile::exists(target)) {
+ 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();
+ switch (box.buttonRole(box.clickedButton())) {
+ case QMessageBox::RejectRole:
+ return;
+ case QMessageBox::ActionRole:
+ break;
+ default:
+ case QMessageBox::YesRole:
+ target = m_OrganizerCore.downloadManager()->getDownloadFileName(file.fileName());
+ break;
+ }
+ }
+
+ bool success = false;
+ if (move) {
+ success = shellMove(file.absoluteFilePath(), target, true, this);
+ } else {
+ success = shellCopy(file.absoluteFilePath(), target, true, this);
+ }
+ if (!success) {
+ qCritical("file operation failed: %s", qPrintable(windowsErrorString(::GetLastError())));
+ }
+}
+
void MainWindow::dropEvent(QDropEvent *event)
{
Qt::DropAction action = event->proposedAction();
- QString output_dir = m_OrganizerCore.downloadManager()->getOutputDirectory();
+ QString outputDir = 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();
- if (QFile::exists(target)) {
- 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;
-
- }
- }
-
- if (action == Qt::MoveAction) {
- if (shellMove(file.absoluteFilePath(), target, true, this)) {
- continue;
- }
- }
- else {
- if (shellCopy(file.absoluteFilePath(), target, true, this)) {
- continue;
- }
+ for (const QUrl &url : event->mimeData()->urls()) {
+ if (url.isLocalFile()) {
+ dropLocalFile(url, outputDir, action == Qt::MoveAction);
+ } else {
+ m_OrganizerCore.downloadManager()->startDownloadURLs(QStringList() << url.url());
}
- //Something has gone horribly wrong here
- qDebug("error %d", GetLastError());
}
event->accept();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 7e59a7b0..405a39ef 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -254,6 +254,8 @@ private:
void startMonitorSaves();
void stopMonitorSaves();
+ void dropLocalFile(const QUrl &url, const QString &outputDir, bool move);
+
private:
static const char *PATTERN_BACKUP_GLOB;