diff --git a/src/Makefile.am b/src/Makefile.am index 22e6358..cae999d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,12 +5,15 @@ libexec_PROGRAMS = telepathy-cauchy AM_VALAFLAGS = \ -C \ + -H cauchy.h \ + --use-header \ tp-base.vapi \ --pkg=telepathy-glib \ $(NULL) libtp_cauchy_convenience_la_VALA_SOURCES = \ cauchy-connection-manager.vala \ + cauchy-protocol.vala \ $(NULL) vala-stamp: $(libtp_cauchy_convenience_la_VALA_SOURCES) @@ -40,8 +43,6 @@ libcauchy_convenience_la_SOURCES = \ $(libtp_cauchy_convenience_la_VALA_SOURCES:.vala=.c) \ cauchy-connection.c \ cauchy-connection.h \ - cauchy-protocol.c \ - cauchy-protocol.h \ cauchy-debug.c \ cauchy-debug.h \ cauchy-handles.c \ diff --git a/src/cauchy-connection-manager.vala b/src/cauchy-connection-manager.vala index dceb6fa..07d7bea 100644 --- a/src/cauchy-connection-manager.vala +++ b/src/cauchy-connection-manager.vala @@ -24,7 +24,7 @@ public class Cauchy.ConnectionManager : BaseConnectionManager { cm_dbus_name = "cauchy"; } - // construct { - // add_protocol(new Protocol()); - // } + construct { + add_protocol(new Cauchy.Protocol()); + } } diff --git a/src/cauchy-protocol.c b/src/cauchy-protocol.c deleted file mode 100644 index 62949af..0000000 --- a/src/cauchy-protocol.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This file is part of telepathy-cauchy - * - * telepathy-cauchy 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-cauchy 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-cauchy. If not, see - * . - */ - -#include "cauchy-protocol.h" -#include "cauchy-handles.h" -#include "cauchy-connection.h" -#include "cauchy-im-manager.h" -#include "cauchy-muc-manager.h" - -#include - -#define PROTOCOL_NAME "matrix" -#define ICON_NAME "im-" PROTOCOL_NAME -#define ENGLISH_NAME "Matrix" -#define VCARD_FIELD_NAME "x-" PROTOCOL_NAME - -static gboolean filter_account(const TpCMParamSpec *, GValue *, GError **); - -static const TpCMParamSpec cauchy_params[] = { - { - "account", - DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, - TP_CONN_MGR_PARAM_FLAG_REQUIRED, - NULL, 0, filter_account - }, - { - "homeserver", - DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, - TP_CONN_MGR_PARAM_FLAG_REQUIRED - }, - { - "password", - DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, - TP_CONN_MGR_PARAM_FLAG_SECRET - }, - {NULL, NULL, 0, 0, NULL, 0} -}; - -G_DEFINE_TYPE(CauchyProtocol, cauchy_protocol, TP_TYPE_BASE_PROTOCOL); - -static gboolean -filter_account(const TpCMParamSpec *paramspec, GValue *value, GError **err) -{ - const gchar *matrix_id = g_value_get_string(value); - - g_assert(matrix_id); - g_assert(G_VALUE_HOLDS_STRING(value)); - - if (!cauchy_id_is_valid(matrix_id, TRUE)) { - g_set_error(err, - TP_ERROR, TP_ERROR_INVALID_HANDLE, - "Invalid account name '%s'", matrix_id); - - return FALSE; - } - - return TRUE; -} - -static const TpCMParamSpec * -get_parameters(TpBaseProtocol *self G_GNUC_UNUSED) -{ - return cauchy_params; -} - -static TpBaseConnection * -new_connection(TpBaseProtocol *protocol G_GNUC_UNUSED, - GHashTable *params, - GError **err G_GNUC_UNUSED) -{ - return g_object_new(CAUCHY_TYPE_CONNECTION, - "homeserver", tp_asv_get_string(params, "homeserver"), - "matrix_id", tp_asv_get_string(params, "account"), - "password", tp_asv_get_string(params, "password"), - NULL); -} - -static gchar * -normalize_contact(TpBaseProtocol *protocol G_GNUC_UNUSED, - const gchar *contact, - GError **err) -{ - return cauchy_normalize_id(contact, err); -} - -static gchar * -identify_account(TpBaseProtocol *protocol G_GNUC_UNUSED, - GHashTable *asv, - GError **err) -{ - gchar *id = cauchy_normalize_id(tp_asv_get_string(asv, "account"), err); - gchar *server; - gchar *id_at_server; - - if (id == NULL) { - return NULL; - } - - server = g_ascii_strdown(tp_asv_get_string(asv, "homeserver"), -1); - - id_at_server = g_strdup_printf("@%s:%s", id, server); - g_free(server); - g_free(id); - - return id_at_server; -} - -static GPtrArray * -get_interfaces_array(TpBaseProtocol *protocol) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_PROTOCOL_CLASS(cauchy_protocol_parent_class)->get_interfaces_array(protocol); - - return interfaces; -} - -static void -get_connection_details(TpBaseProtocol *protocol, - GStrv *connection_interfaces, - GType **channel_managers, - gchar **icon_name, - gchar **english_name, - gchar **vcard_field) -{ - if (connection_interfaces != NULL) { - *connection_interfaces = g_strdupv( - (GStrv)cauchy_connection_get_implemented_interfaces()); - } - - if (channel_managers != NULL) { - GType types[] = { - CAUCHY_TYPE_IM_MANAGER, - CAUCHY_TYPE_MUC_MANAGER, - G_TYPE_INVALID - }; - - *channel_managers = g_memdup(types, sizeof(types)); - } - - if (icon_name != NULL) { - *icon_name = g_strdup(ICON_NAME); - } - - if (vcard_field != NULL) { - *vcard_field = g_strdup(VCARD_FIELD_NAME); - } - - if (english_name != NULL) { - *english_name = g_strdup(ENGLISH_NAME); - } -} - -static GStrv -dup_authentication_types(TpBaseProtocol *base) -{ - const gchar * const * types[] = { - NULL - }; - - return g_strdupv((GStrv)types); -} - -static void -cauchy_protocol_class_init(CauchyProtocolClass *klass) -{ - TpBaseProtocolClass *base_class = (TpBaseProtocolClass *)klass; - - base_class->get_parameters = get_parameters; - base_class->new_connection = new_connection; - base_class->normalize_contact = normalize_contact; - base_class->identify_account = identify_account; - base_class->get_interfaces_array = get_interfaces_array; - base_class->get_connection_details = get_connection_details; - base_class->dup_authentication_types = dup_authentication_types; -} - -static void -cauchy_protocol_init(CauchyProtocol *protocol) -{ -} - -TpBaseProtocol * -cauchy_protocol_new(void) -{ - return g_object_new(CAUCHY_TYPE_PROTOCOL, - "name", PROTOCOL_NAME, - NULL); -} diff --git a/src/cauchy-protocol.h b/src/cauchy-protocol.h deleted file mode 100644 index c7657ed..0000000 --- a/src/cauchy-protocol.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of telepathy-cauchy - * - * telepathy-cauchy 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-cauchy 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-cauchy. If not, see - * . - */ - -#ifndef __CAUCHY_PROTOCOL_H__ -#define __CAUCHY_PROTOCOL_H__ - -#include - -G_BEGIN_DECLS - -#define CAUCHY_TYPE_PROTOCOL (cauchy_protocol_get_type()) -#define CAUCHY_PROTOCOL(o) (G_TYPE_CHECK_INSTANCE_CAST((o), CAUCHY_TYPE_PROTOCOL, CauchyProtocol)) -#define CAUCHY_PROTOCOL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CAUCHY_TYPE_PROTOCOL, CauchyProtocolClass)) -#define CAUCHY_IS_PROTOCOL(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), CAUCHY_TYPE_PROTOCOL)) -#define CAUCHY_IS_PROTOCOL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), CAUCHY_TYPE_PROTOCOL)) -#define CAUCHY_PROTOCOL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), CAUCHY_TYPE_PROTOCOL, CauchyProtocolClass)) - -typedef struct _CauchyProtocol CauchyProtocol; -typedef struct _CauchyProtocolClass CauchyProtocolClass; - -struct _CauchyProtocol { - /* Parent instance structure */ - TpBaseProtocol parent_instance; - - /* Instance members */ -}; - -struct _CauchyProtocolClass { - TpBaseProtocolClass parent_class; -}; - -GType cauchy_protocol_get_type(void) G_GNUC_CONST; - -TpBaseProtocol *cauchy_protocol_new(void); - -G_END_DECLS - -#endif /* __CAUCHY_PROTOCOL_H__ */ diff --git a/src/cauchy-protocol.vala b/src/cauchy-protocol.vala new file mode 100644 index 0000000..b87dba0 --- /dev/null +++ b/src/cauchy-protocol.vala @@ -0,0 +1,21 @@ +/* + * This file is part of telepathy-cauchy + * + * telepathy-cauchy 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-cauchy 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-cauchy. If not, see + * . + */ + +using TelepathyGLib; + +public class Cauchy.Protocol : BaseProtocol {} diff --git a/src/tp-base.vapi b/src/tp-base.vapi index 1efdd04..4fa8586 100644 --- a/src/tp-base.vapi +++ b/src/tp-base.vapi @@ -17,7 +17,11 @@ */ namespace TelepathyGLib { - public abstract class BaseProtocol {} + [CCode (cheader_filename = "telepathy-glib/telepathy-glib.h")] + public abstract class BaseProtocol : GLib.Object { + [CCode (has_construct_function = false)] + public BaseProtocol(); + } [CCode (cheader_filename = "telepathy-glib/telepathy-glib.h")] public abstract class BaseConnectionManager : GLib.Object {