-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
109 lines (93 loc) · 2.91 KB
/
main.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <QApplication>
#include <QtGlobal>
#include <QByteArray>
#include <QString>
#include <QDebug>
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
#include <QChar>
#include <QProcess>
#include <QMovie>
#include <QPushButton>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QObject>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bool ok;
QProcess *proc = new QProcess;
proc->start("bash", QStringList() << "-c" << "uptime | awk '{ print $8 }'");
proc->waitForFinished(-1);
static QString stdout = proc->readAllStandardOutput();
stdout.truncate(stdout.lastIndexOf(QChar('.')));
qWarning() << stdout;
static int i = stdout.toInt(&ok);
QWidget *window = new QWidget();
window->resize(370,288);
window->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
window->setAttribute(Qt::WA_TranslucentBackground);
window->move(1800,900);
QMediaPlayer *player = new QMediaPlayer();
QVideoWidget *v_w = new QVideoWidget();
player->setVideoOutput(v_w);
player->setVolume(25);
QHBoxLayout *hbos = new QHBoxLayout;
hbos->addWidget(v_w);
window->setLayout(hbos);
static int i2;
QTimer *timer1 = new QTimer();
QObject::connect(timer1,&QTimer::timeout,[=](){
proc->start("bash", QStringList() << "-c" << "uptime | awk '{ print $8 }'");
proc->waitForFinished(-1);
stdout = proc->readAllStandardOutput();
stdout.truncate(stdout.lastIndexOf(QChar('.')));
i = stdout.toInt();
timer1->setInterval(2000);
if(i2 != i){
switch (i) {
case 2:
window->show();
player->setMedia(QUrl::fromLocalFile("/home/ajinkya/Videos/25.mp4"));
player->play();
timer1->stop();
i2 = i;
break;
case 4:
window->show();
player->setMedia(QUrl::fromLocalFile("/home/ajinkya/Videos/50.mp4"));
player->play();
timer1->stop();
i2 = i;
break;
case 6:
window->show();
player->setMedia(QUrl::fromLocalFile("/home/ajinkya/Videos/75.mp4"));
player->play();
timer1->stop();
i2 = i;
break;
case 8:
window->show();
player->setMedia(QUrl::fromLocalFile("/home/ajinkya/Videos/100.mp4"));
player->play();
timer1->stop();
i2 = i;
break;
default:
break;
}
}
});
timer1->start();
QObject::connect(player,&QMediaPlayer::stateChanged,[=](){
if(player->state() == 0){
//qApp->exit(0);
window->hide();
timer1->start();
}
});
return a.exec();
}