- Split info/edit/personal dialogs into different functions.
authorXavier Claessens <xclaesse@gmail.com>
Tue, 17 Feb 2009 13:23:52 +0000 (14:23 +0100)
committerXavier Claessens <xclaesse@gmail.com>
Wed, 22 Apr 2009 10:21:09 +0000 (12:21 +0200)
 - Make sure empathy_contact_widget_new works with a NULL contact.

libempathy-gtk/empathy-contact-dialogs.c
libempathy-gtk/empathy-contact-dialogs.h
libempathy-gtk/empathy-contact-menu.c
libempathy-gtk/empathy-contact-widget.c

index 309cd649c8e8708d3530b4e171f79e98b70ed96e..38e02409f3e475c2331892cb5a8d1c2e8dfae496 100644 (file)
 
 static GList *subscription_dialogs = NULL;
 static GList *information_dialogs = NULL;
+static GList *edit_dialogs = NULL;
+static GtkWidget *personal_dialog = NULL;
 static GtkWidget *new_contact_dialog = NULL;
 
-
 static gint
 contact_dialogs_find (GtkDialog      *dialog,
                      EmpathyContact *contact)
@@ -144,25 +145,22 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
  */
 
 static void
-contact_information_response_cb (GtkDialog *dialog,
-                                gint       response,
-                                GtkWidget *contact_widget)
+contact_dialogs_response_cb (GtkDialog *dialog,
+                            gint       response,
+                            GList    **dialogs)
 {
-       information_dialogs = g_list_remove (information_dialogs, dialog);
+       *dialogs = g_list_remove (*dialogs, dialog);
        gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 void
 empathy_contact_information_dialog_show (EmpathyContact *contact,
-                                        GtkWindow      *parent,
-                                        gboolean        edit,
-                                        gboolean        is_user)
+                                        GtkWindow      *parent)
 {
-       GtkWidget                *dialog;
-       GtkWidget                *button;
-       GtkWidget                *contact_widget;
-       GList                    *l;
-       EmpathyContactWidgetFlags flags = 0;
+       GtkWidget *dialog;
+       GtkWidget *button;
+       GtkWidget *contact_widget;
+       GList     *l;
 
        g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
@@ -178,15 +176,7 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
        dialog = gtk_dialog_new ();
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-       if (is_user) {
-               gtk_window_set_title (GTK_WINDOW (dialog), _("Personal Information"));
-       }
-       else if (edit) {
-               gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Contact Information"));
-       }
-       else {
-               gtk_window_set_title (GTK_WINDOW (dialog), _("Contact Information"));
-       }
+       gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Contact Information"));
 
        /* Close button */
        button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
@@ -199,34 +189,19 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
        gtk_widget_show (button);
 
        /* Contact info widget */
-       if (edit) {
-               flags |= EMPATHY_CONTACT_WIDGET_EDIT_ALIAS;
-       }
-       if (is_user) {
-               flags |= EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT;
-               flags |= EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
-       }
-       if (!is_user && edit) {
-               flags |= EMPATHY_CONTACT_WIDGET_EDIT_GROUPS;
-       }
-       contact_widget = empathy_contact_widget_new (contact, flags);
+       contact_widget = empathy_contact_widget_new (contact,
+               EMPATHY_CONTACT_WIDGET_EDIT_NONE);
        gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                            contact_widget,
                            TRUE, TRUE, 0);
-       if (flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
-               empathy_contact_widget_set_account_filter (contact_widget,
-                                                          empathy_account_chooser_filter_is_connected,
-                                                          NULL);
-       }
-       gtk_widget_show (contact_widget);
 
        g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
        information_dialogs = g_list_prepend (information_dialogs, dialog);
 
        g_signal_connect (dialog, "response",
-                         G_CALLBACK (contact_information_response_cb),
-                         contact_widget);
+                         G_CALLBACK (contact_dialogs_response_cb),
+                         &information_dialogs);
 
        if (parent) {
                gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
@@ -235,6 +210,115 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
        gtk_widget_show (dialog);
 }
 
+void
+empathy_contact_edit_dialog_show (EmpathyContact *contact,
+                                 GtkWindow      *parent)
+{
+       GtkWidget *dialog;
+       GtkWidget *button;
+       GtkWidget *contact_widget;
+       GList     *l;
+
+       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+       l = g_list_find_custom (edit_dialogs,
+                               contact,
+                               (GCompareFunc) contact_dialogs_find);
+       if (l) {
+               gtk_window_present (GTK_WINDOW (l->data));
+               return;
+       }
+
+       /* Create dialog */
+       dialog = gtk_dialog_new ();
+       gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+       gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+       gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Contact Information"));
+
+       /* Close button */
+       button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
+       gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
+       gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
+                                     button,
+                                     GTK_RESPONSE_CLOSE);
+       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+       gtk_window_set_default (GTK_WINDOW (dialog), button);
+       gtk_widget_show (button);
+
+       /* Contact info widget */
+       contact_widget = empathy_contact_widget_new (contact,
+               EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
+               EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
+       gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
+       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                           contact_widget,
+                           TRUE, TRUE, 0);
+       g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
+       edit_dialogs = g_list_prepend (edit_dialogs, dialog);
+
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (contact_dialogs_response_cb),
+                         &edit_dialogs);
+
+       if (parent) {
+               gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+       }
+
+       gtk_widget_show (dialog);
+}
+
+void
+empathy_contact_personal_dialog_show (GtkWindow *parent)
+{
+       GtkWidget *button;
+       GtkWidget *contact_widget;
+
+       if (personal_dialog) {
+               gtk_window_present (GTK_WINDOW (personal_dialog));
+               return;
+       }
+
+       /* Create dialog */
+       personal_dialog = gtk_dialog_new ();
+       gtk_dialog_set_has_separator (GTK_DIALOG (personal_dialog), FALSE);
+       gtk_window_set_resizable (GTK_WINDOW (personal_dialog), FALSE);
+       gtk_window_set_title (GTK_WINDOW (personal_dialog), _("Personal Information"));
+
+       /* Close button */
+       button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
+       gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
+       gtk_dialog_add_action_widget (GTK_DIALOG (personal_dialog),
+                                     button,
+                                     GTK_RESPONSE_CLOSE);
+       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+       gtk_window_set_default (GTK_WINDOW (personal_dialog), button);
+       gtk_widget_show (button);
+
+       /* Contact info widget */
+       contact_widget = empathy_contact_widget_new (NULL,
+               EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
+               EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
+               EMPATHY_CONTACT_WIDGET_EDIT_AVATAR);
+       gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8);
+       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (personal_dialog)->vbox),
+                           contact_widget,
+                           TRUE, TRUE, 0);
+       empathy_contact_widget_set_account_filter (contact_widget,
+                                                  empathy_account_chooser_filter_is_connected,
+                                                  NULL);
+
+       g_signal_connect (personal_dialog, "response",
+                         G_CALLBACK (gtk_widget_destroy), NULL);
+       g_object_add_weak_pointer (G_OBJECT (personal_dialog),
+                                  (gpointer) &personal_dialog);
+
+       if (parent) {
+               gtk_window_set_transient_for (GTK_WINDOW (personal_dialog), parent);
+       }
+
+       gtk_widget_show (personal_dialog);
+}
+
 /*
  *  New contact dialog
  */
index e375f959cf0833ee6dda19a1ad6fc0d21e9da4f8..c714c6b9611d3560762d35a5b21cfa99cbc098d0 100644 (file)
 G_BEGIN_DECLS
 
 void empathy_subscription_dialog_show        (EmpathyContact *contact,
-                                             GtkWindow     *parent);
+                                             GtkWindow      *parent);
 void empathy_contact_information_dialog_show (EmpathyContact *contact,
-                                             GtkWindow     *parent,
-                                             gboolean       edit,
-                                             gboolean       is_user);
-void empathy_new_contact_dialog_show         (GtkWindow     *parent);
+                                             GtkWindow      *parent);
+void empathy_contact_edit_dialog_show        (EmpathyContact *contact,
+                                             GtkWindow      *parent);
+void empathy_contact_personal_dialog_show    (GtkWindow      *parent);
+void empathy_new_contact_dialog_show         (GtkWindow      *parent);
 
 G_END_DECLS
 
index 9cd9a0b9fb5f1c9a89eefffa7d587f5713b00e58..a3cf1da26f71aeedf5874d1e26c48d96f6cec19c 100644 (file)
@@ -236,7 +236,7 @@ empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
 static void
 contact_info_menu_item_activate_cb (EmpathyContact *contact)
 {
-       empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
+       empathy_contact_information_dialog_show (contact, NULL);
 }
 
 GtkWidget *
@@ -263,7 +263,7 @@ empathy_contact_info_menu_item_new (EmpathyContact *contact)
 static void
 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
 {
-       empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
+       empathy_contact_edit_dialog_show (contact, NULL);
 }
 
 GtkWidget *
index 0c836f93c4050a469eeb1be96ff24ac7629a1862..165d48b442a73b184967c51524aaba5200855a3c 100644 (file)
@@ -106,8 +106,6 @@ static void contact_widget_contact_update (EmpathyContactWidget *information);
 static void contact_widget_change_contact (EmpathyContactWidget *information);
 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
     EmpathyContactWidget *information);
-static void contact_widget_account_changed_cb (GtkComboBox *widget,
-    EmpathyContactWidget *information);
 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
     GdkEventFocus *event, EmpathyContactWidget *information);
 static gboolean contact_widget_entry_alias_focus_event_cb (
@@ -162,7 +160,8 @@ empathy_contact_widget_new (EmpathyContact *contact,
   TpConnection *connection;
   gchar *filename;
 
-  connection = empathy_contact_get_connection (contact);
+  g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
+
   information = g_slice_new0 (EmpathyContactWidget);
   information->flags = flags;
 
@@ -207,7 +206,8 @@ empathy_contact_widget_new (EmpathyContact *contact,
   contact_widget_details_setup (information);
   contact_widget_client_setup (information);
 
-  contact_widget_set_contact (information, contact);
+  if (contact != NULL)
+      contact_widget_set_contact (information, contact);
 
   return empathy_builder_unref_and_keep_widget (gui,
     information->vbox_contact_widget);
@@ -510,8 +510,9 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
     {
       information->widget_account = empathy_account_chooser_new ();
 
-      g_signal_connect (information->widget_account, "changed",
-            G_CALLBACK (contact_widget_account_changed_cb),
+      contact_widget_change_contact (information);
+      g_signal_connect_swapped (information->widget_account, "changed",
+            G_CALLBACK (contact_widget_change_contact),
             information);
     }
   else
@@ -641,12 +642,12 @@ contact_widget_contact_update (EmpathyContactWidget *information)
       if (account)
         {
           g_signal_handlers_block_by_func (information->widget_account,
-                   contact_widget_account_changed_cb,
+                   contact_widget_change_contact,
                    information);
           empathy_account_chooser_set_account (
               EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
           g_signal_handlers_unblock_by_func (information->widget_account,
-              contact_widget_account_changed_cb, information);
+              contact_widget_change_contact, information);
         }
     }
   else
@@ -775,13 +776,6 @@ contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
     }
 }
 
-static void
-contact_widget_account_changed_cb (GtkComboBox *widget,
-                                   EmpathyContactWidget *information)
-{
-  contact_widget_change_contact (information);
-}
-
 static gboolean
 contact_widget_id_focus_out_cb (GtkWidget *widget,
                                 GdkEventFocus *event,