-
Notifications
You must be signed in to change notification settings - Fork 0
/
qnotifiersettings.cpp
executable file
·104 lines (89 loc) · 2.97 KB
/
qnotifiersettings.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
#include "qnotifiersettings.h"
#include <QApplication>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QSettings>
#include <QVBoxLayout>
QNotifierSettings::QNotifierSettings(QWidget * parent) : QDialog(parent)
{
QVBoxLayout * layout = new QVBoxLayout();
QGroupBox * groupBox = new QGroupBox();
QFormLayout * formLayout = new QFormLayout();
this->guidLineEdit = new QLineEdit();
formLayout->addRow(new QLabel(tr("GUID:")), this->guidLineEdit);
groupBox->setLayout(formLayout);
this->buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(OkButtonClicked()));
connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(CancelButtonClicked()));
layout->addWidget(groupBox);
layout->addWidget(this->buttonBox);
this->setLayout(layout);
this->setWindowTitle(tr("Settings"));
}
QNotifierSettings::~QNotifierSettings()
{
}
void QNotifierSettings::Load()
{
QString filename = QApplication::applicationDirPath().left(1) + QNotifierSettings::Filename;
QSettings settings(filename, QSettings::NativeFormat);
this->guid = settings.value("guid", this->DefaultGUID).toString();
this->guidLineEdit->setText(this->guid);
}
bool TextToGUID(QString text, GUID * guid)
{
bool ok;
//QRegExp sep("^\\{?([a-fA-F\\d]+)-([a-fA-F\\d]+)-([a-fA-F\\d]+)-([a-fA-F\\d]+)\\}?$");
QRegExp sep("([a-fA-F0-9]+)-([a-fA-F0-9]+)-([a-fA-F0-9]+)-([a-fA-F0-9]+)");
//QStringList list = text.split(sep);
sep.indexIn(text);
QStringList list = sep.capturedTexts();
if (list.size() == 5) {
guid->Data1 = list.at(1).toULong(&ok, 16);
if (!ok)
return false;
guid->Data2 = list.at(2).toUShort(&ok, 16);
if (!ok)
return false;
guid->Data3 = list.at(3).toUShort(&ok, 16);
if (!ok)
return false;
unsigned long long data4 = list.at(4).toULongLong(&ok, 16);
if (!ok)
return false;
memcpy(guid->Data4, &data4, 8);
return true;
} else
return false;
}
void QNotifierSettings::Save()
{
QString filename = QApplication::applicationDirPath().left(1) + QNotifierSettings::Filename;
QSettings settings(filename, QSettings::NativeFormat);
settings.setValue("guid", this->guid);
}
GUID QNotifierSettings::GetGUID()
{
GUID guid;
TextToGUID(this->guid, &guid);
return guid;
}
void QNotifierSettings::OkButtonClicked()
{
GUID guid;
if (TextToGUID(this->guidLineEdit->text(), &guid)) {
if (this->guid != this->guidLineEdit->text()) {
this->guid = this->guidLineEdit->text();
emit this->NewGUID(guid);
this->Save();
}
this->accept();
}
}
void QNotifierSettings::CancelButtonClicked()
{
this->reject();
}