Commit 6238b858 authored by Lamarque Souza's avatar Lamarque Souza
Browse files

Add Bluetooth NAP tethering support to Plasma NM. I changed the patch to

make it fit the connection editor in kcm module and added the IpV4Widget
for DUN connections so that user can change his/her DNS list.  Thanks
Rajeesh K Nambiar for this patch.

REVIEW: 101266
BUG: 209624
parent e48256bc
......@@ -167,6 +167,7 @@ void Connection::init()
case Bluetooth:
addSetting(new BluetoothSetting());
addSetting(new GsmSetting());
addSetting(new Ipv4Setting());
addSetting(new PppSetting());
addSetting(new SerialSetting());
break;
......
......@@ -18,6 +18,8 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nm-setting-bluetooth.h>
#include "bluetoothconnectioneditor.h"
#include <QMap>
......@@ -29,6 +31,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "internals/settings/bluetooth.h"
#include "bluetoothwidget.h"
#include "gsmwidget.h"
#include "ipv4widget.h"
#include "pppwidget.h"
#include "connectionwidget.h"
......@@ -43,47 +46,65 @@ BluetoothConnectionEditor::BluetoothConnectionEditor(const QVariantList &args, Q
QString connectionId = args[0].toString();
m_connection = new Knm::Connection(QUuid(connectionId), Knm::Connection::Bluetooth);
m_contents->setConnection(m_connection);
BluetoothSetting *b = static_cast<BluetoothSetting *>(m_connection->setting(Setting::Bluetooth));
BluetoothWidget * bluetoothWidget = new BluetoothWidget(m_connection, this);
IpV4Widget * ipV4Widget = new IpV4Widget(m_connection, this);
QString defaultName;
// Bluetooth part
if (args.count() > 3) {
b->setNetworkname(args[1].toString());
b->setNetworktype(args[2].toString());
b->setBdaddrFromString(args[3].toString());
defaultName = i18n("%1 Network", args[1].toString());
} else {
defaultName = i18n("New Bluetooth Connection");
}
if (b->networktype() == NM_SETTING_BLUETOOTH_TYPE_PANU) {
m_contents->setDefaultName(defaultName);
addToTabWidget(bluetoothWidget);
addToTabWidget(ipV4Widget);
return;
}
// Gsm part for DUN
GsmWidget * gsmWidget = new GsmWidget(m_connection, this);
PppWidget * pppWidget = new PppWidget(m_connection, this);
// Gsm part
if (args.count() > 1) {
if (args.count() > 2) {
QList<QVariant> networkIds = args[2].toList();
defaultName = args[1].toString();
}
if (args.count() > 4) {
defaultName += " " + args[4].toString();
if (args.count() > 5) {
QList<QVariant> networkIds = args[5].toList();
if (!networkIds.isEmpty()) {
gsmWidget->setNetworkIds(networkIds);
}
}
if (args.count() > 3) {
QMap<QString, QVariant> apnInfo = args[3].toMap();
QString defaultName = args[1].toString();
if (!apnInfo["name"].isNull()) {
defaultName += " - " + apnInfo["name"].toString();
}
if (args.count() > 6) {
QMap<QString, QVariant> apnInfo = args[6].toMap();
gsmWidget->setApnInfo(apnInfo);
// Bluetooth part
if (args.count() > 5) {
BluetoothSetting *b = static_cast<BluetoothSetting *>(m_connection->setting(Setting::Bluetooth));
if (b) {
b->setBdaddrFromString(args[4].toString());
b->setNetworkname(args[5].toString());
defaultName = args[5].toString() + " " + defaultName;
}
if (!apnInfo["dnsList"].isNull()) {
ipV4Widget->setDns(apnInfo["dnsList"].toList());
}
if (!apnInfo["name"].isNull()) {
defaultName += " - " + apnInfo["name"].toString();
}
m_contents->setDefaultName(defaultName);
} else {
m_contents->setDefaultName(args[1].toString());
}
} else {
m_contents->setDefaultName(i18n("New Bluetooth Connection"));
}
m_contents->setDefaultName(defaultName);
addToTabWidget(bluetoothWidget);
addToTabWidget(gsmWidget);
addToTabWidget(pppWidget);
addToTabWidget(ipV4Widget);
}
BluetoothConnectionEditor::BluetoothConnectionEditor(Knm::Connection *con, QWidget *parent)
......@@ -97,45 +118,23 @@ BluetoothConnectionEditor::BluetoothConnectionEditor(Knm::Connection *con, QWidg
else
m_connection = con;
QString connectionId = m_connection->uuid().toString();
m_contents->setConnection(m_connection);
BluetoothWidget * bluetoothWidget = new BluetoothWidget(m_connection, this);
GsmWidget * gsmWidget = new GsmWidget(m_connection, this);
PppWidget * pppWidget = new PppWidget(m_connection, this);
/*
if (args.count() > 1) {
if (args.count() > 2) {
QList<QVariant> networkIds = args[2].toList();
if (!networkIds.isEmpty()) {
gsmWidget->setNetworkIds(networkIds);
}
}
BluetoothSetting *b = static_cast<BluetoothSetting *>(m_connection->setting(Setting::Bluetooth));
if (args.count() > 3) {
QMap<QString, QVariant> apnInfo = args[3].toMap();
if (apnInfo["name"].isNull()) {
m_contents->setDefaultName(args[1].toString());
} else {
m_contents->setDefaultName(args[1].toString() + " - " + apnInfo["name"].toString());
}
gsmWidget->setApnInfo(apnInfo);
if (!apnInfo["dnsList"].isNull()) {
ipV4Widget->setDns(apnInfo["dnsList"].toList());
}
} else {
m_contents->setDefaultName(args[1].toString());
}
} else {
m_contents->setDefaultName(i18n("New Cellular Connection"));
BluetoothWidget * bluetoothWidget = new BluetoothWidget(m_connection, this);
IpV4Widget * ipv4Widget = new IpV4Widget(m_connection, this);
if (b->networktype() == NM_SETTING_BLUETOOTH_TYPE_PANU) {
addToTabWidget(bluetoothWidget);
addToTabWidget(ipv4Widget);
} else if (b->networktype() == NM_SETTING_BLUETOOTH_TYPE_DUN){
GsmWidget * gsmWidget = new GsmWidget(m_connection, this);
PppWidget * pppWidget = new PppWidget(m_connection, this);
addToTabWidget(bluetoothWidget);
addToTabWidget(gsmWidget);
addToTabWidget(pppWidget);
addToTabWidget(ipv4Widget);
}
*/
addToTabWidget(bluetoothWidget);
addToTabWidget(gsmWidget);
addToTabWidget(pppWidget);
}
BluetoothConnectionEditor::~BluetoothConnectionEditor()
{
......
......@@ -94,35 +94,6 @@ GsmConnectionEditor::GsmConnectionEditor(Knm::Connection *con, QWidget *parent)
PppWidget * pppWidget = new PppWidget(m_connection, this);
IpV4Widget * ipV4Widget = new IpV4Widget(m_connection, this);
/*
if (args.count() > 1) {
if (args.count() > 2) {
QList<QVariant> networkIds = args[2].toList();
if (!networkIds.isEmpty()) {
gsmWidget->setNetworkIds(networkIds);
}
}
if (args.count() > 3) {
QMap<QString, QVariant> apnInfo = args[3].toMap();
if (apnInfo["name"].isNull()) {
m_contents->setDefaultName(args[1].toString());
} else {
m_contents->setDefaultName(args[1].toString() + " - " + apnInfo["name"].toString());
}
gsmWidget->setApnInfo(apnInfo);
if (!apnInfo["dnsList"].isNull()) {
ipV4Widget->setDns(apnInfo["dnsList"].toList());
}
} else {
m_contents->setDefaultName(args[1].toString());
}
} else {
m_contents->setDefaultName(i18n("New Cellular Connection"));
}
*/
addToTabWidget(gsmWidget);
addToTabWidget(pppWidget);
addToTabWidget(ipV4Widget);
......
......@@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nm-setting-bluetooth.h>
#include <QDBusInterface>
#include <QDBusReply>
......@@ -67,9 +69,10 @@ void saveConnection(Knm::Connection *con)
Bluetooth::Bluetooth(const QString bdaddr, const QString service): QObject(), mBdaddr(bdaddr), mService(service), mobileConnectionWizard(0)
{
mService = mService.toLower();
connect(Solid::Control::ModemManager::notifier(), SIGNAL(modemInterfaceAdded(const QString &)),
SLOT(modemAdded(const QString &)));
if (mService == "dun") {
connect(Solid::Control::ModemManager::notifier(), SIGNAL(modemInterfaceAdded(const QString &)),
SLOT(modemAdded(const QString &)));
}
QTimer::singleShot(0, this, SLOT(init()));
}
......@@ -79,11 +82,12 @@ Bluetooth::~Bluetooth()
void Bluetooth::init()
{
QRegExp rx("dun|rfcomm?");
QRegExp rx("dun|rfcomm?|nap");
if (rx.indexIn(mService) < 0) {
kDebug(KDE_DEFAULT_DEBUG_AREA) << "Error: we only support 'dun' service.";
kDebug(KDE_DEFAULT_DEBUG_AREA) << "Error: we only support 'dun' and 'nap' services.";
kapp->quit();
return;
}
// kDebug(KDE_DEFAULT_DEBUG_AREA) << "Bdaddr == " << mBdaddr;
......@@ -151,8 +155,15 @@ void Bluetooth::init()
mDeviceName = properties["Name"].toString();
}
// TODO: add panu support.
if (mService != QLatin1String("dun")) {
if (mService == "nap") {
ConnectionEditor editor(0);
Knm::Connection *con = editor.createConnection(true, Knm::Connection::Bluetooth, QVariantList() << mDeviceName << QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU) << mBdaddr, false);
if (con) {
saveConnection(con);
}
kapp->quit();
return;
} else if (mService != QLatin1String("dun")) {
mDunDevice = mService;
kDebug(KDE_DEFAULT_DEBUG_AREA) << "device(" << mDunDevice << ") for" << mBdaddr << " passed as argument";
kDebug(KDE_DEFAULT_DEBUG_AREA) << "waiting for it to be registered in ModemManager";
......@@ -169,6 +180,7 @@ void Bluetooth::init()
if (!reply.isValid()) {
kDebug(KDE_DEFAULT_DEBUG_AREA) << "Error: org.bluez.Serial.Connect did not work. Quiting.";
kapp->quit();
return;
}
mDunDevice = reply.value();
......@@ -189,7 +201,6 @@ void Bluetooth::modemAdded(const QString &udi)
mDunDevice = temp[2];
}
// TODO: implement PANU (mDunDevice is empty with PANU)
if (!modem || modem->device() != mDunDevice) {
if (modem) {
kDebug(KDE_DEFAULT_DEBUG_AREA) << "Modem" << modem->device() << " is not the one we want(" << mDunDevice << "). Quitting.";
......@@ -197,6 +208,7 @@ void Bluetooth::modemAdded(const QString &udi)
kDebug(KDE_DEFAULT_DEBUG_AREA) << "Modem interface for " << udi << " not found. Quitting";
}
kapp->quit();
return;
}
Knm::Connection::Type type;
......@@ -208,6 +220,7 @@ void Bluetooth::modemAdded(const QString &udi)
if (type == Knm::Connection::Unknown) {
kapp->quit();
return;
}
if (mobileConnectionWizard) {
......@@ -220,8 +233,10 @@ void Bluetooth::modemAdded(const QString &udi)
if (mobileConnectionWizard->exec() == QDialog::Accepted &&
mobileConnectionWizard->getError() == MobileProviders::Success) {
con = editor.createConnection(true, Knm::Connection::Bluetooth, mobileConnectionWizard->args() << mBdaddr << mDeviceName, false);
saveConnection(con);
con = editor.createConnection(true, Knm::Connection::Bluetooth, QVariantList() << mDeviceName << QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN) << mBdaddr << mobileConnectionWizard->args(), false);
if (con) {
saveConnection(con);
}
}
delete mobileConnectionWizard;
kapp->quit();
......
......@@ -41,7 +41,7 @@ int main(int argc, char **argv)
options.add("connection <connection-id>", ki18n("Connection ID to edit"));
options.add("hiddennetwork <ssid>", ki18n("Connect to a hidden wireless network"));
options.add("type <type>", ki18n("Connection type to create, must be one of '802-3-ethernet', '802-11-wireless', 'pppoe', 'vpn', 'cellular', 'bluetooth'"));
options.add("specific-args <args>", ki18n("Space-separated connection type-specific arguments, may be either 'gsm' or 'cdma' for cellular connections,\n'openvpn' or 'vpnc' for vpn connections,\ninterface and AP identifiers for wireless connections,\nbluetooth mac address and service (only 'dun' for now) for bluetooth connections.\n\nYou can also pass the serial device (i.e. 'rfcomm0') instead of service for bluetooth connections,\nin that case this program will block waiting for that device to be registered in ModemManager."));
options.add("specific-args <args>", ki18n("Space-separated connection type-specific arguments, may be either 'gsm' or 'cdma' for cellular connections,\n'openvpn' or 'vpnc' for vpn connections,\ninterface and AP identifiers for wireless connections,\nbluetooth mac address and service ('dun' or 'nap') for bluetooth connections.\n\nYou can also pass the serial device (i.e. 'rfcomm0') instead of service for dun bluetooth connections,\nin that case this program will block waiting for that device to be registered in ModemManager."));
options.add("+mode", ki18n("Operation mode, may be either 'create' or 'edit'"), "create");
KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
KApplication app;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment