Port core to qCDebug

I had to keep the old kDebug code in kdebugnamespace because other parts
of the code are using it. Will be removed as soon as all code using it
is ported as well.
This commit is contained in:
Àlex Fiestas 2014-09-21 23:54:27 +02:00
parent ba08b593f9
commit df0c262998
9 changed files with 63 additions and 56 deletions

View file

@ -80,7 +80,7 @@ void LanDeviceLink::dataReceived()
const QByteArray package = mSocketLineReader->readLine();
//kDebug(debugArea()) << "LanDeviceLink dataReceived" << package;
//qCDebug(KDECONNECT_CORE) << "LanDeviceLink dataReceived" << package;
NetworkPackage unserialized(QString::null);
NetworkPackage::unserialize(package, &unserialized);
@ -90,7 +90,7 @@ void LanDeviceLink::dataReceived()
unserialized.decrypt(mPrivateKey, &decrypted);
if (decrypted.hasPayloadTransferInfo()) {
kDebug(debugArea()) << "HasPayloadTransferInfo";
qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo";
DownloadJob* job = new DownloadJob(mSocketLineReader->peerAddress(), decrypted.payloadTransferInfo());
job->start();
decrypted.setPayload(job->getPayload(), decrypted.payloadSize());

View file

@ -151,7 +151,7 @@ void LanLinkProvider::connectError()
disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
kDebug(debugArea()) << "Fallback (1), try reverse connection";
qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection";
NetworkPackage np("");
NetworkPackage::createIdentityPackage(&np);
np.set("tcpPort", mTcpPort);
@ -173,7 +173,7 @@ void LanLinkProvider::connected()
NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np;
const QString& deviceId = receivedPackage->get<QString>("deviceId");
//kDebug(debugArea()) << "Connected" << socket->isWritable();
//qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
@ -185,7 +185,7 @@ void LanLinkProvider::connected()
//TODO: Use reverse connection too to preffer connecting a unstable device (a phone) to a stable device (a computer)
if (success) {
//kDebug(debugArea()) << "Handshaking done (i'm the existing device)";
//qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the existing device)";
connect(deviceLink, SIGNAL(destroyed(QObject*)),
this, SLOT(deviceLinkDestroyed(QObject*)));
@ -206,7 +206,7 @@ void LanLinkProvider::connected()
} else {
//I think this will never happen
kDebug(debugArea()) << "Fallback (2), try reverse connection";
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection";
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port);
delete deviceLink;
}
@ -220,7 +220,7 @@ void LanLinkProvider::connected()
//I'm the new device and this is the answer to my UDP introduction (no data received yet)
void LanLinkProvider::newConnection()
{
//kDebug(debugArea()) << "LanLinkProvider newConnection";
//qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection";
while(mTcpServer->hasPendingConnections()) {
QTcpSocket* socket = mTcpServer->nextPendingConnection();
@ -234,7 +234,7 @@ void LanLinkProvider::newConnection()
NetworkPackage::createIdentityPackage(&np);
int written = socket->write(np.serialize());
kDebug(debugArea()) << "LanLinkProvider sent package." << written << " bytes written, waiting for reply";
qCDebug(KDECONNECT_CORE) << "LanLinkProvider sent package." << written << " bytes written, waiting for reply";
*/
}
@ -246,20 +246,20 @@ void LanLinkProvider::dataReceived()
const QByteArray data = socket->readLine();
//kDebug(debugArea()) << "LanLinkProvider received reply:" << data;
//qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
NetworkPackage np("");
bool success = NetworkPackage::unserialize(data, &np);
if (!success || np.type() != PACKAGE_TYPE_IDENTITY) {
kDebug(debugArea()) << "LanLinkProvider/newConnection: Not an identification package (wuh?)";
qCDebug(KDECONNECT_CORE) << "LanLinkProvider/newConnection: Not an identification package (wuh?)";
return;
}
const QString& deviceId = np.get<QString>("deviceId");
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
//kDebug(debugArea()) << "Handshaking done (i'm the new device)";
//qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)";
connect(deviceLink, SIGNAL(destroyed(QObject*)),
this, SLOT(deviceLinkDestroyed(QObject*)));
@ -282,7 +282,7 @@ void LanLinkProvider::dataReceived()
void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
{
//kDebug(debugArea()) << "deviceLinkDestroyed";
//qCDebug(KDECONNECT_CORE) << "deviceLinkDestroyed";
const QString id = destroyedDeviceLink->property("deviceId").toString();
QMap< QString, DeviceLink* >::iterator oldLinkIterator = mLinks.find(id);
if (oldLinkIterator != mLinks.end() && oldLinkIterator.value() == destroyedDeviceLink) {

View file

@ -39,7 +39,7 @@ void UploadJob::start()
while(!mServer->listen(QHostAddress::Any, mPort)) {
mPort++;
if (mPort > 1764) { //No ports available?
kDebug(debugArea()) << "Error opening a port in range 1739-1764 for file transfer";
qCDebug(KDECONNECT_CORE) << "Error opening a port in range 1739-1764 for file transfer";
mPort = 0;
return;
}

View file

@ -66,13 +66,13 @@ Daemon::Daemon(QObject *parent)
uuid = uuid.mid(1, uuid.length() - 2).replace("-", "_");
config->group("myself").writeEntry("id", uuid);
config->sync();
kDebug(debugArea()) << "My id:" << uuid;
qCDebug(KDECONNECT_CORE) << "My id:" << uuid;
}
//kDebug(debugArea()) << "QCA supported capabilities:" << QCA::supportedFeatures().join(",");
//qCDebug(KDECONNECT_CORE) << "QCA supported capabilities:" << QCA::supportedFeatures().join(",");
if(!QCA::isSupported("rsa")) {
//TODO: Maybe display this in a more visible way?
kWarning(debugArea()) << "Error: KDE Connect could not find support for RSA in your QCA installation, if your distribution provides"
qCDebug(KDECONNECT_CORE) << "Error: KDE Connect could not find support for RSA in your QCA installation, if your distribution provides"
<< "separate packages for QCA-ossl and QCA-gnupg plugins, make sure you have them installed and try again";
return;
}
@ -81,18 +81,18 @@ Daemon::Daemon(QObject *parent)
if (!config->group("myself").hasKey("privateKeyPath"))
{
const QString privateKeyPath = KStandardDirs::locateLocal("appdata", "key.pem", true);
QFile privKey(privateKeyPath);
if (!privKey.open(QIODevice::ReadWrite | QIODevice::Truncate))
{
kWarning(debugArea()) << "Error: KDE Connect could not create private keys file: " << privateKeyPath;
qCDebug(KDECONNECT_CORE) << "Error: KDE Connect could not create private keys file: " << privateKeyPath;
return;
}
if (!privKey.setPermissions(strict))
{
kWarning(debugArea()) << "Error: KDE Connect could not set permissions for private file: " << privateKeyPath;
qCDebug(KDECONNECT_CORE) << "Error: KDE Connect could not set permissions for private file: " << privateKeyPath;
}
//http://delta.affinix.com/docs/qca/rsatest_8cpp-example.html
@ -110,11 +110,11 @@ Daemon::Daemon(QObject *parent)
if (QFile::permissions(config->group("myself").readEntry("privateKeyPath")) != strict)
{
kWarning(debugArea()) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKeyPath");
qCDebug(KDECONNECT_CORE) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKeyPath");
}
//Debugging
kDebug(debugArea()) << "Starting KdeConnect daemon";
qCDebug(KDECONNECT_CORE) << "Starting KdeConnect daemon";
//Load backends (hardcoded by now, should be plugins in a future)
d->mLinkProviders.insert(new LanLinkProvider());
@ -182,14 +182,14 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
const QString& id = identityPackage.get<QString>("deviceId");
//kDebug(debugArea()) << "Device discovered" << id << "via" << dl->provider()->name();
//qCDebug(KDECONNECT_CORE) << "Device discovered" << id << "via" << dl->provider()->name();
if (d->mDevices.contains(id)) {
//kDebug(debugArea()) << "It is a known device";
//qCDebug(KDECONNECT_CORE) << "It is a known device";
Device* device = d->mDevices[id];
device->addLink(identityPackage, dl);
} else {
//kDebug(debugArea()) << "It is a new device";
//qCDebug(KDECONNECT_CORE) << "It is a new device";
Device* device = new Device(this, identityPackage, dl);
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceReachableStatusChanged()));
@ -210,12 +210,12 @@ void Daemon::onDeviceReachableStatusChanged()
Q_EMIT deviceVisibilityChanged(id, device->isReachable());
//kDebug(debugArea()) << "Device" << device->name() << "reachable status changed:" << device->isReachable();
//qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "reachable status changed:" << device->isReachable();
if (!device->isReachable()) {
if (!device->isPaired()) {
kDebug(debugArea()) << "Destroying device" << device->name();
qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
Q_EMIT deviceRemoved(id);
d->mDevices.remove(id);
device->deleteLater();

View file

@ -44,6 +44,8 @@
#include "backends/linkprovider.h"
#include "networkpackage.h"
Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core")
Device::Device(QObject* parent, const QString& id)
: QObject(parent)
, m_deviceId(id)
@ -240,7 +242,7 @@ static bool lessThan(DeviceLink* p1, DeviceLink* p2)
void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
{
//kDebug(debugArea()) << "Adding link to" << id() << "via" << link->provider();
//qCDebug(KDECONNECT_CORE) << "Adding link to" << id() << "via" << link->provider();
m_protocolVersion = identityPackage.get<int>("protocolVersion");
if (m_protocolVersion != NetworkPackage::ProtocolVersion) {
@ -287,7 +289,7 @@ void Device::removeLink(DeviceLink* link)
{
m_deviceLinks.removeOne(link);
//kDebug(debugArea()) << "RemoveLink" << m_deviceLinks.size() << "links remaining";
//qCDebug(KDECONNECT_CORE) << "RemoveLink" << m_deviceLinks.size() << "links remaining";
if (m_deviceLinks.isEmpty()) {
reloadPlugins();
@ -320,12 +322,12 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
{
if (np.type() == PACKAGE_TYPE_PAIR) {
//kDebug(debugArea()) << "Pair package";
//qCDebug(KDECONNECT_CORE) << "Pair package";
bool wantsPair = np.get<bool>("pair");
if (wantsPair == isPaired()) {
kDebug(debugArea()) << "Already" << (wantsPair? "paired":"unpaired");
qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
if (m_pairStatus == Device::Requested) {
m_pairStatus = Device::NotPaired;
m_pairingTimeut.stop();
@ -340,7 +342,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
const QString& key = np.get<QString>("publicKey");
m_publicKey = QCA::RSAPublicKey::fromPEM(key);
if (m_publicKey.isNull()) {
kDebug(debugArea()) << "ERROR decoding key";
qCDebug(KDECONNECT_CORE) << "ERROR decoding key";
if (m_pairStatus == Device::Requested) {
m_pairStatus = Device::NotPaired;
m_pairingTimeut.stop();
@ -351,12 +353,12 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
if (m_pairStatus == Device::Requested) { //We started pairing
kDebug(debugArea()) << "Pair answer";
qCDebug(KDECONNECT_CORE) << "Pair answer";
setAsPaired();
} else {
kDebug(debugArea()) << "Pair request";
qCDebug(KDECONNECT_CORE) << "Pair request";
KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent
notification->setPixmap(QIcon::fromTheme("dialog-information").pixmap(48, 48));
@ -374,7 +376,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
} else {
kDebug(debugArea()) << "Unpair request";
qCDebug(KDECONNECT_CORE) << "Unpair request";
PairStatus prevPairStatus = m_pairStatus;
m_pairStatus = Device::NotPaired;
@ -397,7 +399,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
plugin->receivePackage(np);
}
} else {
kDebug(debugArea()) << "device" << name() << "not paired, ignoring package" << np.type();
qCDebug(KDECONNECT_CORE) << "device" << name() << "not paired, ignoring package" << np.type();
unpair();
}
@ -415,7 +417,7 @@ bool Device::sendOwnPublicKey()
void Device::rejectPairing()
{
kDebug(debugArea()) << "Rejected pairing";
qCDebug(KDECONNECT_CORE) << "Rejected pairing";
m_pairStatus = Device::NotPaired;
@ -431,7 +433,7 @@ void Device::acceptPairing()
{
if (m_pairStatus != Device::RequestedByPeer) return;
kDebug(debugArea()) << "Accepted pairing";
qCDebug(KDECONNECT_CORE) << "Accepted pairing";
bool success = sendOwnPublicKey();

View file

@ -41,18 +41,18 @@ FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, int si
mDeviceName = i18nc("Device name that will appear on the jobs", "KDE-Connect");
setCapabilities(Killable);
kDebug(debugArea()) << "FileTransferJob Downloading payload to" << destination;
qCDebug(KDECONNECT_CORE) << "FileTransferJob Downloading payload to" << destination;
}
void FileTransferJob::openFinished(KJob* job)
{
kDebug(debugArea()) << job->errorString();
qCDebug(KDECONNECT_CORE) << job->errorString();
}
void FileTransferJob::start()
{
QMetaObject::invokeMethod(this, "doStart", Qt::QueuedConnection);
//kDebug(debugArea()) << "FileTransferJob start";
//qCDebug(KDECONNECT_CORE) << "FileTransferJob start";
}
void FileTransferJob::doStart()
@ -136,10 +136,10 @@ void FileTransferJob::open(KIO::Job* job)
{
Q_UNUSED(job);
//kDebug(debugArea()) << "FileTransferJob open";
//qCDebug(KDECONNECT_CORE) << "FileTransferJob open";
if (!mOrigin) {
kDebug(debugArea()) << "FileTransferJob: Origin is null";
qCDebug(KDECONNECT_CORE) << "FileTransferJob: Origin is null";
return;
}
@ -161,7 +161,7 @@ void FileTransferJob::readyRead()
mWritten += data.size();
setProcessedAmount(Bytes, mWritten);
//kDebug(debugArea()) << "readyRead" << mSize << mWritten << bytes;
//qCDebug(KDECONNECT_CORE) << "readyRead" << mSize << mWritten << bytes;
if (mSize > -1) {
//If a least 1 second has passed since last update
@ -192,11 +192,11 @@ void FileTransferJob::sourceFinished()
//TODO: MD5 check the file
if (mSize > -1 && mWritten != mSize) {
kDebug(debugArea()) << "Received incomplete file (" << mWritten << " of " << mSize << " bytes)";
qCDebug(KDECONNECT_CORE) << "Received incomplete file (" << mWritten << " of " << mSize << " bytes)";
setError(1);
setErrorText(i18n("Received incomplete file"));
} else {
kDebug(debugArea()) << "Finished transfer" << mDestinationJob->url();
qCDebug(KDECONNECT_CORE) << "Finished transfer" << mDestinationJob->url();
}
mDestinationJob->close();
mDestinationJob->deleteLater();

View file

@ -1,5 +1,6 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
* Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -18,9 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDEBUG_KDECONNECT_KDED_H
#define KDEBUG_KDECONNECT_KDED_H
#ifndef QDEBUG_KDECONNECT_CORE_H
#define QDEBUG_KDECONNECT_CORE_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_CORE)
//Just until we port everything to qCDebug
#include <KDebug>
#include <kdemacros.h>
@ -29,6 +35,5 @@ inline int debugArea()
static int theArea = KDebug::registerArea("kdeconnect");
return theArea;
};
#endif

View file

@ -95,7 +95,7 @@ QByteArray NetworkPackage::serialize() const
auto jsonDocument = QJsonDocument::fromVariant(variant);
QByteArray json = jsonDocument.toJson(QJsonDocument::Compact);
if (json.isEmpty()) {
kDebug(debugArea()) << "Serialization error:";
qCDebug(KDECONNECT_CORE) << "Serialization error:";
} else {
if (!isEncrypted()) {
//kDebug(kDebugArea) << "Serialized package:" << json;
@ -132,7 +132,7 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
QJsonParseError parseError;
auto parser = QJsonDocument::fromJson(a, &parseError);
if (parser.isNull()) {
kDebug(debugArea()) << "Unserialization error:" << parseError.errorString();
qCDebug(KDECONNECT_CORE) << "Unserialization error:" << parseError.errorString();
return false;
}

View file

@ -50,7 +50,7 @@ KPluginInfo PluginLoader::getPluginInfo(const QString& name) const
{
KService::Ptr service = plugins[name];
if (!service) {
kDebug(debugArea()) << "Plugin unknown" << name;
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << name;
return KPluginInfo();
}
@ -63,13 +63,13 @@ PluginData PluginLoader::instantiatePluginForDevice(const QString& name, Device*
KService::Ptr service = plugins[name];
if (!service) {
kDebug(debugArea()) << "Plugin unknown" << name;
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << name;
return ret;
}
KPluginFactory *factory = KPluginLoader(service->library()).factory();
if (!factory) {
kDebug(debugArea()) << "KPluginFactory could not load the plugin:" << service->library();
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service->library();
return ret;
}
@ -81,11 +81,11 @@ PluginData PluginLoader::instantiatePluginForDevice(const QString& name, Device*
//FIXME any reason to use QObject in template param instead KdeConnectPlugin?
ret.plugin = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << ret.outgoingInterfaces);
if (!ret.plugin) {
kDebug(debugArea()) << "Error loading plugin";
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
return ret;
}
kDebug(debugArea()) << "Loaded plugin:" << service->name();
qCDebug(KDECONNECT_CORE) << "Loaded plugin:" << service->name();
return ret;
}