-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathareyouokdialog.cpp
More file actions
93 lines (71 loc) · 2.48 KB
/
areyouokdialog.cpp
File metadata and controls
93 lines (71 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "areyouokdialog.h"
#include "ui_areyouokdialog.h"
#include <QProcess>
#define TOKEN "to complete"
#define CHAT_ID "to complete"
#define MESSAGE "Hola%2C necesito ayuda!"
AreYouOkDialog::AreYouOkDialog(QWidget *parent, unsigned long rtime, unsigned long mtime) :
QDialog(parent),
ui(new Ui::AreYouOkDialog)
{
ui->setupUi(this);
this->repeatTime=rtime;
this->messageTime=mtime;
this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
this->dialogTimer = new QTimer(this);
this->dialogTimer->setSingleShot(true);
connect(this->dialogTimer, SIGNAL(timeout()),this, SLOT(startDialogTimer()));
this->messageTimer = new QTimer(this);
connect(this->messageTimer, SIGNAL(timeout()),this, SLOT(sendMessageTimer()));
this->messageLabelTimer = new QTimer(this);
connect(this->messageLabelTimer, SIGNAL(timeout()),this, SLOT(updateMessageTimer()));
}
AreYouOkDialog::~AreYouOkDialog()
{
delete ui;
}
void AreYouOkDialog::run(){
this->dialogTimer->start(this->repeatTime);
}
void AreYouOkDialog::stop(){
this->dialogTimer->stop();
this->close();
}
void AreYouOkDialog::updateMessageTimer(){
if(this->currentMessageTime>0)
this->currentMessageTime-=1000;
this->ui->AreYouOkTimerLabel->setText("Time remaining for the next message: "+QString::number(this->currentMessageTime/1000)+" s");
}
void AreYouOkDialog::startDialogTimer()
{
this->show();
this->setWindowState(Qt::WindowState::WindowActive);
this->setFocus();
this->currentMessageTime=this->messageTime;
this->ui->AreYouOkTimerLabel->setText("Time remaining for the next message: "+QString::number(this->currentMessageTime/1000)+" s");
this->messageLabelTimer->start(1000);
this->messageTimer->start(this->messageTime);
}
void AreYouOkDialog::sendMessageTimer()
{
this->messageLabelTimer->stop();
this->currentMessageTime=this->messageTime;
this->messageLabelTimer->start(1000);
QProcess *myProcess = new QProcess();
QStringList arguments;
QString token =TOKEN;
QString chat_id=CHAT_ID;
arguments<<"https://api.telegram.org/bot" + token+ "/sendMessage?chat_id=" + chat_id + "&text="+ MESSAGE;
myProcess->start("curl", arguments);
}
void AreYouOkDialog::on_YESpushButton_clicked()
{
this->hide();
this->messageLabelTimer->stop();
this->messageTimer->stop();
this->dialogTimer->start(this->repeatTime);
}
void AreYouOkDialog::on_NOpushButton_clicked()
{
sendMessageTimer();
}