Diffstat (limited to 'kaddressbook/emaileditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/emaileditwidget.cpp | 2 |
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 | |||
@@ -96,180 +96,182 @@ QStringList 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 | ||
110 | void EmailEditWidget::edit() | 110 | void 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 | ||
123 | void EmailEditWidget::textChanged( const QString &text ) | 123 | void 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 | ||
132 | EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent, | 132 | EmailEditDialog::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 | ||
180 | qDebug("EmailEditDialog::EmailEditDialog has to be changed (lowPrio)"); | 180 | qDebug("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 | ||
201 | EmailEditDialog::~EmailEditDialog() | 202 | EmailEditDialog::~EmailEditDialog() |
202 | { | 203 | { |
203 | } | 204 | } |
204 | 205 | ||
205 | QStringList EmailEditDialog::emails() const | 206 | QStringList 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 | ||
215 | void EmailEditDialog::add() | 216 | void 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 | ||
225 | void EmailEditDialog::edit() | 226 | void 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 | ||
231 | void EmailEditDialog::remove() | 233 | void 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 | ||
244 | bool EmailEditDialog::changed() const | 246 | bool EmailEditDialog::changed() const |
245 | { | 247 | { |
246 | return mChanged; | 248 | return mChanged; |
247 | } | 249 | } |
248 | 250 | ||
249 | void EmailEditDialog::standard() | 251 | void 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 | ||
259 | void EmailEditDialog::selectionChanged( int index ) | 261 | void 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 | ||
268 | void EmailEditDialog::emailChanged() | 270 | void 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 |