Skip to content

Commit

Permalink
add the timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonéri Le Bouder committed Mar 20, 2011
1 parent 3540f31 commit ea443f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
30 changes: 29 additions & 1 deletion fusinvform.cpp
@@ -1,12 +1,14 @@
#include "fusinvform.h"
#include "ui_fusinvform.h"
//#include <QMenu>

#include <iostream>
#include <QTimer>

FusInvForm::FusInvForm(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FusInvForm)
{
this->timeout = 0;
ui->setupUi(this);
/* QMenu *qmenu = new QMenu();
qmenu->addAction("Dans 2 heures");
Expand All @@ -20,8 +22,24 @@ FusInvForm::~FusInvForm()
delete ui;
}

void FusInvForm::setType(QString type) {

if (type == QString("info")) {
ui->pushCancel->hide();
}
}
void FusInvForm::setTimeout(QString timeout) {
if (timeout.toInt()>0) {
this->timeout = timeout.toInt();
ui->textEdit->setText(timeout);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateTimeoutStatus()));
timer->start(1000);
}
}

void FusInvForm::setMsg(QString msg) {

ui->textEdit->setText(msg);
}

Expand All @@ -42,3 +60,13 @@ void FusInvForm::on_pushOk_pressed()
std::cout<<"ok"<<std::endl;
QApplication::exit(0);
}

void FusInvForm::updateTimeoutStatus()
{
QString pattern = "Ok (%1)";
ui->pushOk->setText(pattern.arg(this->timeout--));
if (this->timeout == 0) {
std::cout<<"timeout"<<std::endl;
QApplication::exit(0);
}
}
7 changes: 5 additions & 2 deletions fusinvform.h
Expand Up @@ -13,19 +13,22 @@ class FusInvForm : public QMainWindow

public:
explicit FusInvForm(QWidget *parent = 0);
void setType(QString type);
void setTimeout(QString timeout);
void setMsg(QString msg);
void setTitle(QString title);
~FusInvForm();

private slots:

void on_pushButton_pressed();

void on_pushCancel_pressed();

void on_pushOk_pressed();

void updateTimeoutStatus();

private:
int timeout;
Ui::FusInvForm *ui;
};

Expand Down
12 changes: 7 additions & 5 deletions main.cpp
Expand Up @@ -6,13 +6,15 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStringList args = QCoreApplication::arguments ();
if (args.size() < 2) {
std::cerr<<"Usage: fusinvform title msg"<<std::endl;
exit(0);
if (args.size() < 3) {
std::cerr<<"Usage: fusinvform type title msg"<<std::endl;
exit(1);
}
FusInvForm w;
w.setTitle(args[1]);
w.setMsg(args[2]);
w.setType(args[1]);
w.setTimeout(args[2]);
w.setTitle(args[3]);
w.setMsg(args[4]);
w.show();

return a.exec();
Expand Down

0 comments on commit ea443f3

Please sign in to comment.