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