~ubuntu-branches/ubuntu/trusty/hud/trusty-updates

« back to all changes in this revision

Viewing changes to src/hud-dump-application.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-20 19:43:59 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20140120194359-jxxxqtd4ql9elvpf
Tags: 13.10.1+14.04.20140120-0ubuntu1
* New rebuild forced
* Automatic snapshot from revision 362

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Small utility to dump application info in the HUD usage DB
3
 
 
4
 
Copyright 2011 Canonical Ltd.
5
 
 
6
 
Authors:
7
 
    Ted Gould <ted@canonical.com>
8
 
 
9
 
This program is free software: you can redistribute it and/or modify it 
10
 
under the terms of the GNU General Public License version 3, as published 
11
 
by the Free Software Foundation.
12
 
 
13
 
This program is distributed in the hope that it will be useful, but 
14
 
WITHOUT ANY WARRANTY; without even the implied warranties of 
15
 
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
16
 
PURPOSE.  See the GNU General Public License for more details.
17
 
 
18
 
You should have received a copy of the GNU General Public License along 
19
 
with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
*/
21
 
 
22
 
#include <glib.h>
23
 
#include "dump-app-info.h"
24
 
 
25
 
int
26
 
main (int argv, char * argc[])
27
 
{
28
 
        if (argv != 2 && argv != 3) {
29
 
                g_printerr("Usage: %s <desktop file path> [gettext domain]\n", argc[0]);
30
 
                return 1;
31
 
        }
32
 
 
33
 
        const gchar * basecachedir = g_getenv("HUD_CACHE_DIR");
34
 
        if (basecachedir == NULL) {
35
 
                basecachedir = g_get_user_cache_dir();
36
 
        }
37
 
 
38
 
        gchar * cachedir = g_build_filename(basecachedir, "indicator-appmenu", NULL);
39
 
        if (!g_file_test(cachedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
40
 
                g_warning("Cache directory '%s' doesn't exist", cachedir);
41
 
                return 1;
42
 
        }
43
 
        g_free(cachedir);
44
 
 
45
 
        gchar * cachefile = g_build_filename(basecachedir, "indicator-appmenu", "hud-usage-log.sqlite", NULL);
46
 
        gboolean db_exists = g_file_test(cachefile, G_FILE_TEST_EXISTS);
47
 
 
48
 
        if (!db_exists) {
49
 
                g_warning("There is no HUD usage log: %s", cachefile);
50
 
                return 1;
51
 
        }
52
 
 
53
 
        sqlite3 * db;
54
 
        int open_status = sqlite3_open(cachefile, &db); 
55
 
 
56
 
        if (open_status != SQLITE_OK) {
57
 
                g_warning("Error opening usage DB: %s", cachefile);
58
 
                sqlite3_close(db);
59
 
                return 1;
60
 
        }
61
 
 
62
 
        gchar * domain = NULL;
63
 
        if (argv == 3) {
64
 
                domain = argc[2];
65
 
        }
66
 
 
67
 
        dump_app_info(argc[1], domain, db);
68
 
 
69
 
        sqlite3_close(db);
70
 
        g_free(cachefile);
71
 
 
72
 
        return 0;
73
 
}