summaryrefslogtreecommitdiff
authorclem <clem>2004-08-03 23:01:55 (UTC)
committer clem <clem>2004-08-03 23:01:55 (UTC)
commit9f1f34e77527bbb92bd73228e6c09e8cc1a865f9 (patch) (side-by-side diff)
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 @@
+#include "bluepingConfigWidget.h"
+
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qgroupbox.h>
+#include <qmessagebox.h>
+#include <qregexp.h>
+
+using Opie::Security::MultiauthConfigWidget;
+
+BluepingConfigWidget::BluepingConfigWidget(QWidget* parent = 0, const char* name = "Blueping configuration widget")
+: MultiauthConfigWidget(parent, name)
+{
+ m_config = new Config("Security");
+ m_config->setGroup("BluepingPlugin");
+ QVBoxLayout * baseLayout = new QVBoxLayout( this);
+ baseLayout->setSpacing(11);
+ baseLayout->setMargin(11);
+ baseLayout->setAlignment( Qt::AlignTop );
+
+ QGroupBox * configBox = new QGroupBox(0, Qt::Vertical, tr("Set the MAC address to ping here"), this);
+ baseLayout->addWidget(configBox);
+ QVBoxLayout *boxLayout = new QVBoxLayout( configBox->layout() );
+
+ QHBoxLayout * configLayout = new QHBoxLayout();
+ configLayout->setSpacing(6);
+ boxLayout->addLayout(configLayout);
+
+ QString mac = m_config->readEntry("mac");
+ if ( mac.isEmpty() )
+ mac = "00:00:00:00:00:00";
+
+ editMAC = new QLineEdit( mac, configBox, "editMAC" );
+ setMAC = new QPushButton( tr("Set"), configBox, "setMAC" );
+ configLayout->addWidget(editMAC);
+ configLayout->addWidget(setMAC);
+
+ 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>"
+ + tr("Note: if you don't put a valid MAC here but you activate the plugin, it will always succeed!") + "</em></p>", configBox );
+ boxLayout->addWidget(description);
+
+
+ connect(setMAC, SIGNAL( clicked() ), this, SLOT( changeMAC() ));
+
+}
+
+/// checks and writes the MAC in the config file, if its format is OK
+void BluepingConfigWidget::changeMAC() {
+ QString mac = editMAC->text();
+ 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]");
+ if ( (mac.length() == 17) && (macPattern.match(mac) == 0) )
+ {
+ m_config->writeEntry("mac", mac);
+ 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>",
+ QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton );
+ success.exec();
+ } else {
+ 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>"),
+ QMessageBox::Warning, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton );
+ failure.exec();
+ }
+}
+
+/// deletes the m_config pointer
+BluepingConfigWidget::~BluepingConfigWidget()
+{
+ delete m_config;
+}
+
+// does nothing (there's a button to save the config)
+void BluepingConfigWidget::writeConfig()
+{
+}
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 @@
+/**
+ * \file bluepingConfigWidget.h
+ * \brief "BluePing" plugin configuration widget
+ * \author Clément Séveillac (clement . seveillac (at) via . ecp . fr)
+ */
+/*
+ =. This file is part of the Opie Project
+ .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
+ .>+-=
+ _;:, .> :=|. This library is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This library is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef BLUEPINGCONFIGWIDGET_H
+#define BLUEPINGCONFIGWIDGET_H
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qpe/config.h>
+
+#include <opie2/multiauthconfigwidget.h>
+
+class BluepingConfigWidget : public Opie::Security::MultiauthConfigWidget {
+
+ Q_OBJECT
+
+public:
+ BluepingConfigWidget(QWidget* parent, const char* name);
+ virtual ~BluepingConfigWidget();
+ virtual void writeConfig();
+private:
+ QLineEdit *editMAC;
+ QPushButton *setMAC;
+ Config *m_config;
+private slots:
+ void changeMAC();
+
+};
+
+#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
@@ -1,200 +1,203 @@
#include "bluepingplugin.h"
#include <opie2/oapplication.h>
#include <opie2/odebug.h>
#include <opie2/odevice.h>
#include <qdialog.h>
#include <qlayout.h>
#include <qhbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtimer.h>
using namespace Opie::Core;
using Opie::Security::MultiauthPluginObject;
using Opie::Security::MultiauthConfigWidget;
-/// creates and initializes the m_config Config object
-BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0) {
- m_config = new Config("Security");
- m_config->setGroup("BluepingPlugin");
+/// standard c'tor
+BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0) {
bluetoothAlreadyRestarted = false;
}
-/// deletes the m_config Config object and noticeW if necessary
+/// cleans m_ping if we need to
BluepingPlugin::~BluepingPlugin() {
- delete m_config;
delete m_ping;
+ if (m_bluepingW != 0)
+ delete m_bluepingW;
}
/// Simply return its name (Blueping plugin)
QString BluepingPlugin::pluginName() const {
return "Blueping plugin";
}
-/// no configuration widget for the moment
+/// returns a BluepingConfigWidget
MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
- return 0l;
+ if (m_bluepingW == 0)
+ m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget");
+ return m_bluepingW;
}
QString BluepingPlugin::pixmapNameWidget() const {
return "security/bluepingplugin";
}
QString BluepingPlugin::pixmapNameConfig() const {
- return 0l;
+ return "security/bluepingplugin";
}
/// Emit the MultiauthPluginObject::Success emitCode
void BluepingPlugin::success() {
emit emitCode(MultiauthPluginObject::Success);
}
/// Emit the MultiauthPluginObject::Failure emitCode
void BluepingPlugin::failure() {
emit emitCode(MultiauthPluginObject::Failure);
}
/// Emit the MultiauthPluginObject::Skip emitCode
void BluepingPlugin::skip() {
emit emitCode(MultiauthPluginObject::Skip);
}
/// do the actual ping
void BluepingPlugin::ping() {
m_ping = new OProcess();
odebug << "pinging device: " << macToPing << oendl;
*m_ping << "l2ping" << "-c 1" << macToPing;
// starting to ping in the background
/// \todo as soon as ping is launched, check RSSI (signal strength) and check
/// it's high enough, meaning the device is close enough?
/// \todo make it optionally pollable, so don't finish the ping and call
/// Opie suspend if l2ping timeouts?
if ( !m_ping->start() ) {
oerr << "could not start l2ping" << oendl;
this->skip();
}
QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)),
this, SLOT(pingFinished(Opie::Core::OProcess*)) );
}
/// Deals with m_ping result
void BluepingPlugin::pingFinished(OProcess * ping) {
if ( ping->normalExit() && (ping->exitStatus() == 0) )
{
odebug << "Successful Bluetooth ping!" << oendl;
success();
}
else
{
odebug << "Failed Bluetooth ping..." << oendl;
failure();
}
}
/// Make one authentication attempt with this plugin
/**
* (very simple "success" / "failure" buttons in a dialog)
* \return The outcome code of this authentication
*/
int BluepingPlugin::authenticate() {
Config cfg("Security");
cfg.setGroup("BluepingPlugin");
macToPing = cfg.readEntry("mac");
if (!macToPing.isEmpty())
{
/* Standard, inescapable authentication dialog
- */
+ */
QDialog bluepingDialog(0,
"Blueping dialog",
TRUE,
Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop);
QRect desk = oApp->desktop()->geometry();
bluepingDialog.setGeometry( 0, 0, desk.width(), desk.height() );
// Creation of the particular widgets of our Blueping user interface
QVBoxLayout *layout = new QVBoxLayout(&bluepingDialog);
layout->setSpacing(11);
layout->setMargin(11);
layout->setAlignment( Qt::AlignTop );
QLabel title("<center><h1>\"Blueping\" <br />plugin</h1></center>", &bluepingDialog);
QLabel subTitle("<center><h2>Trying to reach your configured bluetooth device...</h2></center>", &bluepingDialog);
QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog);
QPushButton pbSkip("Skip", &bluepingDialog);
layout->addWidget(&title);
layout->addWidget(&subTitle);
layout->addWidget(&subTitle2);
layout->addWidget(&pbSkip, 0, Qt::AlignHCenter);
// connect the skip button to the skip signal emitting function
QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip()));
// connect the signal emitting functions to the bluepingDialog done(int) finishing function
QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int)));
+ // we can uncomment the following when testing
+ //bluetoothAlreadyRestarted = true;
if (!bluetoothAlreadyRestarted)
{
// we have just started or resumed the device, so Bluetooth has to be (re)started
OProcess killB;
killB << "killall" << "hciattach";
odebug << "killing Bluetooth..." << oendl;
if ( !killB.start(OProcess::Block) ) {
oerr << "could not kill bluetooth" << oendl;
}
OProcess startB;
switch ( ODevice::inst()->model() ) {
case Model_iPAQ_H39xx:
startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600";
break;
case Model_iPAQ_H5xxx:
startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600";
break;
default:
startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400";
break;
} // end switch on device models
if ( !startB.start(OProcess::Block) ) {
oerr << "could not (re)start bluetooth" << oendl;
return MultiauthPluginObject::Skip;
}
else
{
if ( startB.normalExit() && (startB.exitStatus() == 0) )
{
odebug << "hciattach exited normally."<< oendl;
bluetoothAlreadyRestarted = true;
// 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started
QTimer::singleShot( 500, this, SLOT(ping()) );
}
else
{
owarn << "hciattach exited anormally (error code: " << startB.exitStatus() << ")" << oendl;
} // end if startBluetooth exit status == 0
} // end if startBluetooth started
}
else
{
// we don't need to wait, since bluetooth has been started long enough ago
ping();
} // end if bluetooth not restarted
// start the dialog event loop, while the ping is starting (or will start soon) in the background
return bluepingDialog.exec();
}
else
{
owarn << "No Bluetooth device has been set!" << oendl;
owarn << "We will consider it as a successful authentication though." << oendl;
return MultiauthPluginObject::Success;
} // end if mac defined
}
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
@@ -1,81 +1,83 @@
/**
* \file bluepingplugin.h
* \brief Standard Opie multiauth plugin definition
* \author Clément Séveillac (clement . seveillac (at) via . ecp . fr)
*/
/*
=. This file is part of the Opie Project
.=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
.>+-=
_;:, .> :=|. This library is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This library is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef BLUEPING_PLUGIN_H
#define BLUEPING_PLUGIN_H
+#include "bluepingConfigWidget.h"
+
#include <opie2/multiauthplugininterface.h>
#include <opie2/oprocess.h>
#include <qobject.h>
#include <qstring.h>
#include <qpe/config.h>
/// Multi-authentication bluetooth plugin, which tries to ping a specific MAC address.
/**
* The plugin itself, implementing the main authenticate() function.
*/
class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObject {
Q_OBJECT
public:
BluepingPlugin();
virtual ~BluepingPlugin();
int authenticate();
Opie::Security::MultiauthConfigWidget * configWidget(QWidget * parent);
QString pixmapNameConfig() const;
QString pixmapNameWidget() const;
QString pluginName() const;
signals:
/// Signal carrying the result code of this plugin
void emitCode(int resultCode);
private slots:
void success();
void failure();
void skip();
void ping();
void pingFinished(Opie::Core::OProcess * ping);
private:
Opie::Core::OProcess *m_ping;
- Config * m_config;
+ BluepingConfigWidget * m_bluepingW;
bool bluetoothAlreadyRestarted;
QString macToPing;
};
#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 @@
TEMPLATE = lib
CONFIG += qt warn_on
-HEADERS = bluepingplugin.h bluepingpluginimpl.h
+HEADERS = bluepingplugin.h bluepingpluginimpl.h bluepingConfigWidget.h
-SOURCES = bluepingplugin.cpp bluepingpluginimpl.cpp
+SOURCES = bluepingplugin.cpp bluepingpluginimpl.cpp bluepingConfigWidget.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH +=
LIBS += -lqpe -lopieui2 -lopiecore2 -lopiesecurity2
DESTDIR = $(OPIEDIR)/plugins/security
TARGET = multiauthbluepingplugin
include ( $(OPIEDIR)/include.pro )