From fb97b238f35bfd837cca7ed2ab46f6c82218e12a Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sun, 10 Jul 2016 23:04:42 +0200 Subject: [PATCH] allow better client selection --- sessman/login.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++++++- sessman/login.h | 28 ++++++++++ sessman/sman.cpp | 7 +++ sessman/sman.h | 4 ++ sessman/smoke-sm_de.ts | 113 +++++++++++++++++++++++++++++++++--------- sessman/smoke-sm_en.ts | 113 +++++++++++++++++++++++++++++++++--------- 6 files changed, 342 insertions(+), 51 deletions(-) diff --git a/sessman/login.cpp b/sessman/login.cpp index f6d9c59..b91ef90 100644 --- a/sessman/login.cpp +++ b/sessman/login.cpp @@ -17,8 +17,11 @@ #include #include +#include #include #include +#include +#include #include #include #include @@ -44,6 +47,7 @@ MLogin::MLogin(MSessionManager*sm) m->addAction(tr("&Exit"),this,SLOT(close())); m=mb->addMenu(tr("&Configure")); m->addAction(tr("&Configuration..."),this,SLOT(configwin())); + m->addAction(tr("Client &Selection..."),this,SLOT(clientConfig())); // mb->addMenu(MApplication::helpMenu()); //create central widget @@ -115,15 +119,27 @@ void MLogin::loadProfile() #define LASTCLIENTSETTING "SessionManager/LastClient" void MLogin::initClients(MSessionManager*sm) { - QString last=QSettings().value(LASTCLIENTSETTING).toString().trimmed(); + //was sman started by a slave? If so: do not allow selection. + if(sm->connectionCount()>0){ + clients->setEnabled(false); + return; + } + //get last active client or forced preselection + QString last= MClientConfig::preselectLast()? QSettings().value(LASTCLIENTSETTING).toString().trimmed() : MClientConfig::preselection(); + //create entries int pos=-1; for(auto entry:sm->menuItems()){ if(!entry.first.startsWith('@'))continue; + if(!MClientConfig::selectable(entry.first))continue; if(last==entry.first)pos=clients->count(); clients->addItem(entry.second.replace("&",""),entry.first); } + //set last selected or preselected if(pos>=0) clients->setCurrentIndex(pos); + //disable if user is not supposed to change this + clients->setEnabled(MClientConfig::selectionChangeable()); + //make sure we remember the selection connect(clients,static_cast(&QComboBox::currentIndexChanged), this, [this]{QSettings().setValue(LASTCLIENTSETTING,clients->currentData());} ); } @@ -207,3 +223,113 @@ void MLogin::relogin() else emit lostSession(); } + +void MLogin::clientConfig() +{ + MClientConfig cc(this); + if(cc.exec()==QDialog::Accepted) + QMessageBox::information(this,tr("Restart Needed"),tr("You have to restart MagicSmoke for these settings to take effect.")); +} + +#define LASTTOKEN "@@last@@" +MClientConfig::MClientConfig ( QWidget* parent, Qt::WindowFlags f ) : QDialog ( parent, f ) +{ + setWindowTitle(tr("Client Selection Settings")); + QVBoxLayout*vl; + QHBoxLayout*hl; + setLayout(vl=new QVBoxLayout); + QFormLayout*fl; + vl->addLayout(fl=new QFormLayout); + + fl->addRow(tr("Editing:"),mallowchange=new QCheckBox(tr("Allow user to change client selection."))); + mallowchange->setChecked(selectionChangeable()); + + fl->addRow(tr("Preselection:"),mpresel=new QComboBox); + mpresel->addItem(tr("Use Last Active Client"),LASTTOKEN); + + int pos=-1; + const QString psel=preselection(); + for(auto entry:MSessionManager::instance()->menuItems()){ + if(!entry.first.startsWith('@'))continue; + //selection + if(psel==entry.first)pos=mpresel->count(); + mpresel->addItem(entry.second.remove('&'),entry.first); + //choices + fl->addRow(entry.second,hl=new QHBoxLayout); + QCheckBox*m,*p; + 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"))); + m->setChecked(inMenu(entry.first)); + mclients.insert(entry.first,QPair(m,p)); + } + if(!preselectLast()&&pos>=0) + mpresel->setCurrentIndex(pos); + + vl->addSpacing(15); + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(1); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("&Save"))); + p->setDefault(true); + connect(p,SIGNAL(clicked(bool)),this,SLOT(accept())); + connect(p,SIGNAL(clicked(bool)),this,SLOT(saveData())); + hl->addWidget(p=new QPushButton(tr("&Cancel"))); + connect(p,SIGNAL(clicked(bool)),this,SLOT(reject())); +} + +#define CCFG_SETTINGS "SessionManager/ClientConfig/" +#define PRESELECTLAST "preselectLast" +#define SELECTABLE "selectable/" +#define INMENU "inmenu/" +#define PRESELECTION "preselection" +#define PRESELECTCHANGE "preselectChange" + +void MClientConfig::saveData() +{ + QSettings set; + set.setValue(CCFG_SETTINGS PRESELECTCHANGE,mallowchange->isChecked()); + + QString psel=mpresel->currentData().toString(); + if(psel==LASTTOKEN){ + set.setValue(CCFG_SETTINGS PRESELECTLAST,true); + set.setValue(CCFG_SETTINGS PRESELECTION,QString()); + }else{ + set.setValue(CCFG_SETTINGS PRESELECTLAST,false); + set.setValue(CCFG_SETTINGS PRESELECTION,psel); + } + + 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()); + } +} + +bool MClientConfig::preselectLast() +{ + return QSettings().value(CCFG_SETTINGS PRESELECTLAST,true).toBool(); +} + +bool MClientConfig::selectable ( QString client ) +{ + return QSettings().value(CCFG_SETTINGS SELECTABLE + client,true).toBool(); +} + +bool MClientConfig::inMenu ( QString client ) +{ + return QSettings().value(CCFG_SETTINGS INMENU + client ,true).toBool(); +} + +QString MClientConfig::preselection() +{ + return QSettings().value(CCFG_SETTINGS PRESELECTION,"").toString(); +} + +bool MClientConfig::selectionChangeable() +{ + return QSettings().value(CCFG_SETTINGS PRESELECTCHANGE,true).toBool(); +} diff --git a/sessman/login.h b/sessman/login.h index 9aa6b8b..d8943d1 100644 --- a/sessman/login.h +++ b/sessman/login.h @@ -13,11 +13,15 @@ #ifndef MAGICSMOKE_LOGIN_H #define MAGICSMOKE_LOGIN_H +#include +#include +#include #include class QComboBox; class QLineEdit; class QSizeGrip; +class QCheckBox; class MSessionManager; @@ -47,10 +51,34 @@ class MLogin:public QWidget public slots: void configwin(); void relogin(); + void clientConfig(); signals: void loginSucceeded(); void lostSession(); }; +///Configures which client is available for selection. +class MClientConfig:public QDialog +{ + Q_OBJECT +public: + explicit MClientConfig ( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + + static bool selectable(QString client); + static bool inMenu(QString client); + + static bool preselectLast(); + static QString preselection(); + static bool selectionChangeable(); + +private slots: + void saveData(); + +private: + QCheckBox*mallowchange; + QComboBox*mpresel; + QMap>mclients; +}; + #endif diff --git a/sessman/sman.cpp b/sessman/sman.cpp index 18a6829..36de1bf 100644 --- a/sessman/sman.cpp +++ b/sessman/sman.cpp @@ -32,9 +32,11 @@ #include static QPointer loginwindow; +static QPointer sessmanobj; MSessionManager::MSessionManager ( QObject* parent ) : QObject ( parent ) { + sessmanobj=this; // create socket mkey=QString::fromLatin1(MagicSmokeRandom::getRandomBytes(32).toHex()); if(mkey.size()<64){ @@ -76,6 +78,7 @@ MSessionManager::MSessionManager ( QObject* parent ) : QObject ( parent ) QMenu*m=new QMenu; QSignalMapper*sm=new QSignalMapper(m); for(auto entry:menuItems()){ + if(!MClientConfig::inMenu(entry.first))continue; QAction*a=m->addAction(entry.second); sm->setMapping(a,entry.first); connect(a,SIGNAL(triggered()),sm,SLOT(map())); @@ -100,6 +103,10 @@ MSessionManager::~MSessionManager() qApp->quit(); } +MSessionManager* MSessionManager::instance() +{ + return sessmanobj; +} bool MSessionManager::hasSession() const { diff --git a/sessman/sman.h b/sessman/sman.h index 3837c54..3ef0db7 100644 --- a/sessman/sman.h +++ b/sessman/sman.h @@ -37,8 +37,12 @@ public: virtual QString profile()const; virtual QString profileName()const; + int connectionCount()const{return mconnections.count();} + virtual QList> menuItems()const; + static MSessionManager*instance(); + private slots: void newConnection(); void readyRead(); diff --git a/sessman/smoke-sm_de.ts b/sessman/smoke-sm_de.ts index b44ff58..2276be9 100644 --- a/sessman/smoke-sm_de.ts +++ b/sessman/smoke-sm_de.ts @@ -2,128 +2,191 @@ + MClientConfig + + + Client Selection Settings + Programmauswahlkonfiguration + + + + Editing: + Auswahl ändern: + + + + Allow user to change client selection. + Dem Nutzer erlauben die Auswahl zu ändern. + + + + Preselection: + Vorauswahl: + + + + Use Last Active Client + Zuletzt aktives Programm vorauswählen + + + + Show in Preselection + In Vorauswahl zeigen + + + + Show in Menu + In Kontextmenü zeigen + + + + &Save + &Speichern + + + + &Cancel + &Abbrechen + + + MLogin - + Magic Smoke Login Magic Smoke Login - + &File &Datei - + &Exit Beenden - + &Configure &Konfigurieren - + &Configuration... &Konfigurieren... - + + Client &Selection... + &Programmauswahl... + + + Profile: Profil: - + Client: Programm: - + Username: Benutzername: - + Password: Passwort: - - + + Login Login - + Logging in... Einloggen... - + Warning Warnung - + Unable to log in. Der Login ist fehlgeschlagen. - + Getting data... Hole Daten... + + + Restart Needed + Neustart + + + + You have to restart MagicSmoke for these settings to take effect. + Sie müssen MagicSmoke neu starten, damit diese Einstellungen aktiv werden. + MSessionManager - + MagicSmoke Session Manager, waiting for login... 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 816bd15..1b2b2f8 100644 --- a/sessman/smoke-sm_en.ts +++ b/sessman/smoke-sm_en.ts @@ -2,128 +2,191 @@ + MClientConfig + + + Client Selection Settings + + + + + Editing: + + + + + Allow user to change client selection. + + + + + Preselection: + + + + + Use Last Active Client + + + + + Show in Preselection + + + + + Show in Menu + + + + + &Save + + + + + &Cancel + + + + MLogin - + Magic Smoke Login - + &File - + &Exit - + &Configure - + &Configuration... - - Profile: + + Client &Selection... + Profile: + + + + Client: - + Username: - + Password: - - + + Login log into the server - + Logging in... - + Warning - + Unable to log in. - + Getting data... + + + Restart Needed + + + + + You have to restart MagicSmoke for these settings to take effect. + + MSessionManager - + MagicSmoke Session Manager, waiting for login... - + 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 -- 1.7.2.5