22.2.12
by Ted Gould
Copyright header |
1 |
/*
|
2 |
* Copyright 2013 Canonical Ltd.
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 3, as published
|
|
6 |
* by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful, but
|
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
10 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
11 |
* PURPOSE. See the GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License along
|
|
14 |
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
* Authors:
|
|
17 |
* Ted Gould <ted.gould@canonical.com>
|
|
18 |
*/
|
|
19 |
||
22.2.8
by Ted Gould
Adding the basis for reporting to ZG opening of the app |
20 |
|
22.2.9
by Ted Gould
Flesh out the zg insert event |
21 |
#include <zeitgeist.h> |
154.5.4
by Ted Gould
Get the lib for the function |
22 |
#include "libubuntu-app-launch/ubuntu-app-launch.h" |
22.2.9
by Ted Gould
Flesh out the zg insert event |
23 |
|
22.2.14
by Ted Gould
Add a watchdog just in case |
24 |
static gboolean |
25 |
watchdog_timeout (gpointer user_data) |
|
26 |
{
|
|
97.1.3
by Ted Gould
Switching to a warning so we don't exit |
27 |
g_warning("Watchdog triggered, took too long to submit into Zeitgeist Database!"); |
22.2.14
by Ted Gould
Add a watchdog just in case |
28 |
g_main_loop_quit((GMainLoop *)user_data); |
29 |
||
30 |
return G_SOURCE_REMOVE; |
|
31 |
}
|
|
32 |
||
22.2.13
by Ted Gould
Waiting until the insert happens |
33 |
static void |
34 |
insert_complete (GObject * obj, GAsyncResult * res, gpointer user_data) |
|
35 |
{
|
|
36 |
GError * error = NULL; |
|
37 |
GArray * result = NULL; |
|
38 |
||
80.3.4
by Ted Gould
Match libZG 2 API |
39 |
result = zeitgeist_log_insert_event_finish(ZEITGEIST_LOG(obj), res, &error); |
22.2.13
by Ted Gould
Waiting until the insert happens |
40 |
|
41 |
if (error != NULL) { |
|
195.3.1
by Ted Gould
Don't error on ZG failure |
42 |
g_warning("Unable to submit Zeitgeist Event: %s", error->message); |
22.2.13
by Ted Gould
Waiting until the insert happens |
43 |
g_error_free(error); |
44 |
}
|
|
45 |
||
46 |
g_array_free(result, TRUE); |
|
47 |
g_main_loop_quit((GMainLoop *)user_data); |
|
48 |
return; |
|
49 |
}
|
|
50 |
||
22.2.8
by Ted Gould
Adding the basis for reporting to ZG opening of the app |
51 |
int
|
52 |
main (int argc, char * argv[]) |
|
53 |
{
|
|
62.1.25
by Ted Gould
Use the APP_ID environment variable and generate the URI in C code |
54 |
if (argc != 2 || (g_strcmp0(argv[1], "open") != 0 && g_strcmp0(argv[1], "close") != 0)) { |
55 |
g_printerr("Usage: %s [open|close]\n", argv[0]); |
|
56 |
return 1; |
|
57 |
}
|
|
58 |
||
59 |
const gchar * appid = g_getenv("APP_ID"); |
|
60 |
if (appid == NULL) { |
|
61 |
g_printerr("No App ID defined"); |
|
62 |
return 1; |
|
63 |
}
|
|
154.5.3
by Ted Gould
Making it so that we use short URLs in the base tool too |
64 |
|
65 |
gchar * uri = NULL; |
|
66 |
gchar * pkg = NULL; |
|
67 |
gchar * app = NULL; |
|
68 |
||
69 |
if (ubuntu_app_launch_app_id_parse(appid, &pkg, &app, NULL)) { |
|
70 |
/* If it's parseable, use the short form */
|
|
71 |
uri = g_strdup_printf("application://%s_%s.desktop", pkg, app); |
|
72 |
g_free(pkg); |
|
73 |
g_free(app); |
|
74 |
} else { |
|
75 |
uri = g_strdup_printf("application://%s.desktop", appid); |
|
76 |
}
|
|
22.2.9
by Ted Gould
Flesh out the zg insert event |
77 |
|
78 |
ZeitgeistLog * log = zeitgeist_log_get_default(); |
|
79 |
||
80 |
ZeitgeistEvent * event = zeitgeist_event_new(); |
|
152.1.6
by Ted Gould
Removing more instances if 'upstart' to not confuse people, leaving the tracepoints for now |
81 |
zeitgeist_event_set_actor(event, "application://ubuntu-app-launch.desktop"); |
22.2.10
by Ted Gould
Making it so the utility can be used for open and close |
82 |
if (g_strcmp0(argv[1], "open") == 0) { |
83 |
zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_ACCESS_EVENT); |
|
84 |
} else { |
|
85 |
zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_LEAVE_EVENT); |
|
86 |
}
|
|
22.2.9
by Ted Gould
Flesh out the zg insert event |
87 |
zeitgeist_event_set_manifestation(event, ZEITGEIST_ZG_USER_ACTIVITY); |
88 |
||
89 |
ZeitgeistSubject * subject = zeitgeist_subject_new(); |
|
90 |
zeitgeist_subject_set_interpretation(subject, ZEITGEIST_NFO_SOFTWARE); |
|
91 |
zeitgeist_subject_set_manifestation(subject, ZEITGEIST_NFO_SOFTWARE_ITEM); |
|
92 |
zeitgeist_subject_set_mimetype(subject, "application/x-desktop"); |
|
62.1.25
by Ted Gould
Use the APP_ID environment variable and generate the URI in C code |
93 |
zeitgeist_subject_set_uri(subject, uri); |
22.2.9
by Ted Gould
Flesh out the zg insert event |
94 |
|
95 |
zeitgeist_event_add_subject(event, subject); |
|
96 |
||
22.2.13
by Ted Gould
Waiting until the insert happens |
97 |
GMainLoop * main_loop = g_main_loop_new(NULL, FALSE); |
98 |
||
80.3.4
by Ted Gould
Match libZG 2 API |
99 |
zeitgeist_log_insert_event(log, event, NULL, insert_complete, main_loop); |
97.1.2
by Ted Gould
Shortening timeout |
100 |
g_timeout_add_seconds(2, watchdog_timeout, main_loop); |
22.2.13
by Ted Gould
Waiting until the insert happens |
101 |
|
102 |
g_main_loop_run(main_loop); |
|
22.2.9
by Ted Gould
Flesh out the zg insert event |
103 |
|
62.1.25
by Ted Gould
Use the APP_ID environment variable and generate the URI in C code |
104 |
g_main_loop_unref(main_loop); |
105 |
g_free(uri); |
|
106 |
||
22.2.9
by Ted Gould
Flesh out the zg insert event |
107 |
return 0; |
22.2.8
by Ted Gould
Adding the basis for reporting to ZG opening of the app |
108 |
}
|