Esempio n. 1
0
int
main( int argc, char **argv )
{
	GOptionContext *context;
	GOptionGroup *main_group;
	GError *error = NULL;
	IMAGE *im;
	unsigned char header[IM_SIZEOF_HEADER];

	if( VIPS_INIT( argv[0] ) )
	        vips_error_exit( "%s", _( "unable to start VIPS" ) );
	textdomain( GETTEXT_PACKAGE );
	setlocale( LC_ALL, "" );

	context = g_option_context_new( 
		_( "vipsedit - edit vips file header" ) );
	main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );
	g_option_group_add_entries( main_group, entries );
	vips_add_option_entries( main_group ); 
	g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE );
	g_option_context_set_main_group( context, main_group );

	if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
		if( error ) {
			fprintf( stderr, "%s\n", error->message );
		        g_error_free( error );
		}

		exit( -1 );
	}
	if( argc != 2 ) {
		fprintf( stderr, _( "usage: %s [OPTION...] vips-file\n" ), 
			g_get_prgname() );
		exit( -1 );
	}

	if( !(im = im_init( argv[1] )) ||
		(im->fd = im__open_image_file( im->filename )) == -1 ) 
		error_exit( _( "could not open image %s" ), argv[1] );
	if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER ||
		im__read_header_bytes( im, header ) ) 
		error_exit( _( "could not read VIPS header for %s" ), 
			im->filename );

	if( endian ) {
		if( strcmp( endian, "little" ) == 0 )
			im->magic = VIPS_MAGIC_INTEL;
		else if( strcmp( endian, "big" ) == 0 )
			im->magic = VIPS_MAGIC_SPARC;
		else 
			error_exit( _( "bad endian-ness %s, "
				"should be 'big' or 'little'" ), endian );
	}
	if( xsize ) 
		parse_pint( xsize, &im->Xsize );
	if( ysize ) 
		parse_pint( ysize, &im->Ysize );
	if( bands ) 
		parse_pint( bands, &im->Bands );
	if( format ) {
		VipsBandFormat f;

		if( (f = im_char2BandFmt( format )) < 0 )
			error_exit( _( "bad format %s" ), format );
		im->BandFmt = f;
		im->Bbits = im_bits_of_fmt( f );
	}
	if( interpretation ) {
		VipsInterpretation i;

		if( (i = im_char2Type( interpretation )) < 0 )
			error_exit( _( "bad interpretation %s" ), 
				interpretation );
		im->Type = i;
	}
	if( coding ) {
		VipsCoding c;

		if( (c = im_char2Coding( coding )) < 0 )
			error_exit( _( "bad coding %s" ), coding );
		im->Coding = c;
	}
	if( xres ) 
		im->Xres = atof( xres );
	if( yres ) 
		im->Yres = atof( yres );
	if( xoffset ) 
		im->Xoffset = atoi( xoffset );
	if( yoffset ) 
		im->Yoffset = atoi( yoffset );

	if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) 
		error_exit( _( "could not seek on %s" ), im->filename );
	if( im__write_header_bytes( im, header ) ||
		im__write( im->fd, header, IM_SIZEOF_HEADER ) )
		error_exit( _( "could not write to %s" ), im->filename );

	if( setext ) {
		char *xml;
		size_t size;

		if( !(xml = im__file_read( stdin, "stdin", &size )) )
			error_exit( "%s", _( "could not get ext data" ) );

		/* Strip trailing whitespace ... we can get stray \n at the 
		 * end, eg. "echo | editvips --setext fred.v".
		 */
		while( size > 0 && isspace( xml[size - 1] ) )
			size -= 1;

		if( im__write_extension_block( im, xml, size ) )
			error_exit( "%s", _( "could not set extension" ) );
		im_free( xml );
	}

	im_close( im );

	vips_shutdown();

	return( 0 );
}
Esempio n. 2
0
static void usage ()
{
  g_print ("usage: %s --socket=SOCKET OPTIONS\n", g_get_prgname ());
  gsk_control_client_print_command_line_usage (GSK_CONTROL_CLIENT_OPTIONS_DEFAULT);
  exit (1);
}
static char *
start_startup_notification (GdkDisplay     *display,
			    EggDesktopFile *desktop_file,
			    const char     *argv0,
			    int             screen,
			    int             workspace,
			    guint32         launch_time)
{
  static int sequence = 0;
  char *startup_id;
  char *description, *wmclass;
  char *screen_str, *workspace_str;

  if (g_key_file_has_key (desktop_file->key_file,
			  EGG_DESKTOP_FILE_GROUP,
			  EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
			  NULL))
    {
      if (!g_key_file_get_boolean (desktop_file->key_file,
				   EGG_DESKTOP_FILE_GROUP,
				   EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
				   NULL))
	return NULL;
      wmclass = NULL;
    }
  else
    {
      wmclass = g_key_file_get_string (desktop_file->key_file,
				       EGG_DESKTOP_FILE_GROUP,
				       EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS,
				       NULL);
      if (!wmclass)
	return NULL;
    }

  if (launch_time == (guint32)-1)
    launch_time = gdk_x11_display_get_user_time (display);
  startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
				g_get_prgname (),
				(unsigned long)getpid (),
				g_get_host_name (),
				argv0,
				sequence++,
				(unsigned long)launch_time);

  description = g_strdup_printf (_("Starting %s"), desktop_file->name);
  screen_str = g_strdup_printf ("%d", screen);
  workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace);

  gdk_x11_display_broadcast_startup_message (display, "new",
					     "ID", startup_id,
					     "NAME", desktop_file->name,
					     "SCREEN", screen_str,
					     "BIN", argv0,
					     "ICON", desktop_file->icon,
					     "DESKTOP", workspace_str,
					     "DESCRIPTION", description,
					     "WMCLASS", wmclass,
					     NULL);

  g_free (description);
  g_free (wmclass);
  g_free (screen_str);
  g_free (workspace_str);

  return startup_id;
}
Esempio n. 4
0
int
main (int argc, char *argv[])
{
  GOptionContext *context;
  GError         *error;
  GFile          *file;
  GFile          *new_file;
  int             retval = 0;
  gchar          *param;
  gchar          *summary;

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  error = NULL;
  param = g_strdup_printf ("%s %s", _("LOCATION"), _("NEW-NAME"));
  summary = _("Rename a file.");

  context = g_option_context_new (param);
  g_option_context_set_summary (context, summary);
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);

  if (error != NULL)
    {
      g_printerr (_("Error parsing commandline options: %s\n"), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      return 1;
    }

  if (show_version)
    {
      g_print (PACKAGE_STRING "\n");
      return 0;
    }

  if (argc < 3)
    {
      show_help (context, _("Missing operand\n"));
      return 1;
    }

  g_option_context_free (context);
  g_free (param);

  file = g_file_new_for_commandline_arg (argv[1]);

  new_file = g_file_set_display_name (file, argv[2],
				      NULL, &error);

  if (new_file == NULL)
    {
      g_printerr (_("Error: %s\n"), error->message);
      g_error_free (error);
      retval = 1;
    }
  else
    {
      char *uri = g_file_get_uri (new_file);
      g_print (_("Rename successful. New uri: %s\n"), uri);
      g_object_unref (new_file);
      g_free (uri);
    }

  g_object_unref (file);
  return retval;
}
Esempio n. 5
0
gboolean
ostree_builtin_admin (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  gboolean ret = FALSE;
  const char *subcommand_name = NULL;
  OstreeAdminCommand *subcommand;
  gs_free char *prgname = NULL;
  int in, out;

  /*
   * Parse the global options. We rearrange the options as
   * necessary, in order to pass relevant options through
   * to the commands, but also have them take effect globally.
   */

  for (in = 1, out = 1; in < argc; in++, out++)
    {
      /* The non-option is the command, take it out of the arguments */
      if (argv[in][0] != '-')
        {
          if (subcommand_name == NULL)
            {
              subcommand_name = argv[in];
              out--;
              continue;
            }
        }

      else if (g_str_equal (argv[in], "--"))
        {
          break;
        }

      argv[out] = argv[in];
    }

  argc = out;

  subcommand = admin_subcommands;
  while (subcommand->name)
    {
      if (g_strcmp0 (subcommand_name, subcommand->name) == 0)
        break;
      subcommand++;
    }

  if (!subcommand->name)
    {
      GOptionContext *context;
      gs_free char *help;

      context = ostree_admin_option_context_new_with_commands ();

      /* This will not return for some options (e.g. --version). */
      if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, NULL, cancellable, error))
        {
          if (subcommand_name == NULL)
            {
              g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                   "No \"admin\" subcommand specified");
            }
          else
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                           "Unknown \"admin\" subcommand '%s'", subcommand_name);
            }
        }

      help = g_option_context_get_help (context, FALSE, NULL);
      g_printerr ("%s", help);

      g_option_context_free (context);

      goto out;
    }

  prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
  g_set_prgname (prgname);

  if (!subcommand->fn (argc, argv, cancellable, error))
    goto out;
 
  ret = TRUE;
 out:
  return ret;
}
Esempio n. 6
0
static gboolean
cat (GFile * file)
{
  GInputStream *in;
  char buffer[1024 * 8 + 1];
  char *p;
  gssize res;
  gboolean close_res;
  GError *error;
  gboolean success;

  error = NULL;
  in = (GInputStream *) g_file_read (file, NULL, &error);
  if (in == NULL)
    {
      /* Translators: the first %s is the program name, the second one  */
      /* is the URI of the file, the third is the error message.        */
      g_printerr (_("%s: %s: error opening file: %s\n"),
                  g_get_prgname (), g_file_get_uri (file), error->message);
      g_error_free (error);
      return FALSE;
    }

  success = TRUE;
  while (1)
    {
      res =
        g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error);
      if (res > 0)
        {
          ssize_t written;

          p = buffer;
          while (res > 0)
            {
              written = write (STDOUT_FILENO, p, res);

              if (written == -1 && errno != EINTR)
                {
                  /* Translators: the first %s is the program name, the */
                  /* second one is the URI of the file.                 */
                  g_printerr (_("%s: %s, error writing to stdout"),
                              g_get_prgname (), g_file_get_uri (file));
                  success = FALSE;
                  goto out;
                }
              res -= written;
              p += written;
            }
        }
      else if (res < 0)
        {
          /* Translators: the first %s is the program name, the second one  */
          /* is the URI of the file, the third is the error message.        */
          g_printerr (_("%s: %s: error reading: %s\n"),
                      g_get_prgname (), g_file_get_uri (file),
                      error->message);
          g_error_free (error);
          error = NULL;
          success = FALSE;
          break;
        }
      else if (res == 0)
        break;
    }

 out:

  close_res = g_input_stream_close (in, NULL, &error);
  if (!close_res)
    {
      /* Translators: the first %s is the program name, the second one  */
      /* is the URI of the file, the third is the error message.        */
      g_printerr (_("%s: %s: error closing: %s\n"),
                  g_get_prgname (), g_file_get_uri (file), error->message);
      g_error_free (error);
      success = FALSE;
    }

  return success;
}
Esempio n. 7
0
int
main( int argc, char **argv )
{
	GOptionContext *context;
	GError *error = NULL;
	IMAGE *im;
	unsigned char header[IM_SIZEOF_HEADER];

	if( im_init_world( argv[0] ) )
	        error_exit( "%s", _( "unable to start VIPS" ) );
	textdomain( GETTEXT_PACKAGE );
	setlocale( LC_ALL, "" );

	context = g_option_context_new( 
		_( "vipsfile - edit vipsfile header" ) );
	g_option_context_add_main_entries( context, entries, GETTEXT_PACKAGE );
	g_option_context_add_group( context, im_get_option_group() );
	if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
		if( error ) {
			fprintf( stderr, "%s\n", error->message );
		        g_error_free( error );
		}

		exit( -1 );
	}
	if( argc != 2 ) {
		fprintf( stderr, _( "usage: %s [OPTION...] vipsfile\n" ), 
			g_get_prgname() );
		exit( -1 );
	}

	if( !(im = im_init( argv[1] )) ||
		(im->fd = im__open_image_file( im->filename )) == -1 ) 
		error_exit( _( "could not open image %s" ), argv[1] );
	if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER ||
		im__read_header_bytes( im, header ) ) 
		error_exit( _( "could not read VIPS header for %s" ), 
			im->filename );

	if( xsize ) 
		parse_pint( xsize, &im->Xsize );
	if( ysize ) 
		parse_pint( ysize, &im->Ysize );
	if( bands ) 
		parse_pint( bands, &im->Bands );
	if( format ) {
		if( (im->BandFmt = im_char2BandFmt( format )) < 0 )
			error_exit( _( "bad format %s" ), format );
		im->Bbits = im_bits_of_fmt( im->BandFmt );
	}
	if( type ) {
		if( (im->Type = im_char2Type( type )) < 0 )
			error_exit( _( "bad type %s" ), type );
	}
	if( coding ) {
		if( (im->Coding = im_char2Coding( coding )) < 0 )
			error_exit( _( "bad coding %s" ), coding );
	}
	if( xres ) 
		im->Xres = atof( xres );
	if( yres ) 
		im->Yres = atof( yres );
	if( xoffset ) 
		im->Xoffset = atoi( xoffset );
	if( yoffset ) 
		im->Yoffset = atoi( yoffset );

	if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) 
		error_exit( _( "could not seek on %s" ), im->filename );
	if( im__write_header_bytes( im, header ) ||
		im__write( im->fd, header, IM_SIZEOF_HEADER ) )
		error_exit( _( "could not write to %s" ), im->filename );

	if( setext ) {
		char *xml;
		unsigned int size;

		if( !(xml = im__file_read( stdin, "stdin", &size )) )
			error_exit( "%s", _( "could not get ext data" ) );

		/* Strip trailing whitespace ... we can get stray \n at the 
		 * end, eg. "echo | edvips --setext fred.v".
		 */
		while( size > 0 && isspace( xml[size - 1] ) )
			size -= 1;

		if( im__write_extension_block( im, xml, size ) )
			error_exit( "%s", _( "could not set extension" ) );
		im_free( xml );
	}

	im_close( im );

	vips_shutdown();

	return( 0 );
}
Esempio n. 8
0
int
main (int argc, char *argv[])
{
  GError *error = NULL;
  GOptionContext *context = NULL;
  gchar *summary;
  gchar *app_name;
#ifdef G_OS_UNIX
  gchar *desktop_file_name;
#endif
  GAppInfo *info = NULL;
  GAppLaunchContext *launch_context;
  GList *l;
  GFile *f;

  setlocale (LC_ALL, "");

#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR);
  textdomain (GETTEXT_PACKAGE);
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif
#endif

  /* Translators: this message will appear immediately after the */
  /* usage string - Usage: COMMAND [OPTION...] <THIS_MESSAGE>    */
  context =
    g_option_context_new (_("APPLICATION [URI...] — launch an APPLICATION"));

  /* Translators: this message will appear after the usage string */
  /* and before the list of options.                              */
  summary = _("Launch an application (specified by its desktop file name),\n"
              "optionally passing one or more URIs as arguments.");
  g_option_context_set_summary (context, summary);
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (FALSE));

  g_option_context_parse (context, &argc, &argv, &error);

  g_option_context_free (context);

  if (error != NULL)
    {
      g_printerr (_("Error parsing commandline options: %s\n"), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      return 1;
    }

  if (show_version)
    {
      g_print ("%d.%d.%d\n",
               gtk_get_major_version (),
               gtk_get_minor_version (),
               gtk_get_micro_version ());
      return 0;
    }

  if (!args)
    {
      /* Translators: the %s is the program name. This error message */
      /* means the user is calling gtk-launch without any argument.  */
      g_printerr (_("%s: missing application name"), g_get_prgname ());
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }


  gtk_init (&argc, &argv);

  app_name = *args;
#ifdef G_OS_UNIX
  if (g_str_has_suffix (app_name, ".desktop"))
    desktop_file_name = g_strdup (app_name);
  else
    desktop_file_name = g_strconcat (app_name, ".desktop", NULL);
  info = G_APP_INFO (g_desktop_app_info_new (desktop_file_name));
  g_free (desktop_file_name);
#else
#warning Please add support for creating AppInfo from id for your OS
  g_printerr (_("Creating AppInfo from id not supported on non unix operating systems"));
#endif
  args++;

  if (!info)
    {
      /* Translators: the first %s is the program name, the second one */
      /* is the application name.                                      */
      g_printerr (_("%s: no such application %s"),
                  g_get_prgname (), app_name);
      g_printerr ("\n");
      return 2;
    }

  l = NULL;
  for (; *args; args++)
    {
      f = g_file_new_for_commandline_arg (*args);
      l = g_list_append (l, f);
    }

  launch_context = (GAppLaunchContext*) gdk_display_get_app_launch_context (gdk_display_get_default ());
  if (!g_app_info_launch (info, l, launch_context, &error))
    {
       /* Translators: the first %s is the program name, the second one  */
       /* is the error message.                                          */
       g_printerr (_("%s: error launching application: %s\n"),
                   g_get_prgname (), error->message);
       return 3;
    }
  g_object_unref (info);
  g_object_unref (launch_context);
  g_list_free_full (l, g_object_unref);

  return 0;
}
Esempio n. 9
0
File: gvfs-ls.c Progetto: snnw/gvfs
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  GFile *file;
  
  setlocale (LC_ALL, "");

  g_type_init ();
  
  error = NULL;
  context = g_option_context_new ("- list files at <location>");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);
  
  if (error != NULL)
    {
      g_printerr ("Error parsing commandline options: %s\n", error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."),
                  g_get_prgname ());
      g_printerr ("\n");
      g_error_free(error);
      return 1;
    }

  if (attributes != NULL)
    {
      /* asking for attributes implies -l; otherwise it won't get shown */
      show_long = TRUE;
    }

  attributes = g_strconcat (G_FILE_ATTRIBUTE_STANDARD_NAME ","
			    G_FILE_ATTRIBUTE_STANDARD_TYPE ","
			    G_FILE_ATTRIBUTE_STANDARD_SIZE ","
			    G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
			    attributes != NULL ? "," : "",
			    attributes,
			    NULL);

  if (show_completions != NULL)
    {
      print_completions (show_completions);
      return 0;
    }
  
  if (argc > 1)
    {
      int i;
      
      for (i = 1; i < argc; i++) {
	file = g_file_new_for_commandline_arg (argv[i]);
	list (file);
	g_object_unref (file);
      }
    }
  else
    {
      char *cwd;
      
      cwd = g_get_current_dir ();
      file = g_file_new_for_path (cwd);
      g_free (cwd);
      list (file);
      g_object_unref (file);
    }

  g_free (attributes);
  
  return 0;
}
Esempio n. 10
0
static void
exit_with_usage( void )
{
	g_printerr( _( "Try %s --help for usage.\n" ), g_get_prgname());
	exit( EXIT_FAILURE );
}
Esempio n. 11
0
void
client_new(struct player_control *player_control,
	   int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{
	static unsigned int next_client_num;
	struct client *client;
	char *remote;

	assert(player_control != NULL);
	assert(fd >= 0);

#ifdef HAVE_LIBWRAP
	if (sa->sa_family != AF_UNIX) {
		char *hostaddr = sockaddr_to_string(sa, sa_length, NULL);
		const char *progname = g_get_prgname();

		struct request_info req;
		request_init(&req, RQ_FILE, fd, RQ_DAEMON, progname, 0);

		fromhost(&req);

		if (!hosts_access(&req)) {
			/* tcp wrappers says no */
			g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
			      "libwrap refused connection (libwrap=%s) from %s",
			      progname, hostaddr);

			g_free(hostaddr);
			close_socket(fd);
			return;
		}

		g_free(hostaddr);
	}
#endif	/* HAVE_WRAP */

	if (client_list_is_full()) {
		g_warning("Max Connections Reached!");
		close_socket(fd);
		return;
	}

	client = g_new0(struct client, 1);
	client->player_control = player_control;

	client->channel = g_io_channel_new_socket(fd);
	/* GLib is responsible for closing the file descriptor */
	g_io_channel_set_close_on_unref(client->channel, true);
	/* NULL encoding means the stream is binary safe; the MPD
	   protocol is UTF-8 only, but we are doing this call anyway
	   to prevent GLib from messing around with the stream */
	g_io_channel_set_encoding(client->channel, NULL, NULL);
	/* we prefer to do buffering */
	g_io_channel_set_buffered(client->channel, false);

	client->source_id = g_io_add_watch(client->channel,
					   G_IO_IN|G_IO_ERR|G_IO_HUP,
					   client_in_event, client);

	client->input = fifo_buffer_new(4096);

	client->permission = getDefaultPermissions();
	client->uid = uid;

	client->last_activity = g_timer_new();

	client->cmd_list = NULL;
	client->cmd_list_OK = -1;
	client->cmd_list_size = 0;

	client->deferred_send = g_queue_new();
	client->deferred_bytes = 0;
	client->num = next_client_num++;

	client->send_buf_used = 0;

	client->subscriptions = NULL;
	client->messages = NULL;
	client->num_messages = 0;

	(void)send(fd, GREETING, sizeof(GREETING) - 1, 0);

	client_list_add(client);

	remote = sockaddr_to_string(sa, sa_length, NULL);
	g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
	      "[%u] opened from %s", client->num, remote);
	g_free(remote);
}
Esempio n. 12
0
int
main (int argc, char **argv)
{
	gboolean got_connections = FALSE;
	GOptionContext *opts;
	GError *error = NULL;
	NmtuiStartupData startup_data;
	const char *prgname;
	int i;

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	opts = g_option_context_new (NULL);
	g_option_context_add_main_entries (opts, entries, NULL);

	if (!g_option_context_parse (opts, &argc, &argv, &error)) {
		g_printerr ("%s: %s: %s\n",
		            argv[0],
		            _("Could not parse arguments"),
		            error->message);
		exit (1);
	}
	g_option_context_free (opts);

	nm_editor_bindings_init ();

	nm_client = nm_client_new ();
	if (!nm_client_get_manager_running (nm_client)) {
		g_printerr ("%s\n", _("NetworkManager is not running."));
		exit (1);
	}

	nm_settings = nm_remote_settings_new (NULL);
	g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
	                  G_CALLBACK (connections_read), &got_connections);
	while (!got_connections)
		g_main_context_iteration (NULL, TRUE);

	if (sleep_on_startup)
		sleep (5);

	startup_data.subprogram = NULL;
	prgname = g_get_prgname ();
	if (g_str_has_prefix (prgname, "lt-"))
		prgname += 3;
	if (!strcmp (prgname, "nmtui")) {
		if (argc > 1) {
			for (i = 0; i < num_subprograms; i++) {
				if (!strcmp (argv[1], subprograms[i].name)) {
					argc--;
					argv[0] = (char *) subprograms[i].shortcut;
					memmove (&argv[1], &argv[2], argc * sizeof (char *));
					startup_data.subprogram = subprograms[i].func;
					break;
				}
			}
		} else
			startup_data.subprogram = nmtui_main;
	} else {
		for (i = 0; i < num_subprograms; i++) {
			if (!strcmp (prgname, subprograms[i].shortcut)) {
				startup_data.subprogram = subprograms[i].func;
				break;
			}
		}
	}
	if (!startup_data.subprogram)
		usage ();

	if (!noinit)
		nmt_newt_init ();

	startup_data.argc = argc;
	startup_data.argv = argv;
	g_idle_add (idle_run_subprogram, &startup_data);
	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	if (!noinit)
		nmt_newt_finished ();

	g_object_unref (nm_client);
	g_object_unref (nm_settings);

	return 0;
}
Esempio n. 13
0
/**
 * This is the "real" main which is called both on Windows and UNIX platforms.
 * For the Windows service case, this will also handle the notifications and set
 * up the logging support appropriately.
 */
int main_cmdline(int argc, char **argv) {
	chassis *srv = NULL;
#ifdef HAVE_SIGACTION
	static struct sigaction sigsegv_sa;
#endif
	/* read the command-line options */
	GOptionContext *option_ctx = NULL;
	GOptionEntry *main_entries = NULL;
	chassis_frontend_t *frontend = NULL;
	chassis_options_t *opts = NULL;

	GError *gerr = NULL;
	chassis_log *log = NULL;

	/* a little helper macro to set the src-location that we stepped out at to exit */
#define GOTO_EXIT(status) \
	exit_code = status; \
	exit_location = G_STRLOC; \
	goto exit_nicely;

	int exit_code = EXIT_SUCCESS;
	const gchar *exit_location = G_STRLOC;

	if (chassis_frontend_init_glib()) { /* init the thread, module, ... system */
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* start the logging ... to stderr */
	log = chassis_log_new();
	log->min_lvl = G_LOG_LEVEL_MESSAGE; /* display messages while parsing or loading plugins */
	g_log_set_default_handler(chassis_log_func, log);

#ifdef _WIN32
	if (chassis_win32_is_service() && chassis_log_set_event_log(log, g_get_prgname())) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	if (chassis_frontend_init_win32()) { /* setup winsock */
		GOTO_EXIT(EXIT_FAILURE);
	}
#endif

	/* may fail on library mismatch */
	if (NULL == (srv = chassis_new())) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	srv->log = log; /* we need the log structure for the log-rotation */

	frontend = chassis_frontend_new();
	option_ctx = g_option_context_new("- MySQL Proxy");
	/**
	 * parse once to get the basic options like --defaults-file and --version
	 *
	 * leave the unknown options in the list
	 */
	if (chassis_frontend_init_base_options(option_ctx,
				&argc, &argv,
				&(frontend->print_version),
				&(frontend->default_file),
				&gerr)) {
		g_critical("%s: %s",
				G_STRLOC,
				gerr->message);
		g_clear_error(&gerr);

		GOTO_EXIT(EXIT_FAILURE);
	}

	if (frontend->default_file) {
		srv->default_file = g_strdup(frontend->default_file); //add by vinchen/CFR
		if (!(frontend->keyfile = chassis_frontend_open_config_file(frontend->default_file, &gerr))) {
			g_critical("%s: loading config from '%s' failed: %s",
					G_STRLOC,
					frontend->default_file,
					gerr->message);
			g_clear_error(&gerr);
			GOTO_EXIT(EXIT_FAILURE);
		}
	}

	/* print the main version number here, but don't exit
	 * we check for print_version again, after loading the plugins (if any)
	 * and print their version numbers, too. then we exit cleanly.
	 */
	if (frontend->print_version) {
#ifndef CHASSIS_BUILD_TAG
#define CHASSIS_BUILD_TAG PACKAGE_STRING
#endif
		g_print("%s" CHASSIS_NEWLINE, CHASSIS_BUILD_TAG); 
		chassis_frontend_print_version();
	}
	
	/* add the other options which can also appear in the configfile */
	opts = chassis_options_new();
	chassis_frontend_set_chassis_options(frontend, opts);
	main_entries = chassis_options_to_g_option_entries(opts);
	g_option_context_add_main_entries(option_ctx, main_entries, NULL);

	/**
	 * parse once to get the basic options 
	 *
	 * leave the unknown options in the list
	 */
	if (FALSE == g_option_context_parse(option_ctx, &argc, &argv, &gerr)) {
		g_critical("%s", gerr->message);

		GOTO_EXIT(EXIT_FAILURE);
	}

	if (frontend->keyfile) {
		if (chassis_keyfile_to_options(frontend->keyfile, "mysql-proxy", main_entries)) {
			GOTO_EXIT(EXIT_FAILURE);
		}
	}

	//add by vinchen/CFR
	if (frontend->base_dir != NULL)
		srv->base_dir_org = g_strdup(frontend->base_dir);

	if (chassis_frontend_init_basedir(argv[0], &(frontend->base_dir))) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* basic setup is done, base-dir is known, ... */
	frontend->lua_subdirs = g_new(char *, 2);
	frontend->lua_subdirs[0] = g_strdup("mysql-proxy");
	frontend->lua_subdirs[1] = NULL;

	if (chassis_frontend_init_lua_path(frontend->lua_path, frontend->base_dir, frontend->lua_subdirs)) {
		GOTO_EXIT(EXIT_FAILURE);
	}
	
	if (chassis_frontend_init_lua_cpath(frontend->lua_cpath, frontend->base_dir, frontend->lua_subdirs)) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* assign the mysqld part to the */
	network_mysqld_init(srv); /* starts the also the lua-scope, LUA_PATH and LUA_CPATH have to be set before this being called */


#ifdef HAVE_SIGACTION
	/* register the sigsegv interceptor */

	memset(&sigsegv_sa, 0, sizeof(sigsegv_sa));
	sigsegv_sa.sa_handler = sigsegv_handler;
	sigemptyset(&sigsegv_sa.sa_mask);

	srv->invoke_dbg_on_crash = frontend->invoke_dbg_on_crash;	//add by vinchen/CFR

	if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
		sigaction(SIGSEGV, &sigsegv_sa, NULL);
	}
#endif

	/*
	 * some plugins cannot see the chassis struct from the point
	 * where they open files, hence we must make it available
	 */
	srv->base_dir = g_strdup(frontend->base_dir);

	if (frontend->plugin_dir)			//vinchen/CFR
		srv->plugin_dir_org = g_strdup(frontend->plugin_dir);
	if (frontend->pid_file)
		srv->pid_file_org	= g_strdup(frontend->pid_file);
	if (frontend->log_filename)
		srv->log_file_name_org	= g_strdup(frontend->log_filename);
	if (frontend->lua_path)
		srv->lua_path_org		= g_strdup(frontend->lua_path);
	if (frontend->lua_cpath)
		srv->lua_cpath_org		= g_strdup(frontend->lua_cpath);
	srv->max_files_number	= frontend->max_files_number;

	chassis_frontend_init_plugin_dir(&frontend->plugin_dir, srv->base_dir);
	
	/* 
	 * these are used before we gathered all the options
	 * from the plugins, thus we need to fix them up before
	 * dealing with all the rest.
	 */
	chassis_resolve_path(srv->base_dir, &frontend->log_filename);
	chassis_resolve_path(srv->base_dir, &frontend->pid_file);
	chassis_resolve_path(srv->base_dir, &frontend->plugin_dir);

	/*
	 * start the logging
	 */
	if (frontend->log_filename) {
		log->log_filename = g_strdup(frontend->log_filename);
	}

	log->use_syslog = frontend->use_syslog;

	if (log->log_filename && log->use_syslog) {
		g_critical("%s: log-file and log-use-syslog were given, but only one is allowed",
				G_STRLOC);
		GOTO_EXIT(EXIT_FAILURE);
	}

	if (log->log_filename && FALSE == chassis_log_open(log)) {
		g_critical("can't open log-file '%s': %s", log->log_filename, g_strerror(errno));

		GOTO_EXIT(EXIT_FAILURE);
	}

	/* handle log-level after the config-file is read, just in case it is specified in the file */
	if (frontend->log_level) {
		if (0 != chassis_log_set_level(log, frontend->log_level)) {
			g_critical("--log-level=... failed, level '%s' is unknown ",
					frontend->log_level);

			GOTO_EXIT(EXIT_FAILURE);
		}
	} else {
		/* if it is not set, use "critical" as default */
		log->min_lvl = G_LOG_LEVEL_CRITICAL;
	}

	/*
	 * the MySQL Proxy should load 'admin' and 'proxy' plugins
	 */
	if (!frontend->plugin_names) {
		frontend->plugin_names = g_new(char *, 2);

		frontend->plugin_names[0] = g_strdup("proxy");
		frontend->plugin_names[1] = NULL;
	}
Esempio n. 14
0
static void sigsegv_handler(int G_GNUC_UNUSED signum) {
	g_on_error_stack_trace(g_get_prgname());

	abort(); /* trigger a SIGABRT instead of just exiting */
}
Esempio n. 15
0
static gboolean
submain (struct EvTag *self,
         int    argc,
         char **argv,
         GError **error)
{
  gboolean ret = FALSE;
  git_status_options statusopts = GIT_STATUS_OPTIONS_INIT;
  GCancellable *cancellable = NULL;
  const char *command_name = NULL;
  Subcommand *command;
  char *prgname = NULL;
  int in, out;
  int r;

  /*
   * Parse the global options. We rearrange the options as
   * necessary, in order to pass relevant options through
   * to the commands, but also have them take effect globally.
   */

  for (in = 1, out = 1; in < argc; in++, out++)
    {
      /* The non-option is the command, take it out of the arguments */
      if (argv[in][0] != '-')
        {
          if (command_name == NULL)
            {
              command_name = argv[in];
              out--;
              continue;
            }
        }

      else if (g_str_equal (argv[in], "--"))
        {
          break;
        }

      argv[out] = argv[in];
    }

  argc = out;

  command = commands;
  while (command->name)
    {
      if (g_strcmp0 (command_name, command->name) == 0)
        break;
      command++;
    }

  if (!command->fn)
    {
      GOptionContext *context;
      char *help;

      context = option_context_new_with_commands (commands);

      /* This will not return for some options (e.g. --version). */
      if (option_context_parse (context, NULL, &argc, &argv, cancellable, error))
        {
          if (command_name == NULL)
            {
              g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                   "No command specified");
            }
          else
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Unknown command '%s'", command_name);
            }
        }

      help = g_option_context_get_help (context, FALSE, NULL);
      g_printerr ("%s", help);

      g_option_context_free (context);

      goto out;
    }

  prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name);
  g_set_prgname (prgname);

  r = git_repository_open_ext (&self->top_repo, ".", 0, NULL);
  if (!handle_libgit_ret (r, error))
    goto out;

  r = git_status_init_options (&statusopts, GIT_STATUS_OPTIONS_VERSION);
  if (!handle_libgit_ret (r, error))
    goto out;

  {
    struct TreeWalkData twdata = { FALSE, self, self->top_repo, NULL, cancellable, error };
    r = git_status_foreach_ext (self->top_repo, &statusopts, status_cb, &twdata);
    if (twdata.caught_error)
      goto out;
    if (!handle_libgit_ret (r, error))
      goto out;
  }

  self->checksum = g_checksum_new (G_CHECKSUM_SHA512); 

  if (!command->fn (self, argc, argv, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  return ret;
}
Esempio n. 16
0
/* A non-fatal error. Print the vips error buffer and continue.
 */
static void
print_error( void )
{
        fprintf( stderr, "%s: %s", g_get_prgname(), im_error_buffer() );
	im_error_clear();
}
Esempio n. 17
0
int
main (int argc, char *argv[])
{
  GError *error = NULL;
  GOptionContext *context = NULL;
  GFile *file;
  gchar *summary;
  gchar *description;
  int i;
  gchar *param;
  gboolean res;

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  param = g_strdup_printf (("%s..."), _("FILE"));
  /* Translators: this message will appear after the usage string */
  /* and before the list of options.                              */
  summary = _("Concatenate files and print to the standard output.");
  description = g_strconcat (_("gvfs-cat works just like the traditional cat utility, but using gvfs\n"
                               "locations instead of local files: for example you can use something\n"
                               "like smb://server/resource/file.txt as location."),
                               "\n\n",
                             _("Note: just pipe through cat if you need its formatting options\n"
                               "like -n, -T or other."),
                             NULL);

  context = g_option_context_new (param);
  g_option_context_set_summary (context, summary);
  g_option_context_set_description (context, description);

  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);

  g_option_context_free (context);
  g_free (param);
  g_free (description);

  if (error != NULL)
    {
      g_printerr (_("Error parsing commandline options: %s\n"), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      return 1;
    }

  if (show_version)
    {
      g_print (PACKAGE_STRING "\n");
      return 0;
    }

  if (!locations)
    {
      /* Translators: the %s is the program name. This error message */
      /* means the user is calling gvfs-cat without any argument.    */
      g_printerr (_("%s: missing locations"), g_get_prgname ());
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."),
                  g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }

  res = TRUE;
  i = 0;

  do
    {
      file = g_file_new_for_commandline_arg (locations[i]);
      res = cat (file) && res;
      g_object_unref (file);
    }
  while (locations[++i] != NULL);

  return res ? 0 : 2;
}
Esempio n. 18
0
static void
print_help (GOptionContext *context,
	    gboolean        main_help,
	    GOptionGroup   *group)
{
  GList *list;
  gint max_length, len;
  gint i;
  GHashTable *shadow_map;
  gboolean seen[256];
  
  g_print ("%s\n  %s %s %s\n\n", 
	   _("Usage:"), g_get_prgname(), _("[OPTION...]"),
	   context->parameter_string ? context->parameter_string : "");

  memset (seen, 0, sizeof (gboolean) * 256);
  shadow_map = g_hash_table_new (g_str_hash, g_str_equal);

  if (context->main_group)
    {
      for (i = 0; i < context->main_group->n_entries; i++)
	{
	  g_hash_table_insert (shadow_map, 
			       (gpointer)context->main_group->entries[i].long_name, 
			       context->main_group->entries + i);
	  
	  if (seen[(guchar)context->main_group->entries[i].short_name])
	    context->main_group->entries[i].short_name = 0;
	  else
	    seen[(guchar)context->main_group->entries[i].short_name] = TRUE;
	}
    }

  list = context->groups;
  while (list != NULL)
    {
      GOptionGroup *group = list->data;
      for (i = 0; i < group->n_entries; i++)
	{
	  if (g_hash_table_lookup (shadow_map, group->entries[i].long_name))
	    group->entries[i].long_name = g_strdup_printf ("%s-%s", group->name, group->entries[i].long_name);
	  else  
	    g_hash_table_insert (shadow_map, (gpointer)group->entries[i].long_name, group->entries + i);

	  if (seen[(guchar)group->entries[i].short_name])
	    group->entries[i].short_name = 0;
	  else
	    seen[(guchar)group->entries[i].short_name] = TRUE;
	}
      list = list->next;
    }

  g_hash_table_destroy (shadow_map);

  list = context->groups;

  max_length = g_utf8_strlen ("--help, -?", -1);

  if (list)
    {
      len = g_utf8_strlen ("--help-all", -1);
      max_length = MAX (max_length, len);
    }

  while (list != NULL)
    {
      GOptionGroup *group = list->data;
      
      /* First, we check the --help-<groupname> options */
      len = g_utf8_strlen ("--help-", -1) + g_utf8_strlen (group->name, -1);
      max_length = MAX (max_length, len);

      /* Then we go through the entries */
      for (i = 0; i < group->n_entries; i++)
	{
	  if (group->entries[i].flags & G_OPTION_FLAG_HIDDEN)
	    continue;

	  len = g_utf8_strlen (group->entries[i].long_name, -1);

	  if (group->entries[i].short_name)
	    len += 4;

	  if (group->entries[i].arg != G_OPTION_ARG_NONE &&
	      group->entries[i].arg_description)
	    len += 1 + g_utf8_strlen (TRANSLATE (group, group->entries[i].arg_description), -1);

	  max_length = MAX (max_length, len);
	}
      
      list = list->next;
    }

  /* Add a bit of padding */
  max_length += 4;

  if (!group)
    {
      list = context->groups;
      
      g_print ("%s\n  --%-*s %s\n", 
	       _("Help Options:"), max_length, "help", _("Show help options"));
      
      /* We only want --help-all when there are groups */
      if (list)
	g_print ("  --%-*s %s\n", max_length, "help-all", _("Show all help options"));

      while (list)
	{
	  GOptionGroup *group = list->data;
	  
	  g_print ("  --help-%-*s %s\n", max_length - 5, group->name, TRANSLATE (group, group->help_description));
	  
	  list = list->next;
	}

      g_print ("\n");
    }

  if (group)
    {
      /* Print a certain group */
      
      g_print ("%s\n", TRANSLATE (group, group->description));
      for (i = 0; i < group->n_entries; i++)
	print_entry (group, max_length, &group->entries[i]);
      g_print ("\n");
    }
  else if (!main_help)
    {
      /* Print all groups */

      list = context->groups;

      while (list)
	{
	  GOptionGroup *group = list->data;

	  g_print ("%s\n", group->description);

	  for (i = 0; i < group->n_entries; i++)
	    if (!(group->entries[i].flags & G_OPTION_FLAG_IN_MAIN))
	      print_entry (group, max_length, &group->entries[i]);
	  
	  g_print ("\n");
	  list = list->next;
	}
    }
  
  /* Print application options if --help or --help-all has been specified */
  if (main_help || !group)
    {
      list = context->groups;

      g_print ("%s\n", _("Application Options:"));

      if (context->main_group)
	for (i = 0; i < context->main_group->n_entries; i++) 
	  print_entry (context->main_group, max_length, &context->main_group->entries[i]);

      while (list != NULL)
	{
	  GOptionGroup *group = list->data;

	  /* Print main entries from other groups */
	  for (i = 0; i < group->n_entries; i++)
	    if (group->entries[i].flags & G_OPTION_FLAG_IN_MAIN)
	      print_entry (group, max_length, &group->entries[i]);
	  
	  list = list->next;
	}

      g_print ("\n");
    }
  
  exit (0);
}
Esempio n. 19
0
/**
 * xfce_dialog_show_help_with_version:
 * @parent    : (allow-none): transient parent of the dialog, or %NULL.
 * @component : (allow-none): name of the component opening the help page or %NULL. If the
 *              value is %NULL the target will be the main page of the
 *              documentation website.
 * @page      : (allow-none): subpage of the @component on the website or %NULL.
 * @offset    : (allow-none): anchor offset in @page or %NULL.
 * @version   : (allow-none): alternative version, or %NULL to use xfce_version_string().
 *
 * Asks the user to visit the online documentation. If confirmed, it will open
 * the webbrowser and redirect the user to the correct location.
 *
 * Appart from the @component, @page and @offset the following information
 * is also send to the server: user language and the xfce_version_string()
 * or @version if set.
 *
 * See also: xfce_dialog_show_help().
 *
 * Since: 4.12
 *
 */
void
xfce_dialog_show_help_with_version (GtkWindow   *parent,
                                    const gchar *component,
                                    const gchar *page,
                                    const gchar *offset,
                                    const gchar *version)
{
  GtkWidget   *dialog;
  const gchar *name;
  gchar       *primary;
  GString     *uri;
  gchar       *locale;
  GtkWidget   *message_box;
  GtkWidget   *button;
  XfceRc      *rc;
  gboolean     auto_online;
  GdkScreen   *screen;

  g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));

  /* get the user's locale without encoding */
  locale = g_strdup (setlocale (LC_MESSAGES, NULL));
  if (G_LIKELY (locale != NULL))
    locale = g_strdelimit (locale, ".", '\0');
  else
    locale = g_strdup ("C");

  /* use desktop version if none is set */
  if (version == NULL)
    version = xfce_version_string ();

  /* build the redirect uri */
  uri = g_string_new (MANUAL_WEBSITE);
  g_string_append_printf (uri, "?version=%s&locale=%s", version, locale);
  g_free (locale);

  if (component != NULL)
    g_string_append_printf (uri, "&component=%s", component);
  if (page != NULL)
    g_string_append_printf (uri, "&page=%s", page);
  if (offset != NULL)
    g_string_append_printf (uri, "&offset=%s", offset);

  /* check if we should automatically go online */
  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/help.rc", TRUE);
  if (rc != NULL)
    {
      auto_online = xfce_rc_read_bool_entry (rc, "auto-online", FALSE);
      xfce_rc_close (rc);

      if (auto_online)
        {
          if (parent != NULL)
            screen = gtk_window_get_screen (GTK_WINDOW (parent));
          else
            screen = xfce_gdk_screen_get_active (NULL);

          xfce_dialog_show_help_uri (screen, parent, uri);
          g_string_free (uri, TRUE);

          return;
        }
    }

  /* try to get a translated name of the application */
  name = g_get_application_name ();
  if (g_strcmp0 (name, g_get_prgname ()) == 0)
    name = NULL;

  /* try to get a decent primary text */
  if (name != NULL)
    primary = g_strdup_printf (_("Do you want to read the %s manual online?"), name);
  else
    primary = g_strdup (_("Do you want to read the manual online?"));

  dialog = xfce_message_dialog_new (parent,
                                    _("Online Documentation"),
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_DIALOG_QUESTION,
#else
                                    "dialog-question",
#endif
                                    primary,
                                    _("You will be redirected to the documentation website "
                                      "where the help pages are maintained and translated."),
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_CANCEL,
#else
                                    "gtk-cancel",
#endif
                                    GTK_RESPONSE_NO,
                                    XFCE_BUTTON_TYPE_MIXED,
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_HELP,
#else
                                    "help-browser",
#endif
                                    _("_Read Online"),
                                    GTK_RESPONSE_YES,
                                    NULL);
  g_free (primary);


  message_box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
  g_return_if_fail (GTK_IS_BOX (message_box));

  button = gtk_check_button_new_with_mnemonic (_("_Always go directly to the online documentation"));
  gtk_box_pack_end (GTK_BOX (message_box), button, FALSE, TRUE, 0);
#if GTK_CHECK_VERSION (3, 0, 0)
  g_object_set (G_OBJECT (button), "halign", GTK_ALIGN_END, "margin-start", 8, "margin-end", 8, NULL);
  gtk_widget_set_hexpand (button, TRUE);
#endif
  g_signal_connect (G_OBJECT (button), "toggled",
      G_CALLBACK (xfce_dialog_show_help_auto_toggled), NULL);
  gtk_widget_show (button);

  /* don't focus the checkbutton */
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
  button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
  gtk_widget_grab_focus (button);

  /* show the dialog without locking the mainloop */
  gtk_window_set_modal (GTK_WINDOW (dialog), parent != NULL);
  g_signal_connect (G_OBJECT (dialog), "response",
      G_CALLBACK (xfce_dialog_show_help_response), uri);
  gtk_window_present (GTK_WINDOW (dialog));
}
Esempio n. 20
0
int
main (int argc, char **argv)
{
  GError         *error        = NULL;
  gboolean        is_no_daemon = FALSE;
  gboolean        is_debug     = FALSE;
  gboolean        is_version   = FALSE;
  GOptionContext *context;
  GOptionEntry    entries[] = {
    {"no-daemon", 0, 0, G_OPTION_ARG_NONE, &is_no_daemon, N_("Do not daemonize"), NULL},
    {"debug", 0, 0, G_OPTION_ARG_NONE, &is_debug, N_("Log debugging message"), NULL},
    {"version", 0, 0, G_OPTION_ARG_NONE, &is_version, N_("Version"), NULL},
    {NULL}
  };

  context = g_option_context_new ("- indicator for Nimf");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);

  if (error != NULL)
  {
    g_warning ("%s", error->message);
    g_error_free (error);
    return EXIT_FAILURE;
  }

#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, NIMF_LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif

  if (is_debug)
    g_setenv ("G_MESSAGES_DEBUG", "nimf", TRUE);

  if (is_version)
  {
    g_print ("%s %s\n", argv[0], VERSION);
    exit (EXIT_SUCCESS);
  }

  if (is_no_daemon == FALSE)
  {
    openlog (g_get_prgname (), LOG_PID | LOG_PERROR, LOG_DAEMON);
    syslog_initialized = TRUE;
    g_log_set_default_handler ((GLogFunc) nimf_log_default_handler, &is_debug);

    if (daemon (0, 0) != 0)
    {
      g_critical ("Couldn't daemonize.");
      return EXIT_FAILURE;
    }
  }

  gtk_init (&argc, &argv);

  AppIndicator *indicator;
  GtkWidget    *menu_shell;
  GtkWidget    *about_menu;
  GtkWidget    *exit_menu;

  menu_shell = gtk_menu_new ();
  indicator = app_indicator_new ("nimf-indicator", "input-keyboard",
                                 APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
  app_indicator_set_status (indicator, APP_INDICATOR_STATUS_ACTIVE);
  app_indicator_set_icon_full (indicator, "nimf-indicator", "Nimf");
  app_indicator_set_menu (indicator, GTK_MENU (menu_shell));

  agent = nimf_agent_new ();

  g_signal_connect (agent, "engine-changed",
                    G_CALLBACK (on_engine_changed), indicator);
  g_signal_connect (agent, "disconnected",
                    G_CALLBACK (on_disconnected), indicator);

  /* menu */
  gchar         **engine_ids = nimf_agent_get_loaded_engine_ids (agent);
  GtkWidget      *engine_menu;
  NimfEngineInfo *info;

  guint i;

  for (i = 0; i < g_strv_length (engine_ids); i++)
  {
    info = nimf_engine_get_info_by_id (engine_ids[i]);
    engine_menu = gtk_menu_item_new_with_label (_(info->engine_name));
    gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), engine_menu);
    g_signal_connect (engine_menu, "activate",
                      G_CALLBACK (on_engine_menu), engine_ids[i]);
    g_slice_free (NimfEngineInfo, info);
  }

  about_menu = gtk_menu_item_new_with_label (_("About"));
  exit_menu  = gtk_menu_item_new_with_label (_("Exit"));

  g_signal_connect (about_menu, "activate",
                    G_CALLBACK (on_about_menu), NULL);
  g_signal_connect (exit_menu,  "activate",
                    G_CALLBACK (on_exit_menu),  NULL);

  gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), about_menu);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), exit_menu);

  gtk_widget_show_all (menu_shell);

  gtk_main ();

  g_object_unref (agent);
  g_object_unref (indicator);
  g_strfreev (engine_ids);

  if (syslog_initialized)
    closelog ();

  return EXIT_SUCCESS;
}
Esempio n. 21
0
int
main (int argc, char *argv[])
{
	GOptionContext *ctx;
	GError *error = NULL;
	gboolean do_usage_exit = FALSE;
	int res = 0;

	CORBA_exception_init (&ev);

	g_set_prgname ("activation-client");
	ctx = g_option_context_new (NULL);
	g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
	if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
		g_printerr ("%s\n", error->message);
		g_error_free (error);
		do_usage_exit = TRUE;
	}
	g_option_context_free (ctx);

	if (!do_usage_exit && !specs && !add_path && !remove_path && !(registerior && registeriid)) {
		g_printerr ("You must specify an operation to perform.\n");
		do_usage_exit = TRUE;
	}

	if (do_usage_exit) {
		g_printerr ("Run '%s --help' to see a full list of available command line options.\n", g_get_prgname ());
		exit (1);
	}

	orb = bonobo_activation_init (argc, argv);

	if (specs) {
		g_print ("Query spec is \"%s\"\n", specs);
		if (do_query)
			do_query_server_info();
		else
			res = do_activating();
	} 

	if (add_path && !res)
		add_load_path();

	if (remove_path && !res)
		remove_load_path();

	if (registerior && registeriid && !res)
		res = register_activate_server();

	CORBA_exception_free (&ev);

        return res;
}
Esempio n. 22
0
int
ostree_run (int    argc,
            char **argv,
            OstreeCommand *commands,
            GError **res_error)
{
  OstreeCommand *command;
  GError *error = NULL;
  GCancellable *cancellable = NULL;
  const char *command_name = NULL;
  g_autofree char *prgname = NULL;
  gboolean success = FALSE;
  int in, out;

  /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
  g_setenv ("GIO_USE_VFS", "local", TRUE);

  g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL);

  /*
   * Parse the global options. We rearrange the options as
   * necessary, in order to pass relevant options through
   * to the commands, but also have them take effect globally.
   */

  for (in = 1, out = 1; in < argc; in++, out++)
    {
      /* The non-option is the command, take it out of the arguments */
      if (argv[in][0] != '-')
        {
          if (command_name == NULL)
            {
              command_name = argv[in];
              out--;
              continue;
            }
        }

      else if (g_str_equal (argv[in], "--"))
        {
          break;
        }

      argv[out] = argv[in];
    }

  argc = out;

  command = commands;
  while (command->name)
    {
      if (g_strcmp0 (command_name, command->name) == 0)
        break;
      command++;
    }

  if (!command->fn)
    {
      GOptionContext *context;
      g_autofree char *help;

      context = ostree_option_context_new_with_commands (commands);

      /* This will not return for some options (e.g. --version). */
      if (ostree_option_context_parse (context, NULL, &argc, &argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, &error))
        {
          if (command_name == NULL)
            {
              g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                   "No command specified");
            }
          else
            {
              g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Unknown command '%s'", command_name);
              ostree_usage (commands, TRUE);
            }
        }

      help = g_option_context_get_help (context, FALSE, NULL);
      g_printerr ("%s", help);

      g_option_context_free (context);

      goto out;
    }

  prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name);
  g_set_prgname (prgname);

  
  if (!command->fn (argc, argv, cancellable, &error))
    goto out;

  success = TRUE;
 out:
  g_assert (success || error);

  if (error)
    {
      g_propagate_error (res_error, error);
      return 1;
    }
  return 0;
}
Esempio n. 23
0
String WebContext::platformDefaultDiskCacheDirectory() const
{
    GUniquePtr<char> diskCacheDirectory(g_build_filename(g_get_user_cache_dir(), g_get_prgname(), nullptr));
    return WebCore::filenameToString(diskCacheDirectory.get());
}
Esempio n. 24
0
void myLog(const gchar *log_domain, GLogLevelFlags log_level,
		const gchar *message, gpointer user_data)
{
	gchar * message_hdr;
	const gchar *prg_name = g_get_prgname();

	if (!prg_name)
		prg_name = "process";

	const char * level;
	FILE * logfd;

	if (user_data)
		logfd = user_data;
	else
		logfd = stdout;

	switch (log_level & G_LOG_LEVEL_MASK)
	{
		case G_LOG_LEVEL_ERROR:
			level = _("ERROR");
			break;
		case G_LOG_LEVEL_CRITICAL:
			level = _("CRITICAL");
			break;
		case G_LOG_LEVEL_WARNING:
			level = _("WARNING");
			break;
		case G_LOG_LEVEL_MESSAGE:
			level = _("Message");
			break;
		case G_LOG_LEVEL_INFO:
			level = _("INFO");
			break;
		case G_LOG_LEVEL_DEBUG:
			level = _("DEBUG");
			break;
		default:
			level = "LOG";
			break;
	}

	if(log_level & G_LOG_FLAG_FATAL)
	{
		if (user_data)
			logfd = user_data;
		else
			logfd = stderr;
	}

	struct timeval tv;

	gettimeofday(&tv,0);

	if( tv.tv_usec < start_time.tv_usec)
	{
		tv.tv_usec = 1000000 + tv.tv_usec - start_time.tv_usec;
		tv.tv_sec -= start_time.tv_sec+1;
	}
	else
	{
		tv.tv_sec -= start_time.tv_sec;
		tv.tv_usec -= start_time.tv_usec;
	}

	message_hdr = g_strdup_printf("(%s) [%06li.%04li] **%s** : ",
			prg_name,tv.tv_sec,tv.tv_usec / 100,level);

	NotifyNotification * notify = notify_notification_new(message_hdr,message,NULL,NULL);

	notify_notification_set_timeout(notify,2000);
	notify_notification_show(notify,0);

	g_object_unref(notify);
	g_free(message_hdr);

	fprintf(logfd,"[%06li.%04li](%s:%lu) **%s** : %s\n",
			tv.tv_sec,tv.tv_usec / 100,
			prg_name,(gulong)getpid(),
			level,message);

	if(user_data)
		fflush(user_data);
}
Esempio n. 25
0
gboolean
photos_utils_file_copy_as_thumbnail (GFile *source,
                                     GFile *destination,
                                     const gchar *original_uri,
                                     gint64 original_height,
                                     gint64 original_width,
                                     GCancellable *cancellable,
                                     GError **error)
{
  g_autoptr (GFileInputStream) istream = NULL;
  g_autoptr (GFileOutputStream) ostream = NULL;
  g_autoptr (GdkPixbuf) pixbuf = NULL;
  gboolean ret_val = FALSE;
  const gchar *prgname;
  g_autofree gchar *original_height_str = NULL;
  g_autofree gchar *original_width_str = NULL;

  g_return_val_if_fail (G_IS_FILE (source), FALSE);
  g_return_val_if_fail (G_IS_FILE (destination), FALSE);
  g_return_val_if_fail (original_uri != NULL && original_uri[0] != '\0', FALSE);
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  istream = g_file_read (source, cancellable, error);
  if (istream == NULL)
    goto out;

  pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (istream), cancellable, error);
  if (pixbuf == NULL)
    goto out;

  ostream = g_file_replace (destination,
                            NULL,
                            FALSE,
                            G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
                            cancellable,
                            error);
  if (ostream == NULL)
    goto out;

  original_height_str = g_strdup_printf ("%" G_GINT64_FORMAT, original_height);
  original_width_str = g_strdup_printf ("%" G_GINT64_FORMAT, original_width);
  prgname = g_get_prgname ();
  if (!gdk_pixbuf_save_to_stream (pixbuf,
                                  G_OUTPUT_STREAM (ostream),
                                  "png",
                                  cancellable,
                                  error,
                                  "tEXt::Software", prgname,
                                  "tEXt::Thumb::URI", original_uri,
                                  "tEXt::Thumb::Image::Height", original_height_str,
                                  "tEXt::Thumb::Image::Width", original_width_str,
                                  NULL))
    {
      goto out;
    }

  ret_val = TRUE;

 out:
  return ret_val;
}
Esempio n. 26
0
int
main (int    argc,
      char **argv)
{
  gchar exe_path[PATH_MAX+1];
  ssize_t exe_path_len;
  gboolean replace;
  gboolean verbose;
  gboolean show_version;
  GBusNameOwnerFlags flags;
  GOptionContext *context;
  g_autoptr(GError) error = NULL;
  const GOptionEntry options[] = {
    { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace,  "Replace old daemon.", NULL },
    { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,  "Enable debug output.", NULL },
    { "session", 0, 0, G_OPTION_ARG_NONE, &on_session_bus,  "Run in session, not system scope (for tests).", NULL },
    { "no-idle-exit", 0, 0, G_OPTION_ARG_NONE, &no_idle_exit,  "Don't exit when idle.", NULL },
    { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "Show program version.", NULL},
    { NULL }
  };

  setlocale (LC_ALL, "");

  g_setenv ("GIO_USE_VFS", "local", TRUE);

  g_set_prgname (argv[0]);

  g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL);

  context = g_option_context_new ("");

  g_option_context_set_summary (context, "Flatpak system helper");
  g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

  replace = FALSE;
  verbose = FALSE;
  show_version = FALSE;

  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr ("%s: %s", g_get_application_name(), error->message);
      g_printerr ("\n");
      g_printerr ("Try \"%s --help\" for more information.",
                  g_get_prgname ());
      g_printerr ("\n");
      g_option_context_free (context);
      return 1;
    }

  if (show_version)
    {
      g_print (PACKAGE_STRING "\n");
      return 0;
    }

  if (verbose)
    g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL);

  authority = polkit_authority_get_sync (NULL, &error);
  if (authority == NULL)
    {
      g_printerr ("Can't get polkit authority: %s\n", error->message);
      return 1;
    }

  exe_path_len = readlink ("/proc/self/exe", exe_path, sizeof (exe_path) - 1);
  if (exe_path_len > 0)
    {
      exe_path[exe_path_len] = 0;
      GFileMonitor *monitor;
      g_autoptr(GFile) exe = NULL;
      g_autoptr(GError) local_error = NULL;

      exe = g_file_new_for_path (exe_path);
      monitor =  g_file_monitor_file (exe,
                                      G_FILE_MONITOR_NONE,
                                      NULL,
                                      &local_error);
      if (monitor == NULL)
        g_warning ("Failed to set watch on %s: %s", exe_path, error->message);
      else
        g_signal_connect (monitor, "changed",
                          G_CALLBACK (binary_file_changed_cb), NULL);
    }

  flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
  if (replace)
    flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;

  name_owner_id = g_bus_own_name (on_session_bus ? G_BUS_TYPE_SESSION  : G_BUS_TYPE_SYSTEM,
                                  "org.freedesktop.Flatpak.SystemHelper",
                                  flags,
                                  on_bus_acquired,
                                  on_name_acquired,
                                  on_name_lost,
                                  NULL,
                                  NULL);

  /* Ensure we don't idle exit */
  schedule_idle_callback ();

  main_loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (main_loop);

  return 0;
}
Esempio n. 27
0
static void report_version(void) {
	g_print("%s %s\n", g_get_prgname(), VERSION);
	g_print("Released %s\n", VG_RELEASE_DATE);
	exit(EXIT_SUCCESS);
}
int
rpmostree_builtin_container (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  RpmOstreeContainerCommand *subcommand;
  const char *subcommand_name = NULL;
  gs_free char *prgname = NULL;
  int exit_status = EXIT_SUCCESS;
  int in, out;

  for (in = 1, out = 1; in < argc; in++, out++)
    {
      /* The non-option is the command, take it out of the arguments */
      if (argv[in][0] != '-')
        {
          if (subcommand_name == NULL)
            {
              subcommand_name = argv[in];
              out--;
              continue;
            }
        }

      else if (g_str_equal (argv[in], "--"))
        {
          break;
        }

      argv[out] = argv[in];
    }

  argc = out;

  subcommand = container_subcommands;
  while (subcommand->name)
    {
      if (g_strcmp0 (subcommand_name, subcommand->name) == 0)
        break;
      subcommand++;
    }

  if (!subcommand->name)
    {
      GOptionContext *context;
      gs_free char *help = NULL;

      context = container_option_context_new_with_commands ();

      /* This will not return for some options (e.g. --version). */
      (void) rpmostree_option_context_parse (context, NULL,
                                             &argc, &argv,
                                             RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
                                             cancellable,
                                             NULL,
                                             NULL);
      if (subcommand_name == NULL)
        {
          g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                               "No \"container\" subcommand specified");
        }
      else
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Unknown \"container\" subcommand '%s'", subcommand_name);
        }

      exit_status = EXIT_FAILURE;
      help = g_option_context_get_help (context, FALSE, NULL);
      g_printerr ("%s", help);

      g_option_context_free (context);

      goto out;
    }

  prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
  g_set_prgname (prgname);

  exit_status = subcommand->fn (argc, argv, cancellable, error);

 out:
  return exit_status;
}
Esempio n. 29
0
static char *
gdk_x11_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
                                                  GAppInfo          *info,
                                                  GList             *files)
{
  static int sequence = 0;
  GdkDisplay *display;
  GdkX11Screen *screen;
  int files_count;
  char *description;
  char *icon_name;
  const char *binary_name;
  const char *application_id;
  char *screen_str;
  char *workspace_str;
  GIcon *icon;
  guint32 timestamp;
  char *startup_id;
  GFileInfo *fileinfo;
  GdkAppLaunchContext *ctx;

  ctx = GDK_APP_LAUNCH_CONTEXT (context);

  display = ctx->display;
  screen = GDK_X11_DISPLAY (display)->screen;

  fileinfo = NULL;

  files_count = g_list_length (files);
  if (files_count == 0)
    {
      description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info));
    }
  else if (files_count == 1)
    {
      gchar *display_name;

      if (g_file_is_native (files->data))
        fileinfo = g_file_query_info (files->data,
                                      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
                                      G_FILE_ATTRIBUTE_STANDARD_ICON,
                                      0, NULL, NULL);

      display_name = get_display_name (files->data, fileinfo);
      description = g_strdup_printf (_("Opening %s"), display_name);
      g_free (display_name);
    }
  else
    description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
                                                "Opening %d Item",
                                                "Opening %d Items",
                                                files_count), files_count);

  icon_name = NULL;
  if (ctx->icon_name)
    icon_name = g_strdup (ctx->icon_name);
  else
    {
      icon = NULL;

      if (ctx->icon != NULL)
        icon = g_object_ref (ctx->icon);
      else if (files_count == 1)
        icon = get_icon (files->data, fileinfo);

      if (icon == NULL)
        {
          icon = g_app_info_get_icon (info);
          if (icon != NULL)
            g_object_ref (icon);
        }

      if (icon != NULL)
        {
          icon_name = gicon_to_string (icon);
          g_object_unref (icon);
        }
    }

  binary_name = g_app_info_get_executable (info);

  timestamp = ctx->timestamp;
  if (timestamp == GDK_CURRENT_TIME)
    timestamp = gdk_x11_display_get_user_time (display);

  screen_str = g_strdup_printf ("%d", gdk_x11_screen_get_screen_number (screen));
  if (ctx->workspace > -1)
    workspace_str = g_strdup_printf ("%d", ctx->workspace);
  else
    workspace_str = NULL;

  if (G_IS_DESKTOP_APP_INFO (info))
    application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info));
  else
    application_id = NULL;

  startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
                                g_get_prgname (),
                                (unsigned long)getpid (),
                                g_get_host_name (),
                                binary_name,
                                sequence++,
                                (unsigned long)timestamp);

  gdk_x11_display_broadcast_startup_message (display, "new",
                                             "ID", startup_id,
                                             "NAME", g_app_info_get_name (info),
                                             "SCREEN", screen_str,
                                             "BIN", binary_name,
                                             "ICON", icon_name,
                                             "DESKTOP", workspace_str,
                                             "DESCRIPTION", description,
                                             "WMCLASS", NULL, /* FIXME */
                                             "APPLICATION_ID", application_id,
                                             NULL);

  g_free (description);
  g_free (screen_str);
  g_free (workspace_str);
  g_free (icon_name);
  if (fileinfo)
    g_object_unref (fileinfo);

  add_startup_timeout (screen, startup_id);

  return startup_id;
}
/**
 * gst_missing_plugin_message_get_installer_detail:
 * @msg: a missing-plugin #GstMessage of type #GST_MESSAGE_ELEMENT
 *
 * Returns an opaque string containing all the details about the missing
 * element to be passed to an external installer called via
 * gst_install_plugins_async() or gst_install_plugins_sync().
 *
 * This function is mainly for applications that call external plugin
 * installation mechanisms using one of the two above-mentioned functions.
 *
 * Returns: a newly-allocated detail string, or NULL on error. Free string
 *          with g_free() when not needed any longer.
 */
gchar *
gst_missing_plugin_message_get_installer_detail (GstMessage * msg)
{
  GstMissingType missing_type;
  const gchar *progname;
  const gchar *type;
  GString *str = NULL;
  gchar *detail = NULL;
  gchar *desc;
  const GstStructure *structure;

  g_return_val_if_fail (gst_is_missing_plugin_message (msg), NULL);

  structure = gst_message_get_structure (msg);
  GST_LOG ("Parsing missing-plugin message: %" GST_PTR_FORMAT, structure);

  missing_type = missing_structure_get_type (structure);
  if (missing_type == GST_MISSING_TYPE_UNKNOWN) {
    GST_WARNING ("couldn't parse 'type' field");
    goto error;
  }

  type = gst_structure_get_string (structure, "type");
  g_assert (type != NULL);      /* validity already checked above */

  /* FIXME: use gst_installer_detail_new() here too */
  str = g_string_new (GST_DETAIL_STRING_MARKER "|");
  g_string_append_printf (str, "%s|", GST_API_VERSION);

  progname = (const gchar *) g_get_prgname ();
  if (progname) {
    g_string_append_printf (str, "%s|", progname);
  } else {
    g_string_append_printf (str, "pid/%lu|", (gulong) getpid ());
  }

  desc = gst_missing_plugin_message_get_description (msg);
  if (desc) {
    g_strdelimit (desc, "|", '#');
    g_string_append_printf (str, "%s|", desc);
    g_free (desc);
  } else {
    g_string_append (str, "|");
  }

  switch (missing_type) {
    case GST_MISSING_TYPE_URISOURCE:
    case GST_MISSING_TYPE_URISINK:
    case GST_MISSING_TYPE_ELEMENT:
      if (!missing_structure_get_string_detail (structure, &detail))
        goto error;
      break;
    case GST_MISSING_TYPE_DECODER:
    case GST_MISSING_TYPE_ENCODER:{
      GstCaps *caps = NULL;

      if (!missing_structure_get_caps_detail (structure, &caps))
        goto error;

      detail = gst_caps_to_string (caps);
      gst_caps_unref (caps);
      break;
    }
    default:
      g_return_val_if_reached (NULL);
  }

  g_string_append_printf (str, "%s-%s", type, detail);
  g_free (detail);

  return g_string_free (str, FALSE);

/* ERRORS */
error:
  {
    GST_WARNING ("Failed to parse missing-plugin msg: %" GST_PTR_FORMAT, msg);
    if (str)
      g_string_free (str, TRUE);
    return NULL;
  }
}