diff options
author | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-04-08 23:30:34 +0800 |
---|---|---|
committer | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-04-08 23:30:34 +0800 |
commit | 14c784281eca531135cc07009fb6d4a463d04ac2 (patch) | |
tree | 0c796b27db8a6408f919e338dbddf2b26da833c9 | |
parent | 415e3772e7108b6dff7d3b89eef01d5b8cc61a47 (diff) | |
parent | e702ff444130b055249fde571d6532931a31e47e (diff) | |
download | gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar.gz gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar.bz2 gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar.lz gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar.xz gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.tar.zst gsoc2013-empathy-14c784281eca531135cc07009fb6d4a463d04ac2.zip |
Merge remote-tracking branch 'danni-public/sms-support' into empathy-skype
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 63 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.h | 3 | ||||
-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/empathy-contact.c | 21 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 3 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.c | 51 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.h | 5 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 89 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.h | 3 | ||||
-rw-r--r-- | src/empathy-chat-manager.c | 10 | ||||
-rw-r--r-- | src/empathy-chat-window.c | 89 | ||||
-rw-r--r-- | src/empathy-chat-window.h | 3 |
14 files changed, 359 insertions, 52 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index e6eca0906..e25c8ff6f 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -144,6 +144,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 { @@ -168,6 +169,7 @@ enum { PROP_SUBJECT, PROP_REMOTE_CONTACT, PROP_SHOW_CONTACTS, + PROP_SMS_CHANNEL, }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -191,7 +193,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); @@ -205,6 +207,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; @@ -245,8 +250,14 @@ account_reconnected (EmpathyChat *chat, * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */ switch (priv->handle_type) { case TP_HANDLE_TYPE_CONTACT: - empathy_dispatcher_chat_with_contact_id ( - account, priv->id, TP_USER_ACTION_TIME_NOT_USER_ACTION); + if (priv->sms_channel) + empathy_dispatcher_sms_contact_id ( + account, priv->id, + TP_USER_ACTION_TIME_NOT_USER_ACTION); + else + empathy_dispatcher_chat_with_contact_id ( + account, priv->id, + TP_USER_ACTION_TIME_NOT_USER_ACTION); break; case TP_HANDLE_TYPE_ROOM: empathy_dispatcher_join_muc (account, priv->id, @@ -2762,6 +2773,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), @@ -3029,6 +3048,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) @@ -3080,6 +3108,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); @@ -3100,6 +3131,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) { @@ -3142,8 +3174,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; @@ -3151,6 +3183,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); } @@ -3158,7 +3191,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 * @@ -3356,3 +3397,13 @@ empathy_chat_messages_read (EmpathyChat *self) } priv->unread_messages = 0; } + +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 596b83f5d..08472400e 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); @@ -89,6 +89,7 @@ void empathy_chat_set_show_contacts (EmpathyChat *chat, guint empathy_chat_get_nb_unread_messages (EmpathyChat *chat); void empathy_chat_messages_read (EmpathyChat *self); +gboolean empathy_chat_is_sms_channel (EmpathyChat *self); G_END_DECLS #endif /* __EMPATHY_CHAT_H__ */ 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 4f4a7e20c..1f01d8d54 100644 --- a/libempathy-gtk/empathy-individual-menu.c +++ b/libempathy-gtk/empathy-individual-menu.c @@ -150,6 +150,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 */ @@ -239,6 +247,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 */ @@ -538,6 +557,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_dispatcher_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/empathy-contact.c b/libempathy/empathy-contact.c index 3706658fa..a9503e14a 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -1075,6 +1075,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; @@ -1166,6 +1178,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; @@ -1697,6 +1712,12 @@ tp_caps_to_capabilities (TpCapabilities *caps) 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 005cf1e7a..1eb493e84 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-dispatcher.c b/libempathy/empathy-dispatcher.c index 2a009b34a..b1cc1d267 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -509,9 +509,11 @@ ensure_text_channel_cb (GObject *source, } } -void -empathy_dispatcher_chat_with_contact_id (TpAccount *account, - const gchar *contact_id, +static void +empathy_dispatcher_create_text_channel (TpAccount *account, + TpHandleType target_handle_type, + const gchar *target_id, + gboolean sms_channel, gint64 timestamp) { GHashTable *request; @@ -520,10 +522,14 @@ empathy_dispatcher_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, NULL, NULL, @@ -534,27 +540,30 @@ empathy_dispatcher_chat_with_contact_id (TpAccount *account, } void +empathy_dispatcher_chat_with_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp) +{ + empathy_dispatcher_create_text_channel (account, TP_HANDLE_TYPE_CONTACT, + contact_id, FALSE, timestamp); +} + +void empathy_dispatcher_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, NULL, NULL, - ensure_text_channel_cb, NULL); + empathy_dispatcher_create_text_channel (account, TP_HANDLE_TYPE_ROOM, + room_name, FALSE, timestamp); +} - g_hash_table_unref (request); - g_object_unref (req); +void +empathy_dispatcher_sms_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp) +{ + empathy_dispatcher_create_text_channel (account, TP_HANDLE_TYPE_CONTACT, + contact_id, TRUE, timestamp); } static gboolean diff --git a/libempathy/empathy-dispatcher.h b/libempathy/empathy-dispatcher.h index cd54fa5d1..19da9dde5 100644 --- a/libempathy/empathy-dispatcher.h +++ b/libempathy/empathy-dispatcher.h @@ -70,6 +70,11 @@ void empathy_dispatcher_join_muc (TpAccount *account, const gchar *roomname, gint64 timestamp); +void +empathy_dispatcher_sms_contact_id (TpAccount *account, + const gchar *contact_id, + gint64 timestamp); + void empathy_dispatcher_find_requestable_channel_classes_async (EmpathyDispatcher *dispatcher, TpConnection *connection, const gchar *channel_type, guint handle_type, diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 462f8a77b..7f1a0dd43 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -60,6 +60,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); @@ -71,6 +73,7 @@ enum { PROP_REMOTE_CONTACT, PROP_PASSWORD_NEEDED, PROP_READY, + PROP_SMS_CHANNEL, }; enum { @@ -854,6 +857,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. */ @@ -1255,6 +1261,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, @@ -1363,6 +1404,19 @@ 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)); + } + return chat; } @@ -1391,6 +1445,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; @@ -1472,6 +1529,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", @@ -1960,3 +2025,27 @@ empathy_tp_chat_is_invited (EmpathyTpChat *self, return tp_channel_group_get_local_pending_info (priv->channel, self_handle, inviter, NULL, NULL); } + +const char * +empathy_tp_chat_get_channel_path (EmpathyTpChat *self) +{ + EmpathyTpChatPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL); + + priv = GET_PRIV (self); + + return tp_proxy_get_object_path (priv->channel); +} + +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 8858f4971..a71c81c7e 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -106,6 +106,9 @@ void empathy_tp_chat_join (EmpathyTpChat *chat); gboolean empathy_tp_chat_is_invited (EmpathyTpChat *chat, TpHandle *inviter); +const char * empathy_tp_chat_get_channel_path (EmpathyTpChat *chat); +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 cfa38ec84..4ff6b7d30 100644 --- a/src/empathy-chat-manager.c +++ b/src/empathy-chat-manager.c @@ -119,18 +119,16 @@ process_tp_chat (EmpathyTpChat *tp_chat, gint64 user_action_time) { EmpathyChat *chat = NULL; - const gchar *id; + const char *channel_path; tell_chatroom_manager_if_needed (account, tp_chat); - id = empathy_tp_chat_get_id (tp_chat); - if (!tp_str_empty (id)) - { - chat = empathy_chat_window_find_chat (account, id); - } + channel_path = empathy_tp_chat_get_channel_path (tp_chat); + chat = empathy_chat_window_find_chat_by_channel (channel_path); if (chat != NULL) { + DEBUG ("found chat %p for path %s", chat, channel_path); empathy_chat_set_tp_chat (chat, tp_chat); } else diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index cb9de9b5b..aa7a1a152 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -146,6 +146,8 @@ static const GtkTargetEntry drag_types_dest_file[] = { static void chat_window_update (EmpathyChatWindow *window, gboolean update_contact_menu); +static EmpathyChat *empathy_chat_window_find_chat (TpAccount *account, + const gchar *id); G_DEFINE_TYPE (EmpathyChatWindow, empathy_chat_window, G_TYPE_OBJECT); @@ -442,14 +444,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); @@ -457,9 +459,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); @@ -471,7 +473,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); @@ -479,7 +481,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); @@ -487,7 +489,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), @@ -496,13 +498,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 @@ -630,7 +636,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; @@ -649,7 +655,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); @@ -668,6 +674,9 @@ chat_window_update_chat_tab_full (EmpathyChat *chat, else if (g_list_find (priv->chats_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 { @@ -696,6 +705,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, @@ -731,6 +744,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 @@ -858,21 +873,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 @@ -882,21 +900,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 @@ -1358,18 +1379,20 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window, static void chat_window_set_highlight_room_tab_label (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); + g_free (name); g_free (markup); } @@ -2213,6 +2236,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); @@ -2329,7 +2355,7 @@ empathy_chat_window_has_focus (EmpathyChatWindow *window) return has_focus; } -EmpathyChat * +static EmpathyChat * empathy_chat_window_find_chat (TpAccount *account, const gchar *id) { @@ -2360,6 +2386,39 @@ empathy_chat_window_find_chat (TpAccount *account, return NULL; } +EmpathyChat * +empathy_chat_window_find_chat_by_channel (const char *channel_path) +{ + GList *l; + + g_return_val_if_fail (!EMP_STR_EMPTY (channel_path), NULL); + + for (l = chat_windows; l; l = l->next) { + EmpathyChatWindowPriv *priv; + EmpathyChatWindow *window; + GList *ll; + + window = l->data; + priv = GET_PRIV (window); + + for (ll = priv->chats; ll; ll = ll->next) { + EmpathyChat *chat; + EmpathyTpChat *tp_chat; + const char *path; + + chat = ll->data; + tp_chat = empathy_chat_get_tp_chat (chat); + path = empathy_tp_chat_get_channel_path (tp_chat); + + if (!tp_strdiff (channel_path, path)) { + return chat; + } + } + } + + return NULL; +} + void empathy_chat_window_present_chat (EmpathyChat *chat, gint64 timestamp) diff --git a/src/empathy-chat-window.h b/src/empathy-chat-window.h index 4cbd2094a..33caec70c 100644 --- a/src/empathy-chat-window.h +++ b/src/empathy-chat-window.h @@ -70,8 +70,7 @@ void empathy_chat_window_move_chat (EmpathyChatWindow *old_wi void empathy_chat_window_switch_to_chat (EmpathyChatWindow *window, EmpathyChat *chat); gboolean empathy_chat_window_has_focus (EmpathyChatWindow *window); -EmpathyChat * empathy_chat_window_find_chat (TpAccount *account, - const gchar *id); +EmpathyChat * empathy_chat_window_find_chat_by_channel (const char *path); void empathy_chat_window_present_chat (EmpathyChat *chat, gint64 timestamp); |