]> git.0d.be Git - empathy.git/blob - tests/empetit.c
14a813034fd26597d56e6d5488891c7e9891bc2a
[empathy.git] / tests / empetit.c
1 #include "config.h"
2
3 #include <gtk/gtk.h>
4
5 #include <libempathy/empathy-contact-manager.h>
6 #include <libempathy/empathy-dispatcher.h>
7
8 #include <libempathy-gtk/empathy-contact-list-store.h>
9 #include <libempathy-gtk/empathy-contact-selector.h>
10
11 static GtkWidget *window = NULL;
12
13 static void
14 chat_cb (EmpathyDispatchOperation *dispatch,
15          const GError *error,
16          gpointer user_data)
17 {
18   GtkWidget *dialog;
19
20   if (error != NULL)
21     {
22       dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL,
23           GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
24           error->message ? error->message : "No error message");
25
26       gtk_dialog_run (GTK_DIALOG (dialog));
27     }
28
29   gtk_widget_destroy (window);
30 }
31
32 static void
33 clicked_cb (GtkButton *button,
34             gpointer data)
35 {
36   EmpathyContactSelector *selector = EMPATHY_CONTACT_SELECTOR (data);
37   EmpathyContact *contact;
38
39   contact = empathy_contact_selector_get_selected (selector);
40
41   if (!contact)
42     return;
43
44   /* This is required otherwise the dispatcher isn't ref'd, and so it
45    * disappears by the time the callback gets called. It's deliberately not
46    * freed otherwise it segfaults... sigh */
47   empathy_dispatcher_dup_singleton ();
48   empathy_dispatcher_chat_with_contact (contact, chat_cb, NULL);
49 }
50
51 int main (int argc,
52           char *argv[])
53 {
54   EmpathyContactManager *manager;
55   EmpathyContactListStore *store;
56   GtkWidget *vbox, *button, *selector;
57   gchar *icon_path;
58
59   gtk_init (&argc, &argv);
60
61   icon_path = g_build_path (G_DIR_SEPARATOR_S, PKGDATADIR, "icons", NULL);
62   gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_path);
63   g_free (icon_path);
64
65   manager = empathy_contact_manager_dup_singleton ();
66   store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (manager));
67
68   vbox = gtk_vbox_new (FALSE, 2);
69
70   selector = empathy_contact_selector_new (store);
71   gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, FALSE, 5);
72
73   button = gtk_button_new_with_label ("Chat");
74   g_signal_connect (G_OBJECT (button), "clicked",
75       G_CALLBACK (clicked_cb), (gpointer) selector);
76   gtk_box_pack_start(GTK_BOX (vbox), button, FALSE, FALSE, 5);
77
78   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
79   g_signal_connect (G_OBJECT (window), "destroy",
80       gtk_main_quit, NULL);
81   gtk_window_set_title (GTK_WINDOW (window),"Empetit");
82   gtk_container_set_border_width (GTK_CONTAINER (window), 5);
83   gtk_container_add (GTK_CONTAINER (window), vbox);
84   gtk_widget_show_all (window);
85
86   gtk_main ();
87
88   g_object_unref (store);
89   g_object_unref (manager);
90
91   return 0;
92 }