@@ -19,7 +19,8 @@
20import QtQuick 2.0
20import QtQuick 2.0
21import Ubuntu.Settings.Menus 0.1 as Menus
21import Ubuntu.Settings.Menus 0.1 as Menus
22+import Ubuntu.Settings.Components 0.1 as SettingsComponents
22−import QMenuModel 0.1 as QMenuModel
23+import QMenuModel 0.1
23import Utils 0.1 as Utils
24import Utils 0.1 as Utils
24import Ubuntu.Components.ListItems 0.1 as ListItems
25import Ubuntu.Components.ListItems 0.1 as ListItems
25import Ubuntu.Components 0.1
26import Ubuntu.Components 0.1
@@ -27,6 +28,7 @@ import Ubuntu.Components 0.1
28 id: menuFactory
29 id: menuFactory
31+ property var rootModel: null
30 property var menuModel: null
32 property var menuModel: null
32 property var _map: {
34 property var _map: {
@@ -41,6 +43,7 @@ Item {
41 "com.canonical.indicator.switch" : switchMenu,
43 "com.canonical.indicator.switch" : switchMenu,
42 "com.canonical.indicator.alarm" : alarmMenu,
44 "com.canonical.indicator.alarm" : alarmMenu,
43 "com.canonical.indicator.appointment" : appointmentMenu,
45 "com.canonical.indicator.appointment" : appointmentMenu,
46+ "com.canonical.indicator.transfer" : transferMenu,
45 "com.canonical.indicator.messages.messageitem" : messageItem,
48 "com.canonical.indicator.messages.messageitem" : messageItem,
46 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
49 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
@@ -330,7 +333,7 @@ Item {
330 property int menuIndex: -1
333 property int menuIndex: -1
331 property var extendedData: menuData && menuData.ext || undefined
334 property var extendedData: menuData && menuData.ext || undefined
333− property var strengthAction: QMenuModel.UnityMenuAction {
336+ property var strengthAction: UnityMenuAction {
334 model: menuModel
337 model: menuModel
335 index: menuIndex
338 index: menuIndex
336 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
339 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
@@ -442,17 +445,17 @@ Item {
442 property int menuIndex: -1
445 property int menuIndex: -1
443 property var extendedData: menuData && menuData.ext || undefined
446 property var extendedData: menuData && menuData.ext || undefined
445− property var playAction: QMenuModel.UnityMenuAction {
448+ property var playAction: UnityMenuAction {
446 model: menuModel
449 model: menuModel
447 index: menuIndex
450 index: menuIndex
448 name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
451 name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
450− property var nextAction: QMenuModel.UnityMenuAction {
453+ property var nextAction: UnityMenuAction {
451 model: menuModel
454 model: menuModel
452 index: menuIndex
455 index: menuIndex
453 name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
456 name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
455− property var previousAction: QMenuModel.UnityMenuAction {
458+ property var previousAction: UnityMenuAction {
456 model: menuModel
459 model: menuModel
457 index: menuIndex
460 index: menuIndex
458 name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
461 name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
@@ -489,6 +492,121 @@ Item {
497+ Menus.TransferMenu {
498+ objectName: "transferMenu"
500+ property QtObject menuData: null
501+ property var menuModel: menuFactory.menuModel
502+ property int menuIndex: -1
503+ property var extendedData: menuData && menuData.ext || undefined
504+ property var uid: getExtendedProperty(extendedData, "xCanonicalUid", undefined)
506+ text: menuData && menuData.label || ""
507+ iconSource: menuData && menuData.icon || "image://theme/save"
509+ enabled: menuData && menuData.sensitive || false
511+ confirmRemoval: true
516+ busName: rootModel.busName
517+ objectPath: rootModel.actions["indicator"]
519+ property QtObject activateAction: action("activate-transfer")
520+ property QtObject cancelAction: action("cancel-transfer")
521+ property QtObject pauseAction: action("pause-transfer")
522+ property QtObject resumeAction: action("resume-transfer")
523+ property QtObject transferStates: action("transfer-states")
525+ Component.onCompleted: actionGroup.start()
528+ property var transferStateProperties: uid !== undefined && actionGroup.transferStates.valid && actionGroup.transferStates.state[uid] || undefined
530+ property var transferState : transferStateProperties !== undefined && transferStateProperties["state"] || undefined
531+ property var secondsLeft : transferStateProperties !== undefined && transferStateProperties["seconds-left"]
533+ active: transferStateProperties !== undefined && transferState !== Menus.TransferState.FINISHED
534+ progress : transferStateProperties !== undefined && transferStateProperties["percent"] || 0.0
536+ property var timeRemaining: {
537+ if (secondsLeft === undefined) return undefined;
540+ var hours = Math.floor(secondsLeft / (60 * 60));
541+ var minutes = Math.floor(secondsLeft / 60) % 60;
542+ var seconds = secondsLeft % 60;
544+ remaining += hours + (hours == 1 ? " hour" : " hours");
547+ if (remaining != "") remaining += ", ";
548+ remaining += minutes + (minutes == 1 ? " minute" : " minutes");
550+ // don't include seconds if hours > 0
551+ if (hours == 0 && minutes < 5 && seconds > 0) {
552+ if (remaining != "") remaining += ", ";
553+ remaining += seconds + (seconds == 1 ? " second" : " seconds");
555+ if (remaining == "")
556+ remaining = "0 seconds";
557+ return remaining + " remaining";
561+ switch (transferState) {
562+ case Menus.TransferState.QUEUED:
563+ return i18n.tr("In queue...");
564+ case Menus.TransferState.HASHING:
565+ case Menus.TransferState.PROCESSING:
566+ case Menus.TransferState.RUNNING:
567+ return timeRemaining === undefined ? "Downloading" : timeRemaining;
568+ case Menus.TransferState.PAUSED:
569+ return i18n.tr("Paused, tap to resume");
570+ case Menus.TransferState.CANCELED:
571+ return i18n.tr("Canceled");
572+ case Menus.TransferState.FINISHED:
573+ return i18n.tr("Finished");
574+ case Menus.TransferState.ERROR:
575+ return i18n.tr("Failed, tap to retry");
580+ onMenuModelChanged: {
583+ onMenuIndexChanged: {
587+ actionGroup.activateAction.activate(uid);
588+ shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
591+ function loadAttributes() {
592+ if (!menuModel || menuIndex == -1) return;
593+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-uid': 'string'});
597+ actionGroup.cancelAction.activate(uid);
601+ actionGroup.pauseAction.activate(uid);
605+ actionGroup.resumeAction.activate(uid);
492 function load(modelData) {
610 function load(modelData) {
493 if (modelData.type !== undefined) {
611 if (modelData.type !== undefined) {
494 var component = _map[modelData.type];
612 var component = _map[modelData.type];