kaddressbook

bookmark_xxport.cpp
1 /*
2  This file is part of KAddressbook.
3  Copyright (c) 2003 Alexander Kellett <lypanov@kde.org>
4  Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <kbookmark.h>
26 #include <kbookmarkmanager.h>
27 #include <kbookmarkmenu.h>
28 #include <kbookmarkdombuilder.h>
29 #include <tdelocale.h>
30 #include <kstandarddirs.h>
31 
32 #include "bookmark_xxport.h"
33 
34 K_EXPORT_KADDRESSBOOK_XXFILTER( libkaddrbk_bookmark_xxport, BookmarkXXPort )
35 
36 BookmarkXXPort::BookmarkXXPort( TDEABC::AddressBook *ab, TQWidget *parent, const char *name )
37  : KAB::XXPort( ab, parent, name )
38 {
39  createExportAction( i18n( "Export Bookmarks Menu..." ) );
40 }
41 
42 bool BookmarkXXPort::exportContacts( const TDEABC::AddresseeList &list, const TQString& )
43 {
44  TQString fileName = locateLocal( "data", "tdeabc/bookmarks.xml" );
45 
46  KBookmarkManager *mgr = KBookmarkManager::managerForFile( fileName );
47  KBookmarkDomBuilder *builder = new KBookmarkDomBuilder( mgr->root(), mgr );
48  builder->connectImporter( this );
49 
50  TDEABC::AddresseeList::ConstIterator it;
51  emit newFolder( i18n( "AddressBook" ), false, "" );
52  for ( it = list.begin(); it != list.end(); ++it ) {
53  if ( !(*it).url().isEmpty() ) {
54  TQString name = (*it).givenName() + " " + (*it).familyName();
55  emit newBookmark( name, (*it).url().url().latin1(), TQString( "" ) );
56  }
57  }
58  emit endFolder();
59  delete builder;
60  mgr->save();
61 
62  KBookmarkMenu::DynMenuInfo menu;
63  menu.name = i18n( "Addressbook Bookmarks" );
64  menu.location = fileName;
65  menu.type = "xbel";
66  menu.show = true;
67  KBookmarkMenu::setDynamicBookmarks( "tdeabc", menu );
68 
69  return true;
70 }
71 
72 #include "bookmark_xxport.moc"