2007-08-13 08:50:06 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
|
|
|
*
|
2008-02-13 13:50:39 -08:00
|
|
|
* Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com>
|
2007-08-13 08:50:06 -07:00
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License Version 2
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2008-11-23 09:19:15 -08:00
|
|
|
#include <locale.h>
|
2007-08-13 08:50:06 -07:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <dbus/dbus-glib.h>
|
2008-10-15 08:03:20 -07:00
|
|
|
#include <packagekit-glib/packagekit.h>
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2008-10-15 08:03:20 -07:00
|
|
|
#include "egg-debug.h"
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2009-02-16 01:59:39 -08:00
|
|
|
static PkControl *control = NULL;
|
|
|
|
static gboolean verbose = FALSE;
|
|
|
|
|
2007-08-13 08:50:06 -07:00
|
|
|
/**
|
2007-08-13 11:37:31 -07:00
|
|
|
* pk_monitor_task_list_changed_cb:
|
2007-08-13 08:50:06 -07:00
|
|
|
**/
|
|
|
|
static void
|
2007-08-13 11:37:31 -07:00
|
|
|
pk_monitor_task_list_changed_cb (PkTaskList *tlist, gpointer data)
|
2007-08-13 08:50:06 -07:00
|
|
|
{
|
2008-09-10 02:20:31 -07:00
|
|
|
guint i;
|
|
|
|
PkTaskListItem *item;
|
|
|
|
guint length;
|
2009-02-16 01:59:39 -08:00
|
|
|
gchar *state;
|
2008-09-10 02:20:31 -07:00
|
|
|
|
|
|
|
length = pk_task_list_get_size (tlist);
|
|
|
|
g_print ("Tasks:\n");
|
|
|
|
if (length == 0) {
|
|
|
|
g_print ("[none]\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i=0; i<length; i++) {
|
|
|
|
item = pk_task_list_get_item (tlist, i);
|
|
|
|
g_print ("#%i\t%s\t%s (%s)\t%s\n", i+1, item->tid, pk_role_enum_to_text (item->role),
|
|
|
|
pk_status_enum_to_text (item->status), item->text);
|
|
|
|
}
|
2009-02-16 01:59:39 -08:00
|
|
|
|
|
|
|
/* only print state when verbose */
|
|
|
|
if (verbose) {
|
|
|
|
state = pk_control_get_daemon_state (control, NULL);
|
|
|
|
g_print ("%s", state);
|
|
|
|
g_free (state);
|
|
|
|
}
|
2007-08-13 08:50:06 -07:00
|
|
|
}
|
|
|
|
|
2008-03-28 04:42:47 -07:00
|
|
|
/**
|
|
|
|
* pk_monitor_repo_list_changed_cb:
|
|
|
|
**/
|
|
|
|
static void
|
2009-02-16 01:59:39 -08:00
|
|
|
pk_monitor_repo_list_changed_cb (PkControl *_control, gpointer data)
|
2008-03-28 04:42:47 -07:00
|
|
|
{
|
|
|
|
g_print ("repo-list-changed\n");
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:40:07 -07:00
|
|
|
/**
|
|
|
|
* pk_monitor_updates_changed_cb:
|
|
|
|
**/
|
|
|
|
static void
|
2009-02-16 01:59:39 -08:00
|
|
|
pk_monitor_updates_changed_cb (PkControl *_control, gpointer data)
|
2008-03-30 08:40:07 -07:00
|
|
|
{
|
|
|
|
g_print ("updates-changed\n");
|
|
|
|
}
|
|
|
|
|
2007-08-20 08:37:32 -07:00
|
|
|
/**
|
2007-08-20 15:42:17 -07:00
|
|
|
* pk_connection_changed_cb:
|
2007-08-20 08:37:32 -07:00
|
|
|
**/
|
|
|
|
static void
|
2007-08-20 15:42:17 -07:00
|
|
|
pk_connection_changed_cb (PkConnection *pconnection, gboolean connected, gpointer data)
|
2007-08-20 08:37:32 -07:00
|
|
|
{
|
2008-08-28 04:44:24 -07:00
|
|
|
egg_debug ("connected=%i", connected);
|
2007-08-20 08:37:32 -07:00
|
|
|
}
|
|
|
|
|
2008-04-08 05:19:34 -07:00
|
|
|
/**
|
|
|
|
* pk_monitor_locked_cb:
|
|
|
|
**/
|
|
|
|
static void
|
2009-02-16 01:59:39 -08:00
|
|
|
pk_monitor_locked_cb (PkControl *_control, gboolean is_locked, gpointer data)
|
2008-04-08 05:19:34 -07:00
|
|
|
{
|
2008-11-17 06:10:40 -08:00
|
|
|
if (is_locked)
|
2008-05-01 15:05:47 -07:00
|
|
|
g_print ("locked\n");
|
2008-11-17 06:10:40 -08:00
|
|
|
else
|
2008-05-01 15:05:47 -07:00
|
|
|
g_print ("unlocked\n");
|
2008-04-08 05:19:34 -07:00
|
|
|
}
|
|
|
|
|
2007-08-13 08:50:06 -07:00
|
|
|
/**
|
|
|
|
* main:
|
|
|
|
**/
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2007-08-13 11:37:31 -07:00
|
|
|
PkTaskList *tlist;
|
2007-08-13 08:50:06 -07:00
|
|
|
gboolean ret;
|
|
|
|
GMainLoop *loop;
|
2007-08-20 15:42:17 -07:00
|
|
|
PkConnection *pconnection;
|
2007-08-20 08:37:32 -07:00
|
|
|
gboolean connected;
|
2007-10-13 18:16:59 -07:00
|
|
|
gboolean program_version = FALSE;
|
2009-02-16 01:59:39 -08:00
|
|
|
gchar *state;
|
2007-10-13 18:16:59 -07:00
|
|
|
GOptionContext *context;
|
|
|
|
|
|
|
|
const GOptionEntry options[] = {
|
|
|
|
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
|
2008-02-26 15:36:56 -08:00
|
|
|
_("Show extra debugging information"), NULL },
|
2007-10-13 18:16:59 -07:00
|
|
|
{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
|
2008-02-26 15:36:56 -08:00
|
|
|
_("Show the program version and exit"), NULL},
|
2007-10-13 18:16:59 -07:00
|
|
|
{ NULL}
|
|
|
|
};
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2008-11-23 09:19:15 -08:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
|
2008-11-17 06:10:40 -08:00
|
|
|
if (! g_thread_supported ())
|
2007-08-13 08:50:06 -07:00
|
|
|
g_thread_init (NULL);
|
|
|
|
dbus_g_thread_init ();
|
|
|
|
g_type_init ();
|
2007-10-13 18:16:59 -07:00
|
|
|
|
|
|
|
context = g_option_context_new (NULL);
|
2009-01-31 03:49:45 -08:00
|
|
|
/* TRANSLATORS: this is a program that monitors PackageKit */
|
2007-10-13 18:16:59 -07:00
|
|
|
g_option_context_set_summary (context, _("PackageKit Monitor"));
|
|
|
|
g_option_context_add_main_entries (context, options, NULL);
|
|
|
|
g_option_context_parse (context, &argc, &argv, NULL);
|
|
|
|
g_option_context_free (context);
|
|
|
|
|
2008-03-25 17:13:09 -07:00
|
|
|
if (program_version) {
|
2007-10-13 18:16:59 -07:00
|
|
|
g_print (VERSION "\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-28 04:44:24 -07:00
|
|
|
egg_debug_init (verbose);
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2007-08-20 08:37:32 -07:00
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2007-08-20 15:42:17 -07:00
|
|
|
pconnection = pk_connection_new ();
|
|
|
|
g_signal_connect (pconnection, "connection-changed",
|
|
|
|
G_CALLBACK (pk_connection_changed_cb), loop);
|
|
|
|
connected = pk_connection_valid (pconnection);
|
2008-08-28 04:44:24 -07:00
|
|
|
egg_debug ("connected=%i", connected);
|
2007-08-20 08:37:32 -07:00
|
|
|
|
2008-04-08 05:19:34 -07:00
|
|
|
control = pk_control_new ();
|
|
|
|
g_signal_connect (control, "locked",
|
|
|
|
G_CALLBACK (pk_monitor_locked_cb), NULL);
|
|
|
|
g_signal_connect (control, "repo-list-changed",
|
2008-03-28 04:42:47 -07:00
|
|
|
G_CALLBACK (pk_monitor_repo_list_changed_cb), NULL);
|
2008-04-08 05:19:34 -07:00
|
|
|
g_signal_connect (control, "updates-changed",
|
2008-03-30 08:40:07 -07:00
|
|
|
G_CALLBACK (pk_monitor_updates_changed_cb), NULL);
|
2007-10-24 11:24:53 -07:00
|
|
|
|
2007-08-13 11:37:31 -07:00
|
|
|
tlist = pk_task_list_new ();
|
2008-04-12 06:32:25 -07:00
|
|
|
g_signal_connect (tlist, "changed",
|
|
|
|
G_CALLBACK (pk_monitor_task_list_changed_cb), NULL);
|
|
|
|
g_signal_connect (tlist, "status-changed",
|
2007-08-13 11:37:31 -07:00
|
|
|
G_CALLBACK (pk_monitor_task_list_changed_cb), NULL);
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2008-11-17 06:10:40 -08:00
|
|
|
|
2008-08-28 04:44:24 -07:00
|
|
|
egg_debug ("refreshing task list");
|
2007-08-13 11:37:31 -07:00
|
|
|
ret = pk_task_list_refresh (tlist);
|
2008-11-17 06:10:40 -08:00
|
|
|
if (!ret)
|
2007-09-21 09:46:30 -07:00
|
|
|
g_error ("cannot refresh transaction list");
|
2007-08-13 11:37:31 -07:00
|
|
|
pk_task_list_print (tlist);
|
2007-08-13 08:50:06 -07:00
|
|
|
|
2009-02-16 01:59:39 -08:00
|
|
|
/* only print state when verbose */
|
|
|
|
if (verbose) {
|
|
|
|
state = pk_control_get_daemon_state (control, NULL);
|
|
|
|
g_print ("%s", state);
|
|
|
|
g_free (state);
|
|
|
|
}
|
|
|
|
|
2008-11-17 06:10:40 -08:00
|
|
|
/* spin */
|
2007-08-13 08:50:06 -07:00
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
2008-04-08 05:19:34 -07:00
|
|
|
g_object_unref (control);
|
2007-08-13 11:37:31 -07:00
|
|
|
g_object_unref (tlist);
|
2007-08-20 15:42:17 -07:00
|
|
|
g_object_unref (pconnection);
|
2007-08-13 08:50:06 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|