Introduce QVariantMap as an argument of NetworkPackage
Makes it possible to specify the different properties sent at once, rather than one by one as we used to do. Also port whenever possible to the initializer-list syntax. REVIEW: 128269
This commit is contained in:
parent
4dde19c8cc
commit
f9406e8afc
20 changed files with 82 additions and 98 deletions
|
@ -79,12 +79,8 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np)
|
|||
return (written != -1);
|
||||
}
|
||||
|
||||
UploadJob* LanDeviceLink::sendPayload(NetworkPackage& np)
|
||||
UploadJob* LanDeviceLink::sendPayload(const NetworkPackage& np)
|
||||
{
|
||||
QVariantMap transferInfo;
|
||||
//FIXME: The next two lines shouldn't be needed! Why are they here?
|
||||
transferInfo.insert("useSsl", true);
|
||||
transferInfo.insert("deviceId", deviceId());
|
||||
UploadJob* job = new UploadJob(np.payload(), deviceId());
|
||||
job->start();
|
||||
return job;
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
|
||||
QString name() override;
|
||||
bool sendPackage(NetworkPackage& np) override;
|
||||
UploadJob* sendPayload(NetworkPackage& np);
|
||||
UploadJob* sendPayload(const NetworkPackage& np);
|
||||
|
||||
void userRequestsPair() override;
|
||||
void userRequestsUnpair() override;
|
||||
|
|
|
@ -91,10 +91,8 @@ bool LanPairingHandler::requestPairing()
|
|||
;
|
||||
}
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||
np.set("pair", true);
|
||||
bool success;
|
||||
success = deviceLink()->sendPackage(np);
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", true}});
|
||||
const bool success = deviceLink()->sendPackage(np);
|
||||
if (success) {
|
||||
setInternalPairStatus(Requested);
|
||||
m_pairingTimeout.start();
|
||||
|
@ -106,8 +104,7 @@ bool LanPairingHandler::acceptPairing()
|
|||
{
|
||||
qDebug() << "User accepts pairing";
|
||||
m_pairingTimeout.stop(); // Just in case it is started
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||
np.set("pair", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", true}});
|
||||
bool success = deviceLink()->sendPackage(np);
|
||||
if (success) {
|
||||
setInternalPairStatus(Paired);
|
||||
|
@ -118,23 +115,20 @@ bool LanPairingHandler::acceptPairing()
|
|||
void LanPairingHandler::rejectPairing()
|
||||
{
|
||||
qDebug() << "User rejects pairing";
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||
np.set("pair", false);
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}});
|
||||
deviceLink()->sendPackage(np);
|
||||
setInternalPairStatus(NotPaired);
|
||||
}
|
||||
|
||||
void LanPairingHandler::unpair() {
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||
np.set("pair", false);
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}});
|
||||
deviceLink()->sendPackage(np);
|
||||
setInternalPairStatus(NotPaired);
|
||||
}
|
||||
|
||||
void LanPairingHandler::pairingTimeout()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||
np.set("pair", false);
|
||||
NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}});
|
||||
deviceLink()->sendPackage(np);
|
||||
setInternalPairStatus(NotPaired); //Will emit the change as well
|
||||
Q_EMIT pairingError(i18n("Timed out"));
|
||||
|
|
|
@ -109,9 +109,6 @@ void UploadJob::aboutToClose()
|
|||
QVariantMap UploadJob::transferInfo()
|
||||
{
|
||||
Q_ASSERT(mPort != 0);
|
||||
|
||||
QVariantMap ret;
|
||||
ret["port"] = mPort;
|
||||
return ret;
|
||||
return {{"port", mPort}};
|
||||
}
|
||||
|
||||
|
|
|
@ -48,13 +48,13 @@ QDebug operator<<(QDebug s, const NetworkPackage& pkg)
|
|||
//const QCA::EncryptionAlgorithm NetworkPackage::EncryptionAlgorithm = QCA::EME_PKCS1v15;
|
||||
const int NetworkPackage::ProtocolVersion = 7;
|
||||
|
||||
NetworkPackage::NetworkPackage(const QString& type)
|
||||
NetworkPackage::NetworkPackage(const QString& type, const QVariantMap &body)
|
||||
: mId(QString::number(QDateTime::currentMSecsSinceEpoch()))
|
||||
, mType(type)
|
||||
, mBody(body)
|
||||
, mPayload()
|
||||
, mPayloadSize(0)
|
||||
{
|
||||
mId = QString::number(QDateTime::currentMSecsSinceEpoch());
|
||||
mType = type;
|
||||
mBody = QVariantMap();
|
||||
mPayload = QSharedPointer<QIODevice>();
|
||||
mPayloadSize = 0;
|
||||
}
|
||||
|
||||
void NetworkPackage::createIdentityPackage(NetworkPackage* np)
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
//const static QCA::EncryptionAlgorithm EncryptionAlgorithm;
|
||||
const static int ProtocolVersion;
|
||||
|
||||
explicit NetworkPackage(const QString& type);
|
||||
explicit NetworkPackage(const QString& type, const QVariantMap &body = {});
|
||||
|
||||
static void createIdentityPackage(NetworkPackage*);
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args)
|
|||
|
||||
void BatteryPlugin::connected()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_BATTERY_REQUEST);
|
||||
np.set("request",true);
|
||||
NetworkPackage np(PACKAGE_TYPE_BATTERY_REQUEST, {{"request",true}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,7 @@ void ClipboardPlugin::clipboardChanged(QClipboard::Mode mode)
|
|||
|
||||
currentContent = content;
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_CLIPBOARD);
|
||||
np.set("content", content);
|
||||
NetworkPackage np(PACKAGE_TYPE_CLIPBOARD, {{"content", content}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ bool LockDevicePlugin::isLocked() const
|
|||
}
|
||||
void LockDevicePlugin::setLocked(bool locked)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST);
|
||||
np.set("setLocked", locked);
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST, {{"setLocked", locked}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
@ -73,8 +72,7 @@ bool LockDevicePlugin::receivePackage(const NetworkPackage & np)
|
|||
sendState = true;
|
||||
}
|
||||
if (sendState) {
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK);
|
||||
np.set("isLocked", iface()->GetActive());
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK, QVariantMap {{"isLocked", QVariant::fromValue<bool>(iface()->GetActive())}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
@ -95,8 +93,7 @@ void LockDevicePlugin::connected()
|
|||
{
|
||||
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST);
|
||||
np.set("requestLocked", QVariant());
|
||||
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST, {{"requestLocked", QVariant()}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,12 +98,14 @@ void MprisControlPlugin::addPlayer(const QString& service)
|
|||
|
||||
void MprisControlPlugin::seeked(qlonglong position){
|
||||
//qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player";
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS);
|
||||
np.set("pos", position/1000); //Send milis instead of nanos
|
||||
OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender();
|
||||
const QString& service = interface->service();
|
||||
const QString& player = playerList.key(service);
|
||||
np.set("player", player);
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS, {
|
||||
{"pos", position/1000}, //Send milis instead of nanos
|
||||
{"player", player}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
@ -279,8 +281,7 @@ bool MprisControlPlugin::receivePackage (const NetworkPackage& np)
|
|||
|
||||
void MprisControlPlugin::sendPlayerList()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS);
|
||||
np.set("playerList",playerList.keys());
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS, QVariantMap{{"playerList", QVariant::fromValue(playerList.keys())}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,49 +97,52 @@ QString MprisRemotePlugin::dbusPath() const
|
|||
|
||||
void MprisRemotePlugin::requestPlayerStatus()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player",m_player);
|
||||
np.set("requestNowPlaying",true);
|
||||
np.set("requestVolume",true);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {
|
||||
{"player", m_player},
|
||||
{"requestNowPlaying", true},
|
||||
{"requestVolume", true}}
|
||||
);
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisRemotePlugin::requestPlayerList()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("requestPlayerList", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {{"requestPlayerList", true}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisRemotePlugin::sendAction(const QString& action)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", m_player);
|
||||
np.set("action", action);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {
|
||||
{"player", m_player},
|
||||
{"action", action}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisRemotePlugin::seek(int offset) const
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", m_player);
|
||||
np.set("Seek", offset);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {
|
||||
{"player", m_player},
|
||||
{"Seek", offset}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisRemotePlugin::setVolume(int volume)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", m_player);
|
||||
np.set("setVolume",volume);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {
|
||||
{"player", m_player},
|
||||
{"setVolume",volume}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void MprisRemotePlugin::setPosition(int position)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", m_player);
|
||||
np.set("SetPosition", position);
|
||||
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {
|
||||
{"player", m_player},
|
||||
{"SetPosition", position}
|
||||
});
|
||||
sendPackage(np);
|
||||
|
||||
m_lastPosition = position;
|
||||
|
|
|
@ -70,12 +70,13 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
|
|||
removeNotification(id);
|
||||
} else if (np.get<bool>("isRequest")) {
|
||||
Q_FOREACH (const auto& n, mNotifications) {
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST);
|
||||
np.set("id", n->internalId());
|
||||
np.set("appName", n->appName());
|
||||
np.set("ticker", n->ticker());
|
||||
np.set("isClearable", n->dismissable());
|
||||
np.set("requestAnswer", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST, {
|
||||
{"id", n->internalId()},
|
||||
{"appName", n->appName()},
|
||||
{"ticker", n->ticker()},
|
||||
{"isClearable", n->dismissable()},
|
||||
{"requestAnswer", true}
|
||||
});
|
||||
mPlugin->sendPackage(np);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -37,8 +37,7 @@ NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& ar
|
|||
|
||||
void NotificationsPlugin::connected()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST);
|
||||
np.set("request", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST, {{"request", true}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,7 @@ void RemoteCommandsPlugin::connected()
|
|||
{
|
||||
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
|
||||
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
|
||||
np.set("requestCommandList", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
@ -81,8 +80,7 @@ void RemoteCommandsPlugin::setCommands(const QByteArray &cmds)
|
|||
|
||||
void RemoteCommandsPlugin::triggerCommand(const QString &key)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
|
||||
np.set("key", key);
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST, {{ "key", key }});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,16 +44,16 @@ RemoteControlPlugin::~RemoteControlPlugin()
|
|||
|
||||
void RemoteControlPlugin::moveCursor(const QPoint &p)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
||||
np.set("dx", p.x());
|
||||
np.set("dy", p.y());
|
||||
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD_REQUEST, {
|
||||
{"dx", p.x()},
|
||||
{"dy", p.y()}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
void RemoteControlPlugin::sendCommand(const QString &name, bool val)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
||||
np.set(name, val);
|
||||
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD_REQUEST, {{name, val}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,7 @@ void RunCommandPlugin::connected()
|
|||
void RunCommandPlugin::sendConfig()
|
||||
{
|
||||
QString commands = config()->get<QString>("commands","{}");
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND);
|
||||
np.set("commandList", commands);
|
||||
NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND, {{"commandList", commands}});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -162,11 +162,12 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId,
|
|||
return 0;
|
||||
|
||||
//qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Sending notification from" << appName << ":" <<ticker << "; appIcon=" << appIcon;
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
|
||||
np.set("id", QString::number(replacesId > 0 ? replacesId : ++id));
|
||||
np.set("appName", appName);
|
||||
np.set("ticker", ticker);
|
||||
np.set("isClearable", timeout == 0); // KNotifications are persistent if
|
||||
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION, {
|
||||
{"id", QString::number(replacesId > 0 ? replacesId : ++id)},
|
||||
{"appName", appName},
|
||||
{"ticker", ticker},
|
||||
{"isClearable", timeout == 0}
|
||||
}); // KNotifications are persistent if
|
||||
// timeout == 0, for other notifications
|
||||
// clearability is pointless
|
||||
|
||||
|
|
|
@ -189,8 +189,7 @@ void Mounter::onMountTimeout()
|
|||
|
||||
void Mounter::start()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_SFTP_REQUEST);
|
||||
np.set("startBrowsing", true);
|
||||
NetworkPackage np(PACKAGE_TYPE_SFTP_REQUEST, {{"startBrowsing", true}});
|
||||
m_sftp->sendPackage(np);
|
||||
|
||||
m_connectTimer.start();
|
||||
|
|
|
@ -53,10 +53,11 @@ bool TelepathyPlugin::receivePackage(const NetworkPackage& np)
|
|||
|
||||
void TelepathyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST);
|
||||
np.set("sendSms", true);
|
||||
np.set("phoneNumber", phoneNumber);
|
||||
np.set("messageBody", messageBody);
|
||||
NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST, {
|
||||
{"sendSms", true},
|
||||
{"phoneNumber", phoneNumber},
|
||||
{"messageBody", messageBody}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -122,17 +122,17 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np)
|
|||
|
||||
void TelephonyPlugin::sendMutePackage()
|
||||
{
|
||||
NetworkPackage package(PACKAGE_TYPE_TELEPHONY_REQUEST);
|
||||
package.set<QString>( "action", "mute" );
|
||||
NetworkPackage package(PACKAGE_TYPE_TELEPHONY_REQUEST, {{"action", "mute"}});
|
||||
sendPackage(package);
|
||||
}
|
||||
|
||||
void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody)
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST);
|
||||
np.set("sendSms", true);
|
||||
np.set("phoneNumber", phoneNumber);
|
||||
np.set("messageBody", messageBody);
|
||||
NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST, {
|
||||
{"sendSms", true},
|
||||
{"phoneNumber", phoneNumber},
|
||||
{"messageBody", messageBody}
|
||||
});
|
||||
sendPackage(np);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue