kaddressbook
advancedcustomfields.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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"
|