Continue implementing
This commit is contained in:
parent
582473cae0
commit
c49ed72d09
@ -18,6 +18,8 @@ libmatrix_convenience_la_SOURCES = \
|
||||
matrix-im-manager.h \
|
||||
matrix-muc-manager.c \
|
||||
matrix-muc-manager.h \
|
||||
matrix-contact-info.c \
|
||||
matrix-contact-info.h \
|
||||
$(NULL)
|
||||
|
||||
nodist_libmatrix_convenience_la_SOURCES = \
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include "matrix-connection.h"
|
||||
|
||||
#include "matrix-contact-info.h"
|
||||
|
||||
static void _aliasing_iface_init(gpointer, gpointer);
|
||||
|
||||
struct _MatrixConnectionPrivate {
|
||||
@ -40,8 +42,8 @@ enum {
|
||||
|
||||
static const gchar *interfaces_always_present[] = {
|
||||
TP_IFACE_CONNECTION_INTERFACE_ALIASING,
|
||||
/*
|
||||
TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO,
|
||||
/* TODO:
|
||||
MATRIX_IFACE_CONNECTION_INTERFACE_RENAMING,
|
||||
*/
|
||||
TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
|
||||
@ -54,14 +56,14 @@ G_DEFINE_TYPE_WITH_CODE(
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING,
|
||||
_aliasing_iface_init);
|
||||
/*
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO,
|
||||
matrix_contact_info_iface_init);
|
||||
/* TODO:
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
MATRIX_TYPE_SVC_CONNECTION_INTERFACE_RENAMING,
|
||||
_renaming_interface_init);
|
||||
*/
|
||||
*/
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS,
|
||||
tp_contacts_mixin_iface_init);
|
||||
@ -265,10 +267,13 @@ _aliasing_fill_contact_attributes(GObject *obj,
|
||||
static void
|
||||
matrix_connection_constructed(GObject *obj)
|
||||
{
|
||||
//MatrixConnection *connection = MATRIX_CONNECTION(obj);
|
||||
MatrixConnection *connection = MATRIX_CONNECTION(obj);
|
||||
|
||||
//matrix_contact_info_init(connection);
|
||||
tp_contacts_mixin_add_contact_attributes_iface(obj, TP_IFACE_CONNECTION_INTERFACE_ALIASING, _aliasing_fill_contact_attributes);
|
||||
matrix_contact_info_init(connection);
|
||||
tp_contacts_mixin_add_contact_attributes_iface(
|
||||
obj,
|
||||
TP_IFACE_CONNECTION_INTERFACE_ALIASING,
|
||||
_aliasing_fill_contact_attributes);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -320,7 +325,7 @@ _iface_create_channel_managers(TpBaseConnection *base)
|
||||
GPtrArray *managers = g_ptr_array_sized_new(1);
|
||||
//GObject *manager;
|
||||
|
||||
/*
|
||||
/* TODO:
|
||||
manager = g_object_new(MATRIX_TYPE_IM_MANAGER,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
@ -334,7 +339,7 @@ _iface_create_channel_managers(TpBaseConnection *base)
|
||||
priv->password_manager = tp_simple_password_manager_new(base);
|
||||
g_ptr_array_add(managers, priv->password_manager);
|
||||
|
||||
/*
|
||||
/* TODO:
|
||||
manager = g_object_new(MATRIX_TYPE_ROOMLIST_MANAGER,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
@ -375,7 +380,7 @@ matrix_connection_class_init(MatrixConnectionClass *klass)
|
||||
parent_class->connecting = NULL;
|
||||
parent_class->connected = NULL;
|
||||
parent_class->disconnected = _iface_disconnected;
|
||||
/*
|
||||
/* TODO:
|
||||
parent_class->shut_down = _iface_shut_down;
|
||||
parent_class->start_connecting = _iface_start_connecting;
|
||||
parent_class->get_interfaces_always_present = get_interfaces_always_present;
|
||||
@ -406,7 +411,7 @@ matrix_connection_class_init(MatrixConnectionClass *klass)
|
||||
g_object_class_install_property(gobject_class, PROP_PASSWORD, param_spec);
|
||||
|
||||
tp_contacts_mixin_class_init(gobject_class, G_STRUCT_OFFSET(MatrixConnectionClass, contacts));
|
||||
//matrix_contact_info_class_init(klass);
|
||||
matrix_contact_info_class_init(klass);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -39,6 +39,7 @@ struct _MatrixConnection {
|
||||
/* Parent instance structure */
|
||||
TpBaseConnection parent_instance;
|
||||
TpContactsMixin contacts;
|
||||
GQueue *contact_info_requests;
|
||||
|
||||
/* Instance members */
|
||||
MatrixConnectionPrivate *priv;
|
||||
|
168
src/matrix-contact-info.c
Normal file
168
src/matrix-contact-info.c
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* This file is part of telepathy-matrix
|
||||
*
|
||||
* telepathy-matrix is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* telepathy-matrix is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with telepathy-matrix. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix-contact-info.h"
|
||||
|
||||
#define MATRIX_DEBUG_FLAG MATRIX_DEBUG_CONNECTION
|
||||
#include "matrix-debug.h"
|
||||
|
||||
typedef enum _ContactPresence {
|
||||
CONTACT_PRESENCE_UNKNOWN,
|
||||
CONTACT_PRESENCE_AVAILABLE,
|
||||
CONTACT_PRESENCE_AWAY,
|
||||
CONTACT_PRESENCE_DND,
|
||||
CONTACT_PRESENCE_ERROR
|
||||
} ContactPresence;
|
||||
|
||||
typedef struct _ContactInfoRequest {
|
||||
guint handle;
|
||||
const gchar *id;
|
||||
ContactPresence presence;
|
||||
GPtrArray *contact_info;
|
||||
DBusGMethodInvocation *context;
|
||||
} ContactInfoRequest;
|
||||
|
||||
static void
|
||||
matrix_contact_info_properties_getter(GObject *gobject,
|
||||
GQuark interface,
|
||||
GQuark name,
|
||||
GValue *value,
|
||||
gpointer getter_data)
|
||||
{
|
||||
GQuark q_supported_fields = g_quark_from_static_string("SupportedFields");
|
||||
|
||||
if (name == q_supported_fields) {
|
||||
GPtrArray *fields = dbus_g_type_specialized_construct(
|
||||
TP_ARRAY_TYPE_FIELD_SPECS);
|
||||
|
||||
g_value_set_boxed(value, fields);
|
||||
g_boxed_free(TP_ARRAY_TYPE_FIELD_SPECS, fields);
|
||||
} else {
|
||||
g_value_set_uint(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
matrix_contact_info_class_init(MatrixConnectionClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
static TpDBusPropertiesMixinPropImpl props[] = {
|
||||
{"ContactInfoFlags", NULL, NULL},
|
||||
{"SupportedFields", NULL, NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
tp_dbus_properties_mixin_implement_interface(
|
||||
gobject_class,
|
||||
TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO,
|
||||
matrix_contact_info_properties_getter,
|
||||
NULL,
|
||||
props);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_contact_info_fill_contact_attributes(GObject *gobject,
|
||||
const GArray *contacts,
|
||||
GHashTable *attributes_hash)
|
||||
{
|
||||
/* We don’t cache contact info yet. */
|
||||
}
|
||||
|
||||
void
|
||||
matrix_contact_info_init(MatrixConnection *connection)
|
||||
{
|
||||
connection->contact_info_requests = g_queue_new();
|
||||
|
||||
/* TODO: add handlers here */
|
||||
|
||||
tp_contacts_mixin_add_contact_attributes_iface(
|
||||
G_OBJECT(connection),
|
||||
TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO,
|
||||
matrix_contact_info_fill_contact_attributes);
|
||||
}
|
||||
|
||||
static void
|
||||
_send_request_contact_info(MatrixConnection *connection,
|
||||
ContactInfoRequest *request)
|
||||
{
|
||||
// TODO: implement actual contact info querying
|
||||
}
|
||||
|
||||
static void
|
||||
_queue_request_contact_info(MatrixConnection *connection,
|
||||
guint handle,
|
||||
const gchar *id,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
ContactInfoRequest *request;
|
||||
|
||||
request = g_slice_new0(ContactInfoRequest);
|
||||
request->handle = handle;
|
||||
request->id = id;
|
||||
request->presence = CONTACT_PRESENCE_UNKNOWN;
|
||||
request->contact_info = NULL;
|
||||
request->context = context;
|
||||
|
||||
if (g_queue_is_empty(connection->contact_info_requests)) {
|
||||
_send_request_contact_info(connection, request);
|
||||
}
|
||||
|
||||
g_queue_push_tail(connection->contact_info_requests, request);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_connection_request_contact_info(
|
||||
TpSvcConnectionInterfaceContactInfo *iface,
|
||||
guint contact,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
MatrixConnection *connection = MATRIX_CONNECTION(iface);
|
||||
TpBaseConnection *base = TP_BASE_CONNECTION(connection);
|
||||
TpHandleRepoIface *contact_handles = tp_base_connection_get_handles(
|
||||
base,
|
||||
TP_HANDLE_TYPE_CONTACT);
|
||||
const gchar *id;
|
||||
GError *err = NULL;
|
||||
|
||||
TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED(base, context);
|
||||
|
||||
if (!tp_handle_is_valid(contact_handles, contact, &err)) {
|
||||
dbus_g_method_return_error(context, err);
|
||||
g_error_free(err);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
id = tp_handle_inspect(contact_handles, contact);
|
||||
|
||||
MATRIX_DEBUG("Queued contact info request for handle: %u (%s)",
|
||||
contact, id);
|
||||
|
||||
_queue_request_contact_info(connection, contact, id, context);
|
||||
}
|
||||
|
||||
void
|
||||
matrix_contact_info_iface_init(gpointer g_iface, gpointer iface_data)
|
||||
{
|
||||
TpSvcConnectionInterfaceContactInfoClass *klass = (TpSvcConnectionInterfaceContactInfoClass *)g_iface;
|
||||
|
||||
#define IMPLEMENT(x) tp_svc_connection_interface_contact_info_implement_##x (klass, matrix_connection_##x)
|
||||
IMPLEMENT(request_contact_info);
|
||||
#undef IMPLEMENT
|
||||
}
|
36
src/matrix-contact-info.h
Normal file
36
src/matrix-contact-info.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of telepathy-matrix
|
||||
*
|
||||
* telepathy-matrix is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* telepathy-matrix is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with telepathy-matrix. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_CONTACT_INFO_H__
|
||||
#define __MATRIX_CONTACT_INFO_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <telepathy-glib/telepathy-glib.h>
|
||||
|
||||
#include "matrix-connection.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void matrix_contact_info_class_init(MatrixConnectionClass *klass);
|
||||
void matrix_contact_info_iface_init(gpointer g_iface, gpointer iface_data);
|
||||
void matrix_contact_info_init(MatrixConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_CONTACT_INFO_H__ */
|
Loading…
Reference in New Issue
Block a user