kmail

vcardviewer.cpp

Go to the documentation of this file.
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   }
00065 
00066   resize(300,400);
00067 }
00068 
00069 KMail::VCardViewer::~VCardViewer()
00070 {
00071 }
00072 
00073 void KMail::VCardViewer::slotUser1()
00074 {
00075   KAddrBookExternal::addVCard( *itAddresseeList, this );
00076 }
00077 
00078 void KMail::VCardViewer::slotUser2()
00079 {
00080   // next vcard
00081   mAddresseeView->setAddressee( *(++itAddresseeList) );
00082   if ( itAddresseeList == --(mAddresseeList.end()) )
00083     enableButton(User2, false);
00084   enableButton(User3, true);
00085 }
00086 
00087 void KMail::VCardViewer::slotUser3()
00088 {
00089   // previous vcard
00090   mAddresseeView->setAddressee( *(--itAddresseeList) );
00091   if ( itAddresseeList == mAddresseeList.begin() )
00092     enableButton(User3, false);
00093   enableButton(User2, true);
00094 }
00095 
00096 #include "vcardviewer.moc"