Example #1
0
void PanelKMenu::initialize()
{
//    kDebug(1210) << "PanelKMenu::initialize()";
    updateRecent();

    if (initialized())
    {
        return;
    }

    if (loadSidePixmap())
    {
        // in case we've been through here before, let's disconnect
        disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
                   this, SLOT(paletteChanged()));
        connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
                this, SLOT(paletteChanged()));
    }
    else
    {
        sidePixmap = sideTilePixmap = QPixmap();
    }

    // add services
    PanelServiceMenu::initialize();

    /*
     FIXME: no more insertTitle! now what?
    if (KickerSettings::showMenuTitles())
    {
        int id;
        id = insertTitle(i18n("All Applications"), -1, 0);
        setItemEnabled( id, false );
        id = insertTitle(i18n("Actions"), -1 , -1);
        setItemEnabled( id, false );
    }
    */

    // create recent menu section
    createRecentMenuItems();

    bool need_separator = false;

    // insert bookmarks
    if (KickerSettings::useBookmarks() && KAuthorized::authorizeKAction("bookmarks"))
    {
        // Need to create a new popup each time, it's deleted by subMenus.clear()
        KMenu * bookmarkParent = new KMenu(this);
        bookmarkParent->setObjectName("bookmarks" );
        delete bookmarkMenu; // can't reuse old one, the popup has been deleted
        bookmarkMenu = new KBookmarkMenu( KBookmarkManager::userBookmarksManager(), 0, bookmarkParent, actionCollection );

        insertItem(Plasma::menuIconSet("bookmark"),
                   i18n("Bookmarks"), bookmarkParent);

        subMenus.append(bookmarkParent);
        need_separator = true;
    }

    // insert quickbrowser
    if (KickerSettings::useBrowser())
    {
        PanelQuickBrowser *browserMnu = new PanelQuickBrowser(this);
        browserMnu->initialize();

        insertItem(Plasma::menuIconSet("kdisknav"),
                   i18n("Quick Browser"),
                   Plasma::reduceMenu(browserMnu));
        subMenus.append(browserMnu);
        need_separator = true;
    }

    // insert dynamic menus
    QStringList menu_ext = KickerSettings::menuExtensions();
    if (!menu_ext.isEmpty())
    {
        for (QStringList::ConstIterator it=menu_ext.begin(); it!=menu_ext.end(); ++it)
        {
            MenuInfo info(*it);
            if (!info.isValid())
               continue;

            KPanelMenu *menu = info.load();
            if (menu)
            {
                insertItem(Plasma::menuIconSet(info.icon()), info.name(), menu);
                dynamicSubMenus.append(menu);
                need_separator = true;
            }
        }
    }

    if (need_separator)
        addSeparator();

    // run command
    if (KAuthorized::authorizeKAction("run_command"))
    {
        insertItem(Plasma::menuIconSet("system-run"),
                   i18n("Run Command..."),
                   this,
                   SLOT( slotRunCommand()));
        addSeparator();
    }

    if (KDisplayManager().isSwitchable() && KAuthorized::authorizeKAction("switch_user"))
    {
        sessionsMenu = new QMenu( this );
        insertItem(Plasma::menuIconSet("switchuser"),
                   i18n("Switch User"), sessionsMenu);
        connect( sessionsMenu, SIGNAL(aboutToShow()), SLOT(slotPopulateSessions()) );
        connect( sessionsMenu, SIGNAL(activated(int)), SLOT(slotSessionActivated(int)) );
    }

    /*
      If  the user configured ksmserver to
    */
    KConfig ksmserver("ksmserverrc", KConfig::CascadeConfig);
    if (ksmserver.group("General").readEntry( "loginMode" ) == "restoreSavedSession")
    {
        insertItem(Plasma::menuIconSet("document-save"),
                   i18n("Save Session"), this, SLOT(slotSaveSession()));
    }

    if (KAuthorized::authorizeKAction("lock_screen"))
    {
        insertItem(Plasma::menuIconSet("system-lock-screen"),
                   i18n("Lock Session"), this, SLOT(slotLock()));
    }

    if (KAuthorized::authorizeKAction("logout"))
    {
        insertItem(Plasma::menuIconSet("application-exit"),
                   i18n("Log Out..."), this, SLOT(slotLogout()));
    }

#if 0
    // WABA: tear off handles don't work together with dynamically updated
    // menus. We can't update the menu while torn off, and we don't know
    // when it is torn off.
    if (KGlobalSettings::insertTearOffHandle())
      insertTearOffHandle();
#endif

    setInitialized(true);
}