Diffstat (limited to 'noncore/securityplugins/blueping/bluepingConfigWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/securityplugins/blueping/bluepingConfigWidget.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/noncore/securityplugins/blueping/bluepingConfigWidget.cpp b/noncore/securityplugins/blueping/bluepingConfigWidget.cpp new file mode 100644 index 0000000..876ccda --- a/dev/null +++ b/noncore/securityplugins/blueping/bluepingConfigWidget.cpp | |||
@@ -0,0 +1,74 @@ | |||
1 | #include "bluepingConfigWidget.h" | ||
2 | |||
3 | #include <qwidget.h> | ||
4 | #include <qlayout.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <qgroupbox.h> | ||
7 | #include <qmessagebox.h> | ||
8 | #include <qregexp.h> | ||
9 | |||
10 | using Opie::Security::MultiauthConfigWidget; | ||
11 | |||
12 | BluepingConfigWidget::BluepingConfigWidget(QWidget* parent = 0, const char* name = "Blueping configuration widget") | ||
13 | : MultiauthConfigWidget(parent, name) | ||
14 | { | ||
15 | m_config = new Config("Security"); | ||
16 | m_config->setGroup("BluepingPlugin"); | ||
17 | QVBoxLayout * baseLayout = new QVBoxLayout( this); | ||
18 | baseLayout->setSpacing(11); | ||
19 | baseLayout->setMargin(11); | ||
20 | baseLayout->setAlignment( Qt::AlignTop ); | ||
21 | |||
22 | QGroupBox * configBox = new QGroupBox(0, Qt::Vertical, tr("Set the MAC address to ping here"), this); | ||
23 | baseLayout->addWidget(configBox); | ||
24 | QVBoxLayout *boxLayout = new QVBoxLayout( configBox->layout() ); | ||
25 | |||
26 | QHBoxLayout * configLayout = new QHBoxLayout(); | ||
27 | configLayout->setSpacing(6); | ||
28 | boxLayout->addLayout(configLayout); | ||
29 | |||
30 | QString mac = m_config->readEntry("mac"); | ||
31 | if ( mac.isEmpty() ) | ||
32 | mac = "00:00:00:00:00:00"; | ||
33 | |||
34 | editMAC = new QLineEdit( mac, configBox, "editMAC" ); | ||
35 | setMAC = new QPushButton( tr("Set"), configBox, "setMAC" ); | ||
36 | configLayout->addWidget(editMAC); | ||
37 | configLayout->addWidget(setMAC); | ||
38 | |||
39 | QLabel * description = new QLabel( "<p>" + tr("Detecting another Bluetooth device by its MAC address provides a minimal and automatic level of protection.") + "</p><p><em>" | ||
40 | + tr("Note: if you don't put a valid MAC here but you activate the plugin, it will always succeed!") + "</em></p>", configBox ); | ||
41 | boxLayout->addWidget(description); | ||
42 | |||
43 | |||
44 | connect(setMAC, SIGNAL( clicked() ), this, SLOT( changeMAC() )); | ||
45 | |||
46 | } | ||
47 | |||
48 | /// checks and writes the MAC in the config file, if its format is OK | ||
49 | void BluepingConfigWidget::changeMAC() { | ||
50 | QString mac = editMAC->text(); | ||
51 | QRegExp macPattern("[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]"); | ||
52 | if ( (mac.length() == 17) && (macPattern.match(mac) == 0) ) | ||
53 | { | ||
54 | m_config->writeEntry("mac", mac); | ||
55 | QMessageBox success( tr("MAC address saved!"), "<p>" + tr("Make sure that Bluetooth is turned on on the corresponding device when the Blueping plugin needs it.") + "</p>", | ||
56 | QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton ); | ||
57 | success.exec(); | ||
58 | } else { | ||
59 | QMessageBox failure( tr("Please enter a valid MAC"), "<p>" + tr("Please separate the six pairs of digits of your MAC like this: 01:02:03:04:05:06") + tr("</p>"), | ||
60 | QMessageBox::Warning, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton ); | ||
61 | failure.exec(); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /// deletes the m_config pointer | ||
66 | BluepingConfigWidget::~BluepingConfigWidget() | ||
67 | { | ||
68 | delete m_config; | ||
69 | } | ||
70 | |||
71 | // does nothing (there's a button to save the config) | ||
72 | void BluepingConfigWidget::writeConfig() | ||
73 | { | ||
74 | } | ||