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 <tqcheckbox.h>
00027 #include <tqcombobox.h>
00028 #include <tqdatetimeedit.h>
00029 #include <tqlayout.h>
00030 #include <tqobjectlist.h>
00031 #include <tqspinbox.h>
00032 #include <tqregexp.h>
00033 #include <tqtextedit.h>
00034 #include <tqwidgetfactory.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 <libtdepim/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( TDEABC::Addressee *a, const TQString &ns )
00052 : mAddressee( a ), mNs( ns )
00053 {
00054 }
00055
00056 TQStringList keys()
00057 {
00058 TQStringList keys;
00059
00060 const TQStringList customs = mAddressee->customs();
00061 TQStringList::ConstIterator it;
00062 for ( it = customs.begin(); it != customs.end(); ++it ) {
00063 TQString app, name, value;
00064 splitField( *it, app, name, value );
00065 if ( app == mNs ) keys.append( name );
00066 }
00067
00068 return keys;
00069 }
00070
00071 TQString read( const TQString &key )
00072 {
00073 return mAddressee->custom( mNs, key );
00074 }
00075
00076 void write( const TQString &key, const TQString &value )
00077 {
00078 mAddressee->insertCustom( mNs, key, value );
00079 }
00080
00081 private:
00082 TDEABC::Addressee *mAddressee;
00083 TQString mNs;
00084 };
00085
00086
00087 AdvancedCustomFields::AdvancedCustomFields( const TQString &uiFile, TDEABC::AddressBook *ab,
00088 TQWidget *parent, const char *name )
00089 : KAB::ContactEditorWidget( ab, parent, name )
00090 {
00091 initGUI( uiFile );
00092 }
00093
00094 void AdvancedCustomFields::loadContact( TDEABC::Addressee *addr )
00095 {
00096 TQString ns;
00097 if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
00098 TQRegExp( "^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( TDEABC::Addressee *addr )
00109 {
00110 TQString ns;
00111 if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
00112 TQRegExp( "^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 TQString &uiFile )
00128 {
00129 TQVBoxLayout *layout = new TQVBoxLayout( this, KDialog::marginHint(),
00130 KDialog::spacingHint() );
00131
00132 mFields = new KPIM::DesignerFields( uiFile, this );
00133 layout->addWidget( mFields );
00134
00135 connect( mFields, TQT_SIGNAL( modified() ), TQT_SLOT( setModified() ) );
00136 }
00137
00138 TQString AdvancedCustomFields::pageIdentifier() const
00139 {
00140 return mFields->identifier();
00141 }
00142
00143 TQString AdvancedCustomFields::pageTitle() const
00144 {
00145 return mFields->title();
00146 }
00147
00148 #include "advancedcustomfields.moc"
|