Merge internal openUrl with internal openFile

This commit is contained in:
Nicolas Fella 2019-06-17 21:35:53 +00:00
parent 7236ffda3b
commit 8406e0de99
2 changed files with 7 additions and 19 deletions

View file

@ -192,13 +192,14 @@ void SharePlugin::openDestinationFolder()
QDesktopServices::openUrl(destinationDir());
}
void SharePlugin::shareUrl(const QUrl& url)
void SharePlugin::shareUrl(const QUrl& url, bool open)
{
NetworkPacket packet(PACKET_TYPE_SHARE_REQUEST);
if(url.isLocalFile()) {
if (url.isLocalFile()) {
QSharedPointer<QIODevice> ioFile(new QFile(url.toLocalFile()));
packet.setPayload(ioFile, ioFile->size());
packet.set<QString>(QStringLiteral("filename"), QUrl(url).fileName());
packet.set<bool>(QStringLiteral("open"), open);
} else {
packet.set<QString>(QStringLiteral("url"), url.toString());
}
@ -207,7 +208,7 @@ void SharePlugin::shareUrl(const QUrl& url)
void SharePlugin::shareUrls(const QStringList& urls) {
for(const QString& url : urls) {
shareUrl(QUrl(url));
shareUrl(QUrl(url), false);
}
}
@ -218,18 +219,6 @@ void SharePlugin::shareText(const QString& text)
sendPacket(packet);
}
void SharePlugin::openFile(const QUrl& url)
{
NetworkPacket packet(PACKET_TYPE_SHARE_REQUEST);
if(url.isLocalFile()) {
QSharedPointer<QIODevice> ioFile(new QFile(url.toLocalFile()));
packet.setPayload(ioFile, ioFile->size());
packet.set<QString>(QStringLiteral("filename"), QUrl(url).fileName());
packet.set<bool>(QStringLiteral("open"), true);
}
sendPacket(packet);
}
QString SharePlugin::dbusPath() const
{
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/share");

View file

@ -41,10 +41,10 @@ public:
explicit SharePlugin(QObject* parent, const QVariantList& args);
///Helper method, QDBus won't recognize QUrl
Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url)); }
Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url), false); }
Q_SCRIPTABLE void shareUrls(const QStringList& urls);
Q_SCRIPTABLE void shareText(const QString& text);
Q_SCRIPTABLE void openFile(const QString& file) { openFile(QUrl(file)); }
Q_SCRIPTABLE void openFile(const QString& file) { shareUrl(QUrl(file), true); }
bool receivePacket(const NetworkPacket& np) override;
void connected() override {}
@ -58,8 +58,7 @@ Q_SIGNALS:
private:
void finished(KJob* job, const qint64 dateModified);
void shareUrl(const QUrl& url);
void openFile(const QUrl& url);
void shareUrl(const QUrl& url, bool open);
QUrl destinationDir() const;
QUrl getFileDestination(const QString filename) const;
void setDateModified(const QUrl& destination, const qint64 timestamp);