~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/migration/kres/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3
 
 
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.
8
 
 
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.
13
 
 
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
17
 
    02110-1301, USA.
18
 
*/
19
 
 
20
 
#include "kabcmigrator.h"
21
 
#include "kcalmigrator.h"
22
 
#include "infodialog.h"
23
 
 
24
 
#include <akonadi/control.h>
25
 
 
26
 
#include <kaboutdata.h>
27
 
#include <kapplication.h>
28
 
#include <kcmdlineargs.h>
29
 
#include <kglobal.h>
30
 
 
31
 
#include <QDBusConnection>
32
 
 
33
 
void connectMigrator( KResMigratorBase *m, InfoDialog *dlg )
34
 
{
35
 
  if ( !dlg || !m )
36
 
    return;
37
 
  dlg->migratorAdded();
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()) );
41
 
}
42
 
 
43
 
int main( int argc, char **argv )
44
 
{
45
 
  KAboutData aboutData( "kres-migrator", 0,
46
 
                        ki18n( "KResource Migration Tool" ),
47
 
                        "0.1",
48
 
                        ki18n( "Migration of KResource settings and application to Akonadi" ),
49
 
                        KAboutData::License_LGPL,
50
 
                        ki18n( "(c) 2008 the Akonadi developers" ),
51
 
                        KLocalizedString(),
52
 
                        "http://pim.kde.org/akonadi/" );
53
 
  aboutData.setProgramIconName( "akonadi" );
54
 
  aboutData.addAuthor( ki18n( "Volker Krause" ),  ki18n( "Author" ), "vkrause@kde.org" );
55
 
 
56
 
  const QStringList supportedTypes = QStringList() << "contact" << "calendar";
57
 
 
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();
70
 
 
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;
77
 
    else
78
 
      typesToMigrate << type;
79
 
  }
80
 
  if ( typesToMigrate.isEmpty() )
81
 
    return 1;
82
 
 
83
 
  KApplication app;
84
 
  app.setQuitOnLastWindowClosed( false );
85
 
 
86
 
  KGlobal::setAllowQuit( true );
87
 
  KGlobal::locale()->insertCatalog( "libakonadi" );
88
 
  if ( !Akonadi::Control::start( 0 ) )
89
 
    return 2;
90
 
 
91
 
  InfoDialog *infoDialog = 0;
92
 
  if ( args->isSet( "interactive" ) || args->isSet( "interactive-on-change" ) ) {
93
 
    infoDialog = new InfoDialog( args->isSet( "interactive-on-change" ) );
94
 
    infoDialog->show();
95
 
  }
96
 
 
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();
103
 
    else {
104
 
      kError() << "Unknown resource type: " << type;
105
 
      continue;
106
 
    }
107
 
    m->setBridgingOnly( args->isSet( "bridge-only" ) );
108
 
    m->setOmitClientBridge( args->isSet( "omit-client-bridge" ) );
109
 
    connectMigrator( m, infoDialog );
110
 
  }
111
 
 
112
 
  const int result = app.exec();
113
 
  if ( infoDialog && infoDialog->hasError() )
114
 
    return 3;
115
 
  return result;
116
 
}