summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Staudinger <robsta@linux.intel.com>2011-10-19 22:56:16 +0200
committerRob Staudinger <robsta@linux.intel.com>2011-10-19 22:56:16 +0200
commit864309380de5f7ba578010ac95bb827335449253 (patch)
treeeeca5a0eb8cb1adbc252ba6583331a1e4ce267a1
parentc8e5152eba20d54c1b472e27b1f89cdefaacee7f (diff)
Contact: get rid of Client pointer.
More untangling of the codebase. Removed "client" property from Contact, means bumping version to 0.4.0. Tags: refactoring, api
-rw-r--r--configure.ac4
-rw-r--r--ytstenut/yts-client.c1
-rw-r--r--ytstenut/yts-contact-internal.h4
-rw-r--r--ytstenut/yts-contact.c89
-rw-r--r--ytstenut/yts-roster-internal.h2
-rw-r--r--ytstenut/yts-roster.c131
6 files changed, 114 insertions, 117 deletions
diff --git a/configure.ac b/configure.ac
index b3b99c1..5622d23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
AC_PREREQ(2.59)
m4_define([yts_major_version], [0])
-m4_define([yts_minor_version], [3])
-m4_define([yts_micro_version], [1])
+m4_define([yts_minor_version], [4])
+m4_define([yts_micro_version], [0])
m4_define([yts_version],
[yts_major_version.yts_minor_version.yts_micro_version])
diff --git a/ytstenut/yts-client.c b/ytstenut/yts-client.c
index fde744c..4b186ef 100644
--- a/ytstenut/yts-client.c
+++ b/ytstenut/yts-client.c
@@ -2134,6 +2134,7 @@ yts_client_process_one_service (YtsClient *self,
}
yts_roster_add_service (roster,
+ priv->connection,
jid,
sid,
type,
diff --git a/ytstenut/yts-contact-internal.h b/ytstenut/yts-contact-internal.h
index 4c9957b..c71690e 100644
--- a/ytstenut/yts-contact-internal.h
+++ b/ytstenut/yts-contact-internal.h
@@ -22,11 +22,11 @@
#define YTS_CONTACT_INTERNAL_H
#include <stdbool.h>
+#include <telepathy-glib/contact.h>
#include <ytstenut/yts-contact.h>
YtsContact *
-yts_contact_new (YtsClient *client,
- char const *contact_id);
+yts_contact_new (TpContact *tp_contact);
bool
yts_contact_dispatch_event (YtsContact *self,
diff --git a/ytstenut/yts-contact.c b/ytstenut/yts-contact.c
index 469e4ce..23a5fc1 100644
--- a/ytstenut/yts-contact.c
+++ b/ytstenut/yts-contact.c
@@ -38,7 +38,7 @@
#include <telepathy-glib/channel.h>
#include "empathy-tp-file.h"
-#include "yts-client-internal.h"
+#include "yts-capability.h"
#include "yts-contact-internal.h"
#include "yts-debug.h"
#include "yts-enum-types.h"
@@ -52,7 +52,6 @@ static void yts_c_pending_file_free (gpointer file);
static void yts_contact_dispose (GObject *object);
static void yts_contact_finalize (GObject *object);
-static void yts_contact_constructed (GObject *object);
static void yts_contact_get_property (GObject *object,
guint property_id,
GValue *value,
@@ -78,8 +77,6 @@ typedef struct {
char *icon_token; /* token identifying this contacts avatar */
- YtsClient *client; /* back-reference to the client that owns us */
-
GQueue *pending_files; /* files dispatched before channel open */
GHashTable *ft_cancellables;
@@ -100,7 +97,6 @@ enum
PROP_0,
PROP_JID,
PROP_ICON,
- PROP_CLIENT,
PROP_TP_CONTACT,
PROP_LAST
@@ -162,7 +158,6 @@ yts_contact_class_init (YtsContactClass *klass)
object_class->dispose = yts_contact_dispose;
object_class->finalize = yts_contact_finalize;
- object_class->constructed = yts_contact_constructed;
object_class->get_property = yts_contact_get_property;
object_class->set_property = yts_contact_set_property;
@@ -188,19 +183,6 @@ yts_contact_class_init (YtsContactClass *klass)
properties[PROP_ICON]);
/**
- * YtsContact:client:
- *
- * #YtsClient that owns the roster
- */
- properties[PROP_CLIENT] = g_param_spec_object ("client",
- "Client",
- "Client",
- YTS_TYPE_CLIENT,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property (object_class, PROP_CLIENT,
- properties[PROP_CLIENT]);
-
- /**
* YtsContact:jid:
*
* The jid of this contact
@@ -218,12 +200,12 @@ yts_contact_class_init (YtsContactClass *klass)
*
* #TpContact of this item.
*/
- properties[PROP_TP_CONTACT] = g_param_spec_object ("tp-contact",
- "TP Contact",
- "TP Contact",
+ properties[PROP_TP_CONTACT] = g_param_spec_object ("tp-contact", "", "",
TP_TYPE_CONTACT,
- G_PARAM_READABLE);
- g_object_class_install_property (object_class, PROP_TP_CONTACT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (object_class,
+ PROP_TP_CONTACT,
properties[PROP_TP_CONTACT]);
/**
@@ -286,7 +268,7 @@ static void
yts_contact_tp_contact_cb (TpConnection *connection,
guint n_contacts,
TpContact * const *contacts,
- const char * const *requesed_ids,
+ const char * const *requested_ids,
GHashTable *failed_id_errors,
const GError *error,
gpointer data,
@@ -313,37 +295,6 @@ yts_contact_tp_contact_cb (TpConnection *connection,
}
static void
-yts_contact_constructed (GObject *object)
-{
- YtsContact *self = YTS_CONTACT (object);
- YtsContactPrivate *priv = GET_PRIVATE (self);
- TpConnection *connection;
- TpContactFeature features[] = { TP_CONTACT_FEATURE_PRESENCE,
- TP_CONTACT_FEATURE_CONTACT_INFO,
- TP_CONTACT_FEATURE_AVATAR_DATA,
- TP_CONTACT_FEATURE_CAPABILITIES};
-
- if (G_OBJECT_CLASS (yts_contact_parent_class)->constructed)
- G_OBJECT_CLASS (yts_contact_parent_class)->constructed (object);
-
- connection = yts_client_get_connection (priv->client);
-
- g_assert (connection);
-
- YTS_NOTE (CONTACT, "Requesting TpContact for %s", priv->contact_id);
-
- tp_connection_get_contacts_by_id (connection,
- 1,
- &priv->contact_id,
- G_N_ELEMENTS (features),
- (const TpContactFeature *)&features,
- yts_contact_tp_contact_cb,
- self,
- NULL,
- (GObject*) object);
-}
-
-static void
yts_contact_get_property (GObject *object,
guint property_id,
GValue *value,
@@ -408,10 +359,9 @@ yts_contact_set_property (GObject *object,
case PROP_JID:
priv->contact_id = g_intern_string (g_value_get_string (value));
break;
- case PROP_CLIENT:
- priv->client = g_value_get_object (value);
+ case PROP_TP_CONTACT:
+ priv->tp_contact = g_value_dup_object (value);
break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -445,11 +395,6 @@ yts_contact_dispose (GObject *object)
priv->disposed = TRUE;
- if (priv->client) {
- yts_client_cleanup_contact (priv->client, YTS_CONTACT (object));
- priv->client = NULL;
- }
-
g_hash_table_destroy (priv->services);
priv->services = NULL;
@@ -497,7 +442,7 @@ yts_contact_get_id (YtsContact const *self)
* yts_contact_get_name:
* @self: object on which to invoke this method.
*
- * Retrieves human readable name of this client
+ * Retrieves human readable name of this contact.
*
* Returns: (transfer none): The name of this contact.
*/
@@ -542,14 +487,10 @@ yts_contact_get_icon (YtsContact const *self,
}
YtsContact *
-yts_contact_new (YtsClient *client, const char *contact_id)
+yts_contact_new (TpContact *tp_contact)
{
- g_return_val_if_fail (YTS_IS_CLIENT (client), NULL);
- g_return_val_if_fail (contact_id && *contact_id, NULL);
-
return g_object_new (YTS_TYPE_CONTACT,
- "client", client,
- "jid", contact_id,
+ "tp-contact", tp_contact,
NULL);
}
@@ -626,7 +567,6 @@ yts_contact_ft_op_cb (EmpathyTpFile *tp_file,
YtsCFtOp *op = data;
YtsContact *self = op->item;
YtsContactPrivate *priv = GET_PRIVATE (self);
- YtsClient *client = priv->client;
guint32 atom = op->atom;
if (error)
@@ -651,7 +591,6 @@ yts_contact_ft_op_cb (EmpathyTpFile *tp_file,
}
yts_c_ft_op_free (op);
- yts_client_emit_error (client, e);
}
typedef struct
@@ -860,9 +799,7 @@ yts_contact_create_ft_channel_cb (TpConnection *proxy,
YtsCPendingFile *pending_file = data;
YtsError e = (YTS_ERROR_NO_ROUTE | pending_file->atom);
- yts_client_emit_error (priv->client, e);
-
- g_warning ("Failed to open channel: %s", error->message);
+ g_critical ("Failed to open channel: %s", error->message);
}
}
diff --git a/ytstenut/yts-roster-internal.h b/ytstenut/yts-roster-internal.h
index 58d3bc8..9814b8d 100644
--- a/ytstenut/yts-roster-internal.h
+++ b/ytstenut/yts-roster-internal.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <glib.h>
+#include <telepathy-glib/connection.h>
#include <ytstenut/yts-contact.h>
#include <ytstenut/yts-roster.h>
@@ -40,6 +41,7 @@ yts_roster_remove_contact (YtsRoster *roster,
void
yts_roster_add_service (YtsRoster *roster,
+ TpConnection *tp_connection,
char const *contact_id,
char const *service_id,
char const *type,
diff --git a/ytstenut/yts-roster.c b/ytstenut/yts-roster.c
index a6f0dd4..8444866 100644
--- a/ytstenut/yts-roster.c
+++ b/ytstenut/yts-roster.c
@@ -116,11 +116,6 @@ _dispose (GObject *object)
{
YtsRosterPrivate *priv = GET_PRIVATE (object);
- if (priv->client) {
- /* no ownership */
- priv->client = NULL;
- }
-
if (priv->contacts) {
GHashTableIter iter;
@@ -135,12 +130,19 @@ _dispose (GObject *object)
g_signal_handlers_disconnect_by_func (contact,
_contact_send_message,
object);
+
+ yts_client_cleanup_contact (priv->client, contact);
}
g_hash_table_destroy (priv->contacts);
priv->contacts = NULL;
}
+ if (priv->client) {
+ /* no ownership */
+ priv->client = NULL;
+ }
+
G_OBJECT_CLASS (yts_roster_parent_class)->dispose (object);
}
@@ -303,6 +305,7 @@ yts_roster_remove_service_by_id (YtsRoster *self,
g_signal_handlers_disconnect_by_func (contact,
_contact_send_message,
self);
+ yts_client_cleanup_contact (priv->client, contact);
g_object_ref (contact);
g_hash_table_remove (priv->contacts, contact_id);
g_signal_emit (self, _signals[SIG_CONTACT_REMOVED], 0, contact);
@@ -405,6 +408,12 @@ yts_roster_clear (YtsRoster *self)
{
YtsContact *contact = value;
+ g_signal_handlers_disconnect_by_func (contact,
+ _contact_send_message,
+ self);
+
+ yts_client_cleanup_contact (priv->client, contact);
+
g_object_ref (contact);
g_hash_table_iter_remove (&iter);
@@ -440,45 +449,74 @@ yts_roster_contact_service_added_cb (YtsContact *contact,
g_signal_emit (roster, _signals[SIG_SERVICE_ADDED], 0, service);
}
-void
-yts_roster_add_service (YtsRoster *self,
- char const *contact_id,
- char const *service_id,
- char const *type,
- char const *const *caps,
- GHashTable *names,
- GHashTable *statuses)
+static void
+_connection_get_contacts (TpConnection *connection,
+ guint n_contacts,
+ TpContact *const *contacts,
+ const char *const *requested_ids,
+ GHashTable *failed_id_errors,
+ const GError *error,
+ gpointer self_,
+ GObject *service_)
{
+ YtsRoster *self = YTS_ROSTER (self_);
YtsRosterPrivate *priv = GET_PRIVATE (self);
- YtsContact *contact;
- YtsService *service;
- YtsServiceFactory *factory = yts_service_factory_get_default ();
+ YtsService *service = YTS_SERVICE (service_);
- g_return_if_fail (YTS_IS_ROSTER (self));
+ if (n_contacts == 0) {
- if (!(contact = (YtsContact*)yts_roster_find_contact_by_jid (self, contact_id)))
- {
- YTS_NOTE (ROSTER, "Creating new contact for %s", contact_id);
+ GError const *error;
- contact = yts_contact_new (priv->client, contact_id);
+ g_return_if_fail (requested_ids && requested_ids[0]);
+ g_return_if_fail (failed_id_errors);
- g_signal_connect (contact, "service-added",
- G_CALLBACK (yts_roster_contact_service_added_cb),
- self);
- g_signal_connect (contact, "service-removed",
- G_CALLBACK (yts_roster_contact_service_removed_cb),
- self);
+ error = g_hash_table_lookup (failed_id_errors, requested_ids[0]);
+ g_critical ("%s : %s", G_STRLOC, error->message);
- g_hash_table_insert (priv->contacts, g_strdup (contact_id), contact);
+ } else {
- YTS_NOTE (ROSTER, "Emitting contact-added for new contact %s", contact_id);
- g_signal_emit (self, _signals[SIG_CONTACT_ADDED], 0, contact);
+ YtsContact *contact;
+ char const *contact_id = requested_ids[0];
+ TpContact *tp_contact = TP_CONTACT (contacts[0]);
- g_signal_connect (contact, "send-message",
- G_CALLBACK (_contact_send_message), self);
- }
+ YTS_NOTE (ROSTER, "Creating new contact for %s", contact_id);
+
+ contact = yts_contact_new (tp_contact);
+
+ g_signal_connect (contact, "service-added",
+ G_CALLBACK (yts_roster_contact_service_added_cb),
+ self);
+ g_signal_connect (contact, "service-removed",
+ G_CALLBACK (yts_roster_contact_service_removed_cb),
+ self);
+
+ g_hash_table_insert (priv->contacts, g_strdup (contact_id), contact);
+
+ YTS_NOTE (ROSTER, "Emitting contact-added for new contact %s", contact_id);
+ g_signal_emit (self, _signals[SIG_CONTACT_ADDED], 0, contact);
+
+ g_signal_connect (contact, "send-message",
+ G_CALLBACK (_contact_send_message), self);
+
+ yts_contact_add_service (contact, service);
+ g_object_unref (service);
+ }
+}
- YTS_NOTE (ROSTER, "Adding service %s:%s", contact_id, service_id);
+void
+yts_roster_add_service (YtsRoster *self,
+ TpConnection *tp_connection,
+ char const *contact_id,
+ char const *service_id,
+ char const *type,
+ char const *const *caps,
+ GHashTable *names,
+ GHashTable *statuses)
+{
+ YtsRosterPrivate *priv = GET_PRIVATE (self);
+ YtsContact *contact;
+ YtsService *service;
+ YtsServiceFactory *factory = yts_service_factory_get_default ();
service = yts_service_factory_create_service (factory,
caps,
@@ -487,9 +525,28 @@ yts_roster_add_service (YtsRoster *self,
names,
statuses);
- yts_contact_add_service (contact, service);
-
- g_object_unref (service);
+ contact = yts_roster_find_contact_by_jid (self, contact_id);
+ if (contact) {
+
+ yts_contact_add_service (contact, service);
+
+ } else {
+
+ TpContactFeature const features[] = { TP_CONTACT_FEATURE_PRESENCE,
+ TP_CONTACT_FEATURE_CONTACT_INFO,
+ TP_CONTACT_FEATURE_AVATAR_DATA,
+ TP_CONTACT_FEATURE_CAPABILITIES };
+
+ tp_connection_get_contacts_by_id (tp_connection,
+ 1,
+ &contact_id,
+ G_N_ELEMENTS (features),
+ features,
+ _connection_get_contacts,
+ self,
+ NULL,
+ G_OBJECT (service));
+ }
}
void