diff options
author | Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> | 2009-12-04 21:14:58 -0200 |
---|---|---|
committer | Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> | 2009-12-04 21:14:58 -0200 |
commit | 8fb9c3d6136c533cb5f240740f357647019b22ab (patch) | |
tree | d377aa717c5df7859a962dfd051aa6a40ffb4229 /src | |
parent | 35c657537049f36e2d6fa445008a498dde4c8423 (diff) | |
download | telepathy-logger-8fb9c3d6136c533cb5f240740f357647019b22ab.tar.gz |
Completed importing and refactoring of EmpathyLogStore
* removed any call which would make TPL depending on libempathy
* copied empathy-time.[hc]
* added some empathy's utility function to tpl_utils.[ch]
* added support for automake/autoconf using empathy's one as basis:
currently TPL depends on telepathy-glib and libxmp-2.0 (and theirs
deps)
* added AUTHORS COPYING INSTALL README and NEWS files (empty)
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 108 | ||||
-rwxr-xr-x | src/compile.sh | 12 | ||||
-rw-r--r-- | src/empathy-log-manager.xsl (renamed from src/logstore/empathy-log-manager.xsl) | 0 | ||||
-rw-r--r-- | src/tpl-log-manager.c (renamed from src/logstore/empathy-log-manager.c) | 165 | ||||
-rw-r--r-- | src/tpl-log-store-empathy.c (renamed from src/logstore/tpl-log-store-empathy.c) | 56 | ||||
-rw-r--r-- | src/tpl-log-store.c (renamed from src/logstore/tpl-log-store.c) | 2 | ||||
-rw-r--r-- | src/tpl-time.c | 170 | ||||
-rw-r--r-- | src/tpl_headless_logger_init.c | 2 | ||||
-rw-r--r-- | src/tpl_log_entry_text.c | 20 | ||||
-rw-r--r-- | src/tpl_observer.c | 19 | ||||
-rw-r--r-- | src/tpl_text_channel_data.c | 26 |
11 files changed, 461 insertions, 119 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..6564061 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,108 @@ +include $(top_srcdir)/tools/shave.mk +include $(top_srcdir)/tools/flymake.mk + +AM_CPPFLAGS = \ + $(ERROR_CFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/include \ + -DG_LOG_DOMAIN=\"tpl\" \ + $(TPL_CFLAGS) \ + $(LIBTPL_CFLAGS) \ + $(DISABLE_DEPRECATED) \ + $(WARN_CFLAGS) + +LDADD = \ + $(TPL_LIBS) \ + $(LIBTPL_LIBS) +# $(top_builddir)/libempathy-gtk/libempathy-gtk.la \ +# $(top_builddir)/libempathy/libempathy.la \ +# $(top_builddir)/extensions/libemp-extensions.la \ +# $(LIBNOTIFY_LIBS) \ +# $(LIBCHAMPLAIN_LIBS) \ +# $(WEBKIT_LIBS) + +bin_PROGRAMS = \ + telepathy-logger + +BUILT_SOURCES= +# empathy-tube-dispatch-enumtypes.h \ +# empathy-tube-dispatch-enumtypes.c + +telepathy_logger_handwritten_source = \ + test.c \ + tpl_channel_data.c \ + tpl_contact.c \ + tpl_headless_logger_init.c \ + tpl_log_entry_text.c \ + tpl_observer.c \ + tpl_text_channel_data.c \ + tpl-time.c \ + tpl_utils.c \ + tpl-log-manager.c \ + tpl-log-store.c \ + tpl-log-store-empathy.c + +telepathy_logger_SOURCES = \ + $(telepathy_logger_handwritten_source) + +nodist_telepathy_logger_SOURCES = $(BUILT_SOURCES) + +check_c_sources = \ + $(telepathy_logger_handwritten_source) \ + $(telepathy_logger_logs_SOURCES) +include $(top_srcdir)/tools/check-coding-style.mk +check-local: check-coding-style + +#DISABLED#uidir = $(datadir)/telepathy-logger +#DISABLED#ui_DATA = \ +#DISABLED# empathy-accounts-dialog.ui \ +#DISABLED# empathy-call-window-fullscreen.ui \ +#DISABLED# empathy-call-window.ui \ +#DISABLED# empathy-chat-window.ui \ +#DISABLED# empathy-chatrooms-window.ui \ +#DISABLED# empathy-ft-manager.ui \ +#DISABLED# empathy-import-dialog.ui \ +#DISABLED# empathy-main-window.ui \ +#DISABLED# empathy-new-chatroom-dialog.ui \ +#DISABLED# empathy-preferences.ui \ +#DISABLED# empathy-status-icon.ui + +EXTRA_DIST = \ + $(autostart_DATA) \ + $(ui_DATA) + +#DISABLED#if HAVE_LIBCHAMPLAIN +#DISABLED#empathy_handwritten_source += \ +#DISABLED# empathy-map-view.c \ +#DISABLED# empathy-map-view.h +#DISABLED# +#DISABLED#ui_DATA += \ +#DISABLED# empathy-map-view.ui +#DISABLED#else +#DISABLED#EXTRA_DIST += \ +#DISABLED# empathy-map-view.c \ +#DISABLED# empathy-map-view.h \ +#DISABLED# empathy-map-view.ui +#DISABLED#endif + +dist_man_MANS = + +# rules for making the glib enum objects +%-enumtypes.h: %.h Makefile.in + $(QUIET_GEN)glib-mkenums \ + --fhead "#ifndef __$(shell echo $* | tr [:lower:]- [:upper:]_)_ENUM_TYPES_H__\n#define __$(shell echo $* | tr [:lower:]- [:upper:]_)_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \ + --fprod "/* enumerations from \"@filename@\" */\n" \ + --vhead "GType @enum_name@_get_type (void);\n#define $(shell echo $* | tr [:lower:]- [:upper:]_ | sed 's/_.*//')_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ + --ftail "G_END_DECLS\n\n#endif /* __$(shell echo $* | tr [:lower:]- [:upper:]_)_ENUM_TYPES_H__ */" \ + $< > $@ + +%-enumtypes.c: %.h Makefile.in + $(QUIET_GEN)glib-mkenums \ + --fhead "#include <$*.h>\n#include <$*-enumtypes.h>" \ + --fprod "\n/* enumerations from \"@filename@\" */" \ + --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ + --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@VALUENAME@\" }," \ + --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \ + $< > $@ + +CLEANFILES = $(BUILT_SOURCES) diff --git a/src/compile.sh b/src/compile.sh index 53062d2..27548cb 100755 --- a/src/compile.sh +++ b/src/compile.sh @@ -2,17 +2,19 @@ PACKAGE_NAME="TpLogger" CC=${CC:-gcc} -CCOPTS="-DPACKAGE_NAME=\"${PACKAGE_NAME}\" --std=c99 -g -I/usr/include/libempathy -I../include -Wall -Werror" # -pedantic" -PKGS="telepathy-glib libempathy" +CCOPTS="-D__USE_POSIX -DPACKAGE_NAME=\"${PACKAGE_NAME}\" --std=c99 -g -I../include -Wall -Werror" # -pedantic" +PKGS="telepathy-glib libxml-2.0" MODULES="tpl_observer.c tpl_headless_logger_init.c tpl_channel_data.c tpl_text_channel_data.c tpl_contact.c tpl_utils.c - logstore/tpl-log-store.c - logstore/tpl-log-store-empathy.c + tpl-time.c + tpl-log-manager.c + tpl-log-store.c + tpl-log-store-empathy.c tpl_log_entry_text.c test.c" -EXECUTABLE="test" +EXECUTABLE="telepathy-logger" ${CC} ${CCOPTS} $(pkg-config --libs --cflags ${PKGS}) ${MODULES} \ diff --git a/src/logstore/empathy-log-manager.xsl b/src/empathy-log-manager.xsl index a934f3a..a934f3a 100644 --- a/src/logstore/empathy-log-manager.xsl +++ b/src/empathy-log-manager.xsl diff --git a/src/logstore/empathy-log-manager.c b/src/tpl-log-manager.c index 07ea521..642733a 100644 --- a/src/logstore/empathy-log-manager.c +++ b/src/tpl-log-manager.c @@ -34,26 +34,29 @@ #include <tpl-log-manager.h> #include <tpl-log-store-empathy.h> #include <tpl-log-store.h> -#include <empathy-tp-chat.h> -#include <empathy-utils.h> +#include <tpl_utils.h> +#include <tpl-time.h> +//#include <empathy-tp-chat.h> -#define DEBUG_FLAG EMPATHY_DEBUG_OTHER -#include <empathy-debug.h> +//#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +//#include <empathy-debug.h> -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLogManager) +#define DEBUG g_debug + +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogManager) typedef struct { GList *stores; -} EmpathyLogManagerPriv; +} TplLogManagerPriv; -G_DEFINE_TYPE (EmpathyLogManager, empathy_log_manager, G_TYPE_OBJECT); +G_DEFINE_TYPE (TplLogManager, tpl_log_manager, G_TYPE_OBJECT); -static EmpathyLogManager * manager_singleton = NULL; +static TplLogManager * manager_singleton = NULL; static void log_manager_finalize (GObject *object) { - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; priv = GET_PRIV (object); @@ -67,7 +70,7 @@ log_manager_constructor (GType type, GObjectConstructParam *props) { GObject *retval; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; if (manager_singleton) { @@ -75,75 +78,75 @@ log_manager_constructor (GType type, } else { - retval = G_OBJECT_CLASS (empathy_log_manager_parent_class)->constructor + retval = G_OBJECT_CLASS (tpl_log_manager_parent_class)->constructor (type, n_props, props); - manager_singleton = EMPATHY_LOG_MANAGER (retval); + manager_singleton = TPL_LOG_MANAGER (retval); g_object_add_weak_pointer (retval, (gpointer *) &manager_singleton); priv = GET_PRIV (manager_singleton); priv->stores = g_list_append (priv->stores, - g_object_new (EMPATHY_TYPE_LOG_STORE_EMPATHY, NULL)); + g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, NULL)); } return retval; } static void -empathy_log_manager_class_init (EmpathyLogManagerClass *klass) +tpl_log_manager_class_init (TplLogManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = log_manager_constructor; object_class->finalize = log_manager_finalize; - g_type_class_add_private (object_class, sizeof (EmpathyLogManagerPriv)); + g_type_class_add_private (object_class, sizeof (TplLogManagerPriv)); } static void -empathy_log_manager_init (EmpathyLogManager *manager) +tpl_log_manager_init (TplLogManager *manager) { - EmpathyLogManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, - EMPATHY_TYPE_LOG_MANAGER, EmpathyLogManagerPriv); + TplLogManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, + TPL_TYPE_LOG_MANAGER, TplLogManagerPriv); manager->priv = priv; } -EmpathyLogManager * -empathy_log_manager_dup_singleton (void) +TplLogManager * +tpl_log_manager_dup_singleton (void) { - return g_object_new (EMPATHY_TYPE_LOG_MANAGER, NULL); + return g_object_new (TPL_TYPE_LOG_MANAGER, NULL); } gboolean -empathy_log_manager_add_message (EmpathyLogManager *manager, +tpl_log_manager_add_message (TplLogManager *manager, const gchar *chat_id, gboolean chatroom, - EmpathyMessage *message, + TplLogEntryText *message, GError **error) { - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; GList *l; gboolean out = FALSE; gboolean found = FALSE; /* TODO: When multiple log stores appear with add_message implementations * make this customisable. */ - const gchar *add_store = "Empathy"; + const gchar *add_store = "TpLogger"; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), FALSE); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); - g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE); + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (message), FALSE); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - if (!tp_strdiff (empathy_log_store_get_name ( - EMPATHY_LOG_STORE (l->data)), add_store)) + if (!tp_strdiff (tpl_log_store_get_name ( + TPL_LOG_STORE (l->data)), add_store)) { - out = empathy_log_store_add_message (EMPATHY_LOG_STORE (l->data), + out = tpl_log_store_add_message (TPL_LOG_STORE (l->data), chat_id, chatroom, message, error); found = TRUE; break; @@ -157,22 +160,22 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, } gboolean -empathy_log_manager_exists (EmpathyLogManager *manager, +tpl_log_manager_exists (TplLogManager *manager, TpAccount *account, const gchar *chat_id, gboolean chatroom) { GList *l; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), FALSE); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - if (empathy_log_store_exists (EMPATHY_LOG_STORE (l->data), + if (tpl_log_store_exists (TPL_LOG_STORE (l->data), account, chat_id, chatroom)) return TRUE; } @@ -181,27 +184,27 @@ empathy_log_manager_exists (EmpathyLogManager *manager, } GList * -empathy_log_manager_get_dates (EmpathyLogManager *manager, +tpl_log_manager_get_dates (TplLogManager *manager, TpAccount *account, const gchar *chat_id, gboolean chatroom) { GList *l, *out = NULL; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); + TplLogStore *store = TPL_LOG_STORE (l->data); GList *new; /* Insert dates of each store in the out list. Keep the out list sorted * and avoid to insert dups. */ - new = empathy_log_store_get_dates (store, account, chat_id, chatroom); + new = tpl_log_store_get_dates (store, account, chat_id, chatroom); while (new) { if (g_list_find_custom (out, new->data, (GCompareFunc) strcmp)) @@ -217,25 +220,25 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager, } GList * -empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, +tpl_log_manager_get_messages_for_date (TplLogManager *manager, TpAccount *account, const gchar *chat_id, gboolean chatroom, const gchar *date) { GList *l, *out = NULL; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); + TplLogStore *store = TPL_LOG_STORE (l->data); - out = g_list_concat (out, empathy_log_store_get_messages_for_date ( + out = g_list_concat (out, tpl_log_store_get_messages_for_date ( store, account, chat_id, chatroom, date)); } @@ -246,32 +249,32 @@ static gint log_manager_message_date_cmp (gconstpointer a, gconstpointer b) { - EmpathyMessage *one = (EmpathyMessage *) a; - EmpathyMessage *two = (EmpathyMessage *) b; + TplLogEntryText *one = (TplLogEntryText *) a; + TplLogEntryText *two = (TplLogEntryText *) b; time_t one_time, two_time; - one_time = empathy_message_get_timestamp (one); - two_time = empathy_message_get_timestamp (two); + one_time = tpl_log_entry_text_get_timestamp (one); + two_time = tpl_log_entry_text_get_timestamp (two); /* Return -1 of message1 is older than message2 */ return one_time < two_time ? -1 : one_time - two_time; } GList * -empathy_log_manager_get_filtered_messages (EmpathyLogManager *manager, +tpl_log_manager_get_filtered_messages (TplLogManager *manager, TpAccount *account, const gchar *chat_id, gboolean chatroom, guint num_messages, - EmpathyLogMessageFilter filter, + TplLogMessageFilter filter, gpointer user_data) { - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; GList *out = NULL; GList *l; guint i = 0; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); priv = GET_PRIV (manager); @@ -280,10 +283,10 @@ empathy_log_manager_get_filtered_messages (EmpathyLogManager *manager, * newest ones in the out list. Keep that list sorted: Older first. */ for (l = priv->stores; l; l = g_list_next (l)) { - EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); + TplLogStore *store = TPL_LOG_STORE (l->data); GList *new; - new = empathy_log_store_get_filtered_messages (store, account, chat_id, + new = tpl_log_store_get_filtered_messages (store, account, chat_id, chatroom, num_messages, filter, user_data); while (new) { @@ -318,52 +321,52 @@ empathy_log_manager_get_filtered_messages (EmpathyLogManager *manager, } GList * -empathy_log_manager_get_chats (EmpathyLogManager *manager, +tpl_log_manager_get_chats (TplLogManager *manager, TpAccount *account) { GList *l, *out = NULL; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); + TplLogStore *store = TPL_LOG_STORE (l->data); out = g_list_concat (out, - empathy_log_store_get_chats (store, account)); + tpl_log_store_get_chats (store, account)); } return out; } GList * -empathy_log_manager_search_new (EmpathyLogManager *manager, +tpl_log_manager_search_new (TplLogManager *manager, const gchar *text) { GList *l, *out = NULL; - EmpathyLogManagerPriv *priv; + TplLogManagerPriv *priv; - g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (!EMP_STR_EMPTY (text), NULL); + g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); priv = GET_PRIV (manager); for (l = priv->stores; l; l = g_list_next (l)) { - EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); + TplLogStore *store = TPL_LOG_STORE (l->data); out = g_list_concat (out, - empathy_log_store_search_new (store, text)); + tpl_log_store_search_new (store, text)); } return out; } void -empathy_log_manager_search_hit_free (EmpathyLogSearchHit *hit) +tpl_log_manager_search_hit_free (TplLogSearchHit *hit) { if (hit->account != NULL) g_object_unref (hit->account); @@ -372,17 +375,17 @@ empathy_log_manager_search_hit_free (EmpathyLogSearchHit *hit) g_free (hit->filename); g_free (hit->chat_id); - g_slice_free (EmpathyLogSearchHit, hit); + g_slice_free (TplLogSearchHit, hit); } void -empathy_log_manager_search_free (GList *hits) +tpl_log_manager_search_free (GList *hits) { GList *l; for (l = hits; l; l = g_list_next (l)) { - empathy_log_manager_search_hit_free (l->data); + tpl_log_manager_search_hit_free (l->data); } g_list_free (hits); @@ -390,19 +393,20 @@ empathy_log_manager_search_free (GList *hits) /* Format is just date, 20061201. */ gchar * -empathy_log_manager_get_date_readable (const gchar *date) +tpl_log_manager_get_date_readable (const gchar *date) { time_t t; - t = empathy_time_parse (date); + t = tpl_time_parse (date); - return empathy_time_to_string_local (t, "%a %d %b %Y"); + return tpl_time_to_string_local (t, "%a %d %b %Y"); } +/* TPL: useless TODO remove static void log_manager_chat_received_message_cb (EmpathyTpChat *tp_chat, - EmpathyMessage *message, - EmpathyLogManager *log_manager) + TplLogEntryText *message, + TplLogManager *log_manager) { GError *error = NULL; TpHandleType handle_type; @@ -411,7 +415,7 @@ log_manager_chat_received_message_cb (EmpathyTpChat *tp_chat, channel = empathy_tp_chat_get_channel (tp_chat); tp_channel_get_handle (channel, &handle_type); - if (!empathy_log_manager_add_message (log_manager, + if (!tpl_log_manager_add_message (log_manager, tp_channel_get_identifier (channel), handle_type == TP_HANDLE_TYPE_ROOM, message, &error)) @@ -423,11 +427,13 @@ log_manager_chat_received_message_cb (EmpathyTpChat *tp_chat, g_error_free (error); } } +*/ +/* TPL: useless TODO remove static void log_manager_dispatcher_observe_cb (EmpathyDispatcher *dispatcher, EmpathyDispatchOperation *operation, - EmpathyLogManager *log_manager) + TplLogManager *log_manager) { GQuark channel_type; @@ -444,12 +450,13 @@ log_manager_dispatcher_observe_cb (EmpathyDispatcher *dispatcher, G_CALLBACK (log_manager_chat_received_message_cb), log_manager); } } - - +*/ +/* void -empathy_log_manager_observe (EmpathyLogManager *log_manager, +tpl_log_manager_observe (TplLogManager *log_manager, EmpathyDispatcher *dispatcher) { g_signal_connect (dispatcher, "observe", G_CALLBACK (log_manager_dispatcher_observe_cb), log_manager); } +*/ diff --git a/src/logstore/tpl-log-store-empathy.c b/src/tpl-log-store-empathy.c index 0409cfb..4fde4ff 100644 --- a/src/logstore/tpl-log-store-empathy.c +++ b/src/tpl-log-store-empathy.c @@ -29,6 +29,9 @@ #include <stdlib.h> #include <glib/gstdio.h> +#include <libxml/parser.h> +#include <libxml/tree.h> + #include <glib-object.h> #include <telepathy-glib/account-manager.h> @@ -39,15 +42,15 @@ #include <tpl-log-store.h> #include <tpl-log-store-empathy.h> #include <tpl-log-manager.h> -#include <empathy-contact.h> -#include <empathy-time.h> -#include <empathy-utils.h> +#include <tpl-time.h> #include <tpl_log_entry_text.h> #include <tpl_contact.h> -#define DEBUG_FLAG EMPATHY_DEBUG_OTHER -#include <empathy-debug.h> +//#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +//#include <empathy-debug.h> + +#define DEBUG g_debug #define LOG_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR) #define LOG_FILE_CREATE_MODE (S_IRUSR | S_IWUSR) @@ -64,7 +67,7 @@ "</log>\n" -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, TplLogStoreEmpathy) +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogStoreEmpathy) typedef struct { gchar *basedir; @@ -108,8 +111,10 @@ tpl_log_store_empathy_init (TplLogStoreEmpathy *self) self->priv = priv; priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), - PACKAGE_NAME, "logs", NULL); + "TpLogger", "logs", NULL); + // TODO update to a more meaningful name when more than one LogStore + // implementation will exist, like TpXMLLogger and TPSQLiteLogger priv->name = g_strdup ("TpLogger"); priv->account_manager = tp_account_manager_dup (); } @@ -160,8 +165,8 @@ log_store_empathy_get_timestamp_filename (void) gchar *time_str; gchar *filename; - t = empathy_time_get_current (); - time_str = empathy_time_to_string_local (t, LOG_TIME_FORMAT); + t = tpl_time_get_current (); + time_str = tpl_time_to_string_local (t, LOG_TIME_FORMAT); filename = g_strconcat (time_str, LOG_FILENAME_SUFFIX, NULL); g_free (time_str); @@ -177,7 +182,7 @@ log_store_empathy_get_timestamp_from_message (TplLogEntryText *message) t = tpl_log_entry_text_get_timestamp (message); /* We keep the timestamps in the messages as UTC. */ - return empathy_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); + return tpl_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); } static gchar * @@ -232,8 +237,7 @@ log_store_empathy_add_message (TplLogStore *self, body_str = tpl_log_entry_text_get_message (message); msg_type = tpl_log_entry_text_get_message_type (message); - - if (EMP_STR_EMPTY (body_str)) + if (TPL_STR_EMPTY (body_str)) return FALSE; filename = log_store_empathy_get_filename (self, account, chat_id, chatroom); @@ -386,12 +390,12 @@ log_store_empathy_get_filename_for_date (TplLogStore *self, return filename; } -static EmpathyLogSearchHit * +static TplLogSearchHit * log_store_empathy_search_hit_new (TplLogStore *self, const gchar *filename) { TplLogStoreEmpathyPriv *priv = GET_PRIV (self); - EmpathyLogSearchHit *hit; + TplLogSearchHit *hit; gchar *account_name; const gchar *end; gchar **strv; @@ -404,7 +408,7 @@ log_store_empathy_search_hit_new (TplLogStore *self, strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); len = g_strv_length (strv); - hit = g_slice_new0 (EmpathyLogSearchHit); + hit = g_slice_new0 (TplLogSearchHit); end = strstr (strv[len-1], LOG_FILENAME_SUFFIX); hit->date = g_strndup (strv[len-1], end - strv[len-1]); @@ -495,7 +499,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, time_t t; gchar *sender_id; gchar *sender_name; - gchar *sender_avatar_token; + //gchar *sender_avatar_token; gchar *body; gchar *is_user_str; gboolean is_user = FALSE; @@ -511,8 +515,10 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, time_ = (gchar *) xmlGetProp (node, (const xmlChar *) "time"); sender_id = (gchar *) xmlGetProp (node, (const xmlChar *) "id"); sender_name = (gchar *) xmlGetProp (node, (const xmlChar *) "name"); + /* sender_avatar_token = (gchar *) xmlGetProp (node, (const xmlChar *) "token"); + */ is_user_str = (gchar *) xmlGetProp (node, (const xmlChar *) "isuser"); msg_type_str = (gchar *) xmlGetProp (node, (const xmlChar *) "type"); cm_id_str = (gchar *) xmlGetProp (node, (const xmlChar *) "cm_id"); @@ -521,12 +527,12 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, is_user = strcmp (is_user_str, "true") == 0; if (msg_type_str) - msg_type = empathy_message_type_from_str (msg_type_str); + msg_type = tpl_log_entry_text_message_type_from_str (msg_type_str); if (cm_id_str) cm_id = atoi (cm_id_str); - t = empathy_time_parse (time_); + t = tpl_time_parse (time_); //TODO remove me //sender = empathy_contact_new_for_log (account, sender_id, sender_name, // is_user); @@ -536,7 +542,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, tpl_contact_set_alias(sender, sender_name); /* TODO remove avatar code - if (!EMP_STR_EMPTY (sender_avatar_token)) + if (!TPL_STR_EMPTY (sender_avatar_token)) empathy_contact_load_avatar_cache (sender, sender_avatar_token); */ @@ -562,7 +568,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, xmlFree (is_user_str); xmlFree (msg_type_str); xmlFree (cm_id_str); - xmlFree (sender_avatar_token); + //xmlFree (sender_avatar_token); } DEBUG ("Parsed %d messages", g_list_length (messages)); @@ -626,7 +632,7 @@ log_store_empathy_search_new (TplLogStore *self, gchar *text_casefold; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (!EMP_STR_EMPTY (text), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); text_casefold = g_utf8_casefold (text, -1); @@ -655,7 +661,7 @@ log_store_empathy_search_new (TplLogStore *self, if (strstr (contents_casefold, text_casefold)) { - EmpathyLogSearchHit *hit; + TplLogSearchHit *hit; hit = log_store_empathy_search_hit_new (self, filename); @@ -697,7 +703,7 @@ log_store_empathy_get_chats_for_dir (TplLogStore *self, while ((name = g_dir_read_name (gdir)) != NULL) { - EmpathyLogSearchHit *hit; + TplLogSearchHit *hit; if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) { @@ -707,7 +713,7 @@ log_store_empathy_get_chats_for_dir (TplLogStore *self, g_free (filename); continue; } - hit = g_slice_new0 (EmpathyLogSearchHit); + hit = g_slice_new0 (TplLogSearchHit); hit->chat_id = g_strdup (name); hit->is_chatroom = is_chatroom; @@ -776,7 +782,7 @@ log_store_empathy_get_filtered_messages (TplLogStore *self, const gchar *chat_id, gboolean chatroom, guint num_messages, - EmpathyLogMessageFilter filter, + TplLogMessageFilter filter, gpointer user_data) { GList *dates, *l, *messages = NULL; diff --git a/src/logstore/tpl-log-store.c b/src/tpl-log-store.c index 0e439d4..d9d62cc 100644 --- a/src/logstore/tpl-log-store.c +++ b/src/tpl-log-store.c @@ -161,7 +161,7 @@ tpl_log_store_get_filtered_messages (TplLogStore *self, const gchar *chat_id, gboolean chatroom, guint num_messages, - EmpathyLogMessageFilter filter, + TplLogMessageFilter filter, gpointer user_data) { diff --git a/src/tpl-time.c b/src/tpl-time.c new file mode 100644 index 0000000..e35c6c8 --- /dev/null +++ b/src/tpl-time.c @@ -0,0 +1,170 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Richard Hult <richard@imendio.com> + */ + +#include <time.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <glib/gi18n.h> + +#include <tpl-time.h> + +/* Note: TplTime is always in UTC. */ + +time_t +tpl_time_get_current (void) +{ + return time (NULL); +} + +time_t +tpl_time_get_local_time (struct tm *tm) +{ + const gchar *tz; + time_t t; + + tz = g_getenv ("TZ"); + g_setenv ("TZ", "", TRUE); + + //TODO reenable + //tzset (); + + t = mktime (tm); + + if (tz) { + g_setenv ("TZ", tz, TRUE); + } else { + g_unsetenv ("TZ"); + } + + //TODO reenable + //tzset (); + + return t; +} + +/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on + * failure. The alternative format "20021209" is also accepted. + */ +time_t +tpl_time_parse (const gchar *str) +{ + struct tm tm; + gint year, month; + gint n_parsed; + + memset (&tm, 0, sizeof (struct tm)); + + n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d", + &year, &month, &tm.tm_mday, &tm.tm_hour, + &tm.tm_min, &tm.tm_sec); + if (n_parsed != 3 && n_parsed != 6) { + return 0; + } + + tm.tm_year = year - 1900; + tm.tm_mon = month - 1; + tm.tm_isdst = -1; + + return tpl_time_get_local_time (&tm); +} + +/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */ +gchar * +tpl_time_to_string_utc (time_t t, + const gchar *format) +{ + gchar stamp[128]; + struct tm *tm; + + g_return_val_if_fail (format != NULL, NULL); + + tm = gmtime (&t); + if (strftime (stamp, sizeof (stamp), format, tm) == 0) { + return NULL; + } + + return g_strdup (stamp); +} + +/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */ +gchar * +tpl_time_to_string_local (time_t t, + const gchar *format) +{ + gchar stamp[128]; + struct tm *tm; + + g_return_val_if_fail (format != NULL, NULL); + + tm = localtime (&t); + if (strftime (stamp, sizeof (stamp), format, tm) == 0) { + return NULL; + } + + return g_strdup (stamp); +} + +gchar * +tpl_time_to_string_relative (time_t then) +{ + time_t now; + gint seconds; + + now = time (NULL); + seconds = now - then; + + if (seconds > 0) { + if (seconds < 60) { + return g_strdup_printf (ngettext ("%d second ago", + "%d seconds ago", seconds), seconds); + } + else if (seconds < (60 * 60)) { + seconds /= 60; + return g_strdup_printf (ngettext ("%d minute ago", + "%d minutes ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24)) { + seconds /= 60 * 60; + return g_strdup_printf (ngettext ("%d hour ago", + "%d hours ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24 * 7)) { + seconds /= 60 * 60 * 24; + return g_strdup_printf (ngettext ("%d day ago", + "%d days ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24 * 30)) { + seconds /= 60 * 60 * 24 * 7; + return g_strdup_printf (ngettext ("%d week ago", + "%d weeks ago", seconds), seconds); + } + else { + seconds /= 60 * 60 * 24 * 30; + return g_strdup_printf (ngettext ("%d month ago", + "%d months ago", seconds), seconds); + } + } + else { + return g_strdup (_("in the future")); + } +} diff --git a/src/tpl_headless_logger_init.c b/src/tpl_headless_logger_init.c index a7b630d..1f9061d 100644 --- a/src/tpl_headless_logger_init.c +++ b/src/tpl_headless_logger_init.c @@ -5,7 +5,7 @@ #include <tpl_observer.h> -#include <empathy-log-store-empathy.h> +#include <tpl-log-store-empathy.h> /* * Initialization of TPL (TelePathy Logger), it futurely set all the diff --git a/src/tpl_log_entry_text.c b/src/tpl_log_entry_text.c index d94324a..66bd071 100644 --- a/src/tpl_log_entry_text.c +++ b/src/tpl_log_entry_text.c @@ -22,6 +22,26 @@ TplLogEntryText *tpl_log_entry_text_new(void) { +TpChannelTextMessageType +tpl_log_entry_text_message_type_from_str (const gchar *type_str) +{ + if (g_strcmp0 (type_str, "normal") == 0) { + return TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; + } + if (g_strcmp0 (type_str, "action") == 0) { + return TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION; + } + else if (g_strcmp0 (type_str, "notice") == 0) { + return TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE; + } + else if (g_strcmp0 (type_str, "auto-reply") == 0) { + return TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY; + } + + return TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; +} + + const gchar *tpl_log_entry_text_message_type_to_str (TpChannelTextMessageType msg_type) { switch (msg_type) { diff --git a/src/tpl_observer.c b/src/tpl_observer.c index 9842159..49ce80a 100644 --- a/src/tpl_observer.c +++ b/src/tpl_observer.c @@ -32,6 +32,13 @@ enum PROP_CHANNEL_FILTER }; +void _observe_channel_when_ready_cb(TpChannel *channel, + const GError *error, + gpointer user_data); +void _tp_connection_called_when_ready_cb(TpConnection *connection, + const GError *error, + gpointer user_data); + void _observe_channel_when_ready_cb(TpChannel *channel, const GError *error, @@ -121,8 +128,7 @@ tpl_observer_observe_channels (TpSvcClientObserver *self, } /* channels is of type a(oa{sv}) */ - int i; - for (i = 0; i < channels->len; i++) + for (guint i = 0; i < channels->len; i++) { GValueArray *channel = g_ptr_array_index (channels, i); TpChannel *tp_chan = NULL; @@ -162,6 +168,8 @@ tpl_observer_get_property (GObject *self, g_print(" :: get_property\n"); switch (property_id) { + GPtrArray *array; + GHashTable *map; case PROP_INTERFACES: g_print (" :: interfaces\n"); g_value_set_boxed (value, client_interfaces); @@ -171,8 +179,8 @@ tpl_observer_get_property (GObject *self, g_print (" :: channel-filter\n"); /* create an empty filter - which means all channels */ - GPtrArray *array = g_ptr_array_new (); - GHashTable *map = g_hash_table_new (NULL, NULL); + array = g_ptr_array_new (); + map = g_hash_table_new (NULL, NULL); g_ptr_array_add (array, map); g_value_set_boxed (value, array); @@ -189,8 +197,6 @@ tpl_observer_class_init (TplObserverClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = tpl_observer_get_property; - /* D-Bus properties are exposed as GObject properties through the * TpDBusPropertiesMixin */ /* properties on the Client interface */ @@ -219,6 +225,7 @@ tpl_observer_class_init (TplObserverClass *klass) }, { NULL } }; + object_class->get_property = tpl_observer_get_property; g_object_class_install_property (object_class, PROP_INTERFACES, g_param_spec_boxed ("interfaces", diff --git a/src/tpl_text_channel_data.c b/src/tpl_text_channel_data.c index de5e922..da8a51e 100644 --- a/src/tpl_text_channel_data.c +++ b/src/tpl_text_channel_data.c @@ -33,6 +33,24 @@ void _channel_on_sent_signal_cb (TpChannel *proxy, const gchar *arg_Text, gpointer user_data, GObject *weak_object); +void _channel_on_received_signal_cb (TpChannel *proxy, + guint arg_ID, + guint arg_Timestamp, + guint arg_Sender, + guint arg_Type, + guint arg_Flags, + const gchar *arg_Text, + gpointer user_data, + GObject *weak_object); +void _tpl_text_channel_connect_signals(TplTextChannel* self); +void _tpl_text_channel_set_ready_cb(TpConnection *connection, + guint n_contacts, + TpContact * const *contacts, + guint n_failed, + const TpHandle *failed, + const GError *error, + gpointer user_data, + GObject *weak_object); /* end of definitions */ @@ -58,7 +76,7 @@ void _channel_on_sent_signal_cb (TpChannel *proxy, TplLogEntryText *log; TplLogStoreEmpathy *logstore; - + /* Initialize data for TplContact */ me = tpl_text_channel_get_my_contact(tpl_text); remote = tpl_text_channel_get_remote_contact(tpl_text); @@ -99,6 +117,8 @@ void _channel_on_sent_signal_cb (TpChannel *proxy, arg_Text); + /* Initialize TplLogEntryText */ + log = tpl_log_entry_text_new(); tpl_log_entry_text_set_tpl_channel(log, tpl_text_channel_get_tpl_channel(tpl_text)); @@ -111,6 +131,7 @@ void _channel_on_sent_signal_cb (TpChannel *proxy, tpl_log_entry_text_set_timestamp(log, (time_t) arg_Timestamp); tpl_log_entry_text_set_id(log, 123); + /* Initialized LogStore and send the message */ logstore = g_object_new(TPL_TYPE_LOG_STORE_EMPATHY, NULL); if (!TPL_LOG_STORE_GET_INTERFACE(logstore)->add_message) { @@ -200,7 +221,8 @@ void _channel_on_received_signal_cb (TpChannel *proxy, /* connect signals to TplTextChannel instance */ -void _tpl_text_channel_connect_signals(TplTextChannel* self) { +void _tpl_text_channel_connect_signals(TplTextChannel* self) +{ GError *error=NULL; // Signals for Text channels // "lost-message" : Run Last / Has Details |