/********************************************************************* * ... * * ********************************************************************/ gboolean fm_file_info_job_run (FmJob *fmjob) { FmFileInfoJob *job = (FmFileInfoJob*) fmjob; GError *err = NULL; GList *l; for (l = fm_list_peek_head_link (job->file_infos); !fm_job_is_cancelled (fmjob) && l; ) { FmFileInfo *file_info = (FmFileInfo*) l->data; GList *next = l->next; job->current = file_info->path; if (fm_path_is_native (file_info->path)) { char *path_str = fm_path_to_str (file_info->path); // FileInfo rework: new function for testing... // this one is not cancellable and doesn't handle errors... // if (!fm_file_info_job_get_info_for_native_file (FM_JOB (job), file_info, path_str, &err)) if (!fm_file_info_set_for_native_file (file_info, path_str)) { //~ FmJobErrorAction act = fm_job_emit_error (FM_JOB(job), err, FM_JOB_ERROR_MILD); //~ //~ g_error_free (err); //~ err = NULL; //~ //~ if (act == FM_JOB_RETRY) //~ continue; DEBUG ("fm_file_info_set_for_native_file: error reading %s\n", path_str); next = l->next; fm_list_delete_link (job->file_infos, l); // Also calls unref... } g_free (path_str); } else { GFile *gf; if (fm_path_is_virtual (file_info->path)) { // This is a xdg menu if (fm_path_is_xdg_menu (file_info->path)) { MenuCache *mc; MenuCacheDir *dir; char *path_str = fm_path_to_str (file_info->path); char *menu_name = path_str + 5, ch; char *dir_name; while (*menu_name == '/') ++menu_name; dir_name = menu_name; while (*dir_name && *dir_name != '/') ++dir_name; ch = *dir_name; *dir_name = '\0'; menu_name = g_strconcat (menu_name, ".menu", NULL); mc = menu_cache_lookup_sync (menu_name); g_free (menu_name); if (*dir_name && !(*dir_name == '/' && dir_name[1] == '\0')) { char *tmp = g_strconcat ("/", menu_cache_item_get_id (MENU_CACHE_ITEM(menu_cache_get_root_dir (mc))), dir_name, NULL); dir = menu_cache_get_dir_from_path (mc, tmp); g_free (tmp); } else { dir = menu_cache_get_root_dir (mc); } if (dir) { fm_file_info_set_from_menu_cache_item (file_info, (MenuCacheItem*) dir); } else { next = l->next; fm_list_delete_link (job->file_infos, l); // Also calls unref... } g_free (path_str); menu_cache_unref (mc); l = l->next; continue; } } gf = fm_path_to_gfile (file_info->path); if (!fm_file_info_job_get_info_for_gfile (FM_JOB (job), file_info, gf, &err)) { FmJobErrorAction act = fm_job_emit_error (FM_JOB (job), err, FM_JOB_ERROR_MILD); g_error_free (err); err = NULL; if (act == FM_JOB_RETRY) continue; next = l->next; fm_list_delete_link (job->file_infos, l); // Also calls unref... } g_object_unref (gf); } l = next; } return TRUE; }
int main (int argc, char **argv) { gpointer reload_notify_id = NULL; GError *error = NULL; gchar *menu = NULL; OB_Menu ob_context = { 0 }; gboolean show_gnome = FALSE; gboolean show_kde = FALSE; gboolean show_xfce = FALSE; gboolean show_rox = FALSE; gboolean persistent = FALSE; gchar **app_menu = NULL; gchar *output = NULL; gchar *terminal = "xterm -e"; gint ret; /* * TODO: Registered OnlyShowIn Environments * Ref: http://standards.freedesktop.org/menu-spec/latest/apb.html * * GNOME GNOME Desktop * KDE KDE Desktop * LXDE LXDE Desktop * MATE MATÉ Desktop * Razor Razor-qt Desktop * ROX ROX Desktop * TDE Trinity Desktop * Unity Unity Shell * XFCE XFCE Desktop * Old Legacy menu systems */ /* removed startup-notify option and associated code as pekwm doesn't support it * 2013-08-21 NF */ GOptionEntry entries[] = { { "comment", 'c', 0, G_OPTION_ARG_NONE, &ob_context.comment, "Show generic name instead of application name", NULL }, { "terminal", 't', 0, G_OPTION_ARG_STRING, &terminal, "Terminal command (default xterm -e)", "cmd" }, { "gnome", 'g', 0, G_OPTION_ARG_NONE, &show_gnome, "Show GNOME entries", NULL }, { "kde", 'k', 0, G_OPTION_ARG_NONE, &show_kde, "Show KDE entries", NULL }, { "xfce", 'x', 0, G_OPTION_ARG_NONE, &show_xfce, "Show XFCE entries", NULL }, { "rox", 'r', 0, G_OPTION_ARG_NONE, &show_rox, "Show ROX entries", NULL }, { "persistent",'p', 0, G_OPTION_ARG_NONE, &persistent, "stay active", NULL }, { "output", 'o', 0, G_OPTION_ARG_STRING, &output, "file to write data to", NULL }, { "noicons", 'i', 0, G_OPTION_ARG_NONE, &ob_context.no_icons, "Don't display icons in menu", NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &app_menu, NULL, "[file.menu]" }, {NULL} }; GOptionContext *help_context = NULL; setlocale (LC_ALL, ""); help_context = g_option_context_new (" - Pekwm menu generator " VERSION); g_option_context_set_help_enabled (help_context, TRUE); g_option_context_add_main_entries (help_context, entries, NULL); g_option_context_parse (help_context, &argc, &argv, &error); if (error) { g_print ("%s\n", error->message); g_error_free (error); return 1; } g_option_context_free (help_context); #ifdef WITH_ICONS gtk_init (&argc, &argv); icon_theme = gtk_icon_theme_get_default (); #endif if (output) ob_context.output = g_build_filename (g_get_user_cache_dir (), output, NULL); else ob_context.output = NULL; if (terminal) ob_context.terminal_cmd = terminal; if (show_gnome) ob_context.show_flag |= SHOW_IN_GNOME; if (show_kde) ob_context.show_flag |= SHOW_IN_KDE; if (show_xfce) ob_context.show_flag |= SHOW_IN_XFCE; if (show_rox) ob_context.show_flag |= SHOW_IN_ROX; // wait for the menu to get ready MenuCache *menu_cache = menu_cache_lookup_sync (app_menu?*app_menu:"applications.menu"); if (!menu_cache ) { g_free (menu); g_warning ("Cannot connect to menu-cache :/"); return 1; } // display the menu anyway ret = display_menu(menu_cache, &ob_context); if (persistent) { // menucache used to reload the cache after a call to menu_cache_lookup* () // It's not true anymore with version >= 0.4.0. reload_notify_id = menu_cache_add_reload_notify (menu_cache, (MenuCacheReloadNotify) display_menu, &ob_context); // install signals handler signal (SIGTERM, sig_term_handler); signal (SIGINT, sig_term_handler); // run main loop loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_main_loop_unref (loop); menu_cache_remove_reload_notify (menu_cache, reload_notify_id); } menu_cache_unref (menu_cache); g_free (menu); if (ob_context.output) g_free (ob_context.output); return ret; }
/** * 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 (app_name && app_name[0] && 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_sync("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; }