3
* Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
4
* Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
6
* Based upon a Python implementation (2010-2011) by:
7
* Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation, either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
[DBus (name = "org.gnome.zeitgeist.Histogram")]
27
public interface RemoteHistogram: Object
29
[DBus (signature = "a(xu)")]
30
public abstract Variant get_histogram_data () throws Error;
33
class Histogram: Extension, RemoteHistogram
36
private uint registration_id = 0;
40
// This will be called after bus is acquired, so it shouldn't block
43
var connection = Bus.get_sync (BusType.SESSION, null);
44
registration_id = connection.register_object<RemoteHistogram> (
45
"/org/gnome/zeitgeist/journal/activity", this);
49
warning ("%s", err.message);
53
public override void unload ()
57
var connection = Bus.get_sync (BusType.SESSION, null);
58
if (registration_id != 0)
60
connection.unregister_object (registration_id);
66
warning ("%s", err.message);
69
debug ("%s, this.ref_count = %u", Log.METHOD, this.ref_count);
72
public Variant get_histogram_data () throws Error
74
var builder = new VariantBuilder (new VariantType ("a(xu)"));
77
SELECT strftime('%s', datetime(timestamp/1000, 'unixepoch',
78
'localtime'), 'start of day') AS daystamp,
82
ORDER BY daystamp DESC
85
Sqlite.Statement stmt;
86
var database = engine.database;
87
unowned Sqlite.Database db = database.database;
89
int rc = db.prepare_v2 (sql, -1, out stmt);
90
database.assert_query_success (rc, "SQL error");
92
while ((rc = stmt.step ()) == Sqlite.ROW)
94
int64 t = stmt.column_int64 (0);
95
uint32 count = stmt.column_int (1);
97
builder.add ("(xu)", t, count);
99
database.assert_query_success (rc, "Error in get_histogram_data",
102
return builder.end ();
108
#if BUILTIN_EXTENSIONS
109
public static Type histogram_init (TypeModule module)
112
public static Type extension_register (TypeModule module)
115
return typeof (Histogram);
119
// vim:expandtab:ts=4:sw=4