Ejemplo n.º 1
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);
		}
	}
}					  
static void
custom_entry_changed_cb (GtkEditable *entry, gpointer user_data)
{
    NemoMimeApplicationChooser *chooser = user_data;

    const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (entry));

    if (g_strcmp0 (entry_text, "") != 0) {
        GAppInfo *default_app;
        gchar *cl = g_strdup_printf ("%s", entry_text);
        GAppInfo *info = g_app_info_create_from_commandline (cl, NULL, G_APP_INFO_CREATE_NONE, NULL);

        default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
        gtk_widget_set_sensitive (chooser->details->set_as_default_button,
                                  !g_app_info_equal (info, default_app));

        gtk_widget_set_sensitive (chooser->details->add_button,
                                  app_info_can_add (info, chooser->details->content_type));

        g_object_unref (default_app);
        if (chooser->details->custom_info != NULL) {
            g_object_unref (chooser->details->custom_info);
            chooser->details->custom_info = NULL;
        }
        chooser->details->custom_info = info;

    } else {
        if (chooser->details->custom_info != NULL) {
            g_object_unref (chooser->details->custom_info);
            chooser->details->custom_info = NULL;
        }
        gtk_widget_set_sensitive (chooser->details->set_as_default_button, FALSE);
        gtk_widget_set_sensitive (chooser->details->add_button, FALSE);
    }
}
Ejemplo n.º 3
0
GAppInfo *gen_app_info (const char* executable, GAppInfoCreateFlags flags)
{
    GAppInfo *appinfo = NULL;
    GError* error = NULL;
    char* cmd_line = NULL;

    if (executable == NULL)
    {
        char* tmp1 = g_shell_quote(DESKTOP_DIR());
        char* tmp2 = g_strdup_printf("cd %s && exec $SHELL", tmp1);
        g_free(tmp1);
        tmp1 = g_shell_quote(tmp2);
        g_free(tmp2);

        cmd_line = g_strconcat("sh -c ", tmp1, NULL);
        g_free(tmp1);
    }
    else
    {
        cmd_line = g_strdup(executable);
    }

    appinfo = g_app_info_create_from_commandline(cmd_line, NULL,
            flags, &error);
    g_free(cmd_line);
    if (error!=NULL)
    {
        g_debug("gen_app_info error: %s", error->message);
        g_error_free(error);
        return NULL;
    }
    error = NULL;

    return appinfo;
}
static void
popup_menu_launch_capplet ()
{
	GAppInfo *info;
	GdkAppLaunchContext *ctx;
	GError *error = NULL;

	info =
	    g_app_info_create_from_commandline
	    ("sagarmatha-settings region", NULL, 0, &error);

	if (info != NULL) {
		ctx =
		    gdk_display_get_app_launch_context
		    (gdk_display_get_default ());

		if (g_app_info_launch (info, NULL,
				   G_APP_LAUNCH_CONTEXT (ctx), &error) == FALSE) {
			g_warning
				("Could not execute keyboard properties capplet: [%s]\n",
				 error->message);
			g_error_free (error);
		}

		g_object_unref (info);
		g_object_unref (ctx);
	}

}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
void invoke(const gchar *cmd, const gchar *desktop, gboolean with_pkexec)
{
   GdkAppLaunchContext *context;
   GAppInfo *appinfo;
   GError *error = NULL;
   static GtkWidget *w = NULL;

   // pkexec
   if(with_pkexec || FORCE_PKEXEC) {
      invoke_with_pkexec(cmd);
      return;
   }

   // fake window to get the current server time *urgh*
   if (!w) {
      w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_realize (w);
   }

   // normal launch
   context = gdk_display_get_app_launch_context (gdk_display_get_default ());
   guint32 timestamp =  gdk_x11_get_server_time (gtk_widget_get_window (w));
   appinfo = g_app_info_create_from_commandline(cmd, 
						cmd, 
						G_APP_INFO_CREATE_NONE,
						&error);
   gdk_app_launch_context_set_timestamp (context, timestamp);
   if (!g_app_info_launch (appinfo, NULL, (GAppLaunchContext*)context, &error))
      g_warning ("Launching failed: %s", error->message);
   g_object_unref (context);
   g_object_unref (appinfo);

}
Ejemplo n.º 7
0
gboolean
gs_plugin_launch (GsPlugin *plugin,
		  GsApp *app,
		  GCancellable *cancellable,
		  GError **error)
{
	const gchar *launch_name;
	g_autofree gchar *binary_name = NULL;
	GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
	g_autoptr(GAppInfo) info = NULL;

	/* We can only launch apps we know of */
	if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0)
		return TRUE;

	launch_name = gs_app_get_metadata_item (app, "snap::launch-name");
	if (!launch_name)
		return TRUE;

	if (g_strcmp0 (launch_name, gs_app_get_id (app)) == 0)
		binary_name = g_strdup_printf ("/snap/bin/%s", launch_name);
	else
		binary_name = g_strdup_printf ("/snap/bin/%s.%s", gs_app_get_id (app), launch_name);

	if (!is_graphical (app, cancellable))
		flags |= G_APP_INFO_CREATE_NEEDS_TERMINAL;
	info = g_app_info_create_from_commandline (binary_name, NULL, flags, error);
	if (info == NULL)
		return FALSE;

	return g_app_info_launch (info, NULL, NULL, error);
}
Ejemplo n.º 8
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);
	}
}
Ejemplo n.º 10
0
static void launch_cmd(const char *cmd, const char *appname)
{
    GAppInfo *appinfo = NULL;
    gboolean ret = FALSE;

    appinfo = g_app_info_create_from_commandline(cmd, NULL,
                G_APP_INFO_CREATE_NONE, NULL);

    if (appname) {
        kdesk_hourglass_start((char *) appname);
    }

    if (appinfo == NULL) {
        perror("Command lanuch failed.");
        if (appname) {
            kdesk_hourglass_end();
        }
        return;
    }

    ret = g_app_info_launch(appinfo, NULL, NULL, NULL);
    if (!ret) {
        perror("Command lanuch failed.");
        if (appname) {
            kdesk_hourglass_end();
        }
    }
}
Ejemplo n.º 11
0
static void launcher_activated(GtkWidget *widget, gchar *command) {
    GError *error = NULL;
    GAppInfo *app = g_app_info_create_from_commandline(command, NULL, 0, &error);

    if (!g_app_info_launch(app, NULL, NULL, &error)) {
        exit(1);
    }
}
Ejemplo n.º 12
0
static void
on_examine_action_clicked (NotifyNotification  *notification,
                           const gchar         *action,
                           gpointer             user_data)
{
  GduSdMonitor *monitor = GDU_SD_MONITOR (user_data);
  const gchar *device_file = NULL;
  gchar *command_line = NULL;
  GAppInfo *app_info = NULL;
  GError *error = NULL;

  if (g_strcmp0 (action, "examine-smart") == 0)
    {
      if (monitor->ata_smart_problems != NULL)
        {
          UDisksObject *object = UDISKS_OBJECT (monitor->ata_smart_problems->data);
          if (object != NULL)
            {
              UDisksDrive *drive = udisks_object_peek_drive (object);
              if (drive != NULL)
                {
                  UDisksBlock *block = udisks_client_get_block_for_drive (monitor->client,
                                                                          drive,
                                                                          TRUE); /* get_physical */
                  if (block != NULL)
                    {
                      device_file = udisks_block_get_device (block);
                      g_object_ref (block);
                    }
                }
            }
        }
    }
  else
    {
      g_assert_not_reached ();
    }

  if (device_file != NULL)
    command_line = g_strdup_printf ("gnome-disks --block-device %s", device_file);
  else
    command_line = g_strdup_printf ("gnome-disks");


  app_info = g_app_info_create_from_commandline (command_line,
                                                 NULL, /* application name */
                                                 G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
                                                 NULL);
  if (!g_app_info_launch (app_info, NULL, NULL, &error))
    {
      g_warning ("Error launching gnome-disks: %s (%s, %d)",
                 error->message, g_quark_to_string (error->domain), error->code);
      g_clear_error (&error);
    }
  g_clear_object (&app_info);
  g_free (command_line);
}
Ejemplo n.º 13
0
gboolean
ol_launch_app (const char *cmdline)
{
  ol_assert_ret (cmdline != NULL, FALSE);
  GAppInfo* app = g_app_info_create_from_commandline (cmdline, "", 0, NULL);
  gboolean ret = g_app_info_launch (app, NULL, NULL, NULL);
  g_object_unref (G_OBJECT (app));
  return ret;
}
Ejemplo n.º 14
0
/**
 * fm_app_info_create_from_commandline
 * @commandline: the commandline to use
 * @application_name: (allow-none): the application name, or %NULL to use @commandline
 * @flags: flags that can specify details of the created #GAppInfo
 * @error: (out) (allow-none): location to store error
 *
 * Creates a new #GAppInfo from the given information.
 *
 * Note that for @commandline, the quoting rules of the Exec key of the
 * <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">freedesktop.org Desktop
 * Entry Specification</ulink> are applied. For example, if the @commandline contains
 * percent-encoded URIs, the percent-character must be doubled in order to prevent it from
 * being swallowed by Exec key unquoting. See the specification for exact quoting rules.
 *
 * Returns: (transfer full): new #GAppInfo for given command.
 *
 * Since: 0.1.15
 */
GAppInfo* fm_app_info_create_from_commandline(const char *commandline,
                                              const char *application_name,
                                              GAppInfoCreateFlags flags,
                                              GError **error)
{
    GAppInfo* app = g_app_info_create_from_commandline(commandline, application_name, flags, error);
    g_object_set_data(G_OBJECT(app), "flags", GUINT_TO_POINTER(flags));
    return app;
}
Ejemplo n.º 15
0
Archivo: main.c Proyecto: haobug/evince
static gboolean
launch_previewer (void)
{
	GString *cmd_str;
	gchar   *cmd;
	gboolean retval = FALSE;
	GError  *error = NULL;

	/* Rebuild the command line, ignoring options
	 * not supported by the previewer and taking only
	 * the first path given
	 */
	cmd_str = g_string_new ("evince-previewer");
		
	if (print_settings) {
		gchar *quoted;

		quoted = g_shell_quote (print_settings);
		g_string_append_printf (cmd_str, " --print-settings %s", quoted);
		g_free (quoted);
	}

	if (unlink_temp_file)
		g_string_append (cmd_str, " --unlink-tempfile");

	if (file_arguments) {
		gchar *quoted;
		
		quoted = g_shell_quote (file_arguments[0]);
		g_string_append_printf (cmd_str, " %s", quoted);
		g_free (quoted);
	}

	cmd = g_string_free (cmd_str, FALSE);

	if (!error) {
		GAppInfo *app;

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

		if (app != NULL) {
			retval = g_app_info_launch (app, NULL, NULL, &error);
			g_object_unref (app);
		}
	}

	if (error) {
		g_warning ("Error launching previewer: %s\n", error->message);
		g_error_free (error);
	}

	g_free (cmd);

	return retval;
}
Ejemplo n.º 16
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);
}
Ejemplo n.º 17
0
static gboolean
_app_info_launch_uris (GAppInfo *appinfo,
                       GList *uris,
                       GAppLaunchContext *launch_context,
                       GError **error)
{
  OlAppInfo *info = OL_APP_INFO (appinfo);
  /* TODO: implement launching. */
  GAppInfo* app = g_app_info_create_from_commandline (info->cmdline, "", 0, NULL);
  gboolean ret = g_app_info_launch_uris (app, uris, launch_context, error);
  g_object_unref (G_OBJECT (app));
  return ret;
}
Ejemplo n.º 18
0
gboolean
empathy_launch_external_app (const gchar *desktop_file,
    const gchar *args,
    GError **error)
{
  GDesktopAppInfo *desktop_info;
  gboolean result;
  GError *err = NULL;

  desktop_info = g_desktop_app_info_new (desktop_file);
  if (desktop_info == NULL)
    {
      DEBUG ("%s not found", desktop_file);

      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
          "%s not found", desktop_file);
      return FALSE;
    }

  if (args == NULL)
    {
      result = launch_app_info (G_APP_INFO (desktop_info), error);
    }
  else
    {
      gchar *cmd;
      GAppInfo *app_info;

      /* glib doesn't have API to start a desktop file with args... (#637875) */
      cmd = g_strdup_printf ("%s %s", g_app_info_get_commandline (
            (GAppInfo *) desktop_info), args);

      app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &err);
      if (app_info == NULL)
        {
          DEBUG ("Failed to launch '%s': %s", cmd, err->message);
          g_free (cmd);
          g_object_unref (desktop_info);
          g_propagate_error (error, err);
          return FALSE;
        }

      result = launch_app_info (app_info, error);

      g_object_unref (app_info);
      g_free (cmd);
    }

  g_object_unref (desktop_info);
  return result;
}
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;
}
Ejemplo n.º 20
0
void
empathy_launch_program (const gchar *dir,
    const gchar *name,
    const gchar *args)
{
  GdkDisplay *display;
  GError *error = NULL;
  gchar *path, *cmd;
  GAppInfo *app_info;
  GdkAppLaunchContext *context = NULL;

  /* Try to run from source directory if possible */
  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
      name, NULL);

  if (!g_file_test (path, G_FILE_TEST_EXISTS))
    {
      g_free (path);
      path = g_build_filename (dir, name, NULL);
    }

  if (args != NULL)
    cmd = g_strconcat (path, " ", args, NULL);
  else
    cmd = g_strdup (path);

  app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
  if (app_info == NULL)
    {
      DEBUG ("Failed to create app info: %s", error->message);
      g_error_free (error);
      goto out;
    }

  display = gdk_display_get_default ();
  context = gdk_display_get_app_launch_context (display);

  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
      &error))
    {
      g_warning ("Failed to launch %s: %s", name, error->message);
      g_error_free (error);
      goto out;
    }

out:
  tp_clear_object (&app_info);
  tp_clear_object (&context);
  g_free (path);
  g_free (cmd);
}
Ejemplo n.º 21
0
/**
 * Create or find already existing application info for specified command
 * and application name.
 * @param cmd command to execute
 * @param appName application name
 * @param appInfo location where created GAppInfo is stored
 * @return NS_OK when object is created, NS_ERROR_FAILURE otherwise.
 */
NS_IMETHODIMP
nsGIOService::CreateAppFromCommand(nsACString const& cmd,
                                   nsACString const& appName,
                                   nsIGIOMimeApp**   appInfo)
{
  GError *error = NULL;
  *appInfo = nsnull;

  GAppInfo *app_info = NULL, *app_info_from_list = NULL;
  GList *apps = g_app_info_get_all();
  GList *apps_p = apps;

  // Try to find relevant and existing GAppInfo in all installed application
  // We do this by comparing each GAppInfo's executable with out own
  while (apps_p) {
    app_info_from_list = (GAppInfo*) apps_p->data;
    if (!app_info) {
      // If the executable is not absolute, get it's full path
      char *executable = g_find_program_in_path(g_app_info_get_executable(app_info_from_list));

      if (executable && strcmp(executable, PromiseFlatCString(cmd).get()) == 0) {
        g_object_ref (app_info_from_list);
        app_info = app_info_from_list;
      }
      g_free(executable);
    }

    g_object_unref(app_info_from_list);
    apps_p = apps_p->next;
  }
  g_list_free(apps);

  if (!app_info) {
    app_info = g_app_info_create_from_commandline(PromiseFlatCString(cmd).get(),
                                                  PromiseFlatCString(appName).get(),
                                                  G_APP_INFO_CREATE_SUPPORTS_URIS,
                                                  &error);
  }

  if (!app_info) {
    g_warning("Cannot create application info from command: %s", error->message);
    g_error_free(error);
    return NS_ERROR_FAILURE;
  }
  nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
  NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
  NS_ADDREF(*appInfo = mozApp);
  return NS_OK;
}
Ejemplo n.º 22
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);
}
Ejemplo n.º 23
0
static VALUE
appinfo_create_from_commandline(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
{
        VALUE commandline, application_name, flags;
        GError *error = NULL;
        GAppInfo *info;

        rb_scan_args(argc, argv, "12", &commandline, &application_name, &flags);
        info = g_app_info_create_from_commandline(RVAL2CSTR(commandline),
                                                  RVAL2CSTR_ACCEPT_NIL(application_name),
                                                  RVAL2GAPPINFOCREATEFLAGSDEFAULT(flags),
                                                  &error);
        if (info == NULL)
                rbgio_raise_error(error);

        return GOBJ2RVAL_UNREF(info);
}
Ejemplo n.º 24
0
static void
notification_action_cb (NotifyNotification *notification,
                        const char *action,
                        DrWright *dr)
{
	GAppInfo *app_info;
	GdkAppLaunchContext *launch_context;

	g_assert (action != NULL);

	if (g_strcmp0 (action, "take-break") == 0) {
		if (dr->enabled) {
			dr->state = STATE_BREAK_SETUP;
			maybe_change_state (dr);
		}
	}
	else if (g_strcmp0 (action, "settings") == 0) {
		GError *error = NULL;

		launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ());

		app_info = g_app_info_create_from_commandline (BINDIR "/gnome-control-center typing-break",
		                                               NULL,
		                                               G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
		                                               &error);
		if (error) {
			g_warning ("%s", error->message);
			goto out;
		}

		g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);
		if (error) {
			g_warning ("%s", error->message);
		}
out:
		g_clear_error (&error);
		g_object_unref (launch_context);
	}
	else {
		g_warning ("Unknown action: %s", action);
	}
}
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);
}
Ejemplo n.º 26
0
gboolean
gs_plugin_launch (GsPlugin *plugin,
		  GsApp *app,
		  GCancellable *cancellable,
		  GError **error)
{
	const gchar *launch_name;
	const gchar *launch_desktop;
	g_autoptr(GAppInfo) info = NULL;

	/* We can only launch apps we know of */
	if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0)
		return TRUE;

	launch_name = gs_app_get_metadata_item (app, "snap::launch-name");
	launch_desktop = gs_app_get_metadata_item (app, "snap::launch-desktop");
	if (!launch_name)
		return TRUE;

	if (launch_desktop) {
		info = (GAppInfo *)g_desktop_app_info_new_from_filename (launch_desktop);
	} else {
		g_autofree gchar *commandline = NULL;
		GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;

		if (g_strcmp0 (launch_name, gs_app_get_metadata_item (app, "snap::name")) == 0)
			commandline = g_strdup_printf ("snap run %s", launch_name);
		else
			commandline = g_strdup_printf ("snap run %s.%s", gs_app_get_metadata_item (app, "snap::name"), launch_name);

		if (!is_graphical (plugin, app, cancellable))
			flags |= G_APP_INFO_CREATE_NEEDS_TERMINAL;
		info = g_app_info_create_from_commandline (commandline, NULL, flags, error);
	}

	if (info == NULL)
		return FALSE;

	return g_app_info_launch (info, NULL, NULL, error);
}
Ejemplo n.º 27
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);
	}
}
/* This will check if the application the user wanted exists will return that
 * application.  If it doesn't exist, it will create one and return that.
 * It also sets the app info as the default for this type.
 */
static GAppInfo *
add_or_find_application (CajaOpenWithDialog *dialog)
{
    GAppInfo *app;
    char *app_name;
    const char *commandline;
    GError *error;
    gboolean success, should_set_default;
    char *message;
    GList *applications;

    error = NULL;
    app = NULL;
    if (dialog->details->selected_app_info)
    {
        app = g_object_ref (dialog->details->selected_app_info);
    }
    else
    {
        commandline = gtk_entry_get_text (GTK_ENTRY (dialog->details->entry));
        app_name = get_app_name (commandline, &error);
        if (app_name != NULL)
        {
            app = g_app_info_create_from_commandline (commandline,
                    app_name,
                    G_APP_INFO_CREATE_NONE,
                    &error);
            g_free (app_name);
        }
    }

    if (app == NULL)
    {
        message = g_strdup_printf (_("Could not add application to the application database: %s"), error->message);
        eel_show_error_dialog (_("Could not add application"),
                               message,
                               GTK_WINDOW (dialog));
        g_free (message);
        g_error_free (error);
        return NULL;
    }

    should_set_default = (dialog->details->add_mode) ||
                         (!dialog->details->add_mode &&
                          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->checkbox)));
    success = TRUE;

    if (should_set_default)
    {
        if (dialog->details->content_type)
        {
            success = g_app_info_set_as_default_for_type (app,
                      dialog->details->content_type,
                      &error);
        }
        else
        {
            success = g_app_info_set_as_default_for_extension (app,
                      dialog->details->extension,
                      &error);
        }
    }
    else
    {
        applications = g_app_info_get_all_for_type (dialog->details->content_type);
        if (dialog->details->content_type && applications != NULL)
        {
            /* we don't care about reporting errors here */
            g_app_info_add_supports_type (app,
                                          dialog->details->content_type,
                                          NULL);
        }

        if (applications != NULL)
        {
            g_list_foreach(applications, (GFunc) g_object_unref, NULL);
            g_list_free(applications);
        }
    }

    if (!success && should_set_default)
    {
        message = g_strdup_printf (_("Could not set application as the default: %s"), error->message);
        eel_show_error_dialog (_("Could not set as default application"),
                               message,
                               GTK_WINDOW (dialog));
        g_free (message);
        g_error_free (error);
    }

    g_signal_emit_by_name (caja_signaller_get_current (),
                           "mime_data_changed");
    return app;
}
Ejemplo n.º 29
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;
}
/**
 * shell_doc_system_open:
 * @system: A #ShellDocSystem
 * @info: A #GtkRecentInfo
 * @workspace: Open on this workspace, or -1 for default
 *
 * Launch the default application associated with the mime type of
 * @info, using its uri.
 */
void
shell_doc_system_open (ShellDocSystem *system,
                       GtkRecentInfo  *info,
                       int             workspace)
{
  GFile *file;
  GAppInfo *app_info;
  gboolean needs_uri;
  GAppLaunchContext *context;

  context = shell_global_create_app_launch_context (shell_global_get ());
  if (workspace != -1)
    gdk_app_launch_context_set_desktop ((GdkAppLaunchContext *)context, workspace);

  file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
  needs_uri = g_file_get_path (file) == NULL;
  g_object_unref (file);

  app_info = g_app_info_get_default_for_type (gtk_recent_info_get_mime_type (info), needs_uri);
  if (app_info != NULL)
    {
      GList *uris;
      uris = g_list_prepend (NULL, (gpointer)gtk_recent_info_get_uri (info));
      g_app_info_launch_uris (app_info, uris, context, NULL);
      g_list_free (uris);
    }
  else
    {
      char *app_name;
      const char *app_exec;
      char *app_exec_quoted;
      guint count;
      time_t time;

      app_name = gtk_recent_info_last_application (info);
      if (gtk_recent_info_get_application_info (info, app_name, &app_exec, &count, &time))
        {
          GRegex *regex;

          /* TODO: Change this once better support for creating
             GAppInfo is added to GtkRecentInfo, as right now
             this relies on the fact that the file uri is
             already a part of appExec, so we don't supply any
             files to app_info.launch().

             The 'command line' passed to
             create_from_command_line is allowed to contain
             '%<something>' macros that are expanded to file
             name / icon name, etc, so we need to escape % as %%
           */

          regex = g_regex_new ("%", 0, 0, NULL);
          app_exec_quoted = g_regex_replace (regex, app_exec, -1, 0, "%%", 0, NULL);
          g_regex_unref (regex);

          app_info = g_app_info_create_from_commandline (app_exec_quoted, NULL, 0, NULL);
          g_free (app_exec_quoted);

          /* The point of passing an app launch context to
             launch() is mostly to get startup notification and
             associated benefits like the app appearing on the
             right desktop; but it doesn't really work for now
             because with the way we create the appInfo we
             aren't reading the application's desktop file, and
             thus don't find the StartupNotify=true in it. So,
             despite passing the app launch context, no startup
             notification occurs.
           */
          g_app_info_launch (app_info, NULL, context, NULL);
        }

      g_free (app_name);
    }

  g_object_unref (context);
}