1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 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_chat;
51 GtkWidget *button_call;
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);
73 empathy_call_with_contact_id (account, id);
75 else if (response == 2) {
76 empathy_chat_with_contact_id (account, id);
79 g_object_unref (account);
80 gtk_widget_destroy (widget);
84 new_message_change_state_button_cb (GtkEditable *editable,
85 EmpathyNewMessageDialog *dialog)
90 id = gtk_entry_get_text (GTK_ENTRY (editable));
91 sensitive = !G_STR_EMPTY (id);
93 gtk_widget_set_sensitive (dialog->button_chat, sensitive);
94 gtk_widget_set_sensitive (dialog->button_call, sensitive);
98 new_message_dialog_destroy_cb (GtkWidget *widget,
99 EmpathyNewMessageDialog *dialog)
105 empathy_new_message_dialog_show (GtkWindow *parent)
107 static EmpathyNewMessageDialog *dialog = NULL;
112 gtk_window_present (GTK_WINDOW (dialog->dialog));
113 return dialog->dialog;
116 dialog = g_new0 (EmpathyNewMessageDialog, 1);
118 filename = empathy_file_lookup ("empathy-new-message-dialog.glade",
120 glade = empathy_glade_get_file (filename,
121 "new_message_dialog",
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,
131 empathy_glade_connect (glade,
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,
138 g_object_add_weak_pointer (G_OBJECT (dialog->dialog), (gpointer) &dialog);
140 g_object_unref (glade);
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,
147 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
148 empathy_account_chooser_filter_is_connected,
150 gtk_widget_show (dialog->account_chooser);
153 gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
154 GTK_WINDOW (parent));
157 gtk_widget_set_sensitive (dialog->button_chat, FALSE);
158 gtk_widget_set_sensitive (dialog->button_call, FALSE);
161 gtk_widget_hide (dialog->button_call);
164 gtk_widget_show (dialog->dialog);
166 return dialog->dialog;