← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nik90/ubuntu-clock-app/fix-alarm-sound-race-issue into lp:ubuntu-clock-app

 

Nekhelesh Ramananthan has proposed merging lp:~nik90/ubuntu-clock-app/fix-alarm-sound-race-issue into lp:ubuntu-clock-app with lp:~nik90/ubuntu-clock-app/default-alarm-sound-backwards-compatibility as a prerequisite.

Commit message:
Fixes race issue in the edit alarm page caused due to the QML FolderListModel resulting in incorrect alarm sound names sometimes being shown.

Requested reviews:
  Ubuntu Clock Developers (ubuntu-clock-dev)

For more details, see:
https://code.launchpad.net/~nik90/ubuntu-clock-app/fix-alarm-sound-race-issue/+merge/268814

In trunk, there is a race issue involved due the 2 QML FolderListModels defaultSoundModel and customSoundModel. The reason it happens is because QML FolderListModel does not have a signal to indicate that it has finished loading. The onComplete() signal is useless here since after it has completed, the count variable still takes another few ms to update.

So some of the file checks we do for custom alarm sound like checking the existence of the file is done *before* the 2 FolderListModels have fully loaded thereby providing incorrect results sometimes.

I have introduced a Timer which introduces a delay of 250ms to ensure that the FolderListModels have fully loaded before performing the file checks. 

This seems to have solved the issue.
-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~nik90/ubuntu-clock-app/fix-alarm-sound-race-issue into lp:ubuntu-clock-app.
=== modified file 'app/alarm/EditAlarmPage.qml'
--- app/alarm/EditAlarmPage.qml	2015-08-21 21:28:40 +0000
+++ app/alarm/EditAlarmPage.qml	2015-08-21 21:58:01 +0000
@@ -252,33 +252,40 @@
     FolderListModel {
         id: defaultSoundModel
 
+        property bool isModelLoaded: false
+
         showDirs: false
         nameFilters: [ "*.ogg", "*.mp3" ]
         folder: "/usr/share/sounds/ubuntu/ringtones"
-
-        onCountChanged: {
-            if(count > 0) {
-                // When folder model is completely loaded set the alarm sound.
-                if(!pageStack.currentPage.isAlarmSoundPage) {
-                    setAlarmSound()
-                }
-            }
+        Component.onCompleted: {
+            isModelLoaded = true
         }
     }
 
     FolderListModel {
         id: customSoundModel
 
+        property bool isModelLoaded: false
+
         showDirs: false
         folder: customSound.alarmSoundDirectory
+        Component.onCompleted: {
+            isModelLoaded = true
+        }
+    }
 
-        onCountChanged: {
-            if(count > 0) {
-                // When folder model is completely loaded set the alarm sound.
-                if(!pageStack.currentPage.isAlarmSoundPage) {
-                    setAlarmSound()
-                }
-            }
+    /*
+     QML FolderListModel does not provide any signals to indicate that it is fully loaded other
+     than the onCompleted() signal which is not sufficient. This introduces a race-condition where
+     file checks are done *before* the folder models have fully loaded. This timer introduces a
+     delay to workaround that issue.
+    */
+    Timer {
+        id: delaySettingAlarmSoundTimer
+        interval: 250
+        running: defaultSoundModel.isModelLoaded && customSoundModel.isModelLoaded
+        onTriggered: {
+            setAlarmSound()
         }
     }
 


Follow ups