@@ -19,7 +19,8 @@
1919
2020import QtQuick 2.0
2121import Ubuntu.Settings.Menus 0.1 as Menus
22−import QMenuModel 0.1 as QMenuModel
22+import Ubuntu.Settings.Components 0.1 as SettingsComponents
23+import QMenuModel 0.1
2324import Utils 0.1 as Utils
2425import Ubuntu.Components.ListItems 0.1 as ListItems
2526import Ubuntu.Components 0.1
@@ -27,6 +28,7 @@ import Ubuntu.Components 0.1
2728Item {
2829 id: menuFactory
2930
31+ property var rootModel: null
3032 property var menuModel: null
3133
3234 property var _map: {
@@ -41,6 +43,7 @@ Item {
4143 "com.canonical.indicator.switch" : switchMenu,
4244 "com.canonical.indicator.alarm" : alarmMenu,
4345 "com.canonical.indicator.appointment" : appointmentMenu,
46+ "com.canonical.indicator.transfer" : transferMenu,
4447
4548 "com.canonical.indicator.messages.messageitem" : messageItem,
4649 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
@@ -330,7 +333,7 @@ Item {
330333 property int menuIndex: -1
331334 property var extendedData: menuData && menuData.ext || undefined
332335
333− property var strengthAction: QMenuModel.UnityMenuAction {
336+ property var strengthAction: UnityMenuAction {
334337 model: menuModel
335338 index: menuIndex
336339 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
@@ -442,17 +445,17 @@ Item {
442445 property int menuIndex: -1
443446 property var extendedData: menuData && menuData.ext || undefined
444447
445− property var playAction: QMenuModel.UnityMenuAction {
448+ property var playAction: UnityMenuAction {
446449 model: menuModel
447450 index: menuIndex
448451 name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
449452 }
450− property var nextAction: QMenuModel.UnityMenuAction {
453+ property var nextAction: UnityMenuAction {
451454 model: menuModel
452455 index: menuIndex
453456 name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
454457 }
455− property var previousAction: QMenuModel.UnityMenuAction {
458+ property var previousAction: UnityMenuAction {
456459 model: menuModel
457460 index: menuIndex
458461 name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
@@ -489,6 +492,121 @@ Item {
489492 }
490493 }
491494
495+ Component {
496+ id: transferMenu
497+ Menus.TransferMenu {
498+ objectName: "transferMenu"
499+ id: transfer
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)
505+
506+ text: menuData && menuData.label || ""
507+ iconSource: menuData && menuData.icon || "image://theme/save"
508+ maximum: 1.0
509+ enabled: menuData && menuData.sensitive || false
510+ removable: true
511+ confirmRemoval: true
512+
513+ QDBusActionGroup {
514+ id: actionGroup
515+ busType: 1
516+ busName: rootModel.busName
517+ objectPath: rootModel.actions["indicator"]
518+
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")
524+
525+ Component.onCompleted: actionGroup.start()
526+ }
527+
528+ property var transferStateProperties: uid !== undefined && actionGroup.transferStates.valid && actionGroup.transferStates.state[uid] || undefined
529+
530+ property var transferState : transferStateProperties !== undefined && transferStateProperties["state"] || undefined
531+ property var secondsLeft : transferStateProperties !== undefined && transferStateProperties["seconds-left"]
532+
533+ active: transferStateProperties !== undefined && transferState !== Menus.TransferState.FINISHED
534+ progress : transferStateProperties !== undefined && transferStateProperties["percent"] || 0.0
535+
536+ property var timeRemaining: {
537+ if (secondsLeft === undefined) return undefined;
538+
539+ var remaining = "";
540+ var hours = Math.floor(secondsLeft / (60 * 60));
541+ var minutes = Math.floor(secondsLeft / 60) % 60;
542+ var seconds = secondsLeft % 60;
543+ if (hours > 0) {
544+ remaining += hours + (hours == 1 ? " hour" : " hours");
545+ }
546+ if (minutes > 0) {
547+ if (remaining != "") remaining += ", ";
548+ remaining += minutes + (minutes == 1 ? " minute" : " minutes");
549+ }
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");
554+ }
555+ if (remaining == "")
556+ remaining = "0 seconds";
557+ return remaining + " remaining";
558+ }
559+
560+ stateText: {
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");
576+ }
577+ return "";
578+ }
579+
580+ onMenuModelChanged: {
581+ loadAttributes();
582+ }
583+ onMenuIndexChanged: {
584+ loadAttributes();
585+ }
586+ onTriggered: {
587+ actionGroup.activateAction.activate(uid);
588+ shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
589+ }
590+
591+ function loadAttributes() {
592+ if (!menuModel || menuIndex == -1) return;
593+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-uid': 'string'});
594+ }
595+
596+ function cancel() {
597+ actionGroup.cancelAction.activate(uid);
598+ }
599+
600+ function pause() {
601+ actionGroup.pauseAction.activate(uid);
602+ }
603+
604+ function resume() {
605+ actionGroup.resumeAction.activate(uid);
606+ }
607+ }
608+ }
609+
492610 function load(modelData) {
493611 if (modelData.type !== undefined) {
494612 var component = _map[modelData.type];