00001 #include "bluepingConfigWidget.h"
00002
00003 #include <qwidget.h>
00004 #include <qlayout.h>
00005 #include <qlabel.h>
00006 #include <qgroupbox.h>
00007 #include <qmessagebox.h>
00008 #include <qregexp.h>
00009
00010 using Opie::Security::MultiauthConfigWidget;
00011
00012 BluepingConfigWidget::BluepingConfigWidget(QWidget* parent = 0, const char* name = "Blueping configuration widget")
00013 : MultiauthConfigWidget(parent, name)
00014 {
00015 Config config("Security");
00016 config.setGroup("BluepingPlugin");
00017 QVBoxLayout * baseLayout = new QVBoxLayout( this);
00018 baseLayout->setSpacing(11);
00019 baseLayout->setMargin(11);
00020 baseLayout->setAlignment( Qt::AlignTop );
00021
00022 QGroupBox * configBox = new QGroupBox(0, Qt::Vertical, tr("Set the MAC address to ping here"), this);
00023 baseLayout->addWidget(configBox);
00024 QVBoxLayout *boxLayout = new QVBoxLayout( configBox->layout() );
00025
00026 QHBoxLayout * configLayout = new QHBoxLayout();
00027 configLayout->setSpacing(6);
00028 boxLayout->addLayout(configLayout);
00029
00030 QString mac = config.readEntry("mac");
00031 if ( mac.isEmpty() )
00032 mac = "00:00:00:00:00:00";
00033
00034 editMAC = new QLineEdit( mac, configBox, "editMAC" );
00035 setMAC = new QPushButton( tr("Set"), configBox, "setMAC" );
00036 configLayout->addWidget(editMAC);
00037 configLayout->addWidget(setMAC);
00038
00039 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>"
00040 + tr("Note: if you don't put a valid MAC here but you activate the plugin, it will always succeed!") + "</em></p>", configBox );
00041 boxLayout->addWidget(description);
00042
00043
00044 connect(setMAC, SIGNAL( clicked() ), this, SLOT( changeMAC() ));
00045
00046 }
00047
00049 void BluepingConfigWidget::changeMAC() {
00050 QString mac = editMAC->text();
00051 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]");
00052 if ( (mac.length() == 17) && (macPattern.match(mac) == 0) )
00053 {
00054 Config config("Security");
00055 config.setGroup("BluepingPlugin");
00056 config.writeEntry("mac", mac);
00057 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>",
00058 QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton );
00059 success.exec();
00060 } else {
00061 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>"),
00062 QMessageBox::Warning, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton );
00063 failure.exec();
00064 }
00065 }
00066
00068 BluepingConfigWidget::~BluepingConfigWidget()
00069 {}
00070
00071
00072 void BluepingConfigWidget::writeConfig()
00073 {
00074 }