More robust fix to problem with device ids being non exportable on dbus
This commit is contained in:
parent
0b511a73cc
commit
ddb9190fbe
6 changed files with 80 additions and 14 deletions
|
@ -23,6 +23,7 @@ set(kded_kdeconnect_SRCS
|
|||
kdeconnectplugin.cpp
|
||||
pluginloader.cpp
|
||||
|
||||
dbushelper.cpp
|
||||
networkpackage.cpp
|
||||
filetransferjob.cpp
|
||||
daemon.cpp
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include <QTcpServer>
|
||||
#include <QUdpSocket>
|
||||
|
||||
#include <KSharedConfig>
|
||||
#include <KConfigGroup>
|
||||
|
||||
#include "../../kdebugnamespace.h"
|
||||
#include "landevicelink.h"
|
||||
|
||||
|
@ -129,11 +132,11 @@ void LanLinkProvider::newUdpConnection()
|
|||
delete receivedPackage;
|
||||
}
|
||||
|
||||
NetworkPackage np2("");
|
||||
NetworkPackage::createIdentityPackage(&np2);
|
||||
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
|
||||
const QString myId = config->group("myself").readEntry<QString>("id","");
|
||||
|
||||
if (receivedPackage->get<QString>("deviceId") == np2.get<QString>("deviceId")) {
|
||||
//kDebug(debugArea()) << "Ignoring my own broadcast";
|
||||
if (receivedPackage->get<QString>("deviceId") == myId) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <KConfigGroup>
|
||||
#include <KStandardDirs>
|
||||
|
||||
#include "dbushelper.h"
|
||||
#include "kdebugnamespace.h"
|
||||
#include "networkpackage.h"
|
||||
#include "backends/lan/lanlinkprovider.h"
|
||||
|
@ -68,8 +69,7 @@ Daemon::Daemon(QObject *parent)
|
|||
|
||||
if (!config->group("myself").hasKey("id")) {
|
||||
QString uuid = QUuid::createUuid().toString();
|
||||
//uuids contain charcaters that are not exportable in dbus paths
|
||||
uuid = uuid.mid(1, uuid.length() - 2).replace("-", "_");
|
||||
DbusHelper::filterNonExportableCharacters(uuid);
|
||||
config->group("myself").writeEntry("id", uuid);
|
||||
config->sync();
|
||||
kDebug(debugArea()) << "My id:" << uuid;
|
||||
|
|
34
core/dbushelper.cpp
Normal file
34
core/dbushelper.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Copyright 2014 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* 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 "dbushelper.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include <kdebug.h>
|
||||
|
||||
namespace DbusHelper {
|
||||
|
||||
void filterNonExportableCharacters(QString& s)
|
||||
{
|
||||
static QRegExp regexp("[^A-Za-z0-9_]", Qt::CaseSensitive, QRegExp::Wildcard);
|
||||
s.replace(regexp,"_");
|
||||
}
|
||||
|
||||
}
|
29
core/dbushelper.h
Normal file
29
core/dbushelper.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Copyright 2014 Albert Vaca <albertvaka@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KDECONNECT_DBUSHELPER_H
|
||||
#define KDECONNECT_DBUSHELPER_H
|
||||
#include <QString>
|
||||
|
||||
namespace DbusHelper {
|
||||
void filterNonExportableCharacters(QString& s);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -32,6 +32,7 @@
|
|||
#include <qjson/serializer.h>
|
||||
#include <qjson/qobjecthelper.h>
|
||||
|
||||
#include "dbushelper.h"
|
||||
#include "filetransferjob.h"
|
||||
#include "pluginloader.h"
|
||||
|
||||
|
@ -120,13 +121,11 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
|
|||
}
|
||||
np->mPayloadTransferInfo = variant["payloadTransferInfo"].toMap(); //Will return an empty qvariantmap if was not present, which is ok
|
||||
|
||||
//uuids contain charcaters that are not exportable in dbus paths
|
||||
np->mId = np->mId.mid(1, np->mId.length() - 2).replace("-", "_");
|
||||
|
||||
//Ids containing characters that are not allowed as dbus paths would make app crash
|
||||
if (np->mBody.contains("deviceId"))
|
||||
{
|
||||
QString deviceId = np->get<QString>("deviceId");
|
||||
deviceId = deviceId.mid(1, deviceId.length() - 2).replace("-", "_");
|
||||
DbusHelper::filterNonExportableCharacters(deviceId);
|
||||
np->set("deviceId", deviceId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue