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-dispatcher.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"
45 GtkWidget *table_contact;
46 GtkWidget *account_chooser;
48 GtkWidget *button_chat;
49 GtkWidget *button_call;
50 } EmpathyNewMessageDialog;
53 new_message_dialog_response_cb (GtkWidget *widget,
55 EmpathyNewMessageDialog *dialog)
60 account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser));
61 id = gtk_entry_get_text (GTK_ENTRY (dialog->entry_id));
62 if (!account || G_STR_EMPTY (id)) {
64 g_object_unref (account);
66 gtk_widget_destroy (widget);
71 empathy_dispatcher_call_with_contact_id (account, id);
73 else if (response == 2) {
74 empathy_dispatcher_chat_with_contact_id (account, id);
77 g_object_unref (account);
78 gtk_widget_destroy (widget);
82 new_message_change_state_button_cb (GtkEditable *editable,
83 EmpathyNewMessageDialog *dialog)
88 id = gtk_entry_get_text (GTK_ENTRY (editable));
89 sensitive = !G_STR_EMPTY (id);
91 gtk_widget_set_sensitive (dialog->button_chat, sensitive);
92 gtk_widget_set_sensitive (dialog->button_call, sensitive);
96 new_message_dialog_destroy_cb (GtkWidget *widget,
97 EmpathyNewMessageDialog *dialog)
103 empathy_new_message_dialog_show (GtkWindow *parent)
105 static EmpathyNewMessageDialog *dialog = NULL;
110 gtk_window_present (GTK_WINDOW (dialog->dialog));
111 return dialog->dialog;
114 dialog = g_new0 (EmpathyNewMessageDialog, 1);
116 filename = empathy_file_lookup ("empathy-new-message-dialog.glade",
118 glade = empathy_glade_get_file (filename,
119 "new_message_dialog",
121 "new_message_dialog", &dialog->dialog,
122 "table_contact", &dialog->table_contact,
123 "entry_id", &dialog->entry_id,
124 "button_chat", &dialog->button_chat,
125 "button_call",&dialog->button_call,
129 empathy_glade_connect (glade,
131 "new_message_dialog", "destroy", new_message_dialog_destroy_cb,
132 "new_message_dialog", "response", new_message_dialog_response_cb,
133 "entry_id", "changed", new_message_change_state_button_cb,
136 g_object_add_weak_pointer (G_OBJECT (dialog->dialog), (gpointer) &dialog);
138 g_object_unref (glade);
140 /* Create account chooser */
141 dialog->account_chooser = empathy_account_chooser_new ();
142 gtk_table_attach_defaults (GTK_TABLE (dialog->table_contact),
143 dialog->account_chooser,
145 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
146 empathy_account_chooser_filter_is_connected,
148 gtk_widget_show (dialog->account_chooser);
151 gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
152 GTK_WINDOW (parent));
155 gtk_widget_set_sensitive (dialog->button_chat, FALSE);
156 gtk_widget_set_sensitive (dialog->button_call, FALSE);
158 gtk_widget_show (dialog->dialog);
160 return dialog->dialog;