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