Esempio n. 1
0
static void on_content_type_finished(GObject* src_obj, GAsyncResult* res, gpointer user_data)
{
    AutoRun* data = (AutoRun*)user_data;
    GMount* mount = G_MOUNT(src_obj);
    char** types;
    char* desc = NULL;

    types = g_mount_guess_content_type_finish(mount, res, NULL);
    if(types)
    {
        GtkTreeIter it;
        GList* apps = NULL, *l;
        char** type;
        if(types[0])
        {
            for(type=types;*type;++type)
            {
                l = g_app_info_get_all_for_type(*type);
                if(l)
                    apps = g_list_concat(apps, l);
            }
            desc = g_content_type_get_description(types[0]);
        }
        g_strfreev(types);

        if(apps)
        {
            int pos = 0;
            GtkTreePath* tp;
            for(l = apps; l; l=l->next, ++pos)
            {
                GAppInfo* app = G_APP_INFO(l->data);
                gtk_list_store_insert_with_values(data->store, &it, pos,
                                   0, g_app_info_get_icon(app),
                                   1, g_app_info_get_name(app),
                                   2, app, -1);
                g_object_unref(app);
            }
            g_list_free(apps);

            gtk_tree_model_get_iter_first(GTK_TREE_MODEL(data->store), &it);
            gtk_tree_selection_select_iter(gtk_tree_view_get_selection(data->view), &it);
            tp = gtk_tree_path_new_first();
            gtk_tree_view_set_cursor(data->view, tp, NULL, FALSE);
            gtk_tree_path_free(tp);
        }
    }

    if(desc)
    {
        gtk_label_set_text(data->type, desc);
        g_free(desc);
    }
    else
        gtk_label_set_text(data->type, _("Removable Disk"));

}
Esempio n. 2
0
static void
populate_mime_handlers (GMenu         *menu,
                        GbProjectFile *project_file)
{
  g_autofree gchar *content_type = NULL;
  GList *list;
  GList *iter;
  GFile *file;

  g_assert (G_IS_MENU (menu));
  g_assert (GB_IS_PROJECT_FILE (project_file));

  g_menu_remove_all (menu);

  file = gb_project_file_get_file (project_file);
  if (file == NULL)
    return;

  content_type = get_content_type (file);
  if (content_type == NULL)
    return;

  list = g_app_info_get_all_for_type (content_type);

  for (iter = list; iter; iter = iter->next)
    {
      g_autoptr(GMenuItem) menu_item = NULL;
      g_autofree gchar *detailed_action = NULL;
      GAppInfo *app_info = iter->data;
      const gchar *display_name;
      const gchar *app_id;

      display_name = g_app_info_get_display_name (app_info);
      app_id = g_app_info_get_id (app_info);

      detailed_action = g_strdup_printf ("project-tree.open-with('%s')", app_id);
      menu_item = g_menu_item_new (display_name, detailed_action);

      g_menu_append_item (menu, menu_item);
    }

  g_list_free_full (list, g_object_unref);
}
Esempio n. 3
0
static void
_gth_browser_update_open_menu (GthBrowser *browser,
			       const char *path)
{
	GtkWidget    *openwith_item;
	GtkWidget    *menu;
	GList        *items;
	GList        *file_list;
	GList        *scan;
	GList        *appinfo_list;
	GHashTable   *used_mime_types;
	GthIconCache *icon_cache;
	GHashTable   *used_apps;

	openwith_item = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), path);
	menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (openwith_item));
	_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);

	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);

	appinfo_list = NULL;
	used_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		const char  *mime_type;

		mime_type = gth_file_data_get_mime_type (file_data);
		if ((mime_type == NULL) || g_content_type_is_unknown (mime_type))
			continue;
		if (g_hash_table_lookup (used_mime_types, mime_type) != NULL)
			continue;

		appinfo_list = g_list_concat (appinfo_list, g_app_info_get_all_for_type (mime_type));

		g_hash_table_insert (used_mime_types, (gpointer) mime_type, GINT_TO_POINTER (1));
	}
	g_hash_table_destroy (used_mime_types);

	icon_cache = gth_browser_get_menu_icon_cache (browser);
	used_apps = g_hash_table_new (g_str_hash, g_str_equal);
	for (scan = appinfo_list; scan; scan = scan->next) {
		GAppInfo  *appinfo = scan->data;
		char      *label;
		GtkWidget *menu_item;
		GIcon     *icon;

		if (strcmp (g_app_info_get_executable (appinfo), "pix") == 0)
			continue;
		if (g_hash_table_lookup (used_apps, g_app_info_get_id (appinfo)) != NULL)
			continue;
		g_hash_table_insert (used_apps, (gpointer) g_app_info_get_id (appinfo), GINT_TO_POINTER (1));

		label = g_strdup_printf ("%s", g_app_info_get_name (appinfo));
		menu_item = gtk_image_menu_item_new_with_label (label);

		icon = g_app_info_get_icon (appinfo);
		if (icon != NULL) {
			GdkPixbuf *pixbuf;

			pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon);
			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_pixbuf (pixbuf));
			gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);

			g_object_unref (pixbuf);
		}

		gtk_widget_show (menu_item);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

		g_object_set_data_full (G_OBJECT (menu_item),
					"appinfo",
					g_object_ref (appinfo),
					g_object_unref);
		g_signal_connect (menu_item,
				  "activate",
				  G_CALLBACK (activate_open_with_application_item),
			  	  browser);

		g_free (label);
	}

	/*
	if (appinfo_list == NULL) {
		GtkWidget *menu_item;

		menu_item = gtk_image_menu_item_new_with_label (_("No application available"));
		gtk_widget_set_sensitive (menu_item, FALSE);
		gtk_widget_show (menu_item);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	}*/

	gtk_widget_set_sensitive (openwith_item, appinfo_list != NULL);
	gtk_widget_show (openwith_item);

	g_hash_table_destroy (used_apps);
	_g_object_list_unref (appinfo_list);
	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (items);
}
Esempio n. 4
0
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  const char *mimetype;
  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]", _("MIMETYPE"), _("HANDLER"));
  summary = _("Get or set the handler for a mime-type.");

  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);
  g_option_context_free (context);
  g_free (param);

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

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

  if (query && argc != 2)
    {
      g_printerr (_("Must specify a single mime-type.\n"));
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }
  else if (set && argc != 3)
    {
      g_printerr (_("Must specify the mime-type followed by the default handler.\n"));
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }

  mimetype = argv[1];

  if (query)
    {
      GAppInfo *info;

      info = g_app_info_get_default_for_type (mimetype, FALSE);
      if (!info)
        {
          g_print (_("No default applications for '%s'\n"), mimetype);
        }
      else
        {
          GList *list, *l;

          g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info));
          g_object_unref (info);

          list = g_app_info_get_all_for_type (mimetype);
          if (list != NULL)
            g_print (_("Registered applications:\n"));
	  else
	    g_print (_("No registered applications\n"));
          for (l = list; l != NULL; l = l->next)
	    {
	      info = l->data;
	      g_print ("\t%s\n", g_app_info_get_id (info));
	      g_object_unref (info);
	    }
	  g_list_free (list);

	  list = g_app_info_get_recommended_for_type (mimetype);
	  if (list != NULL)
            g_print (_("Recommended applications:\n"));
	  else
	    g_print (_("No recommended applications\n"));
          for (l = list; l != NULL; l = l->next)
	    {
	      info = l->data;
	      g_print ("\t%s\n", g_app_info_get_id (info));
	      g_object_unref (info);
	    }
	  g_list_free (list);
        }
    }
  else if (set)
    {
      const char *handler;
      GAppInfo *info;

      handler = argv[2];

      info = get_app_info_for_id (handler);
      if (info == NULL)
        {
          g_printerr (_("Failed to load info for handler '%s'\n"), handler);
          return 1;
        }

      if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE)
        {
          g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"),
                      handler, mimetype, error->message);
          g_error_free (error);
          g_object_unref (info);
          return 1;
        }
      g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype);
      g_object_unref (info);
    }

  return 0;
}
Esempio n. 5
0
void
caja_autorun_prepare_combo_box (GtkWidget *combo_box,
                                const char *x_content_type,
                                gboolean include_ask,
                                gboolean include_open_with_other_app,
                                gboolean update_settings,
                                CajaAutorunComboBoxChanged changed_cb,
                                gpointer user_data)
{
    GList *l;
    GList *app_info_list;
    GAppInfo *default_app_info;
    GtkListStore *list_store;
    GtkTreeIter iter;
    GdkPixbuf *pixbuf;
    int icon_size;
    int set_active;
    int n;
    int num_apps;
    gboolean pref_ask;
    gboolean pref_start_app;
    gboolean pref_ignore;
    gboolean pref_open_folder;
    CajaAutorunComboBoxData *data;
    GtkCellRenderer *renderer;
    gboolean new_data;

    caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder);
    pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);

    set_active = -1;
    data = NULL;
    new_data = TRUE;

    app_info_list = g_app_info_get_all_for_type (x_content_type);
    default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
    num_apps = g_list_length (app_info_list);

    list_store = gtk_list_store_new (5,
                                     GDK_TYPE_PIXBUF,
                                     G_TYPE_STRING,
                                     G_TYPE_APP_INFO,
                                     G_TYPE_STRING,
                                     G_TYPE_INT);

    /* no apps installed */
    if (num_apps == 0)
    {
        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_DIALOG_ERROR,
                                           icon_size,
                                           0,
                                           NULL);

        /* TODO: integrate with PackageKit-mate to find applications */

        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("No applications found"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                            -1);
        g_object_unref (pixbuf);
    }
    else
    {
        if (include_ask)
        {
            gtk_list_store_append (list_store, &iter);
            pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                               GTK_STOCK_DIALOG_QUESTION,
                                               icon_size,
                                               0,
                                               NULL);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, _("Ask what to do"),
                                COLUMN_AUTORUN_APP_INFO, NULL,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                                -1);
            g_object_unref (pixbuf);
        }

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_CLOSE,
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Do Nothing"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "folder-open",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open Folder"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        for (l = app_info_list, n = include_ask ? 4 : 3; l != NULL; l = l->next, n++)
        {
            GIcon *icon;
            CajaIconInfo *icon_info;
            char *open_string;
            GAppInfo *app_info = l->data;

            /* we deliberately ignore should_show because some apps might want
             * to install special handlers that should be hidden in the regular
             * application launcher menus
             */

            icon = g_app_info_get_icon (app_info);
            icon_info = caja_icon_info_lookup (icon, icon_size);
            pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
            g_object_unref (icon_info);

            open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info));

            gtk_list_store_append (list_store, &iter);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, open_string,
                                COLUMN_AUTORUN_APP_INFO, app_info,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
                                -1);
            if (pixbuf != NULL)
            {
                g_object_unref (pixbuf);
            }
            g_free (open_string);

            if (g_app_info_equal (app_info, default_app_info))
            {
                set_active = n;
            }
        }
    }

    if (include_open_with_other_app)
    {
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "application-x-executable",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open with other Application..."),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
                            -1);
        g_object_unref (pixbuf);
    }

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

    gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store));
    g_object_unref (G_OBJECT (list_store));

    gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box));

    renderer = gtk_cell_renderer_pixbuf_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "pixbuf", COLUMN_AUTORUN_PIXBUF,
                                    NULL);
    renderer = gtk_cell_renderer_text_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "text", COLUMN_AUTORUN_NAME,
                                    NULL);
    gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL);

    if (num_apps == 0)
    {
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        gtk_widget_set_sensitive (combo_box, FALSE);
    }
    else
    {
        gtk_widget_set_sensitive (combo_box, TRUE);
        if (pref_ask && include_ask)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        }
        else if (pref_ignore)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }
        else if (pref_open_folder)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 2 : 1);
        }
        else if (set_active != -1)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active);
        }
        else
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }

        /* See if we have an old data around */
        data = g_object_get_data (G_OBJECT (combo_box), "caja_autorun_combobox_data");
        if (data)
        {
            new_data = FALSE;
            g_free (data->x_content_type);
        }
        else
        {
            data = g_new0 (CajaAutorunComboBoxData, 1);
        }

        data->x_content_type = g_strdup (x_content_type);
        data->include_ask = include_ask;
        data->include_open_with_other_app = include_open_with_other_app;
        data->update_settings = update_settings;
        data->changed_cb = changed_cb;
        data->user_data = user_data;
        data->combo_box = combo_box;
        if (data->changed_signal_id == 0)
        {
            data->changed_signal_id = g_signal_connect (G_OBJECT (combo_box),
                                      "changed",
                                      G_CALLBACK (combo_box_changed),
                                      data);
        }
    }

    if (new_data)
    {
        g_object_set_data_full (G_OBJECT (combo_box),
                                "caja_autorun_combobox_data",
                                data,
                                (GDestroyNotify) caja_autorun_combobox_data_destroy);
    }
}
static void
show_dialog(MateDACapplet* capplet, const gchar* start_page)
{
#define get_widget(name) GTK_WIDGET(gtk_builder_get_object(builder, name))

    GtkBuilder* builder;
    guint builder_result;

    capplet->builder = builder = gtk_builder_new ();

    if (g_file_test(MATECC_UI_DIR "/mate-default-applications-properties.ui", G_FILE_TEST_EXISTS) != FALSE)
    {
        builder_result = gtk_builder_add_from_file(builder, MATECC_UI_DIR "/mate-default-applications-properties.ui", NULL);
    }
    else
    {
        builder_result = gtk_builder_add_from_file(builder, "./mate-default-applications-properties.ui", NULL);
    }

    if (builder_result == 0)
    {
        GtkWidget* dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not load the main interface"));
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Please make sure that the applet is properly installed"));
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

        gtk_dialog_run(GTK_DIALOG(dialog));

        gtk_widget_destroy(dialog);
        exit(EXIT_FAILURE);
    }

    capplet->window = get_widget("preferred_apps_dialog");

    g_signal_connect(capplet->window, "response", G_CALLBACK(close_cb), capplet);

    capplet->web_combo_box = get_widget("web_browser_combobox");
    capplet->mail_combo_box = get_widget("mail_reader_combobox");
    capplet->term_combo_box = get_widget("terminal_combobox");
    capplet->media_combo_box = get_widget("media_player_combobox");
    capplet->video_combo_box = get_widget("video_combobox");
    capplet->visual_combo_box = get_widget("visual_combobox");
    capplet->mobility_combo_box = get_widget("mobility_combobox");
    capplet->text_combo_box = get_widget("text_combobox");
    capplet->file_combo_box = get_widget("filemanager_combobox");
    capplet->image_combo_box = get_widget("image_combobox");
    capplet->document_combo_box = get_widget("document_combobox");
    capplet->word_combo_box = get_widget("word_combobox");
    capplet->spreadsheet_combo_box = get_widget("spreadsheet_combobox");

    capplet->visual_startup_checkbutton = get_widget("visual_start_checkbutton");
    capplet->mobility_startup_checkbutton = get_widget("mobility_start_checkbutton");

    g_signal_connect(capplet->window, "screen-changed", G_CALLBACK(screen_changed_cb), capplet);
    screen_changed_cb(capplet->window, gdk_screen_get_default(), capplet);

    /* Lists of default applications */
    capplet->web_browsers = g_app_info_get_all_for_type("x-scheme-handler/http");
    capplet->mail_readers = g_app_info_get_all_for_type("x-scheme-handler/mailto");
    capplet->media_players = g_app_info_get_all_for_type("audio/x-vorbis+ogg");
    capplet->video_players = g_app_info_get_all_for_type("video/x-ogm+ogg");
    capplet->text_editors = g_app_info_get_all_for_type("text/plain");
    capplet->image_viewers = g_app_info_get_all_for_type("image/png");
    capplet->file_managers = g_app_info_get_all_for_type("inode/directory");
    capplet->document_viewers = g_app_info_get_all_for_type("application/pdf");
    capplet->word_editors = g_app_info_get_all_for_type("application/msword");
    capplet->spreadsheet_editors = g_app_info_get_all_for_type("application/vnd.ms-excel");

    capplet->visual_ats = NULL;
    capplet->visual_ats = fill_list_from_desktop_file (capplet->visual_ats, APPLICATIONSDIR "/orca.desktop");
    capplet->visual_ats = g_list_reverse (capplet->visual_ats);

    capplet->mobility_ats = NULL;
    capplet->mobility_ats = fill_list_from_desktop_file (capplet->mobility_ats, APPLICATIONSDIR "/dasher.desktop");
    capplet->mobility_ats = fill_list_from_desktop_file (capplet->mobility_ats, APPLICATIONSDIR "/gok.desktop");
    capplet->mobility_ats = fill_list_from_desktop_file (capplet->mobility_ats, APPLICATIONSDIR "/onboard.desktop");
    capplet->mobility_ats = g_list_reverse (capplet->mobility_ats);

    /* Terminal havent mime types, so check in .desktop files for
       Categories=TerminalEmulator */
    GList *entry;
    GList *all_apps;
    capplet->terminals = NULL;
    all_apps = g_app_info_get_all();
    for (entry = all_apps; entry != NULL; entry = g_list_next(entry))
    {
        GDesktopAppInfo* item = (GDesktopAppInfo*) entry->data;
        if (g_desktop_app_info_get_categories (item) != NULL &&
                g_strrstr (g_desktop_app_info_get_categories (item), "TerminalEmulator"))
        {
            capplet->terminals = g_list_prepend (capplet->terminals, item);
        }
    }
    capplet->terminals = g_list_reverse (capplet->terminals);

    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->web_combo_box), capplet->web_browsers, "x-scheme-handler/http");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mail_combo_box), capplet->mail_readers, "x-scheme-handler/mailto");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->term_combo_box), capplet->terminals, "terminal");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->media_combo_box), capplet->media_players, "audio/x-vorbis+ogg");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->video_combo_box), capplet->video_players, "video/x-ogm+ogg");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->image_combo_box), capplet->image_viewers, "image/png");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->text_combo_box), capplet->text_editors, "text/plain");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->file_combo_box), capplet->file_managers, "inode/directory");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->visual_combo_box), capplet->visual_ats, "visual");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mobility_combo_box), capplet->mobility_ats, "mobility");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->document_combo_box), capplet->document_viewers, "application/pdf");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->word_combo_box), capplet->word_editors, "application/vnd.oasis.opendocument.text");
    fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet->spreadsheet_editors, "application/vnd.oasis.opendocument.spreadsheet");

    g_signal_connect(capplet->web_combo_box, "changed", G_CALLBACK(web_combo_changed_cb), capplet);
    g_signal_connect(capplet->mail_combo_box, "changed", G_CALLBACK(mail_combo_changed_cb), capplet);
    g_signal_connect(capplet->term_combo_box, "changed", G_CALLBACK(terminal_combo_changed_cb), capplet);
    g_signal_connect(capplet->media_combo_box, "changed", G_CALLBACK(media_combo_changed_cb), capplet);
    g_signal_connect(capplet->video_combo_box, "changed", G_CALLBACK(video_combo_changed_cb), capplet);
    g_signal_connect(capplet->visual_combo_box, "changed", G_CALLBACK(visual_combo_changed_cb), capplet);
    g_signal_connect(capplet->mobility_combo_box, "changed", G_CALLBACK(mobility_combo_changed_cb), capplet);
    g_signal_connect(capplet->image_combo_box, "changed", G_CALLBACK(image_combo_changed_cb), capplet);
    g_signal_connect(capplet->text_combo_box, "changed", G_CALLBACK(text_combo_changed_cb), capplet);
    g_signal_connect(capplet->file_combo_box, "changed", G_CALLBACK(file_combo_changed_cb), capplet);
    g_signal_connect(capplet->document_combo_box, "changed", G_CALLBACK(document_combo_changed_cb), capplet);
    g_signal_connect(capplet->word_combo_box, "changed", G_CALLBACK(word_combo_changed_cb), capplet);
    g_signal_connect(capplet->spreadsheet_combo_box, "changed", G_CALLBACK(spreadsheet_combo_changed_cb), capplet);

    g_settings_bind (capplet->mobility_settings, MOBILITY_STARTUP_KEY, capplet->mobility_startup_checkbutton, "active", G_SETTINGS_BIND_DEFAULT);
    g_settings_bind (capplet->visual_settings, VISUAL_STARTUP_KEY, capplet->visual_startup_checkbutton, "active", G_SETTINGS_BIND_DEFAULT);

    gtk_window_set_icon_name(GTK_WINDOW (capplet->window), "preferences-desktop-default-applications");

    if (start_page != NULL)
    {
        gchar* page_name;
        GtkWidget* w;

        page_name = g_strconcat (start_page, "_vbox", NULL);

        w = get_widget(page_name);

        if (w != NULL)
        {
            GtkNotebook* nb;
            gint pindex;

            nb = GTK_NOTEBOOK(get_widget("preferred_apps_notebook"));
            pindex = gtk_notebook_page_num(nb, w);

            if (pindex != -1)
            {
                gtk_notebook_set_current_page(nb, pindex);
            }
        }

        g_free(page_name);
    }

    gtk_widget_show(capplet->window);

#undef get_widget
}
Esempio n. 7
0
static void
fill_open_with_menu (GtkTreeView *view, GtkBuilder *builder, GtkTreePath *path)
{
    GtkTreeModel *model = gtk_tree_view_get_model (view);
    if (!model) {
        return;
    }
    GtkTreeIter iter;
    if (!gtk_tree_model_get_iter(model, &iter, path)) {
        return;
    }
    DatabaseSearchEntry *entry = (DatabaseSearchEntry *)iter.user_data;
    if (!entry) {
        return;
    }

    BTreeNode * node = db_search_entry_get_node (entry);

    GList *app_list = NULL;
    char *content_type = NULL;

    if (node->is_dir) {
        content_type = g_content_type_from_mime_type ("inode/directory");
    }
    else {
        content_type = g_content_type_guess (node->name, NULL, 0, NULL);
    }

    if (!content_type) {
        goto clean_up;
    }

    app_list = g_app_info_get_all_for_type (content_type);
    if (!app_list) {
        goto clean_up;
    }

    GMenu *menu_mime = G_MENU (gtk_builder_get_object (builder,
                                                       "fsearch_listview_menu_open_with_mime_section"));

    for (GList *list_iter = app_list; list_iter; list_iter = list_iter->next) {
        GAppInfo *app_info = list_iter->data;
        const char *display_name = g_app_info_get_display_name (app_info);
        const char *app_id = g_app_info_get_id (app_info);

        char detailed_action[1024] = "";
        snprintf (detailed_action, sizeof (detailed_action), "win.open_with('%s')", app_id);

        GMenuItem *menu_item = g_menu_item_new (display_name, detailed_action);
        g_menu_item_set_icon (menu_item, g_app_info_get_icon (app_info));
        g_menu_append_item (menu_mime, menu_item);
        g_object_unref (menu_item);
    }

clean_up:
    if (content_type) {
        g_free (content_type);
        content_type = NULL;
    }
    if (app_list) {
        g_list_free_full (app_list, g_object_unref);
        app_list = NULL;
    }
}
Esempio n. 8
0
File: apps.c Progetto: 183amir/glib
int
main (int argc, char **argv)
{
  setlocale (LC_ALL, "");

  if (argv[1] == NULL)
    ;
  else if (g_str_equal (argv[1], "list"))
    {
      GList *all, *i;

      all = g_app_info_get_all ();
      for (i = all; i; i = i->next)
        g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
      g_list_free_full (all, g_object_unref);
    }
  else if (g_str_equal (argv[1], "search"))
    {
      gchar ***results;
      gint i, j;

      results = g_desktop_app_info_search (argv[2]);
      for (i = 0; results[i]; i++)
        {
          for (j = 0; results[i][j]; j++)
            g_print ("%s%s", j ? " " : "", results[i][j]);
          g_print ("\n");
          g_strfreev (results[i]);
        }
      g_free (results);
    }
  else if (g_str_equal (argv[1], "implementations"))
    {
      GList *results;

      results = g_desktop_app_info_get_implementations (argv[2]);
      print_app_list (results);
    }
  else if (g_str_equal (argv[1], "show-info"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          print (g_app_info_get_id (info));
          print (g_app_info_get_name (info));
          print (g_app_info_get_display_name (info));
          print (g_app_info_get_description (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "default-for-type"))
    {
      GAppInfo *info;

      info = g_app_info_get_default_for_type (argv[2], FALSE);

      if (info)
        {
          print (g_app_info_get_id (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "recommended-for-type"))
    {
      GList *list;

      list = g_app_info_get_recommended_for_type (argv[2]);
      print_app_list (list);
    }
  else if (g_str_equal (argv[1], "all-for-type"))
    {
      GList *list;

      list = g_app_info_get_all_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "fallback-for-type"))
    {
      GList *list;

      list = g_app_info_get_fallback_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "should-show"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
          g_object_unref (info);
        }
    }

  else if (g_str_equal (argv[1], "monitor"))
    {
      GAppInfoMonitor *monitor;
      GAppInfo *info;

      monitor = g_app_info_monitor_get ();

      info = (GAppInfo *) g_desktop_app_info_new ("this-desktop-file-does-not-exist");
      g_assert (!info);

      g_signal_connect (monitor, "changed", G_CALLBACK (quit), NULL);

      while (1)
        g_main_context_iteration (NULL, TRUE);
    }

  return 0;
}
Esempio n. 9
0
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  const char *mimetype;

  setlocale (LC_ALL, "");

  g_type_init ();

  error = NULL;
  context = g_option_context_new (_("- get/set handler for <mimetype>"));
  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 ||
      query == set)
    {
      g_printerr (_("Error parsing commandline options: %s\n"),
                  error ? error->message : _("Specify one of --query and --set"));
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."),
		  g_get_prgname ());
      g_printerr ("\n");
      if (error != NULL)
        g_error_free(error);
      return 1;
    }

  if (query && argc != 2)
    {
      g_printerr (_("Must specify a single mime-type.\n"));
      g_printerr (_("Try \"%s --help\" for more information."),
		  g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }
  else if (set && argc != 3)
    {
      g_printerr (_("Must specify the mime-type followed by the default handler.\n"));
      g_printerr (_("Try \"%s --help\" for more information."),
		  g_get_prgname ());
      g_printerr ("\n");
      return 1;
    }

  mimetype = argv[1];

  if (query)
    {
      GAppInfo *info;

      info = g_app_info_get_default_for_type (mimetype, FALSE);
      if (!info)
        {
          g_print (_("No default applications for '%s'\n"), mimetype);
        }
      else
        {
          GList *list, *l;

          g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info));
          g_object_unref (info);

          list = g_app_info_get_all_for_type (mimetype);
          if (list != NULL)
            g_print (_("Registered applications:\n"));
          for (l = list; l != NULL; l = l->next)
	    {
	      info = l->data;
	      g_print ("\t%s\n", g_app_info_get_id (info));
	      g_object_unref (info);
	    }
	  g_list_free (list);

	  list = g_app_info_get_recommended_for_type (mimetype);
	  if (list != NULL)
            g_print (_("Recommended applications:\n"));
          for (l = list; l != NULL; l = l->next)
	    {
	      info = l->data;
	      g_print ("\t%s\n", g_app_info_get_id (info));
	      g_object_unref (info);
	    }
	  g_list_free (list);
        }
    }
  else if (set)
    {
      const char *handler;
      GAppInfo *info;

      handler = argv[2];

      info = get_app_info_for_id (handler);
      if (info == NULL)
        {
          g_printerr (_("Failed to load info for handler '%s'\n"), handler);
          return 1;
        }

      if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE)
        {
          g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"),
                      handler, mimetype, error->message);
          g_error_free (error);
          g_object_unref (info);
          return 1;
        }
      g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype);
      g_object_unref (info);
    }

  return 0;
}
Esempio n. 10
0
/* create the "open with" dialog. */
void
dlg_open_with (FrWindow *window,
	       GList    *file_list)
{
	DialogData *data;
	GAppInfo *app;
	GList *scan, *app_names = NULL;
	char **editors;
	int i;
	GtkWidget *cancel_button;
	GtkTreeIter iter;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	GtkIconTheme *theme;
	int icon_size;

	if (file_list == NULL)
		return;

	data = g_new0 (DialogData, 1);
	data->settings = g_settings_new (EXRED_SCHEMA_GENERAL);
	data->builder = _gtk_builder_new_from_file ("open-with.ui");
	if (data->builder == NULL) {
		g_free (data);
		return;
	}

	data->file_list = path_list_dup (file_list);
	data->window = window;

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "open_with_dialog");
	data->o_app_tree_view = _gtk_builder_get_widget (data->builder, "o_app_list_tree_view");
	data->o_recent_tree_view = _gtk_builder_get_widget (data->builder, "o_recent_tree_view");
	data->o_app_entry = _gtk_builder_get_widget (data->builder, "o_app_entry");
	data->o_del_button = _gtk_builder_get_widget (data->builder, "o_del_button");
	data->ok_button = _gtk_builder_get_widget (data->builder, "o_ok_button");
	cancel_button = _gtk_builder_get_widget (data->builder, "o_cancel_button");

	gtk_widget_set_sensitive (data->ok_button, FALSE);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (open_with__destroy_cb),
			  data);

	g_signal_connect (G_OBJECT (data->o_app_entry),
			  "changed",
			  G_CALLBACK (app_entry__changed_cb),
			  data);

	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_app_tree_view))),
			  "changed",
			  G_CALLBACK (app_list_selection_changed_cb),
			  data);
	g_signal_connect (G_OBJECT (data->o_app_tree_view),
			  "row_activated",
			  G_CALLBACK (app_activated_cb),
			  data);

	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_recent_tree_view))),
			  "changed",
			  G_CALLBACK (recent_list_selection_changed_cb),
			  data);
	g_signal_connect (G_OBJECT (data->o_recent_tree_view),
			  "row_activated",
			  G_CALLBACK (recent_activated_cb),
			  data);

	g_signal_connect (G_OBJECT (data->ok_button),
			  "clicked",
			  G_CALLBACK (open_cb),
			  data);
	g_signal_connect_swapped (G_OBJECT (cancel_button),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  G_OBJECT (data->dialog));
	g_signal_connect (G_OBJECT (data->o_del_button),
			  "clicked",
			  G_CALLBACK (delete_recent_cb),
			  data);

	/* Set data. */

	/* * registered applications list. */

	data->app_list = NULL;
	for (scan = data->file_list; scan; scan = scan->next) {
		const char *mime_type;
		const char *name = scan->data;

		mime_type = get_file_mime_type_for_path (name, FALSE);
		if ((mime_type != NULL) && ! g_content_type_is_unknown (mime_type))
			data->app_list = g_list_concat (data->app_list, g_app_info_get_all_for_type (mime_type));
	}

	data->app_model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS,
							      GDK_TYPE_PIXBUF,
							      G_TYPE_STRING,
							      G_TYPE_POINTER));

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->app_model),
					      TEXT_COLUMN,
					      GTK_SORT_ASCENDING);

	gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_app_tree_view),
				 data->app_model);
	g_object_unref (G_OBJECT (data->app_model));

	theme = gtk_icon_theme_get_default ();
	icon_size = get_folder_pixbuf_size_for_list (GTK_WIDGET (data->dialog));

	for (scan = data->app_list; scan; scan = scan->next) {
		gboolean   found;
		char      *utf8_name;
		GdkPixbuf *icon_image = NULL;

		app = scan->data;

		found = FALSE;
		if (app_names != NULL) {
			GList *p;
			for (p = app_names; p && !found; p = p->next)
				if (g_strcmp0 ((char*)p->data, g_app_info_get_executable (app)) == 0)
					found = TRUE;
		}

		if (found)
			continue;

		app_names = g_list_prepend (app_names, (char*) g_app_info_get_executable (app));

		utf8_name = g_locale_to_utf8 (g_app_info_get_name (app), -1, NULL, NULL, NULL);	
		icon_image = get_icon_pixbuf (g_app_info_get_icon (app), icon_size, theme);
		
		gtk_list_store_append (GTK_LIST_STORE (data->app_model),
				       &iter);
		gtk_list_store_set (GTK_LIST_STORE (data->app_model),
				    &iter,
				    ICON_COLUMN, icon_image,
				    TEXT_COLUMN, utf8_name,
				    DATA_COLUMN, app,
				    -1);

		g_free (utf8_name);
	}

	column = gtk_tree_view_column_new ();

	renderer = gtk_cell_renderer_pixbuf_new ();
	gtk_tree_view_column_pack_start (column, renderer, FALSE);
	gtk_tree_view_column_set_attributes (column, renderer,
					     "pixbuf", ICON_COLUMN,
					     NULL);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_column_pack_start (column,
					 renderer,
					 TRUE);
	gtk_tree_view_column_set_attributes (column, renderer,
					     "text", TEXT_COLUMN,
					     NULL);

	gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_app_tree_view),
				     column);

	if (app_names)
		g_list_free (app_names);

	/* * recent editors list. */

	data->recent_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->recent_model), 0, GTK_SORT_ASCENDING);

	gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_recent_tree_view),
				 data->recent_model);
	g_object_unref (G_OBJECT (data->recent_model));

	editors = g_settings_get_strv (data->settings, PREF_GENERAL_EDITORS);
	for (i = 0; editors[i] != NULL; i++) {
		gtk_list_store_append (GTK_LIST_STORE (data->recent_model), &iter);
		gtk_list_store_set (GTK_LIST_STORE (data->recent_model), &iter,
				    0, editors[i],
				    -1);
	}
	g_strfreev (editors);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (NULL,
							   renderer,
							   "text", 0,
							   NULL);
	gtk_tree_view_column_set_sort_column_id (column, 0);
	gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_recent_tree_view),
				     column);

	/* Run dialog. */
	gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
				      GTK_WINDOW (window));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);
	gtk_widget_show_all (data->dialog);
}
Esempio n. 11
0
static VALUE
appinfo_get_all_for_type(G_GNUC_UNUSED VALUE self, VALUE content_type)
{
        return GLIST2ARY_FREE(g_app_info_get_all_for_type(RVAL2CSTR(content_type)));
}
Esempio n. 12
0
/**
 * fm_app_chooser_dlg_dup_selected_app
 * @dlg: a widget
 * @set_default: location to get value that was used for fm_app_chooser_dlg_new()
 *
 * Retrieves a currently selected application from @dlg.
 *
 * Before 1.0.0 this call had name fm_app_chooser_dlg_get_selected_app.
 *
 * Returns: (transfer full): selected application.
 *
 * Since: 0.1.0
 */
GAppInfo* fm_app_chooser_dlg_dup_selected_app(GtkDialog* dlg, gboolean* set_default)
{
    GAppInfo* app = NULL;
    AppChooserData* data = (AppChooserData*)g_object_get_qdata(G_OBJECT(dlg), fm_qdata_id);
    switch( gtk_notebook_get_current_page(data->notebook) )
    {
    case 0: /* all applications */
        app = fm_app_menu_view_dup_selected_app(data->apps_view);
        break;
    case 1: /* custom cmd line */
        {
            const char* cmdline = gtk_entry_get_text(data->cmdline);
            const char* app_name = gtk_entry_get_text(data->app_name);
            if(cmdline && cmdline[0])
            {
                char* _cmdline = NULL;
                gboolean arg_found = FALSE;
                char* bin1 = get_binary(cmdline, &arg_found);
                g_debug("bin1 = %s", bin1);
                /* see if command line contains %f, %F, %u, or %U. */
                if(!arg_found)  /* append %f if no %f, %F, %u, or %U was found. */
                    cmdline = _cmdline = g_strconcat(cmdline, " %f", NULL);

                /* FIXME: is there any better way to do this? */
                /* We need to ensure that no duplicated items are added */
                if(data->mime_type)
                {
                    MenuCache* menu_cache;
                    /* see if the command is already in the list of known apps for this mime-type */
                    GList* apps = g_app_info_get_all_for_type(fm_mime_type_get_type(data->mime_type));
                    GList* l;
                    for(l=apps;l;l=l->next)
                    {
                        GAppInfo* app2 = G_APP_INFO(l->data);
                        const char* cmd = g_app_info_get_commandline(app2);
                        char* bin2 = get_binary(cmd, NULL);
                        if(g_strcmp0(bin1, bin2) == 0)
                        {
                            app = G_APP_INFO(g_object_ref(app2));
                            g_debug("found in app list");
                            g_free(bin2);
                            break;
                        }
                        g_free(bin2);
                    }
                    g_list_foreach(apps, (GFunc)g_object_unref, NULL);
                    g_list_free(apps);
                    if(app)
                        goto _out;

                    /* see if this command can be found in menu cache */
                    menu_cache = menu_cache_lookup("applications.menu");
                    if(menu_cache)
                    {
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
                        MenuCacheDir *root_dir = menu_cache_dup_root_dir(menu_cache);
                        if(root_dir)
#else
                        if(menu_cache_get_root_dir(menu_cache))
#endif
                        {
                            GSList* all_apps = menu_cache_list_all_apps(menu_cache);
                            GSList* l;
                            for(l=all_apps;l;l=l->next)
                            {
                                MenuCacheApp* ma = MENU_CACHE_APP(l->data);
                                const char *exec = menu_cache_app_get_exec(ma);
                                char* bin2;
                                if (exec == NULL)
                                {
                                    g_warning("application %s has no Exec statement", menu_cache_item_get_id(MENU_CACHE_ITEM(ma)));
                                    continue;
                                }
                                bin2 = get_binary(exec, NULL);
                                if(g_strcmp0(bin1, bin2) == 0)
                                {
                                    app = G_APP_INFO(g_desktop_app_info_new(menu_cache_item_get_id(MENU_CACHE_ITEM(ma))));
                                    g_debug("found in menu cache");
                                    menu_cache_item_unref(MENU_CACHE_ITEM(ma));
                                    g_free(bin2);
                                    break;
                                }
                                menu_cache_item_unref(MENU_CACHE_ITEM(ma));
                                g_free(bin2);
                            }
                            g_slist_free(all_apps);
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
                            menu_cache_item_unref(MENU_CACHE_ITEM(root_dir));
#endif
                        }
                        menu_cache_unref(menu_cache);
                    }
                    if(app)
                        goto _out;
                }

                /* FIXME: g_app_info_create_from_commandline force the use of %f or %u, so this is not we need */
                app = app_info_create_from_commandline(cmdline,
                            app_name ? app_name : "", bin1,
                            data->mime_type ? fm_mime_type_get_type(data->mime_type) : NULL,
                            gtk_toggle_button_get_active(data->use_terminal),
                            data->keep_open && gtk_toggle_button_get_active(data->keep_open));
            _out:
                g_free(bin1);
                g_free(_cmdline);
            }
        }
        break;
    }

    if(set_default)
        *set_default = gtk_toggle_button_get_active(data->set_default);
    return app;
}
static void
show_dialog(MateDACapplet* capplet, const gchar* start_page)
{
	#define get_widget(name) GTK_WIDGET(gtk_builder_get_object(builder, name))

	GtkBuilder* builder;
	guint builder_result;

	capplet->builder = builder = gtk_builder_new ();

	if (g_file_test(MATECC_UI_DIR "/mate-default-applications-properties.ui", G_FILE_TEST_EXISTS) != FALSE)
	{
		builder_result = gtk_builder_add_from_file(builder, MATECC_UI_DIR "/mate-default-applications-properties.ui", NULL);
	}
	else
	{
		builder_result = gtk_builder_add_from_file(builder, "./mate-default-applications-properties.ui", NULL);
	}

	if (builder_result == 0)
	{
		GtkWidget* dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not load the main interface"));
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Please make sure that the applet is properly installed"));
		gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

		gtk_dialog_run(GTK_DIALOG(dialog));

		gtk_widget_destroy(dialog);
		exit(EXIT_FAILURE);
	}

	capplet->window = get_widget("preferred_apps_dialog");

	g_signal_connect(capplet->window, "response", G_CALLBACK(close_cb), NULL);

	capplet->web_combo_box = get_widget("web_browser_combobox");
	capplet->mail_combo_box = get_widget("mail_reader_combobox");
	capplet->term_combo_box = get_widget("terminal_combobox");
	capplet->media_combo_box = get_widget("media_player_combobox");
	capplet->video_combo_box = get_widget("video_combobox");
	capplet->visual_combo_box = get_widget("visual_combobox");
	capplet->mobility_combo_box = get_widget("mobility_combobox");
	capplet->text_combo_box = get_widget("text_combobox");
	capplet->file_combo_box = get_widget("filemanager_combobox");
	capplet->image_combo_box = get_widget("image_combobox");


	g_signal_connect(capplet->window, "screen-changed", G_CALLBACK(screen_changed_cb), capplet);
	screen_changed_cb(capplet->window, gdk_screen_get_default(), capplet);

	// lists
	capplet->web_browsers = g_app_info_get_all_for_type("x-scheme-handler/http");
	capplet->mail_readers = g_app_info_get_all_for_type("x-scheme-handler/mailto");
	//capplet->terminals = g_app_info_get_all_for_type("inode/directory");
	capplet->media_players = g_app_info_get_all_for_type("audio/x-vorbis+ogg");
	capplet->video_players = g_app_info_get_all_for_type("video/x-ogm+ogg");
	//capplet->visual_ats = g_app_info_get_all_for_type("inode/directory");
	//capplet->mobility_ats = g_app_info_get_all_for_type("inode/directory");
	capplet->text_editors = g_app_info_get_all_for_type("text/plain");
	capplet->image_viewers = g_app_info_get_all_for_type("image/png");
	capplet->file_managers = g_app_info_get_all_for_type("inode/directory");
	
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->web_combo_box), capplet->web_browsers, "x-scheme-handler/http");
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mail_combo_box), capplet->mail_readers, "x-scheme-handler/mailto");
	//fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->term_combo_box), capplet->terminals, "");
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->media_combo_box), capplet->media_players, "audio/x-vorbis+ogg");
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->video_combo_box), capplet->video_players, "video/x-ogm+ogg");
	//fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->visual_combo_box), capplet->visual_ats, NULL);
	//fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mobility_combo_box), capplet->mobility_ats, NULL);
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->image_combo_box), capplet->image_viewers, "image/png");
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->text_combo_box), capplet->text_editors, "text/plain");
	fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->file_combo_box), capplet->file_managers, "inode/directory");

	g_signal_connect(capplet->web_combo_box, "changed", G_CALLBACK(web_combo_changed_cb), capplet);
	g_signal_connect(capplet->mail_combo_box, "changed", G_CALLBACK(mail_combo_changed_cb), capplet);
	g_signal_connect(capplet->term_combo_box, "changed", G_CALLBACK(terminal_combo_changed_cb), capplet);
	g_signal_connect(capplet->media_combo_box, "changed", G_CALLBACK(media_combo_changed_cb), capplet);
	g_signal_connect(capplet->video_combo_box, "changed", G_CALLBACK(video_combo_changed_cb), capplet);
	g_signal_connect(capplet->visual_combo_box, "changed", G_CALLBACK(visual_combo_changed_cb), capplet);
	g_signal_connect(capplet->mobility_combo_box, "changed", G_CALLBACK(mobility_combo_changed_cb), capplet);
	g_signal_connect(capplet->image_combo_box, "changed", G_CALLBACK(image_combo_changed_cb), capplet);
	g_signal_connect(capplet->text_combo_box, "changed", G_CALLBACK(text_combo_changed_cb), capplet);
	g_signal_connect(capplet->file_combo_box, "changed", G_CALLBACK(file_combo_changed_cb), capplet);


	/* TODO: fix the name icon */
	gtk_window_set_icon_name(GTK_WINDOW (capplet->window), "preferences-desktop-default-applications");

	if (start_page != NULL)
	{
		gchar* page_name;
		GtkWidget* w;

		page_name = g_strconcat (start_page, "_vbox", NULL);

		w = get_widget(page_name);

		if (w != NULL)
		{
			GtkNotebook* nb;
			gint pindex;

			nb = GTK_NOTEBOOK(get_widget("preferred_apps_notebook"));
			pindex = gtk_notebook_page_num(nb, w);
			
			if (pindex != -1)
			{
				gtk_notebook_set_current_page(nb, pindex);
			}
		}

		g_free(page_name);
	}

	gtk_widget_show(capplet->window);

	#undef get_widget
}
Esempio n. 14
0
/**
 * fm_app_chooser_combo_box_setup
 * @combo: a #GtkComboBox
 * @mime_type: (allow-none): a #FmMimeType to select application
 * @apps: (allow-none) (element-type GAppInfo): custom list of applications
 * @sel: (allow-none): a selected application in @apps
 *
 * Setups a combobox for selecting default application either for
 * specified mime-type or from a list of pre-defined applications.
 * If @mime_type is %NULL, and @sel is provided and found in the @apps,
 * then it will be selected. If @mime_type is not %NULL then default
 * application for the @mime_type will be selected.
 * When set up, the combobox will contain a list of available applications.
 *
 * Since: 0.1.5
 */
void fm_app_chooser_combo_box_setup(GtkComboBox* combo, FmMimeType* mime_type, GList* apps, GAppInfo* sel)
{
    FmAppChooserComboBoxData* data = g_slice_new0(FmAppChooserComboBoxData);
    GtkListStore* store = gtk_list_store_new(3, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_APP_INFO);
    GtkTreeIter it;
    GList* l;
    GtkCellRenderer* render;

    gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));

    render = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE);
    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "gicon", 0);

    render = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE);
    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "text", 1);

    if(mime_type)
    {
        data->mime_type = fm_mime_type_ref(mime_type);
        apps = g_app_info_get_all_for_type(fm_mime_type_get_type(data->mime_type));
        sel =  g_app_info_get_default_for_type(fm_mime_type_get_type(data->mime_type), FALSE);
    }

    for(l = apps; l; l = l->next)
    {
        GAppInfo* app = G_APP_INFO(l->data);
        gtk_list_store_insert_with_values(store, &it, -1,
                           0, g_app_info_get_icon(app),
                           1, g_app_info_get_name(app),
                           2, app, -1);
        if(sel && g_app_info_equal(app, sel))
        {
            /* this is the initially selected app */
            data->initial_sel_iter = it;
            data->initial_sel_app = (GAppInfo*)g_object_ref(app);
        }
    }

    if(mime_type) /* if this list is retrived with g_app_info_get_all_for_type() */
    {
        if(apps)
        {
            g_list_foreach(apps, (GFunc)g_object_unref, NULL);
            g_list_free(apps);
        }
        if(sel)
            g_object_unref(sel);
    }

    gtk_list_store_append(store, &it); /* separator */
    data->separator_iter = it;

    /* other applications */
    gtk_list_store_insert_with_values(store, &it, -1,
                       0, NULL,
                       1, _("Customize"), // FIXME: should be "Customize..."
                       2, NULL, -1);
    data->other_apps_iter = it;
    gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));

    if(data->initial_sel_iter.user_data) /* intital selection is set */
    {
        data->prev_sel_iter = data->initial_sel_iter;
        gtk_combo_box_set_active_iter(combo, &data->initial_sel_iter);
    }
    gtk_combo_box_set_row_separator_func(combo, is_row_separator, data, NULL);
    g_object_unref(store);

    g_signal_connect(combo, "changed", G_CALLBACK(on_app_selected), data);
    g_object_set_qdata_full(G_OBJECT(combo), fm_qdata_id, data, free_data);
}
Esempio n. 15
0
static void
_setup_ui (OlPlayerChooser *window)
{
  OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window);
  gtk_container_set_border_width (GTK_CONTAINER (window), WINDOW_BORDER_SIZE);
  /* Setup info widgets */
  priv->info_label = GTK_LABEL (gtk_label_new (NULL));
  gtk_label_set_line_wrap (priv->info_label, TRUE);
  gtk_misc_set_alignment (GTK_MISC (priv->info_label), 0.0, 0.0);
  priv->info_icon = GTK_IMAGE (gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
                                                         GTK_ICON_SIZE_DIALOG));
  GtkWidget *info_box = gtk_hbox_new (FALSE, 10);
  gtk_box_pack_start (GTK_BOX (info_box),
                      GTK_WIDGET (priv->info_icon),
                      FALSE,    /* expand */
                      FALSE,    /* fill */
                      0);
  gtk_box_pack_start (GTK_BOX (info_box),
                      GTK_WIDGET (priv->info_label),
                      TRUE,     /* expand */
                      TRUE,     /* fill */
                      0);
  /* Setup app choosers */
  priv->page_button_panel = GTK_BOX (gtk_hbox_new (FALSE, 0));
  priv->chooser_panel = GTK_BOX (gtk_hbox_new (FALSE, 0));
  _new_page (window, _("Supported players"));
  _new_page (window, _("All players"));
  _set_apps_to_page (window,
                     ALL_CHOOSER_INDEX,
                     g_app_info_get_all_for_type ("audio/mp3"));
  GtkWidget *apps_frame = gtk_frame_new (_("Choose a player to launch"));
  GtkBox *page_vbox = GTK_BOX (gtk_vbox_new (FALSE, 0));
  gtk_widget_show (GTK_WIDGET (page_vbox));
  gtk_box_pack_start (page_vbox,
                      GTK_WIDGET (priv->page_button_panel),
                      FALSE,    /* expand */
                      FALSE,    /* fill */
                      0);       /* padding */
  gtk_box_pack_end (page_vbox,
                    GTK_WIDGET (priv->chooser_panel),
                    FALSE,    /* expand */
                    FALSE,    /* fill */
                    0);       /* padding */
  gtk_container_add (GTK_CONTAINER (apps_frame), GTK_WIDGET (page_vbox));
  /* Setup custom command */
  priv->custom_cmd_panel = GTK_BOX (gtk_hbox_new (FALSE, 5));
  GtkWidget *cmd_label = gtk_label_new (_("Use command:"));
  GtkWidget *cmd_entry = gtk_entry_new ();
  priv->cmd_entry = GTK_ENTRY (cmd_entry);
  gtk_entry_set_activates_default (priv->cmd_entry, TRUE);
  gtk_entry_set_completion (priv->cmd_entry, _new_bin_completion ());
  GtkWidget *launch_button = gtk_button_new_with_label (_("Launch"));
  gtk_widget_set_can_default (launch_button, TRUE);
  gtk_window_set_default (GTK_WINDOW (window), launch_button);
  priv->launch_button = launch_button;
  g_signal_connect (launch_button,
                    "clicked",
                    G_CALLBACK (_launch_button_clicked_cb),
                    window);
  gtk_box_pack_start (priv->custom_cmd_panel, cmd_label, FALSE, TRUE, 0);
  gtk_box_pack_start (priv->custom_cmd_panel, cmd_entry, TRUE, TRUE, 0);
  gtk_box_pack_start (priv->custom_cmd_panel, launch_button, FALSE, TRUE, 0);

  GtkWidget *final_hbox = gtk_hbox_new (FALSE, 0);
  GtkWidget *remember_button = gtk_check_button_new_with_label (_("Remember my choice"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (remember_button), TRUE);
  priv->remember_button = remember_button;
  gtk_box_pack_start (GTK_BOX (final_hbox), remember_button, FALSE, TRUE, 0);
  /* Setup the whole dialog */
  GtkWidget *vbox = gtk_dialog_get_content_area (GTK_DIALOG (window));
  gtk_box_set_spacing (GTK_BOX (vbox), 10);
  gtk_box_pack_start (GTK_BOX (vbox),
                      info_box,
                      FALSE,
                      FALSE,
                      0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      apps_frame,
                      FALSE,
                      FALSE,
                      0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      GTK_WIDGET (priv->custom_cmd_panel),
                      FALSE,
                      TRUE,
                      0);
  gtk_box_pack_end (GTK_BOX (vbox),
                    final_hbox,
                    FALSE,
                    TRUE,
                    0);
  gtk_widget_show (vbox);
  gtk_widget_show_all (info_box);
  gtk_widget_show (apps_frame);
  gtk_widget_show_all (GTK_WIDGET (priv->page_button_panel));
  gtk_widget_show (GTK_WIDGET (priv->chooser_panel));
  gtk_widget_show_all (GTK_WIDGET (priv->custom_cmd_panel));
  gtk_widget_show_all (GTK_WIDGET (final_hbox));

  gtk_dialog_add_button (GTK_DIALOG (window),
                         GTK_STOCK_CLOSE,
                         GTK_RESPONSE_CLOSE);
  gtk_window_set_title (GTK_WINDOW (window), _("Choose a player to launch"));
  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
}
/* 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;
}
Esempio n. 17
0
File: apps.c Progetto: LEW21/glib
int
main (int argc, char **argv)
{
  setlocale (LC_ALL, "");

  if (argv[1] == NULL)
    ;
  else if (g_str_equal (argv[1], "list"))
    {
      GList *all, *i;

      all = g_app_info_get_all ();
      for (i = all; i; i = i->next)
        g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
      g_list_free_full (all, g_object_unref);
    }
  else if (g_str_equal (argv[1], "search"))
    {
      gchar ***results;
      gint i, j;

      results = g_desktop_app_info_search (argv[2]);
      for (i = 0; results[i]; i++)
        {
          for (j = 0; results[i][j]; j++)
            g_print ("%s%s", j ? " " : "", results[i][j]);
          g_print ("\n");
          g_strfreev (results[i]);
        }
      g_free (results);
    }
  else if (g_str_equal (argv[1], "implementations"))
    {
      GList *results;

      results = g_desktop_app_info_get_implementations (argv[2]);
      print_app_list (results);
    }
  else if (g_str_equal (argv[1], "show-info"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          print (g_app_info_get_id (info));
          print (g_app_info_get_name (info));
          print (g_app_info_get_display_name (info));
          print (g_app_info_get_description (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "default-for-type"))
    {
      GAppInfo *info;

      info = g_app_info_get_default_for_type (argv[2], FALSE);

      if (info)
        {
          print (g_app_info_get_id (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "recommended-for-type"))
    {
      GList *list;

      list = g_app_info_get_recommended_for_type (argv[2]);
      print_app_list (list);
    }
  else if (g_str_equal (argv[1], "all-for-type"))
    {
      GList *list;

      list = g_app_info_get_all_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "fallback-for-type"))
    {
      GList *list;

      list = g_app_info_get_fallback_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "should-show"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
          g_object_unref (info);
        }
    }

  return 0;
}