customfieldswidget.h
00001 /* 00002 This file is part of KAddressbook. 00003 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #ifndef CUSTOMFIELDSWIDGET_H 00025 #define CUSTOMFIELDSWIDGET_H 00026 00027 #include <kabc/addressee.h> 00028 #include <kdialogbase.h> 00029 #include <klocale.h> 00030 00031 #include <tqmap.h> 00032 #include <tqpair.h> 00033 #include <tqstringlist.h> 00034 #include <tqvaluevector.h> 00035 #include <tqwidget.h> 00036 00037 #include "contacteditorwidget.h" 00038 00039 class TQCheckBox; 00040 class TQGridLayout; 00041 class TQLabel; 00042 class TQPushButton; 00043 class TQVBoxLayout; 00044 class TQWidget; 00045 00046 class KComboBox; 00047 class KLineEdit; 00048 00049 typedef struct { 00050 TQString mIdentifier; 00051 TQString mTitle; 00052 bool mGlobal; 00053 00054 TQLabel *mLabel; 00055 TQWidget *mWidget; 00056 TQHBoxLayout *mLayout; 00057 } FieldRecord; 00058 00059 typedef TQValueList<FieldRecord> FieldRecordList; 00060 00061 class AddFieldDialog : public KDialogBase 00062 { 00063 Q_OBJECT 00064 TQ_OBJECT 00065 00066 public: 00067 AddFieldDialog( TQWidget *parent, const char *name = 0 ); 00068 00069 TQString title() const; 00070 TQString identifier() const; 00071 TQString type() const; 00072 bool isGlobal() const; 00073 00074 private slots: 00075 void nameChanged( const TQString& ); 00076 00077 private: 00078 KLineEdit *mTitle; 00079 KComboBox *mType; 00080 TQCheckBox *mGlobal; 00081 00082 TQValueVector<TQString> mTypeList; 00083 TQValueVector<TQString> mTypeName; 00084 }; 00085 00086 class FieldWidget : public TQWidget 00087 { 00088 Q_OBJECT 00089 TQ_OBJECT 00090 00091 public: 00092 FieldWidget( TQWidget *parent, const char *name = 0 ); 00093 00094 void addField( const TQString &identifier, const TQString &title, 00095 const TQString &type, bool isGlobal ); 00096 00097 void removeField( const TQString &identifier ); 00098 00099 void loadContact( KABC::Addressee *addr ); 00100 void storeContact( KABC::Addressee *addr ); 00101 void setReadOnly( bool readOnly ); 00102 00103 FieldRecordList fields() const { return mFieldList; } 00104 00105 void removeLocalFields(); 00106 void clearFields(); 00107 00108 signals: 00109 void changed(); 00110 00111 private: 00112 void recalculateLayout(); 00113 00114 TQVBoxLayout *mGlobalLayout; 00115 TQVBoxLayout *mLocalLayout; 00116 TQFrame *mSeparator; 00117 00118 FieldRecordList mFieldList; 00119 }; 00120 00121 class CustomFieldsWidget : public KAB::ContactEditorWidget 00122 { 00123 Q_OBJECT 00124 TQ_OBJECT 00125 00126 public: 00127 CustomFieldsWidget( KABC::AddressBook *ab, TQWidget *parent, const char *name = 0 ); 00128 00129 void loadContact( KABC::Addressee *addr ); 00130 void storeContact( KABC::Addressee *addr ); 00131 void setReadOnly( bool readOnly ); 00132 00133 private slots: 00134 void addField(); 00135 void removeField(); 00136 00137 private: 00138 void initGUI(); 00139 00140 TQStringList marshallFields( bool ) const; 00141 00142 TQPushButton *mAddButton; 00143 TQPushButton *mRemoveButton; 00144 TQGridLayout *mLayout; 00145 00146 FieldWidget *mFieldWidget; 00147 00148 KABC::Addressee mAddressee; 00149 }; 00150 00151 class CustomFieldsWidgetFactory : public KAB::ContactEditorWidgetFactory 00152 { 00153 public: 00154 KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, TQWidget *parent, const char *name ) 00155 { 00156 return new CustomFieldsWidget( ab, parent, name ); 00157 } 00158 00159 TQString pageTitle() const { return i18n( "Custom Fields" ); } 00160 TQString pageIdentifier() const { return "custom_fields"; } 00161 }; 00162 00163 void splitField( const TQString&, TQString&, TQString&, TQString& ); 00164 00165 #endif