From: Konrad Rosenbaum Date: Sat, 13 Aug 2016 11:37:28 +0000 (+0200) Subject: more control over print at home X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=1767c0ea68c25d046c7bbe6aa5f5aad7ea1fb74b;p=web%2Fkonrad%2Fsmoke.git more control over print at home --- diff --git a/doc/printathome-template.txt b/doc/printathome-template.txt new file mode 100644 index 0000000..ef0a356 --- /dev/null +++ b/doc/printathome-template.txt @@ -0,0 +1,34 @@ +Print@Home Templating and Settings +=================================== + +Server Side Settings +--------------------- + +Select bill template +Select ticket and voucher templates + --> select print mode: one per page, several per page +Select generic documents + +==> select names for each document + +Select Mail template + --> select Cc address(es) and From address + --> select which documents to append + +Select shipping types that use p@h + +Later on: combine them into one or several documents + + + +TODO: tell MS server which contact type is email + + +Local Settings +--------------- + +When to run... + +Pre-selected username and profile + +Autostart/Autologin? \ No newline at end of file diff --git a/printathome/client.cpp b/printathome/client.cpp new file mode 100644 index 0000000..b00df10 --- /dev/null +++ b/printathome/client.cpp @@ -0,0 +1,51 @@ +// +// C++ Implementation: print @ home +// +// Description: Client Settings +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "client.h" + +#include +#include +#include +#include +#include + +#define GROUP "PrintAtHome/Client" +#define TIMER GROUP "/timermin" +#define SETPROFILE GROUP "/setprofile" +#define PROFILE GROUP "/profile" +#define SETUSER GROUP "/setuser" +#define USERNAME GROUP "/username" +#define AUTOLOGIN GROUP "/autologin" +#define PASSWD GROUP "/passwd" + + +MPClientConfig::MPClientConfig(QWidget* parent) +{ + QVBoxLayout*vl; + setLayout(vl=new QVBoxLayout); + QFormLayout*fl; + vl->addLayout(fl=new QFormLayout); + fl->addRow(tr("Check Interval in Minutes:"),mtimer=new QSpinBox); + mtimer->setRange(1,10080); + mtimer->setValue(timerInMinutes()); + fl->addRow("",msetprofile=new QCheckBox(tr("Preselect Profile"))); + fl->addRow(tr("Profile:"),mprofile=new QComboBox); + connect(msetprofile,SIGNAL(clicked(bool)),mprofile,SLOT(setEnabled(bool))); + msetprofile->setChecked(preselectProfile()); + //TODO: get profile names + +} + +void MPClientConfig::save() +{ + +} diff --git a/printathome/client.h b/printathome/client.h new file mode 100644 index 0000000..993186b --- /dev/null +++ b/printathome/client.h @@ -0,0 +1,43 @@ +// +// C++ Interface: print @ home, client config +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MSMOKE_PAH_CLIENT_H +#define MSMOKE_PAH_CLIENT_H + +#include + +class MPClientConfig:public QDialog +{ + Q_OBJECT +public: + MPClientConfig(QWidget*parent=nullptr); + + static int timerInMinutes(); + static bool preselectProfile(); + static QString preselectedProfileName(); + static bool preselectUser(); + static QString preselectedUserName(); + static bool autoLogin(); + static QString password(); + +public slots: + void save(); + +private: + QSpinBox*mtimer; + QCheckBox*msetprofile,msetuser,mautologin; + QLineEdit*musername,*mpassword; + QComboBox*mprofile; + +}; + +#endif diff --git a/printathome/pah.cpp b/printathome/pah.cpp index 1f9133f..539b674 100644 --- a/printathome/pah.cpp +++ b/printathome/pah.cpp @@ -1,3 +1,15 @@ +// +// C++ Implementation: print q home +// +// Description: Main Program +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + #include "mapplication.h" #include "msinterface.h" #include "scli.h" @@ -16,7 +28,7 @@ PrintIcon::PrintIcon() QMenu*ctx=new QMenu; ctx->addAction(tr("Start &Printing now")); ctx->addSeparator(); - ctx->addAction(tr("&Client Configuration...")); + ctx->addAction(tr("&Client Configuration..."),this,SLOT(clientConfig())); ctx->addAction(tr("&Server Configuration...")); ctx->addSeparator(); ctx->addAction(tr("&Quit"),qApp,SLOT(quit())); @@ -50,6 +62,11 @@ void PrintIcon::setPrintMode(PrintMode m) setToolTip(tr("MagicSmoke Print@Home: %1 - logged in as %2 at %3").arg(mode).arg(user).arg(host)); } +void PrintIcon::clientConfig() +{ + +} + int main(int argc,char**argv) diff --git a/printathome/pah.h b/printathome/pah.h index 78c7060..f1faadf 100644 --- a/printathome/pah.h +++ b/printathome/pah.h @@ -1,3 +1,15 @@ +// +// C++ Interface: print @ home +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + #ifndef PAH_MAIN_H #define PAH_MAIN_H @@ -19,6 +31,7 @@ public: }; public slots: void setPrintMode(PrintMode); + void clientConfig(); }; #endif \ No newline at end of file diff --git a/sesscli/scli.cpp b/sesscli/scli.cpp index c6751d9..9d43d03 100644 --- a/sesscli/scli.cpp +++ b/sesscli/scli.cpp @@ -141,10 +141,10 @@ bool MSessionClient::waitForSessionAvailable() return !msid.isEmpty(); } -QList< QPair< QString, QString > > MSessionClient::menuEntries() const +QList< QPair< QString, QString > > MSessionClient::menuEntries(bool force) const { if(!isConnected())return QList>(); - if(mmenu.isEmpty()){ + if(mmenu.isEmpty()||force){ //get menu QEventLoop loop; connect(this,SIGNAL(menuChanged()),&loop,SLOT(quit())); @@ -157,6 +157,29 @@ QList< QPair< QString, QString > > MSessionClient::menuEntries() const return mmenu; } +QList< QPair< QString, QString > > MSessionClient::profiles(bool force) const +{ + if(!isConnected())return QList>(); + if(mprofiles.isEmpty()||force){ + //get menu + QEventLoop loop; + connect(this,SIGNAL(profilesChanged()),&loop,SLOT(quit())); + connect(this,SIGNAL(managerLost()),&loop,SLOT(quit())); + QTimer::singleShot(5000,&loop,SLOT(quit())); + msocket->write("getprofiles\n"); + msocket->waitForBytesWritten(1000); + loop.exec(); + } + return mprofiles; +} + +QString MSessionClient::defaultProfileId() const +{ + if(mprofiles.isEmpty())profiles(); + return mdefaultprofile; +} + + void MSessionClient::socketLost() { qDebug()<<"Warning: Session Manager Socket lost!"; @@ -198,6 +221,21 @@ void MSessionClient::readSocket() }else if(cmd=="endmenu"){ qDebug()<<"New Menu received from Session Manager!"; emit menuChanged(); + }else if(cmd=="newprofiles"){ + mprofiles.clear(); + mdefaultprofile.clear(); + }else if(cmd=="haveprofile"){ + const int pos=par.indexOf(' '); + if(pos<2){ + qDebug()<<"Warning: received invalid haveprofile command. Ignoring it."; + continue; + } + mprofiles.append(QPair(par.left(pos),par.mid(pos+1))); + }else if(cmd=="defaultprofile"){ + mdefaultprofile=par; + }else if(cmd=="endprofiles"){ + qDebug()<<"Received new list of profiles."; + emit profilesChanged(); }else if(cmd=="closed"){ msid.clear(); qDebug()<<"Warning: Session lost!"; @@ -215,3 +253,17 @@ void MSessionClient::execServerCommand ( QString cmd) msocket->write(QString("exec "+cmd+"\n").toUtf8()); } +void MSessionClient::setProfile(QString pn) +{ + if(msocket && msocket->isOpen()) + msocket->write(QString("setprofile %1\n").arg(pn).toUtf8()); +} + +void MSessionClient::login(QString user,QString password) +{ + if(msocket && msocket->isOpen()) + msocket->write(QString("setuser %1\nsetpasswd %2\nlogin\n") + .arg(user) + .arg(password.toUtf8().toBase64()) + .toUtf8()); +} diff --git a/sesscli/scli.h b/sesscli/scli.h index 0fafdae..f8e5e26 100644 --- a/sesscli/scli.h +++ b/sesscli/scli.h @@ -53,17 +53,28 @@ 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; + ///retrieves and returns the menu entries of the session manager in the format command -> menu text + /// \param force if true: force fresh retrieval of the menu even if it is already known + virtual QList> menuEntries(bool force=false)const; + + ///retrieves and returns all configured profiles in the format profileId -> profile name + /// \param force if true: force fresh retrieval of the menu profiles if it is already known + virtual QList> profiles(bool force=false)const; + + ///gets the default profile ID + virtual QString defaultProfileId()const; public slots: void execServerCommand(QString); + void setProfile(QString); + void login(QString user,QString password); signals: void sessionIdChanged(QString sessionId); void sessionLost(); void managerLost(); void menuChanged(); + void profilesChanged(); private slots: void socketLost(); @@ -71,8 +82,8 @@ private slots: private: QLocalSocket*msocket=nullptr; - QString msid,mprofile,muser; - QList> mmenu; + QString msid,mprofile,muser,mdefaultprofile; + QList> mmenu,mprofiles; }; diff --git a/sessman/sman.cpp b/sessman/sman.cpp index b0637ae..2085a50 100644 --- a/sessman/sman.cpp +++ b/sessman/sman.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "sman.h" #include "login.h" @@ -202,8 +203,18 @@ void MSessionManager::readyRead() sendSessionInfo(s); }else if(cmd=="getmenu") sendMenu(s); + else if(cmd=="getprofiles") + sendProfiles(s); else if(cmd=="exec") execCmd(par.trimmed()); + else if(cmd=="setprofile") + emit setProfile(par.trimmed()); + else if(cmd=="setuser") + emit setUsername(par.trimmed()); + else if(cmd=="setpasswd") + emit setPassword(QString::fromUtf8(QByteArray::fromBase64(par.trimmed()))); + else if(cmd=="login") + emit startLogin(); else qDebug()<<"Warning: unknown client command"<write("endmenu\n"); } +void MSessionManager::sendProfiles(QLocalSocket*s) +{ + s->write("newprofiles\n"); + QSettings set; + s->write(QString("defaultprofile %1\n").arg(set.value("defaultprofile").toString()).toUtf8()); + set.beginGroup("profiles"); + QStringList prf=set.childGroups(); + for(int i=0;iwrite(QString("haveprofile %1 %2\n").arg(prf[i]).arg(set.value(prf[i]+"/name").toString()).toUtf8()); + } + s->write("endprofiles\n"); +} + + void MSessionManager::execCmd (const QString &cmd) { qDebug()<<"Received command"<