1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
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.
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.
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
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glade/glade.h>
29 #include <glib/gi18n.h>
31 #include <libmissioncontrol/mc-account.h>
32 #include <libmissioncontrol/mission-control.h>
34 #include <libempathy/empathy-contact-factory.h>
35 #include <libempathy/empathy-debug.h>
36 #include <libempathy/empathy-utils.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
40 #include "empathy-new-message-dialog.h"
41 #include "empathy-account-chooser.h"
43 #define DEBUG_DOMAIN "NewMessageDialog"
47 GtkWidget *table_contact;
48 GtkWidget *account_chooser;
50 GtkWidget *button_validate;
51 GtkWidget *button_voip;
52 } EmpathyNewMessageDialog;
55 new_message_dialog_response_cb (GtkWidget *widget,
57 EmpathyNewMessageDialog *dialog)
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)) {
66 g_object_unref (account);
68 gtk_widget_destroy (widget);
72 if (response == GTK_RESPONSE_OK) {
75 mc = empathy_mission_control_new ();
76 mission_control_request_channel_with_string_handle (mc,
78 TP_IFACE_CHANNEL_TYPE_TEXT,
80 TP_HANDLE_TYPE_CONTACT,
84 else if (response == 3) {
85 EmpathyContactFactory *factory;
86 EmpathyContact *contact = NULL;
88 factory = empathy_contact_factory_new ();
89 contact = empathy_contact_factory_get_from_id (factory,
93 empathy_call_contact (contact);
95 empathy_debug (DEBUG_DOMAIN,
96 "Contact ID %s does not exists",
100 g_object_unref (contact);
101 g_object_unref (factory);
104 g_object_unref (account);
105 gtk_widget_destroy (widget);
109 new_message_change_state_button_cb (GtkEditable *editable,
110 EmpathyNewMessageDialog *dialog)
115 id = gtk_entry_get_text (GTK_ENTRY (editable));
116 sensitive = !G_STR_EMPTY (id);
118 gtk_widget_set_sensitive(dialog->button_validate, sensitive);
119 gtk_widget_set_sensitive(dialog->button_voip, sensitive);
123 new_message_dialog_destroy_cb (GtkWidget *widget,
124 EmpathyNewMessageDialog *dialog)
130 empathy_new_message_dialog_show (GtkWindow *parent)
132 static EmpathyNewMessageDialog *dialog = NULL;
136 gtk_window_present (GTK_WINDOW (dialog->dialog));
137 return dialog->dialog;
140 dialog = g_new0 (EmpathyNewMessageDialog, 1);
142 glade = empathy_glade_get_file ("empathy-new-message-dialog.glade",
143 "new_message_dialog",
145 "new_message_dialog", &dialog->dialog,
146 "table_contact", &dialog->table_contact,
147 "entry_id", &dialog->entry_id,
148 "button_validate", &dialog->button_validate,
149 "button_voip",&dialog->button_voip,
152 empathy_glade_connect (glade,
154 "new_message_dialog", "destroy", new_message_dialog_destroy_cb,
155 "new_message_dialog", "response", new_message_dialog_response_cb,
156 "entry_id", "changed", new_message_change_state_button_cb,
159 g_object_add_weak_pointer (G_OBJECT (dialog->dialog), (gpointer) &dialog);
161 g_object_unref (glade);
163 /* Create account chooser */
164 dialog->account_chooser = empathy_account_chooser_new ();
165 gtk_table_attach_defaults (GTK_TABLE (dialog->table_contact),
166 dialog->account_chooser,
168 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
169 empathy_account_chooser_filter_is_connected,
171 gtk_widget_show (dialog->account_chooser);
174 gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
175 GTK_WINDOW (parent));
178 gtk_widget_set_sensitive(dialog->button_validate, FALSE);
179 gtk_widget_set_sensitive(dialog->button_voip, FALSE);
181 gtk_widget_show (dialog->dialog);
183 return dialog->dialog;