You need a space here
[kdepim.git] / kaddressbook / advancedcustomfields.cpp
blob02106b80c63e488cc5ea8d22a1f1df15364d8cb3
1 /*
2 This file is part of KAddressbook.
4 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
26 #include <QtCore/QRegExp>
27 #include <QtGui/QCheckBox>
28 #include <QtGui/QVBoxLayout>
30 #include <kdatepicker.h>
31 #include <kdatetimewidget.h>
32 #include <kdialog.h>
33 #include <klineedit.h>
34 #include <kstandarddirs.h>
36 #include <libkdepim/designerfields.h>
38 #include "customfieldswidget.h"
40 #include "advancedcustomfields.h"
42 class KABCStorage : public KPIM::DesignerFields::Storage
44 public:
45 KABCStorage( KABC::Addressee *a, const QString &ns )
46 : mAddressee( a ), mNs( ns )
50 QStringList keys()
52 QStringList keys;
54 const QStringList customs = mAddressee->customs();
55 QStringList::ConstIterator it;
56 for ( it = customs.begin(); it != customs.end(); ++it ) {
57 QString app, name, value;
58 splitField( *it, app, name, value );
59 if ( app == mNs ) keys.append( name );
62 return keys;
65 QString read( const QString &key )
67 return mAddressee->custom( mNs, key );
70 void write( const QString &key, const QString &value )
72 mAddressee->insertCustom( mNs, key, value );
75 private:
76 KABC::Addressee *mAddressee;
77 QString mNs;
81 AdvancedCustomFields::AdvancedCustomFields( const QString &uiFile, KABC::AddressBook *ab,
82 QWidget *parent )
83 : KAB::ContactEditorWidget( ab, parent )
85 initGUI( uiFile );
88 void AdvancedCustomFields::loadContact( KABC::Addressee *addr )
90 QString ns;
91 if ( mFields->identifier().toUpper() == "KADDRESSBOOK" ||
92 QRegExp( "^Form\\d\\d?$" ).indexIn( mFields->identifier() ) >= 0 ) {
93 ns = "KADDRESSBOOK";
94 } else {
95 ns = mFields->identifier();
98 KABCStorage storage( addr, ns );
99 mFields->load( &storage );
102 void AdvancedCustomFields::storeContact( KABC::Addressee *addr )
104 QString ns;
105 if ( mFields->identifier().toUpper() == "KADDRESSBOOK" ||
106 QRegExp( "^Form\\d\\d?$" ).indexIn( mFields->identifier() ) >= 0 ) {
107 ns = "KADDRESSBOOK";
108 } else {
109 ns = mFields->identifier();
112 KABCStorage storage( addr, ns );
113 mFields->save( &storage );
116 void AdvancedCustomFields::setReadOnly( bool readOnly )
118 mFields->setReadOnly( readOnly );
121 void AdvancedCustomFields::initGUI( const QString &uiFile )
123 QVBoxLayout *layout = new QVBoxLayout( this );
124 layout->setSpacing( KDialog::spacingHint() );
125 layout->setMargin( KDialog::marginHint() );
127 mFields = new KPIM::DesignerFields( uiFile, this );
128 layout->addWidget( mFields );
130 connect( mFields, SIGNAL( modified() ), SLOT( setModified() ) );
133 QString AdvancedCustomFields::pageIdentifier() const
135 return mFields->identifier();
138 QString AdvancedCustomFields::pageTitle() const
140 return mFields->title();
143 #include "advancedcustomfields.moc"