summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-12 20:06:20 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-12 22:37:34 (GMT)
commit39bff653a5d7a9c965bb534c7dcb6303bf1c208a (patch)
tree16abc1172e0bdb2ca178b285ae752ffb4af972ff
parente3e2b7c6e30073acd54766cba8a744058dfd06c1 (diff)
Add config migration
-rw-r--r--part.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/part.cpp b/part.cpp
index f18e9c8..a290657 100644
--- a/part.cpp
+++ b/part.cpp
@@ -38,6 +38,8 @@
#include <QFileDialog>
#include <QStandardPaths>
+#include <Kdelibs4Migration>
+#include <Kdelibs4ConfigMigrator>
#include <KJobWidgets>
#include <kaboutapplicationdialog.h>
#include <kactioncollection.h>
@@ -296,13 +298,51 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW
// when this part is used in an application other than okular (e.g. unit tests)
setComponentName(QStringLiteral("okular"), QString());
+ const QLatin1String configFileName("okularpartrc");
+
// first, we check if a config file name has been specified
- QString configFileName = detectConfigFileName( args );
- if ( configFileName.isEmpty() )
+ QString configFilePath = detectConfigFileName( args );
+
+ if ( configFilePath.isEmpty() )
{
- configFileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("okularpartrc"));
+ configFilePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + configFileName;
+ }
+
+
+ // Migrate old config
+ if ( !QFile::exists( configFilePath ) ) {
+ qCDebug(OkularUiDebug) << "Did not find a config file, attempting to look for old config";
+
+ // Migrate old config + UI
+ Kdelibs4ConfigMigrator configMigrator( componentName() );
+ // UI file is handled automatically, we only need to specify config name because we're a part
+ configMigrator.setConfigFiles( QStringList( configFileName ) );
+
+ // If there's no old okular config to migrate, look for kpdf
+ if ( !configMigrator.migrate() ) {
+ qCDebug(OkularUiDebug) << "Did not find an old okular config file, attempting to look for kpdf config";
+
+ // First try the automatic detection, using $KDEHOME etc.
+ Kdelibs4Migration migration;
+ QString kpdfConfig = migration.locateLocal( "config", QStringLiteral("kpdfpartrc") );
+
+ // Fallback just in case it tried e. g. ~/.kde4
+ if ( kpdfConfig.isEmpty() ) {
+ kpdfConfig = QDir::homePath() + QStringLiteral("/.kde/share/config/kpdfpartrc");
+ }
+
+ if ( QFile::exists( kpdfConfig ) ) {
+ qCDebug(OkularUiDebug) << "Found old kpdf config" << kpdfConfig << "copying to" << configFilePath;
+ QFile::copy( kpdfConfig, configFilePath );
+ } else {
+ qCDebug(OkularUiDebug) << "Did not find an old kpdf config file";
+ }
+ } else {
+ qCDebug(OkularUiDebug) << "Migrated old okular config";
+ }
}
- Okular::Settings::instance( configFileName );
+
+ Okular::Settings::instance( configFilePath );
numberOfParts++;
if (numberOfParts == 1) {