31
31
#include <libempathy/empathy-tp-contact-factory.h>
32
32
#include <libempathy/empathy-contact-manager.h>
33
#include <libempathy/empathy-dispatcher.h>
33
#include <libempathy/empathy-request-util.h>
34
34
#include <libempathy/empathy-utils.h>
36
36
#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
62
62
* to be started with any contact on any enabled account.
66
72
empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
68
74
TpAccount *account;
69
75
const gchar *contact_id;
71
if (response_id != GTK_RESPONSE_ACCEPT) goto out;
77
if (response_id < EMP_NEW_MESSAGE_TEXT) goto out;
73
79
contact_id = empathy_contact_selector_dialog_get_selected (
74
80
EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, &account);
76
82
if (EMP_STR_EMPTY (contact_id) || account == NULL) goto out;
78
empathy_dispatcher_chat_with_contact_id (account, contact_id,
79
gtk_get_current_event_time ());
86
case EMP_NEW_MESSAGE_TEXT:
87
empathy_chat_with_contact_id (account, contact_id,
88
gtk_get_current_event_time ());
91
case EMP_NEW_MESSAGE_SMS:
92
empathy_sms_contact_id (account, contact_id,
93
gtk_get_current_event_time ());
82
101
gtk_widget_destroy (GTK_WIDGET (dialog));
90
109
FilterCallbackData *data = user_data;
91
110
GError *myerr = NULL;
92
111
TpCapabilities *caps;
96
113
if (!tp_proxy_prepare_finish (conn, result, &myerr))
115
data->callback (FALSE, data->user_data);
116
g_slice_free (FilterCallbackData, data);
99
119
caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
100
classes = tp_capabilities_get_channel_classes (caps);
102
for (i = 0; i < classes->len; i++)
106
const gchar *chan_type;
108
tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
111
chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
113
if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
116
if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
117
TP_HANDLE_TYPE_CONTACT)
120
data->callback (TRUE, data->user_data);
121
g_slice_free (FilterCallbackData, data);
126
data->callback (FALSE, data->user_data);
120
data->callback (tp_capabilities_supports_text_chats (caps),
127
123
g_slice_free (FilterCallbackData, data);
158
154
tp_proxy_prepare_async (connection, features, conn_prepared_cb, cb_data);
158
empathy_new_message_dialog_update_sms_button_sensitivity (GtkWidget *widget,
162
GtkWidget *self = gtk_widget_get_toplevel (widget);
163
EmpathyContactSelectorDialog *dialog;
166
gboolean sensitive = FALSE;
169
g_return_if_fail (EMPATHY_IS_NEW_MESSAGE_DIALOG (self));
171
dialog = EMPATHY_CONTACT_SELECTOR_DIALOG (self);
173
/* if the Text widget isn't sensitive, don't bother checking the caps */
174
if (!gtk_widget_get_sensitive (dialog->button_action))
177
empathy_contact_selector_dialog_get_selected (dialog, &conn, NULL);
182
/* iterate the rccs to find if SMS channels are supported, this should
184
rccs = tp_capabilities_get_channel_classes (
185
tp_connection_get_capabilities (conn));
187
for (i = 0; i < rccs->len; i++)
192
gboolean sms_channel;
194
tp_value_array_unpack (g_ptr_array_index (rccs, i), 2,
198
/* SMS channels are type:Text and sms-channel:True */
199
type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
200
sms_channel = tp_asv_get_boolean (fixed,
201
TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, NULL);
203
sensitive = sms_channel &&
204
!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_TEXT);
211
gtk_widget_set_sensitive (button, sensitive);
162
215
empathy_new_message_dialog_constructor (GType type,
189
242
EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
191
245
GtkWidget *image;
247
/* add an SMS button */
248
button = gtk_button_new_with_mnemonic (_("_SMS"));
249
image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
250
GTK_ICON_SIZE_BUTTON);
251
gtk_button_set_image (GTK_BUTTON (button), image);
253
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
254
EMP_NEW_MESSAGE_SMS);
255
gtk_widget_show (button);
193
257
/* add chat button */
194
258
parent->button_action = gtk_button_new_with_mnemonic (_("C_hat"));
195
259
image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE,
197
261
gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
199
263
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
200
GTK_RESPONSE_ACCEPT);
264
EMP_NEW_MESSAGE_TEXT);
201
265
gtk_widget_show (parent->button_action);
267
/* the parent class will update the sensitivity of button_action, propagate
269
g_signal_connect (parent->button_action, "notify::sensitive",
270
G_CALLBACK (empathy_new_message_dialog_update_sms_button_sensitivity),
272
g_signal_connect (dialog, "notify::selected-account",
273
G_CALLBACK (empathy_new_message_dialog_update_sms_button_sensitivity),
203
276
/* Tweak the dialog */
204
277
gtk_window_set_title (GTK_WINDOW (dialog), _("New Conversation"));
205
278
gtk_window_set_role (GTK_WINDOW (dialog), "new_message");