Ejemplo n.º 1
0
static void
gimp_plug_in_procedure_execute_async (GimpProcedure *procedure,
                                      Gimp          *gimp,
                                      GimpContext   *context,
                                      GimpProgress  *progress,
                                      GValueArray   *args,
                                      GimpObject    *display)
{
  GimpPlugInProcedure *plug_in_procedure = GIMP_PLUG_IN_PROCEDURE (procedure);
  GValueArray         *return_vals;

  return_vals = gimp_plug_in_manager_call_run (gimp->plug_in_manager,
                                               context, progress,
                                               plug_in_procedure,
                                               args, FALSE, display);

  if (return_vals)
    {
      gimp_plug_in_procedure_handle_return_values (plug_in_procedure,
                                                   gimp, progress,
                                                   return_vals);
      g_value_array_free (return_vals);
    }
}
static void
about_set_authors (GladeXML *xml, GtkWidget *w,
		   const char *name, const char *value)
{
    char **authors;
    GValueArray *authors_array;
    int i;

    authors = g_strsplit (value, "\n", 0);
    authors_array = g_value_array_new (0);
	
    for (i = 0; authors[i] != NULL; i++) {
	GValue value = { 0 };
		g_value_init (&value, G_TYPE_STRING);
	g_value_set_static_string (&value, authors[i]);
	authors_array = g_value_array_append (authors_array, &value);
    }

    g_object_set (G_OBJECT (w), "authors", authors_array, NULL);

    g_value_array_free (authors_array);

    g_strfreev (authors);
}
Ejemplo n.º 3
0
static void
do_echo (SoupMessage *msg, GValueArray *params)
{
	int i;
	const char *val;
	GValueArray *in, *out;

	if (!soup_value_array_get_nth (params, 0, G_TYPE_VALUE_ARRAY, &in)) {
		type_error (msg, G_TYPE_VALUE_ARRAY, params, 0);
		return;
	}

	out = g_value_array_new (in->n_values);
	for (i = 0; i < in->n_values; i++) {
		if (!soup_value_array_get_nth (in, i, G_TYPE_STRING, &val)) {
			type_error (msg, G_TYPE_STRING, in, i);
			return;
		}
		soup_value_array_append (out, G_TYPE_STRING, val);
	}

	soup_xmlrpc_set_response (msg, G_TYPE_VALUE_ARRAY, out);
	g_value_array_free (out);
}
Ejemplo n.º 4
0
static void
gst_audio_mixer_filter_probe_feature (GstAudioMixerFilterFunc filter_func,
    GstElementFactory * factory,
    GList ** p_collection, gboolean first, gpointer user_data)
{
  GstElement *element;

  GST_DEBUG ("probing %s ...", gst_element_factory_get_longname (factory));

  /* create element */
  element = gst_element_factory_create (factory, NULL);

  if (element == NULL) {
    GST_DEBUG ("could not create element from factory");
    return;
  }

  GST_DEBUG ("created element %s (%p)", GST_ELEMENT_NAME (element), element);

  if (GST_IS_PROPERTY_PROBE (element)) {
    GstPropertyProbe *probe;
    const GParamSpec *devspec;

    probe = GST_PROPERTY_PROBE (element);

    GST_DEBUG ("probing available devices ...");
    if ((devspec = gst_property_probe_get_property (probe, "device"))) {
      GValueArray *array;

      if ((array = gst_property_probe_probe_and_get_values (probe, devspec))) {
        guint n;

        GST_DEBUG ("there are %d available devices", array->n_values);

        /* set all devices and test for mixer */
        for (n = 0; n < array->n_values; n++) {
          GValue *device;

          /* set this device */
          device = g_value_array_get_nth (array, n);
          g_object_set_property (G_OBJECT (element), "device", device);

          GST_DEBUG ("trying device %s ..", g_value_get_string (device));

          if (gst_audio_mixer_filter_check_element (element)) {
            gst_audio_mixer_filter_do_filter (filter_func, factory, &element,
                p_collection, user_data);

            if (first && *p_collection != NULL) {
              GST_DEBUG ("Stopping after first found mixer, as requested");
              break;
            }
          }
        }
        g_value_array_free (array);
      }
    }
  } else {
    GST_DEBUG ("element does not support the property probe interface");

    if (gst_audio_mixer_filter_check_element (element)) {
      gst_audio_mixer_filter_do_filter (filter_func, factory, &element,
          p_collection, user_data);
    }
  }

  if (element) {
    gst_element_set_state (element, GST_STATE_NULL);
    gst_object_unref (element);
  }
}
static GPtrArray *
read_ip6_addresses (GKeyFile *file,
                    const char *setting_name,
                    const char *key)
{
	GPtrArray *addresses;
	struct in6_addr addr, gw;
	guint32 prefix;
	int i = 0;

	addresses = g_ptr_array_sized_new (3);

	/* Look for individual addresses */
	while (i++ < 1000) {
		char *tmp, *key_name, *str_prefix, *str_gw;
		int ret;
		GValueArray *values;
		GByteArray *address;
		GByteArray *gateway;
		GValue value = { 0 };

		key_name = g_strdup_printf ("%s%d", key, i);
		tmp = g_key_file_get_string (file, setting_name, key_name, NULL);
		g_free (key_name);

		if (!tmp)
			break; /* all done */

		/* convert the string array into IPv6 addresses */
		values = g_value_array_new (2); /* NMIP6Address has 2 items */

		/* Split the address and prefix */
		str_prefix = split_prefix (tmp);

		/* address */
		ret = inet_pton (AF_INET6, tmp, &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp);
			g_value_array_free (values);
			goto next;
		}

		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* prefix */
		prefix = 0;
		if (str_prefix) {
			if (!get_one_int (str_prefix, 128, key_name, &prefix)) {
				g_value_array_free (values);
				goto next;
			}
		} else {
			/* Missing prefix defaults to /64 */
			prefix = 64;
		}

		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, prefix);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* Gateway (optional) */
		str_gw = split_gw (str_prefix);
		if (str_gw) {
			ret = inet_pton (AF_INET6, str_gw, &gw);
			if (ret <= 0) {
				g_warning ("%s: ignoring invalid IPv6 %s gateway '%s'", __func__, key_name, tmp);
				g_value_array_free (values);
				goto next;
			}

			if (!IN6_IS_ADDR_UNSPECIFIED (&gw)) {
				gateway = g_byte_array_new ();
				g_byte_array_append (gateway, (guint8 *) gw.s6_addr, 16);
				g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
				g_value_take_boxed (&value, gateway);
				g_value_array_append (values, &value);
				g_value_unset (&value);
			}
		}

		g_ptr_array_add (addresses, values);

next:
		g_free (tmp);
	}

	if (addresses->len < 1) {
		g_ptr_array_free (addresses, TRUE);
		addresses = NULL;
	}

	return addresses;
}
Ejemplo n.º 6
0
static void
gimp_help_call (Gimp        *gimp,
                const gchar *procedure_name,
                const gchar *help_domain,
                const gchar *help_locales,
                const gchar *help_id)
{
  GimpProcedure *procedure;

  /*  Special case the help browser  */
  if (! strcmp (procedure_name, "extension-gimp-help-browser-temp"))
    {
      GValueArray *return_vals;

      return_vals =
        gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                            gimp_get_user_context (gimp),
                                            NULL,
                                            procedure_name,
                                            G_TYPE_STRING, help_domain,
                                            G_TYPE_STRING, help_locales,
                                            G_TYPE_STRING, help_id,
                                            G_TYPE_NONE);

      g_value_array_free (return_vals);

      return;
    }

  /*  Check if a help parser is already running  */
  procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-temp");

  if (! procedure)
    {
      GValueArray  *args         = NULL;
      gint          n_domains    = 0;
      gchar       **help_domains = NULL;
      gchar       **help_uris    = NULL;

      procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help");

      if (! procedure)
        /*  FIXME: error msg  */
        return;

      n_domains = gimp_plug_in_manager_get_help_domains (gimp->plug_in_manager,
                                                         &help_domains,
                                                         &help_uris);

      args = gimp_procedure_get_arguments (procedure);
      gimp_value_array_truncate (args, 4);

      g_value_set_int             (&args->values[0], n_domains);
      gimp_value_take_stringarray (&args->values[1], help_domains, n_domains);
      g_value_set_int             (&args->values[2], n_domains);
      gimp_value_take_stringarray (&args->values[3], help_uris, n_domains);

      gimp_procedure_execute_async (procedure, gimp,
                                    gimp_get_user_context (gimp),
                                    NULL, args, NULL);

      g_value_array_free (args);
    }

  /*  Check if the help parser started properly  */
  procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-temp");

  if (procedure)
    {
      GValueArray *return_vals;

#ifdef GIMP_HELP_DEBUG
      g_printerr ("Calling help via %s: %s %s %s\n",
                  procedure_name,
                  help_domain  ? help_domain  : "(null)",
                  help_locales ? help_locales : "(null)",
                  help_id      ? help_id      : "(null)");
#endif

      return_vals =
        gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                            gimp_get_user_context (gimp),
                                            NULL,
                                            "extension-gimp-help-temp",
                                            G_TYPE_STRING, procedure_name,
                                            G_TYPE_STRING, help_domain,
                                            G_TYPE_STRING, help_locales,
                                            G_TYPE_STRING, help_id,
                                            G_TYPE_NONE);

      g_value_array_free (return_vals);
    }
}
int
main (int argc, char **argv)
{
  DBusGConnection *bus;
  DBusGProxy *remote_object;
  DBusGProxy *remote_object_introspectable;
  GError *error = NULL;
  char **reply_list;
  char **reply_ptr;
  GValueArray *hello_reply_struct;
  GHashTable *hello_reply_dict;
  char *introspect_data;
  guint i;

  g_type_init ();

  {
    GLogLevelFlags fatal_mask;
    
    fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
    fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
    g_log_set_always_fatal (fatal_mask);
  }

  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus)
    lose_gerror ("Couldn't connect to session bus", error);
  
  remote_object = dbus_g_proxy_new_for_name (bus,
					     "org.designfu.SampleService",
					     "/SomeObject",
					     "org.designfu.SampleInterface");

  if (!dbus_g_proxy_call (remote_object, "HelloWorld", &error,
			  G_TYPE_STRING, "Hello from example-client.c!", G_TYPE_INVALID,
			  G_TYPE_STRV, &reply_list, G_TYPE_INVALID))
    lose_gerror ("Failed to complete HelloWorld", error);

  
  if (!dbus_g_proxy_call (remote_object, "GetTuple", &error,
			  G_TYPE_INVALID,
			  G_TYPE_VALUE_ARRAY, &hello_reply_struct, G_TYPE_INVALID))
    lose_gerror ("Failed to complete GetTuple", error);
  
  if (!dbus_g_proxy_call (remote_object, "GetDict", &error,
			  G_TYPE_INVALID,
			  DBUS_TYPE_G_STRING_STRING_HASHTABLE, &hello_reply_dict, G_TYPE_INVALID))
    lose_gerror ("Failed to complete GetDict", error);

  printf ("reply_list: ");
  for (reply_ptr = reply_list; *reply_ptr; reply_ptr++)
    printf ("\"%s\" ", *reply_ptr);
  printf ("\n");
  g_strfreev (reply_list);

  for (i = 0; i < hello_reply_struct->n_values; i++)
    {
      GValue strval = { 0, };

      g_value_init (&strval, G_TYPE_STRING);
      if (!g_value_transform (g_value_array_get_nth (hello_reply_struct, i), &strval))
	g_value_set_static_string (&strval, "(couldn't transform to string)");
      g_print ("%s: %s\n", g_type_name (G_VALUE_TYPE (g_value_array_get_nth (hello_reply_struct, i))),
	       g_value_get_string (&strval));
    }
  g_value_array_free (hello_reply_struct);
  printf ("\n");

  g_hash_table_foreach (hello_reply_dict, print_hash_value, NULL);
  g_hash_table_destroy (hello_reply_dict);

  remote_object_introspectable = dbus_g_proxy_new_for_name (bus,
							    "org.designfu.SampleService",
							    "/SomeObject",
							    "org.freedesktop.DBus.Introspectable");
  if (!dbus_g_proxy_call (remote_object_introspectable, "Introspect", &error,
			  G_TYPE_INVALID,
			  G_TYPE_STRING, &introspect_data, G_TYPE_INVALID))
    lose_gerror ("Failed to complete Introspect", error);
  printf ("%s", introspect_data);
  g_free (introspect_data);

  g_object_unref (G_OBJECT (remote_object_introspectable));
  g_object_unref (G_OBJECT (remote_object));

  exit(0);
}
Ejemplo n.º 8
0
void
sipe_backend_media_relays_free(struct sipe_backend_media_relays *media_relays)
{
	g_value_array_free((GValueArray *)media_relays);
}
Ejemplo n.º 9
0
//! mengambil combo box pilihan id
static GtkWidget *modifGetPilihanId(GtkWidget *bagian){
	gboolean status = FALSE;
	GtkWidget *dialog , *content_area;
	GtkWidget *label1;
	GtkWidget *table;
	dialog = gtk_dialog_new();
	table = gtk_table_new(1, 1, FALSE);
	//
	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
	
	char *str = "<b>Id</b>";
	label1 = gtk_label_new(NULL);
	gtk_label_set_markup(GTK_LABEL(label1), str);
		
	gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);

	//! isinya combobox
    GtkListStore    *store;
    GtkTreeIter      iter;
    GtkCellRenderer *cell;
	store = gtk_list_store_new ( 1, G_TYPE_STRING );
	
	GValueArray* has = databaseGetDatasFromDb("select id from isi ", NULL , &status);
	gint i;
	for(i=0;i<has->n_values;i++){
		GValue *ii = g_value_array_get_nth (has	,i );
		gchar *tmp = g_strdup_printf ("%i", g_value_get_int(ii)  );
		gtk_list_store_append( store, &iter);
		gtk_list_store_set( store, &iter, 0, tmp, -1 );
		
		//! free
		g_free(tmp);
	}
 
//	GtkWidget* bagian   = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
//	bagian   = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
	gtk_combo_box_set_model ( (GtkComboBox *) bagian,(GtkTreeModel *)store);
	gtk_combo_box_set_active( (GtkComboBox *) bagian,0);
	cell = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( bagian ), cell, TRUE );
    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( bagian ), cell, "text", 0, NULL );
	
	gtk_combo_box_set_row_span_column(bagian,0);
	
	gtk_table_attach(GTK_TABLE(table), bagian		, 1, 2	, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_SHRINK, 5, 5);
	
	gtk_window_set_default_size(GTK_WINDOW(dialog), 250, 100);
	gtk_container_add (GTK_CONTAINER (content_area), table );
	modifAddButton(dialog,GTK_RESPONSE_CANCEL);
	gchar *tmp = g_strdup_printf ("Pilih Id - %s", globalGetAppName()); 
	gtk_window_set_title(GTK_WINDOW(dialog), tmp);

	gtk_dialog_set_has_separator(dialog,TRUE);
//	data = bagian;	
	gtk_dialog_set_has_separator(dialog,TRUE);
	gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE );
	gtk_window_set_transient_for( GTK_WINDOW( dialog ),GTK_WINDOW( globalGetParent() ) );

	//! free
	g_value_array_free (has);
	g_object_unref( G_OBJECT( store ) );

	return dialog;
}
Ejemplo n.º 10
0
static void
change_background(PanelApplet * widget,
                  PanelAppletBackgroundType type,
                  GdkColor * color,
                  GdkPixmap * pixmap,
                  void *data)
{
  static GdkPixmap *keep = NULL;
  long xid = 0;
  GValueArray *val = g_value_array_new(4);

  if (type == PANEL_NO_BACKGROUND)
    {
      GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(widget));

      if (style->bg_pixmap[GTK_STATE_NORMAL])
        {
          pixmap = style->bg_pixmap[GTK_STATE_NORMAL];
          type = PANEL_PIXMAP_BACKGROUND;
        }
      else
        {
          color = &style->bg[GTK_STATE_NORMAL];
          if (color != NULL)
            {
              type = PANEL_COLOR_BACKGROUND;
            }
        }
    }
  
  if (type == PANEL_COLOR_BACKGROUND && color != NULL)
    {
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 0), color->pixel);
 
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 1), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 1), color->red);
      
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 2), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 2), color->green);

      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 3), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 3), color->blue);
    }
  else
    {
      int i;
      for (i = 0; i < 4; i++)
        {
          g_value_array_prepend(val, NULL);
          g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
          g_value_set_uint(g_value_array_get_nth(val, 0), 0);
        }
    }
  
  if (type == PANEL_PIXMAP_BACKGROUND)
    {
      if (keep != NULL)
        {
          gdk_pixmap_unref(keep);
          keep = pixmap;
        }
      if (pixmap != NULL)
        {
          gdk_pixmap_ref(pixmap);
        }

      xid = GDK_PIXMAP_XID(pixmap);
    }

  if (g_applet->support != NULL && workrave_is_running())
    {
      dbus_g_proxy_begin_call(g_applet->support, "SetBackground", dbus_callback, NULL, NULL,
                              G_TYPE_UINT, type,
                              G_TYPE_VALUE_ARRAY, val,
                              G_TYPE_UINT, xid,
                              G_TYPE_INVALID);
      

    }

  g_value_array_free(val);
}
Ejemplo n.º 11
0
static gboolean
get_video_recv_info (KmsRembLocal * rl,
    guint64 * bitrate, guint * fraction_lost, guint64 * packets_rcv_interval)
{
  GValueArray *arr = NULL;
  GValue *val;
  guint i;
  gboolean ret = FALSE;

  if (!KMS_REMB_BASE (rl)->rtpsess) {
    GST_WARNING ("Session object does not exist");
    return ret;
  }

  g_object_get (KMS_REMB_BASE (rl)->rtpsess, "sources", &arr, NULL);

  if (arr == NULL) {
    GST_WARNING ("Sources array not found");
    return ret;
  }

  for (i = 0; i < arr->n_values; i++) {
    GObject *source;
    guint ssrc;
    GstStructure *s;

    val = g_value_array_get_nth (arr, i);
    source = g_value_get_object (val);
    g_object_get (source, "ssrc", &ssrc, "stats", &s, NULL);

    GST_TRACE_OBJECT (source, "source ssrc: %u", ssrc);
    GST_TRACE_OBJECT (KMS_REMB_BASE (rl)->rtpsess, "stats: %" GST_PTR_FORMAT,
        s);

    if (ssrc == rl->remote_ssrc) {
      GstClockTime current_time;
      guint64 octets_received, packets_received;

      if (!gst_structure_get_uint64 (s, "bitrate", bitrate)) {
        break;
      }
      if (!gst_structure_get_uint64 (s, "octets-received", &octets_received)) {
        break;
      }
      if (!gst_structure_get_uint (s, "sent-rb-fractionlost", fraction_lost)) {
        break;
      }
      if (!gst_structure_get_uint64 (s, "packets-received", &packets_received)) {
        break;
      }

      current_time = kms_utils_get_time_nsecs ();

      if (rl->last_time != 0) {
        GstClockTime elapsed = current_time - rl->last_time;
        guint64 bytes_handled = octets_received - rl->last_octets_received;

        *bitrate =
            gst_util_uint64_scale (bytes_handled, 8 * GST_SECOND, elapsed);
        GST_TRACE_OBJECT (KMS_REMB_BASE (rl)->rtpsess,
            "Elapsed %" G_GUINT64_FORMAT " bytes %" G_GUINT64_FORMAT ", rate %"
            G_GUINT64_FORMAT, elapsed, bytes_handled, *bitrate);
      }

      rl->last_time = current_time;
      rl->last_octets_received = octets_received;

      *packets_rcv_interval = packets_received - rl->last_packets_received;
      rl->last_packets_received = packets_received;

      ret = TRUE;
    }

    gst_structure_free (s);

    if (ret) {
      break;
    }
  }

  g_value_array_free (arr);

  return ret;
}
Ejemplo n.º 12
0
GimpPDBStatusType
file_save (GimpImage           *image,
           GimpContext         *context,
           GimpProgress        *progress,
           const gchar         *uri,
           GimpPlugInProcedure *file_proc,
           GimpRunMode          run_mode,
           gboolean             save_a_copy,
           GError             **error)
{
  GimpDrawable      *drawable;
  GValueArray       *return_vals;
  GimpPDBStatusType  status;
  gchar             *filename;
  gint32             image_ID;
  gint32             drawable_ID;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_PDB_CALLING_ERROR);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress),
                        GIMP_PDB_CALLING_ERROR);
  g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc),
                        GIMP_PDB_CALLING_ERROR);
  g_return_val_if_fail (error == NULL || *error == NULL,
                        GIMP_PDB_CALLING_ERROR);

  drawable = gimp_image_get_active_drawable (image);

  if (! drawable)
    return GIMP_PDB_EXECUTION_ERROR;

  filename = file_utils_filename_from_uri (uri);

  if (filename)
    {
      /* check if we are saving to a file */
      if (g_file_test (filename, G_FILE_TEST_EXISTS))
        {
          if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           "%s", _("Not a regular file"));
              status = GIMP_PDB_EXECUTION_ERROR;
              goto out;
            }

          if (g_access (filename, W_OK) != 0)
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
                           "%s", g_strerror (errno));
              status = GIMP_PDB_EXECUTION_ERROR;
              goto out;
            }
        }
    }
  else
    {
      filename = g_strdup (uri);
    }

  /* ref the image, so it can't get deleted during save */
  g_object_ref (image);

  image_ID    = gimp_image_get_ID (image);
  drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable));

  return_vals =
    gimp_pdb_execute_procedure_by_name (image->gimp->pdb,
                                        context, progress, error,
                                        GIMP_OBJECT (file_proc)->name,
                                        GIMP_TYPE_INT32,       run_mode,
                                        GIMP_TYPE_IMAGE_ID,    image_ID,
                                        GIMP_TYPE_DRAWABLE_ID, drawable_ID,
                                        G_TYPE_STRING,         filename,
                                        G_TYPE_STRING,         uri,
                                        G_TYPE_NONE);

  status = g_value_get_enum (&return_vals->values[0]);

  g_value_array_free (return_vals);

  if (status == GIMP_PDB_SUCCESS)
    {
      GimpDocumentList *documents;
      GimpImagefile    *imagefile;

      if (save_a_copy)
        {
          /*  remember the "save-a-copy" filename for the next invocation  */
          g_object_set_data_full (G_OBJECT (image), "gimp-image-save-a-copy",
                                  g_strdup (uri),
                                  (GDestroyNotify) g_free);
        }
      else
        {
          /*  reset the "save-a-copy" filename when the image URI changes  */
          if (strcmp (uri, gimp_image_get_uri (image)))
            g_object_set_data (G_OBJECT (image),
                               "gimp-image-save-a-copy", NULL);

          gimp_image_set_uri (image, uri);
          gimp_image_set_save_proc (image, file_proc);

          gimp_image_clean_all (image);
        }

      gimp_image_saved (image, uri);

      documents = GIMP_DOCUMENT_LIST (image->gimp->documents);
      imagefile = gimp_document_list_add_uri (documents,
                                              uri,
                                              file_proc->mime_type);

      /* only save a thumbnail if we are saving as XCF, see bug #25272 */
      if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL)
        gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image);
    }
  else if (status != GIMP_PDB_CANCEL)
    {
      if (error && *error == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("%s plug-in could not save image"),
                       gimp_plug_in_procedure_get_label (file_proc));
        }
    }

  gimp_image_flush (image);

  g_object_unref (image);

 out:
  g_free (filename);

  return status;
}
Ejemplo n.º 13
0
static int
pyg_value_array_from_pyobject(GValue *value,
			      PyObject *obj,
			      const GParamSpecValueArray *pspec)
{
    int len;
    GValueArray *value_array;
    int i;

    len = PySequence_Length(obj);
    if (len == -1) {
	PyErr_Clear();
	return -1;
    }

    if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
	return -1;

    value_array = g_value_array_new(len);

    for (i = 0; i < len; ++i) {
	PyObject *item = PySequence_GetItem(obj, i);
	GType type;
	GValue item_value = { 0, };
	int status;

	if (! item) {
	    PyErr_Clear();
	    g_value_array_free(value_array);
	    return -1;
	}

	if (pspec && pspec->element_spec)
	    type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
	else if (item == Py_None)
	    type = G_TYPE_POINTER; /* store None as NULL */
	else {
	    type = pyg_type_from_object((PyObject*)Py_TYPE(item));
	    if (! type) {
		PyErr_Clear();
		g_value_array_free(value_array);
		Py_DECREF(item);
		return -1;
	    }
	}

	g_value_init(&item_value, type);
	status = (pspec && pspec->element_spec)
	    ? pyg_param_gvalue_from_pyobject(&item_value, item, pspec->element_spec)
	    : pyg_value_from_pyobject(&item_value, item);
	Py_DECREF(item);

	if (status == -1) {
	    g_value_array_free(value_array);
	    g_value_unset(&item_value);
	    return -1;
	}

	g_value_array_append(value_array, &item_value);
	g_value_unset(&item_value);
    }

    g_value_take_boxed(value, value_array);
    return 0;
}
static void
gst_video_parse_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstVideoParse *vp = GST_VIDEO_PARSE (object);

  switch (prop_id) {
    case PROP_FORMAT:
      g_object_set (G_OBJECT (vp->rawvideoparse), "format",
          g_value_get_enum (value), NULL);
      break;

    case PROP_WIDTH:
      g_object_set (G_OBJECT (vp->rawvideoparse), "width",
          g_value_get_int (value), NULL);
      break;

    case PROP_HEIGHT:
      g_object_set (G_OBJECT (vp->rawvideoparse), "height",
          g_value_get_int (value), NULL);
      break;

    case PROP_FRAMERATE:
      g_object_set (G_OBJECT (vp->rawvideoparse), "framerate",
          gst_value_get_fraction_numerator (value),
          gst_value_get_fraction_denominator (value), NULL);
      break;

    case PROP_PAR:
      g_object_set (G_OBJECT (vp->rawvideoparse), "pixel-aspect-ratio",
          gst_value_get_fraction_numerator (value),
          gst_value_get_fraction_denominator (value), NULL);
      break;

    case PROP_INTERLACED:
      g_object_set (G_OBJECT (vp->rawvideoparse), "interlaced",
          g_value_get_boolean (value), NULL);
      break;

    case PROP_TOP_FIELD_FIRST:
      g_object_set (G_OBJECT (vp->rawvideoparse), "top-field-first",
          g_value_get_boolean (value), NULL);
      break;

    case PROP_STRIDES:{
      GValueArray *valarray =
          gst_video_parse_int_valarray_from_string (g_value_get_string (value));

      if (valarray != NULL) {
        g_object_set (G_OBJECT (vp->rawvideoparse), "plane-strides",
            valarray, NULL);
        g_value_array_free (valarray);
      } else {
        GST_WARNING_OBJECT (vp, "failed to deserialize given strides");
      }

      break;
    }

    case PROP_OFFSETS:{
      GValueArray *valarray =
          gst_video_parse_int_valarray_from_string (g_value_get_string (value));

      if (valarray != NULL) {
        g_object_set (G_OBJECT (vp->rawvideoparse), "plane-offsets",
            valarray, NULL);
        g_value_array_free (valarray);
      } else {
        GST_WARNING_OBJECT (vp, "failed to deserialize given offsets");
      }

      break;
    }

    case PROP_FRAMESIZE:
      g_object_set (G_OBJECT (vp->rawvideoparse), "frame-stride",
          g_value_get_uint (value), NULL);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
static GPtrArray *
read_ip6_routes (GKeyFile *file,
                 const char *setting_name,
                 const char *key)
{
	GPtrArray *routes;
	struct in6_addr addr;
	guint32 prefix, metric;
	int i = 0;

	routes = g_ptr_array_sized_new (3);

	/* Look for individual routes */
	while (i++ < 1000) {
		gchar **tmp;
		char *key_name, *str_prefix;
		gsize length = 0;
		int ret;
		GValueArray *values;
		GByteArray *address;
		GValue value = { 0 };

		key_name = g_strdup_printf ("%s%d", key, i);
		tmp = g_key_file_get_string_list (file, setting_name, key_name, &length, NULL);
		g_free (key_name);

		if (!tmp || !length)
			break; /* all done */

		if (length != 3) {
			g_warning ("%s: ignoring invalid IPv6 address item '%s'", __func__, key_name);
			goto next;
		}

		/* convert the string array into IPv6 routes */
		values = g_value_array_new (4); /* NMIP6Route has 4 items */

		/* Split the route and prefix */
		str_prefix = split_prefix (tmp[0]);

		/* destination address */
		ret = inet_pton (AF_INET6, tmp[0], &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp[0]);
			g_value_array_free (values);
			goto next;
		}
		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* prefix */
		prefix = 0;
		if (str_prefix) {
			if (!get_one_int (str_prefix, 128, key_name, &prefix)) {
				g_value_array_free (values);
				goto next;
			}
		} else {
			/* default to 64 if unspecified */
			prefix = 64;
		}
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, prefix);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* next hop address */
		ret = inet_pton (AF_INET6, tmp[1], &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp[1]);
			g_value_array_free (values);
			goto next;
		}
		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* metric */
		metric = 0;
		if (!get_one_int (tmp[2], G_MAXUINT32, key_name, &metric)) {
			g_value_array_free (values);
			goto next;
		}
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		g_ptr_array_add (routes, values);

next:
		g_strfreev (tmp);
	}

	if (routes->len < 1) {
		g_ptr_array_free (routes, TRUE);
		routes = NULL;
	}

	return routes;
}
static void
free_one_ip6_route (gpointer data, gpointer user_data)
{
	g_value_array_free ((GValueArray *) data);
}
Ejemplo n.º 17
0
static gpointer
build_ip6_address_or_route (const char *address_str, guint32 plen, const char *gateway_str, guint32 metric, gboolean route)
{
	GValueArray *result;
	struct in6_addr addr;
	GByteArray *address;
	GByteArray *gateway;
	GValue value = { 0, };
	int err;

	g_return_val_if_fail (address_str, NULL);

	result = g_value_array_new (3);

	/* add address */
	err = inet_pton (AF_INET6, address_str, &addr);
	if (err <= 0) {
		g_warning ("%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
		g_value_array_free (result);
		return NULL;
	}
	address = g_byte_array_new ();
	g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, address);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add prefix length */
	g_value_init (&value, G_TYPE_UINT);
	g_value_set_uint (&value, plen);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add gateway */
	if (gateway_str) {
		err = inet_pton (AF_INET6, gateway_str, &addr);
		if (err <= 0) {
			g_warning ("%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
			g_value_array_free (result);
			return NULL;
		}
	} else
		memset (&addr, 0, 16);
	gateway = g_byte_array_new ();
	g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, gateway);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add metric (for routing) */
	if (route) {
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (result, &value);
		g_value_unset (&value);
	}

	return result;
}
Ejemplo n.º 18
0
/**
 * file_open_thumbnail:
 * @gimp:
 * @context:
 * @progress:
 * @uri:          the URI of the image file
 * @size:         requested size of the thumbnail
 * @mime_type:    return location for image MIME type
 * @image_width:  return location for image width
 * @image_height: return location for image height
 * @type:         return location for image type (set to -1 if unknown)
 * @num_layers:   return location for number of layers
 *                (set to -1 if the number of layers is not known)
 * @error:
 *
 * Attempts to load a thumbnail by using a registered thumbnail loader.
 *
 * Return value: the thumbnail image
 */
GimpImage *
file_open_thumbnail (Gimp           *gimp,
                     GimpContext    *context,
                     GimpProgress   *progress,
                     const gchar    *uri,
                     gint            size,
                     const gchar   **mime_type,
                     gint           *image_width,
                     gint           *image_height,
                     GimpImageType  *type,
                     gint           *num_layers,
                     GError        **error)
{
    GimpPlugInProcedure *file_proc;
    GimpProcedure       *procedure;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
    g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
    g_return_val_if_fail (mime_type != NULL, NULL);
    g_return_val_if_fail (image_width != NULL, NULL);
    g_return_val_if_fail (image_height != NULL, NULL);
    g_return_val_if_fail (type != NULL, NULL);
    g_return_val_if_fail (num_layers != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    *image_width  = 0;
    *image_height = 0;
    *type         = -1;
    *num_layers   = -1;

    file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
                                     NULL);

    if (! file_proc || ! file_proc->thumb_loader)
        return NULL;

    procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

    if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
        GimpPDBStatusType  status;
        GValueArray       *return_vals;
        gchar             *filename;
        GimpImage         *image = NULL;

        filename = file_utils_filename_from_uri (uri);

        if (! filename)
            filename = g_strdup (uri);

        return_vals =
            gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                                context, progress, error,
                                                gimp_object_get_name (procedure),
                                                G_TYPE_STRING,   filename,
                                                GIMP_TYPE_INT32, size,
                                                G_TYPE_NONE);

        g_free (filename);

        status = g_value_get_enum (&return_vals->values[0]);

        if (status == GIMP_PDB_SUCCESS &&
                GIMP_VALUE_HOLDS_IMAGE_ID (&return_vals->values[1]))
        {
            image = gimp_value_get_image (&return_vals->values[1], gimp);

            if (return_vals->n_values >= 3 &&
                    G_VALUE_HOLDS_INT (&return_vals->values[2]) &&
                    G_VALUE_HOLDS_INT (&return_vals->values[3]))
            {
                *image_width  = MAX (0,
                                     g_value_get_int (&return_vals->values[2]));
                *image_height = MAX (0,
                                     g_value_get_int (&return_vals->values[3]));

                if (return_vals->n_values >= 5 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[4]))
                {
                    gint value = g_value_get_int (&return_vals->values[4]);

                    if (gimp_enum_get_value (GIMP_TYPE_IMAGE_TYPE, value,
                                             NULL, NULL, NULL, NULL))
                    {
                        *type = value;
                    }
                }

                if (return_vals->n_values >= 6 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[5]))
                {
                    *num_layers = MAX (0,
                                       g_value_get_int (&return_vals->values[5]));
                }
            }

            if (image)
            {
                file_open_sanitize_image (image, FALSE);

                *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
                g_printerr ("opened thumbnail at %d x %d\n",
                            gimp_image_get_width  (image),
                            gimp_image_get_height (image));
#endif
            }
        }

        g_value_array_free (return_vals);

        return image;
    }

    return NULL;
}
Ejemplo n.º 19
0
static void get_stream_information(TPMediaPlayer * mp)
{
    USERDATA(mp);
    CM(ud);

#if (CLUTTER_GST_MAJOR_VERSION < 1)
    GstElement * pipeline=clutter_gst_video_texture_get_playbin(CLUTTER_GST_VIDEO_TEXTURE(cm));
#else
    GstElement *pipeline=clutter_gst_video_texture_get_pipeline(CLUTTER_GST_VIDEO_TEXTURE(cm));
#endif

    if (!pipeline)
        return;

    //.........................................................................
    // Use stream info to get the type of each stream

#if (CLUTTER_GST_MAJOR_VERSION < 1)
    GValueArray * info_array=NULL;

    g_object_get(G_OBJECT(pipeline),"stream-info-value-array",&info_array,NULL);

    if (info_array)
    {
        // Each entry in the array is information for a single stream

        guint i;

        for (i=0;i<info_array->n_values;++i)
        {
            GValue * info_value=g_value_array_get_nth(info_array,i);

            if (G_VALUE_HOLDS(info_value,G_TYPE_OBJECT))
            {
                GObject * stream_info=g_value_get_object(info_value);

                if (stream_info)
                {
                    gint type = -1;

                    g_object_get(stream_info,"type",&type,NULL);

                    switch (type)
                    {
                        case 1:
                            ud->media_type|=TP_MEDIA_TYPE_AUDIO;
                            break;

                        case 2:
                            ud->media_type|=TP_MEDIA_TYPE_VIDEO;
                            break;
                    }
#if 0
                    // This lets you get the enum value associated with the stream type

                    GParamSpec *pspec;
                    GEnumValue *value;

                    pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(stream_info),"type");

                    value = g_enum_get_value(G_PARAM_SPEC_ENUM(pspec)->enum_class,type);

                    g_debug("  STREAM TYPE IS %d %s",type,value->value_nick);
#endif
                }
            }
        }

        g_value_array_free(info_array);
    }
#else
    gint n_audio, n_video;
    g_object_get(G_OBJECT(pipeline), "n-video", &n_video, NULL);
    g_object_get(G_OBJECT(pipeline), "n-audio", &n_audio, NULL);

    if(n_video) ud->media_type|=TP_MEDIA_TYPE_VIDEO;
    if(n_audio) ud->media_type|=TP_MEDIA_TYPE_AUDIO;
#endif

    //.........................................................................
    // If there is a video stream, we get the video sink and try to find the
    // video size

    if (ud->media_type&TP_MEDIA_TYPE_VIDEO)
    {
        GstElement * video_sink=NULL;

        g_object_get(G_OBJECT(pipeline),"video-sink",&video_sink,NULL);

        if (video_sink)
        {
            GstPad * pad=gst_element_get_static_pad(video_sink,"sink");

            if (pad)
            {
                // Get its video width and height

                gint width;
                gint height;

                if (gst_video_get_size(pad,&width,&height))
                {
                    ud->video_width=width;
                    ud->video_height=height;
                }
                gst_object_unref(GST_OBJECT(pad));
            }
            gst_object_unref(GST_OBJECT(video_sink));
        }
    }

#if 1

    if ( ud->media_type & TP_MEDIA_TYPE_AUDIO )
    {
        GstElement * audio_sink= gst_element_factory_make( "autoaudiosink", "TPAudioSink" );

        if(!audio_sink)
        {
        	g_debug("Failed to create autoaudiosink");
        }
        else
        {
			g_object_set(G_OBJECT(pipeline),"audio-sink",audio_sink,NULL);
		}
    }

#endif
}
Ejemplo n.º 20
0
GimpImage *
file_open_image (Gimp                *gimp,
                 GimpContext         *context,
                 GimpProgress        *progress,
                 const gchar         *uri,
                 const gchar         *entered_filename,
                 gboolean             as_new,
                 GimpPlugInProcedure *file_proc,
                 GimpRunMode          run_mode,
                 GimpPDBStatusType   *status,
                 const gchar        **mime_type,
                 GError             **error)
{
    GValueArray *return_vals;
    gchar       *filename;
    GimpImage   *image = NULL;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
    g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
    g_return_val_if_fail (status != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    *status = GIMP_PDB_EXECUTION_ERROR;

    if (! file_proc)
        file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
                                         error);

    if (! file_proc)
        return NULL;

    filename = file_utils_filename_from_uri (uri);

    if (filename)
    {
        /* check if we are opening a file */
        if (g_file_test (filename, G_FILE_TEST_EXISTS))
        {
            if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
            {
                g_free (filename);
                g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                                     _("Not a regular file"));
                return NULL;
            }

            if (g_access (filename, R_OK) != 0)
            {
                g_free (filename);
                g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
                                     g_strerror (errno));
                return NULL;
            }
        }
    }
    else
    {
        filename = g_strdup (uri);
    }

    return_vals =
        gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                            context, progress, error,
                                            gimp_object_get_name (file_proc),
                                            GIMP_TYPE_INT32, run_mode,
                                            G_TYPE_STRING,   filename,
                                            G_TYPE_STRING,   entered_filename,
                                            G_TYPE_NONE);

    g_free (filename);

    *status = g_value_get_enum (&return_vals->values[0]);

    if (*status == GIMP_PDB_SUCCESS)
    {
        image = gimp_value_get_image (&return_vals->values[1], gimp);

        if (image)
        {
            file_open_sanitize_image (image, as_new);

            /* Only set the load procedure if it hasn't already been set. */
            if (! gimp_image_get_load_proc (image))
                gimp_image_set_load_proc (image, file_proc);

            file_proc = gimp_image_get_load_proc (image);

            if (mime_type)
                *mime_type = file_proc->mime_type;
        }
        else
        {
            if (error && ! *error)
                g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                             _("%s plug-in returned SUCCESS but did not "
                               "return an image"),
                             gimp_plug_in_procedure_get_label (file_proc));

            *status = GIMP_PDB_EXECUTION_ERROR;
        }
    }
    else if (*status != GIMP_PDB_CANCEL)
    {
        if (error && ! *error)
            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                         _("%s plug-In could not open image"),
                         gimp_plug_in_procedure_get_label (file_proc));
    }

    g_value_array_free (return_vals);

    if (image)
    {
        file_open_handle_color_profile (image, context, progress, run_mode);

        if (file_open_file_proc_is_import (file_proc))
        {
            /* Remember the import source */
            gimp_image_set_imported_uri (image, uri);

            /* We shall treat this file as an Untitled file */
            gimp_image_set_uri (image, NULL);
        }
    }

    return image;
}
Ejemplo n.º 21
0
/* run automatically started extensions */
static void
gimp_plug_in_manager_run_extensions (GimpPlugInManager  *manager,
                                     GimpContext        *context,
                                     GimpInitStatusFunc  status_callback)
{
  Gimp   *gimp = manager->gimp;
  GSList *list;
  GList  *extensions = NULL;
  gint    n_extensions;

  /* build list of automatically started extensions */
  for (list = manager->plug_in_procedures; list; list = list->next)
    {
      GimpPlugInProcedure *proc = list->data;

      if (proc->prog                                         &&
          GIMP_PROCEDURE (proc)->proc_type == GIMP_EXTENSION &&
          GIMP_PROCEDURE (proc)->num_args  == 0)
        {
          extensions = g_list_prepend (extensions, proc);
        }
    }

  extensions   = g_list_reverse (extensions);
  n_extensions = g_list_length (extensions);

  /* run the available extensions */
  if (extensions)
    {
      GList *list;
      gint   nth;

      status_callback (_("Starting Extensions"), "", 0.0);

      for (list = extensions, nth = 0; list; list = g_list_next (list), nth++)
        {
          GimpPlugInProcedure *proc = list->data;
          GValueArray         *args;
          GError              *error = NULL;

          if (gimp->be_verbose)
            g_print ("Starting extension: '%s'\n", gimp_object_get_name (proc));

          status_callback (NULL, gimp_object_get_name (proc),
                           (gdouble) nth / (gdouble) n_extensions);

          args = g_value_array_new (0);

          gimp_procedure_execute_async (GIMP_PROCEDURE (proc),
                                        gimp, context, NULL,
                                        args, NULL, &error);

          g_value_array_free (args);

          if (error)
            {
              gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
				    error->message);
              g_clear_error (&error);
            }
        }

      g_list_free (extensions);

      status_callback (NULL, "", 1.0);
    }
}
static void _parse_and_forward_one(IdleParser *parser, gchar **tokens, IdleParserMessageCode code, const gchar *format) {
	IdleParserPrivate *priv = IDLE_PARSER_GET_PRIVATE(parser);
	GValueArray *args = g_value_array_new(3);
	GSList *link_ = priv->handlers[code];
	IdleParserHandlerResult result = IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;
	gboolean success = TRUE;
	gchar **iter = tokens;
	/* We keep a ref to each unique handle in a message so that we can unref them after calling all handlers */
	TpHandleSet *contact_reffed = tp_handle_set_new(tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_CONTACT));
	TpHandleSet *room_reffed = tp_handle_set_new(tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_ROOM));

	IDLE_DEBUG("message code %u", code);

	while ((*format != '\0') && success && (*iter != NULL)) {
		GValue val = {0};

		if (*format == 'v') {
			format++;
			while (*iter != NULL) {
				if (!_parse_atom(parser, args, *format, iter[0], contact_reffed, room_reffed)) {
					success = FALSE;
					break;
				}

				iter += 2;
			}
		} else if ((*format == ':') || (*format == '.')) {
			/* Assume the happy case of the trailing parameter starting after the :
			 * in the trailing string as the RFC intended */
			const gchar *trailing = iter[1] + 1;

			/* Some IRC proxies *cough* bip *cough* omit the : in the trailing
			 * parameter if that parameter is just one word, to cope with that check
			 * if there are no more tokens after the current one and if so, accept a
			 * trailing string without the : prefix. */
			if (iter[0][0] != ':') {
				if (iter[2] == NULL) {
					trailing = iter[1];
				} else {
					success = FALSE;
					break;
				}
			}

			/*
			 * because of the way things are tokenized, if there is a
			 * space immediately after the the ':', the current token will only be
			 * ":", so we check that the trailing string is non-NULL rather than
			 * checking iter[0][1] (since iter[0] is a NULL-terminated token string
			 * whereas trailing is a pointer into the full message string
			 */
			if (trailing[0] == '\0') {
				success = FALSE;
				break;
			}

			g_value_init(&val, G_TYPE_STRING);
			g_value_set_string(&val, trailing);
			g_value_array_append(args, &val);
			g_value_unset(&val);

			IDLE_DEBUG("set string \"%s\"", trailing);
		} else {
			if (!_parse_atom(parser, args, *format, iter[0], contact_reffed, room_reffed)) {
				success = FALSE;
				break;
			}
		}

		format++;
		iter += 2;
	}

	if (!success && (*format != '.')) {
		IDLE_DEBUG("failed to parse \"%s\"", tokens[1]);

		goto cleanup;
	}

	if (*format && (*format != '.')) {
		IDLE_DEBUG("missing args in message \"%s\"", tokens[1]);

		goto cleanup;
	}

	IDLE_DEBUG("successfully parsed");

	while (link_) {
		MessageHandlerClosure *closure = link_->data;
		result = closure->handler(parser, code, args, closure->user_data);
		if (result == IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED) {
			link_ = link_->next;
		} else if (result == IDLE_PARSER_HANDLER_RESULT_HANDLED) {
			break;
		} else if (result == IDLE_PARSER_HANDLER_RESULT_NO_MORE_PLEASE) {
			GSList *tmp = link_->next;
			g_free(closure);
			priv->handlers[code] = g_slist_remove_link(priv->handlers[code], link_);
			link_ = tmp;
		} else {
			g_assert_not_reached();
		}
	}

cleanup:

	g_value_array_free(args);

	tp_handle_set_destroy(contact_reffed);
	tp_handle_set_destroy(room_reffed);
}
Ejemplo n.º 23
0
//! edit
gboolean modifEdi(GtkWidget* parent , gpointer data){
	gboolean status = FALSE;
	gint id = GPOINTER_TO_INT(data);
	gint result = GTK_RESPONSE_OK;
	if(data == NULL){
		GtkWidget *comboId = gtk_combo_box_new ();
		GtkWidget *dialog = modifGetPilihanId(comboId);
		gtk_widget_show_all(dialog);
		result 	= 	gtk_dialog_run (dialog);	// block
		id 		=	globalConStrToInt(gtk_combo_box_get_active_text(comboId));
		gtk_widget_destroy(dialog);
	}	
	if(result==GTK_RESPONSE_OK){
		modifStruct_ *modif = struct_new(modifStruct_);
		gchar *title = g_strdup_printf ("Edit Data dengan id %d", id);
		GtkWidget *dialog = modifGetDialogWithStruct(parent , modif , title);
		//! mengambil data dari database
		GValueArray* varr = 	g_value_array_new (-1);		
		GValue a = {0};
		g_assert (!G_VALUE_HOLDS_STRING (&a));			
		g_value_init (&a, G_TYPE_INT);
		g_value_set_int (&a, id );
		varr =	g_value_array_append(varr,&a);
		gchar *sql = g_strdup_printf ("%s and isi.id=?", globalGetDefCom() );
		GValueArray *hasil = databaseGetDatasFromDb( sql	 , varr , &status);		
		modifSetItemToWidget(modif,hasil);
		//! show 
		gtk_widget_show_all(dialog);
		result = gtk_dialog_run (dialog);	// block
		if (result==GTK_RESPONSE_OK){
			//! sekarang kita akan masuk pada database
			//! mengambil data
			char *filename;
			char* jamchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->jam));
			char* mntchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->mnt));		
			gchar *jamMnt	= g_strdup_printf ("%s:%s", jamchar,mntchar);
			gchar * hari 	= gtk_combo_box_get_active_text ( modif->hari);
			gchar * bagian 	= gtk_combo_box_get_active_text ( modif->bagian );
			gint	total   = gtk_spin_button_get_value_as_int (modif->total);
			filename = fuGetNameFile( gtk_button_get_label(modif->filePilih));
			//! update database
			gint idHari = databaseGetIdHari(hari);
			GValueArray* varr = 	g_value_array_new (-1);		
			GValue a = {0};
			g_assert (!G_VALUE_HOLDS_STRING (&a));			
			g_value_init (&a, G_TYPE_INT);
			g_value_set_int (&a, idHari);			//! 1
			varr =	g_value_array_append(varr,&a);
			g_value_set_int (&a, total);			//! 2
			varr =	g_value_array_append(varr,&a);
			g_value_unset (&a);
			g_value_init (&a, G_TYPE_STRING);
			g_value_set_string (&a, jamMnt);		//! 3
			varr =	g_value_array_append(varr,&a);								
			g_value_set_string (&a, bagian);		//! 4
			varr =	g_value_array_append(varr,&a);								
			g_value_set_string (&a, filename);		//! 5
			varr =	g_value_array_append(varr,&a);
			g_value_unset (&a);
			g_value_init (&a, G_TYPE_INT);
			g_value_set_int (&a, id);			//! 6
			varr =	g_value_array_append(varr,&a);
			GValueArray *hasil = databaseGetDatasFromDb("update isi set dal=? , X=?,jam=?,bagian=?,alarm=? where id = ?" , varr,&status);
			//! free
			g_value_array_free (varr);
			g_value_array_free (hasil);
			//! aslinya harus di cek kembali
			status = TRUE;
		}
		else{
		}
		//! free all
		g_value_array_free (varr);
		g_value_array_free (hasil);
		gtk_widget_destroy(dialog);				
	}
	return TRUE;
}
Ejemplo n.º 24
0
GParameter *
jingle_get_params(JabberStream *js, const gchar *relay_ip, guint relay_udp,
	guint relay_tcp, guint relay_ssltcp, const gchar *relay_username,
    const gchar *relay_password, guint *num)
{
	/* don't set a STUN server if one is set globally in prefs, in that case
	 this will be handled in media.c */
	gboolean has_account_stun = js->stun_ip && !purple_network_get_stun_ip();
	guint num_params = has_account_stun ?
		(relay_ip ? 3 : 2) : (relay_ip ? 1 : 0);
	GParameter *params = NULL;
	int next_index = 0;
	
	if (num_params > 0) {
		params = g_new0(GParameter, num_params);

		if (has_account_stun) {
			purple_debug_info("jabber", 
				"setting param stun-ip for stream using Google auto-config: %s\n",
				js->stun_ip);
			params[next_index].name = "stun-ip";
			g_value_init(&params[next_index].value, G_TYPE_STRING);
			g_value_set_string(&params[next_index].value, js->stun_ip);
			purple_debug_info("jabber", 
				"setting param stun-port for stream using Google auto-config: %d\n",
				js->stun_port);
			next_index++;
			params[next_index].name = "stun-port";
			g_value_init(&params[next_index].value, G_TYPE_UINT);
			g_value_set_uint(&params[next_index].value, js->stun_port);
			next_index++;
		}
	
		if (relay_ip) {
			GValueArray *relay_info = g_value_array_new(0);

			if (relay_udp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_udp, relay_username,
						relay_password, "udp", relay_info);
			}
			if (relay_tcp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_tcp, relay_username,
						relay_password, "tcp", relay_info);
			}
			if (relay_ssltcp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_ssltcp, relay_username,
						relay_password, "tls", relay_info);
			}
			params[next_index].name = "relay-info";
			g_value_init(&params[next_index].value, G_TYPE_VALUE_ARRAY);
			g_value_set_boxed(&params[next_index].value, relay_info);
			g_value_array_free(relay_info);
		}
	}

	*num = num_params;
	return params;
}
Ejemplo n.º 25
0
static void
batch_run_cmd (Gimp          *gimp,
               const gchar   *proc_name,
               GimpProcedure *procedure,
               GimpRunMode    run_mode,
               const gchar   *cmd)
{
  GValueArray *args;
  GValueArray *return_vals;
  GError      *error = NULL;
  gint         i     = 0;

  args = gimp_procedure_get_arguments (procedure);

  if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_INT32 (procedure->args[i]))
    g_value_set_int (&args->values[i++], run_mode);

  if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_STRING (procedure->args[i]))
    g_value_set_static_string (&args->values[i++], cmd);

  return_vals =
    gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
                                             gimp_get_user_context (gimp),
                                             NULL, &error,
                                             proc_name, args);

  switch (g_value_get_enum (&return_vals->values[0]))
    {
    case GIMP_PDB_EXECUTION_ERROR:
      if (error)
        {
          g_printerr ("batch command experienced an execution error: %s\n",
                      error->message);
        }
      else
        {
          g_printerr ("batch command experienced an execution error\n");
        }
      break;

    case GIMP_PDB_CALLING_ERROR:
      if (error)
        {
          g_printerr ("batch command experienced a calling error: %s\n",
                      error->message);
        }
      else
        {
          g_printerr ("batch command experienced a calling error\n");
        }
      break;

    case GIMP_PDB_SUCCESS:
      g_printerr ("batch command executed successfully\n");
      break;
    }

  g_value_array_free (return_vals);
  g_value_array_free (args);

  if (error)
    g_error_free (error);

  return;
}
Ejemplo n.º 26
0
static void
mame_gui_prefs_set_property (GObject *object,
			     guint prop_id,
			     const GValue *value,
			     GParamSpec *pspec)
{
	MameGuiPrefs *prefs;
	GValueArray *va = NULL;	/* Don't free this - the calling function must take the responsibility to do so */
	
	prefs = MAME_GUI_PREFS (object);

	if ((prop_id < NUM_PROPERTIES) && (prop_id >= PROP_DIR_ARTWORK)) {
		GMAMEUI_DEBUG ("Setting the directory value at %d with value %s",
			       (prop_id - PROP_DIR_ARTWORK), g_value_get_string (value));
		/* We are processing a directory property */
		prefs->priv->directories[prop_id - PROP_DIR_ARTWORK] = g_strdup (g_value_get_string (value));
		/* Note we use prop_id - PROP_DIR_ARTWORK since PDA is the first of the directory
		   properties */
		return;
	}

	switch (prop_id) {
		case PROP_UI_WIDTH:
			prefs->priv->ui_width = g_value_get_int (value);
			break;
		case PROP_UI_HEIGHT:
			prefs->priv->ui_height = g_value_get_int (value);
			break;
		case PROP_SHOW_TOOLBAR:
			prefs->priv->show_toolbar = g_value_get_boolean (value);
			break;
		case PROP_SHOW_STATUSBAR:
			prefs->priv->show_statusbar = g_value_get_boolean (value);
			break;
		case PROP_SHOW_FILTERLIST:
			prefs->priv->show_filterlist = g_value_get_boolean (value);
			break;
		case PROP_SHOW_SCREENSHOT:
			prefs->priv->show_screenshot = g_value_get_boolean (value);
			break;
		case PROP_XPOS_FILTERS:
			prefs->priv->xpos_filters = g_value_get_int (value);
			break;
		case PROP_XPOS_GAMELIST:
			prefs->priv->xpos_gamelist = g_value_get_int (value);
			break;
		case PROP_GAMECHECK:
			prefs->priv->GameCheck = g_value_get_boolean (value);
			break;
		case PROP_VERSIONCHECK:
			prefs->priv->VersionCheck = g_value_get_boolean (value);
			break;
		case PROP_USEXMAMEOPTIONS:
			prefs->priv->use_xmame_options = g_value_get_boolean (value);
			break;
		case PROP_PREFERCUSTOMICONS:
			prefs->priv->prefercustomicons = g_value_get_boolean (value);
			/* Emit the signal (so gamelist view can be changed */
			g_signal_emit (G_OBJECT (prefs), signals[GUI_PREFS_PREFERCUSTOMICONS_TOGGLED], 0,
				       prefs->priv->theprefix);
		case PROP_USEJOYINGUI:
			prefs->priv->gui_joy = g_value_get_boolean (value);
			break;
		case PROP_JOYSTICKNAME:
			prefs->priv->joystick_name = g_strdup (g_value_get_string (value));
			break;
		case PROP_THEPREFIX:
			prefs->priv->theprefix = g_value_get_boolean (value);

			/* Emit the signal (so gamelist view can be changed */
			g_signal_emit (G_OBJECT (prefs), signals[GUI_PREFS_THEPREFIX_TOGGLED], 0,
				       prefs->priv->theprefix);
			break;
		case PROP_CURRENT_ROM:
			prefs->priv->current_rom_name = g_strdup (g_value_get_string (value));
			break;
		case PROP_CURRENT_EXECUTABLE:
			prefs->priv->current_executable_name = g_strdup (g_value_get_string (value));
			break;	
		case PROP_EXECUTABLE_PATHS:
			va = g_value_get_boxed (value);
			if (prefs->priv->executable_paths)
				g_value_array_free (prefs->priv->executable_paths);
			prefs->priv->executable_paths = va != NULL ? g_value_array_copy (va) : NULL;
			break;
		case PROP_ROM_PATHS:
			va = g_value_get_boxed (value);
			if (prefs->priv->rom_paths)
				g_value_array_free (prefs->priv->rom_paths);
			prefs->priv->rom_paths = va != NULL ? g_value_array_copy (va) : NULL;
			break;
		case PROP_SAMPLE_PATHS:
			va = g_value_get_boxed (value);
			if (prefs->priv->sample_paths)
				g_value_array_free (prefs->priv->sample_paths);
			prefs->priv->sample_paths = va != NULL ? g_value_array_copy (va) : NULL;
			break;
		case PROP_CURRENT_ROMFILTER:
			prefs->priv->current_rom_filter = g_value_get_int (value);
			break;
		case PROP_CURRENT_MODE:
			prefs->priv->current_mode = g_value_get_int (value);
			break;
		case PROP_PREVIOUS_MODE:
			prefs->priv->previous_mode = g_value_get_int (value);
			break;
		case PROP_COLS_SHOWN:
			va = g_value_get_boxed (value);
			if (prefs->priv->cols_shown)
				g_value_array_free (prefs->priv->cols_shown);
			prefs->priv->cols_shown = va != NULL ? g_value_array_copy (va) : NULL;

			/* Emit the signal (so gamelist view can be changed */
			g_signal_emit (G_OBJECT (prefs), signals[GUI_PREFS_COL_TOGGLED], 0,
				       prefs->priv->cols_shown);
			break;
		case PROP_COLS_WIDTH:
			va = g_value_get_boxed (value);
			if (prefs->priv->cols_width)
				g_value_array_free (prefs->priv->cols_width);
			prefs->priv->cols_width = va != NULL ? g_value_array_copy (va) : NULL;
			break;
		case PROP_SORT_COL:
			prefs->priv->sort_col = g_value_get_int (value);
			break;
		case PROP_SORT_COL_DIR:
			prefs->priv->sort_col_direction = g_value_get_int (value);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
			break;
	}
	
	/* As long as the notify::<property> callback is set, the handler
	   will then manage saving the key file */
}
Ejemplo n.º 27
0
static gboolean
gimp_help_browser (Gimp *gimp)
{
  static gboolean  busy = FALSE;
  GimpProcedure   *procedure;

  if (busy)
    return TRUE;

  busy = TRUE;

  /*  Check if a help browser is already running  */
  procedure = gimp_pdb_lookup_procedure (gimp->pdb,
                                         "extension-gimp-help-browser-temp");

  if (! procedure)
    {
      GValueArray *args          = NULL;
      gint          n_domains    = 0;
      gchar       **help_domains = NULL;
      gchar       **help_uris    = NULL;

      procedure = gimp_pdb_lookup_procedure (gimp->pdb,
                                             "extension-gimp-help-browser");

      if (! procedure)
        {
          gimp_help_browser_error (gimp,
                                   _("Help browser not found"),
                                   _("Could not find GIMP help browser."),
                                   _("The GIMP help browser plug-in appears "
                                     "to be missing from your installation."));
          busy = FALSE;

          return FALSE;
        }

      n_domains = gimp_plug_in_manager_get_help_domains (gimp->plug_in_manager,
                                                         &help_domains,
                                                         &help_uris);

      args = gimp_procedure_get_arguments (procedure);
      gimp_value_array_truncate (args, 5);

      g_value_set_int             (&args->values[0], GIMP_RUN_INTERACTIVE);
      g_value_set_int             (&args->values[1], n_domains);
      gimp_value_take_stringarray (&args->values[2], help_domains, n_domains);
      g_value_set_int             (&args->values[3], n_domains);
      gimp_value_take_stringarray (&args->values[4], help_uris, n_domains);

      gimp_procedure_execute_async (procedure, gimp,
                                    gimp_get_user_context (gimp),
                                    NULL, args, NULL);

      g_value_array_free (args);
    }

  /*  Check if the help browser started properly  */
  procedure = gimp_pdb_lookup_procedure (gimp->pdb,
                                         "extension-gimp-help-browser-temp");

  if (! procedure)
    {
      gimp_help_browser_error (gimp,
                               _("Help browser doesn't start"),
                               _("Could not start the GIMP help browser plug-in."),
                               NULL);
      busy = FALSE;

      return FALSE;
    }

  busy = FALSE;

  return TRUE;
}
Ejemplo n.º 28
0
GList *
lgm_device_enum_devices (const gchar * source_name, LgmDeviceType type)
{
  GstElement *source;
  GstPropertyProbe *probe;
  GValueArray *va;
  const gchar *prop_name;
  GList *list = NULL;
  guint i = 0;

  source = gst_element_factory_make (source_name, "source");
  if (!source || !GST_IS_PROPERTY_PROBE (source))
    goto finish;
  gst_element_set_state (source, GST_STATE_READY);
  gst_element_get_state (source, NULL, NULL, 5 * GST_SECOND);
  probe = GST_PROPERTY_PROBE (source);

  prop_name = lgm_device_get_property_name_for_source (source_name);

  va = gst_property_probe_probe_and_get_values_name (probe, prop_name);
  gst_element_set_state (source, GST_STATE_NULL);
  gst_element_get_state (source, NULL, NULL, 5 * GST_SECOND);
  gst_object_unref (source);

  if (!va)
    goto finish;


  for (i = 0; i < va->n_values; ++i) {
    GValue *v = g_value_array_get_nth (va, i);
    GValue valstr = { 0, };
    LgmDevice *device;
    gchar *name;

    g_value_init (&valstr, G_TYPE_STRING);
    if (!g_value_transform (v, &valstr))
      continue;

    /* Skip blackmagic on avfvideosrc as we only properly support them
     * through decklinkvideosrc. */
    if (!g_strcmp0 (source_name, "avfvideosrc"))
      if (!g_strcmp0 (g_value_get_string (&valstr), "Blackmagic"))
        continue;

    /* Use the pattern "Blackmagic%d" for device name when decklinkvideosrc */
    if (!g_strcmp0 (source_name, "decklinkvideosrc"))
      name = g_strdup_printf ("Blackmagic%s", g_value_get_string (&valstr));
    else
      name = g_value_dup_string (&valstr);
    device = lgm_device_new (source_name, name, type);
    g_value_unset (&valstr);
    g_free (name);

    lgm_device_fill_formats (device, prop_name);
    list = g_list_append (list, device);
  }
  g_value_array_free (va);

finish:
  {
    return list;
  }
}
Ejemplo n.º 29
0
/**
 * up_wakeups_get_data_sync:
 * @wakeups: a #UpWakeups instance.
 * @cancellable: a #GCancellable or %NULL
 * @error: a #GError, or %NULL.
 *
 * Gets the wakeups data from the daemon.
 *
 * Return value: an array of %UpWakeupItem's
 *
 * Since: 0.9.1
 **/
GPtrArray *
up_wakeups_get_data_sync (UpWakeups *wakeups, GCancellable *cancellable, GError **error)
{
	GError *error_local = NULL;
	GType g_type_gvalue_array;
	GPtrArray *gvalue_ptr_array = NULL;
	GValueArray *gva;
	GValue *gv;
	guint i;
	UpWakeupItem *item;
	GPtrArray *array = NULL;
	gboolean ret;

	g_return_val_if_fail (UP_IS_WAKEUPS (wakeups), NULL);
	g_return_val_if_fail (wakeups->priv->proxy != NULL, NULL);

	g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
					dbus_g_type_get_struct("GValueArray",
						G_TYPE_BOOLEAN,
						G_TYPE_UINT,
						G_TYPE_DOUBLE,
						G_TYPE_STRING,
						G_TYPE_STRING,
						G_TYPE_INVALID));

	/* get compound data */
	ret = dbus_g_proxy_call (wakeups->priv->proxy, "GetData", &error_local,
				 G_TYPE_INVALID,
				 g_type_gvalue_array, &gvalue_ptr_array,
				 G_TYPE_INVALID);
	if (!ret) {
		g_warning ("GetData on failed: %s", error_local->message);
		g_set_error (error, 1, 0, "%s", error_local->message);
		g_error_free (error_local);
		goto out;
	}

	/* no data */
	if (gvalue_ptr_array->len == 0)
		goto out;

	/* convert */
	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
	for (i=0; i<gvalue_ptr_array->len; i++) {
		gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
		item = up_wakeup_item_new ();

		/* 0 */
		gv = g_value_array_get_nth (gva, 0);
		up_wakeup_item_set_is_userspace (item, g_value_get_boolean (gv));
		g_value_unset (gv);

		/* 1 */
		gv = g_value_array_get_nth (gva, 1);
		up_wakeup_item_set_id (item, g_value_get_uint (gv));
		g_value_unset (gv);

		/* 2 */
		gv = g_value_array_get_nth (gva, 2);
		up_wakeup_item_set_value (item, g_value_get_double (gv));
		g_value_unset (gv);

		/* 3 */
		gv = g_value_array_get_nth (gva, 3);
		up_wakeup_item_set_cmdline (item, g_value_get_string (gv));
		g_value_unset (gv);

		/* 4 */
		gv = g_value_array_get_nth (gva, 4);
		up_wakeup_item_set_details (item, g_value_get_string (gv));
		g_value_unset (gv);

		/* add */
		g_ptr_array_add (array, item);
		g_value_array_free (gva);
	}
out:
	if (gvalue_ptr_array != NULL)
		g_ptr_array_unref (gvalue_ptr_array);
	return array;
}
Ejemplo n.º 30
0
static gpointer
build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
{
	GValueArray *result;
	struct in6_addr addr;
	GByteArray *address;
	GByteArray *gateway;
	guint32 metric = 0;
	GValue value = G_VALUE_INIT;
	int err;

	g_return_val_if_fail (address_str, NULL);

	result = g_value_array_new (3);

	/* add address */
	err = inet_pton (AF_INET6, address_str, &addr);
	if (err <= 0) {
		g_warning ("%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
		goto error_out;
	}
	address = g_byte_array_new ();
	g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, address);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add prefix length */
	g_value_init (&value, G_TYPE_UINT);
	g_value_set_uint (&value, plen);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add gateway */
	if (gateway_str && gateway_str[0]) {
		err = inet_pton (AF_INET6, gateway_str, &addr);
		if (err <= 0) {
			/* Try workaround for routes written by broken keyfile writer.
			 * Due to bug bgo#719851, an older version of writer would have
			 * written "a:b:c:d::/plen,metric" if the gateway was ::, instead
			 * of "a:b:c:d::/plen,,metric" or "a:b:c:d::/plen,::,metric"
			 * Try workaround by interepeting gateway_str as metric to accept such
			 * invalid routes. This broken syntax should not be not officially
			 * supported.
			 **/
			if (route && !metric_str && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric))
				addr = in6addr_any;
			else {
				g_warning ("%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
				goto error_out;
			}
		}
	} else
		addr = in6addr_any;

	/* parse metric, default to 0 */
	if (metric_str) {
		if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
			goto error_out;
	}

	gateway = g_byte_array_new ();
	g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, gateway);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add metric (for routing) */
	if (route) {
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (result, &value);
		g_value_unset (&value);
	}

	return result;

error_out:
	g_value_array_free (result);
	return NULL;
}