[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [libksieve] /: Add job to rename script
From:       Montel Laurent <montel () kde ! org>
Date:       2016-10-31 20:11:38
Message-ID: E1c1Ivi-0000hG-DP () code ! kde ! org
[Download RAW message or body]

Git commit c856b69e695d98e1a8b6e240be544b727fefb260 by Montel Laurent.
Committed on 31/10/2016 at 19:45.
Pushed by mlaurent into branch 'master'.

Add job to rename script

M  +1    -1    CMakeLists.txt
M  +8    -0    src/ksieveui/CMakeLists.txt
M  +1    -1    src/ksieveui/managescriptsjob/autotests/CMakeLists.txt
M  +36   -1    src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.cpp
M  +24   -5    src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.h
M  +109  -1    src/ksieveui/managescriptsjob/renamescriptjob.cpp
M  +49   -6    src/ksieveui/managescriptsjob/renamescriptjob.h

http://commits.kde.org/libksieve/c856b69e695d98e1a8b6e240be544b727fefb260

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82e1b62..e40f36e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
 include(ECMQtDeclareLoggingCategory)
 include(ECMAddTests)
 
-set(PIM_VERSION "5.3.42")
+set(PIM_VERSION "5.3.43")
 set(LIBKSIEVE_LIB_VERSION ${PIM_VERSION})
 set(QT_REQUIRED_VERSION "5.6.0")
 set(KMIME_LIB_VERSION "5.3.40")
diff --git a/src/ksieveui/CMakeLists.txt b/src/ksieveui/CMakeLists.txt
index 4a97e1c..493061b 100644
--- a/src/ksieveui/CMakeLists.txt
+++ b/src/ksieveui/CMakeLists.txt
@@ -184,6 +184,7 @@ set(ksieveui_LIB_SRCS
     managescriptsjob/checkkolabkep14supportjob.cpp
     managescriptsjob/generateglobalscriptjob.cpp
     managescriptsjob/parseuserscriptjob.cpp
+    managescriptsjob/renamescriptjob.cpp
     templates/sievetemplatewidget.cpp
     templates/sievedefaulttemplate.cpp
     templates/sievetemplateeditdialog.cpp
@@ -248,7 +249,14 @@ ecm_generate_headers(ksieveui_Camelcaseutil_HEADERS
     REQUIRED_HEADERS ksieveui_util_HEADERS
     PREFIX KSieveUi
     RELATIVE util
+    )
 
+ecm_generate_headers(ksieveui_Camelmanagescriptsjob_HEADERS
+    HEADER_NAMES
+    RenameScriptJob
+    REQUIRED_HEADERS ksieveui_managescriptsjob_HEADERS
+    PREFIX KSieveUi
+    RELATIVE managescriptsjob
     )
 
 ecm_generate_headers(ksieveui_Camelcaseeditor_HEADERS
diff --git a/src/ksieveui/managescriptsjob/autotests/CMakeLists.txt \
b/src/ksieveui/managescriptsjob/autotests/CMakeLists.txt index e84f846..25d8bfc \
                100644
--- a/src/ksieveui/managescriptsjob/autotests/CMakeLists.txt
+++ b/src/ksieveui/managescriptsjob/autotests/CMakeLists.txt
@@ -11,6 +11,6 @@ endmacro()
 
 
 add_managesievejob_test( parseuserjobtest.cpp )
-
+add_managesievejob_test( renamescriptjobtest.cpp )
 
 
diff --git a/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.cpp \
b/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.cpp index \
                bc1ab9e..2195295 100644
--- a/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.cpp
+++ b/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.cpp
@@ -1,6 +1,41 @@
+/*
+  Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License, version 2, as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along
+  with this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
 #include "renamescriptjobtest.h"
+#include "../renamescriptjob.h"
+#include <QTest>
+
+
+RenameScriptJobTest::RenameScriptJobTest(QObject *parent)
+    : QObject(parent)
+{
+
+}
 
-RenameScriptJobTest::RenameScriptJobTest(QObject *parent) : QObject(parent)
+RenameScriptJobTest::~RenameScriptJobTest()
 {
 
 }
+
+void RenameScriptJobTest::canNotStartByDefault()
+{
+    KSieveUi::RenameScriptJob job;
+    QVERIFY(!job.canStart());
+}
+
+QTEST_MAIN(RenameScriptJobTest)
diff --git a/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.h \
b/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.h index \
                9141d43..1b4c8ab 100644
--- a/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.h
+++ b/src/ksieveui/managescriptsjob/autotests/renamescriptjobtest.h
@@ -1,16 +1,35 @@
+/*
+  Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License, version 2, as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along
+  with this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
 #ifndef RENAMESCRIPTJOBTEST_H
 #define RENAMESCRIPTJOBTEST_H
 
+#include <QObject>
 
 class RenameScriptJobTest : public QObject
 {
     Q_OBJECT
 public:
-    explicit RenameScriptJobTest(QObject *parent = 0);
-
-signals:
+    explicit RenameScriptJobTest(QObject *parent = Q_NULLPTR);
+    ~RenameScriptJobTest();
 
-public slots:
+private Q_SLOTS:
+    void canNotStartByDefault();
 };
 
-#endif // RENAMESCRIPTJOBTEST_H
\ No newline at end of file
+#endif // RENAMESCRIPTJOBTEST_H
diff --git a/src/ksieveui/managescriptsjob/renamescriptjob.cpp \
b/src/ksieveui/managescriptsjob/renamescriptjob.cpp index e39fe58..89011f1 100644
--- a/src/ksieveui/managescriptsjob/renamescriptjob.cpp
+++ b/src/ksieveui/managescriptsjob/renamescriptjob.cpp
@@ -1,6 +1,114 @@
+/*
+  Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License, version 2, as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along
+  with this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
 #include "renamescriptjob.h"
 
-RenameScriptJob::RenameScriptJob(QObject *parent) : QObject(parent)
+#include <kmanagesieve/sievejob.h>
+
+using namespace KSieveUi;
+
+class KSieveUi::RenameScriptJobPrivate
 {
+public:
+    RenameScriptJobPrivate()
+        : mIsActive(false)
+    {
+    }
+    QString mNewName;
+    QUrl mOldUrl;
+    bool mIsActive;
+};
 
+RenameScriptJob::RenameScriptJob(QObject *parent)
+    : QObject(parent),
+      d(new RenameScriptJobPrivate)
+{
+
+}
+
+RenameScriptJob::~RenameScriptJob()
+{
+    delete d;
+}
+
+void RenameScriptJob::setOldUrl(const QUrl &url)
+{
+    d->mOldUrl = url;
+}
+
+void RenameScriptJob::setIsActive(bool active)
+{
+    d->mIsActive = active;
+}
+
+void RenameScriptJob::setNewName(const QString &newName)
+{
+    d->mNewName = newName;
+}
+
+bool RenameScriptJob::canStart() const
+{
+    return !d->mNewName.isEmpty() && !d->mOldUrl.isEmpty();
+}
+
+void RenameScriptJob::start()
+{
+    if (canStart()) {
+        KManageSieve::SieveJob *job = KManageSieve::SieveJob::get(d->mOldUrl);
+        connect(job, &KManageSieve::SieveJob::result, this, \
&RenameScriptJob::slotGetResult); +    } else {
+        Q_EMIT finished(false);
+        deleteLater();
+    }
+}
+
+void RenameScriptJob::slotGetResult(KManageSieve::SieveJob *job, bool success, const \
QString &script, bool isActive) +{
+    Q_UNUSED(job);
+    Q_UNUSED(isActive);
+    if (!success) {
+        Q_EMIT finished(false);
+        deleteLater();
+        return;
+    }
+    QUrl u = d->mOldUrl;
+    u = u.adjusted(QUrl::RemoveFilename);
+    u.setPath(u.path() +  QLatin1Char('/') + d->mNewName);
+
+    KManageSieve::SieveJob *putJob = KManageSieve::SieveJob::put(u, script, \
d->mIsActive, d->mIsActive); +    connect(putJob, &KManageSieve::SieveJob::result, \
this, &RenameScriptJob::slotPutScript); +}
+
+void RenameScriptJob::slotPutScript(KManageSieve::SieveJob *job, bool success)
+{
+    Q_UNUSED(job);
+    if (!success) {
+        Q_EMIT finished(false);
+        deleteLater();
+        return;
+    }
+    KManageSieve::SieveJob *deleteJob = KManageSieve::SieveJob::del(d->mOldUrl);
+    connect(deleteJob, &KManageSieve::SieveJob::result, this, \
&RenameScriptJob::slotDeleteResult); +}
+
+void RenameScriptJob::slotDeleteResult(KManageSieve::SieveJob *job, bool success)
+{
+    Q_UNUSED(job);
+    Q_EMIT finished(success);
+    deleteLater();
 }
diff --git a/src/ksieveui/managescriptsjob/renamescriptjob.h \
b/src/ksieveui/managescriptsjob/renamescriptjob.h index c4d8ce2..d6047ea 100644
--- a/src/ksieveui/managescriptsjob/renamescriptjob.h
+++ b/src/ksieveui/managescriptsjob/renamescriptjob.h
@@ -1,16 +1,59 @@
+/*
+  Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License, version 2, as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along
+  with this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
 #ifndef RENAMESCRIPTJOB_H
 #define RENAMESCRIPTJOB_H
 
+#include <QObject>
+#include <QUrl>
+#include "ksieveui_export.h"
+namespace KManageSieve {
+class SieveJob;
+}
 
-class RenameScriptJob : public QObject
+namespace KSieveUi
+{
+class RenameScriptJobPrivate;
+class KSIEVEUI_EXPORT RenameScriptJob : public QObject
 {
     Q_OBJECT
 public:
-    explicit RenameScriptJob(QObject *parent = 0);
+    explicit RenameScriptJob(QObject *parent = Q_NULLPTR);
+    ~RenameScriptJob();
 
-signals:
+    void setOldUrl(const QUrl &url);
+    void setIsActive(bool active);
+    void setNewName(const QString &newName);
 
-public slots:
-};
+    bool canStart() const;
+
+    void start();
+
+Q_SIGNALS:
+    void finished(bool success);
 
-#endif // RENAMESCRIPTJOB_H
\ No newline at end of file
+private Q_SLOTS:
+    void slotDeleteResult(KManageSieve::SieveJob *job, bool success);
+    void slotPutScript(KManageSieve::SieveJob *job, bool success);
+    void slotGetResult(KManageSieve::SieveJob *job, bool success, const QString \
&script, bool isActive); +
+private:
+    RenameScriptJobPrivate *const d;
+};
+}
+#endif // RENAMESCRIPTJOB_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic