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 <kabc/vcardconverter.h>
00032 #include <kabc/addressee.h>
00033 using KABC::VCardConverter;
00034 using KABC::Addressee;
00035 
00036 #include <klocale.h>
00037 
00038 #include <qstring.h>
00039 
00040 KMail::VCardViewer::VCardViewer(QWidget *parent, const QString& vCard, const char* name)
00041   : KDialogBase( parent, name, false, i18n("VCard Viewer"), User1|User2|User3|Close, Close,
00042          true, i18n("&Import"), i18n("&Next Card"), i18n("&Previous Card") )
00043 {
00044   mAddresseeView = new AddresseeView(this);
00045   mAddresseeView->enableLinks( 0 );
00046   mAddresseeView->setVScrollBarMode(QScrollView::Auto);
00047   setMainWidget(mAddresseeView);
00048 
00049   VCardConverter vcc;
00050   mAddresseeList = vcc.parseVCards( vCard );
00051   if ( !mAddresseeList.empty() ) {
00052     itAddresseeList = mAddresseeList.begin();
00053     mAddresseeView->setAddressee( *itAddresseeList );
00054     if ( mAddresseeList.size() <= 1 ) {
00055       showButton(User2, false);
00056       showButton(User3, false);
00057     }
00058     else
00059       enableButton(User3, false);
00060   }
00061   else {
00062     mAddresseeView->setText(i18n("Failed to parse vCard."));
00063     enableButton(User1, false);
00064     showButton(User2, false);
00065     showButton(User3, false);
00066   }
00067 
00068   resize(300,400);
00069 }
00070 
00071 KMail::VCardViewer::~VCardViewer()
00072 {
00073 }
00074 
00075 void KMail::VCardViewer::slotUser1()
00076 {
00077   KAddrBookExternal::addVCard( *itAddresseeList, this );
00078 }
00079 
00080 void KMail::VCardViewer::slotUser2()
00081 {
00082   // next vcard
00083   mAddresseeView->setAddressee( *(++itAddresseeList) );
00084   if ( itAddresseeList == --(mAddresseeList.end()) )
00085     enableButton(User2, false);
00086   enableButton(User3, true);
00087 }
00088 
00089 void KMail::VCardViewer::slotUser3()
00090 {
00091   // previous vcard
00092   mAddresseeView->setAddressee( *(--itAddresseeList) );
00093   if ( itAddresseeList == mAddresseeList.begin() )
00094     enableButton(User3, false);
00095   enableButton(User2, true);
00096 }
00097 
00098 #include "vcardviewer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys