dbus/tools dbus-names-model.c,1.3,1.4 dbus-viewer.c,1.8,1.9
Havoc Pennington
hp at freedesktop.org
Sun Jan 30 19:15:26 PST 2005
Update of /cvs/dbus/dbus/tools
In directory gabe:/tmp/cvs-serv31799/tools
Modified Files:
dbus-names-model.c dbus-viewer.c
Log Message:
2005-01-30 Havoc Pennington <hp at redhat.com>
* tools/dbus-viewer.c: kind of half-ass hook up the option menu.
Index: dbus-names-model.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-names-model.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbus-names-model.c 31 Jan 2005 02:55:12 -0000 1.3
+++ dbus-names-model.c 31 Jan 2005 03:15:24 -0000 1.4
@@ -39,7 +39,7 @@
struct NamesModel
{
- GtkTreeStore parent;
+ GtkListStore parent;
DBusGConnection *connection;
DBusGProxy *driver_proxy;
DBusGPendingCall *pending_list_names;
@@ -47,7 +47,7 @@
struct NamesModelClass
{
- GtkTreeStoreClass parent;
+ GtkListStoreClass parent;
};
#define TYPE_NAMES_MODEL (names_model_get_type ())
@@ -99,10 +99,10 @@
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 @@
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 @@
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 @@
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->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_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 @@
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
Index: dbus-viewer.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-viewer.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dbus-viewer.c 30 Jan 2005 23:29:50 -0000 1.8
+++ dbus-viewer.c 31 Jan 2005 03:15:24 -0000 1.9
@@ -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 @@
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 @@
++i;
}
- if (services)
+ if (services || files == NULL)
{
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
@@ -438,55 +512,51 @@
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;
More information about the dbus-commit
mailing list