MagicSmoke  $VERSION$
sclimenu.h
Go to the documentation of this file.
1 //
2 // C++ Interface: Session Client
3 //
4 // Description: Session Client Menu Convenience Function.
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2016
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_SC_SCLIMENU_H
14 #define MAGICSMOKE_SC_SCLIMENU_H
15 
16 #include "scli.h"
17 #include <QMenu>
18 #include <QSignalMapper>
19 #include <QAction>
20 
21 
25 inline QMenu* MSessionClient_createMenuObject(QMenu*menu=nullptr)
26 {
27  //retrieve if necessary
28  auto inst=MSessionClient::instance();
29  auto mmenu=inst->menuEntries();
30  if(mmenu.isEmpty())return nullptr;
31  //generate menu
32  QMenu*m=menu?menu:new QMenu;
33  QSignalMapper*sm=new QSignalMapper(m);
34  for(auto entry:mmenu){
35  QAction*a=m->addAction(entry.second,sm,SLOT(map()));
36  sm->setMapping(a,entry.first);
37  }
38  QObject::connect(sm,SIGNAL(mapped(QString)),inst,SLOT(execServerCommand(QString)));
39  return m;
40 }
41 
42 
43 
44 #endif
QMenu * MSessionClient_createMenuObject(QMenu *menu=nullptr)
creates a menu that allows (limited) control over the session manager returns nullptr if the menu cou...
Definition: sclimenu.h:25
static MSessionClient * instance()
returns the current instance of the Session Client class returns nullptr if there is no instance ...
Definition: scli.cpp:101