-
Notifications
You must be signed in to change notification settings - Fork 3
/
dialogsettings.cpp
125 lines (105 loc) · 3.98 KB
/
dialogsettings.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
/**
* 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 "dialogsettings.h"
#include "ui_dialogsettings.h"
#include <QtCore>
#include "settings.h";
#include "mainwindow.h"
DialogSettings::DialogSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSettings)
{
ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0);
this->setWindowTitle("Settings");
ui->passwordInput->setEchoMode(QLineEdit::Password);
Settings settings;
QString username;
username.append("Active account: ");
username.append(settings.getUserName());
ui->labelActiveUser->setText(username);
ui->spinBoxRefresh->setValue(settings.getRefreshTime());
ui->comboBoxBrowsers->setCurrentIndex(settings.getBrowser());
ui->notifyPositionX->setValue(settings.getPositionX());
ui->notifyPositionY->setValue(settings.getPositionY());
ui->notifyWidth->setValue(settings.getWidth());
ui->notifyHeight->setValue(settings.getHeight());
ui->notifyDuration->setValue(settings.getDuration());
if(settings.getSystemNotifier()){
ui->chkSystemNotifier->setChecked(true);
qDebug() << "is checked";
}
if(settings.getAlertSound()){
ui->chkSoundAlert->setChecked(true);
}
//browser
}
void DialogSettings::on_btnOk_clicked(){
qDebug() << "OK button";
Settings settings;
if(!ui->userNameInput->text().isEmpty()){
settings.setUserName(ui->userNameInput->text());
settings.setPassword(ui->passwordInput->text());
}
QString browserCmd = settings.fetchBrowserCommand(ui->comboBoxBrowsers->currentIndex());
settings.setBrowserCmd(browserCmd);
settings.setBrowser(ui->comboBoxBrowsers->currentIndex());
settings.setRefreshTime(ui->spinBoxRefresh->value());
//notifier
settings.setPositoinX(ui->notifyPositionX->value());
settings.setPositoinY(ui->notifyPositionY->value());
settings.setWidth(ui->notifyWidth->value());
settings.setHeight(ui->notifyHeight->value());
settings.setDuration(ui->notifyDuration->value());
settings.setSystemNotifier(ui->chkSystemNotifier->isChecked());
settings.setAlertSound(ui->chkSoundAlert->isChecked());
settings.save();
// reload parent settings
connect(this, SIGNAL(destroyed()), this->parentWidget(), SLOT(load()));
this->close();
}
void DialogSettings::on_btnCancel_clicked()
{
this->close();
}
void DialogSettings::on_pushButton_clicked()
{
if(ui->chkSystemNotifier->isChecked()){
QString message;
message.append("notify-send \"");
message.append("New Test Email");
message.append("\" \"<br>");
message.append("Test notify message");
message.append("\" -i /usr/share/icons/hicolor/256x256/apps/gmailsniffer.png");
if(ui->chkSoundAlert->isChecked()){
// Play sound
Phonon::MediaObject *alertSound = Phonon::createPlayer(Phonon::MusicCategory , Phonon::MediaSource("/usr/share/sounds/gmailsniffer-newemail.ogg") );
alertSound->play();
}
system(message.toUtf8());
}else{
int x = ui->notifyPositionX->value();
int y = ui->notifyPositionY->value();
int width = ui->notifyWidth->value();
int height = ui->notifyHeight->value();
int duration = ui->notifyDuration->value();
pNotifyTest = new SnifferNotifier(this, x, y, width, height);
pNotifyTest->sendMessage("Test notify message<br>Test notify message", duration);
}
}
DialogSettings::~DialogSettings()
{
delete ui;
Phonon::MediaObject *alertSound;
}