]> git.0d.be Git - empathy.git/blob - tests/empetit.c
Use the new _dup_singleton function instead of _new.
[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
12 static void
13 destroy_cb (GtkWidget *widget,
14             gpointer data)
15 {
16   gtk_main_quit ();
17 }
18
19
20 static void
21 clicked_cb (GtkButton *button,
22             gpointer data)
23 {
24   EmpathyContactSelector *selector = EMPATHY_CONTACT_SELECTOR (data);
25   EmpathyContact *contact;
26
27   contact = empathy_contact_selector_get_selected (selector);
28
29   if (!contact)
30     return;
31
32   empathy_dispatcher_chat_with_contact (contact);
33 }
34
35
36 int main (int argc,
37           char *argv[])
38 {
39   EmpathyContactManager *manager;
40   EmpathyContactListStore *store;
41   EmpathyContactSelector *selector;
42   GtkWidget *window, *vbox, *button;
43   gchar *icon_path;
44
45   gtk_init (&argc, &argv);
46
47   icon_path = g_build_path (G_DIR_SEPARATOR_S, PKGDATADIR, "icons", NULL);
48   gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_path);
49   g_free (icon_path);
50
51   manager = empathy_contact_manager_dup_singleton ();
52   store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (manager));
53
54   vbox = gtk_vbox_new (FALSE, 2);
55
56   selector = empathy_contact_selector_new (store);
57   gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (selector), FALSE, FALSE, 5);
58
59   button = gtk_button_new_with_label ("Chat");
60   g_signal_connect (G_OBJECT (button), "clicked",
61       G_CALLBACK (clicked_cb), (gpointer) selector);
62   gtk_box_pack_start(GTK_BOX (vbox), button, FALSE, FALSE, 5);
63
64   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
65   g_signal_connect (G_OBJECT (window), "destroy",
66       G_CALLBACK (destroy_cb), NULL);
67   gtk_window_set_title (GTK_WINDOW (window),"Empetit");
68   gtk_container_set_border_width (GTK_CONTAINER (window), 5);
69   gtk_container_add (GTK_CONTAINER (window), vbox);
70   gtk_widget_show_all (window);
71
72   gtk_main ();
73
74   g_object_unref (store);
75   g_object_unref (manager);
76
77   return 0;
78 }