PRIVATE GList* _get_x_category(GDesktopAppInfo* info) { GList* categories = NULL; const char* all_categories = g_desktop_app_info_get_categories(info); if (all_categories == NULL) { categories = g_list_append(categories, GINT_TO_POINTER(OTHER_CATEGORY_ID)); return categories; } g_debug("[%s] %s", __func__, g_desktop_app_info_get_filename(info)); gboolean has_other_id = FALSE; gchar** x_categories = g_strsplit(all_categories, ";", 0); for (int i = 0; x_categories[i] != NULL && x_categories[i][0] != '\0'; ++i) { char* lower_case = g_utf8_casefold(x_categories[i], -1); int id = find_category_id(lower_case); g_free(lower_case); g_debug("[%s] #%s#:category name:#%s#:%d", __func__, x_categories[i], lower_case, id); if (id == OTHER_CATEGORY_ID) has_other_id = TRUE; categories = g_list_append(categories, GINT_TO_POINTER(id)); } if (has_other_id) categories = _remove_other_category(categories); if (categories == NULL) categories = g_list_append(categories, GINT_TO_POINTER(OTHER_CATEGORY_ID)); for (GList* iter = g_list_first(categories); iter != NULL; iter = g_list_next(iter)) g_debug("[%s] using %d", __func__, GPOINTER_TO_INT(iter->data)); g_strfreev(x_categories); return categories; }
JS_EXPORT_API double launcher_weight(GDesktopAppInfo* info, const char* key) { double weight = 0.0; /* desktop file information */ const char* path = g_desktop_app_info_get_filename(info); char* basename = g_path_get_basename(path); *strchr(basename, '.') = '\0'; weight += _get_weight(basename, key, _pred, FILENAME_WEIGHT); g_free(basename); const char* gname = g_desktop_app_info_get_generic_name(info); weight += _get_weight(gname, key, _pred, GENERIC_NAME_WEIGHT); const char* const* keys = g_desktop_app_info_get_keywords(info); if (keys != NULL) { size_t n = g_strv_length((char**)keys); for (size_t i=0; i<n; i++) { weight += _get_weight(keys[i], key, _pred, KEYWORD_WEIGHT); } } const char* categories = g_desktop_app_info_get_categories(info); if (categories) { gchar** category_names = g_strsplit(categories, ";", -1); gsize len = g_strv_length(category_names) - 1; for (gsize i = 0; i < len; ++i) { weight += _get_weight(category_names[i], key, _pred, CATEGORY_WEIGHT); } g_strfreev(category_names); } /* application information */ const char* name = g_app_info_get_name((GAppInfo*)info); weight += _get_weight(name, key, _pred, NAME_WEIGHT); const char* dname = g_app_info_get_display_name((GAppInfo*)info); weight += _get_weight(dname, key, _pred, DISPLAY_NAME_WEIGHT); const char* desc = g_app_info_get_description((GAppInfo*)info); weight += _get_weight(desc, key, _pred, DESCRIPTION_WEIGHT); const char* exec = g_app_info_get_executable((GAppInfo*)info); weight += _get_weight(exec, key, _pred, EXECUTABLE_WEIGHT); return weight; }
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 }
static DesktopEntryResultCode desktop_entry_load (DesktopEntry *entry) { if (strstr (entry->path, "/menu-xdg/")) return DESKTOP_ENTRY_LOAD_FAIL_OTHER; if (entry->type == DESKTOP_ENTRY_DESKTOP) { GKeyFile *key_file = NULL; DesktopEntryDesktop *entry_desktop = (DesktopEntryDesktop*)entry; const char *categories_str; entry_desktop->appinfo = g_desktop_app_info_new_from_filename (entry->path); if (!G_IS_DESKTOP_APP_INFO (((DesktopEntryDesktop*)entry)->appinfo)) { menu_verbose ("Failed to load \"%s\"\n", entry->path); return DESKTOP_ENTRY_LOAD_FAIL_APPINFO; } categories_str = g_desktop_app_info_get_categories (entry_desktop->appinfo); if (categories_str) { char **categories; int i; categories = g_strsplit (categories_str, ";", -1); entry_desktop->categories = g_new0 (GQuark, g_strv_length (categories) + 1); for (i = 0; categories[i]; i++) entry_desktop->categories[i] = g_quark_from_string (categories[i]); g_strfreev (categories); } key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, entry->path, 0, NULL)) entry_desktop->showin = TRUE; else entry_desktop->showin = key_file_get_show_in (key_file); g_key_file_free (key_file); return DESKTOP_ENTRY_LOAD_SUCCESS; } else if (entry->type == DESKTOP_ENTRY_DIRECTORY) { GKeyFile *key_file = NULL; GError *error = NULL; DesktopEntryResultCode rescode = DESKTOP_ENTRY_LOAD_SUCCESS; key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, entry->path, 0, &error)) { rescode = DESKTOP_ENTRY_LOAD_FAIL_OTHER; goto out; } if (!desktop_entry_load_directory (entry, key_file, &error)) { rescode = DESKTOP_ENTRY_LOAD_FAIL_OTHER; goto out; } rescode = DESKTOP_ENTRY_LOAD_SUCCESS; out: g_key_file_free (key_file); if (rescode == DESKTOP_ENTRY_LOAD_FAIL_OTHER) { if (error) { menu_verbose ("Failed to load \"%s\": %s\n", entry->path, error->message); g_error_free (error); } else menu_verbose ("Failed to load \"%s\"\n", entry->path); } return rescode; } else g_assert_not_reached (); return DESKTOP_ENTRY_LOAD_FAIL_OTHER; }