kaddressbook

advancedcustomfields.cpp

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 <qcheckbox.h>
00027 #include <qcombobox.h>
00028 #include <qdatetimeedit.h>
00029 #include <qlayout.h>
00030 #include <qobjectlist.h>
00031 #include <qspinbox.h>
00032 #include <qregexp.h>
00033 #include <qtextedit.h>
00034 #include <qwidgetfactory.h>
00035 
00036 #include <kdatepicker.h>
00037 #include <kdatetimewidget.h>
00038 #include <kdialog.h>
00039 #include <klineedit.h>
00040 #include <kstandarddirs.h>
00041 
00042 #include <libkdepim/designerfields.h>
00043 
00044 #include "customfieldswidget.h"
00045 
00046 #include "advancedcustomfields.h"
00047 
00048 class KABCStorage : public KPIM::DesignerFields::Storage
00049 {
00050   public:
00051     KABCStorage( KABC::Addressee *a, const QString &ns )
00052       : mAddressee( a ), mNs( ns )
00053     {
00054     }
00055 
00056     QStringList keys()
00057     {
00058       QStringList keys;
00059 
00060       const QStringList customs = mAddressee->customs();
00061       QStringList::ConstIterator it;
00062       for ( it = customs.begin(); it != customs.end(); ++it ) {
00063         QString app, name, value;
00064         splitField( *it, app, name, value );
00065         if ( app == mNs ) keys.append( name );
00066       }
00067 
00068       return keys;
00069     }
00070 
00071     QString read( const QString &key )
00072     {
00073       return mAddressee->custom( mNs, key );
00074     }
00075 
00076     void write( const QString &key, const QString &value )
00077     {
00078       mAddressee->insertCustom( mNs, key, value );
00079     }
00080 
00081   private:
00082     KABC::Addressee *mAddressee;
00083     QString mNs;
00084 };
00085 
00086 
00087 AdvancedCustomFields::AdvancedCustomFields( const QString &uiFile, KABC::AddressBook *ab,
00088                                             QWidget *parent, const char *name )
00089   : KAB::ContactEditorWidget( ab, parent, name )
00090 {
00091   initGUI( uiFile );
00092 }
00093 
00094 void AdvancedCustomFields::loadContact( KABC::Addressee *addr )
00095 {
00096   QString ns;
00097   if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
00098     QRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
00099     ns = "KADDRESSBOOK";
00100   } else {
00101     ns = mFields->identifier();
00102   }
00103 
00104   KABCStorage storage( addr, ns );
00105   mFields->load( &storage );
00106 }
00107 
00108 void AdvancedCustomFields::storeContact( KABC::Addressee *addr )
00109 {
00110   QString ns;
00111   if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
00112     QRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
00113     ns = "KADDRESSBOOK";
00114   } else {
00115     ns = mFields->identifier();
00116   }
00117 
00118   KABCStorage storage( addr, ns );
00119   mFields->save( &storage );
00120 }
00121 
00122 void AdvancedCustomFields::setReadOnly( bool readOnly )
00123 {
00124   mFields->setReadOnly( readOnly );
00125 }
00126 
00127 void AdvancedCustomFields::initGUI( const QString &uiFile )
00128 {
00129   QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(),
00130                                          KDialog::spacingHint() );
00131 
00132   mFields = new KPIM::DesignerFields( uiFile, this );
00133   layout->addWidget( mFields );
00134 
00135   connect( mFields, SIGNAL( modified() ), SLOT( setModified() ) );
00136 }
00137 
00138 QString AdvancedCustomFields::pageIdentifier() const
00139 {
00140   return mFields->identifier();
00141 }
00142 
00143 QString AdvancedCustomFields::pageTitle() const
00144 {
00145   return mFields->title();
00146 }
00147 
00148 #include "advancedcustomfields.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys