Commit 158e32ad authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Debugging filetransfer

parent 7d4143b9
......@@ -45,7 +45,7 @@ Device::Device(const NetworkPackage& identityPackage, DeviceLink* dl)
int protocolVersion = identityPackage.get<int>("protocolVersion");
if (protocolVersion != NetworkPackage::ProtocolVersion) {
qDebug() << "WARNING: Device uses a different protocol version" << protocolVersion << "expected" << NetworkPackage::ProtocolVersion;
qDebug() << m_deviceName << "- warning, device uses a different protocol version" << protocolVersion << "expected" << NetworkPackage::ProtocolVersion;
//TODO: Do something
}
......
......@@ -79,7 +79,9 @@ QByteArray NetworkPackage::serialize() const
if (!ok) {
qDebug() << "Serialization error:" << serializer.errorMessage();
} else {
//qDebug() << "Serialized package:" << json;
if (!isEncrypted()) {
qDebug() << "Serialized package:" << json;
}
json.append('\n');
}
......@@ -95,7 +97,7 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
bool ok;
QVariantMap variant = parser.parse(a, &ok).toMap();
if (!ok) {
qDebug() << "Unserialization error:" << parser.errorLine() << parser.errorString();
qDebug() << "Unserialization error:" << a;
return false;
}
......@@ -103,7 +105,9 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
QJson::QObjectHelper::qvariant2qobject(variant,np);
if (variant.contains("payloadTransferInfo")) {
//qDebug() << "Unserializing payloadTransferInfo";
if (!np->isEncrypted()) {
//qDebug() << "Unserializing payloadTransferInfo";
}
np->mPayloadTransferInfo = variant["payloadTransferInfo"].toMap();
}
......
......@@ -56,6 +56,7 @@ public:
void encrypt(QCA::PublicKey& key);
bool decrypt(QCA::PrivateKey& key, NetworkPackage* out) const;
bool isEncrypted() const { return mType == PACKAGE_TYPE_ENCRYPTED; }
const QString& id() const { return mId; }
const QString& type() const { return mType; }
......
......@@ -39,32 +39,36 @@ FileTransferPlugin::FileTransferPlugin(QObject* parent, const QVariantList& args
{
//TODO: Use downloads user path
//TODO: Be able to change this from config
mDestinationDir = QDesktopServices::DesktopLocation;
mDestinationDir = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
}
bool FileTransferPlugin::receivePackage(const NetworkPackage& np)
{
//TODO: Move this code to a test and do a diff between files
/*
if (np.type() == PACKAGE_TYPE_PING) {
//if (np.type() == PACKAGE_TYPE_PING) {
NetworkPackage np(PACKAGE_TYPE_FILETRANSFER);
np.set("filename", mDestinationDir + "/itworks.txt");
qDebug() << "sending file" << (QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc");
NetworkPackage out(PACKAGE_TYPE_FILETRANSFER);
out.set("filename", mDestinationDir + "/itworks.txt");
//TODO: Use shared pointers
AutoClosingQFile* file = new AutoClosingQFile("/home/vaka/KdeConnect.apk"); //Test file to transfer
AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer
np.setPayload(file);
out.setPayload(file);
device()->sendPackage(np);
device()->sendPackage(out);
return true;
}
*/
//}
if (np.type() != PACKAGE_TYPE_FILETRANSFER) return false;
qDebug() << "file transfer";
if (np.hasPayload()) {
qDebug() << "receiving file";
QString filename = np.get<QString>("filename");
QIODevice* incoming = np.payload();
FileTransferJob* job = new FileTransferJob(incoming,filename);
......
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