summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2016-10-05 07:31:34 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2016-10-05 07:34:27 (GMT)
commite8e1a109ff494d8da044a328c6e12cb2eede1590 (patch)
treec50c535809e52d613ae0a2876473058158439a61
parentcbb065ade17493f563d0e47a2e699e4ab69c2c5d (diff)
Migrate profiles.db From KDE4 Location
Copying the settings file isn't enough. All the important bits like training stats and unlocked lessons are stored the profiles database.
-rw-r--r--src/application.cpp31
-rw-r--r--src/application.h1
-rw-r--r--src/main.cpp8
3 files changed, 32 insertions, 8 deletions
diff --git a/src/application.cpp b/src/application.cpp
index e10f2dc..8a046c2 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -17,9 +17,14 @@
#include "application.h"
+#include <QDir>
+#include <QFile>
#include <QQmlEngine>
#include <QQmlContext>
+#include <QStandardPaths>
+#include <Kdelibs4ConfigMigrator>
+#include <Kdelibs4Migration>
#include <KDeclarative/KDeclarative>
#include "bindings/utils.h"
@@ -52,6 +57,7 @@ Application::Application(int& argc, char** argv, int flags):
m_dataIndex(new DataIndex(this))
{
registerQmlTypes();
+ migrateKde4Files();
DataAccess dataAccess;
dataAccess.loadDataIndex(m_dataIndex);
@@ -123,3 +129,28 @@ void Application::registerQmlTypes()
qmlRegisterType<LessonPainter>("ktouch", 1, 0, "LessonPainter");
qmlRegisterType<TrainingLineCore>("ktouch", 1, 0, "TrainingLineCore");
}
+
+void Application::migrateKde4Files()
+{
+ QStringList configFiles;
+ configFiles << QLatin1String("ktouchrc");
+ Kdelibs4ConfigMigrator confMigrator(QLatin1String("ktouch"));
+ confMigrator.setConfigFiles(configFiles);
+ confMigrator.migrate();
+
+ Kdelibs4Migration migration;
+ const QDir dataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
+ if (!dataDir.exists())
+ {
+ dataDir.mkpath(dataDir.path());
+ }
+ const QString dbPath = dataDir.filePath("profiles.db");
+ const QString oldDbPath = migration.locateLocal("data", QStringLiteral("ktouch/profiles.db"));
+ auto exists = QFile(dbPath).exists();
+ auto empty = oldDbPath.isEmpty();
+ if (!QFile(dbPath).exists() && !oldDbPath.isEmpty())
+ {
+ QFile(oldDbPath).copy(dbPath);
+ }
+
+}
diff --git a/src/application.h b/src/application.h
index 2855222..7b1ec17 100644
--- a/src/application.h
+++ b/src/application.h
@@ -37,6 +37,7 @@ public:
QStringList& qmlImportPaths();
private:
void registerQmlTypes();
+ void migrateKde4Files();
DataIndex* m_dataIndex;
QSharedPointer<ResourceEditor> m_resourceEditorRef;
QStringList m_qmlImportPaths;
diff --git a/src/main.cpp b/src/main.cpp
index 332d2da..fda7e82 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,7 +19,6 @@
#include <KAboutData>
#include <KLocalizedString>
-#include <Kdelibs4ConfigMigrator>
#include "application.h"
#include "mainwindow.h"
@@ -44,13 +43,6 @@ int main(int argc, char **argv)
QStringLiteral("http://edu.kde.org/ktouch"),
QStringLiteral("submit@bugs.kde.org"));
- /* for migration*/
- QStringList configFiles;
- configFiles << QLatin1String("ktouchrc");
- Kdelibs4ConfigMigrator migrator(QLatin1String("ktouch"));
- migrator.setConfigFiles(configFiles);
- migrator.migrate();
-
about.addAuthor(i18n("Sebastian Gottfried"), i18n("Current maintainer"), "sebastiangottfried@web.de");
about.addAuthor(i18n("Andreas Nicolai"), i18n("Former maintainer and programmer"), "Andreas.Nicolai@gmx.net");
about.addAuthor(i18n("Håvard Frøiland"), i18n("Original author"), "haavard@users.sourceforge.net");