AppMenuView::AppMenuView(QWidget* parent): model_(new QStandardItemModel()), menu_cache(NULL), menu_cache_reload_notify(NULL), QTreeView(parent) { setHeaderHidden(true); setSelectionMode(SingleSelection); // initialize model // TODO: share one model among all app menu view widgets // ensure that we're using lxmenu-data (FIXME: should we do this?) QByteArray oldenv = qgetenv("XDG_MENU_PREFIX"); qputenv("XDG_MENU_PREFIX", "lxde-"); menu_cache = menu_cache_lookup("applications.menu"); // if(!oldenv.isEmpty()) qputenv("XDG_MENU_PREFIX", oldenv); // restore the original value if needed if(menu_cache) { MenuCacheDir* dir = menu_cache_dup_root_dir(menu_cache); menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, _onMenuCacheReload, this); if(dir) { /* content of menu is already loaded */ addMenuItems(NULL, dir); menu_cache_item_unref(MENU_CACHE_ITEM(dir)); } } setModel(model_); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(selectionChanged())); selectionModel()->select(model_->index(0, 0), QItemSelectionModel::SelectCurrent); }
void gtk_run() { GtkWidget *entry, *hbox, *img; if( win ) { gtk_window_present(GTK_WINDOW(win)); return; } win = gtk_dialog_new_with_buttons( _("Run"), NULL, GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL ); gtk_dialog_set_alternative_button_order((GtkDialog*)win, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_dialog_set_default_response( (GtkDialog*)win, GTK_RESPONSE_OK ); entry = gtk_entry_new(); gtk_entry_set_activates_default( (GtkEntry*)entry, TRUE ); gtk_box_pack_start( (GtkBox*)((GtkDialog*)win)->vbox, gtk_label_new(_("Enter the command you want to execute:")), FALSE, FALSE, 8 ); hbox = gtk_hbox_new( FALSE, 2 ); img = gtk_image_new_from_stock( GTK_STOCK_EXECUTE, GTK_ICON_SIZE_DIALOG ); gtk_box_pack_start( (GtkBox*)hbox, img, FALSE, FALSE, 4 ); gtk_box_pack_start( (GtkBox*)hbox, entry, TRUE, TRUE, 4 ); gtk_box_pack_start( (GtkBox*)((GtkDialog*)win)->vbox, hbox, FALSE, FALSE, 8 ); g_signal_connect( win, "response", G_CALLBACK(on_response), entry ); gtk_window_set_position( (GtkWindow*)win, GTK_WIN_POS_CENTER ); gtk_window_set_default_size( (GtkWindow*)win, 360, -1 ); gtk_widget_show_all( win ); setup_auto_complete( (GtkEntry*)entry ); gtk_widget_show( win ); g_signal_connect(entry ,"changed", G_CALLBACK(on_entry_changed), img); /* get all apps */ menu_cache = menu_cache_lookup(g_getenv("XDG_MENU_PREFIX") ? "applications.menu" : "lxde-applications.menu" ); if( menu_cache ) { app_list = (GSList*)menu_cache_list_all_apps(menu_cache); reload_notify_id = menu_cache_add_reload_notify(menu_cache, reload_apps, NULL); } }
GtkWidget *fm_app_menu_view_new(void) { GtkWidget* view; GtkTreeViewColumn* col; GtkCellRenderer* render; if(!store) { static GType menu_cache_item_type = 0; if(G_UNLIKELY(!menu_cache_item_type)) menu_cache_item_type = g_boxed_type_register_static("MenuCacheItem", (GBoxedCopyFunc)menu_cache_item_ref, (GBoxedFreeFunc)menu_cache_item_unref); store = gtk_tree_store_new(N_COLS, G_TYPE_ICON, /*GDK_TYPE_PIXBUF, */G_TYPE_STRING, menu_cache_item_type); g_object_weak_ref(G_OBJECT(store), (GWeakNotify)destroy_store, NULL); menu_cache = menu_cache_lookup("applications.menu"); if(menu_cache) { MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache); menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, on_menu_cache_reload, NULL); if(dir) /* content of menu is already loaded */ add_menu_items(NULL, dir); } } else g_object_ref(store); view = gtk_tree_view_new_with_model((GtkTreeModel*)store); render = gtk_cell_renderer_pixbuf_new(); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, _("Installed Applications")); gtk_tree_view_column_pack_start(col, render, FALSE); gtk_tree_view_column_set_attributes(col, render, "gicon", COL_ICON, NULL); render = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, render, TRUE); gtk_tree_view_column_set_attributes(col, render, "text", COL_TITLE, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); g_object_unref(store); return view; }
AppLinkProvider::AppLinkProvider(): CommandProvider() { #ifdef HAVE_MENU_CACHE menu_cache_init(0); mMenuCache = menu_cache_lookup(XdgMenu::getMenuFileName().toLocal8Bit()); if(mMenuCache) mMenuCacheNotify = menu_cache_add_reload_notify(mMenuCache, (MenuCacheReloadNotify)menuCacheReloadNotify, this); else mMenuCacheNotify = 0; #else mXdgMenu = new XdgMenu(); mXdgMenu->setEnvironments(QStringList() << "X-LXQT" << "LXQt"); connect(mXdgMenu, SIGNAL(changed()), this, SLOT(update())); mXdgMenu->read(XdgMenu::getMenuFileName()); update(); #endif }
/** * fm_app_menu_view_new * * Creates new application tree widget. * * Returns: (transfer full): a new widget. * * Since: 0.1.0 */ GtkTreeView *fm_app_menu_view_new(void) { GtkTreeView* view; GtkTreeViewColumn* col; GtkCellRenderer* render; if(!store) { static GType menu_cache_item_type = 0; char* oldenv; if(G_UNLIKELY(!menu_cache_item_type)) menu_cache_item_type = g_boxed_type_register_static("MenuCacheItem", (GBoxedCopyFunc)menu_cache_item_ref, (GBoxedFreeFunc)menu_cache_item_unref); store = gtk_tree_store_new(N_COLS, G_TYPE_ICON, /*GDK_TYPE_PIXBUF, */G_TYPE_STRING, menu_cache_item_type); g_object_weak_ref(G_OBJECT(store), destroy_store, NULL); /* ensure that we're using lxmenu-data */ oldenv = g_strdup(g_getenv("XDG_MENU_PREFIX")); g_setenv("XDG_MENU_PREFIX", "lxde-", TRUE); menu_cache = menu_cache_lookup("applications.menu"); if(oldenv) { g_setenv("XDG_MENU_PREFIX", oldenv, TRUE); g_free(oldenv); } else g_unsetenv("XDG_MENU_PREFIX"); if(menu_cache) { #if MENU_CACHE_CHECK_VERSION(0, 4, 0) MenuCacheDir* dir = menu_cache_dup_root_dir(menu_cache); #else MenuCacheDir* dir = menu_cache_get_root_dir(menu_cache); #endif menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, on_menu_cache_reload, NULL); if(dir) /* content of menu is already loaded */ { add_menu_items(NULL, dir); #if MENU_CACHE_CHECK_VERSION(0, 4, 0) menu_cache_item_unref(MENU_CACHE_ITEM(dir)); #endif } } } else g_object_ref(store); view = (GtkTreeView*)gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); render = gtk_cell_renderer_pixbuf_new(); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, _("Installed Applications")); gtk_tree_view_column_pack_start(col, render, FALSE); gtk_tree_view_column_set_attributes(col, render, "gicon", COL_ICON, NULL); render = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, render, TRUE); gtk_tree_view_column_set_attributes(col, render, "text", COL_TITLE, NULL); gtk_tree_view_append_column(view, col); g_object_unref(store); return view; }
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; }