]> git.0d.be Git - empathy.git/commitdiff
Display a spinner while loading contacts from Folks
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 6 Feb 2012 13:16:55 +0000 (14:16 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 14 Feb 2012 09:34:45 +0000 (10:34 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=656097

src/empathy-roster-window.c
src/empathy-roster-window.ui

index 8219f79abaa6d54ac23c8a3fa7d6768cda9d8682..454cd256a96015e3c47a21e016054838e09c0e51 100644 (file)
@@ -111,6 +111,7 @@ struct _EmpathyRosterWindowPriv {
   EmpathyEventManager *event_manager;
   EmpathySoundManager *sound_mgr;
   EmpathyCallObserver *call_observer;
+  EmpathyIndividualManager *individual_manager;
   guint flash_timeout_id;
   gboolean flash_on;
   gboolean empty;
@@ -130,6 +131,7 @@ struct _EmpathyRosterWindowPriv {
   GtkWidget *notebook;
   GtkWidget *no_entry_label;
   GtkWidget *button_account_settings;
+  GtkWidget *spinner_loading;
 
   GtkToggleAction *show_protocols;
   GtkRadioAction *sort_by_name;
@@ -619,19 +621,30 @@ button_account_settings_clicked_cb (GtkButton *button,
 static void
 display_page_message (EmpathyRosterWindow *self,
     const gchar *msg,
-    gboolean display_accounts_button)
+    gboolean display_accounts_button,
+    gboolean display_spinner)
 {
-  gchar *tmp;
+  if (msg != NULL)
+    {
+      gchar *tmp;
 
-  tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>", msg);
+      tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>", msg);
 
-  gtk_label_set_markup (GTK_LABEL (self->priv->no_entry_label), tmp);
-  g_free (tmp);
+      gtk_label_set_markup (GTK_LABEL (self->priv->no_entry_label), tmp);
+      g_free (tmp);
 
-  gtk_label_set_line_wrap (GTK_LABEL (self->priv->no_entry_label), TRUE);
+      gtk_label_set_line_wrap (GTK_LABEL (self->priv->no_entry_label), TRUE);
+      gtk_widget_show (self->priv->no_entry_label);
+    }
+  else
+    {
+      gtk_widget_hide (self->priv->no_entry_label);
+    }
 
   gtk_widget_set_visible (self->priv->button_account_settings,
       display_accounts_button);
+  gtk_widget_set_visible (self->priv->spinner_loading,
+      display_spinner);
 
   gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook),
       PAGE_MESSAGE);
@@ -641,7 +654,7 @@ static void
 display_page_no_account (EmpathyRosterWindow *self)
 {
   display_page_message (self,
-      _("You need to setup an account to see contacts here."), TRUE);
+      _("You need to setup an account to see contacts here."), TRUE, FALSE);
 }
 
 static void
@@ -657,7 +670,7 @@ roster_window_row_deleted_cb (GtkTreeModel *model,
 
       if (empathy_individual_view_is_searching (self->priv->individual_view))
         {
-          display_page_message (self, _("No match found"), FALSE);
+          display_page_message (self, _("No match found"), FALSE, FALSE);
         }
     }
 }
@@ -665,6 +678,11 @@ roster_window_row_deleted_cb (GtkTreeModel *model,
 static void
 display_page_contact_list (EmpathyRosterWindow *self)
 {
+  if (!empathy_individual_manager_get_contacts_loaded (
+        self->priv->individual_manager))
+    /* We'll display the contact list once we're done loading */
+    return;
+
   gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook),
       PAGE_CONTACT_LIST);
 }
@@ -1408,6 +1426,7 @@ empathy_roster_window_finalize (GObject *window)
 
   g_object_unref (self->priv->gsettings_ui);
   g_object_unref (self->priv->gsettings_contacts);
+  g_object_unref (self->priv->individual_manager);
 
   G_OBJECT_CLASS (empathy_roster_window_parent_class)->finalize (window);
 }
@@ -2129,7 +2148,7 @@ display_page_account_not_enabled (EmpathyRosterWindow *self,
     {
       display_page_message (self,
           _("You need to enable one of your accounts to see contacts here."),
-          TRUE);
+          TRUE, FALSE);
     }
   else
     {
@@ -2139,7 +2158,7 @@ display_page_account_not_enabled (EmpathyRosterWindow *self,
       tmp = g_strdup_printf (_("You need to enable %s to see contacts here."),
           tp_account_get_display_name (account));
 
-      display_page_message (self, tmp, TRUE);
+      display_page_message (self, tmp, TRUE, FALSE);
       g_free (tmp);
     }
 }
@@ -2393,10 +2412,32 @@ empathy_roster_window_class_init (EmpathyRosterWindowClass *klass)
   g_type_class_add_private (object_class, sizeof (EmpathyRosterWindowPriv));
 }
 
+static void
+show_contacts_loading (EmpathyRosterWindow *self)
+{
+  display_page_message (self, NULL, FALSE, TRUE);
+
+  gtk_spinner_start (GTK_SPINNER (self->priv->spinner_loading));
+}
+
+static void
+hide_contacts_loading (EmpathyRosterWindow *self)
+{
+  gtk_spinner_stop (GTK_SPINNER (self->priv->spinner_loading));
+
+  display_page_contact_list (self);
+}
+
+static void
+contacts_loaded_cb (EmpathyIndividualManager *manager,
+    EmpathyRosterWindow *self)
+{
+  hide_contacts_loading (self);
+}
+
 static void
 empathy_roster_window_init (EmpathyRosterWindow *self)
 {
-  EmpathyIndividualManager *individual_manager;
   GtkBuilder *gui, *gui_mgr;
   GtkWidget *sw;
   GtkToggleAction *show_offline_widget;
@@ -2437,6 +2478,7 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
       "no_entry_label", &self->priv->no_entry_label,
       "roster_scrolledwindow", &sw,
       "button_account_settings", &self->priv->button_account_settings,
+      "spinner_loading", &self->priv->spinner_loading,
       NULL);
   g_free (filename);
 
@@ -2565,10 +2607,19 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
    * so it's got a race condition between its signal handlers and its
    * finalization. The class is planned to be removed, so we won't fix
    * this before then. */
-  individual_manager = empathy_individual_manager_dup_singleton ();
+  self->priv->individual_manager = empathy_individual_manager_dup_singleton ();
+
+  if (!empathy_individual_manager_get_contacts_loaded (
+        self->priv->individual_manager))
+    {
+      show_contacts_loading (self);
+
+      tp_g_signal_connect_object (self->priv->individual_manager,
+          "contacts-loaded", G_CALLBACK (contacts_loaded_cb), self, 0);
+    }
+
   self->priv->individual_store = EMPATHY_INDIVIDUAL_STORE (
-      empathy_individual_store_manager_new (individual_manager));
-  g_object_unref (individual_manager);
+      empathy_individual_store_manager_new (self->priv->individual_manager));
 
   /* For the moment, we disallow Persona drops onto the roster contact list
    * (e.g. from things such as the EmpathyPersonaView in the linking dialogue).
index 87c3354a95026196de9253a2962b2e83df890631..8c8f6300116ea85074c13366fc631a8575fb62ec 100644 (file)
                 <property name="position">2</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="yalign">0</property>
+                <property name="xscale">0</property>
+                <property name="yscale">0</property>
+                <child>
+                  <object class="GtkSpinner" id="spinner_loading">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>