]> git.0d.be Git - empathy.git/commitdiff
[EmpathyContactSelectorDialog] remove got_response vcall
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Sat, 19 Dec 2009 01:42:25 +0000 (12:42 +1100)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Mon, 21 Dec 2009 09:52:47 +0000 (20:52 +1100)
The got_response vcall method wasn't generic enough. It assumed that your
response code was always GTK_RESPONSE_ACCEPT, and doesn't allow for the dialog
to be used with gtk_dialog_run.

Instead dialogs now use the regular response() vcall provided by GtkDialog,
and an additional API method empathy_contact_selector_dialog_get_selected()
provides the information content of the dialog.

libempathy-gtk/empathy-contact-selector-dialog.c
libempathy-gtk/empathy-contact-selector-dialog.h
libempathy-gtk/empathy-new-call-dialog.c
libempathy-gtk/empathy-new-message-dialog.c

index 1f3e21a6db6ca240131a3b5770635f539e43255f..58e0fff3504fd3ab9b135ed7fe4bcac466b70d01 100644 (file)
@@ -201,34 +201,6 @@ out:
   return v;
 }
 
-static void
-contact_selector_dialog_response_cb (GtkWidget *widget,
-    gint response,
-    EmpathyContactSelectorDialog *dialog)
-{
-  EmpathyContactSelectorDialogPriv *priv = GET_PRIV (dialog);
-  TpConnection *connection;
-  const gchar *id;
-  EmpathyContactSelectorDialogClass *class = \
-    EMPATHY_CONTACT_SELECTOR_DIALOG_GET_CLASS (dialog);
-
-  connection = empathy_account_chooser_get_connection (
-    EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser));
-  id = gtk_entry_get_text (GTK_ENTRY (priv->entry_id));
-  if (!connection || EMP_STR_EMPTY (id))
-    {
-      gtk_widget_destroy (widget);
-      return;
-    }
-
-  if (response == GTK_RESPONSE_ACCEPT)
-    {
-      class->got_response (dialog, connection, id);
-    }
-
-  gtk_widget_destroy (widget);
-}
-
 static void
 contact_selector_change_state_button_cb  (GtkEditable *editable,
     EmpathyContactSelectorDialog *dialog)
@@ -331,9 +303,6 @@ empathy_contact_selector_dialog_init (EmpathyContactSelectorDialog *dialog)
   g_object_unref (completion);
   g_object_unref (model);
 
-  g_signal_connect (dialog, "response",
-        G_CALLBACK (contact_selector_dialog_response_cb), dialog);
-
   empathy_builder_connect (gui, dialog,
              "entry_id", "changed", contact_selector_change_state_button_cb,
              NULL);
@@ -435,6 +404,31 @@ empathy_contact_selector_dialog_class_init (
         G_PARAM_READWRITE));
 }
 
+const gchar *
+empathy_contact_selector_dialog_get_selected (
+    EmpathyContactSelectorDialog *self,
+    TpConnection **connection)
+{
+  EmpathyContactSelectorDialogPriv *priv;
+  const char *id;
+
+  g_return_val_if_fail (EMPATHY_IS_CONTACT_SELECTOR_DIALOG (self), NULL);
+
+  priv = GET_PRIV (self);
+
+  if (connection)
+    {
+      if (priv->show_account_chooser)
+        *connection = empathy_account_chooser_get_connection (
+            EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser));
+      else
+        *connection = NULL;
+    }
+
+  id = gtk_entry_get_text (GTK_ENTRY (priv->entry_id));
+  return id;
+}
+
 void
 empathy_contact_selector_dialog_set_show_account_chooser (
     EmpathyContactSelectorDialog *self,
index 255d37ee142d335b401e2124341e7a6b266ba739..d8a698ab5dd5a806ca54d7f17b33f500f4a4d215 100644 (file)
@@ -38,10 +38,6 @@ typedef struct _EmpathyContactSelectorDialogClass \
 struct _EmpathyContactSelectorDialogClass {
   GtkDialogClass parent_class;
 
-  void (*got_response) (EmpathyContactSelectorDialog *self,
-      TpConnection *connection,
-      const gchar *contact_id);
-
   gboolean (*account_filter) (EmpathyContactSelectorDialog *self,
       TpAccount *account);
 };
@@ -55,6 +51,9 @@ struct _EmpathyContactSelectorDialog {
 };
 
 GType empathy_contact_selector_dialog_get_type (void);
+const gchar *empathy_contact_selector_dialog_get_selected (
+    EmpathyContactSelectorDialog *self,
+    TpConnection **connection);
 void empathy_contact_selector_dialog_set_show_account_chooser (
     EmpathyContactSelectorDialog *self,
     gboolean show_account_chooser);
index 2437b4978359bbb1eef1b87f3b74f96f4d0d039f..1a171af5a10d93b15fb4132ce393afe9a46ee9e2 100644 (file)
@@ -90,13 +90,20 @@ got_contact_cb (EmpathyTpContactFactory *factory,
 }
 
 static void
-empathy_new_call_dialog_got_response (EmpathyContactSelectorDialog *dialog,
-    TpConnection *connection,
-    const gchar *contact_id)
+empathy_new_call_dialog_response (GtkDialog *dialog, int response_id)
 {
   EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
   EmpathyTpContactFactory *factory;
   gboolean video;
+  TpConnection *connection;
+  const gchar *contact_id;
+
+  if (response_id != GTK_RESPONSE_ACCEPT) goto out;
+
+  contact_id = empathy_contact_selector_dialog_get_selected (
+      EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), &connection);
+
+  if (EMP_STR_EMPTY (contact_id) || connection == NULL) goto out;
 
   /* check if video is enabled now because the dialog will be destroyed once
    * we return from this function. */
@@ -107,6 +114,9 @@ empathy_new_call_dialog_got_response (EmpathyContactSelectorDialog *dialog,
       got_contact_cb, GUINT_TO_POINTER (video), NULL, NULL);
 
   g_object_unref (factory);
+
+out:
+  gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 static gboolean
@@ -204,15 +214,17 @@ empathy_new_call_dialog_class_init (
   EmpathyNewCallDialogClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
-  EmpathyContactSelectorDialogClass *dialog_class = \
+  GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
+  EmpathyContactSelectorDialogClass *selector_dialog_class = \
     EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
 
   g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
 
   object_class->constructor = empathy_new_call_dialog_constructor;
 
-  dialog_class->got_response = empathy_new_call_dialog_got_response;
-  dialog_class->account_filter = empathy_new_call_dialog_account_filter;
+  dialog_class->response = empathy_new_call_dialog_response;
+
+  selector_dialog_class->account_filter = empathy_new_call_dialog_account_filter;
 }
 
 /**
index 3b60b63d5dc1116f7e27da748ad236d57314cf9e..338da276077a6bb224a2966e47bda0c60fdbb82f 100644 (file)
@@ -58,11 +58,22 @@ G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
  */
 
 static void
-empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
-    TpConnection *connection,
-    const gchar *contact_id)
+empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
 {
+  TpConnection *connection;
+  const gchar *contact_id;
+
+  if (response_id != GTK_RESPONSE_ACCEPT) goto out;
+
+  contact_id = empathy_contact_selector_dialog_get_selected (
+      EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), &connection);
+
+  if (EMP_STR_EMPTY (contact_id) || connection == NULL) goto out;
+
   empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
+
+out:
+  gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 static gboolean
@@ -151,13 +162,15 @@ empathy_new_message_dialog_class_init (
   EmpathyNewMessageDialogClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
-  EmpathyContactSelectorDialogClass *dialog_class = \
+  GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
+  EmpathyContactSelectorDialogClass *selector_dialog_class = \
     EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
 
   object_class->constructor = empathy_new_message_dialog_constructor;
 
-  dialog_class->got_response = empathy_new_message_dialog_got_response;
-  dialog_class->account_filter = empathy_new_message_account_filter;
+  dialog_class->response = empathy_new_message_dialog_response;
+
+  selector_dialog_class->account_filter = empathy_new_message_account_filter;
 }
 
 /**