]> git.0d.be Git - empathy.git/blobdiff - src/empathy-new-chatroom-dialog.c
Updated Polish translation
[empathy.git] / src / empathy-new-chatroom-dialog.c
index 4b2e62b88187e6d96ed0621b677cc188dfd9e3ef..a2f3b4be943c382492f4aae4589ec42db4304648 100644 (file)
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 
-#include <libmissioncontrol/mission-control.h>
-#include <libmissioncontrol/mc-account.h>
-#include <libmissioncontrol/mc-profile.h>
-
 #include <libempathy/empathy-tp-roomlist.h>
 #include <libempathy/empathy-chatroom.h>
 #include <libempathy/empathy-utils.h>
 
 typedef struct {
        EmpathyTpRoomlist *room_list;
+       /* Currently selected account */
+       TpAccount         *account;
+       /* Signal id of the "status-changed" signal connected on the currently
+        * selected account */
+       gulong             status_changed_id;
 
        GtkWidget         *window;
        GtkWidget         *vbox_widgets;
@@ -67,7 +68,8 @@ typedef struct {
        GtkWidget         *treeview;
        GtkTreeModel      *model;
        GtkWidget         *button_join;
-       GtkWidget         *button_close;
+       GtkWidget         *label_error_message;
+       GtkWidget         *viewport_error;
 } EmpathyNewChatroomDialog;
 
 enum {
@@ -124,6 +126,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;
 
@@ -154,6 +158,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);
 
@@ -165,6 +171,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);
@@ -237,6 +244,11 @@ new_chatroom_dialog_destroy_cb (GtkWidget               *widget,
        }
        g_object_unref (dialog->model);
 
+       if (dialog->account != NULL) {
+               g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
+               g_object_unref (dialog->account);
+       }
+
        g_free (dialog);
 }
 
@@ -348,19 +360,42 @@ new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *dialog)
        gtk_tree_view_append_column (view, column);
 }
 
+static void
+update_join_button_sensitivity (EmpathyNewChatroomDialog *dialog)
+{
+       const gchar           *room;
+       gboolean               sensitive = FALSE;
+
+
+       room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
+       if (EMP_STR_EMPTY (room))
+               goto out;
+
+       if (dialog->account == NULL)
+               goto out;
+
+       if (tp_account_get_connection_status (dialog->account, NULL) !=
+                     TP_CONNECTION_STATUS_CONNECTED)
+               goto out;
+
+       sensitive = TRUE;
+
+out:
+       gtk_widget_set_sensitive (dialog->button_join, sensitive);
+}
+
 static void
 new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       McAccount             *account;
-       McProfile             *profile;
        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 (dialog->account == NULL)
+               return;
+
+       protocol = tp_account_get_protocol (dialog->account);
 
        gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
 
@@ -378,14 +413,22 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
                gtk_widget_set_sensitive (dialog->entry_server, TRUE);
        }
 
-       room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
-       gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
+       update_join_button_sensitivity (dialog);
 
        /* Final set up of the dialog */
        gtk_widget_grab_focus (dialog->entry_room);
+}
 
-       g_object_unref (account);
-       g_object_unref (profile);
+static void
+account_status_changed_cb (TpAccount *account,
+                           guint old_status,
+                           guint new_status,
+                           guint reason,
+                           gchar *dbus_error_name,
+                           GHashTable *details,
+                           EmpathyNewChatroomDialog *self)
+{
+       update_join_button_sensitivity (self);
 }
 
 static void
@@ -393,20 +436,31 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                                        EmpathyNewChatroomDialog *dialog)
 {
        EmpathyAccountChooser *account_chooser;
-       McAccount             *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));
        new_chatroom_dialog_model_clear (dialog);
 
+       if (dialog->account != NULL) {
+               g_signal_handler_disconnect (dialog->account, dialog->status_changed_id);
+               g_object_unref (dialog->account);
+       }
+
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
-       account = empathy_account_chooser_dup_account (account_chooser);
-       dialog->room_list = empathy_tp_roomlist_new (account);
+       dialog->account = empathy_account_chooser_dup_account (account_chooser);
+       if (dialog->account == NULL)
+               goto out;
+
+       dialog->status_changed_id = g_signal_connect (dialog->account,
+                     "status-changed", G_CALLBACK (account_status_changed_cb), dialog);
+
+       dialog->room_list = empathy_tp_roomlist_new (dialog->account);
 
        if (dialog->room_list) {
                g_signal_connect (dialog->room_list, "destroy",
@@ -427,6 +481,8 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
 
                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);
                }
 
@@ -436,9 +492,15 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
                }
        }
 
+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
@@ -472,9 +534,9 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
        selection = gtk_tree_view_get_selection (view);
        store = GTK_LIST_STORE (dialog->model);
        members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
-       tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
-               "are a channel name, yes/no, yes/no and a number.",
-               "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
+       /* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
+       yes/no, yes/no and a number. */
+       tooltip = g_strdup_printf (_("<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
                empathy_chatroom_get_name (chatroom),
                empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
                empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
@@ -504,7 +566,9 @@ start_listing_error_cb (EmpathyTpRoomlist        *room_list,
                        GError                   *error,
                        EmpathyNewChatroomDialog *dialog)
 {
-       g_printf("Error when starting listing of chatrooms.");
+       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
@@ -512,7 +576,9 @@ stop_listing_error_cb (EmpathyTpRoomlist        *room_list,
                       GError                   *error,
                       EmpathyNewChatroomDialog *dialog)
 {
-       g_printf("Error when stopping listing of chatrooms.");
+       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
@@ -526,7 +592,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));
        }
@@ -553,7 +619,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;
@@ -608,10 +674,8 @@ new_chatroom_dialog_entry_changed_cb (GtkWidget                *entry,
                                      EmpathyNewChatroomDialog *dialog)
 {
        if (entry == dialog->entry_room) {
-               const gchar *room;
+               update_join_button_sensitivity (dialog);
 
-               room = gtk_entry_get_text (GTK_ENTRY (dialog->entry_room));
-               gtk_widget_set_sensitive (dialog->button_join, !EMP_STR_EMPTY (room));
                /* FIXME: Select the room in the list */
        }
 }
@@ -651,6 +715,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);
        }