more control over print at home
authorKonrad Rosenbaum <konrad@silmor.de>
Sat, 13 Aug 2016 11:37:28 +0000 (13:37 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Sat, 13 Aug 2016 11:37:28 +0000 (13:37 +0200)
doc/printathome-template.txt [new file with mode: 0644]
printathome/client.cpp [new file with mode: 0644]
printathome/client.h [new file with mode: 0644]
printathome/pah.cpp
printathome/pah.h
sesscli/scli.cpp
sesscli/scli.h
sessman/sman.cpp
sessman/sman.h

diff --git a/doc/printathome-template.txt b/doc/printathome-template.txt
new file mode 100644 (file)
index 0000000..ef0a356
--- /dev/null
@@ -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 (file)
index 0000000..b00df10
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// C++ Implementation: print @ home
+//
+// Description: Client Settings
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2016
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#include "client.h"
+
+#include <QFormLayout>
+#include <QBoxLayout>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QComboBox>
+
+#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 (file)
index 0000000..993186b
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// C++ Interface: print @ home, client config
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2016
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#ifndef MSMOKE_PAH_CLIENT_H
+#define MSMOKE_PAH_CLIENT_H
+
+#include <QDialog>
+
+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
index 1f9133f..539b674 100644 (file)
@@ -1,3 +1,15 @@
+//
+// C++ Implementation: print q home
+//
+// Description: Main Program
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (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)
index 78c7060..f1faadf 100644 (file)
@@ -1,3 +1,15 @@
+//
+// C++ Interface: print @ home
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (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
index c6751d9..9d43d03 100644 (file)
@@ -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<QPair<QString,QString>>();
-       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<QPair<QString,QString>>();
+       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<QString,QString>(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());
+}
index 0fafdae..f8e5e26 100644 (file)
@@ -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<QPair<QString,QString>> 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<QPair<QString,QString>> 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<QPair<QString,QString>> 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<QPair<QString,QString>> mmenu;
+       QString msid,mprofile,muser,mdefaultprofile;
+       QList<QPair<QString,QString>> mmenu,mprofiles;
 };
 
 
index b0637ae..2085a50 100644 (file)
@@ -20,6 +20,7 @@
 #include <QSignalMapper>
 #include <QSystemTrayIcon>
 #include <QTimer>
+#include <QSettings>
 
 #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"<<cmd;
        }
@@ -244,6 +255,20 @@ void MSessionManager::sendMenu(QLocalSocket*s)
        s->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;i<prf.size();i++){
+               s->write(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"<<cmd;
index c726ac5..1d82180 100644 (file)
@@ -59,6 +59,10 @@ private slots:
 
 signals:
        void openConfig();
+       void setProfile(QString);
+       void setUsername(QString);
+       void setPassword(QString);
+       void startLogin();
 
 private:
        QLocalServer*mserver=nullptr;
@@ -68,6 +72,7 @@ private:
        bool mhaveslave=false;
 
        void sendMenu(QLocalSocket*);
+       void sendProfiles(QLocalSocket*);
        void sendSessionInfo(QLocalSocket*);
        void startBinary(QString);
 };