示例#1
0
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);
}
示例#2
0
文件: gtk-run.c 项目: bookwar/lxpanel
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);
    }
}
示例#3
0
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;
}
示例#4
0
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
}
示例#5
0
/**
 * 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;
}
示例#6
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;
}