From kde-commits Fri Oct 31 23:53:28 2008 From: Volker Krause Date: Fri, 31 Oct 2008 23:53:28 +0000 To: kde-commits Subject: KDE/kdepimlibs/kresources Message-Id: <1225497208.510011.20372.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=122549721910934 SVN commit 878364 by vkrause: First try to automatically use the KResource to Akonadi migrator. It works nicely for applications, but it is also triggered from the backend bridges, which might be a problem. Still disabled by default. M +32 -0 factory.cpp --- trunk/KDE/kdepimlibs/kresources/factory.cpp #878363:878364 @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include #include @@ -48,6 +50,9 @@ using namespace KRES; +static int akonadiMigratorVersion = 1; +static bool akonadiMigrationEnabled = false; // flip this switch if you dare ;-) + class Factory::Private { public: @@ -70,6 +75,33 @@ if ( !factory ) { factory = new Factory( resourceFamily ); mSelves->insert( resourceFamily, factory ); + + // Akonadi migration + const QString cfgFileName = KStandardDirs::locateLocal( "config", QString( "kres-migratorrc" ) ); + KConfig *config = new KConfig( cfgFileName ); + KConfigGroup migrationCfg( config, "Migration" ); + const bool enabled = migrationCfg.readEntry( "Enabled", akonadiMigrationEnabled ); + const int version = migrationCfg.readEntry( "Version-" + resourceFamily, 0 ); + if ( enabled && version < akonadiMigratorVersion ) { + kDebug() << "Performing Akonadi migration. Good luck!"; + KProcess proc; + proc.setProgram( "kres-migrator", QStringList() << "--interactive-on-change" << "--type" << resourceFamily ); + proc.start(); + bool result = proc.waitForStarted(); + if ( result ) + result = proc.waitForFinished(); + if ( result && proc.exitCode() == 0 ) { + migrationCfg.writeEntry( "Version-" + resourceFamily, akonadiMigratorVersion ); + migrationCfg.sync(); + } else if ( !result || proc.exitCode() != 1 ) { // exit code 1 means it is already running, so we are probably called by a migrator instance + kError() << "Akonadi migration failed!"; + kError() << "command was: " << proc.program(); + kError() << "exit code: " << proc.exitCode(); + kError() << "stdout: " << proc.readAllStandardOutput(); + kError() << "stderr: " << proc.readAllStandardError(); + } + } + } return factory;