|
1 /* js for download dialogs */ |
|
2 |
|
3 function writeDownloadDialog() |
|
4 { |
|
5 var image = 'download.snippet/icons/download_dialog_icon.png'; |
|
6 |
|
7 var html = |
|
8 '<div class="downloadDialogBox">' + |
|
9 '<table><tr>' + |
|
10 '<td class="downloadDialogIcon">' + |
|
11 '<img src="' + image + '" alt="">' + |
|
12 '</td>' + |
|
13 '<td class="downloadDialogText" id="DownloadDialogTextId">' + |
|
14 'Replace with localized message text' + |
|
15 '</td>' + |
|
16 '</tr></table>' + |
|
17 '</div>'; |
|
18 |
|
19 document.write(html); |
|
20 } |
|
21 |
|
22 var downloadTimeoutId = null; |
|
23 |
|
24 var downloadTimeoutSeconds = 3; |
|
25 |
|
26 function disableDownloadTimeout(caller) |
|
27 { |
|
28 if (downloadTimeoutId != null) { |
|
29 clearTimeout(downloadTimeoutId); |
|
30 downloadTimeoutId = null; |
|
31 } |
|
32 } |
|
33 |
|
34 function hideDownloadDialog() |
|
35 { |
|
36 window.snippets.DownloadDialogId.hide(); |
|
37 |
|
38 // Clear timeout so we can use this function to hide |
|
39 // the download dialog in response to an external |
|
40 // mouse event and not just because of a timeout. |
|
41 |
|
42 disableDownloadTimeout("hideDownloadDialog"); |
|
43 } |
|
44 |
|
45 function showDownloadDialog(messageHTML) |
|
46 { |
|
47 // Clear timeout so we can replace an existing dialog |
|
48 // with the newest one without having hideDownloadDialog() |
|
49 // hide the wrong dialog. |
|
50 |
|
51 disableDownloadTimeout("showDownloadDialog"); |
|
52 |
|
53 document.getElementById('DownloadDialogTextId').innerHTML = messageHTML; |
|
54 |
|
55 window.snippets.DownloadDialogId.setPosition(10,80); |
|
56 window.snippets.DownloadDialogId.show(); |
|
57 window.snippets.DownloadDialogId.repaint(); |
|
58 |
|
59 downloadTimeoutId = setTimeout( |
|
60 hideDownloadDialog, |
|
61 downloadTimeoutSeconds * 1000); |
|
62 } |
|
63 |
|
64 // This will get called for BOTH explicit download |
|
65 // requests and for unsupported content downloads. |
|
66 // In the former case the file argument may not be |
|
67 // final as the download manager will rename files |
|
68 // to avoid overwriting existing files in the download |
|
69 // directory. |
|
70 // |
|
71 function onDownloadCreated(messageHTML) |
|
72 { |
|
73 showDownloadDialog(messageHTML); |
|
74 } |
|
75 |
|
76 // This will get called for explicit download requests, |
|
77 // i.e. requests generated by selecting "Save Link" or |
|
78 // "Save Image" from the long-press menu. |
|
79 // |
|
80 // This will NOT get called for downloads executed in |
|
81 // response to QWebPage unsupportedContent signals, |
|
82 // as they get started by the QWebPage implementation |
|
83 // before they get passed to the download manager. |
|
84 // |
|
85 function onDownloadStarted(messageHTML) |
|
86 { |
|
87 showDownloadDialog(messageHTML); |
|
88 } |
|
89 |
|
90 function onDownloadSuccess(messageHTML) |
|
91 { |
|
92 showDownloadDialog(messageHTML); |
|
93 } |
|
94 |
|
95 function onDownloadFailure(messageHTML) |
|
96 { |
|
97 showDownloadDialog(messageHTML); |
|
98 } |
|
99 |
|
100 function connectDownloadSignals() |
|
101 { |
|
102 window.downloads.downloadCreated.connect(onDownloadCreated); |
|
103 window.downloads.downloadStarted.connect(onDownloadStarted); |
|
104 window.downloads.downloadSuccess.connect(onDownloadSuccess); |
|
105 window.downloads.downloadFailure.connect(onDownloadFailure); |
|
106 |
|
107 window.snippets.DownloadDialogId.externalMouseEvent.connect( |
|
108 function(type, name, description) { |
|
109 if ((name == "QGraphicsSceneMouseReleaseEvent") || (name == "QGraphicsSceneResizeEvent")) { |
|
110 hideDownloadDialog(); |
|
111 } |
|
112 } |
|
113 ); |
|
114 } |
|
115 |
|
116 if (window.downloads != null) { |
|
117 window.chrome.chromeComplete.connect(connectDownloadSignals); |
|
118 } |