kaddressbook

advancedcustomfields.cpp
1 /*
2  This file is part of KAddressbook.
3 
4  Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of TQt, and distribute the resulting executable,
23  without including the source code for TQt in the source distribution.
24 */
25 
26 #include <tqcheckbox.h>
27 #include <tqcombobox.h>
28 #include <tqdatetimeedit.h>
29 #include <tqlayout.h>
30 #include <tqobjectlist.h>
31 #include <tqspinbox.h>
32 #include <tqregexp.h>
33 #include <tqtextedit.h>
34 #include <tqwidgetfactory.h>
35 
36 #include <kdatepicker.h>
37 #include <kdatetimewidget.h>
38 #include <kdialog.h>
39 #include <klineedit.h>
40 #include <kstandarddirs.h>
41 
42 #include <libtdepim/designerfields.h>
43 
44 #include "customfieldswidget.h"
45 
46 #include "advancedcustomfields.h"
47 
48 class KABCStorage : public KPIM::DesignerFields::Storage
49 {
50  public:
51  KABCStorage( TDEABC::Addressee *a, const TQString &ns )
52  : mAddressee( a ), mNs( ns )
53  {
54  }
55 
56  TQStringList keys()
57  {
58  TQStringList keys;
59 
60  const TQStringList customs = mAddressee->customs();
61  TQStringList::ConstIterator it;
62  for ( it = customs.begin(); it != customs.end(); ++it ) {
63  TQString app, name, value;
64  splitField( *it, app, name, value );
65  if ( app == mNs ) keys.append( name );
66  }
67 
68  return keys;
69  }
70 
71  TQString read( const TQString &key )
72  {
73  return mAddressee->custom( mNs, key );
74  }
75 
76  void write( const TQString &key, const TQString &value )
77  {
78  mAddressee->insertCustom( mNs, key, value );
79  }
80 
81  private:
82  TDEABC::Addressee *mAddressee;
83  TQString mNs;
84 };
85 
86 
87 AdvancedCustomFields::AdvancedCustomFields( const TQString &uiFile, TDEABC::AddressBook *ab,
88  TQWidget *parent, const char *name )
89  : KAB::ContactEditorWidget( ab, parent, name )
90 {
91  initGUI( uiFile );
92 }
93 
94 void AdvancedCustomFields::loadContact( TDEABC::Addressee *addr )
95 {
96  TQString ns;
97  if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
98  TQRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
99  ns = "KADDRESSBOOK";
100  } else {
101  ns = mFields->identifier();
102  }
103 
104  KABCStorage storage( addr, ns );
105  mFields->load( &storage );
106 }
107 
108 void AdvancedCustomFields::storeContact( TDEABC::Addressee *addr )
109 {
110  TQString ns;
111  if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
112  TQRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
113  ns = "KADDRESSBOOK";
114  } else {
115  ns = mFields->identifier();
116  }
117 
118  KABCStorage storage( addr, ns );
119  mFields->save( &storage );
120 }
121 
122 void AdvancedCustomFields::setReadOnly( bool readOnly )
123 {
124  mFields->setReadOnly( readOnly );
125 }
126 
127 void AdvancedCustomFields::initGUI( const TQString &uiFile )
128 {
129  TQVBoxLayout *layout = new TQVBoxLayout( this, KDialog::marginHint(),
130  KDialog::spacingHint() );
131 
132  mFields = new KPIM::DesignerFields( uiFile, this );
133  layout->addWidget( mFields );
134 
135  connect( mFields, TQ_SIGNAL( modified() ), TQ_SLOT( setModified() ) );
136 }
137 
138 TQString AdvancedCustomFields::pageIdentifier() const
139 {
140  return mFields->identifier();
141 }
142 
143 TQString AdvancedCustomFields::pageTitle() const
144 {
145  return mFields->title();
146 }
147 
148 #include "advancedcustomfields.moc"