]> git.0d.be Git - empathy.git/blobdiff - src/empathy-new-chatroom-dialog.c
Merge branch 'debug-window'
[empathy.git] / src / empathy-new-chatroom-dialog.c
index 1861993e8ca1688965e74ba7d4d332eee62010d9..219be371dad0e9028e8d2b5eebcf34f0b2b56d32 100644 (file)
@@ -15,9 +15,9 @@
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- * 
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
  * Authors: Martyn Russell <martyn@imendio.com>
  *          Xavier Claessens <xclaesse@gmail.com>
  */
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <glib/gi18n.h>
-
-#include <libmissioncontrol/mission-control.h>
-#include <libmissioncontrol/mc-account.h>
-#include <libmissioncontrol/mc-profile.h>
+#include <glib/gprintf.h>
 
 #include <libempathy/empathy-tp-roomlist.h>
 #include <libempathy/empathy-chatroom.h>
@@ -66,7 +63,8 @@ typedef struct {
        GtkWidget         *treeview;
        GtkTreeModel      *model;
        GtkWidget         *button_join;
-       GtkWidget         *button_close;
+       GtkWidget         *label_error_message;
+       GtkWidget         *viewport_error;
 } EmpathyNewChatroomDialog;
 
 enum {
@@ -98,6 +96,12 @@ static void     new_chatroom_dialog_new_room_cb                     (EmpathyTpRo
 static void     new_chatroom_dialog_listing_cb                      (EmpathyTpRoomlist        *room_list,
                                                                     gpointer                  unused,
                                                                     EmpathyNewChatroomDialog *dialog);
+static void     start_listing_error_cb                              (EmpathyTpRoomlist        *room_list,
+                                                                    GError                   *error,
+                                                                    EmpathyNewChatroomDialog *dialog);
+static void     stop_listing_error_cb                               (EmpathyTpRoomlist        *room_list,
+                                                                    GError                   *error,
+                                                                    EmpathyNewChatroomDialog *dialog);
 static void     new_chatroom_dialog_model_clear                     (EmpathyNewChatroomDialog *dialog);
 static void     new_chatroom_dialog_model_row_activated_cb          (GtkTreeView             *tree_view,
                                                                     GtkTreePath             *path,
@@ -117,6 +121,8 @@ static void     new_chatroom_dialog_expander_browse_activate_cb     (GtkWidget
 static gboolean new_chatroom_dialog_entry_server_focus_out_cb       (GtkWidget               *widget,
                                                                     GdkEventFocus           *event,
                                                                     EmpathyNewChatroomDialog *dialog);
+static void    new_chatroom_dialog_button_close_error_clicked_cb   (GtkButton                *button,
+                                                                    EmpathyNewChatroomDialog *dialog);
 
 static EmpathyNewChatroomDialog *dialog_p = NULL;
 
@@ -147,6 +153,8 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
                                       "treeview", &dialog->treeview,
                                       "button_join", &dialog->button_join,
                                       "expander_browse", &dialog->expander_browse,
+                                      "label_error_message", &dialog->label_error_message,
+                                      "viewport_error", &dialog->viewport_error,
                                       NULL);
        g_free (filename);
 
@@ -158,6 +166,7 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
                              "entry_server", "focus-out-event", new_chatroom_dialog_entry_server_focus_out_cb,
                              "entry_room", "changed", new_chatroom_dialog_entry_changed_cb,
                              "expander_browse", "activate", new_chatroom_dialog_expander_browse_activate_cb,
+                             "button_close_error", "clicked", new_chatroom_dialog_button_close_error_clicked_cb,
                              NULL);
 
        g_object_unref (gui);
@@ -228,7 +237,7 @@ new_chatroom_dialog_destroy_cb (GtkWidget               *widget,
        if (dialog->room_list) {
                g_object_unref (dialog->room_list);
        }
-       g_object_unref (dialog->model);  
+       g_object_unref (dialog->model);
 
        g_free (dialog);
 }
@@ -345,15 +354,17 @@ static void
 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       McAccount             *account;
-       McProfile             *profile;
+       EmpathyAccount        *account;
        const gchar           *protocol;
        const gchar           *room;
-       
+
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
        account = empathy_account_chooser_dup_account (account_chooser);
-       profile = mc_account_get_profile (account);
-       protocol = mc_profile_get_protocol_name (profile);
+
+       if (account == NULL)
+               return;
+
+       protocol = empathy_account_get_protocol (account);
 
        gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
 
@@ -378,7 +389,6 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
        gtk_widget_grab_focus (dialog->entry_room);
 
        g_object_unref (account);
-       g_object_unref (profile);
 }
 
 static void
@@ -386,11 +396,13 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                                        EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       McAccount             *account;
+       EmpathyAccount        *account;
        gboolean               listing = FALSE;
+       gboolean               expanded = FALSE;
 
        if (dialog->room_list) {
                g_object_unref (dialog->room_list);
+               dialog->room_list = NULL;
        }
 
        ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
@@ -398,6 +410,9 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
 
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
        account = empathy_account_chooser_dup_account (account_chooser);
+       if (account == NULL)
+               goto out;
+
        dialog->room_list = empathy_tp_roomlist_new (account);
 
        if (dialog->room_list) {
@@ -410,6 +425,19 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                g_signal_connect (dialog->room_list, "notify::is-listing",
                                  G_CALLBACK (new_chatroom_dialog_listing_cb),
                                  dialog);
+               g_signal_connect (dialog->room_list, "error::start",
+                                 G_CALLBACK (start_listing_error_cb),
+                                 dialog);
+               g_signal_connect (dialog->room_list, "error::stop",
+                                 G_CALLBACK (stop_listing_error_cb),
+                                 dialog);
+
+               expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
+               if (expanded) {
+                       gtk_widget_hide (dialog->viewport_error);
+                       gtk_widget_set_sensitive (dialog->treeview, TRUE);
+                       new_chatroom_dialog_browse_start (dialog);
+               }
 
                listing = empathy_tp_roomlist_is_listing (dialog->room_list);
                if (listing) {
@@ -417,9 +445,17 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                }
        }
 
+       g_object_unref (account);
+
+out:
        new_chatroom_dialog_update_widgets (dialog);
+}
 
-       g_object_unref (account);
+static void
+new_chatroom_dialog_button_close_error_clicked_cb   (GtkButton                *button,
+                                                    EmpathyNewChatroomDialog *dialog)
+{
+       gtk_widget_hide (dialog->viewport_error);
 }
 
 static void
@@ -480,6 +516,26 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
        g_free (tooltip);
 }
 
+static void
+start_listing_error_cb (EmpathyTpRoomlist        *room_list,
+                       GError                   *error,
+                       EmpathyNewChatroomDialog *dialog)
+{
+       gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not start room listing"));
+       gtk_widget_show_all (dialog->viewport_error);
+       gtk_widget_set_sensitive (dialog->treeview, FALSE);
+}
+
+static void
+stop_listing_error_cb (EmpathyTpRoomlist        *room_list,
+                      GError                   *error,
+                      EmpathyNewChatroomDialog *dialog)
+{
+       gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not stop room listing"));
+       gtk_widget_show_all (dialog->viewport_error);
+       gtk_widget_set_sensitive (dialog->treeview, FALSE);
+}
+
 static void
 new_chatroom_dialog_listing_cb (EmpathyTpRoomlist        *room_list,
                                gpointer                  unused,
@@ -491,7 +547,7 @@ new_chatroom_dialog_listing_cb (EmpathyTpRoomlist        *room_list,
 
        /* Update the throbber */
        if (listing) {
-               ephy_spinner_start (EPHY_SPINNER (dialog->throbber));           
+               ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
        } else {
                ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
        }
@@ -518,7 +574,7 @@ new_chatroom_dialog_model_row_activated_cb (GtkTreeView             *tree_view,
 static void
 new_chatroom_dialog_model_selection_changed (GtkTreeSelection         *selection,
                                             EmpathyNewChatroomDialog *dialog)
-{      
+{
        GtkTreeModel *model;
        GtkTreeIter   iter;
        gchar        *room = NULL;
@@ -616,6 +672,8 @@ new_chatroom_dialog_expander_browse_activate_cb (GtkWidget               *widget
                new_chatroom_dialog_browse_stop (dialog);
                gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
        } else {
+               gtk_widget_hide (dialog->viewport_error);
+               gtk_widget_set_sensitive (dialog->treeview, TRUE);
                new_chatroom_dialog_browse_start (dialog);
                gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
        }