summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kcmconfigs/addresseewidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kcmconfigs/addresseewidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kcmconfigs/addresseewidget.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/kaddressbook/kcmconfigs/addresseewidget.cpp b/kaddressbook/kcmconfigs/addresseewidget.cpp
index 168d39e..8055085 100644
--- a/kaddressbook/kcmconfigs/addresseewidget.cpp
+++ b/kaddressbook/kcmconfigs/addresseewidget.cpp
@@ -1,238 +1,242 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qgroupbox.h> 24#include <q3groupbox.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qlistbox.h> 27#include <q3listbox.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qapplication.h> 29#include <qapplication.h>
30#include <QDesktopWidget>
31//Added by qt3to4:
32#include <Q3GridLayout>
33#include <Q3HBoxLayout>
30 34
31#include <kbuttonbox.h> 35#include <kbuttonbox.h>
32#include <kcombobox.h> 36#include <kcombobox.h>
33#include <kconfig.h> 37#include <kconfig.h>
34#include <kdialog.h> 38#include <kdialog.h>
35#include <klocale.h> 39#include <klocale.h>
36#include <kglobal.h> 40#include <kglobal.h>
37#include <klineedit.h> 41#include <klineedit.h>
38#include <kstandarddirs.h> 42#include <kstandarddirs.h>
39 43
40#include "addresseewidget.h" 44#include "addresseewidget.h"
41 45
42NamePartWidget::NamePartWidget( const QString &title, QWidget *parent, 46NamePartWidget::NamePartWidget( const QString &title, QWidget *parent,
43 const char *name ) 47 const char *name )
44 : QWidget( parent, name ) 48 : QWidget( parent, name )
45{ 49{
46 if (KGlobal::getOrientation() == KGlobal::Portrait) 50 if (KGlobal::getOrientation() == KGlobal::Portrait)
47 { 51 {
48 QGridLayout* layout = new QGridLayout( this, 1, 1, KDialog::marginHintSmall(), 52 Q3GridLayout* layout = new Q3GridLayout( this, 1, 1, KDialog::marginHintSmall(),
49 KDialog::spacingHintSmall() ); 53 KDialog::spacingHintSmall() );
50 54
51 QLabel *label = new QLabel( i18n( title ), this ); 55 QLabel *label = new QLabel( i18n( title ), this );
52 layout->addWidget( label, 0, 1 ); 56 layout->addWidget( label, 0, 1 );
53 57
54 mBox = new QListBox( this ); 58 mBox = new Q3ListBox( this );
55 mBox->setMaximumSize(70, 70); 59 mBox->setMaximumSize(70, 70);
56 layout->addMultiCellWidget( mBox, 0, 1, 0, 0 ); 60 layout->addMultiCellWidget( mBox, 0, 1, 0, 0 );
57 61
58 KButtonBox *bbox = new KButtonBox( this, Qt::Vertical ); 62 KButtonBox *bbox = new KButtonBox( this, Qt::Vertical );
59 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) ); 63 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
60 mRemoveButton = bbox->addButton( i18n( "Rem" ), this, SLOT( remove() ) ); 64 mRemoveButton = bbox->addButton( i18n( "Rem" ), this, SLOT( remove() ) );
61 bbox->layout(); 65 bbox->layout();
62 layout->addMultiCellWidget( bbox, 0, 1, 2,2); 66 layout->addMultiCellWidget( bbox, 0, 1, 2,2);
63 67
64 mEdit = new KLineEdit( this ); 68 mEdit = new KLineEdit( this );
65 layout->addWidget( mEdit, 1, 1 ); 69 layout->addWidget( mEdit, 1, 1 );
66 //mEdit->setMinimumWidth(50); 70 //mEdit->setMinimumWidth(50);
67 71
68// layout->addWidget( group ); 72// layout->addWidget( group );
69 73
70 } 74 }
71 else 75 else
72 { 76 {
73 QHBoxLayout *layout = new QHBoxLayout( this ); 77 Q3HBoxLayout *layout = new Q3HBoxLayout( this );
74 78
75 QGroupBox *group = new QGroupBox( 0, Qt::Vertical, title, this ); 79 Q3GroupBox *group = new Q3GroupBox( 0, Qt::Vertical, title, this );
76 QGridLayout *groupLayout = new QGridLayout( group->layout(), 2, 2, 80 Q3GridLayout *groupLayout = new Q3GridLayout( group->layout(), 2, 2,
77 KDialog::spacingHint() ); 81 KDialog::spacingHint() );
78 82
79 mBox = new QListBox( group ); 83 mBox = new Q3ListBox( group );
80 84
81 groupLayout->addWidget( mBox, 0, 0 ); 85 groupLayout->addWidget( mBox, 0, 0 );
82 86
83 KButtonBox *bbox = new KButtonBox( group, Qt::Vertical ); 87 KButtonBox *bbox = new KButtonBox( group, Qt::Vertical );
84 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) ); 88 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
85 mRemoveButton = bbox->addButton( i18n( "Remove" ), this, SLOT( remove() ) ); 89 mRemoveButton = bbox->addButton( i18n( "Remove" ), this, SLOT( remove() ) );
86 bbox->layout(); 90 bbox->layout();
87 groupLayout->addWidget( bbox, 0, 1 ); 91 groupLayout->addWidget( bbox, 0, 1 );
88 92
89 mEdit = new KLineEdit( group ); 93 mEdit = new KLineEdit( group );
90 groupLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 ); 94 groupLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 );
91 95
92 layout->addWidget( group ); 96 layout->addWidget( group );
93 97
94 } 98 }
95 99
96 mAddButton->setEnabled( false ); 100 mAddButton->setEnabled( false );
97 mRemoveButton->setEnabled( false ); 101 mRemoveButton->setEnabled( false );
98 102
99 103
100 connect( mBox, SIGNAL( selectionChanged( QListBoxItem* ) ), 104 connect( mBox, SIGNAL( selectionChanged( Q3ListBoxItem* ) ),
101 SLOT( selectionChanged( QListBoxItem* ) ) ); 105 SLOT( selectionChanged( Q3ListBoxItem* ) ) );
102 connect( mEdit, SIGNAL( textChanged( const QString& ) ), 106 connect( mEdit, SIGNAL( textChanged( const QString& ) ),
103 SLOT( textChanged( const QString& ) ) ); 107 SLOT( textChanged( const QString& ) ) );
104 connect( mEdit, SIGNAL( returnPressed() ), SLOT( add() ) ); 108 connect( mEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
105 109
106} 110}
107 111
108NamePartWidget::~NamePartWidget() 112NamePartWidget::~NamePartWidget()
109{ 113{
110} 114}
111 115
112void NamePartWidget::setNameParts( const QStringList &list ) 116void NamePartWidget::setNameParts( const QStringList &list )
113{ 117{
114 mBox->clear(); 118 mBox->clear();
115 mBox->insertStringList( list ); 119 mBox->insertStringList( list );
116} 120}
117 121
118QStringList NamePartWidget::nameParts() const 122QStringList NamePartWidget::nameParts() const
119{ 123{
120 QStringList parts; 124 QStringList parts;
121 for ( uint i = 0; i < mBox->count(); ++i ) 125 for ( uint i = 0; i < mBox->count(); ++i )
122 parts.append( mBox->text( i ) ); 126 parts.append( mBox->text( i ) );
123 127
124 return parts; 128 return parts;
125} 129}
126 130
127void NamePartWidget::add() 131void NamePartWidget::add()
128{ 132{
129 if ( !mEdit->text().isEmpty() ) { 133 if ( !mEdit->text().isEmpty() ) {
130 mBox->insertItem( mEdit->text() ); 134 mBox->insertItem( mEdit->text() );
131 emit modified(); 135 emit modified();
132 } 136 }
133 137
134 mEdit->setText( "" ); 138 mEdit->setText( "" );
135} 139}
136 140
137void NamePartWidget::remove() 141void NamePartWidget::remove()
138{ 142{
139 mBox->removeItem( mBox->currentItem() ); 143 mBox->removeItem( mBox->currentItem() );
140 if ( mBox->count() == 0 ) 144 if ( mBox->count() == 0 )
141 selectionChanged( 0 ); 145 selectionChanged( 0 );
142 146
143 emit modified(); 147 emit modified();
144} 148}
145 149
146void NamePartWidget::selectionChanged( QListBoxItem *item ) 150void NamePartWidget::selectionChanged( Q3ListBoxItem *item )
147{ 151{
148 mRemoveButton->setEnabled( item != 0 ); 152 mRemoveButton->setEnabled( item != 0 );
149} 153}
150 154
151void NamePartWidget::textChanged( const QString& text ) 155void NamePartWidget::textChanged( const QString& text )
152{ 156{
153 mAddButton->setEnabled( !text.isEmpty() ); 157 mAddButton->setEnabled( !text.isEmpty() );
154} 158}
155 159
156 160
157AddresseeWidget::AddresseeWidget( QWidget *parent, const char *name ) 161AddresseeWidget::AddresseeWidget( QWidget *parent, const char *name )
158 : QWidget( parent, name ) 162 : QWidget( parent, name )
159{ 163{
160 QGridLayout *layout; 164 Q3GridLayout *layout;
161 165
162 mPrefix = new NamePartWidget( i18n( "Prefixes" ), this ); 166 mPrefix = new NamePartWidget( i18n( "Prefixes" ), this );
163 mInclusion = new NamePartWidget( i18n( "Inclusions" ), this ); 167 mInclusion = new NamePartWidget( i18n( "Inclusions" ), this );
164 mSuffix = new NamePartWidget( i18n( "Suffixes" ), this ); 168 mSuffix = new NamePartWidget( i18n( "Suffixes" ), this );
165 QString dfn; 169 QString dfn;
166 if (QApplication::desktop()->width() > 320 ) 170 if (QApplication::desktop()->width() > 320 )
167 dfn = i18n( "Default formatted name:" ); 171 dfn = i18n( "Default formatted name:" );
168 else 172 else
169 dfn = i18n( "Def. formatted name:" ); 173 dfn = i18n( "Def. formatted name:" );
170 174
171 QLabel *label = new QLabel( dfn, this ); 175 QLabel *label = new QLabel( dfn, this );
172 176
173 mFormattedNameCombo = new KComboBox( this ); 177 mFormattedNameCombo = new KComboBox( this );
174 mFormattedNameCombo->insertItem( i18n( "Empty" ) ); 178 mFormattedNameCombo->insertItem( i18n( "Empty" ) );
175 mFormattedNameCombo->insertItem( i18n( "Simple Name" ) ); 179 mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
176 mFormattedNameCombo->insertItem( i18n( "Full Name" ) ); 180 mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
177 mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) ); 181 mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
178 182
179 if (KGlobal::getOrientation() == KGlobal::Portrait) 183 if (KGlobal::getOrientation() == KGlobal::Portrait)
180 { 184 {
181 layout = new QGridLayout( this, 4, 2, KDialog::marginHintSmall(), 185 layout = new Q3GridLayout( this, 4, 2, KDialog::marginHintSmall(),
182 KDialog::spacingHintSmall() ); 186 KDialog::spacingHintSmall() );
183 187
184 layout->addMultiCellWidget( mPrefix, 0, 0, 0, 1 ); 188 layout->addMultiCellWidget( mPrefix, 0, 0, 0, 1 );
185 layout->addMultiCellWidget( mInclusion, 1, 1, 0, 1 ); 189 layout->addMultiCellWidget( mInclusion, 1, 1, 0, 1 );
186 layout->addMultiCellWidget( mSuffix, 2, 2, 0, 1 ); 190 layout->addMultiCellWidget( mSuffix, 2, 2, 0, 1 );
187 layout->addWidget( label, 3, 0 ); 191 layout->addWidget( label, 3, 0 );
188 layout->addWidget( mFormattedNameCombo, 3, 1 ); 192 layout->addWidget( mFormattedNameCombo, 3, 1 );
189 193
190 } 194 }
191 else 195 else
192 { 196 {
193 layout = new QGridLayout( this, 2, 3, KDialog::marginHint(), 197 layout = new Q3GridLayout( this, 2, 3, KDialog::marginHint(),
194 KDialog::spacingHint() ); 198 KDialog::spacingHint() );
195 199
196 layout->addWidget( mPrefix, 0, 0 ); 200 layout->addWidget( mPrefix, 0, 0 );
197 layout->addWidget( mInclusion, 0, 1 ); 201 layout->addWidget( mInclusion, 0, 1 );
198 layout->addWidget( mSuffix, 0, 2 ); 202 layout->addWidget( mSuffix, 0, 2 );
199 layout->addWidget( label, 1, 0 ); 203 layout->addWidget( label, 1, 0 );
200 layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 ); 204 layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
201 } 205 }
202 206
203 connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) ); 207 connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) );
204 connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) ); 208 connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) );
205 connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) ); 209 connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) );
206 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SIGNAL( modified() ) ); 210 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SIGNAL( modified() ) );
207} 211}
208 212
209AddresseeWidget::~AddresseeWidget() 213AddresseeWidget::~AddresseeWidget()
210{ 214{
211} 215}
212 216
213void AddresseeWidget::restoreSettings() 217void AddresseeWidget::restoreSettings()
214{ 218{
215 KConfig config( locateLocal("config", "kabcrc") ); 219 KConfig config( locateLocal("config", "kabcrc") );
216 config.setGroup( "General" ); 220 config.setGroup( "General" );
217 221
218 mPrefix->setNameParts( config.readListEntry( "Prefixes" ) ); 222 mPrefix->setNameParts( config.readListEntry( "Prefixes" ) );
219 mInclusion->setNameParts( config.readListEntry( "Inclusions" ) ); 223 mInclusion->setNameParts( config.readListEntry( "Inclusions" ) );
220 mSuffix->setNameParts( config.readListEntry( "Suffixes" ) ); 224 mSuffix->setNameParts( config.readListEntry( "Suffixes" ) );
221 mFormattedNameCombo->setCurrentItem( config.readNumEntry( "FormattedNameType", 1 ) ); 225 mFormattedNameCombo->setCurrentItem( config.readNumEntry( "FormattedNameType", 1 ) );
222} 226}
223 227
224void AddresseeWidget::saveSettings() 228void AddresseeWidget::saveSettings()
225{ 229{
226 qDebug("AddresseeWidget::saveSettings() "); 230 qDebug("AddresseeWidget::saveSettings() ");
227 KConfig config( locateLocal("config","kabcrc") ); 231 KConfig config( locateLocal("config","kabcrc") );
228 config.setGroup( "General" ); 232 config.setGroup( "General" );
229 233
230 config.writeEntry( "Prefixes", mPrefix->nameParts() ); 234 config.writeEntry( "Prefixes", mPrefix->nameParts() );
231 config.writeEntry( "Inclusions", mInclusion->nameParts() ); 235 config.writeEntry( "Inclusions", mInclusion->nameParts() );
232 config.writeEntry( "Suffixes", mSuffix->nameParts() ); 236 config.writeEntry( "Suffixes", mSuffix->nameParts() );
233 config.writeEntry( "FormattedNameType", mFormattedNameCombo->currentItem() ); 237 config.writeEntry( "FormattedNameType", mFormattedNameCombo->currentItem() );
234} 238}
235 239
236#ifndef KAB_EMBEDDED 240#ifndef KAB_EMBEDDED_
237#include "addresseewidget.moc" 241#include "moc_addresseewidget.cpp"
238#endif //KAB_EMBEDDED 242#endif //KAB_EMBEDDED