]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-message-dialog.c
Squashed commit of the following:
[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 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-debug.h>
35 #include <libempathy/empathy-utils.h>
36
37 #include <libempathy-gtk/empathy-ui-utils.h>
38
39 #include "empathy-new-message-dialog.h"
40 #include "empathy-account-chooser.h"
41
42 #define DEBUG_DOMAIN "NewMessageDialog"
43
44 typedef struct {
45         GtkWidget *dialog;
46         GtkWidget *table_contact;
47         GtkWidget *account_chooser;
48         GtkWidget *entry_id;
49 } EmpathyNewMessageDialog;
50
51
52 static void
53 new_message_dialog_response_cb (GtkWidget               *widget,
54                                 gint                     response,
55                                 EmpathyNewMessageDialog *dialog)
56 {
57         if (response == GTK_RESPONSE_OK) {
58                 MissionControl *mc;
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                 mc = empathy_mission_control_new ();
65
66                 mission_control_request_channel_with_string_handle (mc,
67                                                                     account,
68                                                                     TP_IFACE_CHANNEL_TYPE_TEXT,
69                                                                     id,
70                                                                     TP_HANDLE_TYPE_CONTACT,
71                                                                     NULL, NULL);
72                 g_object_unref (mc);
73                 g_object_unref (account);
74         }
75
76         gtk_widget_destroy (widget);
77 }
78
79 static void
80 new_message_dialog_destroy_cb (GtkWidget               *widget,
81                                EmpathyNewMessageDialog *dialog)
82 {       
83         g_free (dialog);
84 }
85
86 GtkWidget *
87 empathy_new_message_dialog_show (GtkWindow *parent)
88 {
89         static EmpathyNewMessageDialog *dialog = NULL;
90         GladeXML                       *glade;
91
92         if (dialog) {
93                 gtk_window_present (GTK_WINDOW (dialog->dialog));
94                 return dialog->dialog;
95         }
96
97         dialog = g_new0 (EmpathyNewMessageDialog, 1);
98
99         glade = empathy_glade_get_file ("empathy-new-message-dialog.glade",
100                                        "new_message_dialog",
101                                        NULL,
102                                        "new_message_dialog", &dialog->dialog,
103                                        "table_contact", &dialog->table_contact,
104                                        "entry_id", &dialog->entry_id,
105                                        NULL);
106
107         empathy_glade_connect (glade,
108                               dialog,
109                               "new_message_dialog", "destroy", new_message_dialog_destroy_cb,
110                               "new_message_dialog", "response", new_message_dialog_response_cb,
111                               NULL);
112
113         g_object_add_weak_pointer (G_OBJECT (dialog->dialog), (gpointer) &dialog);
114
115         g_object_unref (glade);
116
117         /* Create account chooser */
118         dialog->account_chooser = empathy_account_chooser_new ();
119         gtk_table_attach_defaults (GTK_TABLE (dialog->table_contact),
120                                    dialog->account_chooser,
121                                    1, 2, 0, 1);
122         empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
123                                             empathy_account_chooser_filter_is_connected,
124                                             NULL);
125         gtk_widget_show (dialog->account_chooser);
126
127         if (parent) {
128                 gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
129                                               GTK_WINDOW (parent));
130         }
131
132         gtk_widget_show (dialog->dialog);
133
134         return dialog->dialog;
135 }
136