]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-message-dialog.c
empathy-new-message-dialog: port to TP coding style
[empathy.git] / libempathy-gtk / empathy-new-message-dialog.c
1 /*
2  * Copyright (C) 2007-2008 Collabora Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Xavier Claessens <xclaesse@gmail.com>
19  */
20
21 #include <config.h>
22
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include <gtk/gtk.h>
27 #include <glib/gi18n-lib.h>
28
29 #include <libempathy/empathy-tp-contact-factory.h>
30 #include <libempathy/empathy-contact-manager.h>
31 #include <libempathy/empathy-dispatcher.h>
32 #include <libempathy/empathy-utils.h>
33
34 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
35 #include <libempathy/empathy-debug.h>
36
37 #include <libempathy-gtk/empathy-ui-utils.h>
38 #include <libempathy-gtk/empathy-images.h>
39
40 #include "empathy-new-message-dialog.h"
41 #include "empathy-account-chooser.h"
42
43 static EmpathyNewMessageDialog *dialog_singleton = NULL;
44
45 G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
46                EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
47
48 /**
49  * SECTION:empathy-new-message-dialog
50  * @title: EmpathyNewMessageDialog
51  * @short_description: A dialog to show a new message
52  * @include: libempathy-gtk/empathy-new-message-dialog.h
53  *
54  * #EmpathyNewMessageDialog is a dialog which allows a text chat
55  * to be started with any contact on any enabled account.
56  */
57
58 static void
59 empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
60     TpConnection *connection,
61     const gchar *contact_id)
62 {
63   empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
64 }
65
66 static GObject *
67 empathy_new_message_dialog_constructor (GType type,
68     guint n_props,
69     GObjectConstructParam *props)
70 {
71   GObject *retval;
72
73   if (dialog_singleton)
74     {
75       retval = G_OBJECT (dialog_singleton);
76       g_object_ref (retval);
77     }
78   else
79     {
80       retval = G_OBJECT_CLASS (
81       empathy_new_message_dialog_parent_class)->constructor (type,
82         n_props, props);
83
84       dialog_singleton = EMPATHY_NEW_MESSAGE_DIALOG (retval);
85       g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
86     }
87
88   return retval;
89 }
90
91 static void
92 empathy_new_message_dialog_init (EmpathyNewMessageDialog *dialog)
93 {
94   EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
95         dialog);
96   GtkWidget *image;
97
98   /* add chat button */
99   parent->button_action = gtk_button_new_with_mnemonic (_("C_hat"));
100   image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE,
101       GTK_ICON_SIZE_BUTTON);
102   gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
103
104   gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
105       GTK_RESPONSE_ACCEPT);
106   gtk_widget_show (parent->button_action);
107
108   /* Tweak the dialog */
109   gtk_window_set_title (GTK_WINDOW (dialog), _("New Conversation"));
110   gtk_window_set_role (GTK_WINDOW (dialog), "new_message");
111
112   gtk_widget_set_sensitive (parent->button_action, FALSE);
113 }
114
115 static void
116 empathy_new_message_dialog_class_init (
117   EmpathyNewMessageDialogClass *class)
118 {
119   GObjectClass *object_class = G_OBJECT_CLASS (class);
120   EmpathyContactSelectorDialogClass *dialog_class = \
121     EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
122
123   object_class->constructor = empathy_new_message_dialog_constructor;
124
125   dialog_class->got_response = empathy_new_message_dialog_got_response;
126 }
127
128 /**
129  * empathy_new_message_dialog_new:
130  * @parent: parent #GtkWindow of the dialog
131  *
132  * Create a new #EmpathyNewMessageDialog it.
133  *
134  * Return value: the new #EmpathyNewMessageDialog
135  */
136 GtkWidget *
137 empathy_new_message_dialog_show (GtkWindow *parent)
138 {
139   GtkWidget *dialog;
140
141   dialog = g_object_new (EMPATHY_TYPE_NEW_MESSAGE_DIALOG, NULL);
142
143   if (parent)
144     {
145       gtk_window_set_transient_for (GTK_WINDOW (dialog),
146           GTK_WINDOW (parent));
147     }
148
149   gtk_widget_show (dialog);
150   return dialog;
151 }