Diffstat (limited to 'kaddressbook/emaileditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/emaileditwidget.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/kaddressbook/emaileditwidget.cpp b/kaddressbook/emaileditwidget.cpp index e72face..09df47f 100644 --- a/kaddressbook/emaileditwidget.cpp +++ b/kaddressbook/emaileditwidget.cpp | |||
@@ -1,277 +1,279 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
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 <qcheckbox.h> | 24 | #include <qcheckbox.h> |
25 | #include <qlabel.h> | 25 | #include <qlabel.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | #include <qstring.h> | 28 | #include <qstring.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qtooltip.h> | 30 | #include <qtooltip.h> |
31 | #include <qlistbox.h> | 31 | #include <q3listbox.h> |
32 | //Added by qt3to4: | ||
33 | #include <Q3GridLayout> | ||
32 | 34 | ||
33 | #ifndef KAB_EMBEDDED | 35 | #ifndef KAB_EMBEDDED |
34 | #include <kaccelmanager.h> | 36 | #include <kaccelmanager.h> |
35 | #endif //KAB_EMBEDDED | 37 | #endif //KAB_EMBEDDED |
36 | #include <kconfig.h> | 38 | #include <kconfig.h> |
37 | #include <kcombobox.h> | 39 | #include <kcombobox.h> |
38 | #include <kdebug.h> | 40 | #include <kdebug.h> |
39 | #include <kglobal.h> | 41 | #include <kglobal.h> |
40 | #include <kdialog.h> | 42 | #include <kdialog.h> |
41 | #include <kiconloader.h> | 43 | #include <kiconloader.h> |
42 | #include <klineedit.h> | 44 | #include <klineedit.h> |
43 | #include <klocale.h> | 45 | #include <klocale.h> |
44 | #include <kmessagebox.h> | 46 | #include <kmessagebox.h> |
45 | 47 | ||
46 | #include "emaileditwidget.h" | 48 | #include "emaileditwidget.h" |
47 | 49 | ||
48 | EmailEditWidget::EmailEditWidget( QWidget *parent, const char *name ) | 50 | EmailEditWidget::EmailEditWidget( QWidget *parent, const char *name ) |
49 | : QWidget( parent, name ) | 51 | : QWidget( parent, name ) |
50 | { | 52 | { |
51 | QGridLayout *topLayout = new QGridLayout( this, 2, 2 ); | 53 | Q3GridLayout *topLayout = new Q3GridLayout( this, 2, 2 ); |
52 | topLayout->setSpacing( KDialog::spacingHint() ); | 54 | topLayout->setSpacing( KDialog::spacingHint() ); |
53 | QLabel* label = new QLabel( this ); | 55 | QLabel* label = new QLabel( this ); |
54 | 56 | ||
55 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "mail_send", KIcon::Desktop, 0) ); | 57 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "mail_send", KIcon::Desktop, 0) ); |
56 | 58 | ||
57 | topLayout->addWidget( label, 0, 0 ); | 59 | topLayout->addWidget( label, 0, 0 ); |
58 | label->setAlignment( AlignCenter ); | 60 | label->setAlignment( Qt::AlignCenter ); |
59 | QPushButton *editButton = new QPushButton( i18n( "Edit Email Addresses..." ), this); | 61 | QPushButton *editButton = new QPushButton( i18n( "Edit Email Addresses..." ), this); |
60 | topLayout->addWidget( editButton, 0, 1 ); | 62 | topLayout->addWidget( editButton, 0, 1 ); |
61 | label = new QLabel( i18n( "Email:" ), this ); | 63 | label = new QLabel( i18n( "Email:" ), this ); |
62 | topLayout->addWidget( label, 1, 0 ); | 64 | topLayout->addWidget( label, 1, 0 ); |
63 | 65 | ||
64 | mEmailEdit = new KLineEdit( this ); | 66 | mEmailEdit = new KLineEdit( this ); |
65 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), | 67 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), |
66 | SLOT( textChanged( const QString& ) ) ); | 68 | SLOT( textChanged( const QString& ) ) ); |
67 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), | 69 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), |
68 | SIGNAL( modified() ) ); | 70 | SIGNAL( modified() ) ); |
69 | label->setBuddy( mEmailEdit ); | 71 | label->setBuddy( mEmailEdit ); |
70 | topLayout->addWidget( mEmailEdit, 1, 1 ); | 72 | topLayout->addWidget( mEmailEdit, 1, 1 ); |
71 | 73 | ||
72 | 74 | ||
73 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); | 75 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); |
74 | 76 | ||
75 | topLayout->activate(); | 77 | topLayout->activate(); |
76 | } | 78 | } |
77 | 79 | ||
78 | EmailEditWidget::~EmailEditWidget() | 80 | EmailEditWidget::~EmailEditWidget() |
79 | { | 81 | { |
80 | } | 82 | } |
81 | 83 | ||
82 | void EmailEditWidget::setEmails( const QStringList &list ) | 84 | void EmailEditWidget::setEmails( const QStringList &list ) |
83 | { | 85 | { |
84 | mEmailList = list; | 86 | mEmailList = list; |
85 | 87 | ||
86 | bool blocked = mEmailEdit->signalsBlocked(); | 88 | bool blocked = mEmailEdit->signalsBlocked(); |
87 | mEmailEdit->blockSignals( true ); | 89 | mEmailEdit->blockSignals( true ); |
88 | if ( list.count() > 0 ) | 90 | if ( list.count() > 0 ) |
89 | mEmailEdit->setText( list[ 0 ] ); | 91 | mEmailEdit->setText( list[ 0 ] ); |
90 | else | 92 | else |
91 | mEmailEdit->setText( "" ); | 93 | mEmailEdit->setText( "" ); |
92 | mEmailEdit->blockSignals( blocked ); | 94 | mEmailEdit->blockSignals( blocked ); |
93 | } | 95 | } |
94 | 96 | ||
95 | QStringList EmailEditWidget::emails() | 97 | QStringList EmailEditWidget::emails() |
96 | { | 98 | { |
97 | if ( mEmailEdit->text().isEmpty() ) { | 99 | if ( mEmailEdit->text().isEmpty() ) { |
98 | if ( mEmailList.count() > 0 ) | 100 | if ( mEmailList.count() > 0 ) |
99 | mEmailList.remove( mEmailList.begin() ); | 101 | mEmailList.remove( mEmailList.begin() ); |
100 | } else { | 102 | } else { |
101 | if ( mEmailList.count() > 0 ) | 103 | if ( mEmailList.count() > 0 ) |
102 | mEmailList.remove( mEmailList.begin() ); | 104 | mEmailList.remove( mEmailList.begin() ); |
103 | 105 | ||
104 | mEmailList.prepend( mEmailEdit->text() ); | 106 | mEmailList.prepend( mEmailEdit->text() ); |
105 | } | 107 | } |
106 | 108 | ||
107 | return mEmailList; | 109 | return mEmailList; |
108 | } | 110 | } |
109 | 111 | ||
110 | void EmailEditWidget::edit() | 112 | void EmailEditWidget::edit() |
111 | { | 113 | { |
112 | EmailEditDialog dlg( mEmailList, this ); | 114 | EmailEditDialog dlg( mEmailList, this ); |
113 | 115 | ||
114 | if ( dlg.exec() ) { | 116 | if ( dlg.exec() ) { |
115 | if ( dlg.changed() ) { | 117 | if ( dlg.changed() ) { |
116 | mEmailList = dlg.emails(); | 118 | mEmailList = dlg.emails(); |
117 | mEmailEdit->setText( mEmailList[ 0 ] ); | 119 | mEmailEdit->setText( mEmailList[ 0 ] ); |
118 | emit modified(); | 120 | emit modified(); |
119 | } | 121 | } |
120 | } | 122 | } |
121 | } | 123 | } |
122 | 124 | ||
123 | void EmailEditWidget::textChanged( const QString &text ) | 125 | void EmailEditWidget::textChanged( const QString &text ) |
124 | { | 126 | { |
125 | if ( mEmailList.count() > 0 ) | 127 | if ( mEmailList.count() > 0 ) |
126 | mEmailList.remove( mEmailList.begin() ); | 128 | mEmailList.remove( mEmailList.begin() ); |
127 | 129 | ||
128 | mEmailList.prepend( text ); | 130 | mEmailList.prepend( text ); |
129 | } | 131 | } |
130 | 132 | ||
131 | 133 | ||
132 | EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent, | 134 | EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent, |
133 | const char *name ) | 135 | const char *name ) |
134 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Email Addresses" ), | 136 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Email Addresses" ), |
135 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 137 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
136 | parent, name, true ) | 138 | parent, name, true ) |
137 | { | 139 | { |
138 | QWidget *page = plainPage(); | 140 | QWidget *page = plainPage(); |
139 | 141 | ||
140 | QGridLayout *topLayout = new QGridLayout( page, 4, 3 ); | 142 | Q3GridLayout *topLayout = new Q3GridLayout( page, 4, 3 ); |
141 | 143 | ||
142 | QLabel *label = new QLabel( i18n( "Email address:" ), page ); | 144 | QLabel *label = new QLabel( i18n( "Email address:" ), page ); |
143 | topLayout->addWidget( label, 0, 0 ); | 145 | topLayout->addWidget( label, 0, 0 ); |
144 | 146 | ||
145 | mEmailEdit = new KLineEdit( page ); | 147 | mEmailEdit = new KLineEdit( page ); |
146 | label->setBuddy( mEmailEdit ); | 148 | label->setBuddy( mEmailEdit ); |
147 | topLayout->addWidget( mEmailEdit, 0, 1 ); | 149 | topLayout->addWidget( mEmailEdit, 0, 1 ); |
148 | connect( mEmailEdit, SIGNAL( returnPressed() ), SLOT( add() ) ); | 150 | connect( mEmailEdit, SIGNAL( returnPressed() ), SLOT( add() ) ); |
149 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), | 151 | connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ), |
150 | SLOT( emailChanged() ) ); | 152 | SLOT( emailChanged() ) ); |
151 | 153 | ||
152 | mAddButton = new QPushButton( i18n( "Add" ), page ); | 154 | mAddButton = new QPushButton( i18n( "Add" ), page ); |
153 | mAddButton->setEnabled( false ); | 155 | mAddButton->setEnabled( false ); |
154 | connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) ); | 156 | connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) ); |
155 | topLayout->addWidget( mAddButton, 0, 2 ); | 157 | topLayout->addWidget( mAddButton, 0, 2 ); |
156 | 158 | ||
157 | mEmailListBox = new QListBox( page ); | 159 | mEmailListBox = new Q3ListBox( page ); |
158 | 160 | ||
159 | // Make sure there is room for the scrollbar | 161 | // Make sure there is room for the scrollbar |
160 | mEmailListBox->setMinimumHeight( mEmailListBox->sizeHint().height() + 30 ); | 162 | mEmailListBox->setMinimumHeight( mEmailListBox->sizeHint().height() + 30 ); |
161 | connect( mEmailListBox, SIGNAL( highlighted( int ) ), | 163 | connect( mEmailListBox, SIGNAL( highlighted( int ) ), |
162 | SLOT( selectionChanged( int ) ) ); | 164 | SLOT( selectionChanged( int ) ) ); |
163 | topLayout->addMultiCellWidget( mEmailListBox, 1, 3, 0, 1 ); | 165 | topLayout->addMultiCellWidget( mEmailListBox, 1, 3, 0, 1 ); |
164 | 166 | ||
165 | mEditButton = new QPushButton( i18n( "Change" ), page ); | 167 | mEditButton = new QPushButton( i18n( "Change" ), page ); |
166 | connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) ); | 168 | connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) ); |
167 | topLayout->addWidget( mEditButton, 1, 2 ); | 169 | topLayout->addWidget( mEditButton, 1, 2 ); |
168 | 170 | ||
169 | mRemoveButton = new QPushButton( i18n( "Remove" ), page ); | 171 | mRemoveButton = new QPushButton( i18n( "Remove" ), page ); |
170 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) ); | 172 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) ); |
171 | topLayout->addWidget( mRemoveButton, 2, 2 ); | 173 | topLayout->addWidget( mRemoveButton, 2, 2 ); |
172 | 174 | ||
173 | mStandardButton = new QPushButton( i18n( "Set Standard" ), page ); | 175 | mStandardButton = new QPushButton( i18n( "Set Standard" ), page ); |
174 | connect( mStandardButton, SIGNAL( clicked() ), SLOT( standard() ) ); | 176 | connect( mStandardButton, SIGNAL( clicked() ), SLOT( standard() ) ); |
175 | topLayout->addWidget( mStandardButton, 3, 2 ); | 177 | topLayout->addWidget( mStandardButton, 3, 2 ); |
176 | 178 | ||
177 | topLayout->activate(); | 179 | topLayout->activate(); |
178 | QStringList items = list; | 180 | QStringList items = list; |
179 | 181 | ||
180 | qDebug("EmailEditDialog::EmailEditDialog has to be changed (lowPrio)"); | 182 | qDebug("EmailEditDialog::EmailEditDialog has to be changed (lowPrio)"); |
181 | //US must be fixed !!! | 183 | //US must be fixed !!! |
182 | /* | 184 | /* |
183 | if ( items.remove( "" ) > 0 ) | 185 | if ( items.remove( "" ) > 0 ) |
184 | mChanged = true; | 186 | mChanged = true; |
185 | else | 187 | else |
186 | mChanged = false; | 188 | mChanged = false; |
187 | */ | 189 | */ |
188 | 190 | ||
189 | mEmailListBox->insertStringList( items ); | 191 | mEmailListBox->insertStringList( items ); |
190 | // set default state | 192 | // set default state |
191 | selectionChanged( -1 ); | 193 | selectionChanged( -1 ); |
192 | mEmailEdit->setFocus(); | 194 | mEmailEdit->setFocus(); |
193 | 195 | ||
194 | #ifndef KAB_EMBEDDED | 196 | #ifndef KAB_EMBEDDED |
195 | KAcceleratorManager::manage( this ); | 197 | KAcceleratorManager::manage( this ); |
196 | #else //KAB_EMBEDDED | 198 | #else //KAB_EMBEDDED |
197 | //US qDebug("EmailEditDialog::EmailEditDialog has to be changed"); | 199 | //US qDebug("EmailEditDialog::EmailEditDialog has to be changed"); |
198 | #endif //KAB_EMBEDDED | 200 | #endif //KAB_EMBEDDED |
199 | 201 | ||
200 | } | 202 | } |
201 | 203 | ||
202 | EmailEditDialog::~EmailEditDialog() | 204 | EmailEditDialog::~EmailEditDialog() |
203 | { | 205 | { |
204 | } | 206 | } |
205 | 207 | ||
206 | QStringList EmailEditDialog::emails() const | 208 | QStringList EmailEditDialog::emails() const |
207 | { | 209 | { |
208 | QStringList emails; | 210 | QStringList emails; |
209 | 211 | ||
210 | for ( uint i = 0; i < mEmailListBox->count(); ++i ) | 212 | for ( uint i = 0; i < mEmailListBox->count(); ++i ) |
211 | emails << mEmailListBox->text( i ); | 213 | emails << mEmailListBox->text( i ); |
212 | 214 | ||
213 | return emails; | 215 | return emails; |
214 | } | 216 | } |
215 | 217 | ||
216 | void EmailEditDialog::add() | 218 | void EmailEditDialog::add() |
217 | { | 219 | { |
218 | mEmailListBox->insertItem( mEmailEdit->text() ); | 220 | mEmailListBox->insertItem( mEmailEdit->text() ); |
219 | 221 | ||
220 | mEmailEdit->clear(); | 222 | mEmailEdit->clear(); |
221 | mEmailEdit->setFocus(); | 223 | mEmailEdit->setFocus(); |
222 | 224 | ||
223 | mChanged = true; | 225 | mChanged = true; |
224 | } | 226 | } |
225 | 227 | ||
226 | void EmailEditDialog::edit() | 228 | void EmailEditDialog::edit() |
227 | { | 229 | { |
228 | mEmailEdit->setText( mEmailListBox->currentText() ); | 230 | mEmailEdit->setText( mEmailListBox->currentText() ); |
229 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); | 231 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); |
230 | mEmailEdit->setFocus(); | 232 | mEmailEdit->setFocus(); |
231 | } | 233 | } |
232 | 234 | ||
233 | void EmailEditDialog::remove() | 235 | void EmailEditDialog::remove() |
234 | { | 236 | { |
235 | QString address = mEmailListBox->currentText(); | 237 | QString address = mEmailListBox->currentText(); |
236 | 238 | ||
237 | QString text = i18n( "<qt>Are you sure that you want to remove the email address <b>%1</b>?</qt>" ).arg( address ); | 239 | QString text = i18n( "<qt>Are you sure that you want to remove the email address <b>%1</b>?</qt>" ).arg( address ); |
238 | QString caption = i18n( "Confirm Remove" ); | 240 | QString caption = i18n( "Confirm Remove" ); |
239 | 241 | ||
240 | if ( KMessageBox::questionYesNo( this, text, caption ) == KMessageBox::Yes ) { | 242 | if ( KMessageBox::questionYesNo( this, text, caption ) == KMessageBox::Yes ) { |
241 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); | 243 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); |
242 | mChanged = true; | 244 | mChanged = true; |
243 | } | 245 | } |
244 | } | 246 | } |
245 | 247 | ||
246 | bool EmailEditDialog::changed() const | 248 | bool EmailEditDialog::changed() const |
247 | { | 249 | { |
248 | return mChanged; | 250 | return mChanged; |
249 | } | 251 | } |
250 | 252 | ||
251 | void EmailEditDialog::standard() | 253 | void EmailEditDialog::standard() |
252 | { | 254 | { |
253 | QString text = mEmailListBox->currentText(); | 255 | QString text = mEmailListBox->currentText(); |
254 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); | 256 | mEmailListBox->removeItem( mEmailListBox->currentItem() ); |
255 | mEmailListBox->insertItem( text, 0 ); | 257 | mEmailListBox->insertItem( text, 0 ); |
256 | mEmailListBox->setSelected( 0, true ); | 258 | mEmailListBox->setSelected( 0, true ); |
257 | 259 | ||
258 | mChanged = true; | 260 | mChanged = true; |
259 | } | 261 | } |
260 | 262 | ||
261 | void EmailEditDialog::selectionChanged( int index ) | 263 | void EmailEditDialog::selectionChanged( int index ) |
262 | { | 264 | { |
263 | bool value = ( index >= 0 ); // An item is selected | 265 | bool value = ( index >= 0 ); // An item is selected |
264 | 266 | ||
265 | mRemoveButton->setEnabled( value ); | 267 | mRemoveButton->setEnabled( value ); |
266 | mEditButton->setEnabled( value ); | 268 | mEditButton->setEnabled( value ); |
267 | mStandardButton->setEnabled( value ); | 269 | mStandardButton->setEnabled( value ); |
268 | } | 270 | } |
269 | 271 | ||
270 | void EmailEditDialog::emailChanged() | 272 | void EmailEditDialog::emailChanged() |
271 | { | 273 | { |
272 | mAddButton->setEnabled( !mEmailEdit->text().isEmpty() ); | 274 | mAddButton->setEnabled( !mEmailEdit->text().isEmpty() ); |
273 | } | 275 | } |
274 | 276 | ||
275 | #ifndef KAB_EMBEDDED | 277 | #ifndef KAB_EMBEDDED_ |
276 | #include "emaileditwidget.moc" | 278 | #include "moc_emaileditwidget.cpp" |
277 | #endif //KAB_EMBEDDED | 279 | #endif //KAB_EMBEDDED |