[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:28:18 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=ede7dd0

The following commit has been merged in the master branch:
commit ede7dd0e843a2c83db1297383ff568a8fbe7fbe0
Author: Aleix Pol <aleixpol at kde.org>
Date:   Mon Mar 9 13:22:10 2015 +0100

    Drop KIOWidgets dependency from KDEConnectCore
    
    Removes the usage of RenameDialog by moving the functionality away. In
    fact, what it does is make the share dialog try to come up with a different
    name rather than asking the user. It's a quite common procedure as makes
    the interaction simpler (for example, Chromium and Kamoso work like that).
    
    REVIEW: 122813
---
 core/CMakeLists.txt           |  1 -
 core/filetransferjob.cpp      | 49 +++----------------------------------------
 core/filetransferjob.h        |  1 -
 plugins/share/shareplugin.cpp | 41 +++++++++++++++++++++++++++++++++++-
 4 files changed, 43 insertions(+), 49 deletions(-)

diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 95b8bd8..ec7fd7f 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -35,7 +35,6 @@ PUBLIC
 PRIVATE
     Qt5::DBus
     Qt5::Gui
-    KF5::KIOWidgets
     KF5::I18n
     KF5::ConfigCore
     KF5::Notifications
diff --git a/core/filetransferjob.cpp b/core/filetransferjob.cpp
index 1e0dfcd..73bad79 100644
--- a/core/filetransferjob.cpp
+++ b/core/filetransferjob.cpp
@@ -25,7 +25,6 @@
 #include <QFileInfo>
 #include <QDebug>
 
-#include <KIO/RenameDialog>
 #include <KLocalizedString>
 
 FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl& destination)
@@ -66,54 +65,12 @@ void FileTransferJob::doStart()
         QString(mDeviceName))
     );
     QUrl destCheck = mDestination;
-    if (QFile::exists(destCheck.toLocalFile())) {
-        QFileInfo destInfo(destCheck.toLocalFile());
-        KIO::RenameDialog *dialog = new KIO::RenameDialog(Q_NULLPTR,
-            i18n("Incoming file exists"),
-            QUrl(mDeviceName + ":/" + destCheck.fileName()),
-            destCheck,
-            KIO::RenameDialog_Overwrite,
-            mSize,
-            destInfo.size(),
-            QDateTime(),
-            destInfo.created(),
-            QDateTime(),
-            destInfo.lastModified()
-        );
-        connect(this, SIGNAL(finished(KJob*)), dialog, SLOT(deleteLater()));
-        connect(dialog, SIGNAL(finished(int)), SLOT(renameDone(int)));
-        dialog->show();
-        return;
-    }
-
-    startTransfer();
-}
-
-void FileTransferJob::renameDone(int result)
-{
-    KIO::RenameDialog *renameDialog = qobject_cast<KIO::RenameDialog*>(sender());
-    switch (result) {
-    case KIO::R_CANCEL:
-        //The user cancelled, killing the job
-        emitResult();
-    case KIO::R_RENAME:
-        mDestination = renameDialog->newDestUrl();
-        break;
-    case KIO::R_OVERWRITE:
-    {
-        // Delete the old file if exists
-        QFile oldFile(mDestination.toLocalFile());
-        if (oldFile.exists()) {
-            oldFile.remove();
-        }
-        break;
-    }
-    default:
-        qCWarning(KDECONNECT_CORE()) << "Unknown Error";
+    if (destCheck.isLocalFile() && QFile::exists(destCheck.toLocalFile())) {
+        setError(2);
+        setErrorText(i18n("Filename already present"));
         emitResult();
     }
 
-    renameDialog->deleteLater();
     startTransfer();
 }
 
diff --git a/core/filetransferjob.h b/core/filetransferjob.h
index 8c94c99..973bd3a 100644
--- a/core/filetransferjob.h
+++ b/core/filetransferjob.h
@@ -44,7 +44,6 @@ public:
 
 public Q_SLOTS:
     void doStart();
-    void renameDone(int result);
     void readyRead();
     void open(KIO::Job*);
     void sourceFinished();
diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp
index 2c1566b..dbafb11 100644
--- a/plugins/share/shareplugin.cpp
+++ b/plugins/share/shareplugin.cpp
@@ -42,6 +42,41 @@ K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< SharePlugin >(); )
 
 Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SHARE, "kdeconnect.plugin.share");
 
+static void autoincFilename(QUrl &filename)
+{
+    // Extract the filename from the path
+    QString name= filename.fileName();
+
+    // If the name contains a number then increment it
+    QRegExp numSearch( "(^|[^\d])(\d+)" ); // we want to match as far left as possible, and when the number is at the start of the name
+
+    // Does it have a number?
+    int start = numSearch.lastIndexIn( name );
+    if (start != -1) {
+        // It has a number, increment it
+        start = numSearch.pos( 2 ); // we are only interested in the second group
+        QString numAsStr = numSearch.cap(2);
+        QString number = QString::number( numAsStr.toInt() + 1 );
+        number = number.rightJustified( numAsStr.length(), '0' );
+        name.replace( start, numAsStr.length(), number );
+    }
+    else {
+        // no number
+        start = name.lastIndexOf('.');
+        if (start != -1) {
+            // has a . somewhere, e.g. it has an extension
+            name.insert(start, '1');
+        }
+        else {
+            // no extension, just tack it on to the end
+            name += '1';
+        }
+    }
+
+    //Rebuild the path
+    filename.setPath( filename.adjusted(QUrl::RemoveFilename).toLocalFile() + name );
+}
+
 SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
     : KdeConnectPlugin(parent, args)
 {
@@ -92,7 +127,11 @@ bool SharePlugin::receivePackage(const NetworkPackage& np)
         //qCDebug(KDECONNECT_PLUGIN_SHARE) << "receiving file";
         const QString filename = np.get<QString>("filename", QString::number(QDateTime::currentMSecsSinceEpoch()));
         const QString dir = destinationDir().adjusted(QUrl::StripTrailingSlash).toString();
-        const QUrl destination(dir + '/' + filename);
+        QUrl destination(dir + '/' + filename);
+        while (destination.isLocalFile() && QFile::exists(destination.toLocalFile())) {
+            autoincFilename(destination);
+        }
+
         FileTransferJob* job = np.createPayloadTransferJob(destination);
         job->setDeviceName(device()->name());
         connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list