From ca5aaa3e4bb84ab0e956e2e1513887ade5a503d7 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Mon, 28 Oct 2013 13:57:15 +0100 Subject: [PATCH] Move to migrate code to util class --- kmkernel.cpp | 81 +--------------------------------------------------- kmkernel.h | 1 - util.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ util.h | 1 + 4 files changed, 83 insertions(+), 81 deletions(-) diff --git a/kmkernel.cpp b/kmkernel.cpp index 63c1563d9..961806d73 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -126,7 +126,7 @@ KMKernel::KMKernel (QObject *parent, const char *name) : { Akonadi::AttributeFactory::registerAttribute(); QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.kmail")); - migrateFromKMail1(); + KMail::Util::migrateFromKMail1(); kDebug() << "Starting up..."; mySelf = this; @@ -246,85 +246,6 @@ KMKernel::~KMKernel () kDebug(); } -void KMKernel::migrateFromKMail1() -{ - // Akonadi migration - // check if there is something to migrate at all - bool needMigration = true; - KConfig oldKMailConfig( QLatin1String("kmailrc"), KConfig::NoGlobals ); - if ( oldKMailConfig.hasGroup("General") || - ( oldKMailConfig.groupList().count() == 1 && - oldKMailConfig.groupList().first() == QLatin1String("$Version") ) ) { - const QFileInfo oldDataDirFileInfo( KStandardDirs::locateLocal( "data", QLatin1String("kmail") ) ); - if ( !oldDataDirFileInfo.exists() || !oldDataDirFileInfo.isDir() ) { - // neither config or data, the migrator cannot do anything useful anyways - needMigration = false; - } - } else { - needMigration = false; - } - - KConfig config( QLatin1String("kmail-migratorrc") ); - KConfigGroup migrationCfg( &config, "Migration" ); - if ( needMigration ) { - const bool enabled = migrationCfg.readEntry( "Enabled", false ); - const int currentVersion = migrationCfg.readEntry( "Version", 0 ); - const int targetVersion = migrationCfg.readEntry( "TargetVersion", 1 ); - if ( enabled && currentVersion < targetVersion ) { - const int choice = KMessageBox::questionYesNoCancel( 0, i18n( - "Thanks for using KMail2!" - "

KMail2 uses a new storage technology that requires migration of your current KMail data and configuration.

\n" - "

The conversion process can take a lot of time (depending on the amount of email you have) and it must not be interrupted.

\n" - "

You can:

" - "

More Information...

" - ), i18n( "KMail Migration" ), KGuiItem(i18n( "Migrate Now" )), KGuiItem(i18n( "Skip Migration" )), KStandardGuiItem::cancel(), - QString(), KMessageBox::Notify | KMessageBox::Dangerous | KMessageBox::AllowLink ); - if ( choice == KMessageBox::Cancel ) - exit( 1 ); - - if ( choice != KMessageBox::Yes ) { // user skipped migration - // we only will make one attempt at this - migrationCfg.writeEntry( "Version", targetVersion ); - migrationCfg.sync(); - - return; - } - - kDebug() << "Performing Akonadi migration. Good luck!"; - KProcess proc; - QStringList args = QStringList() << QLatin1String("--interactive-on-change"); - const QString path = KStandardDirs::findExe( QLatin1String("kmail-migrator" ) ); - proc.setProgram( path, args ); - proc.start(); - bool result = proc.waitForStarted(); - if ( result ) { - result = proc.waitForFinished( -1 ); - } - if ( result && proc.exitCode() == 0 ) { - kDebug() << "Akonadi migration has been successful"; - } else { - // 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(); - - KMessageBox::error( 0, i18n("Migration to KMail 2 failed. In case you want to try again, run 'kmail-migrator --interactive' manually."), - i18n( "Migration Failed" ) ); - return; - } - } - } else { - migrationCfg.writeEntry( "Enabled", false ); - migrationCfg.sync(); - } -} - Akonadi::ChangeRecorder * KMKernel::folderCollectionMonitor() const { return mFolderCollectionMonitor->monitor(); diff --git a/kmkernel.h b/kmkernel.h index 9dd9ccb83..a64402853 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -483,7 +483,6 @@ private slots: private: void resourceGoOnLine(); - void migrateFromKMail1(); void openReader( bool onlyCheck ); QSharedPointer currentFolderCollection(); diff --git a/util.cpp b/util.cpp index 0e0196ca9..70d9a0fb0 100644 --- a/util.cpp +++ b/util.cpp @@ -46,10 +46,12 @@ #include #include #include +#include #include #include +#include #include #include "foldercollection.h" @@ -231,3 +233,82 @@ void KMail::Util::reduceQuery(QString &query) query.replace( QLatin1String("XMLSchema:"), QLatin1String("xsd:") ); query = query.simplified(); } + +void KMail::Util::migrateFromKMail1() +{ + // Akonadi migration + // check if there is something to migrate at all + bool needMigration = true; + KConfig oldKMailConfig( QLatin1String("kmailrc"), KConfig::NoGlobals ); + if ( oldKMailConfig.hasGroup("General") || + ( oldKMailConfig.groupList().count() == 1 && + oldKMailConfig.groupList().first() == QLatin1String("$Version") ) ) { + const QFileInfo oldDataDirFileInfo( KStandardDirs::locateLocal( "data", QLatin1String("kmail") ) ); + if ( !oldDataDirFileInfo.exists() || !oldDataDirFileInfo.isDir() ) { + // neither config or data, the migrator cannot do anything useful anyways + needMigration = false; + } + } else { + needMigration = false; + } + + KConfig config( QLatin1String("kmail-migratorrc") ); + KConfigGroup migrationCfg( &config, "Migration" ); + if ( needMigration ) { + const bool enabled = migrationCfg.readEntry( "Enabled", false ); + const int currentVersion = migrationCfg.readEntry( "Version", 0 ); + const int targetVersion = migrationCfg.readEntry( "TargetVersion", 1 ); + if ( enabled && currentVersion < targetVersion ) { + const int choice = KMessageBox::questionYesNoCancel( 0, i18n( + "Thanks for using KMail2!" + "

KMail2 uses a new storage technology that requires migration of your current KMail data and configuration.

\n" + "

The conversion process can take a lot of time (depending on the amount of email you have) and it must not be interrupted.

\n" + "

You can:

    " + "
  • Migrate now (be prepared to wait)
  • " + "
  • Skip the migration and start with fresh data and configuration
  • " + "
  • Cancel and exit KMail2.
  • " + "
" + "

More Information...

" + ), i18n( "KMail Migration" ), KGuiItem(i18n( "Migrate Now" )), KGuiItem(i18n( "Skip Migration" )), KStandardGuiItem::cancel(), + QString(), KMessageBox::Notify | KMessageBox::Dangerous | KMessageBox::AllowLink ); + if ( choice == KMessageBox::Cancel ) + exit( 1 ); + + if ( choice != KMessageBox::Yes ) { // user skipped migration + // we only will make one attempt at this + migrationCfg.writeEntry( "Version", targetVersion ); + migrationCfg.sync(); + + return; + } + + kDebug() << "Performing Akonadi migration. Good luck!"; + KProcess proc; + QStringList args = QStringList() << QLatin1String("--interactive-on-change"); + const QString path = KStandardDirs::findExe( QLatin1String("kmail-migrator" ) ); + proc.setProgram( path, args ); + proc.start(); + bool result = proc.waitForStarted(); + if ( result ) { + result = proc.waitForFinished( -1 ); + } + if ( result && proc.exitCode() == 0 ) { + kDebug() << "Akonadi migration has been successful"; + } else { + // 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(); + + KMessageBox::error( 0, i18n("Migration to KMail 2 failed. In case you want to try again, run 'kmail-migrator --interactive' manually."), + i18n( "Migration Failed" ) ); + return; + } + } + } else { + migrationCfg.writeEntry( "Enabled", false ); + migrationCfg.sync(); + } +} diff --git a/util.h b/util.h index ddd7b22b0..071c94aac 100644 --- a/util.h +++ b/util.h @@ -103,6 +103,7 @@ QColor quoteL1Color(); QColor quoteL2Color(); QColor quoteL3Color(); void reduceQuery(QString &query); +void migrateFromKMail1(); } }