Пример #1
0
gboolean
panel_app_info_launch_uris (GAppInfo   *appinfo,
			    GList      *uris,
			    GdkScreen  *screen,
			    guint32     timestamp,
			    GError    **error)
{
	GdkAppLaunchContext *context;
	GError              *local_error;
	gboolean             retval;

	g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
	g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	context = gdk_app_launch_context_new ();
	gdk_app_launch_context_set_screen (context, screen);
	gdk_app_launch_context_set_timestamp (context, timestamp);

	local_error = NULL;
	retval = g_app_info_launch_uris (appinfo, uris,
					 (GAppLaunchContext *) context,
					 &local_error);

	g_object_unref (context);

        if ((local_error == NULL) && (retval == TRUE))
            return TRUE;

	return _panel_launch_handle_error (g_app_info_get_name (appinfo),
					   screen, local_error, error);
}
Пример #2
0
static void browse_python_scripts_dir(GtkAction *action, gpointer data)
{
  gchar *uri;
  GdkAppLaunchContext *launch_context;
  GError *error = NULL;
  MainWindow *mainwin;

  mainwin =  mainwindow_get_mainwindow();
  if(!mainwin) {
      debug_print("Browse Python scripts: Problems getting the mainwindow\n");
      return;
  }
  launch_context = gdk_app_launch_context_new();
  gdk_app_launch_context_set_screen(launch_context, gtk_widget_get_screen(mainwin->window));
  uri = g_strconcat("file://", get_rc_dir(), G_DIR_SEPARATOR_S, PYTHON_SCRIPTS_BASE_DIR, G_DIR_SEPARATOR_S, NULL);
  g_app_info_launch_default_for_uri(uri, G_APP_LAUNCH_CONTEXT(launch_context), &error);

  if(error) {
      debug_print("Could not open scripts dir browser: '%s'\n", error->message);
      g_error_free(error);
  }

  g_object_unref(launch_context);
  g_free(uri);
}
Пример #3
0
void
_g_launch_command (GtkWidget  *parent,
		   const char *command,
		   const char *name,
		   GList      *files)
{
	GError              *error = NULL;
	GAppInfo            *app_info;
	GdkAppLaunchContext *launch_context;

	app_info = g_app_info_create_from_commandline (command, name, G_APP_INFO_CREATE_SUPPORTS_URIS, &error);
	if (app_info == NULL) {
		_gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error);
		return;
	}

	launch_context = gdk_app_launch_context_new ();
	gdk_app_launch_context_set_screen (launch_context, gtk_widget_get_screen (parent));

	if (! g_app_info_launch (app_info, files, G_APP_LAUNCH_CONTEXT (launch_context), &error)) {
		_gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error);
		return;
	}

	g_object_unref (app_info);
}
Пример #4
0
static void
launch_application_from_command_internal (const gchar *full_command,
					  GdkScreen *screen,
					  gboolean use_terminal)
{
	GAppInfo *app;
	GdkAppLaunchContext *ctx;
	GdkDisplay *display;

	if (use_terminal) {
		eel_gnome_open_terminal_on_screen (full_command, screen);
	} else {
		app = g_app_info_create_from_commandline (full_command, NULL, 0, NULL);

		if (app != NULL) {
			display = gdk_screen_get_display (screen);
			ctx = gdk_display_get_app_launch_context (display);
			gdk_app_launch_context_set_screen (ctx, screen);

			g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), NULL);

			g_object_unref (app);
			g_object_unref (ctx);
		}
	}
}					  
Пример #5
0
gboolean
libre_impuesto_file_launch_application (GAppInfo *app,
			      GList *files,
			      guint32 user_time,
			      GtkWidget *widget)
{
	GdkAppLaunchContext *context;
	GdkDisplay *display;
	GdkScreen *screen;
	gboolean res;

	if (widget)
	{
		display = gtk_widget_get_display (widget);
		screen = gtk_widget_get_screen (widget);
	}
	else
	{
		display = gdk_display_get_default ();
		screen = gdk_screen_get_default ();
	}

	context = gdk_display_get_app_launch_context (display);
	gdk_app_launch_context_set_screen (context, screen);
	gdk_app_launch_context_set_timestamp (context, user_time);

	res = g_app_info_launch (app, files,
				 G_APP_LAUNCH_CONTEXT (context), NULL);
	g_object_unref (context);

	return res;
}
Пример #6
0
gboolean exec_app_info (const char *executable, GAppInfoCreateFlags flags)
{
    GAppInfo *appinfo = NULL;
    GError *error = NULL;
    gboolean is_ok __attribute__((unused)) = FALSE;

    appinfo = gen_app_info (executable, flags);
    if ( appinfo == NULL ) {
        g_debug ("gen app info failed!");
        return FALSE;
    }

    GdkAppLaunchContext* ctx = gdk_display_get_app_launch_context(gdk_display_get_default());
    gdk_app_launch_context_set_screen(ctx, gdk_screen_get_default()); //must set this otherwise termiator will not work properly
    is_ok = g_app_info_launch (appinfo, NULL, (GAppLaunchContext*)ctx, &error);
    g_object_unref(ctx);
    if (error!=NULL)
    {
        g_debug("exec app info error: %s", error->message);
        g_error_free(error);
        g_object_unref (appinfo);

        return FALSE;
    }

    g_object_unref (appinfo);
    return TRUE;
}
Пример #7
0
static void
panel_menu_item_activate_switch_user (GtkWidget *menuitem,
				      gpointer   user_data)
{
	GdkScreen *screen;
	GAppInfo  *app_info;

	if (panel_lockdown_get_disable_switch_user_s ())
		return;

	screen = gtk_widget_get_screen (GTK_WIDGET (menuitem));
	app_info = g_app_info_create_from_commandline (GDM_FLEXISERVER_COMMAND " " GDM_FLEXISERVER_ARGS,
						       GDM_FLEXISERVER_COMMAND,
						       G_APP_INFO_CREATE_NONE,
						       NULL);

	if (app_info) {
		GdkAppLaunchContext *launch_context;
		GdkDisplay          *display;

		display = gdk_screen_get_display (screen);
		launch_context = gdk_display_get_app_launch_context (display);
		gdk_app_launch_context_set_screen (launch_context, screen);

		g_app_info_launch (app_info, NULL,
				   G_APP_LAUNCH_CONTEXT (launch_context),
				   NULL);

		g_object_unref (launch_context);
		g_object_unref (app_info);
	}
}
void
eel_gnome_open_terminal_on_screen (const char *command,
				   GdkScreen  *screen)
{
	GAppInfo *app;
	GdkAppLaunchContext *ctx;
	GError *error = NULL;
	GdkDisplay *display;

	app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, &error);

	if (app != NULL && screen != NULL) {
		display = gdk_screen_get_display (screen);
		ctx = gdk_display_get_app_launch_context (display);
		gdk_app_launch_context_set_screen (ctx, screen);

		g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);

		g_object_unref (app);
		g_object_unref (ctx);
	}

	if (error != NULL) {
		g_message ("Could not start application on terminal: %s", error->message);

		g_error_free (error);
	}
}
Пример #9
0
gboolean
panel_app_info_launch_uris (GAppInfo   *appinfo,
			    GList      *uris,
			    GdkScreen  *screen,
			    guint32     timestamp,
			    GError    **error)
{
	GdkAppLaunchContext *context;
	GError              *local_error;
	gboolean             retval;

	g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (appinfo), FALSE);
	g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	GdkDisplay *display = gdk_display_get_default ();
	context = gdk_display_get_app_launch_context (display);
	gdk_app_launch_context_set_screen (context, screen);
	gdk_app_launch_context_set_timestamp (context, timestamp);

	local_error = NULL;
	retval = g_desktop_app_info_launch_uris_as_manager ((GDesktopAppInfo*)appinfo, uris,
						   (GAppLaunchContext *) context,
						   G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
						   NULL, NULL, gather_pid_callback, appinfo,
						   &local_error);

	g_object_unref (context);

	if ((local_error == NULL) && (retval == TRUE))
		return TRUE;

	return _panel_launch_handle_error (g_app_info_get_name ((GAppInfo*) appinfo),
					   screen, local_error, error);
}
Пример #10
0
static gboolean
panel_app_info_launch_uris (GAppInfo   *appinfo,
			    GList      *uris,
			    GdkScreen  *screen,
			    guint32     timestamp,
			    GError    **error)
{
  GdkAppLaunchContext *context;
  GError              *local_error;
  GdkDisplay          *display;

  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  display = gdk_screen_get_display (screen);
  context = gdk_display_get_app_launch_context (display);
  gdk_app_launch_context_set_screen (context, screen);
  gdk_app_launch_context_set_timestamp (context, timestamp);

  local_error = NULL;
  g_app_info_launch_uris (appinfo, uris,
			  (GAppLaunchContext *) context,
			  &local_error);

  g_object_unref (context);

  return _panel_launch_handle_error (g_app_info_get_name (appinfo),
				     screen, local_error, error);
}
Пример #11
0
/**
 * caja_launch_application_from_command:
 *
 * Fork off a process to launch an application with a given uri as
 * a parameter.
 *
 * @command_string: The application to be launched, with any desired
 * command-line options.
 * @...: Passed as parameters to the application after quoting each of them.
 */
void
caja_launch_application_from_command (GdkScreen  *screen,
                                      const char *name,
                                      const char *command_string,
                                      gboolean use_terminal,
                                      ...)
{
    char *full_command, *tmp;
    char *quoted_parameter;
    char *parameter;
    va_list ap;

    full_command = g_strdup (command_string);

    va_start (ap, use_terminal);

    while ((parameter = va_arg (ap, char *)) != NULL)
    {
        quoted_parameter = g_shell_quote (parameter);
        tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
        g_free (quoted_parameter);

        g_free (full_command);
        full_command = tmp;

    }

    va_end (ap);

    if (use_terminal)
    {
        eel_mate_open_terminal_on_screen (full_command, screen);
    }
    else
    {
        GdkAppLaunchContext *launch_context;
        GdkDisplay *display;
        GAppInfo *app_info = NULL;
        app_info = g_app_info_create_from_commandline (full_command,
                                                       NULL,
                                                       G_APP_INFO_CREATE_NONE,
                                                       NULL);
        if (app_info != NULL)
        {
            display = gdk_screen_get_display (screen);
            launch_context = gdk_display_get_app_launch_context (display);
            gdk_app_launch_context_set_screen (launch_context, screen);
            g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), NULL);
            g_object_unref (launch_context);
            g_object_unref (app_info);
        }
    }

    g_free (full_command);
}
static gboolean
photos_empty_results_box_activate_link (PhotosEmptyResultsBox *self, const gchar *uri)
{
  GAppInfo *app = NULL;
  GError *error;
  GdkAppLaunchContext *ctx = NULL;
  GdkDisplay *display;
  GdkScreen *screen;
  gboolean ret_val = FALSE;

  if (g_strcmp0 (uri, "system-settings") != 0)
    goto out;

  error = NULL;
  app = g_app_info_create_from_commandline ("gnome-control-center online-accounts",
                                            NULL,
                                            G_APP_INFO_CREATE_NONE,
                                            &error);
  if (error != NULL)
    {
      g_warning ("Unable to launch gnome-control-center: %s", error->message);
      g_error_free (error);
      goto out;
    }

  screen = gtk_widget_get_screen (GTK_WIDGET (self));
  if (screen != NULL)
    display = gdk_screen_get_display (screen);
  else
    display = gdk_display_get_default ();

  ctx = gdk_display_get_app_launch_context (display);
  if (screen != NULL)
    gdk_app_launch_context_set_screen (ctx, screen);

  error = NULL;
  g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
  if (error != NULL)
    {
      g_warning ("Unable to launch gnome-control-center: %s", error->message);
      g_error_free (error);
      goto out;
    }

  ret_val = TRUE;

 out:
  g_clear_object (&ctx);
  g_clear_object (&app);
  return ret_val;
}
Пример #13
0
static void dialog_cb(GtkAction* action, AccessxStatusApplet* sapplet)
{
    GError* error = NULL;
    GdkScreen *screen;
    GdkAppLaunchContext *launch_context;
    GAppInfo *appinfo;

    if (sapplet->error_type != ACCESSX_STATUS_ERROR_NONE)
    {
        popup_error_dialog(sapplet);
        return;
    }


    screen = gtk_widget_get_screen (GTK_WIDGET (sapplet->applet));
    appinfo = g_app_info_create_from_commandline ("mate-keyboard-properties --a11y",
              _("Open the keyboard preferences dialog"),
              G_APP_INFO_CREATE_NONE,
              &error);

    if (!error) {
#if GTK_CHECK_VERSION (3, 0, 0)
        launch_context = gdk_display_get_app_launch_context (
                             gtk_widget_get_display (GTK_WIDGET (screen)));
#else
        launch_context = gdk_app_launch_context_new ();
#endif
        gdk_app_launch_context_set_screen (launch_context, screen);
        g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);

        g_object_unref (launch_context);
    }

    if (error != NULL)
    {
        GtkWidget* dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("There was an error launching the keyboard preferences dialog: %s"), error->message);

        g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL);

        gtk_window_set_screen(GTK_WINDOW(dialog), screen);
        gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);

        gtk_widget_show(dialog);
        g_error_free(error);
    }

    g_object_unref (appinfo);
}
Пример #14
0
/**
 * mate_url_show_on_screen:
 * @url: The url to display. Should begin with the protocol to use (e.g.
 * "http:", "ghelp:", etc)
 * @screen: a #GdkScreen.
 * @error: Used to store any errors that result from trying to display the @url.
 *
 * Description: Like mate_url_show(), but ensures that the viewer application
 * appears on @screen.
 *
 * Returns: %TRUE if everything went fine, %FALSE otherwise (in which case
 * @error will contain the actual error).
 * 
 * Since: 2.6
 **/
gboolean
mate_url_show_on_screen (const char  *url,
			  GdkScreen   *screen,
			  GError     **error)
{
	gboolean   retval;
	GdkAppLaunchContext *context;

	context = gdk_app_launch_context_new ();
	gdk_app_launch_context_set_screen (context, screen);

	retval = g_app_info_launch_default_for_uri (url, context, error);

	g_object_unref (context);

	return retval;
}
Пример #15
0
static gboolean
ev_attachment_launch_app (EvAttachment *attachment,
			  GdkScreen    *screen,
			  guint32       timestamp,
			  GError      **error)
{
	gboolean           result;
	GList             *files = NULL;
	GdkAppLaunchContext *context;
	GdkDisplay          *display;
	GError            *ioerror = NULL;

	g_assert (G_IS_FILE (attachment->priv->tmp_file));
	g_assert (G_IS_APP_INFO (attachment->priv->app));

	files = g_list_prepend (files, attachment->priv->tmp_file);

	display = screen ? gdk_screen_get_display (screen) : gdk_display_get_default ();
	context = gdk_display_get_app_launch_context (display);
	gdk_app_launch_context_set_screen (context, screen);
	gdk_app_launch_context_set_timestamp (context, timestamp);

	result = g_app_info_launch (attachment->priv->app, files,
							    G_APP_LAUNCH_CONTEXT (context),
							    &ioerror);
	g_object_unref (context);

	if (!result) {
		g_set_error (error,
			     EV_ATTACHMENT_ERROR,
			     (gint) result,
			     _("Couldn't open attachment “%s”: %s"),
			     attachment->priv->name,
			     ioerror->message);

		g_list_free (files);
		g_error_free (ioerror);
		
		return FALSE;
	}

	g_list_free (files);
	
	return TRUE;
}
void
nemo_connect_server_dialog_display_location_async (NemoConnectServerDialog *self,
						       GFile *location,
						       GAsyncReadyCallback callback,
						       gpointer user_data)
{
	GError *error;
	GdkAppLaunchContext *launch_context;
	gchar *uri;

	display_location_res = g_simple_async_result_new (G_OBJECT (self),
							  callback, user_data,
							  nemo_connect_server_dialog_display_location_async);

	error = NULL;
	uri = g_file_get_uri (location);

	if (just_print_uri) {
		g_print ("%s\n", uri);
	}
	else {
		launch_context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (self)));
		gdk_app_launch_context_set_screen (launch_context,
						   gtk_widget_get_screen (GTK_WIDGET (self)));

		g_app_info_launch_default_for_uri (uri,
						   G_APP_LAUNCH_CONTEXT (launch_context),
						   &error);

		g_object_unref (launch_context);
	}

	if (error != NULL) {
		g_simple_async_result_set_from_error (display_location_res, error);
		g_error_free (error);
	}

	g_simple_async_result_complete_in_idle (display_location_res);

	g_free (uri);
	g_object_unref (display_location_res);
	display_location_res = NULL;
}
Пример #17
0
GAppLaunchContext *
giggle_create_app_launch_context (GtkWidget *widget)
{
#if GTK_CHECK_VERSION(2,14,0)
	GdkAppLaunchContext *context;
	GdkScreen           *screen = NULL;

	context = gdk_app_launch_context_new ();

	if (widget) {
		screen = gtk_widget_get_screen (widget);
		gdk_app_launch_context_set_screen (context, screen);
	}

	return G_APP_LAUNCH_CONTEXT (context);
#else
	return g_app_launch_context_new ();
#endif
}
Пример #18
0
gboolean
open_file_with_application (GtkWidget * window,
                            const gchar * file,
                            GAppInfo * app)
{
	GdkAppLaunchContext * context;
	GdkScreen * screen;
	gboolean result;

	if (g_file_test (file, G_FILE_TEST_IS_DIR) == TRUE) {
		return FALSE;
	}

	context = gdk_app_launch_context_new ();
	screen = gtk_widget_get_screen (window);
	gdk_app_launch_context_set_screen (context, screen);

	if (app == NULL) {
		gchar * uri;

		uri = g_filename_to_uri (file, NULL, NULL);
		result = g_app_info_launch_default_for_uri (uri, (GAppLaunchContext *) context, NULL);
		g_free (uri);
	}
	else {
		GList * g_file_list = NULL;
		GFile * g_file = NULL;

		g_file = g_file_new_for_path (file);

		if (g_file == NULL) {
			result = FALSE;
		}
		else {
			g_file_list = g_list_prepend (g_file_list, g_file);

			result = g_app_info_launch (app, g_file_list, (GAppLaunchContext *) context, NULL);
			g_list_free (g_file_list);
			g_object_unref (g_file);
		}
	}
	return result;
}
void
_not_eel_gnome_open_terminal_on_screen (const char *command,
					GdkScreen  *screen)
{
	char *command_line;
	GAppInfo *app;
	GdkAppLaunchContext *ctx;
	GError *error = NULL;
	GdkDisplay *display;

	if (screen == NULL) {
		screen = gdk_screen_get_default ();
	}
	
	command_line = _not_eel_gnome_make_terminal_command (command);
	if (command_line == NULL) {
		g_message ("Could not start a terminal");
		return;
	}

	app = g_app_info_create_from_commandline (command_line, NULL, 0, &error);

	if (app != NULL) {
		display = gdk_screen_get_display (screen);
		ctx = gdk_display_get_app_launch_context (display);
		gdk_app_launch_context_set_screen (ctx, screen);

		g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);

		g_object_unref (app);
		g_object_unref (ctx);	
	}

	if (error != NULL) {
		g_message ("Could not start application on terminal: %s", error->message);

		g_error_free (error);
	}

	g_free (command_line);
}
Пример #20
0
/* Connect Server
 */
static void
panel_action_connect_server (GtkWidget *widget)
{
	GdkScreen *screen;
	GAppInfo  *app_info;
	GError    *error;

	screen = gtk_widget_get_screen (GTK_WIDGET (widget));
	error = NULL;
	app_info = g_app_info_create_from_commandline ("nautilus-connect-server",
						       _("Connect to server"),
						       G_APP_INFO_CREATE_NONE,
						       &error);

	if (!error) {
		GdkAppLaunchContext *launch_context;
		GdkDisplay          *display;

		display = gdk_screen_get_display (screen);
		launch_context = gdk_display_get_app_launch_context (display);
		gdk_app_launch_context_set_screen (launch_context, screen);

		g_app_info_launch (app_info, NULL,
				   G_APP_LAUNCH_CONTEXT (launch_context),
				   &error);

		g_object_unref (launch_context);
		g_object_unref (app_info);
	}

	if (error) {
		panel_error_dialog (NULL, screen,
				    "cannot_connect_server",
				    TRUE,
				    _("Could not connect to server"),
				    error->message);
		g_clear_error (&error);
	}
}
Пример #21
0
GAppLaunchContext *
photos_utils_new_app_launch_context_from_widget (GtkWidget *widget)
{
  GAppLaunchContext *ret_val = NULL;
  g_autoptr (GdkAppLaunchContext) ctx = NULL;
  GdkDisplay *display = NULL;
  GdkScreen *screen = NULL;

  if (widget != NULL)
    {
      screen = gtk_widget_get_screen (widget);
      display = gdk_screen_get_display (screen);
    }

  if (display == NULL)
    display = gdk_display_get_default ();

  ctx = gdk_display_get_app_launch_context (display);
  if (screen != NULL)
    gdk_app_launch_context_set_screen (ctx, screen);

  ret_val = G_APP_LAUNCH_CONTEXT (g_steal_pointer (&ctx));
  return ret_val;
}
Пример #22
0
static void
run_cc_cb (G_GNUC_UNUSED GtkButton *button, GdauiLogin *login)
{
	gboolean sresult = FALSE;
	GError *lerror = NULL;
	gchar *cmd;

	/* run gda-control-center tool */
#ifdef G_OS_WIN32
#define EXENAME "gda-control-center-" GDA_ABI_VERSION ".exe"
	gchar *argv[] = {EXENAME, NULL};
	cmd = gda_gbr_get_file_path (GDA_BIN_DIR, NULL);
	sresult = g_spawn_async (cmd, argv, NULL, 0, NULL, NULL, NULL, &lerror);
	g_free (cmd);
#else
#define EXENAME "gda-control-center-" GDA_ABI_VERSION
	GAppInfo *appinfo;
	GdkAppLaunchContext *context;
	GdkScreen *screen;
	cmd = gda_gbr_get_file_path (GDA_BIN_DIR, (char *) EXENAME, NULL);
	appinfo = g_app_info_create_from_commandline (cmd,
						      NULL,
						      G_APP_INFO_CREATE_NONE,
						      &lerror);
	g_free (cmd);
	if (!appinfo)
		goto checkerror;

	screen = gtk_widget_get_screen (GTK_WIDGET (login));
	context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
	gdk_app_launch_context_set_screen (context, screen);
	sresult = g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), NULL);
	if (! sresult) {
		g_object_unref (appinfo);
		appinfo = g_app_info_create_from_commandline (EXENAME,
							      NULL,
							      G_APP_INFO_CREATE_NONE,
							      NULL);
		if (!appinfo) {
			g_object_unref (context);
			goto checkerror;
		}
		sresult = g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), &lerror);
	}
	g_object_unref (context);
	g_object_unref (appinfo);
#endif /* G_OS_WIN32 */

 checkerror:
	if (!sresult) {
		GtkWidget *msgdialog;
		GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (login));
		if (!gtk_widget_is_toplevel (toplevel))
			toplevel = NULL;
		msgdialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (toplevel), GTK_DIALOG_MODAL,
								GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
								"<b>%s:</b>\n%s",
								_("Could not execute the Database access control center"),
								lerror && lerror->message ? lerror->message : _("No detail"));

		if (lerror)
			g_error_free (lerror);
		gtk_dialog_run (GTK_DIALOG (msgdialog));
		gtk_widget_destroy (msgdialog);
	}
}
Пример #23
0
static void
start_procman (MultiloadApplet *ma)
{
	GError *error = NULL;
	GDesktopAppInfo *appinfo;
	gchar *monitor;
	GdkAppLaunchContext *launch_context;
	GdkDisplay *display;
	GAppInfo *app_info;
	GdkScreen *screen;

	g_return_if_fail (ma != NULL);

	monitor = g_settings_get_string (ma->settings, "system-monitor");
	if (monitor == NULL)
	        monitor = g_strdup ("mate-system-monitor.desktop");

	screen = gtk_widget_get_screen (GTK_WIDGET (ma->applet));
	appinfo = g_desktop_app_info_new (monitor);
	if (appinfo) {
		GdkScreen *screen;
		GdkAppLaunchContext *context;
		screen = gtk_widget_get_screen (GTK_WIDGET (ma->applet));
		display = gdk_screen_get_display (screen);
		context = gdk_display_get_app_launch_context (display);
		gdk_app_launch_context_set_screen (context, screen);
		g_app_info_launch (G_APP_INFO (appinfo), NULL, G_APP_LAUNCH_CONTEXT (context), &error);
		g_object_unref (context);
		g_object_unref (appinfo);
	}
	else {
		app_info = g_app_info_create_from_commandline ("mate-system-monitor",
							      _("Start system-monitor"),
							      G_APP_INFO_CREATE_NONE,
							      &error);

		if (!error) {
			display = gdk_screen_get_display (screen);
			launch_context = gdk_display_get_app_launch_context (display);
			gdk_app_launch_context_set_screen (launch_context, screen);
			g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);

			g_object_unref (launch_context);
		}
	}
	g_free (monitor);

	if (error) {
		GtkWidget *dialog;

		dialog = gtk_message_dialog_new (NULL,
						 GTK_DIALOG_DESTROY_WITH_PARENT,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_OK,
						 _("There was an error executing '%s': %s"),
						 "mate-system-monitor",
						 error->message);

		g_signal_connect (dialog, "response",
				  G_CALLBACK (gtk_widget_destroy),
				  NULL);

		gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
		gtk_window_set_screen (GTK_WINDOW (dialog),
				       gtk_widget_get_screen (GTK_WIDGET (ma->applet)));

		gtk_widget_show (dialog);

		g_error_free (error);
	}
}
Пример #24
0
static gboolean
totem_disc_recorder_plugin_start_burning (TotemDiscRecorderPlugin *pi,
					  const char *path,
					  gboolean copy)
{
	GtkWindow *main_window;
	GdkScreen *screen;
	GdkDisplay *display;
	gchar *command_line;
	GList *uris;
	GAppInfo *info;
	GdkAppLaunchContext *context;
	GError *error = NULL;
	char *xid_arg;

	main_window = totem_object_get_main_window (pi->priv->totem);
	screen = gtk_widget_get_screen (GTK_WIDGET (main_window));
	display = gdk_display_get_default ();

	/* Build a command line to use */
	xid_arg = NULL;
#ifdef GDK_WINDOWING_X11
	if (GDK_IS_X11_DISPLAY (display))
		xid_arg = g_strdup_printf ("-x %d", (int) gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (main_window))));
#endif /* GDK_WINDOWING_X11 */
	g_object_unref (main_window);

	if (copy != FALSE)
		command_line = g_strdup_printf ("brasero %s -c", xid_arg ? xid_arg : "");
	else
		command_line = g_strdup_printf ("brasero %s -r", xid_arg ? xid_arg : "");

	/* Build the app info */
	info = g_app_info_create_from_commandline (command_line, NULL,
	                                           G_APP_INFO_CREATE_SUPPORTS_URIS | G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION, &error);
	g_free (command_line);

	if (error != NULL)
		goto error;

	/* Create a launch context and launch it */
	context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (main_window)));
	gdk_app_launch_context_set_screen (context, screen);

	uris = g_list_prepend (NULL, (gpointer) path);
	g_app_info_launch_uris (info, uris, G_APP_LAUNCH_CONTEXT (context), &error);
	g_list_free (uris);

	g_object_unref (info);
	g_object_unref (context);

	if (error != NULL)
		goto error;

	return TRUE;

error:
	main_window = totem_object_get_main_window (pi->priv->totem);

	if (copy != FALSE)
		totem_interface_error (_("The video disc could not be duplicated."), error->message, main_window);
	else
		totem_interface_error (_("The movie could not be recorded."), error->message, main_window);

	g_error_free (error);
	g_object_unref (main_window);

	return FALSE;
}
void
caja_launch_desktop_file (GdkScreen   *screen,
                          const char  *desktop_file_uri,
                          const GList *parameter_uris,
                          GtkWindow   *parent_window)
{
    GError *error;
    char *message, *desktop_file_path;
    const GList *p;
    GList *files;
    int total, count;
    GFile *file, *desktop_file;
    GDesktopAppInfo *app_info;
    GdkAppLaunchContext *context;

    /* Don't allow command execution from remote locations
     * to partially mitigate the security
     * risk of executing arbitrary commands.
     */
    desktop_file = g_file_new_for_uri (desktop_file_uri);
    desktop_file_path = g_file_get_path (desktop_file);
    if (!g_file_is_native (desktop_file))
    {
        g_free (desktop_file_path);
        g_object_unref (desktop_file);
        eel_show_error_dialog
        (_("Sorry, but you cannot execute commands from "
           "a remote site."),
         _("This is disabled due to security considerations."),
         parent_window);

        return;
    }
    g_object_unref (desktop_file);

    app_info = g_desktop_app_info_new_from_filename (desktop_file_path);
    g_free (desktop_file_path);
    if (app_info == NULL)
    {
        eel_show_error_dialog
        (_("There was an error launching the application."),
         NULL,
         parent_window);
        return;
    }

    /* count the number of uris with local paths */
    count = 0;
    total = g_list_length ((GList *) parameter_uris);
    files = NULL;
    for (p = parameter_uris; p != NULL; p = p->next)
    {
        file = g_file_new_for_uri ((const char *) p->data);
        if (g_file_is_native (file))
        {
            count++;
        }
        files = g_list_prepend (files, file);
    }

    /* check if this app only supports local files */
    if (g_app_info_supports_files (G_APP_INFO (app_info)) &&
            !g_app_info_supports_uris (G_APP_INFO (app_info)) &&
            parameter_uris != NULL)
    {
        if (count == 0)
        {
            /* all files are non-local */
            eel_show_error_dialog
            (_("This drop target only supports local files."),
             _("To open non-local files copy them to a local folder and then"
               " drop them again."),
             parent_window);

            g_list_free_full (files, g_object_unref);
            g_object_unref (app_info);
            return;
        }
        else if (count != total)
        {
            /* some files are non-local */
            eel_show_warning_dialog
            (_("This drop target only supports local files."),
             _("To open non-local files copy them to a local folder and then"
               " drop them again. The local files you dropped have already been opened."),
             parent_window);
        }
    }

    error = NULL;
    context = gdk_app_launch_context_new ();
    /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */
    gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME);
    gdk_app_launch_context_set_screen (context,
                                       gtk_window_get_screen (parent_window));
    if (count == total)
    {
        /* All files are local, so we can use g_app_info_launch () with
         * the file list we constructed before.
         */
        g_app_info_launch (G_APP_INFO (app_info),
                           files,
                           G_APP_LAUNCH_CONTEXT (context),
                           &error);
    }
    else
    {
        /* Some files are non local, better use g_app_info_launch_uris ().
         */
        g_app_info_launch_uris (G_APP_INFO (app_info),
                                (GList *) parameter_uris,
                                G_APP_LAUNCH_CONTEXT (context),
                                &error);
    }
    if (error != NULL)
    {
        message = g_strconcat (_("Details: "), error->message, NULL);
        eel_show_error_dialog
        (_("There was an error launching the application."),
         message,
         parent_window);

        g_error_free (error);
        g_free (message);
    }

    g_list_free_full (files, g_object_unref);
    g_object_unref (context);
    g_object_unref (app_info);
}
void
caja_launch_application_by_uri (GAppInfo *application,
                                GList *uris,
                                GtkWindow *parent_window)
{
    char            *uri, *uri_scheme;
    GList           *locations, *l;
    GFile *location;
    CajaFile    *file;
    gboolean        result;
    GError *error;
    GdkAppLaunchContext *launch_context;
    CajaIconInfo *icon;
    int count, total;

    g_assert (uris != NULL);

    /* count the number of uris with local paths */
    count = 0;
    total = g_list_length (uris);
    locations = NULL;
    for (l = uris; l != NULL; l = l->next)
    {
        uri = l->data;

        location = g_file_new_for_uri (uri);
        if (g_file_is_native (location))
        {
            count++;
        }
        locations = g_list_prepend (locations, location);
    }
    locations = g_list_reverse (locations);

    launch_context = gdk_app_launch_context_new ();
    if (parent_window)
        gdk_app_launch_context_set_screen (launch_context,
                                           gtk_window_get_screen (parent_window));

    file = caja_file_get_by_uri (uris->data);
    icon = caja_file_get_icon (file, 48, 0);
    caja_file_unref (file);
    if (icon)
    {
        gdk_app_launch_context_set_icon_name (launch_context,
                                              caja_icon_info_get_used_name (icon));
        g_object_unref (icon);
    }

    error = NULL;

    if (count == total)
    {
        /* All files are local, so we can use g_app_info_launch () with
         * the file list we constructed before.
         */
        result = g_app_info_launch (application,
                                    locations,
                                    G_APP_LAUNCH_CONTEXT (launch_context),
                                    &error);
    }
    else
    {
        /* Some files are non local, better use g_app_info_launch_uris ().
         */
        result = g_app_info_launch_uris (application,
                                         uris,
                                         G_APP_LAUNCH_CONTEXT (launch_context),
                                         &error);
    }

    g_object_unref (launch_context);

    if (!result)
    {
        if (error->domain == G_IO_ERROR &&
                error->code == G_IO_ERROR_NOT_SUPPORTED)
        {
            uri_scheme = g_uri_parse_scheme (uris->data);
            application_cannot_open_location (application,
                                              file,
                                              uri_scheme,
                                              parent_window);
            g_free (uri_scheme);
        }
        else
        {
#ifdef NEW_MIME_COMPLETE
            caja_program_chooser_show_invalid_message
            (MATE_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window);
#else
            g_warning ("Cannot open app: %s\n", error->message);
#endif
        }
        g_error_free (error);
    }
    else
    {
        for (l = uris; l != NULL; l = l->next)
        {
            file = caja_file_get_by_uri (l->data);
            caja_recent_add_file (file, application);
            caja_file_unref (file);
        }
    }

    g_list_free_full (locations, g_object_unref);
}
Пример #27
0
void
nemo_launch_application_by_uri (GAppInfo *application, 
				    GList *uris,
				    GtkWindow *parent_window)
{
	char *uri;
	GList *locations, *l;
	GFile *location;
	NemoFile *file;
	gboolean result;
	GError *error;
	GdkDisplay *display;
	GdkAppLaunchContext *launch_context;
	NemoIconInfo *icon;
	int count, total;

	g_assert (uris != NULL);

	/* count the number of uris with local paths */
	count = 0;
	total = g_list_length (uris);
	locations = NULL;
	for (l = uris; l != NULL; l = l->next) {
		uri = l->data;
		
		location = g_file_new_for_uri (uri);
		if (g_file_is_native (location)) {
			count++;
		}
		locations = g_list_prepend (locations, location);
	}
	locations = g_list_reverse (locations);

	if (parent_window != NULL) {
		display = gtk_widget_get_display (GTK_WIDGET (parent_window));
	} else {
		display = gdk_display_get_default ();
	}

	launch_context = gdk_display_get_app_launch_context (display);

	if (parent_window != NULL) {
		gdk_app_launch_context_set_screen (launch_context,
						   gtk_window_get_screen (parent_window));
	}

	file = nemo_file_get_by_uri (uris->data);
	icon = nemo_file_get_icon (file,
                               48,
                               gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)),
                               0);
	nemo_file_unref (file);
	if (icon) {
		gdk_app_launch_context_set_icon_name (launch_context,
							nemo_icon_info_get_used_name (icon));
		g_object_unref (icon);
	}
	
	error = NULL;

	if (count == total) {
		/* All files are local, so we can use g_app_info_launch () with
		 * the file list we constructed before.
		 */
		result = g_app_info_launch (application,
					    locations,
					    G_APP_LAUNCH_CONTEXT (launch_context),
					    &error);
	} else {
		/* Some files are non local, better use g_app_info_launch_uris ().
		 */
		result = g_app_info_launch_uris (application,
						 uris,
						 G_APP_LAUNCH_CONTEXT (launch_context),
						 &error);
	}

	g_object_unref (launch_context);

	if (result) {
		for (l = uris; l != NULL; l = l->next) {
			file = nemo_file_get_by_uri (l->data);
			nemo_recent_add_file (file, application);
			nemo_file_unref (file);
		}
	}

	g_list_free_full (locations, g_object_unref);
}
Пример #28
0
gboolean
open_file_with_filemanager (GtkWidget * window,
                            const gchar * file)
{
	GDesktopAppInfo * d_app_info;
	GKeyFile * key_file;
	GdkAppLaunchContext * ctx = NULL;
	GList * list = NULL;
	GAppInfo * g_app_info;
	GFile * g_file;
	gchar * command;
	gchar * contents;
	gchar * uri;
	gboolean result = TRUE;

	uri = g_filename_to_uri (file, NULL, NULL);
	list = g_list_prepend (list, uri);

	g_file = g_file_new_for_path (file);
	g_app_info = g_file_query_default_handler (g_file, NULL, NULL);

	if (strcmp (g_app_info_get_executable (g_app_info), "nautilus") == 0) {
		command = g_strconcat ("nautilus ",
		                       "--sm-disable ",
		                       "--no-desktop ",
		                       "--no-default-window ",
		                       NULL);
	}
	else {
		command = g_strconcat (g_app_info_get_executable (g_app_info),
		                       " ", NULL);
	}

	contents = g_strdup_printf ("[Desktop Entry]\n"
				    "Name=Nautilus\n"
				    "Icon=file-manager\n"
				    "Exec=%s\n"
				    "Terminal=false\n"
				    "StartupNotify=true\n"
				    "Type=Application\n",
				    command);
	key_file = g_key_file_new ();
	g_key_file_load_from_data (key_file, contents, strlen(contents), G_KEY_FILE_NONE, NULL);
	d_app_info = g_desktop_app_info_new_from_keyfile (key_file);
	
	if (d_app_info != NULL) {
		ctx = gdk_app_launch_context_new ();
		gdk_app_launch_context_set_screen (ctx, gtk_widget_get_screen (window));

		result = g_app_info_launch_uris (G_APP_INFO (d_app_info), list,  G_APP_LAUNCH_CONTEXT (ctx), NULL);
	}
	else {
		result = FALSE;
	}

	g_object_unref (g_app_info);
	g_object_unref (d_app_info);
	g_object_unref (g_file);
	g_object_unref (ctx);
	g_key_file_free (key_file);
	g_list_free (list);
	g_free (contents);
	g_free (command);
	g_free (uri);

	return result;
}
Пример #29
0
static void
action_caja_manual_callback (GtkAction *action,
                             gpointer user_data)
{
    CajaWindow *window;
    GError *error;
    GtkWidget *dialog;

    error = NULL;
    window = CAJA_WINDOW (user_data);

    if (CAJA_IS_DESKTOP_WINDOW (window))
    {
#if GTK_CHECK_VERSION (3, 0, 0)
        GdkScreen *screen;
        GdkAppLaunchContext *launch_context;
        GAppInfo *app_info = NULL;
        app_info = g_app_info_create_from_commandline ("mate-help",
                                                       NULL,
                                                       G_APP_INFO_CREATE_NONE,
                                                       &error);
        if (error == NULL)
        {
            screen = gtk_window_get_screen(GTK_WINDOW(window));
            launch_context = gdk_app_launch_context_new ();
            gdk_app_launch_context_set_screen (launch_context, screen);
            g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);
            g_object_unref (launch_context);
        }
        if (app_info != NULL)
            g_object_unref (app_info);
#else
#if GTK_CHECK_VERSION (2, 24, 0)
        gdk_spawn_command_line_on_screen(gtk_window_get_screen(GTK_WINDOW(window)), "mate-help", &error);
#else
        g_spawn_command_line_async("mate-help", &error);
#endif
#endif
    }
    else
    {
        gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (window)),
                      "help:mate-user-guide/goscaja-1",
                      gtk_get_current_event_time (), &error);
    }

    if (error)
    {
        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                         GTK_DIALOG_MODAL,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_OK,
                                         _("There was an error displaying help: \n%s"),
                                         error->message);
        g_signal_connect (G_OBJECT (dialog), "response",
                          G_CALLBACK (gtk_widget_destroy),
                          NULL);

        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
        gtk_widget_show (dialog);
        g_error_free (error);
    }
}
Пример #30
0
static void
ev_spawn (const char     *uri,
	  GdkScreen      *screen,
	  EvLinkDest     *dest,
	  EvWindowRunMode mode,
	  const gchar    *search_string,
	  guint           timestamp)
{
	GString *cmd;
	gchar *path, *cmdline;
	GAppInfo *app;
	GdkAppLaunchContext *ctx;
	GError  *error = NULL;

	cmd = g_string_new (NULL);

#ifdef G_OS_WIN32
{
	gchar *dir;

	dir = g_win32_get_package_installation_directory_of_module (NULL);
	path = g_build_filename (dir, "bin", "atril", NULL);
	g_free (dir);
}
#else
	path = g_build_filename (BINDIR, "atril", NULL);
#endif

	g_string_append_printf (cmd, " %s", path);
	g_free (path);

	/* Page label */
	if (dest) {
		const gchar *page_label;

		page_label = ev_link_dest_get_page_label (dest);
		if (page_label)
			g_string_append_printf (cmd, " --page-label=%s", page_label);
		else
			g_string_append_printf (cmd, " --page-label=%d", ev_link_dest_get_page (dest));
	}

	/* Find string */
	if (search_string) {
		g_string_append_printf (cmd, " --find=%s", search_string);
	}

	/* Mode */
	switch (mode) {
	case EV_WINDOW_MODE_FULLSCREEN:
		g_string_append (cmd, " -f");
		break;
	case EV_WINDOW_MODE_PRESENTATION:
		g_string_append (cmd, " -s");
		break;
	default:
		break;
	}

	cmdline = g_string_free (cmd, FALSE);
	app = g_app_info_create_from_commandline (cmdline, NULL, 0, &error);

	if (app != NULL) {
		GList uri_list;
		GList *uris = NULL;

#if GTK_CHECK_VERSION (3, 0, 0)
		ctx = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
#else
		ctx = gdk_app_launch_context_new ();
		gdk_app_launch_context_set_display (ctx, gdk_screen_get_display (screen));
#endif
		gdk_app_launch_context_set_screen (ctx, screen);
		gdk_app_launch_context_set_timestamp (ctx, timestamp);

		if (uri) {
			uri_list.data = (gchar *)uri;
			uri_list.prev = uri_list.next = NULL;
			uris = &uri_list;
		}
		g_app_info_launch_uris (app, uris, G_APP_LAUNCH_CONTEXT (ctx), &error);

		g_object_unref (app);
		g_object_unref (ctx);
	}
	if (error != NULL) {
		g_warning ("Error launching atril %s: %s\n", uri, error->message);
		g_error_free (error);
	}

	g_free (cmdline);
}