[empathy] - Split info/edit/personal dialogs into different functions.
- From: Xavier Claessens <xclaesse src gnome org>
- To: svn-commits-list gnome org
- Subject: [empathy] - Split info/edit/personal dialogs into different functions.
- Date: Wed, 22 Apr 2009 06:25:20 -0400 (EDT)
commit 8dcee288a0733ece2681f437f9da4651f4b7f5d8
Author: Xavier Claessens <xclaesse gmail com>
Date: Tue Feb 17 14:23:52 2009 +0100
- Split info/edit/personal dialogs into different functions.
- Make sure empathy_contact_widget_new works with a NULL contact.
---
libempathy-gtk/empathy-contact-dialogs.c | 166 ++++++++++++++++++++++--------
libempathy-gtk/empathy-contact-dialogs.h | 11 +-
libempathy-gtk/empathy-contact-menu.c | 4 +-
libempathy-gtk/empathy-contact-widget.c | 24 ++---
4 files changed, 142 insertions(+), 63 deletions(-)
diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c
index 309cd64..38e0240 100644
--- a/libempathy-gtk/empathy-contact-dialogs.c
+++ b/libempathy-gtk/empathy-contact-dialogs.c
@@ -40,9 +40,10 @@
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
*/
diff --git a/libempathy-gtk/empathy-contact-dialogs.h b/libempathy-gtk/empathy-contact-dialogs.h
index e375f95..c714c6b 100644
--- a/libempathy-gtk/empathy-contact-dialogs.h
+++ b/libempathy-gtk/empathy-contact-dialogs.h
@@ -29,12 +29,13 @@
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
diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c
index 9cd9a0b..a3cf1da 100644
--- a/libempathy-gtk/empathy-contact-menu.c
+++ b/libempathy-gtk/empathy-contact-menu.c
@@ -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 *
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 0c836f9..165d48b 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]