kaddressbook
customfieldswidget.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 <qmap.h>
00032 #include <qpair.h>
00033 #include <qstringlist.h>
00034 #include <qvaluevector.h>
00035 #include <qwidget.h>
00036
00037 #include "contacteditorwidget.h"
00038
00039 class QCheckBox;
00040 class QGridLayout;
00041 class QLabel;
00042 class QPushButton;
00043 class QVBoxLayout;
00044 class QWidget;
00045
00046 class KComboBox;
00047 class KLineEdit;
00048
00049 typedef struct {
00050 QString mIdentifier;
00051 QString mTitle;
00052 bool mGlobal;
00053
00054 QLabel *mLabel;
00055 QWidget *mWidget;
00056 QHBoxLayout *mLayout;
00057 } FieldRecord;
00058
00059 typedef QValueList<FieldRecord> FieldRecordList;
00060
00061 class AddFieldDialog : public KDialogBase
00062 {
00063 Q_OBJECT
00064
00065 public:
00066 AddFieldDialog( QWidget *parent, const char *name = 0 );
00067
00068 QString title() const;
00069 QString identifier() const;
00070 QString type() const;
00071 bool isGlobal() const;
00072
00073 private slots:
00074 void nameChanged( const QString& );
00075
00076 private:
00077 KLineEdit *mTitle;
00078 KComboBox *mType;
00079 QCheckBox *mGlobal;
00080
00081 QValueVector<QString> mTypeList;
00082 QValueVector<QString> mTypeName;
00083 };
00084
00085 class FieldWidget : public QWidget
00086 {
00087 Q_OBJECT
00088
00089 public:
00090 FieldWidget( QWidget *parent, const char *name = 0 );
00091
00092 void addField( const QString &identifier, const QString &title,
00093 const QString &type, bool isGlobal );
00094
00095 void removeField( const QString &identifier );
00096
00097 void loadContact( KABC::Addressee *addr );
00098 void storeContact( KABC::Addressee *addr );
00099 void setReadOnly( bool readOnly );
00100
00101 FieldRecordList fields() const { return mFieldList; }
00102
00103 void removeLocalFields();
00104 void clearFields();
00105
00106 signals:
00107 void changed();
00108
00109 private:
00110 void recalculateLayout();
00111
00112 QVBoxLayout *mGlobalLayout;
00113 QVBoxLayout *mLocalLayout;
00114 QFrame *mSeparator;
00115
00116 FieldRecordList mFieldList;
00117 };
00118
00119 class CustomFieldsWidget : public KAB::ContactEditorWidget
00120 {
00121 Q_OBJECT
00122
00123 public:
00124 CustomFieldsWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
00125
00126 void loadContact( KABC::Addressee *addr );
00127 void storeContact( KABC::Addressee *addr );
00128 void setReadOnly( bool readOnly );
00129
00130 private slots:
00131 void addField();
00132 void removeField();
00133
00134 private:
00135 void initGUI();
00136
00137 QStringList marshallFields( bool ) const;
00138
00139 QPushButton *mAddButton;
00140 QPushButton *mRemoveButton;
00141 QGridLayout *mLayout;
00142
00143 FieldWidget *mFieldWidget;
00144
00145 KABC::Addressee mAddressee;
00146 };
00147
00148 class CustomFieldsWidgetFactory : public KAB::ContactEditorWidgetFactory
00149 {
00150 public:
00151 KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
00152 {
00153 return new CustomFieldsWidget( ab, parent, name );
00154 }
00155
00156 QString pageTitle() const { return i18n( "Custom Fields" ); }
00157 QString pageIdentifier() const { return "custom_fields"; }
00158 };
00159
00160 void splitField( const QString&, QString&, QString&, QString& );
00161
00162 #endif
|