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