kaddressbook

customfieldswidget.h
1 /*
2  This file is part of KAddressbook.
3  Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #ifndef CUSTOMFIELDSWIDGET_H
25 #define CUSTOMFIELDSWIDGET_H
26 
27 #include <tdeabc/addressee.h>
28 #include <kdialogbase.h>
29 #include <tdelocale.h>
30 
31 #include <tqmap.h>
32 #include <tqpair.h>
33 #include <tqstringlist.h>
34 #include <tqvaluevector.h>
35 #include <tqwidget.h>
36 
37 #include "contacteditorwidget.h"
38 
39 class TQCheckBox;
40 class TQGridLayout;
41 class TQLabel;
42 class TQPushButton;
43 class TQVBoxLayout;
44 class TQWidget;
45 
46 class KComboBox;
47 class KLineEdit;
48 
49 typedef struct {
50  TQString mIdentifier;
51  TQString mTitle;
52  bool mGlobal;
53 
54  TQLabel *mLabel;
55  TQWidget *mWidget;
56  TQHBoxLayout *mLayout;
57 } FieldRecord;
58 
59 typedef TQValueList<FieldRecord> FieldRecordList;
60 
61 class AddFieldDialog : public KDialogBase
62 {
63  TQ_OBJECT
64 
65 
66  public:
67  AddFieldDialog( TQWidget *parent, const char *name = 0 );
68 
69  TQString title() const;
70  TQString identifier() const;
71  TQString type() const;
72  bool isGlobal() const;
73 
74  private slots:
75  void nameChanged( const TQString& );
76 
77  private:
78  KLineEdit *mTitle;
79  KComboBox *mType;
80  TQCheckBox *mGlobal;
81 
82  TQValueVector<TQString> mTypeList;
83  TQValueVector<TQString> mTypeName;
84 };
85 
86 class FieldWidget : public TQWidget
87 {
88  TQ_OBJECT
89 
90 
91  public:
92  FieldWidget( TQWidget *parent, const char *name = 0 );
93 
94  void addField( const TQString &identifier, const TQString &title,
95  const TQString &type, bool isGlobal );
96 
97  void removeField( const TQString &identifier );
98 
99  void loadContact( TDEABC::Addressee *addr );
100  void storeContact( TDEABC::Addressee *addr );
101  void setReadOnly( bool readOnly );
102 
103  FieldRecordList fields() const { return mFieldList; }
104 
105  void removeLocalFields();
106  void clearFields();
107 
108  signals:
109  void changed();
110 
111  private:
112  void recalculateLayout();
113 
114  TQVBoxLayout *mGlobalLayout;
115  TQVBoxLayout *mLocalLayout;
116  TQFrame *mSeparator;
117 
118  FieldRecordList mFieldList;
119 };
120 
121 class CustomFieldsWidget : public KAB::ContactEditorWidget
122 {
123  TQ_OBJECT
124 
125 
126  public:
127  CustomFieldsWidget( TDEABC::AddressBook *ab, TQWidget *parent, const char *name = 0 );
128 
129  void loadContact( TDEABC::Addressee *addr );
130  void storeContact( TDEABC::Addressee *addr );
131  void setReadOnly( bool readOnly );
132 
133  private slots:
134  void addField();
135  void removeField();
136 
137  private:
138  void initGUI();
139 
140  TQStringList marshallFields( bool ) const;
141 
142  TQPushButton *mAddButton;
143  TQPushButton *mRemoveButton;
144  TQGridLayout *mLayout;
145 
146  FieldWidget *mFieldWidget;
147 
148  TDEABC::Addressee mAddressee;
149 };
150 
151 class CustomFieldsWidgetFactory : public KAB::ContactEditorWidgetFactory
152 {
153  public:
154  KAB::ContactEditorWidget *createWidget( TDEABC::AddressBook *ab, TQWidget *parent, const char *name )
155  {
156  return new CustomFieldsWidget( ab, parent, name );
157  }
158 
159  TQString pageTitle() const { return i18n( "Custom Fields" ); }
160  TQString pageIdentifier() const { return "custom_fields"; }
161 };
162 
163 void splitField( const TQString&, TQString&, TQString&, TQString& );
164 
165 #endif