summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-01-31 03:15:24 +0000
committerHavoc Pennington <hp@redhat.com>2005-01-31 03:15:24 +0000
commit4f0fd00e9e274f641692fab6bdec2c44f49cee57 (patch)
treef63b7a504ebc5a3719276177b53b59df8993ef4f /tools
parentd2c1a633d15611eb6ca757863c489ebf201d07cd (diff)
2005-01-30 Havoc Pennington <hp@redhat.com>
* tools/dbus-viewer.c: kind of half-ass hook up the option menu.
Diffstat (limited to 'tools')
-rw-r--r--tools/dbus-names-model.c32
-rw-r--r--tools/dbus-viewer.c302
2 files changed, 202 insertions, 132 deletions
diff --git a/tools/dbus-names-model.c b/tools/dbus-names-model.c
index 38c121bc..82016f2f 100644
--- a/tools/dbus-names-model.c
+++ b/tools/dbus-names-model.c
@@ -39,7 +39,7 @@ GType names_model_get_type (void);
struct NamesModel
{
- GtkTreeStore parent;
+ GtkListStore parent;
DBusGConnection *connection;
DBusGProxy *driver_proxy;
DBusGPendingCall *pending_list_names;
@@ -47,7 +47,7 @@ struct NamesModel
struct NamesModelClass
{
- GtkTreeStoreClass parent;
+ GtkListStoreClass parent;
};
#define TYPE_NAMES_MODEL (names_model_get_type ())
@@ -99,10 +99,10 @@ have_names_notify (DBusGPendingCall *call,
i, n_elements, names[i]);
#endif
- gtk_tree_store_append (GTK_TREE_STORE (names_model),
- &iter, NULL);
+ gtk_list_store_append (GTK_LIST_STORE (names_model),
+ &iter);
- gtk_tree_store_set (GTK_TREE_STORE (names_model),
+ gtk_list_store_set (GTK_LIST_STORE (names_model),
&iter,
MODEL_COLUMN_NAME, names[i],
-1);
@@ -167,7 +167,7 @@ name_owner_changed (DBusGProxy *driver_proxy,
GtkTreeIter iter;
if (names_model_find_name (names_model, name, &iter))
- gtk_tree_store_remove (GTK_TREE_STORE (names_model),
+ gtk_list_store_remove (GTK_LIST_STORE (names_model),
&iter);
}
else if (*old_owner == '\0')
@@ -177,10 +177,10 @@ name_owner_changed (DBusGProxy *driver_proxy,
if (!names_model_find_name (names_model, name, &iter))
{
- gtk_tree_store_append (GTK_TREE_STORE (names_model),
- &iter, NULL);
+ gtk_list_store_append (GTK_LIST_STORE (names_model),
+ &iter);
- gtk_tree_store_set (GTK_TREE_STORE (names_model),
+ gtk_list_store_set (GTK_LIST_STORE (names_model),
&iter,
MODEL_COLUMN_NAME, name,
-1);
@@ -191,9 +191,9 @@ name_owner_changed (DBusGProxy *driver_proxy,
static void
names_model_reload (NamesModel *names_model)
{
- GtkTreeStore *tree_store;
+ GtkListStore *list_store;
- tree_store = GTK_TREE_STORE (names_model);
+ list_store = GTK_LIST_STORE (names_model);
if (names_model->pending_list_names)
{
@@ -202,7 +202,7 @@ names_model_reload (NamesModel *names_model)
names_model->pending_list_names = NULL;
}
- gtk_tree_store_clear (tree_store);
+ gtk_list_store_clear (list_store);
if (names_model->connection == NULL)
return;
@@ -266,7 +266,7 @@ names_model_set_connection (NamesModel *names_model,
names_model_reload (names_model);
}
-G_DEFINE_TYPE(NamesModel, names_model, GTK_TYPE_TREE_STORE)
+G_DEFINE_TYPE(NamesModel, names_model, GTK_TYPE_LIST_STORE)
/* Properties */
enum
@@ -348,13 +348,13 @@ names_model_get_property (GObject *object,
static void
names_model_init (NamesModel *names_model)
{
- GtkTreeStore *tree_store;
+ GtkListStore *list_store;
GType types[MODEL_COLUMN_LAST];
- tree_store = GTK_TREE_STORE (names_model);
+ list_store = GTK_LIST_STORE (names_model);
types[0] = G_TYPE_STRING; /* name */
- gtk_tree_store_set_column_types (tree_store, MODEL_COLUMN_LAST, types);
+ gtk_list_store_set_column_types (list_store, MODEL_COLUMN_LAST, types);
}
static void
diff --git a/tools/dbus-viewer.c b/tools/dbus-viewer.c
index 41660135..c3903097 100644
--- a/tools/dbus-viewer.c
+++ b/tools/dbus-viewer.c
@@ -33,88 +33,6 @@
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
-typedef struct
-{
- GtkWidget *window;
- GtkWidget *treeview;
- GtkWidget *name_menu;
-
- GtkTreeModel *names_model;
-
-} TreeWindow;
-
-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->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);
- }
-
- /* 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;
-}
-
static void
show_error_dialog (GtkWindow *transient_parent,
GtkWidget **weak_ptr,
@@ -340,6 +258,162 @@ load_from_service (DBusGConnection *connection,
return node;
}
+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);
+}
+
+static void
+tree_window_set_service (TreeWindow *w,
+ const char *service_name)
+{
+ GError *error;
+ NodeInfo *node;
+
+ error = NULL;
+ node = load_from_service (w->connection, service_name, &error);
+ if (node == NULL)
+ {
+ g_assert (error != NULL);
+ show_error_dialog (GTK_WINDOW (w->window), &w->error_dialog,
+ _("Unable to load \"%s\": %s\n"),
+ service_name, error->message);
+ g_error_free (error);
+ return;
+ }
+
+ tree_window_set_node (w, node);
+
+ node_info_unref (node);
+}
+
+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;
+}
+
static void
usage (int ecode)
{
@@ -417,7 +491,7 @@ main (int argc, char **argv)
++i;
}
- if (services)
+ if (services || files == NULL)
{
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
@@ -438,55 +512,51 @@ main (int argc, char **argv)
connection = NULL;
names_model = NULL;
}
+
+ if (files == NULL)
+ {
+ TreeWindow *w;
+
+ w = tree_window_new (connection, names_model);
+ }
files = g_slist_reverse (files);
tmp = files;
while (tmp != NULL)
{
- NodeInfo *node;
const char *filename;
+ TreeWindow *w;
filename = tmp->data;
-
- error = NULL;
- if (services)
- node = load_from_service (connection, filename, &error);
- else
- node = description_load_from_file (filename,
- &error);
- if (node == NULL)
+ if (services)
{
- g_assert (error != NULL);
- show_error_dialog (NULL, NULL,
- _("Unable to load \"%s\": %s\n"),
- filename, error->message);
- g_error_free (error);
+ w = tree_window_new (connection, names_model);
+ tree_window_set_service (w, filename);
}
else
{
- TreeWindow *w;
- char **path;
- const char *name;
-
- name = node_info_get_name (node);
- if (name == NULL ||
- name[0] != '/')
+ NodeInfo *node;
+
+ error = NULL;
+ node = description_load_from_file (filename,
+ &error);
+
+ if (node == NULL)
{
- g_printerr (_("Assuming root node of \"%s\" is at path /, since no absolute path is specified"), filename);
- name = "/";
+ 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);
}
-
- path = _dbus_gutils_split_path (name);
-
- w = tree_window_new (connection, names_model);
- dbus_tree_view_update (GTK_TREE_VIEW (w->treeview),
- (const char**) path,
- node);
- node_info_unref (node);
-
- g_strfreev (path);
}
tmp = tmp->next;