[gedit] Added Zeitgeist dataprovider plugin
- From: Siegfried-Angel Gevatter Pujals <sgevatter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Added Zeitgeist dataprovider plugin
- Date: Sun, 13 Feb 2011 17:25:55 +0000 (UTC)
commit b10d7f92a220aa44fcbda6cf9b42fb31d1bfaacb
Author: Michal Hruby <michal mhr gmail com>
Date: Thu Feb 10 12:41:10 2011 +0100
Added Zeitgeist dataprovider plugin
configure.ac | 25 ++
plugins/Makefile.am | 7 +-
plugins/zeitgeist/Makefile.am | 31 +++
plugins/zeitgeist/gedit-zeitgeist-plugin.c | 356 +++++++++++++++++++++++++
plugins/zeitgeist/gedit-zeitgeist-plugin.h | 65 +++++
plugins/zeitgeist/zeitgeist.plugin.desktop.in | 9 +
po/POTFILES.in | 1 +
7 files changed, 493 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ee9e793..e7d6563 100644
--- a/configure.ac
+++ b/configure.ac
@@ -272,6 +272,29 @@ fi
AM_CONDITIONAL(ENABLE_ENCHANT, test x"$enable_enchant" = "xyes")
dnl ================================================================
+dnl libzeitgeit check: for zeitgeist plugin
+dnl ================================================================
+
+LIBZEITGEIST_REQUIRED=0.3.2
+
+AC_ARG_ENABLE([zeitgeist],
+ AS_HELP_STRING([--enable-indicator[=@<:@no/auto/yes@:>@]],[Build with zeitgeist support]),
+ [enable_zeitgeist=$enableval],
+ [enable_zeitgeist="auto"])
+
+if test "x$enable_zeitgeist" = "xauto" ; then
+ PKG_CHECK_EXISTS([zeitgeist-1.0 >= $LIBZEITGEIST_REQUIRED], \
+ enable_zeitgeist="yes", enable_zeitgeist="no")
+fi
+
+if test "x$enable_zeitgeist" = "xyes" ; then
+ PKG_CHECK_MODULES(ZEITGEIST, \
+ [zeitgeist-1.0 >= $LIBZEITGEIST_REQUIRED])
+fi
+
+AM_CONDITIONAL(ENABLE_ZEITGEIST, test x"$enable_zeitgeist" = "xyes")
+
+dnl ================================================================
dnl Start of pkg-config checks
dnl ================================================================
@@ -444,6 +467,7 @@ plugins/sort/Makefile
plugins/spell/Makefile
plugins/time/org.gnome.gedit.plugins.time.gschema.xml.in
plugins/time/Makefile
+plugins/zeitgeist/Makefile
po/Makefile.in
tests/Makefile
win32/gedit.iss
@@ -464,6 +488,7 @@ Configuration:
Deprecations enabled: $enable_deprecations
GObject Introspection: $enable_introspection
GDK Backend: $gdk_windowing
+ Zeitgeist support: $enable_zeitgeist
"
if expr ${GEDIT_MINOR_VERSION} % 2 > /dev/null; then
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 63272bc..961b5fe 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -10,7 +10,8 @@ DIST_SUBDIRS = \
snippets \
sort \
spell \
- time
+ time \
+ zeitgeist
SUBDIRS = \
changecase \
@@ -36,4 +37,8 @@ if ENABLE_UPDATER
SUBDIRS += checkupdate
endif
+if ENABLE_ZEITGEIST
+SUBDIRS += zeitgeist
+endif
+
-include $(top_srcdir)/git.mk
diff --git a/plugins/zeitgeist/Makefile.am b/plugins/zeitgeist/Makefile.am
new file mode 100644
index 0000000..8e7d07b
--- /dev/null
+++ b/plugins/zeitgeist/Makefile.am
@@ -0,0 +1,31 @@
+# zeitgeist plugin
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ $(GEDIT_CFLAGS) \
+ $(ZEITGEIST_CFLAGS) \
+ $(WARN_CFLAGS) \
+ $(DISABLE_DEPRECATED_CFLAGS)
+
+plugin_LTLIBRARIES = libzeitgeistplugin.la
+
+libzeitgeistplugin_la_SOURCES = \
+ gedit-zeitgeist-plugin.h \
+ gedit-zeitgeist-plugin.c
+
+libzeitgeistplugin_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+libzeitgeistplugin_la_LIBADD = $(GEDIT_LIBS) $(ZEITGEIST_LIBS)
+
+plugin_in_files = zeitgeist.plugin.desktop.in
+
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA)
+DISTCLEANFILES = $(plugin_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/zeitgeist/gedit-zeitgeist-plugin.c b/plugins/zeitgeist/gedit-zeitgeist-plugin.c
new file mode 100644
index 0000000..60214b9
--- /dev/null
+++ b/plugins/zeitgeist/gedit-zeitgeist-plugin.c
@@ -0,0 +1,356 @@
+/*
+ * gedit-zeitgeist-plugin.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2011 - Michal Hruby
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gedit-zeitgeist-plugin.h"
+
+#include <glib/gi18n.h>
+#include <gmodule.h>
+
+#include <gedit/gedit-view.h>
+#include <gedit/gedit-view-activatable.h>
+#include <gedit/gedit-app.h>
+#include <gedit/gedit-app-activatable.h>
+#include <gedit/gedit-debug.h>
+#include <zeitgeist.h>
+
+enum
+{
+ SIGNAL_DOC_SAVED,
+ SIGNAL_DOC_LOADED,
+
+ N_SIGNALS
+};
+
+struct _GeditZeitgeistPluginPrivate
+{
+ GeditView *view;
+ GeditApp *app;
+
+ gulong signals[N_SIGNALS];
+};
+
+enum
+{
+ PROP_0,
+ PROP_VIEW,
+ PROP_APP
+};
+
+static void gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface);
+static void gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditZeitgeistPlugin,
+ gedit_zeitgeist_plugin,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_VIEW_ACTIVATABLE,
+ gedit_view_activatable_iface_init)
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_APP_ACTIVATABLE,
+ gedit_app_activatable_iface_init))
+
+static ZeitgeistLog *zg_log = NULL;
+static ZeitgeistDataSourceRegistry *zg_dsr = NULL;
+
+static void
+gedit_zeitgeist_plugin_init (GeditZeitgeistPlugin *plugin)
+{
+ gedit_debug_message (DEBUG_PLUGINS, "GeditZeitgeistPlugin initializing");
+
+ plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+ GEDIT_TYPE_ZEITGEIST_PLUGIN,
+ GeditZeitgeistPluginPrivate);
+}
+
+static void
+gedit_zeitgeist_plugin_dispose (GObject *object)
+{
+ GeditZeitgeistPlugin *plugin = GEDIT_ZEITGEIST_PLUGIN (object);
+
+ gedit_debug_message (DEBUG_PLUGINS, "GeditZeitgeistPlugin disposing");
+
+ if (plugin->priv->view != NULL)
+ {
+ g_object_unref (plugin->priv->view);
+ plugin->priv->view = NULL;
+ }
+
+ if (plugin->priv->app != NULL)
+ {
+ g_object_unref (plugin->priv->app);
+ plugin->priv->app = NULL;
+ }
+
+ G_OBJECT_CLASS (gedit_zeitgeist_plugin_parent_class)->dispose (object);
+}
+
+static void
+gedit_zeitgeist_plugin_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gedit_zeitgeist_plugin_parent_class)->finalize (object);
+
+ gedit_debug_message (DEBUG_PLUGINS, "GeditZeitgeistPlugin finalizing");
+}
+
+static void
+gedit_zeitgeist_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeditZeitgeistPlugin *plugin = GEDIT_ZEITGEIST_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ plugin->priv->view = GEDIT_VIEW (g_value_dup_object (value));
+ break;
+
+ case PROP_APP:
+ plugin->priv->app = GEDIT_APP (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_zeitgeist_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeditZeitgeistPlugin *plugin = GEDIT_ZEITGEIST_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ g_value_set_object (value, plugin->priv->view);
+ break;
+
+ case PROP_APP:
+ g_value_set_object (value, plugin->priv->app);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_zeitgeist_plugin_send_event (GeditZeitgeistPlugin *plugin,
+ GeditDocument *doc, gchar *interpretation)
+{
+ ZeitgeistEvent *event;
+ ZeitgeistSubject *subject;
+ GFile *location;
+
+ location = gedit_document_get_location (doc);
+
+ if (location != NULL)
+ {
+ gchar *display_name;
+ gchar *dir_name;
+ gchar *mime_type;
+ gchar *doc_uri;
+
+ doc_uri = g_file_get_uri (location);
+ dir_name = g_path_get_dirname (doc_uri);
+ mime_type = gedit_document_get_mime_type (doc);
+ display_name = gedit_document_get_short_name_for_display (doc);
+
+ subject = zeitgeist_subject_new_full (doc_uri,
+ ZEITGEIST_NFO_DOCUMENT,
+ zeitgeist_manifestation_for_uri (doc_uri),
+ mime_type,
+ dir_name,
+ display_name,
+ NULL);
+
+ event = zeitgeist_event_new_full (interpretation,
+ ZEITGEIST_ZG_USER_ACTIVITY,
+ "application://gedit.desktop",
+ subject,
+ NULL);
+
+ zeitgeist_log_insert_events_no_reply (zg_log, event, NULL);
+
+ g_free (display_name);
+ g_free (mime_type);
+ g_free (dir_name);
+ g_free (doc_uri);
+
+ g_object_unref (location);
+ }
+}
+
+static void
+document_saved (GeditDocument *doc,
+ const GError *error,
+ GeditZeitgeistPlugin *plugin)
+{
+ gedit_zeitgeist_plugin_send_event (plugin, doc, ZEITGEIST_ZG_MODIFY_EVENT);
+}
+
+static void
+document_loaded (GeditDocument *doc,
+ const GError *error,
+ GeditZeitgeistPlugin *plugin)
+{
+ gedit_zeitgeist_plugin_send_event (plugin, doc, ZEITGEIST_ZG_ACCESS_EVENT);
+}
+
+static void
+gedit_zeitgeist_plugin_view_activate (GeditViewActivatable *activatable)
+{
+ GeditZeitgeistPluginPrivate *priv;
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = GEDIT_ZEITGEIST_PLUGIN (activatable)->priv;
+
+ doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)));
+
+ priv->signals[SIGNAL_DOC_SAVED] =
+ g_signal_connect (doc,
+ "saved",
+ G_CALLBACK (document_saved),
+ activatable);
+
+ priv->signals[SIGNAL_DOC_LOADED] =
+ g_signal_connect (doc,
+ "loaded",
+ G_CALLBACK (document_loaded),
+ activatable);
+}
+
+static void
+gedit_zeitgeist_plugin_view_deactivate (GeditViewActivatable *activatable)
+{
+ GeditZeitgeistPluginPrivate *priv;
+ GeditDocument *doc;
+ int i;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = GEDIT_ZEITGEIST_PLUGIN (activatable)->priv;
+
+ doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)));
+
+ for (i = 0; i < N_SIGNALS; i++)
+ {
+ g_signal_handler_disconnect (doc, priv->signals[i]);
+ }
+
+ gedit_zeitgeist_plugin_send_event (GEDIT_ZEITGEIST_PLUGIN (activatable),
+ doc, ZEITGEIST_ZG_LEAVE_EVENT);
+
+ g_object_unref (zg_log);
+}
+
+static void
+gedit_zeitgeist_plugin_app_activate (GeditAppActivatable *activatable)
+{
+ GPtrArray *ptr_arr;
+ ZeitgeistEvent *event;
+ ZeitgeistDataSource *ds;
+
+ zg_log = zeitgeist_log_new ();
+
+ event = zeitgeist_event_new_full (NULL, NULL,
+ "application://gedit.desktop", NULL);
+ ptr_arr = g_ptr_array_new ();
+ g_ptr_array_add (ptr_arr, event);
+
+ ds = zeitgeist_data_source_new_full ("org.gnome.gedit,dataprovider",
+ "Gedit dataprovider",
+ "Logs events about accessed documents",
+ ptr_arr),
+
+ zg_dsr = zeitgeist_data_source_registry_new ();
+ zeitgeist_data_source_registry_register_data_source (zg_dsr, ds,
+ NULL, NULL, NULL);
+}
+
+static void
+gedit_zeitgeist_plugin_app_deactivate (GeditAppActivatable *activatable)
+{
+ g_object_unref (zg_log);
+ g_object_unref (zg_dsr);
+}
+
+static void
+gedit_zeitgeist_plugin_class_init (GeditZeitgeistPluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gedit_zeitgeist_plugin_dispose;
+ object_class->finalize = gedit_zeitgeist_plugin_finalize;
+ object_class->set_property = gedit_zeitgeist_plugin_set_property;
+ object_class->get_property = gedit_zeitgeist_plugin_get_property;
+
+ g_object_class_override_property (object_class, PROP_VIEW, "view");
+ g_object_class_override_property (object_class, PROP_APP, "app");
+
+ g_type_class_add_private (klass, sizeof (GeditZeitgeistPluginPrivate));
+}
+
+static void
+gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface)
+{
+ iface->activate = gedit_zeitgeist_plugin_view_activate;
+ iface->deactivate = gedit_zeitgeist_plugin_view_deactivate;
+}
+
+static void
+gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface)
+{
+ iface->activate = gedit_zeitgeist_plugin_app_activate;
+ iface->deactivate = gedit_zeitgeist_plugin_app_deactivate;
+}
+
+static void
+gedit_zeitgeist_plugin_class_finalize (GeditZeitgeistPluginClass *klass)
+{
+}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ gedit_zeitgeist_plugin_register_type (G_TYPE_MODULE (module));
+
+ peas_object_module_register_extension_type (module,
+ GEDIT_TYPE_VIEW_ACTIVATABLE,
+ GEDIT_TYPE_ZEITGEIST_PLUGIN);
+ peas_object_module_register_extension_type (module,
+ GEDIT_TYPE_APP_ACTIVATABLE,
+ GEDIT_TYPE_ZEITGEIST_PLUGIN);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/zeitgeist/gedit-zeitgeist-plugin.h b/plugins/zeitgeist/gedit-zeitgeist-plugin.h
new file mode 100644
index 0000000..58feac5
--- /dev/null
+++ b/plugins/zeitgeist/gedit-zeitgeist-plugin.h
@@ -0,0 +1,65 @@
+/*
+ * gedit-zeitgeist-plugin.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2011 - Michal Hruby
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GEDIT_ZEITGEIST_PLUGIN_H__
+#define __GEDIT_ZEITGEIST_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_ZEITGEIST_PLUGIN (gedit_zeitgeist_plugin_get_type ())
+#define GEDIT_ZEITGEIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_ZEITGEIST_PLUGIN, GeditZeitgeistPlugin))
+#define GEDIT_ZEITGEIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_ZEITGEIST_PLUGIN, GeditZeitgeistPluginClass))
+#define GEDIT_IS_ZEITGEIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_ZEITGEIST_PLUGIN))
+#define GEDIT_IS_ZEITGEIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_ZEITGEIST_PLUGIN))
+#define GEDIT_ZEITGEIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_ZEITGEIST_PLUGIN, GeditZeitgeistPluginClass))
+
+typedef struct _GeditZeitgeistPlugin GeditZeitgeistPlugin;
+typedef struct _GeditZeitgeistPluginPrivate GeditZeitgeistPluginPrivate;
+typedef struct _GeditZeitgeistPluginClass GeditZeitgeistPluginClass;
+
+struct _GeditZeitgeistPlugin
+{
+ PeasExtensionBase parent;
+
+ /*< private >*/
+ GeditZeitgeistPluginPrivate *priv;
+};
+
+struct _GeditZeitgeistPluginClass
+{
+ PeasExtensionBaseClass parent_class;
+};
+
+GType gedit_zeitgeist_plugin_get_type (void) G_GNUC_CONST;
+
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
+
+G_END_DECLS
+
+#endif /* __GEDIT_ZEITGEIST_PLUGIN_H__ */
+
+/* ex:ts=8:noet: */
diff --git a/plugins/zeitgeist/zeitgeist.plugin.desktop.in b/plugins/zeitgeist/zeitgeist.plugin.desktop.in
new file mode 100644
index 0000000..2f93293
--- /dev/null
+++ b/plugins/zeitgeist/zeitgeist.plugin.desktop.in
@@ -0,0 +1,9 @@
+[Plugin]
+Module=zeitgeistplugin
+IAge=3
+_Name=Zeitgeist dataprovider
+_Description=Logs access and leave event for documents used with gedit
+Authors=Michal Hruby <michal mhr gmail com>
+Copyright=Copyright © 2011 Michal Hruby
+Website=http://www.gedit.org
+
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e108336..0239691 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -101,3 +101,4 @@ plugins/time/time.plugin.desktop.in
plugins/time/org.gnome.gedit.plugins.time.gschema.xml.in.in
[type: gettext/glade]plugins/time/gedit-time-dialog.ui
[type: gettext/glade]plugins/time/gedit-time-setup-dialog.ui
+plugins/zeitgeist/zeitgeist.plugin.desktop.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]