kmail

vcardviewer.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU 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 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include "vcardviewer.h"
25 #include "kmaddrbook.h"
26 #include <kaddrbook.h>
27 
28 #include <addresseeview.h>
29 using KPIM::AddresseeView;
30 
31 #include <tdeabc/vcardconverter.h>
32 #include <tdeabc/addressee.h>
33 using TDEABC::VCardConverter;
34 using TDEABC::Addressee;
35 
36 #include <tdelocale.h>
37 
38 #include <tqstring.h>
39 
40 #if defined(KABC_VCARD_ENCODING_FIX)
41 KMail::VCardViewer::VCardViewer( TQWidget *parent, const TQByteArray &vCard, const char *name )
42 #else
43 KMail::VCardViewer::VCardViewer( TQWidget *parent, const TQString &vCard, const char *name )
44 #endif
45  : KDialogBase( parent, name, false, i18n("VCard Viewer"), User1|User2|User3|Close, Close,
46  true, i18n("&Import"), i18n("&Next Card"), i18n("&Previous Card") )
47 {
48  mAddresseeView = new AddresseeView(this);
49  mAddresseeView->enableLinks( 0 );
50  mAddresseeView->setVScrollBarMode(TQScrollView::Auto);
51  setMainWidget(mAddresseeView);
52 
53  VCardConverter vcc;
54 #if defined(KABC_VCARD_ENCODING_FIX)
55  mAddresseeList = vcc.parseVCardsRaw( vCard.data() );
56 #else
57  mAddresseeList = vcc.parseVCards( vCard );
58 #endif
59  if ( !mAddresseeList.empty() ) {
60  itAddresseeList = mAddresseeList.begin();
61  mAddresseeView->setAddressee( *itAddresseeList );
62  if ( mAddresseeList.size() <= 1 ) {
63  showButton(User2, false);
64  showButton(User3, false);
65  }
66  else
67  enableButton(User3, false);
68  }
69  else {
70  mAddresseeView->setText(i18n("Failed to parse vCard."));
71  enableButton(User1, false);
72  }
73 
74  resize(300,400);
75 }
76 
77 KMail::VCardViewer::~VCardViewer()
78 {
79 }
80 
81 void KMail::VCardViewer::slotUser1()
82 {
83  KAddrBookExternal::addVCard( *itAddresseeList, this );
84 }
85 
86 void KMail::VCardViewer::slotUser2()
87 {
88  // next vcard
89  mAddresseeView->setAddressee( *(++itAddresseeList) );
90  if ( itAddresseeList == --(mAddresseeList.end()) )
91  enableButton(User2, false);
92  enableButton(User3, true);
93 }
94 
95 void KMail::VCardViewer::slotUser3()
96 {
97  // previous vcard
98  mAddresseeView->setAddressee( *(--itAddresseeList) );
99  if ( itAddresseeList == mAddresseeList.begin() )
100  enableButton(User3, false);
101  enableButton(User2, true);
102 }
103 
104 #include "vcardviewer.moc"