From 4fa47642360c8054eafc14e25189a11004a926a4 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Mon, 11 Jul 2016 12:55:21 +0200 Subject: [PATCH] Add client session menu --- sesscli/scli.cpp | 20 ++++++++++++++++++-- sesscli/scli.h | 5 +++++ sesscli/sclimenu.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ sessman/login.cpp | 22 +++++++++++++++++----- sessman/login.h | 12 +++++++++++- sessman/sman.cpp | 3 ++- sessman/smoke-sm_de.ts | 32 +++++++++++++++++++------------- sessman/smoke-sm_en.ts | 30 ++++++++++++++++++------------ src/mwin/overview.cpp | 4 ++++ 9 files changed, 138 insertions(+), 34 deletions(-) create mode 100644 sesscli/sclimenu.h diff --git a/sesscli/scli.cpp b/sesscli/scli.cpp index 5bf5751..c6751d9 100644 --- a/sesscli/scli.cpp +++ b/sesscli/scli.cpp @@ -17,13 +17,17 @@ #include #include #include +#include #include #include #include #include +static QPointer sessionclientinstance; + MSessionClient::MSessionClient() { + sessionclientinstance=this; //check parameters for socket name QString sms; for(QString arg:qApp->arguments()) @@ -94,6 +98,12 @@ MSessionClient::~MSessionClient() msocket->close(); } +MSessionClient* MSessionClient::instance() +{ + return sessionclientinstance; +} + + bool MSessionClient::isConnected() const { return msocket!=nullptr && msocket->isOpen(); @@ -160,11 +170,11 @@ void MSessionClient::socketLost() void MSessionClient::readSocket() { - while(msocket->canReadLine()){ + while(msocket && msocket->canReadLine()){ const QString line=QString::fromUtf8(msocket->readLine()).trimmed(); const int pos=line.indexOf(' '); const QString cmd=pos>0?line.left(pos):line; - const QString par=pos>0?line.mid(pos+1):QString(); + const QString par=pos>0?line.mid(pos+1).trimmed():QString(); qDebug()<<"Received session manager command"<(par.left(pos),par.mid(pos+1))); }else if(cmd=="endmenu"){ qDebug()<<"New Menu received from Session Manager!"; emit menuChanged(); diff --git a/sesscli/scli.h b/sesscli/scli.h index 5a874ae..0fafdae 100644 --- a/sesscli/scli.h +++ b/sesscli/scli.h @@ -34,6 +34,10 @@ public: ///Disconnect the session client. virtual ~MSessionClient(); + ///returns the current instance of the Session Client class + ///returns nullptr if there is no instance + static MSessionClient*instance(); + ///Wait until a session is available or the Session Manager quits. ///\returns true if a session is available, false on error virtual bool waitForSessionAvailable(); @@ -49,6 +53,7 @@ public: ///Returns true if the client is connected to a manager. If false there is something wrong. virtual bool isConnected()const; + ///retrieves and returns the menu entries of the session manager virtual QList> menuEntries()const; public slots: diff --git a/sesscli/sclimenu.h b/sesscli/sclimenu.h new file mode 100644 index 0000000..c1382f4 --- /dev/null +++ b/sesscli/sclimenu.h @@ -0,0 +1,44 @@ +// +// C++ Interface: Session Client +// +// Description: Session Client Menu Convenience Function. +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_SC_SCLIMENU_H +#define MAGICSMOKE_SC_SCLIMENU_H + +#include "scli.h" +#include +#include +#include + + +///creates a menu that allows (limited) control over the session manager +///returns nullptr if the menu could not be retrieved +///\param menu if not NULL: the menu to fill, if NULL: a new menu will be created, please do not forget to take ownership of the new menu +inline QMenu* MSessionClient_createMenuObject(QMenu*menu=nullptr) +{ + //retrieve if necessary + auto inst=MSessionClient::instance(); + auto mmenu=inst->menuEntries(); + if(mmenu.isEmpty())return nullptr; + //generate menu + QMenu*m=menu?menu:new QMenu; + QSignalMapper*sm=new QSignalMapper(m); + for(auto entry:mmenu){ + QAction*a=m->addAction(entry.second,sm,SLOT(map())); + sm->setMapping(a,entry.first); + } + QObject::connect(sm,SIGNAL(mapped(QString)),inst,SLOT(execServerCommand(QString))); + return m; +} + + + +#endif diff --git a/sessman/login.cpp b/sessman/login.cpp index b91ef90..9976746 100644 --- a/sessman/login.cpp +++ b/sessman/login.cpp @@ -256,16 +256,21 @@ MClientConfig::MClientConfig ( QWidget* parent, Qt::WindowFlags f ) : QDialog ( mpresel->addItem(entry.second.remove('&'),entry.first); //choices fl->addRow(entry.second,hl=new QHBoxLayout); - QCheckBox*m,*p; + QCheckBox*m,*p,*c; hl->addWidget(p=new QCheckBox(tr("Show in Preselection"))); p->setChecked(selectable(entry.first)); QFrame*f; hl->addWidget(f=new QFrame); f->setFrameShadow(QFrame::Sunken); f->setFrameShape(QFrame::VLine); - hl->addWidget(m=new QCheckBox(tr("Show in Menu"))); + hl->addWidget(m=new QCheckBox(tr("Show in Tray Menu"))); m->setChecked(inMenu(entry.first)); - mclients.insert(entry.first,QPair(m,p)); + hl->addWidget(f=new QFrame); + f->setFrameShadow(QFrame::Sunken); + f->setFrameShape(QFrame::VLine); + hl->addWidget(c=new QCheckBox(tr("Show in Client Menu"))); + c->setChecked(inClientMenu(entry.first)); + mclients.insert(entry.first,s_checkbox(m,p,c)); } if(!preselectLast()&&pos>=0) mpresel->setCurrentIndex(pos); @@ -286,6 +291,7 @@ MClientConfig::MClientConfig ( QWidget* parent, Qt::WindowFlags f ) : QDialog ( #define PRESELECTLAST "preselectLast" #define SELECTABLE "selectable/" #define INMENU "inmenu/" +#define INCLIENT "inclient/" #define PRESELECTION "preselection" #define PRESELECTCHANGE "preselectChange" @@ -304,8 +310,9 @@ void MClientConfig::saveData() } for(QString k:mclients.keys()){ - set.setValue(CCFG_SETTINGS INMENU + k,mclients[k].first->isChecked()); - set.setValue(CCFG_SETTINGS SELECTABLE + k,mclients[k].second->isChecked()); + set.setValue(CCFG_SETTINGS INMENU + k,mclients[k].menu->isChecked()); + set.setValue(CCFG_SETTINGS SELECTABLE + k,mclients[k].presel->isChecked()); + set.setValue(CCFG_SETTINGS INCLIENT + k,mclients[k].client->isChecked()); } } @@ -324,6 +331,11 @@ bool MClientConfig::inMenu ( QString client ) return QSettings().value(CCFG_SETTINGS INMENU + client ,true).toBool(); } +bool MClientConfig::inClientMenu ( QString client ) +{ + return QSettings().value(CCFG_SETTINGS INCLIENT + client ,true).toBool(); +} + QString MClientConfig::preselection() { return QSettings().value(CCFG_SETTINGS PRESELECTION,"").toString(); diff --git a/sessman/login.h b/sessman/login.h index d8943d1..5527ea9 100644 --- a/sessman/login.h +++ b/sessman/login.h @@ -67,6 +67,7 @@ public: static bool selectable(QString client); static bool inMenu(QString client); + static bool inClientMenu(QString client); static bool preselectLast(); static QString preselection(); @@ -78,7 +79,16 @@ private slots: private: QCheckBox*mallowchange; QComboBox*mpresel; - QMap>mclients; + struct s_checkbox{ + QCheckBox*presel=nullptr,*menu=nullptr,*client=nullptr; + s_checkbox(){} + s_checkbox(QCheckBox*m,QCheckBox*p,QCheckBox*c):presel(p),menu(m),client(c){} + s_checkbox(const s_checkbox&)=default; + s_checkbox(s_checkbox&&)=default; + s_checkbox& operator=(const s_checkbox&)=default; + s_checkbox& operator=(s_checkbox&&)=default; + }; + QMapmclients; }; #endif diff --git a/sessman/sman.cpp b/sessman/sman.cpp index 36de1bf..eff6959 100644 --- a/sessman/sman.cpp +++ b/sessman/sman.cpp @@ -238,7 +238,8 @@ void MSessionManager::sendMenu(QLocalSocket*s) s->write("newmenu\n"); //send "menu command entry-text" for each entry for(auto entry:menuItems()) - s->write(QString("menu %1 %2\n").arg(entry.first).arg(entry.second).toUtf8()); + if(MClientConfig::inClientMenu(entry.first)) + s->write(QString("menu %1 %2\n").arg(entry.first).arg(entry.second).toUtf8()); s->write("endmenu\n"); } diff --git a/sessman/smoke-sm_de.ts b/sessman/smoke-sm_de.ts index 2276be9..71a2c13 100644 --- a/sessman/smoke-sm_de.ts +++ b/sessman/smoke-sm_de.ts @@ -35,16 +35,22 @@ - Show in Menu - In Kontextmenü zeigen + Show in Tray Menu + Show in Menu + In SysTray-Menü zeigen - + + Show in Client Menu + In Client-Programm-Menü zeigen + + + &Save &Speichern - + &Cancel &Abbrechen @@ -146,47 +152,47 @@ MagicSmoke Session Manager, warte auf Login... - + Warning Warnung - + Cannot start a client while not logged in! Programm kann nicht gestartet werden wenn noch kein Login besteht! - + MagicSmoke Session Manager, logged in as %1 at %2. MagicSmoke Session Manager, eingeloggt als %1 auf Profil %2. - + &Configuration... &Konfigurieren... - + Start &Expert Client Starte &Experten-Programm - + Start &Wizard Starte &Wizard - + Start &Statistics Client Starte &Statistik-Programm - + Start &Print@Home Daemon Starte &Print@Home Hintergrundprogramm - + &Quit Session Session &Beenden diff --git a/sessman/smoke-sm_en.ts b/sessman/smoke-sm_en.ts index 1b2b2f8..a9a1cc4 100644 --- a/sessman/smoke-sm_en.ts +++ b/sessman/smoke-sm_en.ts @@ -35,16 +35,22 @@ - Show in Menu + Show in Tray Menu + Show in Menu - + + Show in Client Menu + + + + &Save - + &Cancel @@ -146,47 +152,47 @@ - + Warning - + Cannot start a client while not logged in! - + MagicSmoke Session Manager, logged in as %1 at %2. - + &Configuration... - + Start &Expert Client - + Start &Wizard - + Start &Statistics Client - + Start &Print@Home Daemon - + &Quit Session diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index e4cc47c..caf0881 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -67,6 +67,8 @@ #include "MTBackup" #include "MTGetAllUsers" +#include "sclimenu.h" + MOverview::MOverview(QString pk) :MTabWin(pk),entrancetab(nullptr) { @@ -148,6 +150,8 @@ MOverview::MOverview(QString pk) m2->addAction(tr("&OpenOffice settings..."),this,SLOT(openOfficeSettings())); m2->addAction(tr("&Barcode Scanner settings..."),this,SLOT(barcodeSettings())); + MSessionClient_createMenuObject(m->addMenu(tr("&Session Manager"))); + //make sure webrequest knows its settings webSettings(false); -- 1.7.2.5