TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9KB

  1. /*
  2. This file is part of libkabc.
  3. Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <kaboutdata.h>
  18. #include <kapplication.h>
  19. #include <kcmdlineargs.h>
  20. #include <ksimpleconfig.h>
  21. #include <kdebug.h>
  22. #include <kglobal.h>
  23. #include <klocale.h>
  24. #include <kstandarddirs.h>
  25. #include <kabc/stdaddressbook.h>
  26. #include <libtdepim/distributionlist.h>
  27. static const KCmdLineOptions options[] =
  28. {
  29. { "disable-autostart", "Disable automatic startup on login", 0 },
  30. KCmdLineLastOption
  31. };
  32. void convertDistributionLists()
  33. {
  34. KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
  35. const TQMap<TQString, TQString> entryMap = cfg.entryMap( "DistributionLists" );
  36. if ( entryMap.isEmpty() ) // nothing to convert
  37. return;
  38. TQMapConstIterator<TQString, TQString> it;
  39. for ( it = entryMap.begin(); it != entryMap.end(); ++it ) {
  40. const TQString listName = it.key();
  41. const TQStringList entries = TQStringList::split( ',', it.data(), true );
  42. KPIM::DistributionList distList;
  43. distList.setUid( KApplication::randomString( 10 ) );
  44. distList.setName( listName );
  45. if ( entries.count() > 1 ) {
  46. for ( uint i = 0; i < entries.count(); i += 2 ) {
  47. const TQString uid = entries[ i ];
  48. const TQString preferredEMail = entries[ i + 1 ];
  49. distList.insertEntry( uid, preferredEMail );
  50. }
  51. }
  52. KABC::StdAddressBook::self()->insertAddressee( distList );
  53. }
  54. KABC::StdAddressBook::self()->save();
  55. }
  56. int main( int argc, char **argv )
  57. {
  58. KApplication::disableAutoDcopRegistration();
  59. KAboutData aboutData( "kabcdistlistupdater", "Converter tool for distribution lists", "0.1" );
  60. aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
  61. KCmdLineArgs::init( argc, argv, &aboutData );
  62. KCmdLineArgs::addCmdLineOptions( options );
  63. KApplication app( false, false );
  64. KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
  65. if ( args->isSet( "disable-autostart" ) ) {
  66. kdDebug() << "Disable autostart." << endl;
  67. KConfig *config = app.config();
  68. config->setGroup( "Startup" );
  69. config->writeEntry( "EnableAutostart", false );
  70. }
  71. convertDistributionLists();
  72. }