2
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "kabcmigrator.h"
21
#include "kcalmigrator.h"
22
#include "infodialog.h"
24
#include <akonadi/control.h>
26
#include <kaboutdata.h>
27
#include <kapplication.h>
28
#include <kcmdlineargs.h>
31
#include <QDBusConnection>
33
void connectMigrator( KResMigratorBase *m, InfoDialog *dlg )
38
QObject::connect( m, SIGNAL(message(KResMigratorBase::MessageType,QString)), dlg,
39
SLOT(message(KResMigratorBase::MessageType,QString)) );
40
QObject::connect( m, SIGNAL(destroyed()), dlg, SLOT(migratorDone()) );
43
int main( int argc, char **argv )
45
KAboutData aboutData( "kres-migrator", 0,
46
ki18n( "KResource Migration Tool" ),
48
ki18n( "Migration of KResource settings and application to Akonadi" ),
49
KAboutData::License_LGPL,
50
ki18n( "(c) 2008 the Akonadi developers" ),
52
"http://pim.kde.org/akonadi/" );
53
aboutData.setProgramIconName( "akonadi" );
54
aboutData.addAuthor( ki18n( "Volker Krause" ), ki18n( "Author" ), "vkrause@kde.org" );
56
const QStringList supportedTypes = QStringList() << "contact" << "calendar";
58
KCmdLineArgs::init( argc, argv, &aboutData );
59
KCmdLineOptions options;
60
options.add( "bridge-only", ki18n("Only migrate to Akonadi KResource bridges") );
61
options.add( "omit-client-bridge", ki18n("Omit setting up of the client side compatibility bridges") );
62
options.add( "contacts-only", ki18n("Only migrate contact resources") );
63
options.add( "calendar-only", ki18n("Only migrate calendar resources") );
64
options.add( "type <type>", ki18n("Only migrate the specified types (supported: contact, calendar)" ),
65
supportedTypes.join( "," ).toLatin1() );
66
options.add( "interactive", ki18n( "Show reporting dialog") );
67
options.add( "interactive-on-change", ki18n("Show report only if changes were made") );
68
KCmdLineArgs::addCmdLineOptions( options );
69
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
71
QStringList typesToMigrate;
72
foreach ( const QString &type, args->getOption( "type" ).split( ',' ) ) {
73
if ( !supportedTypes.contains( type ) )
74
kWarning() << "Unknown resource type: " << type;
75
else if ( !QDBusConnection::sessionBus().registerService( "org.kde.Akonadi.KResMigrator." + type ) )
76
kWarning() << "Migrator instance already running for type " << type;
78
typesToMigrate << type;
80
if ( typesToMigrate.isEmpty() )
84
app.setQuitOnLastWindowClosed( false );
86
KGlobal::setAllowQuit( true );
87
KGlobal::locale()->insertCatalog( "libakonadi" );
88
if ( !Akonadi::Control::start( 0 ) )
91
InfoDialog *infoDialog = 0;
92
if ( args->isSet( "interactive" ) || args->isSet( "interactive-on-change" ) ) {
93
infoDialog = new InfoDialog( args->isSet( "interactive-on-change" ) );
97
foreach ( const QString &type, typesToMigrate ) {
98
KResMigratorBase *m = 0;
99
if ( type == "contact" )
100
m = new KABCMigrator();
101
else if ( type == "calendar" )
102
m = new KCalMigrator();
104
kError() << "Unknown resource type: " << type;
107
m->setBridgingOnly( args->isSet( "bridge-only" ) );
108
m->setOmitClientBridge( args->isSet( "omit-client-bridge" ) );
109
connectMigrator( m, infoDialog );
112
const int result = app.exec();
113
if ( infoDialog && infoDialog->hasError() )