automatic update of display
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 17 Nov 2008 12:39:24 +0000 (12:39 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 17 Nov 2008 12:39:24 +0000 (12:39 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@187 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/overview.cpp
src/overview.h

index f449073..4f5a946 100644 (file)
@@ -18,6 +18,7 @@
 #include "orderwin.h"
 
 #include <QBoxLayout>
+#include <QCheckBox>
 #include <QComboBox>
 #include <QCryptographicHash>
 #include <QDomDocument>
 
 MOverview::MOverview(MWebRequest*mw,QString pk)
 {
+       profilekey=pk;
        req=mw;
        setAttribute(Qt::WA_DeleteOnClose);
        setWindowTitle("MagicSmoke: "+QSettings().value("profiles/"+pk+"/name").toString());
+       rtimer.setInterval(QSettings().value("profiles/"+pk+"/refresh",300).toInt()*1000);
+       rtimer.start();
+       connect(&rtimer,SIGNAL(timeout()),this,SLOT(refreshData()));
        
        //menu
        QMenuBar*mb=menuBar();
@@ -80,6 +85,9 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        m=mb->addMenu(tr("&Misc"));
        m->addAction(tr("&Return ticket..."),this,SLOT(ticketReturn()));
        
+       m=mb->addMenu(tr("C&onfigure"));
+       m->addAction(tr("&Auto-Refresh settings..."),this,SLOT(setRefresh()));
+       
        m=mb->addMenu(tr("&Admin"));
        m->setEnabled(req->hasRole("_admin"));
        m->addAction(tr("&Schedule Backup..."));
@@ -1142,6 +1150,61 @@ void MOverview::ticketReturn()
        if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8()));
 }
 
+void MOverview::refreshData()
+{
+       QSettings set;
+       set.beginGroup("profiles/"+profilekey);
+       if(set.value("refreshEvents",false).toBool() && req->hasRole("geteventlist"))
+               updateEvents();
+       if(set.value("refreshUsers",false).toBool() && req->hasRole("getusers"))
+               updateUsers();
+       if(set.value("refreshHosts",false).toBool() && req->hasRole("gethosts"))
+               updateHosts();
+}
+
+void MOverview::setRefresh()
+{
+       QSettings set;
+       set.beginGroup("profiles/"+profilekey);
+       //dialog
+       QDialog d;
+       d.setWindowTitle(tr("Refresh Settings"));
+       QVBoxLayout*vl;
+       QHBoxLayout*hl;
+       d.setLayout(vl=new QVBoxLayout);
+       vl->addLayout(hl=new QHBoxLayout);
+       hl->addWidget(new QLabel(tr("Refresh Rate (minutes):")),1);
+       QSpinBox*rate;
+       hl->addWidget(rate=new QSpinBox,0);
+       rate->setRange(1,999);
+       rate->setValue(set.value("refresh",300).toInt()/60);
+       QCheckBox *rev,*rus,*rho;
+       vl->addWidget(rev=new QCheckBox(tr("refresh &event list")));
+       rev->setChecked(set.value("refreshEvents",false).toBool());
+       vl->addWidget(rus=new QCheckBox(tr("refresh &user list")));
+       rus->setChecked(set.value("refreshUsers",false).toBool());
+       vl->addWidget(rho=new QCheckBox(tr("refresh &host list")));
+       rho->setChecked(set.value("refreshHosts",false).toBool());
+       vl->addSpacing(15);
+       vl->addStretch(10);
+       vl->addLayout(hl=new QHBoxLayout);
+       hl->addStretch(10);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("&OK")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+       hl->addWidget(p=new QPushButton(tr("&Cancel")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+       if(d.exec()!=QDialog::Accepted)return;
+       //write settings
+       set.setValue("refreshEvents",rev->isChecked());
+       set.setValue("refreshUsers",rus->isChecked());
+       set.setValue("refreshHosts",rho->isChecked());
+       set.setValue("refresh",rate->value()*60);
+       //reset timer
+       rtimer.stop();
+       rtimer.setInterval(rate->value()*60000);
+       rtimer.start();
+}
 
 /**********************************************/
 
index 2a747a6..4eae8a2 100644 (file)
@@ -18,6 +18,7 @@
 #include <QItemDelegate>
 #include <QMainWindow>
 #include <QPointer>
+#include <QTimer>
 
 #include "customer.h"
 
@@ -129,6 +130,11 @@ class MOverview:public QMainWindow
                /**find/select orders by customer*/
                void orderByCustomer();
                
+               /**refresh data that we can refresh*/
+               void refreshData();
+               /**set refresh timeout*/
+               void setRefresh();
+               
        private:
                //my session object
                QPointer<MWebRequest>req;
@@ -149,6 +155,8 @@ class MOverview:public QMainWindow
                //barcode cache
                QString lastbarcode;
                QDateTime lastbcscan;
+               //refresh timers
+               QTimer rtimer;
 };
 
 /**Helper dialog for changing passwords*/