summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2013-01-16 14:47:30 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2013-01-16 14:50:47 +0000
commit2332f4c6c6445616672617b587addc7211d3e99a (patch)
tree7717c69e6454c3b11d987ede75116562b5e88a2a
parent586e2c4b847e8c39a01b648ab24e4cbd44dae67d (diff)
downloadtelepathy-logger-2332f4c6c6445616672617b587addc7211d3e99a.tar.gz
Split legacy Empathy log reader into its own class
My commit eaefb26 introduced a regression: by assuming that any class that implements add_event is writable, logs were being written to the legacy Empathy location. By splitting the legacy location handling into a subclass, we can override add_event to un-implement it and make the subclass read-only, as well as removing special cases from the XML store itself. Thanks to Debarshi Ray for catching this!
-rw-r--r--telepathy-logger/Makefile.am2
-rw-r--r--telepathy-logger/log-manager.c4
-rw-r--r--telepathy-logger/log-store-empathy-internal.h53
-rw-r--r--telepathy-logger/log-store-empathy.c67
-rw-r--r--telepathy-logger/log-store-xml.c27
5 files changed, 125 insertions, 28 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index b875d70..bc1f55a 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -79,6 +79,8 @@ libtelepathy_logger_la_SOURCES = \
log-store-internal.h \
log-store-xml.c \
log-store-xml-internal.h \
+ log-store-empathy.c \
+ log-store-empathy-internal.h \
log-store-sqlite.c \
log-store-sqlite-internal.h \
log-store-pidgin.c \
diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c
index ede6d26..37ff1d4 100644
--- a/telepathy-logger/log-manager.c
+++ b/telepathy-logger/log-manager.c
@@ -38,6 +38,7 @@
#include <telepathy-logger/event.h>
#include <telepathy-logger/event-internal.h>
#include <telepathy-logger/log-store-internal.h>
+#include <telepathy-logger/log-store-empathy-internal.h>
#include <telepathy-logger/log-store-xml-internal.h>
#include <telepathy-logger/log-store-pidgin-internal.h>
#include <telepathy-logger/log-store-sqlite-internal.h>
@@ -280,8 +281,7 @@ tpl_log_manager_init (TplLogManager *self)
/* Load by default the Empathy's legacy 'past coversations' LogStore */
add_log_store (self,
- g_object_new (TPL_TYPE_LOG_STORE_XML,
- "empathy-legacy", TRUE,
+ g_object_new (TPL_TYPE_LOG_STORE_EMPATHY,
NULL));
add_log_store (self,
diff --git a/telepathy-logger/log-store-empathy-internal.h b/telepathy-logger/log-store-empathy-internal.h
new file mode 100644
index 0000000..8022445
--- /dev/null
+++ b/telepathy-logger/log-store-empathy-internal.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2013 Collabora Ltd.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef TPL_LOG_STORE_EMPATHY_H
+#define TPL_LOG_STORE_EMPATHY_H
+
+#include "log-store-xml-internal.h"
+
+typedef struct _TplLogStoreEmpathy TplLogStoreEmpathy;
+typedef struct _TplLogStoreEmpathyClass TplLogStoreEmpathyClass;
+
+struct _TplLogStoreEmpathyClass {
+ TplLogStoreXmlClass parent_class;
+};
+
+struct _TplLogStoreEmpathy {
+ TplLogStoreXml parent;
+};
+
+GType _tpl_log_store_empathy_get_type (void);
+
+/* TYPE MACROS */
+#define TPL_TYPE_LOG_STORE_EMPATHY \
+ (_tpl_log_store_empathy_get_type ())
+#define TPL_LOG_STORE_EMPATHY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), TPL_TYPE_LOG_STORE_EMPATHY, TplLogStoreEmpathy))
+#define TPL_LOG_STORE_EMPATHY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), TPL_TYPE_LOG_STORE_EMPATHY,\
+ TplLogStoreEmpathyClass))
+#define TPL_IS_LOG_STORE_EMPATHY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), TPL_TYPE_LOG_STORE_EMPATHY))
+#define TPL_IS_LOG_STORE_EMPATHY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), TPL_TYPE_LOG_STORE_EMPATHY))
+#define TPL_LOG_STORE_EMPATHY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_STORE_EMPATHY, \
+ TplLogStoreEmpathyClass))
+
+#endif /* TPL_LOG_STORE_EMPATHY_H */
diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c
new file mode 100644
index 0000000..651c721
--- /dev/null
+++ b/telepathy-logger/log-store-empathy.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright ©2013 Collabora Ltd.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * This is a subclass of TplLogStoreXml to read logs from the directory Empathy
+ * used to store them it. It disables writing to that legacy location.
+ */
+
+#include "config.h"
+#include "log-store-empathy-internal.h"
+
+#include "telepathy-logger/log-store-internal.h"
+
+static void log_store_iface_init (gpointer g_iface, gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (TplLogStoreEmpathy, _tpl_log_store_empathy,
+ TPL_TYPE_LOG_STORE_XML,
+ G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init))
+
+static void
+_tpl_log_store_empathy_init (TplLogStoreEmpathy *self)
+{
+}
+
+static void
+_tpl_log_store_empathy_class_init (TplLogStoreEmpathyClass *klass)
+{
+}
+
+
+static const gchar *
+log_store_empathy_get_name (TplLogStore *store)
+{
+ TplLogStoreXml *self = (TplLogStoreXml *) store;
+
+ g_return_val_if_fail (TPL_IS_LOG_STORE_EMPATHY (self), NULL);
+
+ return "Empathy";
+}
+
+static void
+log_store_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface;
+
+ iface->get_name = log_store_empathy_get_name;
+
+ /* We don't want to store new logs in Empathy's directory, just read the old
+ * ones. */
+ iface->add_event = NULL;
+}
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index f9edc22..72d2c4b 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -79,7 +79,6 @@
struct _TplLogStoreXmlPriv
{
gchar *basedir;
- gboolean empathy_legacy;
gboolean test_mode;
TpAccountManager *account_manager;
};
@@ -88,7 +87,6 @@ enum {
PROP_0,
PROP_READABLE,
PROP_BASEDIR,
- PROP_EMPATHY_LEGACY,
PROP_TESTMODE
};
@@ -159,9 +157,6 @@ tpl_log_store_xml_get_property (GObject *object,
case PROP_BASEDIR:
g_value_set_string (value, priv->basedir);
break;
- case PROP_EMPATHY_LEGACY:
- g_value_set_boolean (value, priv->empathy_legacy);
- break;
case PROP_TESTMODE:
g_value_set_boolean (value, priv->test_mode);
break;
@@ -182,9 +177,6 @@ tpl_log_store_xml_set_property (GObject *object,
switch (param_id)
{
- case PROP_EMPATHY_LEGACY:
- self->priv->empathy_legacy = g_value_get_boolean (value);
- break;
case PROP_BASEDIR:
log_store_xml_set_basedir (self, g_value_get_string (value));
break;
@@ -223,20 +215,6 @@ _tpl_log_store_xml_class_init (TplLogStoreXmlClass *klass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_BASEDIR, param_spec);
- /**
- * TplLogStoreXml:empathy-legacy:
- *
- * If %TRUE, the logstore pointed by TplLogStoreXml::base-dir will be
- * considered formatted as an Empathy's LogStore (pre telepathy-logger).
- * Xml: %FALSE.
- */
- param_spec = g_param_spec_boolean ("empathy-legacy",
- "EmpathyLegacy",
- "Enables compatibility with old Empathy's logs",
- FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_EMPATHY_LEGACY,
- param_spec);
-
param_spec = g_param_spec_boolean ("testmode",
"TestMode",
"Whether the logstore is in testmode, for testsuite use only",
@@ -1745,10 +1723,7 @@ log_store_xml_get_name (TplLogStore *store)
g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL);
- if (self->priv->empathy_legacy)
- return "Empathy";
- else
- return "TpLogger";
+ return "TpLogger";
}