1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
*
*/
#include <glib.h>
#include <glib/gprintf.h>
#include <glib-object.h>
#include <zeitgeist.h>
static void
on_events_received (ZeitgeistLog *log,
GAsyncResult *res,
gpointer user_data)
{
ZeitgeistResultSet *events;
ZeitgeistEvent *event;
ZeitgeistSubject *subject;
GError *error;
GMainLoop *mainloop = (GMainLoop*) user_data;
gint i;
error = NULL;
events = zeitgeist_log_find_events_finish (log, res, &error);
if (error)
{
g_warning ("Error reading results: %s", error->message);
g_error_free (error);
return;
}
g_message ("Got %i events:", zeitgeist_result_set_size (events));
while (zeitgeist_result_set_has_next (events))
{
event = zeitgeist_result_set_next_value (events);
for (i = 0; i < zeitgeist_event_num_subjects (event); i++)
{
subject = zeitgeist_event_get_subject (event, i);
g_printf ("%s\n", zeitgeist_subject_get_uri (subject));
}
}
g_object_unref (events);
g_main_loop_quit (mainloop);
}
gint
main (gint argc,
gchar *argv[])
{
GMainLoop *mainloop;
ZeitgeistLog *log;
GPtrArray *templates;
mainloop = g_main_loop_new (NULL, FALSE);
log = zeitgeist_log_new();
templates = g_ptr_array_new ();
g_ptr_array_add (templates, zeitgeist_event_new ());
zeitgeist_log_find_events (log,
zeitgeist_time_range_new_to_now (),
templates,
ZEITGEIST_STORAGE_STATE_ANY,
10,
ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS,
NULL,
(GAsyncReadyCallback)on_events_received,
mainloop);
g_main_loop_run (mainloop);
return 0;
}
|