diff options
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-contact-list.c | 11 | ||||
-rw-r--r-- | libempathy/empathy-contact-list.h | 12 | ||||
-rw-r--r-- | libempathy/empathy-contact-manager.c | 34 | ||||
-rw-r--r-- | libempathy/empathy-contact-manager.h | 4 | ||||
-rw-r--r-- | libempathy/empathy-log-store-empathy.c | 8 | ||||
-rw-r--r-- | libempathy/empathy-message.c | 36 | ||||
-rw-r--r-- | libempathy/empathy-message.h | 3 | ||||
-rw-r--r-- | libempathy/empathy-tp-contact-list.c | 129 |
8 files changed, 213 insertions, 24 deletions
diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c index 1fe894e99..d9493af1e 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -229,3 +229,14 @@ empathy_contact_list_remove_group (EmpathyContactList *list, } } +EmpathyContactListFlags +empathy_contact_list_get_flags (EmpathyContactList *list) +{ + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), 0); + + if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags) { + return EMPATHY_CONTACT_LIST_GET_IFACE (list)->get_flags (list); + } else { + return 0; + } +} diff --git a/libempathy/empathy-contact-list.h b/libempathy/empathy-contact-list.h index 5eabf32c3..28238e44a 100644 --- a/libempathy/empathy-contact-list.h +++ b/libempathy/empathy-contact-list.h @@ -34,6 +34,13 @@ G_BEGIN_DECLS #define EMPATHY_IS_CONTACT_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONTACT_LIST)) #define EMPATHY_CONTACT_LIST_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), EMPATHY_TYPE_CONTACT_LIST, EmpathyContactListIface)) +typedef enum { + EMPATHY_CONTACT_LIST_CAN_ADD = 1 << 0, + EMPATHY_CONTACT_LIST_CAN_REMOVE = 1 << 1, + EMPATHY_CONTACT_LIST_CAN_ALIAS = 1 << 2, + EMPATHY_CONTACT_LIST_CAN_GROUP = 1 << 3, +} EmpathyContactListFlags; + typedef struct _EmpathyContactListIface EmpathyContactListIface; struct _EmpathyContactListIface { @@ -64,6 +71,8 @@ struct _EmpathyContactListIface { const gchar *group); EmpathyContactMonitor * (*get_monitor) (EmpathyContactList *list); + EmpathyContactListFlags + (*get_flags) (EmpathyContactList *list); }; GType empathy_contact_list_get_type (void) G_GNUC_CONST; @@ -92,6 +101,9 @@ void empathy_contact_list_remove_group (EmpathyContactList *list, EmpathyContactMonitor * empathy_contact_list_get_monitor (EmpathyContactList *list); +EmpathyContactListFlags + empathy_contact_list_get_flags (EmpathyContactList *list); + G_END_DECLS #endif /* __EMPATHY_CONTACT_LIST_H__ */ diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index 7af2bd349..302fad3c5 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -204,6 +204,23 @@ contact_manager_constructor (GType type, return retval; } +/** + * empathy_contact_manager_initialized: + * + * Reports whether or not the singleton has already been created. + * + * There can be instances where you want to access the #EmpathyContactManager + * only if it has been set up for this process. + * + * Returns: %TRUE if the #EmpathyContactManager singleton has previously + * been initialized. + */ +gboolean +empathy_contact_manager_initialized (void) +{ + return (manager_singleton != NULL); +} + static void empathy_contact_manager_class_init (EmpathyContactManagerClass *klass) { @@ -527,19 +544,24 @@ contact_manager_iface_init (EmpathyContactListIface *iface) iface->remove_group = contact_manager_remove_group; } -gboolean -empathy_contact_manager_can_add (EmpathyContactManager *manager, - TpConnection *connection) +EmpathyContactListFlags +empathy_contact_manager_get_flags_for_connection ( + EmpathyContactManager *manager, + TpConnection *connection) { EmpathyContactManagerPriv *priv = GET_PRIV (manager); - EmpathyTpContactList *list; + EmpathyContactList *list; + EmpathyContactListFlags flags; g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), FALSE); + g_return_val_if_fail (connection != NULL, FALSE); list = g_hash_table_lookup (priv->lists, connection); - if (list == NULL) + if (list == NULL) { return FALSE; + } + flags = empathy_contact_list_get_flags (list); - return empathy_tp_contact_list_can_add (list); + return flags; } diff --git a/libempathy/empathy-contact-manager.h b/libempathy/empathy-contact-manager.h index fbe9e2df0..97e21464a 100644 --- a/libempathy/empathy-contact-manager.h +++ b/libempathy/empathy-contact-manager.h @@ -50,10 +50,12 @@ struct _EmpathyContactManagerClass { }; GType empathy_contact_manager_get_type (void) G_GNUC_CONST; +gboolean empathy_contact_manager_initialized (void); EmpathyContactManager *empathy_contact_manager_dup_singleton (void); EmpathyTpContactList * empathy_contact_manager_get_list (EmpathyContactManager *manager, TpConnection *connection); -gboolean empathy_contact_manager_can_add (EmpathyContactManager *manager, +EmpathyContactListFlags empathy_contact_manager_get_flags_for_connection ( + EmpathyContactManager *manager, TpConnection *connection); G_END_DECLS diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c index 7e50cb12f..b814defe7 100644 --- a/libempathy/empathy-log-store-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -27,7 +27,14 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> + +/* FIXME: g_mapped_file_free has been deprecated in GLib 2.22, but the + * replacement symbol, g_mapped_file_unref is not available in older Glib + * and we're not ready to bump our version requirement just for this. When + * we're ready to bump our version requirement, just revert this patch. */ +#undef G_DISABLE_DEPRECATED #include <glib/gstdio.h> +#define G_DISABLE_DEPRECATED #include "empathy-log-store.h" #include "empathy-log-store-empathy.h" @@ -497,6 +504,7 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self, empathy_message_set_sender (message, sender); empathy_message_set_timestamp (message, t); empathy_message_set_tptype (message, msg_type); + empathy_message_set_is_backlog (message, TRUE); if (cm_id_str) empathy_message_set_id (message, cm_id); diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c index d020b72e4..a8fe6084c 100644 --- a/libempathy/empathy-message.c +++ b/libempathy/empathy-message.c @@ -39,6 +39,7 @@ typedef struct { EmpathyContact *receiver; gchar *body; time_t timestamp; + gboolean is_backlog; guint id; } EmpathyMessagePriv; @@ -61,6 +62,7 @@ enum { PROP_RECEIVER, PROP_BODY, PROP_TIMESTAMP, + PROP_IS_BACKLOG, }; static void @@ -112,6 +114,13 @@ empathy_message_class_init (EmpathyMessageClass *class) G_MAXLONG, -1, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_IS_BACKLOG, + g_param_spec_boolean ("is-backlog", + "History message", + "If the message belongs to history", + FALSE, + G_PARAM_READWRITE)); g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv)); @@ -387,6 +396,33 @@ empathy_message_set_timestamp (EmpathyMessage *message, g_object_notify (G_OBJECT (message), "timestamp"); } +gboolean +empathy_message_is_backlog (EmpathyMessage *message) +{ + EmpathyMessagePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE); + + priv = GET_PRIV (message); + + return priv->is_backlog; +} + +void +empathy_message_set_is_backlog (EmpathyMessage *message, + gboolean is_backlog) +{ + EmpathyMessagePriv *priv; + + g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + + priv = GET_PRIV (message); + + priv->is_backlog = is_backlog; + + g_object_notify (G_OBJECT (message), "is-backlog"); +} + #define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':') gboolean empathy_message_should_highlight (EmpathyMessage *message) diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h index 2172c9784..00064df57 100644 --- a/libempathy/empathy-message.h +++ b/libempathy/empathy-message.h @@ -68,6 +68,9 @@ void empathy_message_set_body (EmpathyMessage time_t empathy_message_get_timestamp (EmpathyMessage *message); void empathy_message_set_timestamp (EmpathyMessage *message, time_t timestamp); +gboolean empathy_message_is_backlog (EmpathyMessage *message); +void empathy_message_set_is_backlog (EmpathyMessage *message, + gboolean is_backlog); gboolean empathy_message_should_highlight (EmpathyMessage *message); TpChannelTextMessageType empathy_message_type_from_str (const gchar *type_str); const gchar * empathy_message_type_to_str (TpChannelTextMessageType type); diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c index cdb0431c4..c1c46b3ca 100644 --- a/libempathy/empathy-tp-contact-list.c +++ b/libempathy/empathy-tp-contact-list.c @@ -50,6 +50,8 @@ typedef struct { GHashTable *pendings; /* handle -> EmpathyContact */ GHashTable *groups; /* group name -> TpChannel */ GHashTable *add_to_group; /* group name -> GArray of handles */ + + EmpathyContactListFlags flags; } EmpathyTpContactListPriv; typedef enum { @@ -509,6 +511,64 @@ tp_contact_list_publish_request_channel_cb (TpConnection *connection, } static void +tp_contact_list_get_alias_flags_cb (TpConnection *connection, + guint flags, + const GError *error, + gpointer user_data, + GObject *list) +{ + EmpathyTpContactListPriv *priv = GET_PRIV (list); + + if (error) { + DEBUG ("Error: %s", error->message); + return; + } + + if (flags & TP_CONNECTION_ALIAS_FLAG_USER_SET) { + priv->flags |= EMPATHY_CONTACT_LIST_CAN_ALIAS; + } +} + +static void +tp_contact_list_get_requestablechannelclasses_cb (TpProxy *connection, + const GValue *value, + const GError *error, + gpointer user_data, + GObject *list) +{ + EmpathyTpContactListPriv *priv = GET_PRIV (list); + GPtrArray *classes; + int i; + + if (error) { + DEBUG ("Error: %s", error->message); + return; + } + + classes = g_value_get_boxed (value); + for (i = 0; i < classes->len; i++) { + GValueArray *class = g_ptr_array_index (classes, i); + GHashTable *props; + const char *channel_type; + guint handle_type; + + props = g_value_get_boxed (g_value_array_get_nth (class, 0)); + + channel_type = tp_asv_get_string (props, + TP_IFACE_CHANNEL ".ChannelType"); + handle_type = tp_asv_get_uint32 (props, + TP_IFACE_CHANNEL ".TargetHandleType", NULL); + + if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) && + handle_type == TP_HANDLE_TYPE_GROUP) { + DEBUG ("Got channel class for a contact group"); + priv->flags |= EMPATHY_CONTACT_LIST_CAN_GROUP; + break; + } + } +} + +static void tp_contact_list_publish_request_handle_cb (TpConnection *connection, const GArray *handles, const GError *error, @@ -722,6 +782,32 @@ tp_contact_list_constructed (GObject *list) priv->factory = empathy_tp_contact_factory_dup_singleton (priv->connection); + /* call GetAliasFlags */ + if (tp_proxy_has_interface_by_id (priv->connection, + TP_IFACE_QUARK_CONNECTION_INTERFACE_ALIASING)) { + tp_cli_connection_interface_aliasing_call_get_alias_flags ( + priv->connection, + -1, + tp_contact_list_get_alias_flags_cb, + NULL, NULL, + G_OBJECT (list)); + } + + /* lookup RequestableChannelClasses */ + if (tp_proxy_has_interface_by_id (priv->connection, + TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS)) { + tp_cli_dbus_properties_call_get (priv->connection, + -1, + TP_IFACE_CONNECTION_INTERFACE_REQUESTS, + "RequestableChannelClasses", + tp_contact_list_get_requestablechannelclasses_cb, + NULL, NULL, + G_OBJECT (list)); + } else { + /* we just don't know... better mark the flag just in case */ + priv->flags |= EMPATHY_CONTACT_LIST_CAN_GROUP; + } + names[0] = "publish"; tp_cli_connection_call_request_handles (priv->connection, -1, @@ -1074,6 +1160,31 @@ tp_contact_list_remove_group (EmpathyContactList *list, g_array_free (handles, TRUE); } +static EmpathyContactListFlags +tp_contact_list_get_flags (EmpathyContactList *list) +{ + EmpathyTpContactListPriv *priv; + EmpathyContactListFlags flags; + TpChannelGroupFlags group_flags; + + g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), FALSE); + + priv = GET_PRIV (list); + flags = priv->flags; + + group_flags = tp_channel_group_get_flags (priv->subscribe); + + if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD) { + flags |= EMPATHY_CONTACT_LIST_CAN_ADD; + } + + if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_REMOVE) { + flags |= EMPATHY_CONTACT_LIST_CAN_REMOVE; + } + + return flags; +} + static void tp_contact_list_iface_init (EmpathyContactListIface *iface) { @@ -1087,23 +1198,7 @@ tp_contact_list_iface_init (EmpathyContactListIface *iface) iface->remove_from_group = tp_contact_list_remove_from_group; iface->rename_group = tp_contact_list_rename_group; iface->remove_group = tp_contact_list_remove_group; -} - -gboolean -empathy_tp_contact_list_can_add (EmpathyTpContactList *list) -{ - EmpathyTpContactListPriv *priv; - TpChannelGroupFlags flags; - - g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), FALSE); - - priv = GET_PRIV (list); - - if (priv->subscribe == NULL) - return FALSE; - - flags = tp_channel_group_get_flags (priv->subscribe); - return (flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD) != 0; + iface->get_flags = tp_contact_list_get_flags; } void |