diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-05-05 15:37:40 +0800 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-05-05 15:37:40 +0800 |
commit | 9a1a49ed9ddf5a3d1da99eabca27882705688545 (patch) | |
tree | 5626cc6bb9aa534c4734de4fe76caf82d42f72a4 | |
parent | 77fab8ebc60ce2625c4f449cde6296b25b10b05d (diff) | |
parent | 0fda59487b536e49bfcec7ab1ee6e9c6d7b6f306 (diff) | |
download | gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar.gz gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar.bz2 gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar.lz gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar.xz gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.tar.zst gsoc2013-empathy-9a1a49ed9ddf5a3d1da99eabca27882705688545.zip |
Merge branch 'sms-support-rebase'
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 63 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.h | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contact-selector-dialog.c | 25 | ||||
-rw-r--r-- | libempathy-gtk/empathy-images.h | 1 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-menu.c | 65 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-menu.h | 5 | ||||
-rw-r--r-- | libempathy-gtk/empathy-new-message-dialog.c | 104 | ||||
-rw-r--r-- | libempathy/empathy-contact.c | 21 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 3 | ||||
-rw-r--r-- | libempathy/empathy-request-util.c | 55 | ||||
-rw-r--r-- | libempathy/empathy-request-util.h | 5 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 80 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.h | 2 | ||||
-rw-r--r-- | src/empathy-chat-manager.c | 3 | ||||
-rw-r--r-- | src/empathy-chat-window.c | 60 | ||||
-rw-r--r-- | src/empathy-chat-window.h | 3 |
16 files changed, 444 insertions, 55 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index c146941b3..5c8bbce3b 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -146,6 +146,7 @@ struct _EmpathyChatPriv { * notified again about the already notified pending messages when the * messages in tab will be properly shown */ gboolean retrieving_backlogs; + gboolean sms_channel; }; typedef struct { @@ -170,6 +171,7 @@ enum { PROP_SUBJECT, PROP_REMOTE_CONTACT, PROP_SHOW_CONTACTS, + PROP_SMS_CHANNEL, }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -195,7 +197,7 @@ chat_get_property (GObject *object, g_value_set_object (value, priv->account); break; case PROP_NAME: - g_value_set_string (value, empathy_chat_get_name (chat)); + g_value_take_string (value, empathy_chat_dup_name (chat)); break; case PROP_ID: g_value_set_string (value, priv->id); @@ -209,6 +211,9 @@ chat_get_property (GObject *object, case PROP_SHOW_CONTACTS: g_value_set_boolean (value, priv->show_contacts); break; + case PROP_SMS_CHANNEL: + g_value_set_boolean (value, priv->sms_channel); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -249,8 +254,14 @@ account_reconnected (EmpathyChat *chat, * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */ switch (priv->handle_type) { case TP_HANDLE_TYPE_CONTACT: - empathy_chat_with_contact_id ( - account, priv->id, TP_USER_ACTION_TIME_NOT_USER_ACTION); + if (priv->sms_channel) + empathy_sms_contact_id ( + account, priv->id, + TP_USER_ACTION_TIME_NOT_USER_ACTION); + else + empathy_chat_with_contact_id ( + account, priv->id, + TP_USER_ACTION_TIME_NOT_USER_ACTION); break; case TP_HANDLE_TYPE_ROOM: empathy_join_muc (account, priv->id, @@ -2963,6 +2974,14 @@ empathy_chat_class_init (EmpathyChatClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_SMS_CHANNEL, + g_param_spec_boolean ("sms-channel", + "SMS Channel", + "TRUE if this channel is for sending SMSes", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + signals[COMPOSING] = g_signal_new ("composing", G_OBJECT_CLASS_TYPE (object_class), @@ -3459,6 +3478,15 @@ chat_password_needed_changed_cb (EmpathyChat *self) } } +static void +chat_sms_channel_changed_cb (EmpathyChat *self) +{ + EmpathyChatPriv *priv = GET_PRIV (self); + + priv->sms_channel = empathy_tp_chat_is_sms_channel (priv->tp_chat); + g_object_notify (G_OBJECT (self), "sms-channel"); +} + void empathy_chat_set_tp_chat (EmpathyChat *chat, EmpathyTpChat *tp_chat) @@ -3508,6 +3536,9 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, g_signal_connect_swapped (tp_chat, "notify::password-needed", G_CALLBACK (chat_password_needed_changed_cb), chat); + g_signal_connect_swapped (tp_chat, "notify::sms-channel", + G_CALLBACK (chat_sms_channel_changed_cb), + chat); /* Get initial value of properties */ properties = empathy_tp_chat_get_properties (priv->tp_chat); @@ -3528,6 +3559,7 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, } } + chat_sms_channel_changed_cb (chat); chat_remote_contact_changed_cb (chat); if (chat->input_text_view) { @@ -3570,8 +3602,8 @@ empathy_chat_get_id (EmpathyChat *chat) return priv->id; } -const gchar * -empathy_chat_get_name (EmpathyChat *chat) +gchar * +empathy_chat_dup_name (EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); const gchar *ret; @@ -3579,6 +3611,7 @@ empathy_chat_get_name (EmpathyChat *chat) g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL); ret = priv->name; + if (!ret && priv->remote_contact) { ret = empathy_contact_get_alias (priv->remote_contact); } @@ -3586,7 +3619,15 @@ empathy_chat_get_name (EmpathyChat *chat) if (!ret) ret = priv->id; - return ret ? ret : _("Conversation"); + if (!ret) + ret = _("Conversation"); + + if (priv->sms_channel) + /* Translators: this string is a something like + * "Escher Cat (SMS)" */ + return g_strdup_printf (_("%s (SMS)"), ret); + else + return g_strdup (ret); } const gchar * @@ -3812,3 +3853,13 @@ empathy_chat_is_composing (EmpathyChat *chat) { return chat->priv->compositors != NULL; } + +gboolean +empathy_chat_is_sms_channel (EmpathyChat *self) +{ + EmpathyChatPriv *priv = GET_PRIV (self); + + g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0); + + return priv->sms_channel; +} diff --git a/libempathy-gtk/empathy-chat.h b/libempathy-gtk/empathy-chat.h index 77122f7c8..8da8004ec 100644 --- a/libempathy-gtk/empathy-chat.h +++ b/libempathy-gtk/empathy-chat.h @@ -69,7 +69,7 @@ void empathy_chat_set_tp_chat (EmpathyChat *chat, EmpathyTpChat *tp_chat); TpAccount * empathy_chat_get_account (EmpathyChat *chat); const gchar * empathy_chat_get_id (EmpathyChat *chat); -const gchar * empathy_chat_get_name (EmpathyChat *chat); +gchar * empathy_chat_dup_name (EmpathyChat *chat); const gchar * empathy_chat_get_subject (EmpathyChat *chat); EmpathyContact * empathy_chat_get_remote_contact (EmpathyChat *chat); GtkWidget * empathy_chat_get_contact_menu (EmpathyChat *chat); @@ -94,6 +94,8 @@ guint empathy_chat_get_nb_unread_messages (EmpathyChat *chat); void empathy_chat_messages_read (EmpathyChat *self); gboolean empathy_chat_is_composing (EmpathyChat *chat); + +gboolean empathy_chat_is_sms_channel (EmpathyChat *self); G_END_DECLS #endif /* __EMPATHY_CHAT_H__ */ diff --git a/libempathy-gtk/empathy-contact-selector-dialog.c b/libempathy-gtk/empathy-contact-selector-dialog.c index d5e533aeb..a4747b488 100644 --- a/libempathy-gtk/empathy-contact-selector-dialog.c +++ b/libempathy-gtk/empathy-contact-selector-dialog.c @@ -66,7 +66,8 @@ struct _EmpathyContactSelectorDialogPriv { enum { PROP_0, PROP_SHOW_ACCOUNT_CHOOSER, - PROP_FILTER_ACCOUNT + PROP_FILTER_ACCOUNT, + PROP_SELECTED_ACCOUNT }; enum { @@ -151,6 +152,8 @@ contact_selector_dialog_account_changed_cb (GtkWidget *widget, g_object_unref (contact); members = g_list_delete_link (members, members); } + + g_object_notify (G_OBJECT (dialog), "selected-account"); } static gboolean @@ -375,6 +378,7 @@ empathy_contact_selector_dialog_get_property (GObject *self, GParamSpec *pspec) { EmpathyContactSelectorDialog *dialog = EMPATHY_CONTACT_SELECTOR_DIALOG (self); + EmpathyContactSelectorDialogPriv *priv = GET_PRIV (dialog); switch (prop_id) { @@ -388,6 +392,11 @@ empathy_contact_selector_dialog_get_property (GObject *self, empathy_contact_selector_dialog_get_filter_account (dialog)); break; + case PROP_SELECTED_ACCOUNT: + g_value_set_object (value, empathy_account_chooser_get_account ( + EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser))); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec); break; @@ -401,6 +410,7 @@ empathy_contact_selector_dialog_set_property (GObject *self, GParamSpec *pspec) { EmpathyContactSelectorDialog *dialog = EMPATHY_CONTACT_SELECTOR_DIALOG (self); + EmpathyContactSelectorDialogPriv *priv = GET_PRIV (dialog); switch (prop_id) { @@ -414,6 +424,12 @@ empathy_contact_selector_dialog_set_property (GObject *self, g_value_get_object (value)); break; + case PROP_SELECTED_ACCOUNT: + empathy_account_chooser_set_account ( + EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser), + g_value_get_object (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec); break; @@ -490,6 +506,13 @@ empathy_contact_selector_dialog_class_init ( "account are displayed", TP_TYPE_ACCOUNT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_SELECTED_ACCOUNT, + g_param_spec_object ("selected-account", + "Selected Account", + "Current account selected in the account-chooser", + TP_TYPE_ACCOUNT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } const gchar * diff --git a/libempathy-gtk/empathy-images.h b/libempathy-gtk/empathy-images.h index 2c40b2ae7..86f1db641 100644 --- a/libempathy-gtk/empathy-images.h +++ b/libempathy-gtk/empathy-images.h @@ -40,6 +40,7 @@ G_BEGIN_DECLS #define EMPATHY_IMAGE_TYPING "user-typing" #define EMPATHY_IMAGE_CONTACT_INFORMATION "gtk-info" #define EMPATHY_IMAGE_GROUP_MESSAGE "system-users" +#define EMPATHY_IMAGE_SMS "stock_cell-phone" #define EMPATHY_IMAGE_VOIP "audio-input-microphone" #define EMPATHY_IMAGE_VIDEO_CALL "camera-web" #define EMPATHY_IMAGE_LOG "document-open-recent" diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c index 3e404c39f..576d3b9fa 100644 --- a/libempathy-gtk/empathy-individual-menu.c +++ b/libempathy-gtk/empathy-individual-menu.c @@ -149,6 +149,14 @@ individual_menu_add_personas (GtkMenuShell *menu, gtk_widget_show (action); } + /* SMS */ + if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS) + { + action = empathy_individual_sms_menu_item_new (NULL, contact); + gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action); + gtk_widget_show (action); + } + if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL) { /* Audio Call */ @@ -238,6 +246,17 @@ constructed (GObject *object) } } + /* SMS */ + if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS) + { + item = empathy_individual_sms_menu_item_new (individual, NULL); + if (item != NULL) + { + gtk_menu_shell_append (shell, item); + gtk_widget_show (item); + } + } + if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL) { /* Audio Call */ @@ -537,6 +556,52 @@ empathy_individual_chat_menu_item_new (FolksIndividual *individual, } static void +empathy_individual_sms_menu_item_activated (GtkMenuItem *item, + EmpathyContact *contact) +{ + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + empathy_sms_contact_id ( + empathy_contact_get_account (contact), + empathy_contact_get_id (contact), + gtk_get_current_event_time ()); +} + +GtkWidget * +empathy_individual_sms_menu_item_new (FolksIndividual *individual, + EmpathyContact *contact) +{ + GtkWidget *item; + GtkWidget *image; + + g_return_val_if_fail ((FOLKS_IS_INDIVIDUAL (individual) && + empathy_folks_individual_contains_contact (individual)) || + EMPATHY_IS_CONTACT (contact), + NULL); + + item = gtk_image_menu_item_new_with_mnemonic (_("_SMS")); + image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + gtk_widget_show (image); + + if (contact != NULL) + { + menu_item_set_contact (item, contact, + G_CALLBACK (empathy_individual_sms_menu_item_activated), + EMPATHY_ACTION_SMS); + } + else + { + menu_item_set_first_contact (item, individual, + G_CALLBACK (empathy_individual_sms_menu_item_activated), + EMPATHY_ACTION_SMS); + } + + return item; +} + +static void empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item, EmpathyContact *contact) { diff --git a/libempathy-gtk/empathy-individual-menu.h b/libempathy-gtk/empathy-individual-menu.h index 5b3d220df..c2841ad6d 100644 --- a/libempathy-gtk/empathy-individual-menu.h +++ b/libempathy-gtk/empathy-individual-menu.h @@ -36,7 +36,8 @@ typedef enum { EMPATHY_INDIVIDUAL_FEATURE_INFO = 1 << 4, EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE = 1 << 5, EMPATHY_INDIVIDUAL_FEATURE_LINK = 1 << 6, - EMPATHY_INDIVIDUAL_FEATURE_ALL = (1 << 7) - 1, + EMPATHY_INDIVIDUAL_FEATURE_SMS = 1 << 7, + EMPATHY_INDIVIDUAL_FEATURE_ALL = (1 << 8) - 1, } EmpathyIndividualFeatureFlags; #define EMPATHY_TYPE_INDIVIDUAL_MENU (empathy_individual_menu_get_type ()) @@ -69,6 +70,8 @@ GtkWidget * empathy_individual_menu_new (FolksIndividual *individual, EmpathyIndividualFeatureFlags features); GtkWidget * empathy_individual_chat_menu_item_new (FolksIndividual *individual, EmpathyContact *contact); +GtkWidget * empathy_individual_sms_menu_item_new (FolksIndividual *individual, + EmpathyContact *contact); GtkWidget * empathy_individual_audio_call_menu_item_new ( FolksIndividual *individual, EmpathyContact *contact); diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c index b9edb93e7..3d811abbb 100644 --- a/libempathy-gtk/empathy-new-message-dialog.c +++ b/libempathy-gtk/empathy-new-message-dialog.c @@ -62,21 +62,40 @@ G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog, * to be started with any contact on any enabled account. */ +enum +{ + EMP_NEW_MESSAGE_TEXT, + EMP_NEW_MESSAGE_SMS, +}; + static void empathy_new_message_dialog_response (GtkDialog *dialog, int response_id) { TpAccount *account; const gchar *contact_id; - if (response_id != GTK_RESPONSE_ACCEPT) goto out; + if (response_id < EMP_NEW_MESSAGE_TEXT) goto out; contact_id = empathy_contact_selector_dialog_get_selected ( EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, &account); if (EMP_STR_EMPTY (contact_id) || account == NULL) goto out; - empathy_chat_with_contact_id (account, contact_id, - gtk_get_current_event_time ()); + switch (response_id) + { + case EMP_NEW_MESSAGE_TEXT: + empathy_chat_with_contact_id (account, contact_id, + gtk_get_current_event_time ()); + break; + + case EMP_NEW_MESSAGE_SMS: + empathy_sms_contact_id (account, contact_id, + gtk_get_current_event_time ()); + break; + + default: + g_warn_if_reached (); + } out: gtk_widget_destroy (GTK_WIDGET (dialog)); @@ -135,6 +154,63 @@ empathy_new_message_account_filter (EmpathyContactSelectorDialog *dialog, tp_proxy_prepare_async (connection, features, conn_prepared_cb, cb_data); } +static void +empathy_new_message_dialog_update_sms_button_sensitivity (GtkWidget *widget, + GParamSpec *pspec, + GtkWidget *button) +{ + GtkWidget *self = gtk_widget_get_toplevel (widget); + EmpathyContactSelectorDialog *dialog; + TpConnection *conn; + GPtrArray *rccs; + gboolean sensitive = FALSE; + guint i; + + g_return_if_fail (EMPATHY_IS_NEW_MESSAGE_DIALOG (self)); + + dialog = EMPATHY_CONTACT_SELECTOR_DIALOG (self); + + /* if the Text widget isn't sensitive, don't bother checking the caps */ + if (!gtk_widget_get_sensitive (dialog->button_action)) + goto finally; + + empathy_contact_selector_dialog_get_selected (dialog, &conn, NULL); + + if (conn == NULL) + goto finally; + + /* iterate the rccs to find if SMS channels are supported, this should + * be in tp-glib */ + rccs = tp_capabilities_get_channel_classes ( + tp_connection_get_capabilities (conn)); + + for (i = 0; i < rccs->len; i++) + { + GHashTable *fixed; + GStrv allowed; + const char *type; + gboolean sms_channel; + + tp_value_array_unpack (g_ptr_array_index (rccs, i), 2, + &fixed, + &allowed); + + /* SMS channels are type:Text and sms-channel:True */ + type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE); + sms_channel = tp_asv_get_boolean (fixed, + TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, NULL); + + sensitive = sms_channel && + !tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_TEXT); + + if (sensitive) + break; + } + +finally: + gtk_widget_set_sensitive (button, sensitive); +} + static GObject * empathy_new_message_dialog_constructor (GType type, guint n_props, @@ -165,8 +241,19 @@ empathy_new_message_dialog_init (EmpathyNewMessageDialog *dialog) { EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG ( dialog); + GtkWidget *button; GtkWidget *image; + /* add an SMS button */ + button = gtk_button_new_with_mnemonic (_("_SMS")); + image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS, + GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), image); + + gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, + EMP_NEW_MESSAGE_SMS); + gtk_widget_show (button); + /* add chat button */ parent->button_action = gtk_button_new_with_mnemonic (_("C_hat")); image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE, @@ -174,9 +261,18 @@ empathy_new_message_dialog_init (EmpathyNewMessageDialog *dialog) gtk_button_set_image (GTK_BUTTON (parent->button_action), image); gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action, - GTK_RESPONSE_ACCEPT); + EMP_NEW_MESSAGE_TEXT); gtk_widget_show (parent->button_action); + /* the parent class will update the sensitivity of button_action, propagate + * it */ + g_signal_connect (parent->button_action, "notify::sensitive", + G_CALLBACK (empathy_new_message_dialog_update_sms_button_sensitivity), + button); + g_signal_connect (dialog, "notify::selected-account", + G_CALLBACK (empathy_new_message_dialog_update_sms_button_sensitivity), + button); + /* Tweak the dialog */ gtk_window_set_title (GTK_WINDOW (dialog), _("New Conversation")); gtk_window_set_role (GTK_WINDOW (dialog), "new_message"); diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 680094a54..620c479e2 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -1098,6 +1098,18 @@ empathy_contact_get_status (EmpathyContact *contact) } gboolean +empathy_contact_can_sms (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + + priv = GET_PRIV (contact); + + return priv->capabilities & EMPATHY_CAPABILITIES_SMS; +} + +gboolean empathy_contact_can_voip (EmpathyContact *contact) { EmpathyContactPriv *priv; @@ -1189,6 +1201,9 @@ empathy_contact_can_do_action (EmpathyContact *self, case EMPATHY_ACTION_CHAT: sensitivity = TRUE; break; + case EMPATHY_ACTION_SMS: + sensitivity = empathy_contact_can_sms (self); + break; case EMPATHY_ACTION_AUDIO_CALL: sensitivity = empathy_contact_can_voip_audio (self); break; @@ -1729,6 +1744,12 @@ tp_caps_to_capabilities (TpCapabilities *caps) TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, NULL)) capabilities |= EMPATHY_CAPABILITIES_VIDEO; } + else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT)) + { + if (tp_asv_get_boolean (fixed_prop, + TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, NULL)) + capabilities |= EMPATHY_CAPABILITIES_SMS; + } } return capabilities; diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h index f9217c108..16b50e500 100644 --- a/libempathy/empathy-contact.h +++ b/libempathy/empathy-contact.h @@ -67,6 +67,7 @@ typedef enum { EMPATHY_CAPABILITIES_VIDEO = 1 << 1, EMPATHY_CAPABILITIES_FT = 1 << 2, EMPATHY_CAPABILITIES_RFB_STREAM_TUBE = 1 << 3, + EMPATHY_CAPABILITIES_SMS = 1 << 4, EMPATHY_CAPABILITIES_UNKNOWN = 1 << 7 } EmpathyCapabilities; @@ -94,6 +95,7 @@ void empathy_contact_set_is_user (EmpathyContact *contact, gboolean is_user); gboolean empathy_contact_is_online (EmpathyContact *contact); const gchar * empathy_contact_get_status (EmpathyContact *contact); +gboolean empathy_contact_can_sms (EmpathyContact *contact); gboolean empathy_contact_can_voip (EmpathyContact *contact); gboolean empathy_contact_can_voip_audio (EmpathyContact *contact); gboolean empathy_contact_can_voip_video (EmpathyContact *contact); @@ -102,6 +104,7 @@ gboolean empathy_contact_can_use_rfb_stream_tube (EmpathyContact *contact); typedef enum { EMPATHY_ACTION_CHAT, + EMPATHY_ACTION_SMS, EMPATHY_ACTION_AUDIO_CALL, EMPATHY_ACTION_VIDEO_CALL, EMPATHY_ACTION_VIEW_LOGS, diff --git a/libempathy/empathy-request-util.c b/libempathy/empathy-request-util.c index ea885dacc..6472230ab 100644 --- a/libempathy/empathy-request-util.c +++ b/libempathy/empathy-request-util.c @@ -58,9 +58,11 @@ ensure_text_channel_cb (GObject *source, } } -void -empathy_chat_with_contact_id (TpAccount *account, - const gchar *contact_id, +static void +create_text_channel (TpAccount *account, + TpHandleType target_handle_type, + const gchar *target_id, + gboolean sms_channel, gint64 timestamp) { GHashTable *request; @@ -69,39 +71,46 @@ empathy_chat_with_contact_id (TpAccount *account, request = tp_asv_new ( TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, - TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, target_handle_type, + TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, target_id, NULL); + if (sms_channel) + tp_asv_set_boolean (request, + TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, TRUE); + req = tp_account_channel_request_new (account, request, timestamp); - tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME, - NULL, ensure_text_channel_cb, NULL); + tp_account_channel_request_ensure_channel_async (req, NULL, NULL, + ensure_text_channel_cb, NULL); g_hash_table_unref (request); g_object_unref (req); } void +empathy_chat_with_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp) +{ + create_text_channel (account, TP_HANDLE_TYPE_CONTACT, + contact_id, FALSE, timestamp); +} + +void empathy_join_muc (TpAccount *account, const gchar *room_name, gint64 timestamp) { - GHashTable *request; - TpAccountChannelRequest *req; - - request = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM, - TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, room_name, - NULL); - - req = tp_account_channel_request_new (account, request, timestamp); - - tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME, - NULL, ensure_text_channel_cb, NULL); + create_text_channel (account, TP_HANDLE_TYPE_ROOM, + room_name, FALSE, timestamp); +} - g_hash_table_unref (request); - g_object_unref (req); +void +empathy_sms_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp) +{ + create_text_channel (account, TP_HANDLE_TYPE_CONTACT, + contact_id, TRUE, timestamp); } diff --git a/libempathy/empathy-request-util.h b/libempathy/empathy-request-util.h index afb8013cb..49b98a433 100644 --- a/libempathy/empathy-request-util.h +++ b/libempathy/empathy-request-util.h @@ -52,6 +52,11 @@ void empathy_join_muc (TpAccount *account, const gchar *roomname, gint64 timestamp); +/* Request a sms channel */ +void empathy_sms_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp); + G_END_DECLS #endif /* __EMPATHY_DISPATCHER_H__ */ diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index a56c08a32..b8e4cdf0c 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -59,6 +59,8 @@ typedef struct { gboolean got_password_flags; gboolean ready; gboolean can_upgrade_to_muc; + gboolean got_sms_channel; + gboolean sms_channel; } EmpathyTpChatPriv; static void tp_chat_iface_init (EmpathyContactListIface *iface); @@ -70,6 +72,7 @@ enum { PROP_REMOTE_CONTACT, PROP_PASSWORD_NEEDED, PROP_READY, + PROP_SMS_CHANNEL, }; enum { @@ -827,6 +830,9 @@ check_almost_ready (EmpathyTpChat *chat) if (!priv->got_password_flags) return; + if (!priv->got_sms_channel) + return; + /* We need either the members (room) or the remote contact (private chat). * If the chat is protected by a password we can't get these information so * consider the chat as ready so it can be presented to the user. */ @@ -1218,6 +1224,41 @@ got_password_flags_cb (TpChannel *proxy, check_almost_ready (EMPATHY_TP_CHAT (self)); } +static void +sms_channel_changed_cb (TpChannel *channel, + gboolean sms_channel, + gpointer user_data, + GObject *chat) +{ + EmpathyTpChatPriv *priv = GET_PRIV (chat); + + priv->sms_channel = sms_channel; + + g_object_notify (G_OBJECT (chat), "sms-channel"); +} + +static void +get_sms_channel_cb (TpProxy *channel, + const GValue *value, + const GError *in_error, + gpointer user_data, + GObject *chat) +{ + EmpathyTpChatPriv *priv = GET_PRIV (chat); + + if (in_error != NULL) { + DEBUG ("Failed to get SMSChannel: %s", in_error->message); + return; + } + + g_return_if_fail (G_VALUE_HOLDS_BOOLEAN (value)); + + priv->sms_channel = g_value_get_boolean (value); + priv->got_sms_channel = TRUE; + + check_almost_ready (EMPATHY_TP_CHAT (chat)); +} + static GObject * tp_chat_constructor (GType type, guint n_props, @@ -1327,6 +1368,22 @@ tp_chat_constructor (GType type, priv->got_password_flags = TRUE; } + /* Check if the chat is for SMS */ + if (tp_proxy_has_interface_by_id (priv->channel, + TP_IFACE_QUARK_CHANNEL_INTERFACE_SMS)) { + tp_cli_channel_interface_sms_connect_to_sms_channel_changed ( + priv->channel, + sms_channel_changed_cb, chat, NULL, G_OBJECT (chat), + NULL); + + tp_cli_dbus_properties_call_get (priv->channel, -1, + TP_IFACE_CHANNEL_INTERFACE_SMS, "SMSChannel", + get_sms_channel_cb, chat, NULL, G_OBJECT (chat)); + } else { + /* if there's no SMS support, then we're not waiting for it */ + priv->got_sms_channel = TRUE; + } + return chat; } @@ -1355,6 +1412,9 @@ tp_chat_get_property (GObject *object, case PROP_PASSWORD_NEEDED: g_value_set_boolean (value, empathy_tp_chat_password_needed (self)); break; + case PROP_SMS_CHANNEL: + g_value_set_boolean (value, priv->sms_channel); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -1436,6 +1496,14 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) FALSE, G_PARAM_READABLE)); + g_object_class_install_property (object_class, + PROP_SMS_CHANNEL, + g_param_spec_boolean ("sms-channel", + "SMS Channel", + "TRUE if channel is for sending SMSes", + FALSE, + G_PARAM_READABLE)); + /* Signals */ signals[MESSAGE_RECEIVED] = g_signal_new ("message-received", @@ -1909,3 +1977,15 @@ empathy_tp_chat_get_self_contact (EmpathyTpChat *self) return priv->user; } + +gboolean +empathy_tp_chat_is_sms_channel (EmpathyTpChat *self) +{ + EmpathyTpChatPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), FALSE); + + priv = GET_PRIV (self); + + return priv->sms_channel; +} diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index 7c998a3fa..7ac1296e0 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -112,6 +112,8 @@ TpChannelChatState EmpathyContact * empathy_tp_chat_get_self_contact (EmpathyTpChat *self); +gboolean empathy_tp_chat_is_sms_channel (EmpathyTpChat *chat); + G_END_DECLS #endif /* __EMPATHY_TP_CHAT_H__ */ diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c index 9c2a17891..a90c2d08c 100644 --- a/src/empathy-chat-manager.c +++ b/src/empathy-chat-manager.c @@ -128,7 +128,8 @@ process_tp_chat (EmpathyChatManager *self, id = empathy_tp_chat_get_id (tp_chat); if (!tp_str_empty (id)) { - chat = empathy_chat_window_find_chat (account, id); + chat = empathy_chat_window_find_chat (account, id, + empathy_tp_chat_is_sms_channel (tp_chat)); } if (chat != NULL) diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index ee4f445e5..7faeb2793 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -453,14 +453,14 @@ get_all_unread_messages (EmpathyChatWindowPriv *priv) static gchar * get_window_title_name (EmpathyChatWindowPriv *priv) { - const gchar *active_name; + gchar *active_name, *ret; guint nb_chats; guint current_unread_msgs; nb_chats = g_list_length (priv->chats); g_assert (nb_chats > 0); - active_name = empathy_chat_get_name (priv->current_chat); + active_name = empathy_chat_dup_name (priv->current_chat); current_unread_msgs = empathy_chat_get_nb_unread_messages ( priv->current_chat); @@ -468,9 +468,9 @@ get_window_title_name (EmpathyChatWindowPriv *priv) if (nb_chats == 1) { /* only one tab */ if (current_unread_msgs == 0) - return g_strdup (active_name); + ret = g_strdup (active_name); else - return g_strdup_printf (ngettext ( + ret = g_strdup_printf (ngettext ( "%s (%d unread)", "%s (%d unread)", current_unread_msgs), active_name, current_unread_msgs); @@ -482,7 +482,7 @@ get_window_title_name (EmpathyChatWindowPriv *priv) if (all_unread_msgs == 0) { /* no unread message */ - return g_strdup_printf (ngettext ( + ret = g_strdup_printf (ngettext ( "%s (and %u other)", "%s (and %u others)", nb_others), active_name, nb_others); @@ -490,7 +490,7 @@ get_window_title_name (EmpathyChatWindowPriv *priv) else if (all_unread_msgs == current_unread_msgs) { /* unread messages are in the current tab */ - return g_strdup_printf (ngettext ( + ret = g_strdup_printf (ngettext ( "%s (%d unread)", "%s (%d unread)", current_unread_msgs), active_name, current_unread_msgs); @@ -498,7 +498,7 @@ get_window_title_name (EmpathyChatWindowPriv *priv) else if (current_unread_msgs == 0) { /* unread messages are in other tabs */ - return g_strdup_printf (ngettext ( + ret = g_strdup_printf (ngettext ( "%s (%d unread from others)", "%s (%d unread from others)", all_unread_msgs), @@ -507,13 +507,17 @@ get_window_title_name (EmpathyChatWindowPriv *priv) else { /* unread messages are in all the tabs */ - return g_strdup_printf (ngettext ( + ret = g_strdup_printf (ngettext ( "%s (%d unread from all)", "%s (%d unread from all)", all_unread_msgs), active_name, all_unread_msgs); } } + + g_free (active_name); + + return ret; } static void @@ -637,7 +641,7 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, EmpathyChatWindow *window; EmpathyChatWindowPriv *priv; EmpathyContact *remote_contact; - const gchar *name; + gchar *name; const gchar *id; TpAccount *account; const gchar *subject; @@ -656,7 +660,7 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, priv = GET_PRIV (window); /* Get information */ - name = empathy_chat_get_name (chat); + name = empathy_chat_dup_name (chat); account = empathy_chat_get_account (chat); subject = empathy_chat_get_subject (chat); remote_contact = empathy_chat_get_remote_contact (chat); @@ -675,6 +679,9 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, else if (remote_contact && empathy_chat_is_composing (chat)) { icon_name = EMPATHY_IMAGE_TYPING; } + else if (empathy_chat_is_sms_channel (chat)) { + icon_name = EMPATHY_IMAGE_SMS; + } else if (remote_contact) { icon_name = empathy_icon_name_for_contact (remote_contact); } else { @@ -703,6 +710,10 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, id = name; } + if (empathy_chat_is_sms_channel (chat)) { + append_markup_printf (tooltip, "%s ", _("SMS:")); + } + append_markup_printf (tooltip, "<b>%s</b><small> (%s)</small>", id, @@ -738,6 +749,8 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, if (priv->current_chat == chat) { chat_window_update (window, update_contact_menu); } + + g_free (name); } static void @@ -865,21 +878,24 @@ chat_window_favorite_toggled_cb (GtkToggleAction *toggle_action, EmpathyChatWindowPriv *priv = GET_PRIV (window); gboolean active; TpAccount *account; + gchar *name; const gchar *room; EmpathyChatroom *chatroom; active = gtk_toggle_action_get_active (toggle_action); account = empathy_chat_get_account (priv->current_chat); room = empathy_chat_get_id (priv->current_chat); + name = empathy_chat_dup_name (priv->current_chat); chatroom = empathy_chatroom_manager_ensure_chatroom ( priv->chatroom_manager, account, room, - empathy_chat_get_name (priv->current_chat)); + name); empathy_chatroom_set_favorite (chatroom, active); g_object_unref (chatroom); + g_free (name); } static void @@ -889,21 +905,24 @@ chat_window_always_urgent_toggled_cb (GtkToggleAction *toggle_action, EmpathyChatWindowPriv *priv = GET_PRIV (window); gboolean active; TpAccount *account; + gchar *name; const gchar *room; EmpathyChatroom *chatroom; active = gtk_toggle_action_get_active (toggle_action); account = empathy_chat_get_account (priv->current_chat); room = empathy_chat_get_id (priv->current_chat); + name = empathy_chat_dup_name (priv->current_chat); chatroom = empathy_chatroom_manager_ensure_chatroom ( priv->chatroom_manager, account, room, - empathy_chat_get_name (priv->current_chat)); + name); empathy_chatroom_set_always_urgent (chatroom, active); g_object_unref (chatroom); + g_free (name); } static void @@ -1357,15 +1376,16 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window, static void chat_window_set_highlight_room_labels (EmpathyChat *chat) { - gchar *markup; + gchar *markup, *name; GtkWidget *widget; if (!empathy_chat_is_room (chat)) return; + name = empathy_chat_dup_name (chat); markup = g_markup_printf_escaped ( "<span color=\"red\" weight=\"bold\">%s</span>", - empathy_chat_get_name (chat)); + name); widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label"); gtk_label_set_markup (GTK_LABEL (widget), markup); @@ -1373,6 +1393,7 @@ chat_window_set_highlight_room_labels (EmpathyChat *chat) widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-label"); gtk_label_set_markup (GTK_LABEL (widget), markup); + g_free (name); g_free (markup); } @@ -1766,7 +1787,7 @@ chat_window_drag_data_received (GtkWidget *widget, account = tp_account_manager_ensure_account (account_manager, account_id); if (account != NULL) - chat = empathy_chat_window_find_chat (account, contact_id); + chat = empathy_chat_window_find_chat (account, contact_id, FALSE); } if (account == NULL) { @@ -2228,6 +2249,9 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window, g_signal_connect (chat, "notify::remote-contact", G_CALLBACK (chat_window_chat_notify_cb), NULL); + g_signal_connect (chat, "notify::sms-channel", + G_CALLBACK (chat_window_chat_notify_cb), + NULL); chat_window_chat_notify_cb (chat); gtk_notebook_append_page_menu (GTK_NOTEBOOK (priv->notebook), child, label, popup_label); @@ -2331,7 +2355,8 @@ empathy_chat_window_switch_to_chat (EmpathyChatWindow *window, EmpathyChat * empathy_chat_window_find_chat (TpAccount *account, - const gchar *id) + const gchar *id, + gboolean sms_channel) { GList *l; @@ -2351,7 +2376,8 @@ empathy_chat_window_find_chat (TpAccount *account, chat = ll->data; if (account == empathy_chat_get_account (chat) && - !tp_strdiff (id, empathy_chat_get_id (chat))) { + !tp_strdiff (id, empathy_chat_get_id (chat)) && + sms_channel == empathy_chat_is_sms_channel (chat)) { return chat; } } diff --git a/src/empathy-chat-window.h b/src/empathy-chat-window.h index 5477479ac..2112b6647 100644 --- a/src/empathy-chat-window.h +++ b/src/empathy-chat-window.h @@ -59,7 +59,8 @@ struct _EmpathyChatWindowClass { GType empathy_chat_window_get_type (void); EmpathyChat * empathy_chat_window_find_chat (TpAccount *account, - const gchar *id); + const gchar *id, + gboolean sms_channel); void empathy_chat_window_present_chat (EmpathyChat *chat, gint64 timestamp); |