1 //===========================================
2 // Lumina-DE source code
3 // Copyright (c) 2015, Ken Moore
4 // Available under the 3-clause BSD license
5 // See the LICENSE file for full details
6 //===========================================
7 #include "LAppMenuPlugin.h"
8 #include "../../LSession.h"
9
10 #include <LuminaXDG.h>
11
LAppMenuPlugin(QWidget * parent,QString id,bool horizontal)12 LAppMenuPlugin::LAppMenuPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){
13 button = new QToolButton(this);
14 button->setAutoRaise(true);
15 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
16 mainmenu = new QMenu(this);
17 button->setMenu( mainmenu );
18 button->setPopupMode(QToolButton::InstantPopup);
19 this->layout()->setContentsMargins(0,0,0,0);
20 this->layout()->addWidget(button);
21
22 connect(mainmenu, SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed()));
23 connect(mainmenu, SIGNAL(triggered(QAction*)), this, SLOT(LaunchItem(QAction*)) );
24 connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateMenu()));
25 QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes
26 QTimer::singleShot(0,this, SLOT(UpdateMenu()) );
27 //Setup the global shortcut handling for opening the start menu
28 connect(QApplication::instance(), SIGNAL(StartButtonActivated()), this, SLOT(shortcutActivated()) );
29 LSession::handle()->registerStartButton(this->type());
30 }
31
~LAppMenuPlugin()32 LAppMenuPlugin::~LAppMenuPlugin(){
33
34 }
35
updateButtonVisuals()36 void LAppMenuPlugin::updateButtonVisuals(){
37 button->setToolTip( tr("Quickly launch applications or open files"));
38 button->setText( tr("Applications") );
39 //Use the TrueOS icon by default (or the Lumina icon for non-TrueOS systems)
40 button->setIcon( LXDG::findIcon("start-here-lumina","Lumina-DE") );
41 }
42
43 // ========================
44 // PRIVATE FUNCTIONS
45 // ========================
shortcutActivated()46 void LAppMenuPlugin::shortcutActivated(){
47 if(LSession::handle()->registerStartButton(this->type())){
48 if(button->menu()->isVisible()){ button->menu()->hide(); }
49 else{ button->showMenu(); }
50 }
51 }
52
LaunchItem(QAction * item)53 void LAppMenuPlugin::LaunchItem(QAction* item){
54 QString appFile = item->whatsThis();
55 if(appFile.startsWith("internal::")){
56 appFile = appFile.section("::",1,50); //cut off the "internal" flag
57 if(appFile=="logout"){ LSession::handle()->systemWindow(); }
58 }else if(!appFile.isEmpty()){
59 LSession::LaunchApplication("lumina-open "+appFile);
60 }
61 }
62
UpdateMenu()63 void LAppMenuPlugin::UpdateMenu(){
64 mainmenu->clear();
65 QHash<QString, QList<XDGDesktop*> > *HASH = LSession::handle()->applicationMenu()->currentAppHash();
66 //Now Re-create the menu (orignally copied from the AppMenu class)
67 //Add link to the file manager
68 QAction *tmpact = mainmenu->addAction( LXDG::findIcon("user-home", ""), tr("Browse Files") );
69 tmpact->setWhatsThis("\""+QDir::homePath()+"\"");
70 //--Look for the app store
71 XDGDesktop store(LOS::AppStoreShortcut());
72 if(store.isValid()){
73 tmpact = mainmenu->addAction( LXDG::findIcon(store.icon, ""), tr("Install Applications") );
74 tmpact->setWhatsThis("\""+store.filePath+"\"");
75 }
76 //--Look for the control panel
77 XDGDesktop controlp(LOS::ControlPanelShortcut());
78 if(controlp.isValid()){
79 tmpact = mainmenu->addAction( LXDG::findIcon(controlp.icon, ""), tr("Control Panel") );
80 tmpact->setWhatsThis("\""+controlp.filePath+"\"");
81 }
82 mainmenu->addSeparator();
83 //--Now create the sub-menus
84 QStringList cats = HASH->keys();
85 cats.sort(); //make sure they are alphabetical
86 for(int i=0; i<cats.length(); i++){
87 //Make sure they are translated and have the right icons
88 QString name, icon;
89 if(cats[i]=="All"){continue; } //skip this listing for the menu
90 else if(cats[i] == "Multimedia"){ name = tr("Multimedia"); icon = "applications-multimedia"; }
91 else if(cats[i] == "Development"){ name = tr("Development"); icon = "applications-development"; }
92 else if(cats[i] == "Education"){ name = tr("Education"); icon = "applications-education"; }
93 else if(cats[i] == "Game"){ name = tr("Games"); icon = "applications-games"; }
94 else if(cats[i] == "Graphics"){ name = tr("Graphics"); icon = "applications-graphics"; }
95 else if(cats[i] == "Network"){ name = tr("Network"); icon = "applications-internet"; }
96 else if(cats[i] == "Office"){ name = tr("Office"); icon = "applications-office"; }
97 else if(cats[i] == "Science"){ name = tr("Science"); icon = "applications-science"; }
98 else if(cats[i] == "Settings"){ name = tr("Settings"); icon = "preferences-system"; }
99 else if(cats[i] == "System"){ name = tr("System"); icon = "applications-system"; }
100 else if(cats[i] == "Utility"){ name = tr("Utility"); icon = "applications-utilities"; }
101 else if(cats[i] == "Wine"){ name = tr("Wine"); icon = "wine"; }
102 else{ name = tr("Unsorted"); icon = "applications-other"; }
103
104 QMenu *menu = new QMenu(name, this);
105 menu->setIcon(LXDG::findIcon(icon,""));
106 QList<XDGDesktop*> appL = HASH->value(cats[i]);
107 for( int a=0; a<appL.length(); a++){
108 if(appL[a]->actions.isEmpty()){
109 //Just a single entry point - no extra actions
110 QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, menu);
111 act->setToolTip(appL[a]->comment);
112 act->setWhatsThis("\""+appL[a]->filePath+"\"");
113 menu->addAction(act);
114 }else{
115 //This app has additional actions - make this a sub menu
116 // - first the main menu/action
117 QMenu *submenu = new QMenu(appL[a]->name, menu);
118 submenu->setIcon( LXDG::findIcon(appL[a]->icon,"") );
119 //This is the normal behavior - not a special sub-action (although it needs to be at the top of the new menu)
120 QAction *act = new QAction(LXDG::findIcon(appL[a]->icon, ""), appL[a]->name, submenu);
121 act->setToolTip(appL[a]->comment);
122 act->setWhatsThis(appL[a]->filePath);
123 submenu->addAction(act);
124 //Now add entries for every sub-action listed
125 for(int sa=0; sa<appL[a]->actions.length(); sa++){
126 QAction *sact = new QAction(LXDG::findIcon(appL[a]->actions[sa].icon, appL[a]->icon), appL[a]->actions[sa].name, this);
127 sact->setToolTip(appL[a]->comment);
128 sact->setWhatsThis("-action \""+appL[a]->actions[sa].ID+"\" \""+appL[a]->filePath+"\"");
129 submenu->addAction(sact);
130 }
131 menu->addMenu(submenu);
132 }
133 }//end loop over apps within this category
134 mainmenu->addMenu(menu);
135 } //end loop over categories
136 //Now add any logout options
137 mainmenu->addSeparator();
138 //QMenu *tmpmenu = mainmenu->addMenu(LXDG::findIcon("system-log-out",""), tr("Leave"));
139 tmpact =mainmenu->addAction(LXDG::findIcon("system-log-out"),tr("Leave"));
140 tmpact->setWhatsThis("internal::logout");
141
142 }
143