If quick-settings is displayed too early on startup,
phoneui_utils_sound_profile_list() fails, resulting in an error message
and an empty profile combo that stays empty until phoneuid is restarted.

This patch keeps the error message (not much we can do), but it retries
the profile list retrieval on each quick_settings_view_show() if it has
not succeeded yet. -> The error is recoverable.

As an added bonus, the current profile is queried and selected into the
list combo once the profile list is filled, so it should always reflect
the current profile. The combo box is disabled until the profile list is
filled.

Signed-off-by: David Kozub <[email protected]>
---
 src/view/quick-settings-view.c |   58 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/src/view/quick-settings-view.c b/src/view/quick-settings-view.c
index a8b6de5..ac0b27a 100644
--- a/src/view/quick-settings-view.c
+++ b/src/view/quick-settings-view.c
@@ -45,14 +45,18 @@ struct QuickSettingsViewData {
        Evas_Object *airplane_slide, *profiles_combo, *dimming_slide, 
*suspend_slide;
        Evas_Object *gprs_slide, *sharing_slide;
        Evas_Object *button_lock, *button_suspend, *button_shutdown;
+       Eina_Bool sound_profiles_pending;
+       Eina_Bool sound_profiles_loaded;
 };

 static struct QuickSettingsViewData view;

 static void _init_profiles_power_page();
+static void _load_sound_profiles();
 static void _init_network_page();
 static void _delete_cb(struct View *view, Evas_Object * win, void *event_info);
 static void _profiles_list_cb(GError *error, char **list, int count, gpointer 
userdata);
+static void _profile_get_current_cb(GError *error, char *profile, gpointer 
userdata);
 static void _profile_selected_cb(void *data, Evas_Object *obj, void 
*event_info);
 static void _get_offline_mode_cb(GError *error, gboolean offline, gpointer 
data);
 static void _button_lock_clicked_cb(void *data, Evas_Object *obj, void 
*event_info);
@@ -136,7 +140,9 @@ quick_settings_view_is_init()
 void
 quick_settings_view_show()
 {
-        ui_utils_view_show(VIEW_PTR(view));
+       if (!view.sound_profiles_loaded)
+               _load_sound_profiles();
+       ui_utils_view_show(VIEW_PTR(view));
 }

 void
@@ -207,7 +213,9 @@ _init_profiles_power_page()

        elm_pager_content_push(view.pager, view.layout1);

-       phoneui_utils_sound_profile_list(_profiles_list_cb, NULL);
+       /* Disabled until we get the list + current profile. */
+       elm_object_disabled_set(view.profiles_combo, EINA_TRUE);
+
        phoneui_utils_resources_get_resource_policy("CPU", _cpu_get_policy_cb, 
NULL);
        phoneui_utils_resources_get_resource_policy("Display", 
_display_get_policy_cb, NULL);
        phoneui_utils_get_offline_mode(_get_offline_mode_cb, NULL);
@@ -218,6 +226,18 @@ _init_profiles_power_page()
 }

 static void
+_load_sound_profiles()
+{
+       g_assert(!view.sound_profiles_loaded);
+       if (!view.sound_profiles_pending)
+       {
+               view.sound_profiles_pending = EINA_TRUE;
+               phoneui_utils_sound_profile_list(_profiles_list_cb, NULL);
+       }
+       /* else: Ignore the request, as another is already pending. */
+}
+
+static void
 _init_network_page()
 {
        Evas_Object *win = ui_utils_view_window_get(VIEW_PTR(view));
@@ -301,18 +321,48 @@ _profiles_list_cb(GError *error, char **list, int count, 
gpointer userdata)
        (void) userdata;
        int i;

+       g_assert(view.sound_profiles_pending);
+
        if (error || !list) {
                g_warning("Failed to retrieve profiles list: (%d) %s",
                        (error)? error->code : 0, (error)? error->message : 
"NULL");
                error_message_show_from_gerror(VIEW_PTR(view),
                        D_("Failed to retrieve profiles list."), error);
+               view.sound_profiles_pending = EINA_FALSE;
                return;
        }

+       view.sound_profiles_loaded = EINA_TRUE;
+
        for (i = 0; i < count; i++) {
                elm_hoversel_item_add(view.profiles_combo, list[i], NULL,
                        ELM_ICON_NONE, NULL, NULL);
        }
+
+       /* Determine the current profile. */
+       phoneui_utils_sound_profile_get(_profile_get_current_cb, NULL);
+}
+
+static void
+_profile_get_current_cb(GError *error, char *profile, gpointer userdata)
+{
+       (void)userdata;
+
+       g_assert(view.sound_profiles_pending);
+       g_assert(view.sound_profiles_loaded);
+       view.sound_profiles_pending = EINA_FALSE;
+
+       if (error || !profile) {
+               g_warning("Failed to retrieve the current profile: (%d) %s",
+                       (error)? error->code : 0, (error)? error->message : 
"NULL");
+               error_message_show_from_gerror(VIEW_PTR(view),
+                       D_("Failed to retrieve the current profile."), error);
+       }
+       else
+               elm_hoversel_label_set(view.profiles_combo, profile);
+
+       /* Whether we got the profile or not, enable it now. */
+       elm_object_disabled_set(view.profiles_combo, EINA_FALSE);
 }

 static void
@@ -320,7 +370,9 @@ _profile_changed_signal_cb(void *userdata, const char 
*profile)
 {
        /*FIXME: I should probably free this profile, but how?, CHECK DBUS*/
        (void) userdata;
-       elm_hoversel_label_set(view.profiles_combo, profile);
+       if (view.sound_profiles_loaded)
+               elm_hoversel_label_set(view.profiles_combo, profile);
+       /* else: don't bother, will be filled in by _profile_get_current_cb */
 }

 static void
--
1.6.4.4

_______________________________________________
Shr-devel mailing list
[email protected]
http://lists.shr-project.org/mailman/listinfo/shr-devel

Reply via email to