]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-message-dialog.c
Remove conditional build of VOIP.
[empathy.git] / libempathy-gtk / empathy-new-message-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include <gtk/gtk.h>
28 #include <glade/glade.h>
29 #include <glib/gi18n.h>
30
31 #include <libmissioncontrol/mc-account.h>
32 #include <libmissioncontrol/mission-control.h>
33
34 #include <libempathy/empathy-contact-factory.h>
35 #include <libempathy/empathy-debug.h>
36 #include <libempathy/empathy-utils.h>
37
38 #include <libempathy-gtk/empathy-ui-utils.h>
39
40 #include "empathy-new-message-dialog.h"
41 #include "empathy-account-chooser.h"
42
43 #define DEBUG_DOMAIN "NewMessageDialog"
44
45 typedef struct {
46         GtkWidget *dialog;
47         GtkWidget *table_contact;
48         GtkWidget *account_chooser;
49         GtkWidget *entry_id;
50         GtkWidget *button_chat;
51         GtkWidget *button_call;
52 } EmpathyNewMessageDialog;
53
54 static void
55 new_message_dialog_response_cb (GtkWidget               *widget,
56                                 gint                    response,
57                                 EmpathyNewMessageDialog *dialog)
58 {
59         McAccount   *account;
60         const gchar *id;
61
62         account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser));
63         id = gtk_entry_get_text (GTK_ENTRY (dialog->entry_id));
64         if (!account || G_STR_EMPTY (id)) {
65                 if (account) {
66                         g_object_unref (account);
67                 }
68                 gtk_widget_destroy (widget);
69                 return;
70         }
71
72         if (response == 1) {
73                 empathy_call_with_contact_id (account, id);
74         }       
75         else if (response == 2) {
76                 empathy_chat_with_contact_id (account, id);
77         }
78
79         g_object_unref (account);
80         gtk_widget_destroy (widget);
81 }
82
83 static void
84 new_message_change_state_button_cb  (GtkEditable             *editable,
85                                      EmpathyNewMessageDialog *dialog)  
86 {
87         const gchar *id;
88         gboolean     sensitive;
89
90         id = gtk_entry_get_text (GTK_ENTRY (editable));
91         sensitive = !G_STR_EMPTY (id);
92         
93         gtk_widget_set_sensitive (dialog->button_chat, sensitive);
94         gtk_widget_set_sensitive (dialog->button_call, sensitive);
95 }
96
97 static void
98 new_message_dialog_destroy_cb (GtkWidget               *widget,
99                                EmpathyNewMessageDialog *dialog)
100 {       
101         g_free (dialog);
102 }
103
104 GtkWidget *
105 empathy_new_message_dialog_show (GtkWindow *parent)
106 {
107         static EmpathyNewMessageDialog *dialog = NULL;
108         GladeXML                       *glade;
109         gchar                          *filename;
110
111         if (dialog) {
112                 gtk_window_present (GTK_WINDOW (dialog->dialog));
113                 return dialog->dialog;
114         }
115
116         dialog = g_new0 (EmpathyNewMessageDialog, 1);
117
118         filename = empathy_file_lookup ("empathy-new-message-dialog.glade",
119                                         "libempathy-gtk");
120         glade = empathy_glade_get_file (filename,
121                                         "new_message_dialog",
122                                         NULL,
123                                         "new_message_dialog", &dialog->dialog,
124                                         "table_contact", &dialog->table_contact,
125                                         "entry_id", &dialog->entry_id,
126                                         "button_chat", &dialog->button_chat,
127                                         "button_call",&dialog->button_call,
128                                         NULL);
129         g_free (filename);
130
131         empathy_glade_connect (glade,
132                                dialog,
133                                "new_message_dialog", "destroy", new_message_dialog_destroy_cb,
134                                "new_message_dialog", "response", new_message_dialog_response_cb,
135                                "entry_id", "changed", new_message_change_state_button_cb,
136                                NULL);
137
138         g_object_add_weak_pointer (G_OBJECT (dialog->dialog), (gpointer) &dialog);
139
140         g_object_unref (glade);
141
142         /* Create account chooser */
143         dialog->account_chooser = empathy_account_chooser_new ();
144         gtk_table_attach_defaults (GTK_TABLE (dialog->table_contact),
145                                    dialog->account_chooser,
146                                    1, 2, 0, 1);
147         empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
148                                             empathy_account_chooser_filter_is_connected,
149                                             NULL);
150         gtk_widget_show (dialog->account_chooser);
151
152         if (parent) {
153                 gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
154                                               GTK_WINDOW (parent));
155         }
156
157         gtk_widget_set_sensitive (dialog->button_chat, FALSE);
158         gtk_widget_set_sensitive (dialog->button_call, FALSE);
159
160         gtk_widget_show (dialog->dialog);
161
162         return dialog->dialog;
163 }
164