Move to migrate code to util class

wilder-work
Montel Laurent 13 years ago
parent 993815ac24
commit ca5aaa3e4b
  1. 81
      kmkernel.cpp
  2. 1
      kmkernel.h
  3. 81
      util.cpp
  4. 1
      util.h

@ -126,7 +126,7 @@ KMKernel::KMKernel (QObject *parent, const char *name) :
{
Akonadi::AttributeFactory::registerAttribute<Akonadi::SearchDescriptionAttribute>();
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(
"<b>Thanks for using KMail2!</b>"
"<p>KMail2 uses a new storage technology that requires migration of your current KMail data and configuration.</p>\n"
"<p>The conversion process can take a lot of time (depending on the amount of email you have) and it <em>must not be interrupted</em>.</p>\n"
"<p>You can:</p><ul>"
"<li>Migrate now (be prepared to wait)</li>"
"<li>Skip the migration and start with fresh data and configuration</li>"
"<li>Cancel and exit KMail2.</li>"
"</ul>"
"<p><a href=\"http://userbase.kde.org/Akonadi\">More Information...</a></p>"
), 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();

@ -483,7 +483,6 @@ private slots:
private:
void resourceGoOnLine();
void migrateFromKMail1();
void openReader( bool onlyCheck );
QSharedPointer<MailCommon::FolderCollection> currentFolderCollection();

@ -46,10 +46,12 @@
#include <kmime/kmime_message.h>
#include <kmessagebox.h>
#include <KLocale>
#include <KProcess>
#include <KStandardDirs>
#include <QProcess>
#include <QFileInfo>
#include <QModelIndex>
#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(
"<b>Thanks for using KMail2!</b>"
"<p>KMail2 uses a new storage technology that requires migration of your current KMail data and configuration.</p>\n"
"<p>The conversion process can take a lot of time (depending on the amount of email you have) and it <em>must not be interrupted</em>.</p>\n"
"<p>You can:</p><ul>"
"<li>Migrate now (be prepared to wait)</li>"
"<li>Skip the migration and start with fresh data and configuration</li>"
"<li>Cancel and exit KMail2.</li>"
"</ul>"
"<p><a href=\"http://userbase.kde.org/Akonadi\">More Information...</a></p>"
), 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();
}
}

@ -103,6 +103,7 @@ QColor quoteL1Color();
QColor quoteL2Color();
QColor quoteL3Color();
void reduceQuery(QString &query);
void migrateFromKMail1();
}
}

Loading…
Cancel
Save