Re: About dialog API



On Thu, 2003-04-10 at 09:22, Owen Taylor wrote:
> This perhaps solves the GUI builder problem, but it doesn't solve
> the problem of use from C at all. Creating a GValueArray of strings
> looks to be quite painful, in fact.

  gchar *authors[] = {
    "Peter Mattis",
    "Spencer Kimball",
    "Josh MacDonald",
    "and many more...",
    NULL
  };

  GValueArray *array = g_value_array_new (0);

  for (tmp = authors; tmp != NULL; tmp++) 
    {
      GValue tmp_value = { 0 };
 
      g_value_init (&tmp_value, G_TYPE_STRING);
      g_value_set_string (&tmp_value, tmp);
      g_value_array_append (array, &tmp_value);
    } 

Doesn't look too bad to me. You can make it better by introducing a
little g_value_array_append_string (GValueArray *array, gchar *str)
helper, which would reduce to loop to

for (tmp = authors; tmp != NULL; tmp++)
  g_value_array_append_string (array, tmp);


Matthias





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]