kaddressbook Library API Documentation

bookmark_xxport.cpp

00001 /*
00002     This file is part of KAddressbook.
00003     Copyright (c) 2003  Alexander Kellett <lypanov@kde.org>
00004                         Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <kbookmark.h>
00026 #include <kbookmarkmanager.h>
00027 #include <kbookmarkmenu.h>
00028 #include <kbookmarkdombuilder.h>
00029 #include <klocale.h>
00030 #include <kstandarddirs.h>
00031 
00032 #include "bookmark_xxport.h"
00033 
00034 class BookmarkXXPortFactory : public KAB::XXPortFactory
00035 {
00036   public:
00037     KAB::XXPort *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
00038     {
00039       return new BookmarkXXPort( ab, parent, name );
00040     }
00041 };
00042 
00043 extern "C"
00044 {
00045   void *init_libkaddrbk_bookmark_xxport()
00046   {
00047     return ( new BookmarkXXPortFactory() );
00048   }
00049 }
00050 
00051 
00052 BookmarkXXPort::BookmarkXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
00053   : KAB::XXPort( ab, parent, name )
00054 {
00055   createExportAction( i18n( "Export Bookmarks Menu..." ) );
00056 }
00057 
00058 bool BookmarkXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
00059 {
00060   QString fileName = locateLocal( "data", "kabc/bookmarks.xml" );
00061 
00062   KBookmarkManager *mgr = KBookmarkManager::managerForFile( fileName );
00063   KBookmarkDomBuilder *builder = new KBookmarkDomBuilder( mgr->root(), mgr );
00064   builder->connectImporter( this );
00065 
00066   KABC::AddresseeList::ConstIterator it;
00067   emit newFolder( i18n( "AddressBook" ), false, "" );
00068   for ( it = list.begin(); it != list.end(); ++it ) {
00069     if ( !(*it).url().isEmpty() ) {
00070       QString name = (*it).givenName() + " " + (*it).familyName();
00071       emit newBookmark( name, (*it).url().url().latin1(), QString( "" ) );
00072     }
00073   }
00074   emit endFolder();
00075   delete builder;
00076   mgr->save();
00077 
00078   KBookmarkMenu::DynMenuInfo menu;
00079   menu.name = i18n( "Addressbook Bookmarks" );
00080   menu.location = fileName;
00081   menu.type = "xbel";
00082   menu.show = true;
00083   KBookmarkMenu::setDynamicBookmarks( "kabc", menu );
00084 
00085   return true;
00086 }
00087 
00088 #include "bookmark_xxport.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:50 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003