[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra] libs/main: Calligra2Migration: Fill out a couple of holes in first version
From: Dag Andersen <danders () get2net ! dk>
Date: 2016-11-24 10:57:41
Message-ID: E1c9rin-0005h4-6p () code ! kde ! org
[Download RAW message or body]
Git commit 93092c16334ad607ebe6a9ab0cea9d53a8c89ea5 by Dag Andersen.
Committed on 24/11/2016 at 10:39.
Pushed by danders into branch 'master'.
Calligra2Migration: Fill out a couple of holes in first version
Always migrate data dir, also when app is not renamed.
When app is renamed ui files are moved under ...kxmlgui5/<appname>/
so first rename directory, then files.
Add explicit check if migration is already done, so we do not waste startup time.
Do migration of global calligra files (if not already done)
M +52 -24 libs/main/Calligra2Migration.cpp
M +5 -0 libs/main/Calligra2Migration.h
https://commits.kde.org/calligra/93092c16334ad607ebe6a9ab0cea9d53a8c89ea5
diff --git a/libs/main/Calligra2Migration.cpp b/libs/main/Calligra2Migration.cpp
index 4a3bf9f..72c3091 100644
--- a/libs/main/Calligra2Migration.cpp
+++ b/libs/main/Calligra2Migration.cpp
@@ -30,8 +30,7 @@
#include <QDebug>
Q_DECLARE_LOGGING_CATEGORY(CALLIGRA2MIGRATION)
-// logging category for this class, default: log stuff >= warning
-Q_LOGGING_CATEGORY(CALLIGRA2MIGRATION, "calligra.lib.migration", QtWarningMsg)
+Q_LOGGING_CATEGORY(CALLIGRA2MIGRATION, "calligra.lib.migration")
Calligra2Migration::Calligra2Migration(const QString &appName, const QString \
&oldAppName) : m_newAppName(appName)
@@ -52,6 +51,20 @@ void Calligra2Migration::setUiFiles(const QStringList &uiFiles)
void Calligra2Migration::migrate()
{
+ const QString newdatapath = KoResourcePaths::saveLocation("data", m_newAppName, \
false); + QDir newdatadir(newdatapath);
+ if (newdatadir.exists()) {
+ // assume we have migrated
+ qCDebug(CALLIGRA2MIGRATION)<<"migration has been done";
+ return;
+ }
+
+ // do common calligra in case not yet migrated
+ Kdelibs4ConfigMigrator m("calligra");
+ m.setConfigFiles(QStringList() << QStringLiteral("calligrarc"));
+ m.setUiFiles(QStringList() << QStringLiteral("calligra_shell.rc") << \
QStringLiteral("osx.stylesheet")); + m.migrate();
+
bool didSomething = false;
Kdelibs4ConfigMigrator cm(m_oldAppName.isEmpty() ? m_newAppName : m_oldAppName);
cm.setConfigFiles(m_configFiles);
@@ -67,12 +80,27 @@ void Calligra2Migration::migrate()
}
QString oldfile = \
QStandardPaths::locate(QStandardPaths::GenericConfigLocation, oldname); if \
(!oldfile.isEmpty()) { + qCDebug(CALLIGRA2MIGRATION)<<"config \
rename:"<<oldfile; QFile f(oldfile);
- f.rename(newname);
+ QFileInfo fi(f);
+ f.rename(fi.absolutePath() + '/' + newname);
didSomething = true;
- qCDebug(CALLIGRA2MIGRATION)<<"config \
renamed:"<<oldfile<<"->"<<newname; + \
qCDebug(CALLIGRA2MIGRATION)<<"config renamed:"<<f.fileName(); }
}
+ // subdirectory must be renamed
+ // eg: .local/share/kxmlgui5/ + m_oldAppName
+ // rename to: .local/share/kxmlgui5/ + m_newAppName
+ const QString loc = \
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + \
QStringLiteral("/kxmlgui5/"); + const QString oldui = loc + m_oldAppName;
+ const QString newui = loc + m_newAppName;
+ qCDebug(CALLIGRA2MIGRATION)<<"rename ui dir:"<<oldui;
+ QDir newdir(newui);
+ if (!newdir.exists()) {
+ newdir.rename(oldui, newui);
+ didSomething = true;
+ qCDebug(CALLIGRA2MIGRATION)<<"renamed ui dir:"<<newui;
+ }
qCDebug(CALLIGRA2MIGRATION)<<"rename ui files to new names"<<m_uiFiles;
for (const QString &oldname : m_uiFiles) {
QString newname = oldname;
@@ -80,31 +108,31 @@ void Calligra2Migration::migrate()
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);
+ const QString oldfile = newui + QLatin1Char('/') + oldname;
+ QFile f(oldfile);
+ if (f.exists()) {
+ const QString newfile = newui + QLatin1Char('/') + newname;
+ f.rename(newfile);
didSomething = true;
- qCDebug(CALLIGRA2MIGRATION)<<"ui renamed:"<<oldfile<<"->"<<newname;
+ QFileInfo fi(f);
+ qCDebug(CALLIGRA2MIGRATION)<<"ui \
renamed:"<<oldfile<<"->"<<fi.filePath(); }
}
}
- 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";}
+
+ // migrate data dir, must be done after ui files
+ Kdelibs4Migration md;
+ if (md.kdeHomeFound()) {
+ const QString oldpath = md.saveLocation("data", m_oldAppName.isEmpty() ? \
m_newAppName : m_oldAppName); + if (!oldpath.isEmpty()) {
+ qCDebug(CALLIGRA2MIGRATION)<<"old data:"<<oldpath;
+ newdatadir.rename(oldpath, newdatapath);
+ qCDebug(CALLIGRA2MIGRATION)<<"renamed data:"<<newdatapath;
+ }
+ } else {
+ qCWarning(CALLIGRA2MIGRATION)<<"kde home not found";
}
+
// Copied from Kdelibs4ConfigMigrator:
// Trigger KSharedConfig::openConfig()->reparseConfiguration() via the framework \
integration plugin if (didSomething) {
diff --git a/libs/main/Calligra2Migration.h b/libs/main/Calligra2Migration.h
index b5115e3..5ac3b9a 100644
--- a/libs/main/Calligra2Migration.h
+++ b/libs/main/Calligra2Migration.h
@@ -17,6 +17,9 @@
* Boston, MA 02110-1301, USA.
*/
+#ifndef Calligra2Migration_h
+#define Calligra2Migration_h
+
#include "komain_export.h"
#include <QString>
@@ -50,3 +53,5 @@ private:
QStringList m_configFiles;
QStringList m_uiFiles;
};
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic