kaddressbook Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt 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 <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 
00105   signals:
00106     void changed();
00107 
00108   private:
00109     void recalculateLayout();
00110 
00111     QVBoxLayout *mGlobalLayout;
00112     QVBoxLayout *mLocalLayout;
00113     QFrame *mSeparator;
00114 
00115     FieldRecordList mFieldList;
00116 };
00117 
00118 class CustomFieldsWidget : public KAB::ContactEditorWidget
00119 {
00120   Q_OBJECT
00121 
00122   public:
00123     CustomFieldsWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
00124 
00125     void loadContact( KABC::Addressee *addr );
00126     void storeContact( KABC::Addressee *addr );
00127     void setReadOnly( bool readOnly );
00128 
00129   private slots:
00130     void addField();
00131     void removeField();
00132 
00133   private:
00134     void initGUI();
00135 
00136     QStringList marshallFields( bool ) const;
00137 
00138     QPushButton *mAddButton;
00139     QPushButton *mRemoveButton;
00140     QGridLayout *mLayout;
00141 
00142     FieldWidget *mFieldWidget;
00143 
00144     KABC::Addressee mAddressee;
00145 };
00146 
00147 class CustomFieldsWidgetFactory : public KAB::ContactEditorWidgetFactory
00148 {
00149   public:
00150     KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
00151     {
00152       return new CustomFieldsWidget( ab, parent, name );
00153     }
00154 
00155     QString pageTitle() const { return i18n( "Custom Fields" ); }
00156     QString pageIdentifier() const { return "custom_fields"; }
00157 };
00158 
00159 void splitField( const QString&, QString&, QString&, QString& );
00160 
00161 #endif
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:42:46 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003