summaryrefslogtreecommitdiff
authorclem <clem>2004-08-03 23:01:55 (UTC)
committer clem <clem>2004-08-03 23:01:55 (UTC)
commit9f1f34e77527bbb92bd73228e6c09e8cc1a865f9 (patch) (unidiff)
treeb3d98310987c57c2123c25f36ce1198a6b3e8d92
parent72d6b839da4aecba0ad6479c3e1d68192bbe6a51 (diff)
downloadopie-9f1f34e77527bbb92bd73228e6c09e8cc1a865f9.zip
opie-9f1f34e77527bbb92bd73228e6c09e8cc1a865f9.tar.gz
opie-9f1f34e77527bbb92bd73228e6c09e8cc1a865f9.tar.bz2
first revision of the Blueping configuration widget, which asks simply for a MAC address. It follows the style of e.g. NoticeConfigWidget
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/securityplugins/blueping/bluepingConfigWidget.cpp74
-rw-r--r--noncore/securityplugins/blueping/bluepingConfigWidget.h59
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.cpp23
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.h4
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.pro4
5 files changed, 151 insertions, 13 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
10using Opie::Security::MultiauthConfigWidget;
11
12BluepingConfigWidget::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
49void 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
66BluepingConfigWidget::~BluepingConfigWidget()
67{
68 delete m_config;
69}
70
71// does nothing (there's a button to save the config)
72void BluepingConfigWidget::writeConfig()
73{
74}
diff --git a/noncore/securityplugins/blueping/bluepingConfigWidget.h b/noncore/securityplugins/blueping/bluepingConfigWidget.h
new file mode 100644
index 0000000..bd1bec9
--- a/dev/null
+++ b/noncore/securityplugins/blueping/bluepingConfigWidget.h
@@ -0,0 +1,59 @@
1/**
2 * \file bluepingConfigWidget.h
3 * \brief "BluePing" plugin configuration widget
4 * \author Clément Séveillac (clement . seveillac (at) via . ecp . fr)
5 */
6/*
7 =. This file is part of the Opie Project
8 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
9 .>+-=
10 _;:, .> :=|. This library is free software; you can
11.> <`_, > . <= redistribute it and/or modify it under
12:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
13.="- .-=="i, .._ License as published by the Free Software
14 - . .-<_> .<> Foundation; either version 2 of the License,
15 ._= =} : or (at your option) any later version.
16 .%`+i> _;_.
17 .i_,=:_. -<s. This library is distributed in the hope that
18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
19 : .. .:, . . . without even the implied warranty of
20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.= = ; Library General Public License for more
23++= -. .` .: details.
24 : = ...= . :.=-
25 -. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = Library General Public License along with
27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31
32*/
33
34#ifndef BLUEPINGCONFIGWIDGET_H
35#define BLUEPINGCONFIGWIDGET_H
36#include <qlineedit.h>
37#include <qpushbutton.h>
38#include <qpe/config.h>
39
40#include <opie2/multiauthconfigwidget.h>
41
42class BluepingConfigWidget : public Opie::Security::MultiauthConfigWidget {
43
44 Q_OBJECT
45
46public:
47 BluepingConfigWidget(QWidget* parent, const char* name);
48 virtual ~BluepingConfigWidget();
49 virtual void writeConfig();
50private:
51 QLineEdit *editMAC;
52 QPushButton *setMAC;
53 Config *m_config;
54private slots:
55 void changeMAC();
56
57};
58
59#endif // BLUEPINGCONFIGWIDGET_H
diff --git a/noncore/securityplugins/blueping/bluepingplugin.cpp b/noncore/securityplugins/blueping/bluepingplugin.cpp
index 05fd3c2..f5d9ad6 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.cpp
+++ b/noncore/securityplugins/blueping/bluepingplugin.cpp
@@ -7,51 +7,52 @@
7#include <qdialog.h> 7#include <qdialog.h>
8#include <qlayout.h> 8#include <qlayout.h>
9#include <qhbox.h> 9#include <qhbox.h>
10#include <qlabel.h> 10#include <qlabel.h>
11#include <qpushbutton.h> 11#include <qpushbutton.h>
12#include <qtimer.h> 12#include <qtimer.h>
13 13
14using namespace Opie::Core; 14using namespace Opie::Core;
15using Opie::Security::MultiauthPluginObject; 15using Opie::Security::MultiauthPluginObject;
16using Opie::Security::MultiauthConfigWidget; 16using Opie::Security::MultiauthConfigWidget;
17 17
18 18
19/// creates and initializes the m_config Config object 19/// standard c'tor
20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0) { 20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0) {
21 m_config = new Config("Security");
22 m_config->setGroup("BluepingPlugin");
23 bluetoothAlreadyRestarted = false; 21 bluetoothAlreadyRestarted = false;
24} 22}
25 23
26/// deletes the m_config Config object and noticeW if necessary 24/// cleans m_ping if we need to
27BluepingPlugin::~BluepingPlugin() { 25BluepingPlugin::~BluepingPlugin() {
28 delete m_config;
29 delete m_ping; 26 delete m_ping;
27 if (m_bluepingW != 0)
28 delete m_bluepingW;
30} 29}
31 30
32/// Simply return its name (Blueping plugin) 31/// Simply return its name (Blueping plugin)
33QString BluepingPlugin::pluginName() const { 32QString BluepingPlugin::pluginName() const {
34 return "Blueping plugin"; 33 return "Blueping plugin";
35} 34}
36 35
37/// no configuration widget for the moment 36/// returns a BluepingConfigWidget
38MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) { 37MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
39 return 0l; 38 if (m_bluepingW == 0)
39 m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget");
40 return m_bluepingW;
40} 41}
41QString BluepingPlugin::pixmapNameWidget() const { 42QString BluepingPlugin::pixmapNameWidget() const {
42 return "security/bluepingplugin"; 43 return "security/bluepingplugin";
43} 44}
44QString BluepingPlugin::pixmapNameConfig() const { 45QString BluepingPlugin::pixmapNameConfig() const {
45 return 0l; 46 return "security/bluepingplugin";
46} 47}
47 48
48/// Emit the MultiauthPluginObject::Success emitCode 49/// Emit the MultiauthPluginObject::Success emitCode
49void BluepingPlugin::success() { 50void BluepingPlugin::success() {
50 emit emitCode(MultiauthPluginObject::Success); 51 emit emitCode(MultiauthPluginObject::Success);
51} 52}
52 53
53/// Emit the MultiauthPluginObject::Failure emitCode 54/// Emit the MultiauthPluginObject::Failure emitCode
54void BluepingPlugin::failure() { 55void BluepingPlugin::failure() {
55 emit emitCode(MultiauthPluginObject::Failure); 56 emit emitCode(MultiauthPluginObject::Failure);
56} 57}
57 58
@@ -97,25 +98,25 @@ void BluepingPlugin::ping() {
97/** 98/**
98 * (very simple "success" / "failure" buttons in a dialog) 99 * (very simple "success" / "failure" buttons in a dialog)
99 * \return The outcome code of this authentication 100 * \return The outcome code of this authentication
100 */ 101 */
101int BluepingPlugin::authenticate() { 102int BluepingPlugin::authenticate() {
102 103
103 Config cfg("Security"); 104 Config cfg("Security");
104 cfg.setGroup("BluepingPlugin"); 105 cfg.setGroup("BluepingPlugin");
105 macToPing = cfg.readEntry("mac"); 106 macToPing = cfg.readEntry("mac");
106 if (!macToPing.isEmpty()) 107 if (!macToPing.isEmpty())
107 { 108 {
108 /* Standard, inescapable authentication dialog 109 /* Standard, inescapable authentication dialog
109 */ 110 */
110 QDialog bluepingDialog(0, 111 QDialog bluepingDialog(0,
111 "Blueping dialog", 112 "Blueping dialog",
112 TRUE, 113 TRUE,
113 Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop); 114 Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop);
114 115
115 QRect desk = oApp->desktop()->geometry(); 116 QRect desk = oApp->desktop()->geometry();
116 bluepingDialog.setGeometry( 0, 0, desk.width(), desk.height() ); 117 bluepingDialog.setGeometry( 0, 0, desk.width(), desk.height() );
117 118
118 // Creation of the particular widgets of our Blueping user interface 119 // Creation of the particular widgets of our Blueping user interface
119 QVBoxLayout *layout = new QVBoxLayout(&bluepingDialog); 120 QVBoxLayout *layout = new QVBoxLayout(&bluepingDialog);
120 layout->setSpacing(11); 121 layout->setSpacing(11);
121 layout->setMargin(11); 122 layout->setMargin(11);
@@ -126,24 +127,26 @@ int BluepingPlugin::authenticate() {
126 QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog); 127 QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog);
127 QPushButton pbSkip("Skip", &bluepingDialog); 128 QPushButton pbSkip("Skip", &bluepingDialog);
128 layout->addWidget(&title); 129 layout->addWidget(&title);
129 layout->addWidget(&subTitle); 130 layout->addWidget(&subTitle);
130 layout->addWidget(&subTitle2); 131 layout->addWidget(&subTitle2);
131 layout->addWidget(&pbSkip, 0, Qt::AlignHCenter); 132 layout->addWidget(&pbSkip, 0, Qt::AlignHCenter);
132 133
133 // connect the skip button to the skip signal emitting function 134 // connect the skip button to the skip signal emitting function
134 QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip())); 135 QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip()));
135 // connect the signal emitting functions to the bluepingDialog done(int) finishing function 136 // connect the signal emitting functions to the bluepingDialog done(int) finishing function
136 QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int))); 137 QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int)));
137 138
139 // we can uncomment the following when testing
140 //bluetoothAlreadyRestarted = true;
138 if (!bluetoothAlreadyRestarted) 141 if (!bluetoothAlreadyRestarted)
139 { 142 {
140 // we have just started or resumed the device, so Bluetooth has to be (re)started 143 // we have just started or resumed the device, so Bluetooth has to be (re)started
141 OProcess killB; 144 OProcess killB;
142 killB << "killall" << "hciattach"; 145 killB << "killall" << "hciattach";
143 odebug << "killing Bluetooth..." << oendl; 146 odebug << "killing Bluetooth..." << oendl;
144 if ( !killB.start(OProcess::Block) ) { 147 if ( !killB.start(OProcess::Block) ) {
145 oerr << "could not kill bluetooth" << oendl; 148 oerr << "could not kill bluetooth" << oendl;
146 } 149 }
147 150
148 OProcess startB; 151 OProcess startB;
149 switch ( ODevice::inst()->model() ) { 152 switch ( ODevice::inst()->model() ) {
diff --git a/noncore/securityplugins/blueping/bluepingplugin.h b/noncore/securityplugins/blueping/bluepingplugin.h
index 0df3f78..b8d6734 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.h
+++ b/noncore/securityplugins/blueping/bluepingplugin.h
@@ -25,24 +25,26 @@
25 -. .:....=;==+<; You should have received a copy of the GNU 25 -. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = Library General Public License along with 26 -_. . . )=. = Library General Public License along with
27 -- :-=` this library; see the file COPYING.LIB. 27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef BLUEPING_PLUGIN_H 34#ifndef BLUEPING_PLUGIN_H
35#define BLUEPING_PLUGIN_H 35#define BLUEPING_PLUGIN_H
36 36
37#include "bluepingConfigWidget.h"
38
37#include <opie2/multiauthplugininterface.h> 39#include <opie2/multiauthplugininterface.h>
38 40
39#include <opie2/oprocess.h> 41#include <opie2/oprocess.h>
40 42
41#include <qobject.h> 43#include <qobject.h>
42#include <qstring.h> 44#include <qstring.h>
43#include <qpe/config.h> 45#include <qpe/config.h>
44 46
45/// Multi-authentication bluetooth plugin, which tries to ping a specific MAC address. 47/// Multi-authentication bluetooth plugin, which tries to ping a specific MAC address.
46/** 48/**
47 * The plugin itself, implementing the main authenticate() function. 49 * The plugin itself, implementing the main authenticate() function.
48 */ 50 */
@@ -63,19 +65,19 @@ class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObj
63 /// Signal carrying the result code of this plugin 65 /// Signal carrying the result code of this plugin
64 void emitCode(int resultCode); 66 void emitCode(int resultCode);
65 67
66 private slots: 68 private slots:
67 void success(); 69 void success();
68 void failure(); 70 void failure();
69 void skip(); 71 void skip();
70 void ping(); 72 void ping();
71 void pingFinished(Opie::Core::OProcess * ping); 73 void pingFinished(Opie::Core::OProcess * ping);
72 74
73 private: 75 private:
74 Opie::Core::OProcess *m_ping; 76 Opie::Core::OProcess *m_ping;
75 Config * m_config; 77 BluepingConfigWidget * m_bluepingW;
76 bool bluetoothAlreadyRestarted; 78 bool bluetoothAlreadyRestarted;
77 QString macToPing; 79 QString macToPing;
78 80
79}; 81};
80 82
81#endif 83#endif
diff --git a/noncore/securityplugins/blueping/bluepingplugin.pro b/noncore/securityplugins/blueping/bluepingplugin.pro
index 2cc0cd3..0946749 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.pro
+++ b/noncore/securityplugins/blueping/bluepingplugin.pro
@@ -1,18 +1,18 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3 3
4 HEADERS = bluepingplugin.h bluepingpluginimpl.h 4 HEADERS = bluepingplugin.h bluepingpluginimpl.h bluepingConfigWidget.h
5 5
6 SOURCES = bluepingplugin.cpp bluepingpluginimpl.cpp 6 SOURCES = bluepingplugin.cpp bluepingpluginimpl.cpp bluepingConfigWidget.cpp
7 7
8 8
9 INCLUDEPATH+= $(OPIEDIR)/include 9 INCLUDEPATH+= $(OPIEDIR)/include
10 DEPENDPATH+= 10 DEPENDPATH+=
11 11
12 LIBS += -lqpe -lopieui2 -lopiecore2 -lopiesecurity2 12 LIBS += -lqpe -lopieui2 -lopiecore2 -lopiesecurity2
13 13
14DESTDIR = $(OPIEDIR)/plugins/security 14DESTDIR = $(OPIEDIR)/plugins/security
15TARGET = multiauthbluepingplugin 15TARGET = multiauthbluepingplugin
16 16
17include ( $(OPIEDIR)/include.pro ) 17include ( $(OPIEDIR)/include.pro )
18 18