]> git.0d.be Git - empathy.git/blobdiff - tests/empetit.c
Adjust empetit to test the contact selector filtering.
[empathy.git] / tests / empetit.c
index 6ba5a2ad417490ab64bf6781b169b71cd6bd8a21..e2eb61f66eeaec3007cec65d5994e2bef9c08df4 100644 (file)
@@ -5,17 +5,30 @@
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-dispatcher.h>
 
+#include <libempathy-gtk/empathy-ui-utils.h>
 #include <libempathy-gtk/empathy-contact-list-store.h>
 #include <libempathy-gtk/empathy-contact-selector.h>
 
+static GtkWidget *window = NULL;
 
 static void
-destroy_cb (GtkWidget *widget,
-            gpointer data)
+chat_cb (EmpathyDispatchOperation *dispatch,
+         const GError *error,
+         gpointer user_data)
 {
-  gtk_main_quit ();
-}
+  GtkWidget *dialog;
+
+  if (error != NULL)
+    {
+      dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL,
+          GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s",
+          error->message ? error->message : "No error message");
+
+      gtk_dialog_run (GTK_DIALOG (dialog));
+    }
 
+  gtk_widget_destroy (window);
+}
 
 static void
 clicked_cb (GtkButton *button,
@@ -24,37 +37,35 @@ clicked_cb (GtkButton *button,
   EmpathyContactSelector *selector = EMPATHY_CONTACT_SELECTOR (data);
   EmpathyContact *contact;
 
-  contact = empathy_contact_selector_get_selected (selector);
+  contact = empathy_contact_selector_dup_selected (selector);
 
   if (!contact)
     return;
 
-  empathy_dispatcher_chat_with_contact (contact);
-}
+  empathy_dispatcher_chat_with_contact (contact, chat_cb, NULL);
 
+  g_object_unref (contact);
+}
 
 int main (int argc,
           char *argv[])
 {
   EmpathyContactManager *manager;
-  EmpathyContactListStore *store;
-  EmpathyContactSelector *selector;
-  GtkWidget *window, *vbox, *button;
-  gchar *icon_path;
+  GtkWidget *vbox, *button, *selector;
 
   gtk_init (&argc, &argv);
 
-  icon_path = g_build_path (G_DIR_SEPARATOR_S, PKGDATADIR, "icons", NULL);
-  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_path);
-  g_free (icon_path);
+  empathy_gtk_init ();
 
   manager = empathy_contact_manager_dup_singleton ();
-  store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (manager));
+  selector = empathy_contact_selector_new (EMPATHY_CONTACT_LIST (manager));
+
+  empathy_contact_selector_set_visible (EMPATHY_CONTACT_SELECTOR (selector),
+      (EmpathyContactSelectorFilterFunc) empathy_contact_can_send_files, NULL);
 
   vbox = gtk_vbox_new (FALSE, 2);
 
-  selector = empathy_contact_selector_new (store);
-  gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (selector), FALSE, FALSE, 5);
+  gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, FALSE, 5);
 
   button = gtk_button_new_with_label ("Chat");
   g_signal_connect (G_OBJECT (button), "clicked",
@@ -63,7 +74,7 @@ int main (int argc,
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   g_signal_connect (G_OBJECT (window), "destroy",
-      G_CALLBACK (destroy_cb), NULL);
+      gtk_main_quit, NULL);
   gtk_window_set_title (GTK_WINDOW (window),"Empetit");
   gtk_container_set_border_width (GTK_CONTAINER (window), 5);
   gtk_container_add (GTK_CONTAINER (window), vbox);
@@ -71,7 +82,6 @@ int main (int argc,
 
   gtk_main ();
 
-  g_object_unref (store);
   g_object_unref (manager);
 
   return 0;