summaryrefslogtreecommitdiffstats
path: root/kabc/kabcdistlistupdater/kabcdistlistupdater.cpp
blob: d8f5e9969a66d7915aa212f678622f596097694c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    This file is part of libkabc.
    Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <ksimpleconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <kstandarddirs.h>

#include <kabc/stdaddressbook.h>
#include <libtdepim/distributionlist.h>

static const KCmdLineOptions options[] =
{
  { "disable-autostart", "Disable automatic startup on login", 0 },
  KCmdLineLastOption
};

void convertDistributionLists()
{
  KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
  const TQMap<TQString, TQString> entryMap = cfg.entryMap( "DistributionLists" );

  if ( entryMap.isEmpty() ) // nothing to convert
    return;

  TQMapConstIterator<TQString, TQString> it;
  for ( it = entryMap.begin(); it != entryMap.end(); ++it ) {
    const TQString listName = it.key();
    const TQStringList entries = TQStringList::split( ',', it.data(), true );

    KPIM::DistributionList distList;
    distList.setUid( TDEApplication::randomString( 10 ) );
    distList.setName( listName );

    if ( entries.count() > 1 ) {
      for ( uint i = 0; i < entries.count(); i += 2 ) {
        const TQString uid = entries[ i ];
        const TQString preferredEMail = entries[ i + 1 ];

        distList.insertEntry( uid, preferredEMail );
      }
    }

    KABC::StdAddressBook::self()->insertAddressee( distList );
  }

  KABC::StdAddressBook::self()->save();
}

int main( int argc, char **argv )
{
  TDEApplication::disableAutoDcopRegistration();

  TDEAboutData aboutData( "kabcdistlistupdater", "Converter tool for distribution lists", "0.1" );
  aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );

  TDECmdLineArgs::init( argc, argv, &aboutData );
  TDECmdLineArgs::addCmdLineOptions( options );

  TDEApplication app( false, false );

  TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

  if ( args->isSet( "disable-autostart" ) ) {
    kdDebug() << "Disable autostart." << endl;

    KConfig *config = app.config();
    config->setGroup( "Startup" );
    config->writeEntry( "EnableAutostart", false );
  }

  convertDistributionLists();
}