summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Hruby <michal.mhr@gmail.com>2011-02-09 10:31:02 +0100
committerMichal Hruby <michal.mhr@gmail.com>2011-02-09 10:31:02 +0100
commitbf3dd17b102eaf05e1c0175d9c61f15c418494a9 (patch)
tree1f73aded1032e7455fe31a84dddc2943ea4fae3b
parentc8644d01bdfd47d5a5a4bdada3ede9cb175f5507 (diff)
parentb55fbf6977960a4ae72008300ecd0b6f9679f6fe (diff)
Merge from <lp:~mhr3/zeitgeist-datahub/gdbus-update>
-rw-r--r--configure.ac8
-rw-r--r--src/Makefile.am5
-rw-r--r--src/desktop-launch-listener.vala185
-rw-r--r--src/glib-extra.vapi5
-rw-r--r--src/zeitgeist-datahub.vala44
5 files changed, 216 insertions, 31 deletions
diff --git a/configure.ac b/configure.ac
index 70627f9..31cb34a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,18 +31,18 @@ AC_STDC_HEADERS
dnl ==============================================
dnl Check for vala
dnl ==============================================
-AM_PROG_VALAC([0.9.8])
+AM_PROG_VALAC([0.11.2])
AM_SILENT_RULES([yes])
dnl ==============================================
dnl Check that we meet the dependencies
dnl ==============================================
-MIN_GLIB_VERSION=2.22.0
+MIN_GLIB_VERSION=2.26.0
MIN_GTK_VERSION=2.16.0
-MIN_ZEITGEIST_VERSION=0.2.3
+MIN_ZEITGEIST_VERSION=0.3.1
-LIBRARY_MODULES="glib-2.0 >= $MIN_GLIB_VERSION gobject-2.0 dbus-glib-1 zeitgeist-1.0 >= $MIN_ZEITGEIST_VERSION"
+LIBRARY_MODULES="glib-2.0 >= $MIN_GLIB_VERSION gobject-2.0 gio-2.0 gio-unix-2.0 zeitgeist-1.0 >= $MIN_ZEITGEIST_VERSION"
PKG_CHECK_MODULES(DATAHUB_MODULES, [$LIBRARY_MODULES])
PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= $MIN_GTK_VERSION])
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b87af3..ff5c7db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,9 @@
VALAFLAGS = \
- --pkg dbus-glib-1 \
+ --pkg gio-2.0 \
+ --pkg gio-unix-2.0 \
--pkg gtk+-2.0 \
--pkg zeitgeist-1.0 \
+ glib-extra.vapi \
$(NULL)
datahubdir = $(bindir)
@@ -12,6 +14,7 @@ zeitgeist_datahub_CFLAGS = $(DATAHUB_MODULES_CFLAGS) $(GTK_CFLAGS)
zeitgeist_datahub_LDADD = $(DATAHUB_MODULES_LIBS) $(GTK_LIBS)
zeitgeist_datahub_SOURCES = \
data-provider.vala \
+ desktop-launch-listener.vala \
recent-manager-provider.vala \
zeitgeist-datahub.vala \
$(NULL)
diff --git a/src/desktop-launch-listener.vala b/src/desktop-launch-listener.vala
new file mode 100644
index 0000000..3a68c73
--- /dev/null
+++ b/src/desktop-launch-listener.vala
@@ -0,0 +1,185 @@
+/*
+ * Zeitgeist
+ *
+ * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
+ *
+ * This program 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.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by Michal Hruby <michal.mhr@gmail.com>
+ *
+ */
+
+using Zeitgeist;
+
+public class DesktopLaunchListener : DataProvider
+{
+ public DesktopLaunchListener (DataHub datahub)
+ {
+ GLib.Object (unique_id: "com.zeitgeist-project,datahub,gio-launch-listener",
+ name: "Launched desktop files",
+ description: "Logs events about launched desktop files using GIO",
+ datahub: datahub);
+ }
+
+ // if vala didn't have bug in construct-only properties, the properties
+ // would be construct-only
+ public override string unique_id { get; construct set; }
+ public override string name { get; construct set; }
+ public override string description { get; construct set; }
+
+ public override DataHub datahub { get; construct set; }
+ public override bool enabled { get; set; default = true; }
+ public override bool register { get; construct set; default = true; }
+
+ private GLib.DBusConnection bus;
+ private uint launched_signal_id = 0;
+
+ construct
+ {
+ try
+ {
+ bus = GLib.Bus.get_sync (GLib.BusType.SESSION);
+ }
+ catch (IOError err)
+ {
+ warning ("%s", err.message);
+ }
+ }
+
+ public override void start ()
+ {
+ if (launched_signal_id != 0) return;
+
+ launched_signal_id = bus.signal_subscribe (null,
+ "org.gtk.gio.DesktopAppInfo",
+ "Launched",
+ "/org/gtk/gio/DesktopAppInfo",
+ null,
+ 0,
+ this.signal_received);
+ }
+
+ private void signal_received (GLib.DBusConnection connection,
+ string sender,
+ string object_path,
+ string interface_name,
+ string signal_name,
+ Variant parameters)
+ {
+ // unpack the variant
+ Variant desktop_variant;
+ VariantIter uris;
+ Variant dict;
+ int64 pid;
+
+ parameters.get ("(@aysxas@a{sv})", out desktop_variant, null,
+ out pid, out uris, out dict);
+
+ string desktop_file = desktop_variant.get_bytestring ();
+ if (desktop_file == "") return;
+
+ // are we going to do anything with these?
+ string uri;
+ while (uris.next ("s", out uri))
+ {
+ debug ("ran with uri: %s", uri);
+ }
+
+ // here we should be able to get info about the origin of the launch
+ HashTable<string, Variant> extra_params = (HashTable<string, Variant>) dict;
+
+ string? launched_display_name;
+ string launched_uri = get_uri_for_desktop_file (desktop_file,
+ out launched_display_name);
+ if (launched_uri == null)
+ {
+ warning ("Unable to open desktop file '%s'", desktop_file);
+ return;
+ }
+
+ string? launcher_uri = null;
+ unowned Variant origin_df = extra_params.lookup ("origin-desktop-file");
+ if (origin_df != null)
+ {
+ launcher_uri = get_uri_for_desktop_file (origin_df.get_bytestring ());
+ }
+ else
+ {
+ unowned Variant origin_prgname = extra_params.lookup ("origin-prgname");
+ if (origin_prgname != null)
+ {
+ unowned string? prgname = origin_prgname.get_bytestring ();
+ string origin_desktop_id = prgname + ".desktop";
+ DesktopAppInfo id_check = new DesktopAppInfo (origin_desktop_id);
+ if (id_check != null) launcher_uri = "application://%s".printf (origin_desktop_id);
+ }
+ }
+
+ // FIXME: check if the app should be shown, and return? /
+ // set manifestation to WORLD?_EVENT
+
+ var event = new Zeitgeist.Event ();
+ var subject = new Zeitgeist.Subject ();
+
+ event.set_actor (launcher_uri);
+ event.set_interpretation (Zeitgeist.ZG_ACCESS_EVENT);
+ event.set_manifestation (Zeitgeist.ZG_USER_ACTIVITY);
+ event.add_subject (subject);
+
+ subject.set_uri (launched_uri);
+ subject.set_interpretation (Zeitgeist.NFO_SOFTWARE);
+ subject.set_manifestation (Zeitgeist.NFO_SOFTWARE_ITEM);
+ subject.set_mimetype ("application/x-desktop");
+ subject.set_text (launched_display_name);
+
+ var arr = new GenericArray<Event> ();
+ arr.add (event);
+
+ items_available (arr);
+ }
+
+ private string? get_uri_for_desktop_file (string desktop_file,
+ out string? display_name = null)
+ {
+ DesktopAppInfo? dai;
+ if (Path.is_absolute (desktop_file))
+ {
+ dai = new DesktopAppInfo.from_filename (desktop_file);
+ }
+ else
+ {
+ dai = new DesktopAppInfo (desktop_file);
+ }
+
+ if (dai == null)
+ {
+ display_name = null;
+ return null;
+ }
+
+ string desktop_id = dai.get_id () ?? Path.get_basename (dai.get_filename ());
+ display_name = dai.get_display_name ();
+ return "application://%s".printf (desktop_id);
+ }
+
+ public override void stop ()
+ {
+ if (launched_signal_id != 0)
+ {
+ bus.signal_unsubscribe (launched_signal_id);
+ launched_signal_id = 0;
+ }
+ }
+}
+
diff --git a/src/glib-extra.vapi b/src/glib-extra.vapi
new file mode 100644
index 0000000..dd3ade5
--- /dev/null
+++ b/src/glib-extra.vapi
@@ -0,0 +1,5 @@
+[CCode (cprefix = "G", lower_case_cprefix = "g_")]
+namespace GLibExtra {
+ [CCode (cname = "GLIB_CHECK_VERSION")]
+ public static bool check_version (uint major, uint minor, uint micro);
+}
diff --git a/src/zeitgeist-datahub.vala b/src/zeitgeist-datahub.vala
index 663d1b5..05b8b97 100644
--- a/src/zeitgeist-datahub.vala
+++ b/src/zeitgeist-datahub.vala
@@ -25,7 +25,7 @@ using Zeitgeist;
[DBus (name = "org.gnome.zeitgeist.datahub")]
public interface DataHubService : Object
{
- public abstract string[] get_data_providers () throws DBus.Error;
+ public abstract string[] get_data_providers () throws IOError;
}
public class DataHub : Object, DataHubService
@@ -109,6 +109,11 @@ public class DataHub : Object, DataHubService
*/
providers.prepend (new RecentManagerGtk (this));
+ if (GLibExtra.check_version (2, 28, 0))
+ {
+ providers.prepend (new DesktopLaunchListener (this));
+ }
+
foreach (unowned DataProvider prov in providers)
{
bool enabled = true;
@@ -200,36 +205,23 @@ public class DataHub : Object, DataHubService
}
}
+ const string UNIQUE_NAME = "org.gnome.zeitgeist.datahub";
+ const string OBJECT_PATH = "/org/gnome/zeitgeist/datahub";
+
protected void run ()
{
- try
- {
- var connection = DBus.Bus.get (DBus.BusType.SESSION);
- dynamic DBus.Object bus =
- connection.get_object ("org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus");
-
- uint request_name_result =
- bus.request_name ("org.gnome.zeitgeist.datahub",
- (uint) DBus.NameFlag.DO_NOT_QUEUE);
-
- if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER)
- {
- connection.register_object ("/org/gnome/zeitgeist/datahub", this);
- start_data_providers ();
- main_loop.run ();
- }
- else
+ Bus.own_name (BusType.SESSION, UNIQUE_NAME, BusNameOwnerFlags.NONE,
+ (conn) => { conn.register_object (OBJECT_PATH, (DataHubService) this); },
+ () => { start_data_providers (); },
+ () =>
{
warning ("Unable to get name \"org.gnome.zeitgeist.datahub\"" +
" on the bus!");
+ this.quit ();
}
- }
- catch (GLib.Error err)
- {
- warning ("%s", err.message);
- }
+ );
+
+ main_loop.run ();
}
protected void quit ()
@@ -264,7 +256,7 @@ public class DataHub : Object, DataHubService
return actors;
}
- public string[] get_data_providers () throws DBus.Error
+ public string[] get_data_providers () throws IOError
{
string[] arr = {};
foreach (var provider in providers)