From: Konrad Rosenbaum Date: Tue, 29 Nov 2016 10:17:15 +0000 (+0100) Subject: Print@Home: extend DB and transactions, prototype app X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d90f5794aaef15993ce8e80e3e8e6abcb28a429e;p=web%2Fkonrad%2Fsmoke.git Print@Home: extend DB and transactions, prototype app Change-Id: I12a228ecfecae4f5e245e9a630982dc30164c532 --- diff --git a/printathome/client.cpp b/printathome/client.cpp index b00df10..d1f4a38 100644 --- a/printathome/client.cpp +++ b/printathome/client.cpp @@ -12,11 +12,16 @@ #include "client.h" +#include "scli.h" + #include #include #include #include #include +#include +#include +#include #define GROUP "PrintAtHome/Client" #define TIMER GROUP "/timermin" @@ -29,23 +34,135 @@ MPClientConfig::MPClientConfig(QWidget* parent) +:QDialog(parent) { + setWindowTitle(tr("Print@Home Client Configuration")); QVBoxLayout*vl; setLayout(vl=new QVBoxLayout); QFormLayout*fl; vl->addLayout(fl=new QFormLayout); + //check Interval fl->addRow(tr("Check Interval in Minutes:"),mtimer=new QSpinBox); mtimer->setRange(1,10080); mtimer->setValue(timerInMinutes()); + //profile 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 + //get profile names + auto prfs=MSessionClient::instance()->profiles(); + const QString cprf=preselectedProfileId(); + int cprfn=-1; + for(auto prf:prfs){ + if(prf.first==cprf)cprfn=mprofile->count(); + mprofile->addItem(prf.second,prf.first); + } + mprofile->setCurrentIndex(cprfn); + //user + fl->addRow("",msetuser=new QCheckBox(tr("Set User Name"))); + fl->addRow(tr("User Name:"),musername=new QLineEdit); + musername->setText(preselectedUserName()); + connect(msetuser,SIGNAL(clicked(bool)),musername,SLOT(setEnabled(bool))); + msetuser->setChecked(preselectUser()); + //password + fl->addRow("",mautologin=new QCheckBox(tr("Auto-Login"))); + fl->addRow(tr("Password:"),mpassword=new QLineEdit); + connect(mautologin,SIGNAL(clicked(bool)),mpassword,SLOT(setEnabled(bool))); + mautologin->setChecked(autoLogin()); + mpassword->setEchoMode(QLineEdit::Password); + mpassword->setText(password()); + + vl->addSpacing(15); + QHBoxLayout*hl; + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(1); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("&OK"))); + connect(p,SIGNAL(clicked()),this,SLOT(save()),Qt::DirectConnection); + connect(p,SIGNAL(clicked()),this,SLOT(accept()),Qt::QueuedConnection); + hl->addWidget(p=new QPushButton(tr("&Cancel"))); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); } +//note: this is NOT an encryption algorithm - it merely masks against accidental reading, it is trivial to reverse +static inline QByteArray maskPwd(QString pwd) +{ + QByteArray r=pwd.toUtf8(); + int m=0x58; + for(int i=0;iisChecked()); + set.setValue(TIMER,mtimer->value()); + set.setValue(PROFILE,mprofile->currentData()); + set.setValue(SETUSER,msetuser->isChecked()); + set.setValue(USERNAME,musername->text()); + set.setValue(AUTOLOGIN,mautologin->isChecked()); + set.setValue(PASSWD,maskPwd(mpassword->text())); +} + +bool MPClientConfig::preselectProfile() +{ + return QSettings().value(SETPROFILE,false).toBool(); +} +int MPClientConfig::timerInMinutes() +{ + return QSettings().value(TIMER,60).toInt(); +} + +QString MPClientConfig::preselectedProfileId() +{ + return QSettings().value(PROFILE).toString(); +} + +bool MPClientConfig::preselectUser() +{ + return QSettings().value(SETUSER,false).toBool(); +} + +QString MPClientConfig::preselectedUserName() +{ + return QSettings().value(USERNAME).toString(); +} + +bool MPClientConfig::autoLogin() +{ + return QSettings().value(AUTOLOGIN,false).toBool(); +} + +QString MPClientConfig::password() +{ + return unmaskPwd(QSettings().value(PASSWD).toByteArray()); +} + +void MPClientConfig::performAutoLogin(MSessionClient&sc) +{ + sc.waitForReady(); + if(preselectProfile()) + sc.setProfile(preselectedProfileId()); + if(preselectUser()) + sc.login(preselectedUserName(),password(),autoLogin()); } diff --git a/printathome/client.h b/printathome/client.h index 993186b..4ab0a92 100644 --- a/printathome/client.h +++ b/printathome/client.h @@ -15,6 +15,12 @@ #include +class QCheckBox; +class QLineEdit; +class QComboBox; +class QSpinBox; +class MSessionClient; + class MPClientConfig:public QDialog { Q_OBJECT @@ -23,18 +29,20 @@ public: static int timerInMinutes(); static bool preselectProfile(); - static QString preselectedProfileName(); + static QString preselectedProfileId(); static bool preselectUser(); static QString preselectedUserName(); static bool autoLogin(); static QString password(); + static void performAutoLogin(MSessionClient&); + public slots: void save(); private: QSpinBox*mtimer; - QCheckBox*msetprofile,msetuser,mautologin; + QCheckBox*msetprofile,*msetuser,*mautologin; QLineEdit*musername,*mpassword; QComboBox*mprofile; diff --git a/printathome/pah.cpp b/printathome/pah.cpp index 539b674..0874a3b 100644 --- a/printathome/pah.cpp +++ b/printathome/pah.cpp @@ -16,6 +16,7 @@ #include #include "pah.h" +#include "client.h" #include #include @@ -64,7 +65,8 @@ void PrintIcon::setPrintMode(PrintMode m) void PrintIcon::clientConfig() { - + MPClientConfig cc; + cc.exec(); } @@ -79,11 +81,13 @@ int main(int argc,char**argv) //init app.initialize(); + app.setQuitOnLastWindowClosed(false); //get session MSessionClient sc; sc.connect(&sc,SIGNAL(sessionLost()),&app,SLOT(quit())); sc.connect(&sc,SIGNAL(managerLost()),&app,SLOT(quit())); + MPClientConfig::performAutoLogin(sc); if(sc.waitForSessionAvailable()){ WTransaction::setLogPrefix("P@H-T"); MSInterface*ms=new MSInterface(sc.currentProfileId()); diff --git a/printathome/printathome.pro b/printathome/printathome.pro index d657e80..68806e3 100644 --- a/printathome/printathome.pro +++ b/printathome/printathome.pro @@ -7,8 +7,8 @@ include(../iface/iface.pri) include(../commonlib/commonlib.pri) #sources -SOURCES += pah.cpp -HEADERS += pah.h +SOURCES += pah.cpp client.cpp +HEADERS += pah.h client.h RESOURCES += files.qrc diff --git a/sesscli/scli.cpp b/sesscli/scli.cpp index ee0422c..6905450 100644 --- a/sesscli/scli.cpp +++ b/sesscli/scli.cpp @@ -141,6 +141,18 @@ bool MSessionClient::waitForSessionAvailable() return !msid.isEmpty(); } +bool MSessionClient::waitForReady() +{ + if(!isConnected())return false; + if(misready)return true; + //wait for signal + QEventLoop loop; + connect(this,SIGNAL(readyReceived()),&loop,SLOT(quit())); + connect(this,SIGNAL(managerLost()),&loop,SLOT(quit())); + loop.exec(); + return misready; +} + QList< QPair< QString, QString > > MSessionClient::menuEntries(bool force) const { if(!isConnected())return QList>(); @@ -226,13 +238,13 @@ void MSessionClient::readSocket() mdefaultprofile.clear(); }else if(cmd=="haveprofile"){ const int pos=par.indexOf(' '); - if(pos<2){ - qDebug()<<"Warning: received invalid haveprofile command. Ignoring it."; + if(pos<1){ + qDebug()<<"Warning: received invalid haveprofile command. Ignoring it. Info Parameter: "<(par.left(pos),par.mid(pos+1))); }else if(cmd=="defaultprofile"){ - mdefaultprofile=par; + mdefaultprofile=par.trimmed(); }else if(cmd=="endprofiles"){ qDebug()<<"Received new list of profiles."; emit profilesChanged(); @@ -242,6 +254,9 @@ void MSessionClient::readSocket() emit sessionLost(); }else if(cmd=="quit"){ socketLost(); + }else if(cmd=="ready"){ + misready=true; + emit readyReceived(); }else qDebug()<<"Warning: unknown session manager signal"<write(QString("setprofile %1\n").arg(pn).toUtf8()); } -void MSessionClient::login(QString user,QString password) +void MSessionClient::login(QString user,QString password,bool attemptLogin) { if(msocket && msocket->isOpen()) - msocket->write(QString("setuser %1\nsetpasswd %2\nlogin\n") + msocket->write(QString("setuser %1\nsetpasswd %2\n%3") .arg(user) .arg(QString::fromLatin1(password.toUtf8().toBase64())) + .arg(attemptLogin?"login\n":"") .toUtf8()); } diff --git a/sesscli/scli.h b/sesscli/scli.h index f8e5e26..05846d7 100644 --- a/sesscli/scli.h +++ b/sesscli/scli.h @@ -41,6 +41,9 @@ public: ///Wait until a session is available or the Session Manager quits. ///\returns true if a session is available, false on error virtual bool waitForSessionAvailable(); + + ///Wait until the session manager is ready to receive commands. + virtual bool waitForReady(); ///Returns true if there currently is a session available. virtual bool sessionIsAvailable()const; @@ -67,7 +70,7 @@ public: public slots: void execServerCommand(QString); void setProfile(QString); - void login(QString user,QString password); + void login(QString user,QString password,bool attemptLogin=true); signals: void sessionIdChanged(QString sessionId); @@ -75,6 +78,7 @@ signals: void managerLost(); void menuChanged(); void profilesChanged(); + void readyReceived(); private slots: void socketLost(); @@ -84,6 +88,7 @@ private: QLocalSocket*msocket=nullptr; QString msid,mprofile,muser,mdefaultprofile; QList> mmenu,mprofiles; + bool misready=false; }; diff --git a/sessman/login.cpp b/sessman/login.cpp index 6c22591..958107a 100644 --- a/sessman/login.cpp +++ b/sessman/login.cpp @@ -229,6 +229,24 @@ void MLogin::relogin() emit lostSession(); } +void MLogin::setProfile(QString p) +{ + bool ok; + int n=p.toInt(&ok); + if(!ok)return; + profiles->setCurrentIndex(n); +} + +void MLogin::setUsername(QString u) +{ + username->setText(u); +} + +void MLogin::setPassword(QString pw) +{ + password->setText(pw); +} + void MLogin::clientConfig() { MClientConfig cc(this); diff --git a/sessman/login.h b/sessman/login.h index 5527ea9..eb2b9b3 100644 --- a/sessman/login.h +++ b/sessman/login.h @@ -45,13 +45,16 @@ class MLogin:public QWidget private slots: void initProfiles(); void loadProfile(); - void startLogin(); void initClients(MSessionManager*); public slots: void configwin(); void relogin(); void clientConfig(); + void setProfile(QString); + void setUsername(QString); + void setPassword(QString); + void startLogin(); signals: void loginSucceeded(); diff --git a/sessman/sman.cpp b/sessman/sman.cpp index 40bf458..e930908 100644 --- a/sessman/sman.cpp +++ b/sessman/sman.cpp @@ -171,6 +171,7 @@ void MSessionManager::newConnection() connect(s,SIGNAL(error(QLocalSocket::LocalSocketError)),this,SLOT(socketClosed())); connect(s,SIGNAL(destroyed(QObject*)),this,SLOT(socketLost(QObject*))); mconnections.append(s); + if(misready)s->write("ready\n"); } } @@ -351,6 +352,14 @@ void MSessionManager::loginLost() s->write("closed\n"); } +void MSessionManager::setReady() +{ + if(misready)return; + misready=true; + for(QLocalSocket*s:mconnections) + s->write("ready\n"); +} + QList> MSessionManager::menuItems() const { static QList> items; @@ -383,7 +392,13 @@ int main(int ac,char**av) lw.connect(&lw,SIGNAL(loginSucceeded()),sm,SLOT(loginSucceeded())); lw.connect(&lw,SIGNAL(lostSession()),sm,SLOT(loginLost())); lw.connect(sm,SIGNAL(openConfig()),&lw,SLOT(configwin())); + lw.connect(sm,SIGNAL(setProfile(QString)),&lw,SLOT(setProfile(QString))); + lw.connect(sm,SIGNAL(setUsername(QString)),&lw,SLOT(setUsername(QString))); + lw.connect(sm,SIGNAL(setPassword(QString)),&lw,SLOT(setPassword(QString))); + lw.connect(sm,SIGNAL(startLogin()),&lw,SLOT(startLogin())); lw.show(); + + sm->setReady(); return app.exec(); } diff --git a/sessman/sman.h b/sessman/sman.h index 1d82180..bbe4ffb 100644 --- a/sessman/sman.h +++ b/sessman/sman.h @@ -43,6 +43,8 @@ public: virtual QList> menuItems()const; static MSessionManager*instance(); + + void setReady(); private slots: void newConnection(); @@ -70,6 +72,7 @@ private: QString mkey; QSystemTrayIcon*micon; bool mhaveslave=false; + bool misready=false; void sendMenu(QLocalSocket*); void sendProfiles(QLocalSocket*); diff --git a/wob/classes/basics.wolf b/wob/classes/basics.wolf index ef5e9c2..47ba998 100644 --- a/wob/classes/basics.wolf +++ b/wob/classes/basics.wolf @@ -58,4 +58,10 @@ Olsen database time zone name + + + + + + diff --git a/wob/db/db.wolf b/wob/db/db.wolf index 6cd70be..ce017b5 100644 --- a/wob/db/db.wolf +++ b/wob/db/db.wolf @@ -9,7 +9,7 @@ + version="01.08" versionRow="MagicSmokeVersion"> Time at which the change was made. diff --git a/wob/db/order.wolf b/wob/db/order.wolf index d07e5df..a79aebd 100644 --- a/wob/db/order.wolf +++ b/wob/db/order.wolf @@ -179,9 +179,15 @@ Documents that refer to a specific order. E.g. invoices, Print@Home tickets, etc. - + + The file name shown to the customer, not necessarily related to the template. + The time when the file was last modified. + The time when the file was last retrieved by the customer. + + Flag whether the document is internal to the theater (false) or visible to the customer (true). + orderid,filename diff --git a/wob/transact/order.wolf b/wob/transact/order.wolf index 52dff6d..d55d46d 100644 --- a/wob/transact/order.wolf +++ b/wob/transact/order.wolf @@ -498,6 +498,9 @@ + + + @@ -506,6 +509,7 @@ + @@ -529,5 +533,22 @@ + + + + Gets all settings pertaining to Print@Home + + + + + + + + Overrides settings for Print@Home, use isnull=true to delete entries. + + + + +