[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/akonadi/migration/kres
From:       Volker Krause <vkrause () kde ! org>
Date:       2008-10-31 21:01:59
Message-ID: 1225486919.101791.11379.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 878308 by vkrause:

prepare for the integration into KRes


 M  +34 -15    infodialog.cpp  
 M  +10 -4     infodialog.h  
 M  +1 -0      kcalmigrator.cpp  
 M  +11 -11    kresmigrator.h  
 M  +5 -5      kresmigratorbase.cpp  
 M  +9 -3      kresmigratorbase.h  
 M  +19 -13    main.cpp  


--- trunk/KDE/kdepim/akonadi/migration/kres/infodialog.cpp #878307:878308
@@ -19,12 +19,16 @@
 
 #include "infodialog.h"
 
+#include <KDebug>
 #include <KGlobal>
 
 #include <QListWidget>
 
-InfoDialog::InfoDialog() :
-    mMigratorCount( 0 )
+InfoDialog::InfoDialog( bool closeWhenDone ) :
+    mMigratorCount( 0 ),
+    mError( false ),
+    mChange( false ),
+    mCloseWhenDone( closeWhenDone )
 {
   KGlobal::ref();
   setButtons( Close );
@@ -41,21 +45,33 @@
   KGlobal::deref();
 }
 
-void InfoDialog::successMessage(const QString & msg)
+void InfoDialog::message(KResMigratorBase::MessageType type, const QString & msg)
 {
-  new QListWidgetItem( KIcon( "dialog-ok" ), msg, mList );
+  QListWidgetItem *item = new QListWidgetItem( msg, mList );
+  switch ( type ) {
+    case KResMigratorBase::Success:
+      item->setIcon( KIcon( "dialog-ok-apply" ) );
+      mChange = true;
+      kDebug() << msg;
+      break;
+    case KResMigratorBase::Skip:
+      item->setIcon( KIcon( "dialog-ok" ) );
+      kDebug() << msg;
+      break;
+    case KResMigratorBase::Info:
+      item->setIcon( KIcon( "dialog-information" ) );
+      kDebug() << msg;
+      break;
+    case KResMigratorBase::Error:
+      item->setIcon( KIcon( "dialog-error" ) );
+      mError = true;
+      kError() << msg;
+      break;
+    default:
+      kError() << "WTF?";
+  }
 }
 
-void InfoDialog::infoMessage(const QString & msg)
-{
-  new QListWidgetItem( KIcon( "dialog-information" ), msg, mList );
-}
-
-void InfoDialog::errorMessage(const QString & msg)
-{
-  new QListWidgetItem( KIcon( "dialog-error" ), msg, mList );
-}
-
 void InfoDialog::migratorAdded()
 {
   ++mMigratorCount;
@@ -64,6 +80,9 @@
 void InfoDialog::migratorDone()
 {
   --mMigratorCount;
-  if ( mMigratorCount == 0 )
+  if ( mMigratorCount == 0 ) {
     enableButton( Close, true );
+    if ( mCloseWhenDone && !hasError() && !hasChange() )
+      emit closeClicked();
+  }
 }
--- trunk/KDE/kdepim/akonadi/migration/kres/infodialog.h #878307:878308
@@ -20,6 +20,8 @@
 #ifndef INFODIALOG_H
 #define INFODIALOG_H
 
+#include "kresmigratorbase.h"
+
 #include <KDialog>
 
 class QListWidget;
@@ -28,20 +30,24 @@
 {
   Q_OBJECT
   public:
-    InfoDialog();
+    InfoDialog( bool closeWhenDone = true );
     ~InfoDialog();
 
   public slots:
-    void successMessage( const QString &msg );
-    void infoMessage( const QString &msg );
-    void errorMessage( const QString &msg );
+    void message( KResMigratorBase::MessageType type, const QString &msg );
 
     void migratorAdded();
     void migratorDone();
 
+    bool hasError() const { return mError; }
+    bool hasChange() const { return mChange; }
+
   private:
     QListWidget *mList;
     int mMigratorCount;
+    bool mError;
+    bool mChange;
+    bool mCloseWhenDone;
 };
 
 #endif
--- trunk/KDE/kdepim/akonadi/migration/kres/kcalmigrator.cpp #878307:878308
@@ -48,6 +48,7 @@
 
 void KCalMigrator::migrateFileResource(KCal::ResourceCalendar * res)
 {
+  Q_UNUSED( res );
   const AgentType type = AgentManager::self()->type( "akonadi_ical_resource" );
   if ( !type.isValid() ) {
     migrationFailed( "Unable to obtain ical resource type" );
--- trunk/KDE/kdepim/akonadi/migration/kres/kresmigrator.h #878307:878308
@@ -63,20 +63,20 @@
       while ( mIt != mManager->end() ) {
         if ( (*mIt)->type() == "akonadi" ) {
           mClientBridgeFound = true;
-          emit successMessage( i18n( "Client-side bridge already set up." ) );
+          emit message( Skip, i18n( "Client-side bridge already set up." ) );
           ++mIt;
           continue;
         }
         KConfigGroup cfg( KGlobal::config(), "Resource " + (*mIt)->identifier() );
         if ( migrationState( *mIt ) == None ) {
-          emit infoMessage( i18n( "Trying to migrate '%1'...", \
(*mIt)->resourceName() ) ); +          emit message( Info, i18n( "Trying to migrate \
'%1'...", (*mIt)->resourceName() ) );  mPendingBridgedResources.removeAll( \
(*mIt)->identifier() );  T* res = *mIt;
           mCurrentKResource = res;
           ++mIt;
           bool nativeAvailable = mBridgeOnly ? false : migrateResource( res );
           if ( !nativeAvailable ) {
-            emit infoMessage( i18n( "No native backend for '%1' available.", \
res->resourceName() ) ); +            emit message( Info, i18n( "No native backend \
for '%1' available.", res->resourceName() ) );  migrateToBridge( res, mBridgeType );
           }
           return;
@@ -84,7 +84,7 @@
         if ( migrationState( *mIt ) == Bridged && \
!mPendingBridgedResources.contains( (*mIt)->identifier() ) )  \
mPendingBridgedResources << (*mIt)->identifier();  if ( migrationState( *mIt ) == \
                Complete )
-          emit successMessage( i18n( "'%1' has already been migrated.", \
(*mIt)->resourceName() ) ); +          emit message( Skip, i18n( "'%1' has already \
been migrated.", (*mIt)->resourceName() ) );  ++mIt;
       }
       if ( mIt == mManager->end() ) {
@@ -107,7 +107,7 @@
       KConfigGroup resMigrationCfg( KGlobal::config(), "Resource " + resId );
       const QString akoResId = resMigrationCfg.readEntry( "ResourceIdentifier", "" \
);  if ( akoResId.isEmpty() ) {
-        emit errorMessage( "No Akonadi agent identifier specified for previously \
bridged resource '" + resId + "'" ); +        emit message( Error, "No Akonadi agent \
identifier specified for previously bridged resource '" + resId + "'" );  \
migrateNext();  return;
       }
@@ -119,17 +119,17 @@
       KRES::Manager<T> *mBridgeManager = new KRES::Manager<T>( mType );
       mBridgeManager->readConfig( mConfig );
       if ( !mBridgeManager->standardResource() ) {
-        emit errorMessage( "Bridged resource '" + resId + "' has no standard \
resource." ); +        emit message( Error, "Bridged resource '" + resId + "' has no \
standard resource." );  migrateNext();
         return;
       }
 
       T *res = mBridgeManager->standardResource();
-      emit infoMessage( i18n( "Trying to migrate '%1' from compatibility bridge to \
native backend...", res->resourceName() ) ); +      emit message( Info, i18n( "Trying \
to migrate '%1' from compatibility bridge to native backend...", res->resourceName() \
) );  mCurrentKResource = res;
       bool nativeAvailable = migrateResource( res );
       if ( !nativeAvailable ) {
-        emit successMessage( i18n( "No native backend avaiable, keeping \
compatibility bridge for '%1'", res->resourceName() ) ); +        emit message( Skip, \
i18n( "No native backend avaiable, keeping compatibility bridge for '%1'", \
res->resourceName() ) );  migrateNext();
       }
     }
@@ -152,15 +152,15 @@
     void setupClientBridge()
     {
       if ( !mClientBridgeFound ) {
-        emit infoMessage( i18n( "Setting up client-side bridge..." ) );
+        emit message( Info, i18n( "Setting up client-side bridge..." ) );
         T* clientBridge = mManager->createResource( "akonadi" );
         if ( clientBridge ) {
           clientBridge->setResourceName( i18n("Akonadi Compatibility Resource") );
           mManager->add( clientBridge );
           mManager->setStandardResource( clientBridge );
-          emit successMessage( i18n( "Client-side bridge set up successfully." ) );
+          emit message( Info, i18n( "Client-side bridge set up successfully." ) );
         } else {
-          emit errorMessage( i18n( "Could not create client-side bridge, check if \
Akonadi KResource bridge is installed." ) ); +          emit message( Error, i18n( \
"Could not create client-side bridge, check if Akonadi KResource bridge is \
installed." ) );  }
       }
       deleteLater();
--- trunk/KDE/kdepim/akonadi/migration/kres/kresmigratorbase.cpp #878307:878308
@@ -103,7 +103,7 @@
     return;
   }
 
-  emit infoMessage( i18n( "Trying to migragte '%1' to compatibility bridge...", \
res->resourceName() ) ); +  emit message( Info, i18n( "Trying to migragte '%1' to \
compatibility bridge...", res->resourceName() ) );  mBridgingInProgress = true;
   const AgentType type = AgentManager::self()->type( typeId );
   if ( !type.isValid() ) {
@@ -163,7 +163,7 @@
   }
 
   setMigrationState( mCurrentKResource, Complete, instance.identifier() );
-  emit successMessage( i18n( "Migration of '%1' succeeded.", \
mCurrentKResource->resourceName() ) ); +  emit message( Success, i18n( "Migration of \
'%1' succeeded.", mCurrentKResource->resourceName() ) );  mCurrentKResource = 0;
   migrateNext();
 }
@@ -172,7 +172,7 @@
 {
   mBridgingInProgress = false;
   setMigrationState( mCurrentKResource, Bridged, instance.identifier() );
-  emit successMessage( i18n( "Migration of '%1' to compatibility bridge succeeded.", \
mCurrentKResource->resourceName() ) ); +  emit message( Success, i18n( "Migration of \
'%1' to compatibility bridge succeeded.", mCurrentKResource->resourceName() ) );  \
mCurrentKResource = 0;  migrateNext();
 }
@@ -180,10 +180,10 @@
 void KResMigratorBase::migrationFailed(const QString & errorMsg, const \
Akonadi::AgentInstance & instance)  {
   if ( mBridgingInProgress ) {
-    emit errorMessage( i18n( "Migration of '%1' to compatibility bridge failed: %2",
+    emit message( Error, i18n( "Migration of '%1' to compatibility bridge failed: \
%2",  mCurrentKResource->resourceName(), errorMsg ) );
   } else {
-    emit errorMessage( i18n( "Migration of '%1' to native backend failed: %2",
+    emit message( Error, i18n( "Migration of '%1' to native backend failed: %2",
                        mCurrentKResource->resourceName(), errorMsg ) );
   }
 
--- trunk/KDE/kdepim/akonadi/migration/kres/kresmigratorbase.h #878307:878308
@@ -46,6 +46,14 @@
       Complete
     };
 
+    enum MessageType
+    {
+      Success,
+      Skip,
+      Info,
+      Error
+    };
+
     Q_ENUMS( MigrationState )
 
     KResMigratorBase( const QString &type, const QString &bridgeType );
@@ -65,9 +73,7 @@
     void migrationFailed( const QString &errorMsg, const Akonadi::AgentInstance \
&instance = Akonadi::AgentInstance() );  
   signals:
-    void successMessage( const QString &msg );
-    void infoMessage( const QString &msg );
-    void errorMessage( const QString &msg );
+    void message( KResMigratorBase::MessageType type, const QString &msg );
 
   protected slots:
     virtual void migrate() = 0;
--- trunk/KDE/kdepim/akonadi/migration/kres/main.cpp #878307:878308
@@ -33,9 +33,8 @@
   if ( !dlg || !m )
     return;
   dlg->migratorAdded();
-  QObject::connect( m, SIGNAL(successMessage(QString)), dlg, \
                SLOT(successMessage(QString)) );
-  QObject::connect( m, SIGNAL(infoMessage(QString)), dlg, SLOT(infoMessage(QString)) \
                );
-  QObject::connect( m, SIGNAL(errorMessage(QString)), dlg, \
SLOT(errorMessage(QString)) ); +  QObject::connect( m, \
SIGNAL(message(KResMigratorBase::MessageType,QString)), dlg, +                    \
SLOT(message(KResMigratorBase::MessageType,QString)) );  QObject::connect( m, \
SIGNAL(destroyed()), dlg, SLOT(migratorDone()) );  }
 
@@ -52,12 +51,16 @@
   aboutData.setProgramIconName( "akonadi" );
   aboutData.addAuthor( ki18n( "Volker Krause" ),  ki18n( "Author" ), \
"vkrause@kde.org" );  
+  const QStringList supportedTypes = QStringList() << "contact" << "calendar";
+
   KCmdLineArgs::init( argc, argv, &aboutData );
   KCmdLineOptions options;
   options.add( "bridge-only", ki18n("Only migrate to Akonadi KResource bridges") );
   options.add( "contacts-only", ki18n("Only migrate contact resources") );
   options.add( "calendar-only", ki18n("Only migrate calendar resources") );
-  options.add( "interactive", ki18n( "Do not show reporting dialog") );
+  options.add( "type <type>", ki18n("Only migrate the specified types (supported: \
contact, calendar)" ), "contact,calendar" ); +  options.add( "interactive", ki18n( \
"Show reporting dialog") ); +  options.add( "interactive-on-change", ki18n("Show \
report only if changes were made") );  KCmdLineArgs::addCmdLineOptions( options );
   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
@@ -70,21 +73,24 @@
     return 1;
 
   InfoDialog *infoDialog = 0;
-  if ( args->isSet( "interactive" ) ) {
-    infoDialog = new InfoDialog();
+  if ( args->isSet( "interactive" ) || args->isSet( "interactive-on-change" ) ) {
+    infoDialog = new InfoDialog( args->isSet( "interactive-on-change" ) );
     infoDialog->show();
   }
 
-  if ( !args->isSet( "calendar-only" ) ) {
-    KABCMigrator *m = new KABCMigrator();
+  foreach ( const QString &type, args->getOption( "type" ).split( ',' ) ) {
+    KResMigratorBase *m = 0;
+    if ( type == "contact" )
+      m = new KABCMigrator();
+    else if ( type == "calendar" )
+      m = new KCalMigrator();
+    else {
+      kError() << "Unknown resource type: " << type;
+      continue;
+    }
     m->setBridgingOnly( args->isSet( "bridge-only" ) );
     connectMigrator( m, infoDialog );
   }
-  if ( !args->isSet( "contacts-only" ) ) {
-    KCalMigrator *m = new KCalMigrator();
-    m->setBridgingOnly( args->isSet( "bridge-only" ) );
-    connectMigrator( m, infoDialog );
-  }
 
   return app.exec();
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic