//=========================================== // Lumina-DE source code // Copyright (c) 2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "LAppMenuPlugin.h" #include "../../LSession.h" #include LAppMenuPlugin::LAppMenuPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ button = new QToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); mainmenu = new QMenu(this); button->setMenu( mainmenu ); button->setPopupMode(QToolButton::InstantPopup); this->layout()->setContentsMargins(0,0,0,0); this->layout()->addWidget(button); connect(mainmenu, SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed())); connect(mainmenu, SIGNAL(triggered(QAction*)), this, SLOT(LaunchItem(QAction*)) ); connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateMenu())); QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes QTimer::singleShot(0,this, SLOT(UpdateMenu()) ); } LAppMenuPlugin::~LAppMenuPlugin(){ } void LAppMenuPlugin::updateButtonVisuals(){ button->setToolTip( tr("Quickly launch applications or open files")); button->setText( tr("Applications") ); //Use the PC-BSD icon by default (or the Lumina icon for non-PC-BSD systems) button->setIcon( LXDG::findIcon("start-here-lumina","Lumina-DE") ); } // ======================== // PRIVATE FUNCTIONS // ======================== void LAppMenuPlugin::LaunchItem(QAction* item){ QString appFile = item->whatsThis(); if(appFile.startsWith("internal::")){ appFile = appFile.section("::",1,50); //cut off the "internal" flag if(appFile=="logout"){ LSession::handle()->systemWindow(); } }else if(!appFile.isEmpty()){ LSession::LaunchApplication("lumina-open "+appFile); } } void LAppMenuPlugin::UpdateMenu(){ mainmenu->clear(); QHash > *HASH = LSession::handle()->applicationMenu()->currentAppHash(); //Now Re-create the menu (orignally copied from the AppMenu class) bool ok; //for checking inputs //Add link to the file manager QAction *tmpact = mainmenu->addAction( LXDG::findIcon("user-home", ""), tr("Browse Files") ); tmpact->setWhatsThis("\""+QDir::homePath()+"\""); //--Look for the app store XDGDesktop store = LXDG::loadDesktopFile(LOS::AppStoreShortcut(), ok); if(ok){ tmpact = mainmenu->addAction( LXDG::findIcon(store.icon, ""), tr("Install Applications") ); tmpact->setWhatsThis("\""+store.filePath+"\""); } //--Look for the control panel store = LXDG::loadDesktopFile(LOS::ControlPanelShortcut(), ok); if(ok){ tmpact = mainmenu->addAction( LXDG::findIcon(store.icon, ""), tr("Control Panel") ); tmpact->setWhatsThis("\""+store.filePath+"\""); } mainmenu->addSeparator(); //--Now create the sub-menus QStringList cats = HASH->keys(); cats.sort(); //make sure they are alphabetical for(int i=0; isetIcon(LXDG::findIcon(icon,"")); QList appL = HASH->value(cats[i]); for( int a=0; asetToolTip(appL[a].comment); act->setWhatsThis("\""+appL[a].filePath+"\""); menu->addAction(act); }else{ //This app has additional actions - make this a sub menu // - first the main menu/action QMenu *submenu = new QMenu(appL[a].name, menu); submenu->setIcon( LXDG::findIcon(appL[a].icon,"") ); //This is the normal behavior - not a special sub-action (although it needs to be at the top of the new menu) QAction *act = new QAction(LXDG::findIcon(appL[a].icon, ""), appL[a].name, submenu); act->setToolTip(appL[a].comment); act->setWhatsThis(appL[a].filePath); submenu->addAction(act); //Now add entries for every sub-action listed for(int sa=0; sasetToolTip(appL[a].comment); sact->setWhatsThis("-action \""+appL[a].actions[sa].ID+"\" \""+appL[a].filePath+"\""); submenu->addAction(sact); } menu->addMenu(submenu); } }//end loop over apps within this category mainmenu->addMenu(menu); } //end loop over categories //Now add any logout options mainmenu->addSeparator(); //QMenu *tmpmenu = mainmenu->addMenu(LXDG::findIcon("system-log-out",""), tr("Leave")); tmpact =mainmenu->addAction(LXDG::findIcon("system-log-out"),tr("Leave")); tmpact->setWhatsThis("internal::logout"); }