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

List:       kde-commits
Subject:    [calligra] libs/main: Add a calligra 2 -> 3 migration class
From:       Dag Andersen <danders () get2net ! dk>
Date:       2016-11-18 8:00:56
Message-ID: E1c7e6S-0006as-AB () code ! kde ! org
[Download RAW message or body]

Git commit 6ae21ca168be1bf1ec94c47739f613211dab8c1f by Dag Andersen.
Committed on 18/11/2016 at 08:00.
Pushed by danders into branch 'master'.

Add a calligra 2 -> 3 migration class

Summary:
Copies files from old kde directories to new QStandardPaths based dirs
If application has been renamed, renames files accordingly

Ref: T469

Tested (tentatively) with plan

Reviewers: boemann, kossebau, mecir

Tags: #kexi, #calligra:_3.0

Differential Revision: https://phabricator.kde.org/D3401

M  +1    -0    libs/main/CMakeLists.txt
A  +118  -0    libs/main/Calligra2Migration.cpp     [License: LGPL (v2+)]
A  +52   -0    libs/main/Calligra2Migration.h     [License: LGPL (v2+)]

http://commits.kde.org/calligra/6ae21ca168be1bf1ec94c47739f613211dab8c1f

diff --git a/libs/main/CMakeLists.txt b/libs/main/CMakeLists.txt
index 00bae55..4e8f04c 100644
--- a/libs/main/CMakeLists.txt
+++ b/libs/main/CMakeLists.txt
@@ -68,6 +68,7 @@ set(komain_LIB_SRCS
     KoPart.cpp
 
     MainDebug.cpp
+    Calligra2Migration.cpp
 )
 
 if( Qt5DBus_FOUND )
diff --git a/libs/main/Calligra2Migration.cpp b/libs/main/Calligra2Migration.cpp
new file mode 100644
index 0000000..4a3bf9f
--- /dev/null
+++ b/libs/main/Calligra2Migration.cpp
@@ -0,0 +1,118 @@
+/* This file is part of the KDE project
+ *   Copyright (C) 2016 Dag Andersen <danders@get2net.dk>
+ * 
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2 of the License, or (at your option) any later version.
+ * 
+ *   This library 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
+ *   Library General Public License for more details.
+ * 
+ *   You should have received a copy of the GNU Library General Public License
+ *   along with this library; see the file COPYING.LIB.  If not, write to
+ *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *   Boston, MA 02110-1301, USA.
+ */
+
+#include "Calligra2Migration.h"
+
+#include "KoResourcePaths.h"
+
+#include <kdelibs4configmigrator.h>
+#include <kdelibs4migration.h>
+#include <QStandardPaths>
+#include <QDir>
+#include <QPluginLoader>
+#include <QLoggingCategory>
+#include <QDebug>
+
+Q_DECLARE_LOGGING_CATEGORY(CALLIGRA2MIGRATION)
+// logging category for this class, default: log stuff >= warning
+Q_LOGGING_CATEGORY(CALLIGRA2MIGRATION, "calligra.lib.migration", QtWarningMsg)
+
+Calligra2Migration::Calligra2Migration(const QString &appName, const QString &oldAppName)
+    : m_newAppName(appName)
+    , m_oldAppName(oldAppName)
+{
+    qCDebug(CALLIGRA2MIGRATION)<<appName<<oldAppName;
+}
+
+void Calligra2Migration::setConfigFiles(const QStringList &configFiles)
+{
+    m_configFiles = configFiles;
+}
+
+void Calligra2Migration::setUiFiles(const QStringList &uiFiles)
+{
+    m_uiFiles = uiFiles;
+}
+
+void Calligra2Migration::migrate()
+{
+    bool didSomething = false;
+    Kdelibs4ConfigMigrator cm(m_oldAppName.isEmpty() ? m_newAppName : m_oldAppName);
+    cm.setConfigFiles(m_configFiles);
+    cm.setUiFiles(m_uiFiles);
+    if (cm.migrate() && !m_oldAppName.isEmpty()) {
+        // rename config files to new names
+        qCDebug(CALLIGRA2MIGRATION)<<"rename config files to new names"<<m_configFiles;
+        for (const QString &oldname : m_configFiles) {
+            QString newname = oldname;
+            newname.replace(m_oldAppName, m_newAppName);
+            if (oldname == newname) {
+                continue;
+            }
+            QString oldfile = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, oldname);
+            if (!oldfile.isEmpty()) {
+                QFile f(oldfile);
+                f.rename(newname);
+                didSomething = true;
+                qCDebug(CALLIGRA2MIGRATION)<<"config renamed:"<<oldfile<<"->"<<newname;
+            }
+        }
+        qCDebug(CALLIGRA2MIGRATION)<<"rename ui files to new names"<<m_uiFiles;
+        for (const QString &oldname : m_uiFiles) {
+            QString newname = oldname;
+            newname.replace(m_oldAppName, m_newAppName);
+            if (oldname == newname) {
+                continue;
+            }
+            QString oldfile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + \
QStringLiteral("/kxmlgui5/") + m_newAppName + QLatin1Char('/') + oldname; +            if \
(!oldfile.isEmpty()) { +                QFile f(oldfile);
+                f.rename(newname);
+                didSomething = true;
+                qCDebug(CALLIGRA2MIGRATION)<<"ui renamed:"<<oldfile<<"->"<<newname;
+            }
+        }
+    }
+    if (!m_oldAppName.isEmpty()) {
+        // rename data dirs
+        Kdelibs4Migration m;
+        if (m.kdeHomeFound()) {
+            const QString oldpath = m.saveLocation("data", m_oldAppName);
+            if (!oldpath.isEmpty()) {
+                qCDebug(CALLIGRA2MIGRATION)<<"old data:"<<oldpath;
+                const QString newpath = KoResourcePaths::saveLocation("data", m_newAppName, false);
+                QDir newdir(newpath);
+                if (!newdir.exists()) {
+                    newdir.rename(oldpath, newpath); // copy instead?
+                    qCDebug(CALLIGRA2MIGRATION)<<"renamed data:"<<newpath;
+                }
+            }
+        } else {qCDebug(CALLIGRA2MIGRATION)<<"kde home not found";}
+    }
+    // Copied from Kdelibs4ConfigMigrator:
+    // Trigger KSharedConfig::openConfig()->reparseConfiguration() via the framework integration plugin
+    if (didSomething) {
+        qCDebug(CALLIGRA2MIGRATION)<<"reparse configuration";
+        QPluginLoader lib(QStringLiteral("kf5/FrameworkIntegrationPlugin"));
+        QObject *rootObj = lib.instance();
+        if (rootObj) {
+            QMetaObject::invokeMethod(rootObj, "reparseConfiguration");
+        }
+    }
+}
diff --git a/libs/main/Calligra2Migration.h b/libs/main/Calligra2Migration.h
new file mode 100644
index 0000000..b5115e3
--- /dev/null
+++ b/libs/main/Calligra2Migration.h
@@ -0,0 +1,52 @@
+/* This file is part of the KDE project
+ *   Copyright (C) 2016 Dag Andersen <danders@get2net.dk>
+ * 
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2 of the License, or (at your option) any later version.
+ * 
+ *   This library 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
+ *   Library General Public License for more details.
+ * 
+ *   You should have received a copy of the GNU Library General Public License
+ *   along with this library; see the file COPYING.LIB.  If not, write to
+ *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *   Boston, MA 02110-1301, USA.
+ */
+
+#include "komain_export.h"
+
+#include <QString>
+#include <QStringList>
+
+/**
+ * class Calligra2Migration
+ * 
+ * Migrate application directories and files to new QStandardPaths locations
+ * 
+ * Calligra2Migration handles config files, ui files and data location.
+ * Config- and ui files is handled by Kdelibs4Migrator.
+ * If application has been renamed, rc files and data location is renamed accordingly.
+ */
+
+class KOMAIN_EXPORT Calligra2Migration
+{
+public:
+    /// Create a migration instance
+    /// @p appName Name of the application
+    /// @p oldAppName If the application has been renamed the old name must be specified here
+    explicit Calligra2Migration(const QString &appName, const QString &oldAppName = QString());
+
+    void setConfigFiles(const QStringList &configFiles);
+    void setUiFiles(const QStringList &uiFiles);
+    void migrate();
+    
+private:
+    QString m_newAppName;
+    QString m_oldAppName;
+    QStringList m_configFiles;
+    QStringList m_uiFiles;
+};


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

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