← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nik90/ubuntu-clock-app/custom-alarm-sound into lp:ubuntu-clock-app

 

Nekhelesh Ramananthan has proposed merging lp:~nik90/ubuntu-clock-app/custom-alarm-sound into lp:ubuntu-clock-app with lp:~nik90/ubuntu-clock-app/add-utility-backend as a prerequisite.

Commit message:
Add support for setting custom alarm sounds

Requested reviews:
  Ubuntu Clock Developers (ubuntu-clock-dev)
Related bugs:
  Bug #1450640 in Ubuntu Clock App: "[clock][UX] Allow users to set custom alarm sound"
  https://bugs.launchpad.net/ubuntu-clock-app/+bug/1450640

For more details, see:
https://code.launchpad.net/~nik90/ubuntu-clock-app/custom-alarm-sound/+merge/268499

Added support for setting custom alarm sounds :-) This first requires the prerequisite branch to land in trunk.

Steps to test
-------------
bzr branch lp:~ahayzen/music-app/fix-1357324-content-hub-source
cd fix-1357324-content-hub-source
click-buddy
Install music-app click package in the phone
Install this MP's clock app on the phone
Reboot phone for good measure
Test feature


Things still to do
------------------
- Rebuild .pot file
- Refactor and clean code
- Manual testing (Cannot be tested on desktop)
- Merge prerequisite branch to trunk
-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~nik90/ubuntu-clock-app/custom-alarm-sound into lp:ubuntu-clock-app.
=== modified file 'app/alarm/AlarmSound.qml'
--- app/alarm/AlarmSound.qml	2015-08-13 13:29:49 +0000
+++ app/alarm/AlarmSound.qml	2015-08-19 15:24:56 +0000
@@ -17,7 +17,9 @@
  */
 
 import QtQuick 2.4
+import Clock.Utility 1.0
 import QtMultimedia 5.0
+import Ubuntu.Content 1.1
 import Ubuntu.Components 1.2
 
 Page {
@@ -37,6 +39,8 @@
     // Property to set the alarm sound model in the edit alarm page
     property var soundModel
 
+    property var customSoundModel
+
     /*
      Properties to store the previously set alarm sound values to detect
      if the user changed the alarm sound or not
@@ -44,6 +48,10 @@
     property url oldAlarmSoundUrl
     property string oldAlarmSoundName
 
+    property list<ContentItem> importItems
+    property var activeTransfer
+    property list<ContentPeer> peers
+
     Component.onCompleted: {
         // Record the current alarm sound values (url, name)
         oldAlarmSoundUrl = alarm.sound
@@ -70,22 +78,149 @@
         }
     }
 
+    ContentTransferHint {
+        anchors.fill: parent
+        activeTransfer: _alarmSoundPage.activeTransfer
+    }
+
+    Connections {
+        target: _alarmSoundPage.activeTransfer
+        onStateChanged: {
+            if (_alarmSoundPage.activeTransfer.state === ContentTransfer.Charged) {
+                _alarmSoundPage.importItems = _alarmSoundPage.activeTransfer.items
+                console.log("[LOG] Original URL: " + _alarmSoundPage.importItems[0].url)
+                _alarmSoundPage.importItems[0].move("/home/phablet/.local/share/com.ubuntu.clock")
+                console.log("[LOG] Final URL: " + _alarmSoundPage.importItems[0].url)
+            }
+        }
+    }
+
     Audio {
         id: previewAlarmSound
         audioRole: MediaPlayer.alert
     }
 
+    FileManagement {
+        id: fileManagement
+    }
+
+    StandardPath {
+        id: standardPath
+    }
+
     Flickable {
         id: _pageFlickable
 
         anchors.fill: parent
-        contentHeight: soundModel.count * units.gu(7)
+        contentHeight: soundModel.count * units.gu(7) + customSoundModel.count * units.gu(7) + customSoundListItem.height
 
         Column {
             id: _alarmSoundColumn
 
             anchors.fill: parent
 
+            ListItem {
+                id: customSoundListItem
+                height: units.gu(7)
+                Button {
+                    id: customSoundButton
+                    text: i18n.tr("Custom Sound")
+                    width: parent.width/1.1
+                    anchors.centerIn: parent
+                    onClicked: {
+                        pageStack.push(Qt.resolvedUrl("MusicAppPicker.qml"), {alarmSoundPage: _alarmSoundPage})
+                    }
+                }
+            }
+
+            Repeater {
+                id: _customAlarmSounds
+                objectName: "customAlarmSounds"
+
+                model: customSoundModel
+
+                ListItem {
+                    id: _customAlarmSoundDelegate
+
+                    property alias isChecked: _customSoundStatus.checked
+
+                    height: units.gu(7)
+
+                    leadingActions: ListItemActions {
+                        actions: [
+                            Action {
+                                iconName: "delete"
+                                onTriggered: {
+                                    fileManagement.deleteFile(standardPath.appDirectory, fileName)
+                                }
+                            }
+                        ]
+                    }
+
+                    Label {
+                        id: _customSoundName
+                        objectName: "customSoundName" + index
+
+                        anchors {
+                            left: parent.left
+                            leftMargin: units.gu(2)
+                            verticalCenter: parent.verticalCenter
+                        }
+
+                        color: UbuntuColors.midAubergine
+                        fontSize: "medium"
+                        text: fileBaseName
+                    }
+
+                    CheckBox {
+                        id: _customSoundStatus
+                        objectName: "customSoundStatus" + index
+
+                        anchors {
+                            right: parent.right
+                            rightMargin: units.gu(2)
+                            verticalCenter: parent.verticalCenter
+                        }
+
+                        checked: alarmSound.subText === _customSoundName.text ? true
+                                                                              : false
+                        onCheckedChanged: {
+                            if (checked) {
+                                previewAlarmSound.source = fileURL
+                                previewAlarmSound.play()
+                                alarmSound.subText = _customSoundName.text
+                                alarm.sound = fileURL
+
+                                // Ensures only one alarm sound is selected
+                                for(var i=0; i<customSoundModel.count; i++) {
+                                    if(_customAlarmSounds.itemAt(i).isChecked &&
+                                            i !== index) {
+                                        _customAlarmSounds.itemAt(i).isChecked = false
+                                    }
+                                }
+
+                                // Ensures only one alarm sound is selected
+                                for(i=0; i<soundModel.count; i++) {
+                                    _alarmSounds.itemAt(i).isChecked = false
+                                }
+                            }
+                        }
+
+                        onClicked: {
+                            if (!checked) {
+                                checked = true
+                            }
+                        }
+                    }
+
+                    onClicked: {
+                        if (!_customSoundStatus.checked) {
+                            _customSoundStatus.checked = true
+                        }
+                    }
+                }
+            }
+
             Repeater {
                 id: _alarmSounds
                 objectName: "alarmSounds"
@@ -140,6 +275,11 @@
                                         _alarmSounds.itemAt(i).isChecked = false
                                     }
                                 }
+
+                                // Ensures only one alarm sound is selected
+                                for(i=0; i<customSoundModel.count; i++) {
+                                    _customAlarmSounds.itemAt(i).isChecked = false
+                                }
                             }
                         }
 

=== modified file 'app/alarm/CMakeLists.txt'
--- app/alarm/CMakeLists.txt	2015-08-11 15:05:34 +0000
+++ app/alarm/CMakeLists.txt	2015-08-19 15:24:56 +0000
@@ -9,6 +9,7 @@
     AlarmSound.qml
     AlarmUtils.qml
     EditAlarmPage.qml
+    MusicAppPicker.qml
 )
 
 # make the files visible in the qtcreator tree

=== modified file 'app/alarm/EditAlarmPage.qml'
--- app/alarm/EditAlarmPage.qml	2015-08-14 13:39:38 +0000
+++ app/alarm/EditAlarmPage.qml	2015-08-19 15:24:56 +0000
@@ -18,6 +18,7 @@
 
 import QtQuick 2.4
 import DateTime 1.0
+import Clock.Utility 1.0
 import Ubuntu.Components 1.2
 import Qt.labs.folderlistmodel 2.1
 import Ubuntu.Components.Pickers 1.0
@@ -130,6 +131,12 @@
                 return soundModel.get(i, "fileBaseName")
             }
         }
+
+        for(var j=0; j<customSoundModel.count; j++) {
+            if(chosenSoundPath === Qt.resolvedUrl(customSoundModel.get(j, "filePath"))) {
+                return customSoundModel.get(j, "fileBaseName")
+            }
+        }
     }
 
     function getSoundPath(chosenSoundName) {
@@ -138,6 +145,12 @@
                 return soundModel.get(i, "filePath")
             }
         }
+
+        for(var j=0; j<customSoundModel.count; j++) {
+            if(chosenSoundName === customSoundModel.get(i, "fileBaseName")) {
+                return customSoundModel.get(i, "filePath")
+            }
+        }
     }
 
     function validateDate(date) {
@@ -225,6 +238,41 @@
         }
     }
 
+    StandardPath {
+        id: standardPath
+    }
+
+    FolderListModel {
+        id: customSoundModel
+
+        showDirs: false
+        nameFilters: [ "*.ogg", "*.mp3" ]
+        folder: standardPath.appDirectory
+
+        onCountChanged: {
+            if(count > 0) {
+                /*
+                  When folder model is completely loaded, proceed to perform
+                  the following operations,
+
+                  if new alarm, then set the sound name as "Alarm clock" and
+                  retrieve the sound path from the folder model to assign to
+                  the alarm model sound property.
+
+                  If it is a saved alarm, get the sound path from the alarm
+                  object and retrieve the sound name from the folder model.
+                */
+                if(isNewAlarm) {
+                    _alarm.sound = getSoundPath(_alarmSound._soundName)
+                    _alarmSound.subText = _alarmSound._soundName
+                }
+                else {
+                    _alarmSound.subText = getSoundName(_alarm.sound.toString())
+                }
+            }
+        }
+    }
+
     AlarmUtils {
         id: alarmUtils
     }
@@ -304,7 +352,8 @@
             onClicked: pageStack.push(Qt.resolvedUrl("AlarmSound.qml"), {
                                           "alarmSound": _alarmSound,
                                           "alarm": _alarm,
-                                          "soundModel": soundModel
+                                          "soundModel": soundModel,
+                                          "customSoundModel": customSoundModel
                                       })
         }
     }

=== added file 'app/alarm/MusicAppPicker.qml'
--- app/alarm/MusicAppPicker.qml	1970-01-01 00:00:00 +0000
+++ app/alarm/MusicAppPicker.qml	2015-08-19 15:24:56 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 Canonical Ltd
+ *
+ * This file is part of Ubuntu Clock App
+ *
+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Ubuntu Clock App is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 2.4
+import Ubuntu.Components 1.2
+import Ubuntu.Content 1.1
+
+Page {
+    id: picker
+
+    // #TRANSLATORS: This is the page title. Please keep the translation length to 3 words if possible
+    title: i18n.tr("Choose sound from")
+
+    property var alarmSoundPage
+
+    ContentPeerPicker {
+        id: peerPicker
+        handler: ContentHandler.Source
+        contentType: ContentType.Music
+        showTitle: false
+
+        onPeerSelected: {
+            peer.selectionType = ContentTransfer.Single
+            alarmSoundPage.activeTransfer = peer.request()
+            pageStack.pop()
+        }
+    }
+}

=== modified file 'debian/changelog'
--- debian/changelog	2015-08-19 15:24:56 +0000
+++ debian/changelog	2015-08-19 15:24:56 +0000
@@ -15,6 +15,7 @@
   * Fix alarm interval information being inconsistent (LP: #1466000)
   * Changed default alarm sound (LP: #1354370)
   * Added Clock Utility C++ plugin housing filemanagement and standardpath.
+  * Added support for setting custom alarm sounds (LP: #1450640)
 
   [Victor Thompson]
   * Show all README files in QtCreator 

=== modified file 'ubuntu-clock-app.json'
--- ubuntu-clock-app.json	2015-05-27 16:03:23 +0000
+++ ubuntu-clock-app.json	2015-08-19 15:24:56 +0000
@@ -3,7 +3,8 @@
         "audio",
         "calendar",
         "networking",
-        "location"
+        "location",
+        "content_exchange"
     ],
     "policy_version": 1.3
-}
\ No newline at end of file
+}


Follow ups