Commit 1f9176ad authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Simplify path handling in the share plugin

Prefer ::toLocalFile() to ::path(). ::path() won't work on Windows properly.
Let KUrl handle the trailing slash adjusting, no need to do the string
handling ourselves.
Take advantage of the fact that it can be a url, at the moment it was just
doing silly type conversions.

REVIEW: 116484
parent 39c72cb4
......@@ -44,17 +44,14 @@ SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
QString SharePlugin::destinationDir()
KUrl SharePlugin::destinationDir() const
QString defaultPath = KGlobalSettings::downloadPath();
//FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/share");
QString dir = config->group("receive").readEntry("path", defaultPath);
if (!dir.endsWith('/')) dir.append('/');
KUrl dir = config->group("receive").readEntry("path", KGlobalSettings::downloadPath());
QDir().mkpath(KUrl(dir).path()); //Using KUrl to remove file:/// protocol, wich seems to confuse QDir.mkpath
kDebug(kdeconnect_kded()) << dir;
......@@ -89,7 +86,10 @@ bool SharePlugin::receivePackage(const NetworkPackage& np)
//kDebug(kdeconnect_kded()) << "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(destinationDir() + filename);
KUrl destination = destinationDir();
FileTransferJob* job = np.createPayloadTransferJob(destination);
connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));
} else if (np.has("text")) {
......@@ -45,7 +45,7 @@ private Q_SLOTS:
void openDestinationFolder();
QString destinationDir();
KUrl destinationDir() const;
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