Added button to open incoming file transfer's folder in browser

This commit is contained in:
Albert Vaca 2013-10-01 02:44:49 +02:00
parent 4363ea8fdb
commit a06cf677f4
3 changed files with 15 additions and 6 deletions

View file

@ -28,6 +28,7 @@
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, int size, const KUrl& destination): KJob()
{
Q_ASSERT(destination.isLocalFile());
//TODO: Make a precondition before calling this function that destination file exists
QFile(destination.path()).open(QIODevice::WriteOnly | QIODevice::Truncate); //HACK: KIO is so dumb it can't create the file if it doesn't exist
mDestination = KIO::open(destination, QIODevice::WriteOnly);
connect(mDestination, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*)));
@ -86,9 +87,8 @@ void FileTransferJob::readyRead()
}
if (mSize > -1 && mWritten >= mSize) { //At the end or expected size reached
qDebug() << "No more data to read";
disconnect(mOrigin.data(), SIGNAL(readyRead()),this, SLOT(readyRead()));
mOrigin->close();
//sourceFinished();
} else if (mOrigin->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
}

View file

@ -65,12 +65,14 @@ bool FileTransferPlugin::receivePackage(const NetworkPackage& np)
}
*/
if (np.type() != PACKAGE_TYPE_FILETRANSFER) return false;
qDebug() << "File transfer";
if (np.hasPayload()) {
qDebug() << "receiving file";
//qDebug() << "receiving file";
QString filename = np.get<QString>("filename", QString::number(QDateTime::currentMSecsSinceEpoch()));
//TODO: Ask before overwritting or rename file if it already exists
FileTransferJob* job = np.createPayloadTransferJob(mDestinationDir + filename);
connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));
job->start();
@ -111,7 +113,12 @@ void FileTransferPlugin::finished(KJob* job)
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(i18n("Transfer finished"));
notification->setText(transferJob->destination().fileName());
//TODO: Add action "open destination folder"
notification->setActions(QStringList(i18n("Open destination folder")));
connect(notification, SIGNAL(action1Activated()), this, SLOT(openDestinationFolder()));
notification->sendEvent();
}
void FileTransferPlugin::openDestinationFolder()
{
QDesktopServices::openUrl(mDestinationDir);
}

View file

@ -39,9 +39,11 @@ public Q_SLOTS:
virtual void connected() { }
void finished(KJob*);
private Q_SLOTS:
void openDestinationFolder();
private:
QString mDestinationDir;
};
#endif