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) ...@@ -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 //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"); KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/share");
QString dir = config->group("receive").readEntry("path", defaultPath); KUrl dir = config->group("receive").readEntry("path", KGlobalSettings::downloadPath());
dir.adjustPath(KUrl::AddTrailingSlash);
if (!dir.endsWith('/')) dir.append('/');
QDir().mkpath(KUrl(dir).path()); //Using KUrl to remove file:/// protocol, wich seems to confuse QDir.mkpath QDir().mkpath(dir.toLocalFile());
kDebug(kdeconnect_kded()) << dir; kDebug(kdeconnect_kded()) << dir;
...@@ -89,7 +86,10 @@ bool SharePlugin::receivePackage(const NetworkPackage& np) ...@@ -89,7 +86,10 @@ bool SharePlugin::receivePackage(const NetworkPackage& np)
//kDebug(kdeconnect_kded()) << "receiving file"; //kDebug(kdeconnect_kded()) << "receiving file";
QString filename = np.get<QString>("filename", QString::number(QDateTime::currentMSecsSinceEpoch())); QString filename = np.get<QString>("filename", QString::number(QDateTime::currentMSecsSinceEpoch()));
//TODO: Ask before overwritting or rename file if it already exists //TODO: Ask before overwritting or rename file if it already exists
FileTransferJob* job = np.createPayloadTransferJob(destinationDir() + filename);
KUrl destination = destinationDir();
destination.addPath(filename);
FileTransferJob* job = np.createPayloadTransferJob(destination);
connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*))); connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));
job->start(); job->start();
} else if (np.has("text")) { } else if (np.has("text")) {
......
...@@ -45,7 +45,7 @@ private Q_SLOTS: ...@@ -45,7 +45,7 @@ private Q_SLOTS:
void openDestinationFolder(); void openDestinationFolder();
private: private:
QString destinationDir(); KUrl destinationDir() const;
}; };
#endif #endif
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