-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsniffernotifier.cpp
143 lines (121 loc) · 3.71 KB
/
sniffernotifier.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* This file is Copyright 2012
* Kristian Beres <[email protected]>
*
* Other copyrights also apply to some parts of this work. Please
* see the individual file headers for details.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version. See the file
* COPYING included with this distribution for more information.
*/
#include "sniffernotifier.h"
#include "ui_sniffernotifier.h"
#include "settings.h"
#include <QtGui>
#include <QString>
#include <QRect>
SnifferNotifier::SnifferNotifier(QWidget *parent) :
QWidget(parent),
ui(new Ui::SnifferNotifier)
{
ui->setupUi(this);
// settings
this->pSettings = new Settings();
// init
desktop = QApplication::desktop();
this->setWindowFlags(Qt::ToolTip);
this->setWindowOpacity(0.9);
//windowSize = size();
qDebug() << this->pSettings->getWidth();
width = this->pSettings->getWidth();//350;
height = this->pSettings->getHeight();//windowSize.height();
//QRect rec1 = desktop->screenGeometry(0);
//QRect rec2 = desktop->availableGeometry(0);
//height = 0, x = rec2.width() - width, y = rec2.height() + this->getTopPanel();
x = this->pSettings->getPositionX();
y = this->pSettings->getPositionY();
setGeometry(x,y,width,height);
QPixmap pixmap(":/images/gmailredsmall.png");
ui->lblImage->setPixmap(pixmap);
}
// settings test notify position
SnifferNotifier::SnifferNotifier(QWidget *parent, int x, int y, int width, int height) :
QWidget(parent),
ui(new Ui::SnifferNotifier)
{
ui->setupUi(this);
this->setWindowFlags(Qt::ToolTip);
this->setWindowOpacity(0.9);
this->width = width;
this->height = height;
this->x = x;
this->y = y;
setGeometry(x,y,width,height);
QPixmap pixmap(":/images/gmailredsmall.png");
ui->lblImage->setPixmap(pixmap);
}
void SnifferNotifier::sendMessage(QString data, int duration){
timer = new QTimer(this);
this->showWidget();
connect(timer, SIGNAL(timeout()), this, SLOT(hideWidget()));
timer->start(duration * 1000);
ui->lblMessage->setText(data);
}
// settings test notify position
void SnifferNotifier::sendMessage(QString data){
timer = new QTimer(this);
this->showWidget();
connect(timer, SIGNAL(timeout()), this, SLOT(hideWidget()));
timer->start(this->pSettings->getDuration() * 1000);
ui->lblMessage->setText(data);
}
void SnifferNotifier::showWidget(){
//y = y - 100;
//height = height + 100;
setGeometry(x,y,width,height);
this->show();
}
void SnifferNotifier::hideWidget(){
//y = y + 100;
//height = height - 100;
setGeometry(x,y,width,height);
this->hide();
timer->stop();
}
/**
* @brief SnifferNotifier::getTopPanel KDE stuff
* @return
*/
int SnifferNotifier::getTopPanel()
{
int topPanel = 0;
#ifdef Q_WS_X11
char * pPath = getenv ("KDE_FULL_SESSION");
if (QString(pPath) == NULL)
{
QProcess gconf;
gconf.start("gconftool", QStringList() << "--get" << "/schemas/apps/panel/toplevels/size");
gconf.waitForStarted();
gconf.closeWriteChannel();
gconf.waitForFinished();
QByteArray result = gconf.readAll();
QString str = QString(result);
int j = 0;
j = str.indexOf("Default Value:", j);
int k = 0;
k = str.indexOf("Owner:", k);
topPanel = str.section("", j, k).trimmed().section("",-3,-1).toInt();
}
#endif
return topPanel;
}
SnifferNotifier::~SnifferNotifier()
{
delete pSettings;
delete desktop;
delete timer;
delete ui;
}