2003-09-17 13:56:29 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* dbus-viewer.c Graphical D-BUS frontend utility
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
2004-08-10 03:07:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2003-09-17 13:56:29 +00:00
|
|
|
*
|
|
|
|
|
* 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 <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include "dbus-tree-view.h"
|
2005-01-30 23:06:32 +00:00
|
|
|
#include "dbus-names-model.h"
|
2003-09-17 13:56:29 +00:00
|
|
|
#include <glib/dbus-gparser.h>
|
|
|
|
|
#include <glib/dbus-gutils.h>
|
2005-01-30 05:18:44 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
2005-01-30 23:06:32 +00:00
|
|
|
#include <glib/gi18n.h>
|
2003-09-17 13:56:29 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_error_dialog (GtkWindow *transient_parent,
|
|
|
|
|
GtkWidget **weak_ptr,
|
|
|
|
|
const char *message_format,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
char *message;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
if (message_format)
|
|
|
|
|
{
|
|
|
|
|
va_start (args, message_format);
|
|
|
|
|
message = g_strdup_vprintf (message_format, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
message = NULL;
|
|
|
|
|
|
|
|
|
|
if (weak_ptr == NULL || *weak_ptr == NULL)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
dialog = gtk_message_dialog_new (transient_parent,
|
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
|
message);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
|
|
|
|
|
|
if (weak_ptr != NULL)
|
|
|
|
|
{
|
|
|
|
|
*weak_ptr = dialog;
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (dialog), (void**)weak_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
|
|
|
|
|
gtk_widget_show_all (dialog);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MESSAGE_DIALOG (*weak_ptr));
|
|
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (*weak_ptr)->label), message);
|
|
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (*weak_ptr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
DBusGConnection *connection;
|
|
|
|
|
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
GtkWidget *treeview;
|
|
|
|
|
GtkWidget *name_menu;
|
|
|
|
|
|
|
|
|
|
GtkTreeModel *names_model;
|
|
|
|
|
|
|
|
|
|
GtkWidget *error_dialog;
|
|
|
|
|
|
|
|
|
|
} TreeWindow;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tree_window_set_node (TreeWindow *w,
|
|
|
|
|
NodeInfo *node)
|
|
|
|
|
{
|
|
|
|
|
char **path;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
name = node_info_get_name (node);
|
|
|
|
|
if (name == NULL ||
|
|
|
|
|
name[0] != '/')
|
|
|
|
|
{
|
|
|
|
|
g_printerr (_("Assuming root node is at path /, since no absolute path is specified"));
|
|
|
|
|
name = "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = _dbus_gutils_split_path (name);
|
|
|
|
|
|
|
|
|
|
dbus_tree_view_update (GTK_TREE_VIEW (w->treeview),
|
|
|
|
|
(const char**) path,
|
|
|
|
|
node);
|
|
|
|
|
|
|
|
|
|
g_strfreev (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
DBusGConnection *connection;
|
|
|
|
|
char *service_name;
|
|
|
|
|
GError *error;
|
|
|
|
|
NodeInfo *node;
|
|
|
|
|
TreeWindow *window; /* Not touched from child thread */
|
|
|
|
|
} LoadFromServiceData;
|
|
|
|
|
|
2005-01-30 05:18:44 +00:00
|
|
|
static gboolean
|
|
|
|
|
load_child_nodes (const char *service_name,
|
|
|
|
|
NodeInfo *parent,
|
2005-01-30 07:44:08 +00:00
|
|
|
GString *path,
|
2005-01-30 05:18:44 +00:00
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
DBusGConnection *connection;
|
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
|
|
connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
return FALSE;
|
2005-01-30 07:44:08 +00:00
|
|
|
|
2005-01-30 05:18:44 +00:00
|
|
|
tmp = node_info_get_nodes (parent);
|
|
|
|
|
while (tmp != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusGProxy *proxy;
|
|
|
|
|
DBusGPendingCall *call;
|
|
|
|
|
const char *data;
|
|
|
|
|
NodeInfo *child;
|
|
|
|
|
NodeInfo *complete_child;
|
2005-01-30 07:44:08 +00:00
|
|
|
int save_len;
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
complete_child = NULL;
|
2005-01-30 07:44:08 +00:00
|
|
|
call = NULL;
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
child = tmp->data;
|
|
|
|
|
|
2005-01-30 07:44:08 +00:00
|
|
|
save_len = path->len;
|
|
|
|
|
|
|
|
|
|
if (save_len > 1)
|
|
|
|
|
g_string_append (path, "/");
|
|
|
|
|
g_string_append (path, base_info_get_name ((BaseInfo*)child));
|
|
|
|
|
|
|
|
|
|
if (*service_name == ':')
|
|
|
|
|
{
|
|
|
|
|
proxy = dbus_g_proxy_new_for_name (connection,
|
|
|
|
|
service_name,
|
|
|
|
|
path->str,
|
2005-02-17 21:19:49 +00:00
|
|
|
DBUS_INTERFACE_INTROSPECTABLE);
|
2005-01-30 07:44:08 +00:00
|
|
|
g_assert (proxy != NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
proxy = dbus_g_proxy_new_for_name_owner (connection,
|
|
|
|
|
service_name,
|
|
|
|
|
path->str,
|
2005-02-17 21:19:49 +00:00
|
|
|
DBUS_INTERFACE_INTROSPECTABLE,
|
2005-01-30 07:44:08 +00:00
|
|
|
error);
|
|
|
|
|
if (proxy == NULL)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
call = dbus_g_proxy_begin_call (proxy, "Introspect",
|
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
|
|
|
|
|
data = NULL;
|
|
|
|
|
if (!dbus_g_proxy_end_call (proxy, call, error, DBUS_TYPE_STRING, &data,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
complete_child = description_load_from_string (data, -1, error);
|
|
|
|
|
if (complete_child == NULL)
|
2005-01-30 07:44:08 +00:00
|
|
|
{
|
|
|
|
|
g_printerr ("%s\n", data);
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
done:
|
2005-01-30 07:44:08 +00:00
|
|
|
if (call)
|
|
|
|
|
dbus_g_pending_call_unref (call);
|
2005-01-30 05:18:44 +00:00
|
|
|
g_object_unref (proxy);
|
|
|
|
|
|
|
|
|
|
if (complete_child == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* change complete_child's name to relative */
|
|
|
|
|
base_info_set_name ((BaseInfo*)complete_child,
|
|
|
|
|
base_info_get_name ((BaseInfo*)child));
|
|
|
|
|
|
|
|
|
|
/* Stitch in complete_child rather than child */
|
|
|
|
|
node_info_replace_node (parent, child, complete_child);
|
|
|
|
|
node_info_unref (complete_child); /* ref still held by parent */
|
|
|
|
|
|
|
|
|
|
/* Now recurse */
|
2005-01-30 07:44:08 +00:00
|
|
|
if (!load_child_nodes (service_name, complete_child, path, error))
|
2005-01-30 05:18:44 +00:00
|
|
|
return FALSE;
|
2005-01-30 07:44:08 +00:00
|
|
|
|
|
|
|
|
/* restore path */
|
|
|
|
|
g_string_set_size (path, save_len);
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
static gboolean
|
|
|
|
|
load_from_service_complete_idle (void *data)
|
2005-01-30 05:18:44 +00:00
|
|
|
{
|
2005-02-13 17:16:25 +00:00
|
|
|
/* Called in main thread */
|
|
|
|
|
GThread *thread = data;
|
|
|
|
|
LoadFromServiceData *d;
|
|
|
|
|
NodeInfo *node;
|
|
|
|
|
|
|
|
|
|
d = g_thread_join (thread);
|
|
|
|
|
|
|
|
|
|
node = d->node;
|
|
|
|
|
|
|
|
|
|
if (d->error)
|
|
|
|
|
{
|
|
|
|
|
g_assert (d->node == NULL);
|
|
|
|
|
show_error_dialog (GTK_WINDOW (d->window->window), &d->window->error_dialog,
|
|
|
|
|
_("Unable to load \"%s\": %s\n"),
|
|
|
|
|
d->service_name, d->error->message);
|
|
|
|
|
g_error_free (d->error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert (d->error == NULL);
|
|
|
|
|
|
|
|
|
|
tree_window_set_node (d->window, node);
|
|
|
|
|
node_info_unref (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (d->service_name);
|
|
|
|
|
dbus_g_connection_unref (d->connection);
|
|
|
|
|
g_free (d);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
load_from_service_thread_func (void *thread_data)
|
|
|
|
|
{
|
|
|
|
|
DBusGProxy *root_proxy;
|
2005-01-30 05:18:44 +00:00
|
|
|
DBusGPendingCall *call;
|
|
|
|
|
const char *data;
|
|
|
|
|
NodeInfo *node;
|
2005-01-30 07:44:08 +00:00
|
|
|
GString *path;
|
2005-02-13 17:16:25 +00:00
|
|
|
LoadFromServiceData *lfsd;
|
|
|
|
|
|
|
|
|
|
lfsd = thread_data;
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
node = NULL;
|
|
|
|
|
call = NULL;
|
2005-01-30 07:44:08 +00:00
|
|
|
path = NULL;
|
2005-01-30 23:06:32 +00:00
|
|
|
|
2005-01-30 07:44:08 +00:00
|
|
|
#if 1
|
|
|
|
|
/* this will end up autolaunching the service when we introspect it */
|
2005-02-13 17:16:25 +00:00
|
|
|
root_proxy = dbus_g_proxy_new_for_name (lfsd->connection,
|
|
|
|
|
lfsd->service_name,
|
2005-01-30 07:44:08 +00:00
|
|
|
"/",
|
2005-02-17 21:19:49 +00:00
|
|
|
DBUS_INTERFACE_INTROSPECTABLE);
|
2005-01-30 07:44:08 +00:00
|
|
|
g_assert (root_proxy != NULL);
|
|
|
|
|
#else
|
|
|
|
|
/* this will be an error if the service doesn't exist */
|
2005-02-13 17:16:25 +00:00
|
|
|
root_proxy = dbus_g_proxy_new_for_name_owner (lfsd->connection,
|
|
|
|
|
lfsd->service_name,
|
2005-01-30 05:18:44 +00:00
|
|
|
"/",
|
2005-02-17 21:19:49 +00:00
|
|
|
DBUS_INTERFACE_INTROSPECTABLE,
|
2005-02-13 17:16:25 +00:00
|
|
|
&lfsd->error);
|
2005-01-30 05:18:44 +00:00
|
|
|
if (root_proxy == NULL)
|
2005-01-30 07:44:08 +00:00
|
|
|
{
|
2005-02-13 17:16:25 +00:00
|
|
|
g_printerr ("Failed to get owner of '%s'\n", lfsd->service_name);
|
|
|
|
|
return lfsd->data;
|
2005-01-30 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
call = dbus_g_proxy_begin_call (root_proxy, "Introspect",
|
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
|
|
|
|
|
data = NULL;
|
2005-02-13 17:16:25 +00:00
|
|
|
if (!dbus_g_proxy_end_call (root_proxy, call, &lfsd->error, DBUS_TYPE_STRING, &data,
|
2005-01-30 05:18:44 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2005-01-30 07:44:08 +00:00
|
|
|
{
|
|
|
|
|
g_printerr ("Failed to Introspect() %s\n",
|
|
|
|
|
dbus_g_proxy_get_bus_name (root_proxy));
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2005-01-30 05:18:44 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
node = description_load_from_string (data, -1, &lfsd->error);
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
/* g_print ("%s\n", data); */
|
|
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
base_info_set_name ((BaseInfo*)node, "/");
|
2005-01-30 07:44:08 +00:00
|
|
|
|
|
|
|
|
path = g_string_new ("/");
|
2005-01-30 05:18:44 +00:00
|
|
|
|
|
|
|
|
if (!load_child_nodes (dbus_g_proxy_get_bus_name (root_proxy),
|
2005-02-13 17:16:25 +00:00
|
|
|
node, path, &lfsd->error))
|
2005-01-30 05:18:44 +00:00
|
|
|
{
|
|
|
|
|
node_info_unref (node);
|
|
|
|
|
node = NULL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (call)
|
|
|
|
|
dbus_g_pending_call_unref (call);
|
|
|
|
|
|
|
|
|
|
g_object_unref (root_proxy);
|
2005-01-30 07:44:08 +00:00
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
|
g_string_free (path, TRUE);
|
2005-01-30 05:18:44 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
lfsd->node = node;
|
|
|
|
|
g_assert (lfsd->node || lfsd->error);
|
|
|
|
|
g_assert (lfsd->node == NULL || lfsd->error == NULL);
|
2005-01-31 03:15:24 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
/* Add idle to main thread that will join us back */
|
|
|
|
|
g_idle_add (load_from_service_complete_idle, g_thread_self ());
|
2005-01-31 03:15:24 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
return lfsd;
|
|
|
|
|
}
|
2005-01-31 03:15:24 +00:00
|
|
|
|
|
|
|
|
static void
|
2005-02-13 17:16:25 +00:00
|
|
|
start_load_from_service (TreeWindow *w,
|
|
|
|
|
DBusGConnection *connection,
|
|
|
|
|
const char *service_name)
|
2005-01-31 03:15:24 +00:00
|
|
|
{
|
2005-02-13 17:16:25 +00:00
|
|
|
LoadFromServiceData *d;
|
2005-01-31 03:15:24 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
d = g_new0 (LoadFromServiceData, 1);
|
2005-01-31 03:15:24 +00:00
|
|
|
|
2005-02-13 17:16:25 +00:00
|
|
|
d->connection = dbus_g_connection_ref (connection);
|
|
|
|
|
d->service_name = g_strdup (service_name);
|
|
|
|
|
d->error = NULL;
|
|
|
|
|
d->node = NULL;
|
|
|
|
|
d->window = w;
|
|
|
|
|
|
|
|
|
|
g_thread_create (load_from_service_thread_func, d, TRUE, NULL);
|
2005-01-31 03:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tree_window_set_service (TreeWindow *w,
|
|
|
|
|
const char *service_name)
|
|
|
|
|
{
|
2005-02-13 17:16:25 +00:00
|
|
|
start_load_from_service (w, w->connection, service_name);
|
2005-01-31 03:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
name_combo_changed_callback (GtkComboBox *combo,
|
|
|
|
|
TreeWindow *w)
|
|
|
|
|
{
|
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
|
|
text = gtk_combo_box_get_active_text (combo);
|
|
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
|
{
|
|
|
|
|
tree_window_set_service (w, text);
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
window_closed_callback (GtkWidget *window,
|
|
|
|
|
TreeWindow *w)
|
|
|
|
|
{
|
|
|
|
|
g_assert (window == w->window);
|
|
|
|
|
w->window = NULL;
|
|
|
|
|
gtk_main_quit ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TreeWindow*
|
|
|
|
|
tree_window_new (DBusGConnection *connection,
|
|
|
|
|
GtkTreeModel *names_model)
|
|
|
|
|
{
|
|
|
|
|
TreeWindow *w;
|
|
|
|
|
GtkWidget *sw;
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
GtkWidget *hbox;
|
|
|
|
|
GtkWidget *combo;
|
|
|
|
|
|
|
|
|
|
/* Should use glade, blah */
|
|
|
|
|
|
|
|
|
|
w = g_new0 (TreeWindow, 1);
|
|
|
|
|
w->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (w->window), "D-BUS Viewer");
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (w->window), 400, 500);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (w->window, "destroy", G_CALLBACK (window_closed_callback),
|
|
|
|
|
w);
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (w->window), 6);
|
|
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (w->window), vbox);
|
|
|
|
|
|
|
|
|
|
/* Create names option menu */
|
|
|
|
|
if (connection)
|
|
|
|
|
{
|
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
|
|
|
|
|
|
w->connection = connection;
|
|
|
|
|
|
|
|
|
|
w->names_model = names_model;
|
|
|
|
|
|
|
|
|
|
combo = gtk_combo_box_new_with_model (w->names_model);
|
|
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
|
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
|
|
|
|
|
"text", 0,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (combo, "changed",
|
|
|
|
|
G_CALLBACK (name_combo_changed_callback),
|
|
|
|
|
w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create tree view */
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
|
|
w->treeview = dbus_tree_view_new ();
|
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sw), w->treeview);
|
|
|
|
|
|
|
|
|
|
/* Show everything */
|
|
|
|
|
gtk_widget_show_all (w->window);
|
|
|
|
|
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-17 13:56:29 +00:00
|
|
|
static void
|
|
|
|
|
usage (int ecode)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "dbus-viewer [--version] [--help]\n");
|
|
|
|
|
exit (ecode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
version (void)
|
|
|
|
|
{
|
|
|
|
|
printf ("D-BUS Message Bus Viewer %s\n"
|
|
|
|
|
"Copyright (C) 2003 Red Hat, Inc.\n"
|
|
|
|
|
"This is free software; see the source for copying conditions.\n"
|
|
|
|
|
"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
|
|
|
|
VERSION);
|
|
|
|
|
exit (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
const char *prev_arg;
|
|
|
|
|
int i;
|
|
|
|
|
GSList *files;
|
|
|
|
|
gboolean end_of_args;
|
|
|
|
|
GSList *tmp;
|
2005-01-30 05:18:44 +00:00
|
|
|
gboolean services;
|
2005-01-30 23:06:32 +00:00
|
|
|
DBusGConnection *connection;
|
|
|
|
|
GError *error;
|
|
|
|
|
GtkTreeModel *names_model;
|
2005-02-13 17:16:25 +00:00
|
|
|
|
|
|
|
|
g_thread_init (NULL);
|
|
|
|
|
dbus_g_thread_init ();
|
2003-09-17 13:56:29 +00:00
|
|
|
|
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
|
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
2005-02-13 17:16:25 +00:00
|
|
|
textdomain (GETTEXT_PACKAGE);
|
2003-09-17 13:56:29 +00:00
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
2005-01-30 05:18:44 +00:00
|
|
|
services = FALSE;
|
2003-09-17 13:56:29 +00:00
|
|
|
end_of_args = FALSE;
|
|
|
|
|
files = NULL;
|
|
|
|
|
prev_arg = NULL;
|
|
|
|
|
i = 1;
|
|
|
|
|
while (i < argc)
|
|
|
|
|
{
|
|
|
|
|
const char *arg = argv[i];
|
|
|
|
|
|
|
|
|
|
if (!end_of_args)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (arg, "--help") == 0 ||
|
|
|
|
|
strcmp (arg, "-h") == 0 ||
|
|
|
|
|
strcmp (arg, "-?") == 0)
|
|
|
|
|
usage (0);
|
|
|
|
|
else if (strcmp (arg, "--version") == 0)
|
|
|
|
|
version ();
|
2005-01-30 05:18:44 +00:00
|
|
|
else if (strcmp (arg, "--services") == 0)
|
|
|
|
|
services = TRUE;
|
2003-09-17 13:56:29 +00:00
|
|
|
else if (arg[0] == '-' &&
|
|
|
|
|
arg[1] == '-' &&
|
|
|
|
|
arg[2] == '\0')
|
|
|
|
|
end_of_args = TRUE;
|
|
|
|
|
else if (arg[0] == '-')
|
|
|
|
|
{
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
files = g_slist_prepend (files, (char*) arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
files = g_slist_prepend (files, (char*) arg);
|
|
|
|
|
|
|
|
|
|
prev_arg = arg;
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-31 03:15:24 +00:00
|
|
|
if (services || files == NULL)
|
2005-01-30 23:06:32 +00:00
|
|
|
{
|
|
|
|
|
error = NULL;
|
|
|
|
|
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Could not open bus connection: %s\n",
|
|
|
|
|
error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
|
|
|
|
|
|
|
|
|
|
names_model = names_model_new (connection);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connection = NULL;
|
|
|
|
|
names_model = NULL;
|
|
|
|
|
}
|
2005-01-31 03:15:24 +00:00
|
|
|
|
|
|
|
|
if (files == NULL)
|
|
|
|
|
{
|
|
|
|
|
TreeWindow *w;
|
|
|
|
|
|
|
|
|
|
w = tree_window_new (connection, names_model);
|
|
|
|
|
}
|
2005-01-30 23:06:32 +00:00
|
|
|
|
2003-09-17 13:56:29 +00:00
|
|
|
files = g_slist_reverse (files);
|
|
|
|
|
|
|
|
|
|
tmp = files;
|
|
|
|
|
while (tmp != NULL)
|
|
|
|
|
{
|
|
|
|
|
const char *filename;
|
2005-01-31 03:15:24 +00:00
|
|
|
TreeWindow *w;
|
2003-09-17 13:56:29 +00:00
|
|
|
|
|
|
|
|
filename = tmp->data;
|
2005-01-30 05:18:44 +00:00
|
|
|
|
2005-01-31 03:15:24 +00:00
|
|
|
if (services)
|
2003-09-17 13:56:29 +00:00
|
|
|
{
|
2005-01-31 03:15:24 +00:00
|
|
|
w = tree_window_new (connection, names_model);
|
|
|
|
|
tree_window_set_service (w, filename);
|
2003-09-17 13:56:29 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-01-31 03:15:24 +00:00
|
|
|
NodeInfo *node;
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
node = description_load_from_file (filename,
|
|
|
|
|
&error);
|
|
|
|
|
|
|
|
|
|
if (node == NULL)
|
2003-09-17 13:56:29 +00:00
|
|
|
{
|
2005-01-31 03:15:24 +00:00
|
|
|
g_assert (error != NULL);
|
|
|
|
|
show_error_dialog (NULL, NULL,
|
|
|
|
|
_("Unable to load \"%s\": %s\n"),
|
|
|
|
|
filename, error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
w = tree_window_new (connection, names_model);
|
|
|
|
|
tree_window_set_node (w, node);
|
|
|
|
|
node_info_unref (node);
|
2003-09-17 13:56:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|