-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
107 lines (75 loc) · 2.36 KB
/
mainwindow.cpp
File metadata and controls
107 lines (75 loc) · 2.36 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
#include <QTimer>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QSound>
QString mediadir = "./media/"; //change mediadir2 in main.cpp aswell if needed
extern "C" {
int mains(int argc, char **argv);
}
void test(){
char *argv1[]={"appname","-h","test"};
// char *argv1[]={"appname","-l",,ui->deviceCMB->currentText().toLocal8Bit().data(),"test"};
int argc1 = sizeof(argv1) / sizeof(char*) - 1;
mains(argc1,argv1);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
char *argv1[]={"appname","-l",QString::number(ui->threshold->value()).toLocal8Bit().data(),"-d",ui->deviceCMB->currentText().toLocal8Bit().data(),"test"};
int argc1 = sizeof(argv1) / sizeof(char*) - 1;
// mains(argc1,argv1); to run the command
QPixmap oPixmap(32,32);
oPixmap.load ( mediadir + "trayicon.png");
QIcon oIcon( oPixmap );
trayIcon = new QSystemTrayIcon(oIcon);
QAction *quit_action = new QAction( "Exit", trayIcon );
connect( quit_action, SIGNAL(triggered()), this, SLOT(on_exit()) );
trayIconMenu = new QMenu(this);
trayIconMenu->addAction( quit_action );
trayIcon->setContextMenu( trayIconMenu);
trayIcon->setVisible(true);
//trayIcon->showMessage("Test Message", "Text", QSystemTrayIcon::Information, 1000);
//trayIcon->show();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
this->show();
break;
case QSystemTrayIcon::DoubleClick:
this->show();
break;
case QSystemTrayIcon::MiddleClick:
showMessage();
break;
default:
;
}
}
void MainWindow::showMessage()
{
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
trayIcon->showMessage(tr("QSatisfy"), tr("Will you smoke now..."), icon, 100);
}
void MainWindow::on_exit()
{
this->close();
QApplication::quit();
}
void MainWindow::showEvent( QShowEvent* event ) {
QWidget::showEvent( event );
}