]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-message-dialog.c
new-message-dialog: inherit from EmpathyContactSelectorDialog
[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 <glib/gi18n-lib.h>
29
30 #include <libempathy/empathy-tp-contact-factory.h>
31 #include <libempathy/empathy-contact-manager.h>
32 #include <libempathy/empathy-dispatcher.h>
33 #include <libempathy/empathy-utils.h>
34
35 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
36 #include <libempathy/empathy-debug.h>
37
38 #include <libempathy-gtk/empathy-ui-utils.h>
39 #include <libempathy-gtk/empathy-images.h>
40
41 #include "empathy-new-message-dialog.h"
42 #include "empathy-account-chooser.h"
43
44 static EmpathyNewMessageDialog *dialog_singleton = NULL;
45
46 G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
47                                        EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
48
49 /**
50  * SECTION:empathy-new-message-dialog
51  * @title: EmpathyNewMessageDialog
52  * @short_description: A dialog to show a new message
53  * @include: libempathy-gtk/empathy-new-message-dialog.h
54  *
55  * #EmpathyNewMessageDialog is a dialog which allows a text chat
56  * to be started with any contact on any enabled account.
57  */
58
59 static void
60 empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
61                                 TpConnection *connection,
62                                 const gchar *contact_id)
63 {
64         empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
65 }
66
67 static GObject *
68 empathy_new_message_dialog_constructor (GType type,
69                                         guint n_props,
70                                         GObjectConstructParam *props)
71 {
72         GObject *retval;
73
74         if (dialog_singleton) {
75                 retval = G_OBJECT (dialog_singleton);
76                 g_object_ref (retval);
77         }
78         else {
79                 retval = G_OBJECT_CLASS (
80                 empathy_new_message_dialog_parent_class)->constructor (type,
81                         n_props, props);
82
83                 dialog_singleton = EMPATHY_NEW_MESSAGE_DIALOG (retval);
84                 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
85         }
86
87         return retval;
88 }
89
90 static void
91 empathy_new_message_dialog_init (EmpathyNewMessageDialog *dialog)
92 {
93         EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
94                                 dialog);
95         GtkWidget                      *image;
96
97         /* add chat button */
98         parent->button_action = gtk_button_new_with_mnemonic (_("C_hat"));
99         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE,
100                 GTK_ICON_SIZE_BUTTON);
101         gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
102
103         gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
104                 GTK_RESPONSE_ACCEPT);
105         gtk_widget_show (parent->button_action);
106
107         /* Tweak the dialog */
108         gtk_window_set_title (GTK_WINDOW (dialog), _("New Conversation"));
109         gtk_window_set_role (GTK_WINDOW (dialog), "new_message");
110
111         gtk_widget_set_sensitive (parent->button_action, FALSE);
112 }
113
114 static void
115 empathy_new_message_dialog_class_init (
116   EmpathyNewMessageDialogClass *class)
117 {
118         GObjectClass *object_class = G_OBJECT_CLASS (class);
119         EmpathyContactSelectorDialogClass *dialog_class = \
120                 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
121
122         object_class->constructor = empathy_new_message_dialog_constructor;
123
124         dialog_class->got_response = empathy_new_message_dialog_got_response;
125 }
126
127 /**
128  * empathy_new_message_dialog_new:
129  * @parent: parent #GtkWindow of the dialog
130  *
131  * Create a new #EmpathyNewMessageDialog it.
132  *
133  * Return value: the new #EmpathyNewMessageDialog
134  */
135 GtkWidget *
136 empathy_new_message_dialog_show (GtkWindow *parent)
137 {
138         GtkWidget *dialog;
139
140         dialog = g_object_new (EMPATHY_TYPE_NEW_MESSAGE_DIALOG, NULL);
141
142         if (parent) {
143                 gtk_window_set_transient_for (GTK_WINDOW (dialog),
144                                               GTK_WINDOW (parent));
145         }
146
147         gtk_widget_show (dialog);
148         return dialog;
149 }