Move Telepathy utility functions from shell-global to shell-tp-client
https://bugzilla.gnome.org/show_bug.cgi?id=645585
This commit is contained in:
parent
2028f33e38
commit
227da25776
@ -2048,66 +2048,6 @@ gboolean _shell_global_check_xdnd_event (ShellGlobal *global,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ShellGetTpContactCb:
|
||||
* @connection: The connection
|
||||
* @contacts: (element-type TelepathyGLib.Contact): List of contacts
|
||||
* @failed: Array of failed contacts
|
||||
*/
|
||||
|
||||
static void
|
||||
shell_global_get_tp_contacts_cb (TpConnection *self,
|
||||
guint n_contacts,
|
||||
TpContact * const *contacts,
|
||||
guint n_failed,
|
||||
const TpHandle *failed,
|
||||
const GError *error,
|
||||
gpointer user_data,
|
||||
GObject *weak_object)
|
||||
{
|
||||
int i;
|
||||
GList *contact_list = NULL;
|
||||
for (i = 0; i < n_contacts; i++) {
|
||||
contact_list = g_list_append(contact_list, contacts[i]);
|
||||
}
|
||||
|
||||
TpHandle *failed_list = g_new0 (TpHandle, n_failed + 1);
|
||||
memcpy(failed_list, failed, n_failed);
|
||||
|
||||
((ShellGetTpContactCb)user_data)(self, contact_list, failed_list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shell_get_tp_contacts:
|
||||
* @self: A connection, which must be ready
|
||||
* @n_handles: Number of handles in handles
|
||||
* @handles: (array length=n_handles) (element-type uint): Array of handles
|
||||
* @n_features: Number of features in features
|
||||
* @features: (array length=n_features) (allow-none) (element-type uint):
|
||||
* Array of features
|
||||
* @callback: (scope async): User callback to run when the contacts are ready
|
||||
*
|
||||
* Wrap tp_connection_get_contacts_by_handle so we can transform the array
|
||||
* into a null-terminated one, which gjs can handle.
|
||||
* We send the original callback to tp_connection_get_contacts_by_handle as
|
||||
* user_data, and we have our own function as callback, which does the
|
||||
* transforming.
|
||||
*/
|
||||
void
|
||||
shell_get_tp_contacts (TpConnection *self,
|
||||
guint n_handles,
|
||||
const TpHandle *handles,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetTpContactCb callback)
|
||||
{
|
||||
tp_connection_get_contacts_by_handle(self, n_handles, handles,
|
||||
n_features, features,
|
||||
shell_global_get_tp_contacts_cb,
|
||||
callback, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_global_launch_calendar_server:
|
||||
* @global: The #ShellGlobal.
|
||||
@ -2162,74 +2102,6 @@ shell_global_launch_calendar_server (ShellGlobal *global)
|
||||
g_free (calendar_server_exe);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_global_get_self_contact_features_cb (TpConnection *connection,
|
||||
guint n_contacts,
|
||||
TpContact * const *contacts,
|
||||
const GError *error,
|
||||
gpointer user_data,
|
||||
GObject *weak_object)
|
||||
{
|
||||
if (error != NULL) {
|
||||
g_print ("Failed to upgrade self contact: %s", error->message);
|
||||
return;
|
||||
}
|
||||
((ShellGetSelfContactFeaturesCb)user_data)(connection, *contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_get_self_contact_features:
|
||||
* @self: A connection, which must be ready
|
||||
* @n_features: Number of features in features
|
||||
* @features: (array length=n_features) (allow-none) (element-type uint):
|
||||
* Array of features
|
||||
* @callback: (scope async): User callback to run when the contact is ready
|
||||
*
|
||||
* Wrap tp_connection_upgrade_contacts due to the lack of support for
|
||||
* proper arrays arguments in GJS.
|
||||
*/
|
||||
void
|
||||
shell_get_self_contact_features (TpConnection *self,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetSelfContactFeaturesCb callback)
|
||||
{
|
||||
TpContact *self_contact = tp_connection_get_self_contact (self);
|
||||
|
||||
tp_connection_upgrade_contacts (self, 1, &self_contact,
|
||||
n_features, features,
|
||||
shell_global_get_self_contact_features_cb,
|
||||
callback, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_get_contact_events:
|
||||
* @log_manager: A #TplLogManager
|
||||
* @account: A #TpAccount
|
||||
* @entity: A #TplEntity
|
||||
* @num_events: The number of events to retrieve
|
||||
* @callback: (scope async): User callback to run when the contact is ready
|
||||
*
|
||||
* Wrap tpl_log_manager_get_filtered_events_async because gjs cannot support
|
||||
* multiple callbacks in the same function call.
|
||||
*/
|
||||
void
|
||||
shell_get_contact_events (TplLogManager *log_manager,
|
||||
TpAccount *account,
|
||||
TplEntity *entity,
|
||||
guint num_events,
|
||||
GAsyncReadyCallback callback)
|
||||
{
|
||||
tpl_log_manager_get_filtered_events_async (log_manager,
|
||||
account,
|
||||
entity,
|
||||
TPL_EVENT_MASK_TEXT,
|
||||
num_events,
|
||||
NULL, NULL,
|
||||
callback, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shell_get_file_contents_utf8_sync:
|
||||
* @path: UTF-8 encoded filename path
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <meta/meta-plugin.h>
|
||||
#include <telepathy-glib/telepathy-glib.h>
|
||||
#include <telepathy-logger/telepathy-logger.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -158,33 +156,8 @@ void shell_global_notify_error (ShellGlobal *global,
|
||||
|
||||
void shell_global_init_xdnd (ShellGlobal *global);
|
||||
|
||||
typedef void (*ShellGetTpContactCb) (TpConnection *connection,
|
||||
GList *contacts,
|
||||
TpHandle *failed);
|
||||
|
||||
void shell_get_tp_contacts (TpConnection *self,
|
||||
guint n_handles,
|
||||
const TpHandle *handles,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetTpContactCb callback);
|
||||
|
||||
void shell_global_launch_calendar_server (ShellGlobal *global);
|
||||
|
||||
typedef void (*ShellGetSelfContactFeaturesCb) (TpConnection *connection,
|
||||
TpContact *contact);
|
||||
|
||||
void shell_get_self_contact_features (TpConnection *self,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetSelfContactFeaturesCb callback);
|
||||
|
||||
void shell_get_contact_events (TplLogManager *log_manager,
|
||||
TpAccount *account,
|
||||
TplEntity *entity,
|
||||
guint num_events,
|
||||
GAsyncReadyCallback callback);
|
||||
|
||||
char *shell_get_file_contents_utf8_sync (const char *path,
|
||||
GError **error);
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "shell-tp-client.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <telepathy-glib/telepathy-glib.h>
|
||||
|
||||
G_DEFINE_TYPE(ShellTpClient, shell_tp_client, TP_TYPE_BASE_CLIENT)
|
||||
@ -123,3 +125,131 @@ shell_tp_client_set_observe_channels_func (ShellTpClient *self,
|
||||
self->priv->user_data_obs = user_data;
|
||||
self->priv->destroy_obs = destroy;
|
||||
}
|
||||
|
||||
/* Telepathy utility functions */
|
||||
|
||||
/**
|
||||
* ShellGetTpContactCb:
|
||||
* @connection: The connection
|
||||
* @contacts: (element-type TelepathyGLib.Contact): List of contacts
|
||||
* @failed: Array of failed contacts
|
||||
*/
|
||||
|
||||
static void
|
||||
shell_global_get_tp_contacts_cb (TpConnection *self,
|
||||
guint n_contacts,
|
||||
TpContact * const *contacts,
|
||||
guint n_failed,
|
||||
const TpHandle *failed,
|
||||
const GError *error,
|
||||
gpointer user_data,
|
||||
GObject *weak_object)
|
||||
{
|
||||
int i;
|
||||
GList *contact_list = NULL;
|
||||
for (i = 0; i < n_contacts; i++) {
|
||||
contact_list = g_list_append(contact_list, contacts[i]);
|
||||
}
|
||||
|
||||
TpHandle *failed_list = g_new0 (TpHandle, n_failed + 1);
|
||||
memcpy(failed_list, failed, n_failed);
|
||||
|
||||
((ShellGetTpContactCb)user_data)(self, contact_list, failed_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_get_tp_contacts:
|
||||
* @self: A connection, which must be ready
|
||||
* @n_handles: Number of handles in handles
|
||||
* @handles: (array length=n_handles) (element-type uint): Array of handles
|
||||
* @n_features: Number of features in features
|
||||
* @features: (array length=n_features) (allow-none) (element-type uint):
|
||||
* Array of features
|
||||
* @callback: (scope async): User callback to run when the contacts are ready
|
||||
*
|
||||
* Wrap tp_connection_get_contacts_by_handle so we can transform the array
|
||||
* into a null-terminated one, which gjs can handle.
|
||||
* We send the original callback to tp_connection_get_contacts_by_handle as
|
||||
* user_data, and we have our own function as callback, which does the
|
||||
* transforming.
|
||||
*/
|
||||
void
|
||||
shell_get_tp_contacts (TpConnection *self,
|
||||
guint n_handles,
|
||||
const TpHandle *handles,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetTpContactCb callback)
|
||||
{
|
||||
tp_connection_get_contacts_by_handle(self, n_handles, handles,
|
||||
n_features, features,
|
||||
shell_global_get_tp_contacts_cb,
|
||||
callback, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_global_get_self_contact_features_cb (TpConnection *connection,
|
||||
guint n_contacts,
|
||||
TpContact * const *contacts,
|
||||
const GError *error,
|
||||
gpointer user_data,
|
||||
GObject *weak_object)
|
||||
{
|
||||
if (error != NULL) {
|
||||
g_print ("Failed to upgrade self contact: %s", error->message);
|
||||
return;
|
||||
}
|
||||
((ShellGetSelfContactFeaturesCb)user_data)(connection, *contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_get_self_contact_features:
|
||||
* @self: A connection, which must be ready
|
||||
* @n_features: Number of features in features
|
||||
* @features: (array length=n_features) (allow-none) (element-type uint):
|
||||
* Array of features
|
||||
* @callback: (scope async): User callback to run when the contact is ready
|
||||
*
|
||||
* Wrap tp_connection_upgrade_contacts due to the lack of support for
|
||||
* proper arrays arguments in GJS.
|
||||
*/
|
||||
void
|
||||
shell_get_self_contact_features (TpConnection *self,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetSelfContactFeaturesCb callback)
|
||||
{
|
||||
TpContact *self_contact = tp_connection_get_self_contact (self);
|
||||
|
||||
tp_connection_upgrade_contacts (self, 1, &self_contact,
|
||||
n_features, features,
|
||||
shell_global_get_self_contact_features_cb,
|
||||
callback, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_get_contact_events:
|
||||
* @log_manager: A #TplLogManager
|
||||
* @account: A #TpAccount
|
||||
* @entity: A #TplEntity
|
||||
* @num_events: The number of events to retrieve
|
||||
* @callback: (scope async): User callback to run when the contact is ready
|
||||
*
|
||||
* Wrap tpl_log_manager_get_filtered_events_async because gjs cannot support
|
||||
* multiple callbacks in the same function call.
|
||||
*/
|
||||
void
|
||||
shell_get_contact_events (TplLogManager *log_manager,
|
||||
TpAccount *account,
|
||||
TplEntity *entity,
|
||||
guint num_events,
|
||||
GAsyncReadyCallback callback)
|
||||
{
|
||||
tpl_log_manager_get_filtered_events_async (log_manager,
|
||||
account,
|
||||
entity,
|
||||
TPL_EVENT_MASK_TEXT,
|
||||
num_events,
|
||||
NULL, NULL,
|
||||
callback, NULL);
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <telepathy-glib/base-client.h>
|
||||
#include <telepathy-glib/telepathy-glib.h>
|
||||
#include <telepathy-logger/telepathy-logger.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -57,5 +58,31 @@ void shell_tp_client_set_observe_channels_func (ShellTpClient *self,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Telepathy utility functions */
|
||||
typedef void (*ShellGetTpContactCb) (TpConnection *connection,
|
||||
GList *contacts,
|
||||
TpHandle *failed);
|
||||
|
||||
void shell_get_tp_contacts (TpConnection *self,
|
||||
guint n_handles,
|
||||
const TpHandle *handles,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetTpContactCb callback);
|
||||
|
||||
typedef void (*ShellGetSelfContactFeaturesCb) (TpConnection *connection,
|
||||
TpContact *contact);
|
||||
|
||||
void shell_get_self_contact_features (TpConnection *self,
|
||||
guint n_features,
|
||||
const TpContactFeature *features,
|
||||
ShellGetSelfContactFeaturesCb callback);
|
||||
|
||||
void shell_get_contact_events (TplLogManager *log_manager,
|
||||
TpAccount *account,
|
||||
TplEntity *entity,
|
||||
guint num_events,
|
||||
GAsyncReadyCallback callback);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __SHELL_TP_CLIENT_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user