• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

advancedcustomfields.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KAddressbook.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00005     Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <QtCore/QRegExp>
00027 #include <QtGui/QCheckBox>
00028 #include <QtGui/QVBoxLayout>
00029 
00030 #include <kdatepicker.h>
00031 #include <kdatetimewidget.h>
00032 #include <kdialog.h>
00033 #include <klineedit.h>
00034 #include <kstandarddirs.h>
00035 
00036 #include <libkdepim/designerfields.h>
00037 
00038 #include "customfieldswidget.h"
00039 
00040 #include "advancedcustomfields.h"
00041 
00042 class KABCStorage : public KPIM::DesignerFields::Storage
00043 {
00044   public:
00045     KABCStorage( KABC::Addressee *a, const QString &ns )
00046       : mAddressee( a ), mNs( ns )
00047     {
00048     }
00049 
00050     QStringList keys()
00051     {
00052       QStringList keys;
00053 
00054       const QStringList customs = mAddressee->customs();
00055       QStringList::ConstIterator it;
00056       for ( it = customs.begin(); it != customs.end(); ++it ) {
00057         QString app, name, value;
00058         splitField( *it, app, name, value );
00059         if ( app == mNs ) keys.append( name );
00060       }
00061 
00062       return keys;
00063     }
00064 
00065     QString read( const QString &key )
00066     {
00067       return mAddressee->custom( mNs, key );
00068     }
00069 
00070     void write( const QString &key, const QString &value )
00071     {
00072       mAddressee->insertCustom( mNs, key, value );
00073     }
00074 
00075   private:
00076     KABC::Addressee *mAddressee;
00077     QString mNs;
00078 };
00079 
00080 
00081 AdvancedCustomFields::AdvancedCustomFields( const QString &uiFile, KABC::AddressBook *ab,
00082                                             QWidget *parent )
00083   : KAB::ContactEditorWidget( ab, parent )
00084 {
00085   initGUI( uiFile );
00086 }
00087 
00088 void AdvancedCustomFields::loadContact( KABC::Addressee *addr )
00089 {
00090   QString ns;
00091   if ( mFields->identifier().toUpper() == "KADDRESSBOOK" ||
00092     QRegExp( "^Form\\d\\d?$" ).indexIn( mFields->identifier() ) >= 0 ) {
00093     ns = "KADDRESSBOOK";
00094   } else {
00095     ns = mFields->identifier();
00096   }
00097 
00098   KABCStorage storage( addr, ns );
00099   mFields->load( &storage );
00100 }
00101 
00102 void AdvancedCustomFields::storeContact( KABC::Addressee *addr )
00103 {
00104   QString ns;
00105   if ( mFields->identifier().toUpper() == "KADDRESSBOOK" ||
00106     QRegExp( "^Form\\d\\d?$" ).indexIn( mFields->identifier() ) >= 0 ) {
00107     ns = "KADDRESSBOOK";
00108   } else {
00109     ns = mFields->identifier();
00110   }
00111 
00112   KABCStorage storage( addr, ns );
00113   mFields->save( &storage );
00114 }
00115 
00116 void AdvancedCustomFields::setReadOnly( bool readOnly )
00117 {
00118   mFields->setReadOnly( readOnly );
00119 }
00120 
00121 void AdvancedCustomFields::initGUI( const QString &uiFile )
00122 {
00123   QVBoxLayout *layout = new QVBoxLayout( this );
00124   layout->setSpacing( KDialog::spacingHint() );
00125   layout->setMargin( KDialog::marginHint() );
00126 
00127   mFields = new KPIM::DesignerFields( uiFile, this );
00128   layout->addWidget( mFields );
00129 
00130   connect( mFields, SIGNAL( modified() ), SLOT( setModified() ) );
00131 }
00132 
00133 QString AdvancedCustomFields::pageIdentifier() const
00134 {
00135   return mFields->identifier();
00136 }
00137 
00138 QString AdvancedCustomFields::pageTitle() const
00139 {
00140   return mFields->title();
00141 }
00142 
00143 #include "advancedcustomfields.moc"

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal