• Skip to content
  • Skip to link menu
KDE API Documentation - DownloadDialog.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • core
DownloadDialog.qml
1 /* GCompris - DownloadDialog.qml
2  *
3  * Copyright (C) 2014 Holger Kaelberer <holger.k@elberer.de>
4  *
5  * Authors:
6  * Holger Kaelberer <holger.k@elberer.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 import QtQuick 2.2
22 import GCompris 1.0
23 import QtQuick.Layouts 1.1
24 import QtQuick.Controls 1.0
25 import "qrc:/gcompris/src/core/core.js" as Core
26 
40 Item {
41  id: downloadDialog
42  opacity: 0
43 
44  anchors {
45  fill: parent
46  }
47 
52  property Item main
53 
59  property bool autohide: false;
60 
66  property bool reportSuccess: true;
67 
73  property bool reportError: true;
74 
83  property bool dynamic: false
84 
90  property alias backgroundButtonVisible: backgroundButton.visible
91 
97  property alias abortButtonVisible: abortButton.visible
98 
106  property int fixedFontSize: 14
107 
109 
110  // start and stop trigs the animation FIXME: need to document?
111  signal start
112  signal stop
113 
114  // emitted at stop animation end
115  signal close
116 
117  signal finished
118 
119  onStart: opacity = 1
120  onStop: opacity = 0
121  onClose: destroy()
122 
123  Behavior on opacity { NumberAnimation { duration: 200 } }
124  onOpacityChanged: opacity === 0 ? close() : null
125 
126  function shutdown()
127  {
128  if (downloadDialog.dynamic)
129  Core.destroyDialog(downloadDialog);
130  else
131  downloadDialog.close();
132  }
133 
135 
136  Rectangle {
137  anchors.fill: parent
138  opacity: 0.8
139  color: "grey"
140 
141  MouseArea {
142  // Empty mouseArea to prevent clicking "behind" the Dialog
143  anchors.fill: parent
144  enabled: downloadDialog.opacity != 0
145  }
146  }
147 
148  Item {
149  id: instruction
150  anchors {
151  horizontalCenter: parent.horizontalCenter
152  top: parent.top
153  topMargin: parent.height * 0.1
154  }
155  width: parent.width * 0.8
156 
157  GCText {
158  id: instructionTxt
159  fontSize: mediumSize
160  color: "black"
161  horizontalAlignment: Text.AlignHCenter
162  width: parent.width
163  wrapMode: TextEdit.WordWrap
164  z: 2
165  height: 60 * ApplicationInfo.ratio
166  text: qsTr("Downloading ...")
167  }
168 
169  Rectangle {
170  anchors.fill: instructionTxt
171  z: 1
172  opacity: 0.9
173  radius: 10
174  border.width: 2
175  border.color: "white"
176  gradient: Gradient {
177  GradientStop { position: 0.0; color: "#fff" }
178  GradientStop { position: 0.9; color: "#fff" }
179  GradientStop { position: 1.0; color: "#ddd" }
180  }
181  }
182 
183  ProgressBar {
184  id: downloadDialogProgress
185  width: parent.width
186  anchors {
187  horizontalCenter: parent.horizontalCenter
188  top: instructionTxt.bottom
189  topMargin: 10
190  }
191  visible: true
192  Layout.alignment: Qt.AlignHCenter
193  Layout.rowSpan: 1
194  Layout.fillWidth: true
195  minimumValue: 0
196  maximumValue: 100
197  value: 0
198  }
199 
200  Button {
201  id: backgroundButton
202  width: parent.width
203  height: 60 * ApplicationInfo.ratio
204  anchors {
205  horizontalCenter: parent.horizontalCenter
206  top: downloadDialogProgress.bottom
207  topMargin: 10
208  }
209  //: Run this task in background
210  text: qsTr("Background")
211  style: GCButtonStyle {
212  fixedFontSize: downloadDialog.fixedFontSize
213  }
214  visible: true
215  onClicked: downloadDialog.shutdown();
216  }
217 
218  Button {
219  id: abortButton
220  width: parent.width
221  height: 60 * ApplicationInfo.ratio
222  anchors {
223  horizontalCenter: parent.horizontalCenter
224  top: backgroundButton.bottom
225  topMargin: 10
226  }
227  text: qsTr("Abort")
228  style: GCButtonStyle {
229  fixedFontSize: downloadDialog.fixedFontSize
230  }
231  visible: true
232  onClicked: {
233  if (DownloadManager.downloadIsRunning())
234  DownloadManager.abortDownloads();
235  downloadDialog.finished();
236  downloadDialog.shutdown();
237  }
238  }
239 
240  }
241 
242  Connections {
243  target: DownloadManager
244 
245  onError: {
246  //console.warn("DownloadDialog: DM reports error: " + code + ": " + msg);
247  downloadDialog.finished();
248  if (downloadDialog.reportError
249  && code != 5) { // no error: OperationCanceledError
250  // show error message
251  var messageDialog = Core.showMessageDialog(main,
252  qsTr("Download error") + code + ": " + msg,
253  "", null,
254  "", null,
255  function() {
256  downloadDialog.shutdown();
257  }
258  );
259  } else
260  downloadDialog.shutdown();
261  }
262 
263  onDownloadProgress: downloadDialogProgress.value = 100 * bytesReceived / bytesTotal;
264 
265  onDownloadStarted: {
266  //console.log("dialog: DM reports started: " + resource);
267  downloadDialogProgress.value = 0;
268  }
269 
270  onDownloadFinished: {
271  //console.log("dialog: DM reports finished: " + code);
272  downloadDialog.finished();
273  if (downloadDialog.reportSuccess
274  && code != 1) // note: errors will be reported by the onError handler
275  {
276  // report success
277  downloadDialog.stop();
278  var infText = "";
279  if (code == 0) { // Success
280  infText = qsTr("Your download finished successfully. The data files are now available.")
281  + '\n'
282  + qsTr("Restart any currently active activity.");
283  } else if (code == 2) // NoChange
284  infText = qsTr("Your local data files are up-to-date.")
285 
286  var messageDialog = Core.showMessageDialog(main,
287  infText,
288  "", null,
289  "", null,
290  null
291  );
292  } else if (downloadDialog.autohide)
293  downloadDialog.shutdown();
294  }
295  }
296 
297 }
DownloadManager::shutdown
Q_INVOKABLE void shutdown()
Shutdown DownloadManager instance.
Definition: DownloadManager.cpp:56
DownloadManager::abortDownloads
Q_INVOKABLE void abortDownloads()
Abort all currently running downloads.
Definition: DownloadManager.cpp:94
GCText
A QML component unifying text presentation in GCompris.
Definition: GCText.qml:47
QtQuick
DownloadManager
A singleton class responsible for downloading, updating and maintaining remote resources.
Definition: DownloadManager.h:81
GCButtonStyle::fixedFontSize
real fixedFontSize
Fixed font size of the label in pt.
Definition: GCButtonStyle.qml:41
GCompris
DownloadManager::downloadIsRunning
Q_INVOKABLE bool downloadIsRunning() const
Whether any download is currently running.
Definition: DownloadManager.cpp:89
GCButtonStyle
Provides styling for GCompris' Buttons.
Definition: GCButtonStyle.qml:31
main
GCompris' main QML file defining the top level window.
Definition: main.qml:41
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
ApplicationInfo::ratio
qreal ratio
Ratio factor used for scaling of sizes on high-dpi devices.
Definition: ApplicationInfo.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal