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 /korganizer/koeditordetails.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'korganizer/koeditordetails.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditordetails.cpp | 398 |
1 files changed, 398 insertions, 0 deletions
diff --git a/korganizer/koeditordetails.cpp b/korganizer/koeditordetails.cpp new file mode 100644 index 0000000..7c4c382 --- a/dev/null +++ b/korganizer/koeditordetails.cpp | |||
@@ -0,0 +1,398 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@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 thse 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 <qtooltip.h> | ||
25 | #include <qfiledialog.h> | ||
26 | #include <qlayout.h> | ||
27 | #include <qvbox.h> | ||
28 | #include <qbuttongroup.h> | ||
29 | #include <qvgroupbox.h> | ||
30 | #include <qwidgetstack.h> | ||
31 | #include <qdatetime.h> | ||
32 | #include <qapp.h> | ||
33 | |||
34 | #include <klocale.h> | ||
35 | #include <kglobal.h> | ||
36 | #include <kiconloader.h> | ||
37 | #include <kstandarddirs.h> | ||
38 | #include <kmessagebox.h> | ||
39 | #ifndef KORG_NOKABC | ||
40 | #include <kabc/addresseedialog.h> | ||
41 | #endif | ||
42 | |||
43 | #include <libkcal/incidence.h> | ||
44 | |||
45 | #include "koprefs.h" | ||
46 | |||
47 | #include "koeditordetails.h" | ||
48 | #include "koeditordetails.moc" | ||
49 | |||
50 | template <> | ||
51 | CustomListViewItem<class Attendee *>::~CustomListViewItem() | ||
52 | { | ||
53 | delete mData; | ||
54 | } | ||
55 | |||
56 | template <> | ||
57 | void CustomListViewItem<class Attendee *>::updateItem() | ||
58 | { | ||
59 | setText(0,mData->name()); | ||
60 | setText(1,mData->email()); | ||
61 | setText(2,mData->roleStr()); | ||
62 | setText(3,mData->statusStr()); | ||
63 | if (mData->RSVP() && !mData->email().isEmpty()) | ||
64 | setPixmap(4,SmallIcon("mailappt")); | ||
65 | else | ||
66 | setPixmap(4,SmallIcon("nomailappt")); | ||
67 | } | ||
68 | |||
69 | |||
70 | KOEditorDetails::KOEditorDetails (int spacing,QWidget* parent,const char* name) | ||
71 | : QWidget( parent, name), mDisableItemUpdate( false ) | ||
72 | { | ||
73 | QGridLayout *topLayout = new QGridLayout(this); | ||
74 | topLayout->setSpacing(spacing); | ||
75 | |||
76 | QString organizer = KOPrefs::instance()->email(); | ||
77 | mOrganizerLabel = new QLabel(i18n("Organizer: %1").arg(organizer),this); | ||
78 | |||
79 | mListView = new KListView(this,"mListView"); | ||
80 | mListView->addColumn(i18n("Name"),180); | ||
81 | mListView->addColumn(i18n("Email"),180); | ||
82 | mListView->addColumn(i18n("Role"),60); | ||
83 | mListView->addColumn(i18n("Status"),100); | ||
84 | mListView->addColumn(i18n("RSVP"),35); | ||
85 | if ( KOPrefs::instance()->mCompactDialogs ) { | ||
86 | //mListView->setFixedHeight(78); | ||
87 | } | ||
88 | |||
89 | connect(mListView,SIGNAL(selectionChanged(QListViewItem *)), | ||
90 | SLOT(updateAttendeeInput())); | ||
91 | |||
92 | QLabel *attendeeLabel = new QLabel(this); | ||
93 | attendeeLabel->setText(i18n("Name:")); | ||
94 | attendeeLabel->setFixedSize( attendeeLabel->sizeHint() ); | ||
95 | mNameEdit = new QLineEdit(this); | ||
96 | connect(mNameEdit,SIGNAL(textChanged(const QString &)), | ||
97 | SLOT(updateAttendeeItem())); | ||
98 | |||
99 | mUidEdit = new QLineEdit(0); | ||
100 | mUidEdit->setText(""); | ||
101 | |||
102 | QLabel *emailLabel = new QLabel(this); | ||
103 | emailLabel->setText(i18n("Email:")); | ||
104 | mEmailEdit = new QLineEdit(this); | ||
105 | connect(mEmailEdit,SIGNAL(textChanged(const QString &)), | ||
106 | SLOT(updateAttendeeItem())); | ||
107 | |||
108 | QLabel *attendeeRoleLabel = new QLabel(this); | ||
109 | attendeeRoleLabel->setText(i18n("Role:")); | ||
110 | mRoleCombo = new QComboBox(false,this); | ||
111 | mRoleCombo->insertStringList(Attendee::roleList()); | ||
112 | connect(mRoleCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem())); | ||
113 | |||
114 | QLabel *statusLabel = new QLabel(this); | ||
115 | statusLabel->setText( i18n("Status:") ); | ||
116 | |||
117 | mStatusCombo = new QComboBox(false,this); | ||
118 | mStatusCombo->insertStringList(Attendee::statusList()); | ||
119 | connect(mStatusCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem())); | ||
120 | |||
121 | mRsvpButton = new QCheckBox(this); | ||
122 | mRsvpButton->setText(i18n("Request response")); | ||
123 | connect(mRsvpButton,SIGNAL(clicked()),SLOT(updateAttendeeItem())); | ||
124 | QWidget *buttonBox = new QWidget(this); | ||
125 | QVBoxLayout *buttonLayout = new QVBoxLayout(buttonBox); | ||
126 | |||
127 | QPushButton *newButton = new QPushButton(i18n("&New"),buttonBox); | ||
128 | buttonLayout->addWidget(newButton); | ||
129 | connect(newButton,SIGNAL(clicked()),SLOT(addNewAttendee())); | ||
130 | |||
131 | mRemoveButton = new QPushButton(i18n("&Remove"),buttonBox); | ||
132 | buttonLayout->addWidget(mRemoveButton); | ||
133 | connect(mRemoveButton, SIGNAL(clicked()),SLOT(removeAttendee())); | ||
134 | |||
135 | mAddressBookButton = new QPushButton(i18n("Address &Book..."),this); | ||
136 | // buttonLayout->addWidget(mAddressBookButton); | ||
137 | connect(mAddressBookButton,SIGNAL(clicked()),SLOT(openAddressBook())); | ||
138 | //mRoleCombo->setFixedSize( mRoleCombo->sizeHint () ); | ||
139 | |||
140 | if (qApp->desktop()->width() < 300 ) { | ||
141 | mListView->setFixedHeight(80); | ||
142 | topLayout->addMultiCellWidget(mOrganizerLabel,0,0,0,3); | ||
143 | topLayout->addMultiCellWidget(mListView,1,1,0,3); | ||
144 | topLayout->addWidget(attendeeLabel,3,0); | ||
145 | topLayout->addMultiCellWidget(mNameEdit,3,3,1,2); | ||
146 | topLayout->addWidget(emailLabel,4,0); | ||
147 | topLayout->addMultiCellWidget(mEmailEdit,4,4,1,2); | ||
148 | topLayout->addWidget(attendeeRoleLabel,5,0); | ||
149 | topLayout->addMultiCellWidget(mRoleCombo,5,5,1,2); | ||
150 | topLayout->addWidget(statusLabel,6,0); | ||
151 | topLayout->addMultiCellWidget(mStatusCombo,6,6,1,2); | ||
152 | topLayout->addMultiCellWidget(mAddressBookButton,2,2,2,3); | ||
153 | topLayout->addMultiCellWidget(mRsvpButton,2,2,0,1); | ||
154 | topLayout->addMultiCellWidget(buttonBox,3,4,3,3); | ||
155 | topLayout->setRowStretch(1,2); | ||
156 | topLayout->setColStretch(0,0); | ||
157 | topLayout->setColStretch(1,2); | ||
158 | topLayout->setColStretch(2,1); | ||
159 | topLayout->setColStretch(3,1); | ||
160 | |||
161 | } else { | ||
162 | topLayout->addMultiCellWidget(mOrganizerLabel,0,0,0,5); | ||
163 | topLayout->addMultiCellWidget(mListView,1,1,0,5); | ||
164 | topLayout->addWidget(attendeeLabel,3,0); | ||
165 | topLayout->addMultiCellWidget(mNameEdit,3,3,1,4); | ||
166 | topLayout->addWidget(emailLabel,4,0); | ||
167 | topLayout->addMultiCellWidget(mEmailEdit,4,4,1,4); | ||
168 | topLayout->addWidget(attendeeRoleLabel,5,0); | ||
169 | topLayout->addMultiCellWidget(mRoleCombo,5,5,1,2); | ||
170 | topLayout->addWidget(statusLabel,5,3); | ||
171 | topLayout->addMultiCellWidget(mStatusCombo,5,5,4,5); | ||
172 | topLayout->addMultiCellWidget(mAddressBookButton,2,2,4,5); | ||
173 | topLayout->addMultiCellWidget(mRsvpButton,2,2,0,1); | ||
174 | topLayout->addMultiCellWidget(buttonBox,3,4,5,5); | ||
175 | topLayout->setRowStretch(1,5); | ||
176 | topLayout->setColStretch(0,0); | ||
177 | } | ||
178 | // #if 0 | ||
179 | // topLayout->setColStretch(2,1); | ||
180 | // topLayout->addWidget(statusLabel,3,3); | ||
181 | // topLayout->addWidget(mStatusCombo,3,4); | ||
182 | // #else | ||
183 | // topLayout->addWidget(statusLabel,4,3); | ||
184 | // // topLayout->addWidget(mStatusCombo,4,3); | ||
185 | // topLayout->addMultiCellWidget(mStatusCombo,4,4,4,5); | ||
186 | |||
187 | // #endif | ||
188 | // // topLayout->setRowStretch(5,1); | ||
189 | // topLayout->addMultiCellWidget(mRsvpButton,5,5,0,1); | ||
190 | // topLayout->addMultiCellWidget(buttonBox,2,3,5,5); | ||
191 | // topLayout->setRowStretch(1,5); | ||
192 | // topLayout->setColStretch(0,0); | ||
193 | |||
194 | #ifdef KORG_NOKABC | ||
195 | mAddressBookButton->hide(); | ||
196 | #endif | ||
197 | |||
198 | updateAttendeeInput(); | ||
199 | } | ||
200 | |||
201 | KOEditorDetails::~KOEditorDetails() | ||
202 | { | ||
203 | } | ||
204 | |||
205 | void KOEditorDetails::removeAttendee() | ||
206 | { | ||
207 | AttendeeListItem *aItem = (AttendeeListItem *)mListView->selectedItem(); | ||
208 | if (!aItem) return; | ||
209 | |||
210 | Attendee *delA = new Attendee(aItem->data()->name(),aItem->data()->email(), | ||
211 | aItem->data()->RSVP(),aItem->data()->status(),aItem->data()->role(), | ||
212 | aItem->data()->uid()); | ||
213 | mdelAttendees.append(delA); | ||
214 | |||
215 | delete aItem; | ||
216 | |||
217 | updateAttendeeInput(); | ||
218 | } | ||
219 | |||
220 | |||
221 | void KOEditorDetails::openAddressBook() | ||
222 | { | ||
223 | #ifndef KORG_NOKABC | ||
224 | |||
225 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | ||
226 | uint i=0; | ||
227 | for (i=0; i < list.count(); i++) { | ||
228 | insertAttendee( new Attendee( list[i].realName(), list[i].preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,list[i].uid()) ); | ||
229 | } | ||
230 | |||
231 | #if 0 | ||
232 | KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this); | ||
233 | if (!a.isEmpty()) { | ||
234 | insertAttendee( new Attendee( a.realName(), a.preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,a.uid()) ); | ||
235 | } | ||
236 | #endif | ||
237 | #endif | ||
238 | } | ||
239 | |||
240 | |||
241 | void KOEditorDetails::addNewAttendee() | ||
242 | { | ||
243 | #if 0 | ||
244 | // this is cool. If they didn't enter an email address, | ||
245 | // try to look it up in the address book and fill it in for them. | ||
246 | if (QString(mEmailEdit->text()).stripWhiteSpace().isEmpty()) { | ||
247 | KabAPI addrBook; | ||
248 | QString name; | ||
249 | std::list<AddressBook::Entry> entries; | ||
250 | name = mNameEdit->text(); | ||
251 | if (addrBook.init() == AddressBook::NoError) { | ||
252 | if (addrBook.getEntryByName(name, entries, 1) == AddressBook::NoError) { | ||
253 | kdDebug() << "positive match" << endl; | ||
254 | // take first email address | ||
255 | if (!entries.front().emails.isEmpty() && | ||
256 | entries.front().emails.first().length()>0) | ||
257 | mEmailEdit->setText(entries.front().emails.first()); | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | #endif | ||
262 | |||
263 | Attendee *a = new Attendee(i18n("(EmptyName)"),i18n("(EmptyEmail)")); | ||
264 | insertAttendee(a); | ||
265 | } | ||
266 | |||
267 | |||
268 | void KOEditorDetails::insertAttendee(Attendee *a) | ||
269 | { | ||
270 | AttendeeListItem *item = new AttendeeListItem(a,mListView); | ||
271 | mListView->setSelected( item, true ); | ||
272 | } | ||
273 | |||
274 | void KOEditorDetails::setDefaults() | ||
275 | { | ||
276 | mRsvpButton->setChecked(true); | ||
277 | mListView->clear(); | ||
278 | mdelAttendees.clear(); | ||
279 | clearAttendeeInput(); | ||
280 | mOrganizerLabel->setText(i18n("Organizer: %1").arg(KOPrefs::instance()->email())); | ||
281 | |||
282 | mNameEdit->setText(""); | ||
283 | mUidEdit->setText(""); | ||
284 | mEmailEdit->setText(""); | ||
285 | mRoleCombo->setCurrentItem( 0 ); | ||
286 | mStatusCombo->setCurrentItem( 0 ); | ||
287 | |||
288 | } | ||
289 | |||
290 | void KOEditorDetails::readEvent(Incidence *event) | ||
291 | { | ||
292 | setDefaults(); | ||
293 | //mListView->clear(); | ||
294 | //mdelAttendees.clear(); | ||
295 | QPtrList<Attendee> tmpAList = event->attendees(); | ||
296 | Attendee *a; | ||
297 | for (a = tmpAList.first(); a; a = tmpAList.next()) | ||
298 | insertAttendee(new Attendee(*a)); | ||
299 | |||
300 | mListView->setSelected( mListView->firstChild(), true ); | ||
301 | mOrganizerLabel->setText(i18n("Organizer: %1").arg(event->organizer())); | ||
302 | } | ||
303 | |||
304 | void KOEditorDetails::writeEvent(Incidence *event) | ||
305 | { | ||
306 | event->clearAttendees(); | ||
307 | QListViewItem *item; | ||
308 | AttendeeListItem *a; | ||
309 | for (item = mListView->firstChild(); item; | ||
310 | item = item->nextSibling()) { | ||
311 | a = (AttendeeListItem *)item; | ||
312 | event->addAttendee(new Attendee(*(a->data()))); | ||
313 | } | ||
314 | event->setOrganizer(KOPrefs::instance()->email()); | ||
315 | } | ||
316 | |||
317 | void KOEditorDetails::cancelAttendeeEvent(Incidence *event) | ||
318 | { | ||
319 | event->clearAttendees(); | ||
320 | Attendee * att; | ||
321 | for (att=mdelAttendees.first();att;att=mdelAttendees.next()) { | ||
322 | event->addAttendee(new Attendee(*att)); | ||
323 | } | ||
324 | mdelAttendees.clear(); | ||
325 | } | ||
326 | |||
327 | bool KOEditorDetails::validateInput() | ||
328 | { | ||
329 | return true; | ||
330 | } | ||
331 | |||
332 | void KOEditorDetails::updateAttendeeInput() | ||
333 | { | ||
334 | QListViewItem *item = mListView->selectedItem(); | ||
335 | AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item ); | ||
336 | if (aItem) { | ||
337 | fillAttendeeInput( aItem ); | ||
338 | } else { | ||
339 | clearAttendeeInput(); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | void KOEditorDetails::clearAttendeeInput() | ||
344 | { | ||
345 | mNameEdit->setText(""); | ||
346 | mUidEdit->setText(""); | ||
347 | mEmailEdit->setText(""); | ||
348 | mRoleCombo->setCurrentItem(0); | ||
349 | mStatusCombo->setCurrentItem(0); | ||
350 | mRsvpButton->setChecked(true); | ||
351 | setEnabledAttendeeInput( false ); | ||
352 | } | ||
353 | |||
354 | void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem ) | ||
355 | { | ||
356 | Attendee *a = aItem->data(); | ||
357 | mDisableItemUpdate = true; | ||
358 | mNameEdit->setText(a->name()); | ||
359 | mUidEdit->setText(a->uid()); | ||
360 | mEmailEdit->setText(a->email()); | ||
361 | mRoleCombo->setCurrentItem(a->role()); | ||
362 | mStatusCombo->setCurrentItem(a->status()); | ||
363 | mRsvpButton->setChecked(a->RSVP()); | ||
364 | |||
365 | mDisableItemUpdate = false; | ||
366 | |||
367 | setEnabledAttendeeInput( true ); | ||
368 | } | ||
369 | |||
370 | void KOEditorDetails::setEnabledAttendeeInput( bool enabled ) | ||
371 | { | ||
372 | mNameEdit->setEnabled( enabled ); | ||
373 | mEmailEdit->setEnabled( enabled ); | ||
374 | mRoleCombo->setEnabled( enabled ); | ||
375 | mStatusCombo->setEnabled( enabled ); | ||
376 | mRsvpButton->setEnabled( enabled ); | ||
377 | |||
378 | mRemoveButton->setEnabled( enabled ); | ||
379 | } | ||
380 | |||
381 | void KOEditorDetails::updateAttendeeItem() | ||
382 | { | ||
383 | if (mDisableItemUpdate) return; | ||
384 | |||
385 | QListViewItem *item = mListView->selectedItem(); | ||
386 | AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item ); | ||
387 | if ( !aItem ) return; | ||
388 | |||
389 | Attendee *a = aItem->data(); | ||
390 | |||
391 | a->setName( mNameEdit->text() ); | ||
392 | a->setUid( mUidEdit->text() ); | ||
393 | a->setEmail( mEmailEdit->text() ); | ||
394 | a->setRole( Attendee::Role( mRoleCombo->currentItem() ) ); | ||
395 | a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) ); | ||
396 | a->setRSVP( mRsvpButton->isChecked() ); | ||
397 | aItem->updateItem(); | ||
398 | } | ||