mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-04 23:28:05 +02:00
2005-01-30 Havoc Pennington <hp@redhat.com>
* tools/dbus-names-model.c (have_names_notify): fix this * dbus/dbus-message.c (_dbus_message_iter_get_args_valist): clean up the string array handling a bit
This commit is contained in:
parent
1dcacffc32
commit
d5b7d7a78c
4 changed files with 53 additions and 87 deletions
|
|
@ -1,3 +1,10 @@
|
|||
2005-01-30 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* tools/dbus-names-model.c (have_names_notify): fix this
|
||||
|
||||
* dbus/dbus-message.c (_dbus_message_iter_get_args_valist): clean
|
||||
up the string array handling a bit
|
||||
|
||||
2005-01-30 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* glib/dbus-glib.c (dbus_g_pending_call_set_notify): new function
|
||||
|
|
|
|||
|
|
@ -1765,7 +1765,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
|
|||
spec_element_type == DBUS_TYPE_OBJECT_PATH)
|
||||
{
|
||||
char ***str_array_p;
|
||||
int i;
|
||||
int n_elements;
|
||||
char **str_array;
|
||||
|
||||
str_array_p = va_arg (var_args, char***);
|
||||
|
|
@ -1777,14 +1777,14 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
|
|||
/* Count elements in the array */
|
||||
_dbus_type_reader_recurse (&real->u.reader, &array);
|
||||
|
||||
i = 0;
|
||||
if (_dbus_type_reader_has_next (&array))
|
||||
n_elements = 0;
|
||||
while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID)
|
||||
{
|
||||
while (_dbus_type_reader_next (&array))
|
||||
++i;
|
||||
++n_elements;
|
||||
_dbus_type_reader_next (&array);
|
||||
}
|
||||
|
||||
str_array = dbus_new0 (char*, i + 1);
|
||||
str_array = dbus_new0 (char*, n_elements + 1);
|
||||
if (str_array == NULL)
|
||||
{
|
||||
_DBUS_SET_OOM (error);
|
||||
|
|
@ -1795,29 +1795,32 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
|
|||
_dbus_type_reader_recurse (&real->u.reader, &array);
|
||||
|
||||
i = 0;
|
||||
if (_dbus_type_reader_has_next (&array))
|
||||
while (i < n_elements)
|
||||
{
|
||||
do
|
||||
const char *s;
|
||||
_dbus_type_reader_read_basic (&array,
|
||||
&s);
|
||||
|
||||
str_array[i] = _dbus_strdup (s);
|
||||
if (str_array[i] == NULL)
|
||||
{
|
||||
const char *s;
|
||||
_dbus_type_reader_read_basic (&array,
|
||||
&s);
|
||||
|
||||
str_array[i] = _dbus_strdup (s);
|
||||
if (str_array[i] == NULL)
|
||||
{
|
||||
dbus_free_string_array (str_array);
|
||||
_DBUS_SET_OOM (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
++i;
|
||||
dbus_free_string_array (str_array);
|
||||
_DBUS_SET_OOM (error);
|
||||
goto out;
|
||||
}
|
||||
while (_dbus_type_reader_next (&array));
|
||||
|
||||
++i;
|
||||
|
||||
if (!_dbus_type_reader_next (&array))
|
||||
_dbus_assert (i == n_elements);
|
||||
}
|
||||
|
||||
_dbus_assert (_dbus_type_reader_get_current_type (&array) == DBUS_TYPE_INVALID);
|
||||
_dbus_assert (i == n_elements);
|
||||
_dbus_assert (str_array[i] == NULL);
|
||||
|
||||
*str_array_p = str_array;
|
||||
*n_elements_p = i;
|
||||
*n_elements_p = n_elements;
|
||||
}
|
||||
#ifndef DBUS_DISABLE_CHECKS
|
||||
else
|
||||
|
|
|
|||
|
|
@ -25,63 +25,11 @@
|
|||
|
||||
enum
|
||||
{
|
||||
MODEL_COLUMN_NAME_DATA,
|
||||
MODEL_COLUMN_NAME,
|
||||
|
||||
MODEL_COLUMN_LAST
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int refcount;
|
||||
char *name;
|
||||
} NameData;
|
||||
|
||||
static NameData*
|
||||
name_data_new (const char *name)
|
||||
{
|
||||
NameData *nd;
|
||||
|
||||
nd = g_new0 (NameData, 1);
|
||||
|
||||
nd->refcount = 1;
|
||||
nd->name = g_strdup (name);
|
||||
|
||||
return nd;
|
||||
}
|
||||
|
||||
static NameData*
|
||||
name_data_ref (NameData *nd)
|
||||
{
|
||||
nd->refcount += 1;
|
||||
return nd;
|
||||
}
|
||||
|
||||
static void
|
||||
name_data_unref (NameData *nd)
|
||||
{
|
||||
nd->refcount -= 1;
|
||||
if (nd->refcount == 0)
|
||||
{
|
||||
g_free (nd->name);
|
||||
g_free (nd);
|
||||
}
|
||||
}
|
||||
|
||||
static GType
|
||||
name_data_get_gtype (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static ("NameData",
|
||||
(GBoxedCopyFunc) name_data_ref,
|
||||
(GBoxedFreeFunc) name_data_unref);
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
||||
#define NAME_DATA_TYPE (name_data_get_gtype())
|
||||
|
||||
|
||||
typedef struct NamesModel NamesModel;
|
||||
typedef struct NamesModelClass NamesModelClass;
|
||||
|
|
@ -134,26 +82,29 @@ have_names_notify (DBusGPendingCall *call,
|
|||
g_assert (error != NULL);
|
||||
|
||||
g_printerr (_("Failed to load names on the bus: %s\n"), error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (names[i])
|
||||
{
|
||||
NameData *nd;
|
||||
GtkTreeIter iter;
|
||||
|
||||
nd = name_data_new (names[i]);
|
||||
|
||||
g_assert (i < n_elements);
|
||||
|
||||
#if 0
|
||||
g_printerr ("%d of %d: %s\n",
|
||||
i, n_elements, names[i]);
|
||||
#endif
|
||||
|
||||
gtk_tree_store_append (GTK_TREE_STORE (names_model),
|
||||
&iter, NULL);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (names_model),
|
||||
&iter,
|
||||
MODEL_COLUMN_NAME_DATA, nd,
|
||||
MODEL_COLUMN_NAME, names[i],
|
||||
-1);
|
||||
|
||||
name_data_unref (nd);
|
||||
|
||||
++i;
|
||||
}
|
||||
|
|
@ -315,7 +266,7 @@ names_model_init (NamesModel *names_model)
|
|||
|
||||
tree_store = GTK_TREE_STORE (names_model);
|
||||
|
||||
types[0] = NAME_DATA_TYPE;
|
||||
types[0] = G_TYPE_STRING; /* name */
|
||||
gtk_tree_store_set_column_types (tree_store, MODEL_COLUMN_LAST, types);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,22 +76,27 @@ tree_window_new (DBusGConnection *connection,
|
|||
|
||||
vbox = gtk_vbox_new (FALSE, 6);
|
||||
gtk_container_add (GTK_CONTAINER (w->window), vbox);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 6);
|
||||
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
||||
|
||||
|
||||
/* 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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue