summaryrefslogtreecommitdiff
path: root/net/kdenetwork4/patches/patch-ba
blob: 4df3754af8f8dc287dbb6bf9a9a2e8fa7924d747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$NetBSD: patch-ba,v 1.1 2010/05/16 21:21:39 markd Exp $

--- kget/transfer-plugins/metalink/metalink.cpp.orig	2010-04-29 19:58:02.000000000 +0000
+++ kget/transfer-plugins/metalink/metalink.cpp
@@ -99,6 +99,7 @@ void Metalink::start()
 void Metalink::metalinkInit(const KUrl &src, const QByteArray &data)
 {
     kDebug(5001);
+
     bool justDownloaded = !m_localMetalinkLocation.isValid();
     if (!src.isEmpty())
     {
@@ -121,7 +122,9 @@ void Metalink::metalinkInit(const KUrl &
     //error
     if (!m_metalink.isValid())
     {
-        kDebug(5001) << "Unknown error when trying to load the .metalink-file";
+        kError(5001) << "Unknown error when trying to load the .metalink-file. Metalink is not valid.";
+        setStatus(Job::Aborted);
+        setTransferChange(Tc_Status, true);
         return;
     }
 
@@ -202,7 +205,7 @@ void Metalink::metalinkInit(const KUrl &
     if (!m_dataSourceFactory.size())
     {
         KMessageBox::error(0, i18n("Download failed, no working URLs were found."), i18n("Error"));
-        setStatus(Job::Aborted, i18n("An error occurred...."), SmallIcon("document-preview"));
+        setStatus(Job::Aborted);
         setTransferChange(Tc_Status, true);
         return;
     }
@@ -227,16 +230,29 @@ void Metalink::metalinkInit(const KUrl &
         ui.treeView->hideColumn(FileItem::SignatureVerified);
         dialog->setMainWidget(widget);
         dialog->setCaption(i18n("File Selection"));
-        dialog->setButtons(KDialog::Ok);
-        connect(dialog, SIGNAL(finished()), this, SLOT(filesSelected()));
+        dialog->setButtons(KDialog::Ok | KDialog::Cancel);
+        connect(dialog, SIGNAL(finished(int)), this, SLOT(fileDlgFinished(int)));
 
         dialog->show();
     }
 }
 
-void Metalink::filesSelected()
+void Metalink::fileDlgFinished(int result)
 {
+    //BEGIN HACK if the dialog was not accepted untick every file, so that the download does not start
+    //generally setStatus should do the job as well, but does not as it appears
+    if (result != QDialog::Accepted) {
+        for (int row = 0; row < fileModel()->rowCount(); ++row) {
+            QModelIndex index = fileModel()->index(row, FileItem::File);
+            if (index.isValid()) {
+                fileModel()->setData(index, Qt::Unchecked, Qt::CheckStateRole);
+            }
+        }
+    }
+    //END
+
     QModelIndexList files = fileModel()->fileIndexes(FileItem::File);
+    int numFilesSelected = 0;
     foreach (const QModelIndex &index, files)
     {
         const KUrl dest = fileModel()->getUrl(index);
@@ -244,6 +260,9 @@ void Metalink::filesSelected()
         if (m_dataSourceFactory.contains(dest))
         {
             m_dataSourceFactory[dest]->setDoDownload(doDownload);
+            if (doDownload) {
+                ++numFilesSelected;
+            }
         }
     }
 
@@ -252,9 +271,15 @@ void Metalink::filesSelected()
     processedSizeChanged();
     speedChanged();
 
+    //no files selected to download or dialog rejected, stop the download
+    if (!numFilesSelected  || (result != QDialog::Accepted)) {
+         setStatus(Job::Stopped);//FIXME
+         setTransferChange(Tc_Status, true);
+        return;
+    }
+
     //some files may be set to download, so start them as long as the transfer is not stopped
-    if (status() != Job::Stopped)
-    {
+    if (status() != Job::Stopped) {
         startMetalink();
     }
 }