Back to index

indicator-appmenu  12.10.0
hud-dump-application.c
Go to the documentation of this file.
00001 /*
00002 Small utility to dump application info in the HUD usage DB
00003 
00004 Copyright 2011 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This program is free software: you can redistribute it and/or modify it 
00010 under the terms of the GNU General Public License version 3, as published 
00011 by the Free Software Foundation.
00012 
00013 This program is distributed in the hope that it will be useful, but 
00014 WITHOUT ANY WARRANTY; without even the implied warranties of 
00015 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
00016 PURPOSE.  See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License along 
00019 with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include <glib.h>
00023 #include "dump-app-info.h"
00024 
00025 int
00026 main (int argv, char * argc[])
00027 {
00028        if (argv != 2 && argv != 3) {
00029               g_printerr("Usage: %s <desktop file path> [gettext domain]\n", argc[0]);
00030               return 1;
00031        }
00032 
00033        const gchar * basecachedir = g_getenv("HUD_CACHE_DIR");
00034        if (basecachedir == NULL) {
00035               basecachedir = g_get_user_cache_dir();
00036        }
00037 
00038        gchar * cachedir = g_build_filename(basecachedir, "indicator-appmenu", NULL);
00039        if (!g_file_test(cachedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
00040               g_warning("Cache directory '%s' doesn't exist", cachedir);
00041               return 1;
00042        }
00043        g_free(cachedir);
00044 
00045        gchar * cachefile = g_build_filename(basecachedir, "indicator-appmenu", "hud-usage-log.sqlite", NULL);
00046        gboolean db_exists = g_file_test(cachefile, G_FILE_TEST_EXISTS);
00047 
00048        if (!db_exists) {
00049               g_warning("There is no HUD usage log: %s", cachefile);
00050               return 1;
00051        }
00052 
00053        sqlite3 * db;
00054        int open_status = sqlite3_open(cachefile, &db); 
00055 
00056        if (open_status != SQLITE_OK) {
00057               g_warning("Error opening usage DB: %s", cachefile);
00058               sqlite3_close(db);
00059               return 1;
00060        }
00061 
00062        gchar * domain = NULL;
00063        if (argv == 3) {
00064               domain = argc[2];
00065        }
00066 
00067        dump_app_info(argc[1], domain, db);
00068 
00069        sqlite3_close(db);
00070        g_free(cachefile);
00071 
00072        return 0;
00073 }