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 <glib/gi18n-lib.h>
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>
35 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
36 #include <libempathy/empathy-debug.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
39 #include <libempathy-gtk/empathy-images.h>
41 #include "empathy-new-message-dialog.h"
42 #include "empathy-account-chooser.h"
44 static EmpathyNewMessageDialog *dialog_singleton = NULL;
46 G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
47 EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
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
55 * #EmpathyNewMessageDialog is a dialog which allows a text chat
56 * to be started with any contact on any enabled account.
60 empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
61 TpConnection *connection,
62 const gchar *contact_id)
64 empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
68 empathy_new_message_dialog_constructor (GType type,
70 GObjectConstructParam *props)
74 if (dialog_singleton) {
75 retval = G_OBJECT (dialog_singleton);
76 g_object_ref (retval);
79 retval = G_OBJECT_CLASS (
80 empathy_new_message_dialog_parent_class)->constructor (type,
83 dialog_singleton = EMPATHY_NEW_MESSAGE_DIALOG (retval);
84 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
91 empathy_new_message_dialog_init (EmpathyNewMessageDialog *dialog)
93 EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
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);
103 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
104 GTK_RESPONSE_ACCEPT);
105 gtk_widget_show (parent->button_action);
107 /* Tweak the dialog */
108 gtk_window_set_title (GTK_WINDOW (dialog), _("New Conversation"));
109 gtk_window_set_role (GTK_WINDOW (dialog), "new_message");
111 gtk_widget_set_sensitive (parent->button_action, FALSE);
115 empathy_new_message_dialog_class_init (
116 EmpathyNewMessageDialogClass *class)
118 GObjectClass *object_class = G_OBJECT_CLASS (class);
119 EmpathyContactSelectorDialogClass *dialog_class = \
120 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
122 object_class->constructor = empathy_new_message_dialog_constructor;
124 dialog_class->got_response = empathy_new_message_dialog_got_response;
128 * empathy_new_message_dialog_new:
129 * @parent: parent #GtkWindow of the dialog
131 * Create a new #EmpathyNewMessageDialog it.
133 * Return value: the new #EmpathyNewMessageDialog
136 empathy_new_message_dialog_show (GtkWindow *parent)
140 dialog = g_object_new (EMPATHY_TYPE_NEW_MESSAGE_DIALOG, NULL);
143 gtk_window_set_transient_for (GTK_WINDOW (dialog),
144 GTK_WINDOW (parent));
147 gtk_widget_show (dialog);