kmail

vcardviewer.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 #include "vcardviewer.h"
00025 #include "kmaddrbook.h"
00026 #include <kaddrbook.h>
00027 
00028 #include <addresseeview.h>
00029 using KPIM::AddresseeView;
00030 
00031 #include <tdeabc/vcardconverter.h>
00032 #include <tdeabc/addressee.h>
00033 using TDEABC::VCardConverter;
00034 using TDEABC::Addressee;
00035 
00036 #include <tdelocale.h>
00037 
00038 #include <tqstring.h>
00039 
00040 #if defined(KABC_VCARD_ENCODING_FIX)
00041 KMail::VCardViewer::VCardViewer( TQWidget *parent, const TQByteArray &vCard, const char *name )
00042 #else
00043 KMail::VCardViewer::VCardViewer( TQWidget *parent, const TQString &vCard, const char *name )
00044 #endif
00045   : KDialogBase( parent, name, false, i18n("VCard Viewer"), User1|User2|User3|Close, Close,
00046          true, i18n("&Import"), i18n("&Next Card"), i18n("&Previous Card") )
00047 {
00048   mAddresseeView = new AddresseeView(this);
00049   mAddresseeView->enableLinks( 0 );
00050   mAddresseeView->setVScrollBarMode(TQScrollView::Auto);
00051   setMainWidget(mAddresseeView);
00052 
00053   VCardConverter vcc;
00054 #if defined(KABC_VCARD_ENCODING_FIX)
00055   mAddresseeList = vcc.parseVCardsRaw( vCard.data() );
00056 #else
00057   mAddresseeList = vcc.parseVCards( vCard );
00058 #endif
00059   if ( !mAddresseeList.empty() ) {
00060     itAddresseeList = mAddresseeList.begin();
00061     mAddresseeView->setAddressee( *itAddresseeList );
00062     if ( mAddresseeList.size() <= 1 ) {
00063       showButton(User2, false);
00064       showButton(User3, false);
00065     }
00066     else
00067       enableButton(User3, false);
00068   }
00069   else {
00070     mAddresseeView->setText(i18n("Failed to parse vCard."));
00071     enableButton(User1, false);
00072   }
00073 
00074   resize(300,400);
00075 }
00076 
00077 KMail::VCardViewer::~VCardViewer()
00078 {
00079 }
00080 
00081 void KMail::VCardViewer::slotUser1()
00082 {
00083   KAddrBookExternal::addVCard( *itAddresseeList, this );
00084 }
00085 
00086 void KMail::VCardViewer::slotUser2()
00087 {
00088   // next vcard
00089   mAddresseeView->setAddressee( *(++itAddresseeList) );
00090   if ( itAddresseeList == --(mAddresseeList.end()) )
00091     enableButton(User2, false);
00092   enableButton(User3, true);
00093 }
00094 
00095 void KMail::VCardViewer::slotUser3()
00096 {
00097   // previous vcard
00098   mAddresseeView->setAddressee( *(--itAddresseeList) );
00099   if ( itAddresseeList == mAddresseeList.begin() )
00100     enableButton(User3, false);
00101   enableButton(User2, true);
00102 }
00103 
00104 #include "vcardviewer.moc"