-rw-r--r-- | korganizer/kolistview.cpp | 1062 |
1 files changed, 1062 insertions, 0 deletions
diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp new file mode 100644 index 0000000..b6061d0 --- a/dev/null +++ b/korganizer/kolistview.cpp | |||
@@ -0,0 +1,1062 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 1999 Preston Brown | ||
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
19 | |||
20 | As a special exception, permission is given to link this program | ||
21 | with any edition of Qt, and distribute the resulting executable, | ||
22 | without including the source code for Qt in the source distribution. | ||
23 | */ | ||
24 | |||
25 | #include <qlistview.h> | ||
26 | #include <qlayout.h> | ||
27 | #include <qlabel.h> | ||
28 | #include <qpopupmenu.h> | ||
29 | #include <qprogressbar.h> | ||
30 | #include <qfileinfo.h> | ||
31 | #include <qmessagebox.h> | ||
32 | #include <qdialog.h> | ||
33 | #include <qtextstream.h> | ||
34 | #include <qdir.h> | ||
35 | |||
36 | #include <klocale.h> | ||
37 | #include <kdebug.h> | ||
38 | #include <kiconloader.h> | ||
39 | #include <kglobal.h> | ||
40 | |||
41 | #include <libkcal/calendar.h> | ||
42 | #include <libkcal/calendarlocal.h> | ||
43 | #include <libkcal/icalformat.h> | ||
44 | #include <libkcal/vcalformat.h> | ||
45 | #include <libkcal/recurrence.h> | ||
46 | #include <libkcal/filestorage.h> | ||
47 | #include <libkdepim/categoryselectdialog.h> | ||
48 | #ifndef DESKTOP_VERSION | ||
49 | #include <qpe/qpeapplication.h> | ||
50 | #else | ||
51 | #include <qapplication.h> | ||
52 | #endif | ||
53 | |||
54 | #ifndef KORG_NOPRINTER | ||
55 | #include "calprinter.h" | ||
56 | #endif | ||
57 | #include "koglobals.h" | ||
58 | #include "koprefs.h" | ||
59 | #include "kfiledialog.h" | ||
60 | |||
61 | #include "kolistview.h" | ||
62 | #include "kolistview.moc" | ||
63 | |||
64 | ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) | ||
65 | { | ||
66 | mItem = item; | ||
67 | mDate = date; | ||
68 | } | ||
69 | |||
70 | ListItemVisitor::~ListItemVisitor() | ||
71 | { | ||
72 | } | ||
73 | |||
74 | bool ListItemVisitor::visit(Event *e) | ||
75 | { | ||
76 | |||
77 | bool ok = false; | ||
78 | QString start, end; | ||
79 | if ( e->doesRecur() ) { | ||
80 | QDate d = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); | ||
81 | if ( ok ) { | ||
82 | int days = e->dtStart().date().daysTo(e->dtEnd().date() ); | ||
83 | start = KGlobal::locale()->formatDate(d,true); | ||
84 | end = KGlobal::locale()->formatDate(d.addDays( days),true); | ||
85 | } | ||
86 | |||
87 | } | ||
88 | if ( ! ok ) { | ||
89 | start =e->dtStartDateStr(); | ||
90 | end = e->dtEndDateStr(); | ||
91 | } | ||
92 | mItem->setText(0,e->summary()); | ||
93 | mItem->setText(1,start); | ||
94 | mItem->setText(2,e->dtStartTimeStr()); | ||
95 | mItem->setText(3,end); | ||
96 | mItem->setText(4,e->dtEndTimeStr()); | ||
97 | mItem->setText(5,e->isAlarmEnabled() ? i18n("Yes") : i18n("No")); | ||
98 | mItem->setText(6, e->recurrence()->recurrenceText()); | ||
99 | mItem->setText(7,"---"); | ||
100 | mItem->setText(8,"---"); | ||
101 | mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No")); | ||
102 | mItem->setText(10,e->categoriesStr()); | ||
103 | |||
104 | QString key; | ||
105 | QDate d = e->dtStart().date(); | ||
106 | QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); | ||
107 | key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute()); | ||
108 | mItem->setSortKey(1,key); | ||
109 | |||
110 | d = e->dtEnd().date(); | ||
111 | t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); | ||
112 | key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute()); | ||
113 | mItem->setSortKey(3,key); | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | bool ListItemVisitor::visit(Todo *t) | ||
119 | { | ||
120 | mItem->setText(0,i18n("To-Do: %1").arg(t->summary())); | ||
121 | if (t->hasStartDate()) { | ||
122 | mItem->setText(1,t->dtStartDateStr()); | ||
123 | if (t->doesFloat()) { | ||
124 | mItem->setText(2,"---"); | ||
125 | } else { | ||
126 | mItem->setText(2,t->dtStartTimeStr()); | ||
127 | } | ||
128 | } else { | ||
129 | mItem->setText(1,"---"); | ||
130 | mItem->setText(2,"---"); | ||
131 | } | ||
132 | mItem->setText(3,"---"); | ||
133 | mItem->setText(4,"---"); | ||
134 | mItem->setText(5,"---"); | ||
135 | mItem->setText(6,"---"); | ||
136 | if (t->hasDueDate()) { | ||
137 | mItem->setText(7,t->dtDueDateStr()); | ||
138 | if (t->doesFloat()) { | ||
139 | mItem->setText(8,"---"); | ||
140 | } else { | ||
141 | mItem->setText(8,t->dtDueTimeStr()); | ||
142 | } | ||
143 | } else { | ||
144 | mItem->setText(7,"---"); | ||
145 | mItem->setText(8,"---"); | ||
146 | } | ||
147 | mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No")); | ||
148 | mItem->setText(10,t->categoriesStr()); | ||
149 | |||
150 | QString key; | ||
151 | QDate d; | ||
152 | if (t->hasDueDate()) { | ||
153 | d = t->dtDue().date(); | ||
154 | QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); | ||
155 | key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); | ||
156 | mItem->setSortKey(7,key); | ||
157 | } | ||
158 | if ( t->hasStartDate() ) { | ||
159 | d = t->dtStart().date(); | ||
160 | QTime tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); | ||
161 | key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); | ||
162 | mItem->setSortKey(1,key); | ||
163 | } | ||
164 | return true; | ||
165 | } | ||
166 | |||
167 | bool ListItemVisitor::visit(Journal * j) | ||
168 | { | ||
169 | mItem->setText(0,i18n("Journal")); | ||
170 | mItem->setText(1,j->dtStartDateStr()); | ||
171 | mItem->setText(2,"---"); | ||
172 | mItem->setText(3,"---"); | ||
173 | mItem->setText(4,"---"); | ||
174 | mItem->setText(5,"---"); | ||
175 | mItem->setText(6,"---"); | ||
176 | mItem->setText(7,j->dtStartDateStr()); | ||
177 | mItem->setText(8,"---"); | ||
178 | mItem->setText(9,"---"); | ||
179 | |||
180 | QString key; | ||
181 | QDate d = j->dtStart().date(); | ||
182 | key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); | ||
183 | mItem->setSortKey(1,key); | ||
184 | mItem->setSortKey(7,key); | ||
185 | |||
186 | return true; | ||
187 | } | ||
188 | |||
189 | KOListView::KOListView(Calendar *calendar, QWidget *parent, | ||
190 | const char *name) | ||
191 | : KOEventView(calendar, parent, name) | ||
192 | { | ||
193 | mActiveItem = 0; | ||
194 | mListView = new KOListViewListView(this); | ||
195 | mListView->addColumn(i18n("Summary")); | ||
196 | mListView->addColumn(i18n("Start Date")); | ||
197 | mListView->addColumn(i18n("Start Time")); | ||
198 | mListView->addColumn(i18n("End Date")); | ||
199 | mListView->addColumn(i18n("End Time")); | ||
200 | mListView->addColumn(i18n("Alarm")); // alarm set? | ||
201 | mListView->addColumn(i18n("Recurs")); // recurs? | ||
202 | mListView->addColumn(i18n("Due Date")); | ||
203 | mListView->addColumn(i18n("Due Time")); | ||
204 | mListView->addColumn(i18n("Cancelled")); | ||
205 | mListView->addColumn(i18n("Categories")); | ||
206 | |||
207 | mListView->setColumnAlignment(0,AlignLeft); | ||
208 | mListView->setColumnAlignment(1,AlignLeft); | ||
209 | mListView->setColumnAlignment(2,AlignHCenter); | ||
210 | mListView->setColumnAlignment(3,AlignLeft); | ||
211 | mListView->setColumnAlignment(4,AlignHCenter); | ||
212 | mListView->setColumnAlignment(5,AlignLeft); | ||
213 | mListView->setColumnAlignment(6,AlignLeft); | ||
214 | mListView->setColumnAlignment(7,AlignLeft); | ||
215 | mListView->setColumnAlignment(8,AlignLeft); | ||
216 | mListView->setColumnAlignment(9,AlignLeft); | ||
217 | mListView->setColumnAlignment(10,AlignLeft); | ||
218 | |||
219 | int iii = 0; | ||
220 | for ( iii = 0; iii< 10 ; ++iii ) | ||
221 | mListView->setColumnWidthMode( iii, QListView::Manual ); | ||
222 | |||
223 | QBoxLayout *layoutTop = new QVBoxLayout(this); | ||
224 | layoutTop->addWidget(mListView); | ||
225 | mListView->setFont ( KOPrefs::instance()->mListViewFont ); | ||
226 | mPopupMenu = eventPopup(); | ||
227 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
228 | i18n("Select all"),this, | ||
229 | SLOT(allSelection()),true); | ||
230 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
231 | i18n("Deselect All"),this, | ||
232 | SLOT(clearSelection()),true); | ||
233 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
234 | i18n("Delete all selected"),this, | ||
235 | SLOT(deleteAll()),true); | ||
236 | mPopupMenu->insertSeparator(); | ||
237 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
238 | i18n("Save selected to file..."),this, | ||
239 | SLOT(saveToFile()),true); | ||
240 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
241 | i18n("Save Journal/Description..."),this, | ||
242 | SLOT(saveDescriptionToFile()),true); | ||
243 | mPopupMenu->insertSeparator(); | ||
244 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
245 | i18n("Add Categ. to selected..."),this, | ||
246 | SLOT(addCat()),true); | ||
247 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
248 | i18n("Set Categ. for selected..."),this, | ||
249 | SLOT(setCat()),true); | ||
250 | mPopupMenu->insertSeparator(); | ||
251 | |||
252 | |||
253 | #ifndef DESKTOP_VERSION | ||
254 | mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
255 | i18n("Beam selected via IR"),this, | ||
256 | SLOT(beamSelected()),true); | ||
257 | #endif | ||
258 | /* | ||
259 | mPopupMenu = new QPopupMenu; | ||
260 | mPopupMenu->insertItem(i18n("Edit Event"), this, | ||
261 | SLOT (editEvent())); | ||
262 | mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, | ||
263 | SLOT (deleteEvent())); | ||
264 | mPopupMenu->insertSeparator(); | ||
265 | mPopupMenu->insertItem(i18n("Show Dates"), this, | ||
266 | SLOT(showDates())); | ||
267 | mPopupMenu->insertItem(i18n("Hide Dates"), this, | ||
268 | SLOT(hideDates())); | ||
269 | */ | ||
270 | QObject::connect(mListView,SIGNAL( newEvent()), | ||
271 | this,SIGNAL(signalNewEvent())); | ||
272 | QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), | ||
273 | this,SLOT(defaultItemAction(QListViewItem *))); | ||
274 | QObject::connect(mListView,SIGNAL(rightButtonClicked ( QListViewItem *, | ||
275 | const QPoint &, int )), | ||
276 | this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); | ||
277 | QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), | ||
278 | SLOT(processSelectionChange(QListViewItem *))); | ||
279 | QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), | ||
280 | SIGNAL(showIncidenceSignal(Incidence *)) ); | ||
281 | |||
282 | readSettings(KOGlobals::config(),"KOListView Layout"); | ||
283 | } | ||
284 | |||
285 | KOListView::~KOListView() | ||
286 | { | ||
287 | delete mPopupMenu; | ||
288 | } | ||
289 | |||
290 | void KOListView::updateList() | ||
291 | { | ||
292 | // qDebug(" KOListView::updateList() "); | ||
293 | |||
294 | } | ||
295 | |||
296 | void KOListView::addCat( ) | ||
297 | { | ||
298 | setCategories( false ); | ||
299 | } | ||
300 | void KOListView::setCat() | ||
301 | { | ||
302 | setCategories( true ); | ||
303 | } | ||
304 | void KOListView::setCategories( bool removeOld ) | ||
305 | { | ||
306 | |||
307 | KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); | ||
308 | if (! csd->exec()) { | ||
309 | delete csd; | ||
310 | return; | ||
311 | } | ||
312 | QStringList catList = csd->selectedCategories(); | ||
313 | delete csd; | ||
314 | // if ( catList.count() == 0 ) | ||
315 | // return; | ||
316 | catList.sort(); | ||
317 | QString categoriesStr = catList.join(","); | ||
318 | int i; | ||
319 | QStringList itemList; | ||
320 | QPtrList<KOListViewItem> sel ; | ||
321 | QListViewItem *qitem = mListView->firstChild (); | ||
322 | while ( qitem ) { | ||
323 | if ( qitem->isSelected() ) { | ||
324 | sel.append(((KOListViewItem *)qitem)); | ||
325 | } | ||
326 | qitem = qitem->nextSibling(); | ||
327 | } | ||
328 | KOListViewItem * item, *temp; | ||
329 | item = sel.first(); | ||
330 | Incidence* inc; | ||
331 | while ( item ) { | ||
332 | inc = item->data(); | ||
333 | if ( removeOld ) { | ||
334 | inc->setCategories( categoriesStr ); | ||
335 | } else { | ||
336 | itemList = QStringList::split (",", inc->categoriesStr() ); | ||
337 | for( i = 0; i< catList.count(); ++i ) { | ||
338 | if ( !itemList.contains (catList[i])) | ||
339 | itemList.append( catList[i] ); | ||
340 | } | ||
341 | itemList.sort(); | ||
342 | inc->setCategories( itemList.join(",") ); | ||
343 | } | ||
344 | temp = item; | ||
345 | item = sel.next(); | ||
346 | mUidDict.remove( inc->uid() ); | ||
347 | delete temp;; | ||
348 | addIncidence( inc ); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | void KOListView::beamSelected() | ||
353 | { | ||
354 | int icount = 0; | ||
355 | QPtrList<Incidence> delSel ; | ||
356 | QListViewItem *item = mListView->firstChild (); | ||
357 | while ( item ) { | ||
358 | if ( item->isSelected() ) { | ||
359 | delSel.append(((KOListViewItem *)item)->data()); | ||
360 | ++icount; | ||
361 | } | ||
362 | |||
363 | item = item->nextSibling(); | ||
364 | } | ||
365 | if ( icount ) { | ||
366 | emit beamIncidenceList( delSel ); | ||
367 | return; | ||
368 | QString fn ; | ||
369 | fn = QDir::homeDirPath()+"/kopitempbeamfile.vcs"; | ||
370 | QString mes; | ||
371 | bool createbup = true; | ||
372 | if ( createbup ) { | ||
373 | QString description = "\n"; | ||
374 | CalendarLocal* cal = new CalendarLocal(); | ||
375 | cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | ||
376 | Incidence *incidence = delSel.first(); | ||
377 | while ( incidence ) { | ||
378 | Incidence *in = incidence->clone(); | ||
379 | description += in->summary() + "\n"; | ||
380 | cal->addIncidence( in ); | ||
381 | incidence = delSel.next(); | ||
382 | } | ||
383 | FileStorage storage( cal, fn, new VCalFormat ); | ||
384 | storage.save(); | ||
385 | delete cal; | ||
386 | mes = i18n("KO/Pi: Ready for beaming"); | ||
387 | topLevelWidget()->setCaption(mes); | ||
388 | |||
389 | #ifndef DESKTOP_VERSION | ||
390 | Ir *ir = new Ir( this ); | ||
391 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | ||
392 | ir->send( fn, description, "text/x-vCalendar" ); | ||
393 | #endif | ||
394 | } | ||
395 | } | ||
396 | } | ||
397 | void KOListView::beamDone( Ir *ir ) | ||
398 | { | ||
399 | #ifndef DESKTOP_VERSION | ||
400 | delete ir; | ||
401 | #endif | ||
402 | topLevelWidget()->setCaption(i18n("KO/Pi:Beaming done")); | ||
403 | } | ||
404 | |||
405 | void KOListView::saveDescriptionToFile() | ||
406 | { | ||
407 | |||
408 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | ||
409 | i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), | ||
410 | i18n("Continue"), i18n("Cancel"), 0, | ||
411 | 0, 1 ); | ||
412 | if ( result != 0 ) { | ||
413 | return; | ||
414 | } | ||
415 | int icount = 0; | ||
416 | QPtrList<Incidence> delSel ; | ||
417 | QListViewItem *item = mListView->firstChild (); | ||
418 | while ( item ) { | ||
419 | if ( item->isSelected() ) { | ||
420 | delSel.append(((KOListViewItem *)item)->data()); | ||
421 | ++icount; | ||
422 | } | ||
423 | |||
424 | item = item->nextSibling(); | ||
425 | } | ||
426 | if ( icount ) { | ||
427 | QString fn = KOPrefs::instance()->mLastSaveFile; | ||
428 | fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); | ||
429 | |||
430 | if ( fn == "" ) | ||
431 | return; | ||
432 | QFileInfo info; | ||
433 | info.setFile( fn ); | ||
434 | QString mes; | ||
435 | bool createbup = true; | ||
436 | if ( info. exists() ) { | ||
437 | mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); | ||
438 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, | ||
439 | i18n("Overwrite!"), i18n("Cancel"), 0, | ||
440 | 0, 1 ); | ||
441 | if ( result != 0 ) { | ||
442 | createbup = false; | ||
443 | } | ||
444 | } | ||
445 | if ( createbup ) { | ||
446 | QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") + | ||
447 | KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false); | ||
448 | Incidence *incidence = delSel.first(); | ||
449 | icount = 0; | ||
450 | while ( incidence ) { | ||
451 | if ( incidence->type() == "Journal" ) { | ||
452 | text += "\n************************************\n"; | ||
453 | text += i18n("Journal from: ") +incidence->dtStartDateStr( false ); | ||
454 | text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); | ||
455 | text +="\n" + i18n("Description: ") + "\n"+ incidence->description(); | ||
456 | ++icount; | ||
457 | |||
458 | } else { | ||
459 | if ( !incidence->description().isEmpty() ) { | ||
460 | text += "\n************************************\n"; | ||
461 | if ( incidence->type() == "Todo" ) | ||
462 | text += i18n("To-Do: "); | ||
463 | text += incidence->summary(); | ||
464 | if ( incidence->hasStartDate() ) | ||
465 | text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false ); | ||
466 | text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); | ||
467 | if ( !incidence->location().isEmpty() ) | ||
468 | text += "\n" +i18n("Location: ") + incidence->location(); | ||
469 | text += "\n" + i18n("Description: ") + "\n" + incidence->description(); | ||
470 | ++icount; | ||
471 | |||
472 | } | ||
473 | } | ||
474 | incidence = delSel.next(); | ||
475 | } | ||
476 | QFile file( fn ); | ||
477 | if (!file.open( IO_WriteOnly ) ) { | ||
478 | topLevelWidget()->setCaption(i18n("File open error - nothing saved!") ); | ||
479 | return; | ||
480 | } | ||
481 | QTextStream ts( &file ); | ||
482 | ts << text; | ||
483 | file.close(); | ||
484 | //qDebug("%s ", text.latin1()); | ||
485 | mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount ); | ||
486 | KOPrefs::instance()->mLastSaveFile = fn; | ||
487 | topLevelWidget()->setCaption(mes); | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | void KOListView::saveToFile() | ||
492 | { | ||
493 | |||
494 | int icount = 0; | ||
495 | QPtrList<Incidence> delSel ; | ||
496 | QListViewItem *item = mListView->firstChild (); | ||
497 | while ( item ) { | ||
498 | if ( item->isSelected() ) { | ||
499 | delSel.append(((KOListViewItem *)item)->data()); | ||
500 | ++icount; | ||
501 | } | ||
502 | |||
503 | item = item->nextSibling(); | ||
504 | } | ||
505 | if ( icount ) { | ||
506 | QString fn = KOPrefs::instance()->mLastSaveFile; | ||
507 | fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); | ||
508 | |||
509 | if ( fn == "" ) | ||
510 | return; | ||
511 | QFileInfo info; | ||
512 | info.setFile( fn ); | ||
513 | QString mes; | ||
514 | bool createbup = true; | ||
515 | if ( info. exists() ) { | ||
516 | mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); | ||
517 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, | ||
518 | i18n("Overwrite!"), i18n("Cancel"), 0, | ||
519 | 0, 1 ); | ||
520 | if ( result != 0 ) { | ||
521 | createbup = false; | ||
522 | } | ||
523 | } | ||
524 | if ( createbup ) { | ||
525 | CalendarLocal cal; | ||
526 | cal.setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | ||
527 | Incidence *incidence = delSel.first(); | ||
528 | while ( incidence ) { | ||
529 | cal.addIncidence( incidence->clone() ); | ||
530 | incidence = delSel.next(); | ||
531 | } | ||
532 | ICalFormat format; | ||
533 | format.save( &cal, fn ); | ||
534 | mes = i18n("KO/Pi:Saved %1").arg(fn ); | ||
535 | KOPrefs::instance()->mLastSaveFile = fn; | ||
536 | topLevelWidget()->setCaption(mes); | ||
537 | } | ||
538 | } | ||
539 | } | ||
540 | void KOListView::deleteAll() | ||
541 | { | ||
542 | int icount = 0; | ||
543 | QPtrList<Incidence> delSel ; | ||
544 | QListViewItem *item = mListView->firstChild (); | ||
545 | while ( item ) { | ||
546 | if ( item->isSelected() ) { | ||
547 | delSel.append(((KOListViewItem *)item)->data()); | ||
548 | ++icount; | ||
549 | } | ||
550 | |||
551 | item = item->nextSibling(); | ||
552 | } | ||
553 | if ( icount ) { | ||
554 | Incidence *incidence = delSel.first(); | ||
555 | Incidence *toDelete; | ||
556 | KOPrefs *p = KOPrefs::instance(); | ||
557 | bool confirm = p->mConfirm; | ||
558 | QString mess; | ||
559 | mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount ); | ||
560 | if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) { | ||
561 | p->mConfirm = false; | ||
562 | int delCounter = 0; | ||
563 | QDialog dia ( this, "p-dialog", true ); | ||
564 | QLabel lab (i18n("Close dialog to abort deletion!"), &dia ); | ||
565 | QVBoxLayout lay( &dia ); | ||
566 | lay.setMargin(7); | ||
567 | lay.setSpacing(7); | ||
568 | lay.addWidget( &lab); | ||
569 | QProgressBar bar( icount, &dia ); | ||
570 | lay.addWidget( &bar); | ||
571 | int w = 220; | ||
572 | int h = 50; | ||
573 | int dw = QApplication::desktop()->width(); | ||
574 | int dh = QApplication::desktop()->height(); | ||
575 | dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
576 | //dia.resize( 240,50 ); | ||
577 | dia.show(); | ||
578 | |||
579 | while ( incidence ) { | ||
580 | bar.setProgress( delCounter ); | ||
581 | mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter ); | ||
582 | dia.setCaption( mess ); | ||
583 | qApp->processEvents(); | ||
584 | toDelete = (incidence); | ||
585 | incidence = delSel.next(); | ||
586 | emit deleteIncidenceSignal(toDelete ); | ||
587 | if ( dia.result() != 0 ) | ||
588 | break; | ||
589 | |||
590 | } | ||
591 | mess = mess.sprintf( i18n("%d items remaining in list."), count() ); | ||
592 | topLevelWidget ()->setCaption( mess ); | ||
593 | p->mConfirm = confirm; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | |||
598 | } | ||
599 | int KOListView::maxDatesHint() | ||
600 | { | ||
601 | return 0; | ||
602 | } | ||
603 | |||
604 | int KOListView::currentDateCount() | ||
605 | { | ||
606 | return 0; | ||
607 | } | ||
608 | |||
609 | QPtrList<Incidence> KOListView::selectedIncidences() | ||
610 | { | ||
611 | QPtrList<Incidence> eventList; | ||
612 | QListViewItem *item = mListView->firstChild (); | ||
613 | while ( item ) { | ||
614 | if ( item->isSelected() ) { | ||
615 | eventList.append(((KOListViewItem *)item)->data()); | ||
616 | } | ||
617 | |||
618 | item = item->nextSibling(); | ||
619 | } | ||
620 | |||
621 | // // QListViewItem *item = mListView->selectedItem(); | ||
622 | //if (item) eventList.append(((KOListViewItem *)item)->data()); | ||
623 | |||
624 | return eventList; | ||
625 | } | ||
626 | |||
627 | DateList KOListView::selectedDates() | ||
628 | { | ||
629 | DateList eventList; | ||
630 | return eventList; | ||
631 | } | ||
632 | |||
633 | void KOListView::showDates(bool show) | ||
634 | { | ||
635 | // Shouldn't we set it to a value greater 0? When showDates is called with | ||
636 | // show == true at first, then the columnwidths are set to zero. | ||
637 | static int oldColWidth1 = 0; | ||
638 | static int oldColWidth3 = 0; | ||
639 | |||
640 | if (!show) { | ||
641 | oldColWidth1 = mListView->columnWidth(1); | ||
642 | oldColWidth3 = mListView->columnWidth(3); | ||
643 | mListView->setColumnWidth(1, 0); | ||
644 | mListView->setColumnWidth(3, 0); | ||
645 | } else { | ||
646 | mListView->setColumnWidth(1, oldColWidth1); | ||
647 | mListView->setColumnWidth(3, oldColWidth3); | ||
648 | } | ||
649 | mListView->repaint(); | ||
650 | } | ||
651 | |||
652 | void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, | ||
653 | const QDate &td) | ||
654 | { | ||
655 | #ifndef KORG_NOPRINTER | ||
656 | calPrinter->preview(CalPrinter::Day, fd, td); | ||
657 | #endif | ||
658 | } | ||
659 | |||
660 | void KOListView::showDates() | ||
661 | { | ||
662 | showDates(true); | ||
663 | } | ||
664 | |||
665 | void KOListView::hideDates() | ||
666 | { | ||
667 | showDates(false); | ||
668 | } | ||
669 | |||
670 | void KOListView::updateView() | ||
671 | { | ||
672 | mListView->setFocus(); | ||
673 | if ( mListView->firstChild () ) | ||
674 | mListView->setCurrentItem( mListView->firstChild () ); | ||
675 | } | ||
676 | void KOListView::updateConfig() | ||
677 | { | ||
678 | |||
679 | mListView->setFont ( KOPrefs::instance()->mListViewFont ); | ||
680 | updateView(); | ||
681 | |||
682 | } | ||
683 | void KOListView::setStartDate(const QDate &start) | ||
684 | { | ||
685 | mStartDate = start; | ||
686 | } | ||
687 | |||
688 | void KOListView::showDates(const QDate &start, const QDate &end) | ||
689 | { | ||
690 | clear(); | ||
691 | mStartDate = start; | ||
692 | QDate date = start; | ||
693 | while( date <= end ) { | ||
694 | addEvents(calendar()->events(date)); | ||
695 | addTodos(calendar()->todos(date)); | ||
696 | date = date.addDays( 1 ); | ||
697 | } | ||
698 | emit incidenceSelected( 0 ); | ||
699 | updateView(); | ||
700 | |||
701 | } | ||
702 | |||
703 | void KOListView::addEvents(QPtrList<Event> eventList) | ||
704 | { | ||
705 | Event *ev; | ||
706 | for(ev = eventList.first(); ev; ev = eventList.next()) { | ||
707 | addIncidence(ev); | ||
708 | } | ||
709 | if ( !mListView->currentItem() ){ | ||
710 | updateView(); | ||
711 | } | ||
712 | } | ||
713 | |||
714 | void KOListView::addTodos(QPtrList<Todo> eventList) | ||
715 | { | ||
716 | Todo *ev; | ||
717 | for(ev = eventList.first(); ev; ev = eventList.next()) { | ||
718 | addIncidence(ev); | ||
719 | } | ||
720 | if ( !mListView->currentItem() ){ | ||
721 | updateView(); | ||
722 | } | ||
723 | } | ||
724 | void KOListView::addJournals(QPtrList<Journal> eventList) | ||
725 | { | ||
726 | Journal *ev; | ||
727 | for(ev = eventList.first(); ev; ev = eventList.next()) { | ||
728 | addIncidence(ev); | ||
729 | } | ||
730 | if ( !mListView->currentItem() ){ | ||
731 | updateView(); | ||
732 | } | ||
733 | } | ||
734 | |||
735 | void KOListView::addIncidence(Incidence *incidence) | ||
736 | { | ||
737 | if ( mUidDict.find( incidence->uid() ) ) return; | ||
738 | |||
739 | // mListView->setFont ( KOPrefs::instance()->mListViewFont ); | ||
740 | mUidDict.insert( incidence->uid(), incidence ); | ||
741 | |||
742 | KOListViewItem *item = new KOListViewItem( incidence, mListView ); | ||
743 | ListItemVisitor v(item, mStartDate ); | ||
744 | if (incidence->accept(v)) return; | ||
745 | else delete item; | ||
746 | //qDebug("delete item "); | ||
747 | } | ||
748 | |||
749 | void KOListView::showEvents(QPtrList<Event> eventList) | ||
750 | { | ||
751 | clear(); | ||
752 | |||
753 | addEvents(eventList); | ||
754 | |||
755 | // After new creation of list view no events are selected. | ||
756 | emit incidenceSelected( 0 ); | ||
757 | } | ||
758 | int KOListView::count() | ||
759 | { | ||
760 | return mListView->childCount(); | ||
761 | } | ||
762 | |||
763 | void KOListView::changeEventDisplay(Event *event, int action) | ||
764 | { | ||
765 | KOListViewItem *item; | ||
766 | |||
767 | switch(action) { | ||
768 | case KOGlobals::EVENTADDED: | ||
769 | addIncidence( event ); | ||
770 | break; | ||
771 | case KOGlobals::EVENTEDITED: | ||
772 | item = getItemForEvent(event); | ||
773 | if (item) { | ||
774 | mUidDict.remove( event->uid() ); | ||
775 | delete item; | ||
776 | addIncidence( event ); | ||
777 | } | ||
778 | break; | ||
779 | case KOGlobals::EVENTDELETED: | ||
780 | item = getItemForEvent(event); | ||
781 | if (item) { | ||
782 | mUidDict.remove( event->uid() ); | ||
783 | delete item; | ||
784 | } | ||
785 | break; | ||
786 | default: | ||
787 | ; | ||
788 | } | ||
789 | } | ||
790 | |||
791 | KOListViewItem *KOListView::getItemForEvent(Event *event) | ||
792 | { | ||
793 | KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); | ||
794 | while (item) { | ||
795 | if (item->data() == event) return item; | ||
796 | item = (KOListViewItem *)item->nextSibling(); | ||
797 | } | ||
798 | return 0; | ||
799 | } | ||
800 | |||
801 | void KOListView::defaultItemAction(QListViewItem *i) | ||
802 | { | ||
803 | KOListViewItem *item = static_cast<KOListViewItem *>( i ); | ||
804 | if ( item ) defaultAction( item->data() ); | ||
805 | |||
806 | } | ||
807 | |||
808 | void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) | ||
809 | { | ||
810 | mActiveItem = (KOListViewItem *)item; | ||
811 | if (mActiveItem) { | ||
812 | Incidence *incidence = mActiveItem->data(); | ||
813 | mPopupMenu->showIncidencePopup(incidence); | ||
814 | |||
815 | /* | ||
816 | if ( incidence && incidence->type() == "Event" ) { | ||
817 | Event *event = static_cast<Event *>( incidence ); | ||
818 | mPopupMenu->showEventPopup(event); | ||
819 | } | ||
820 | */ | ||
821 | } | ||
822 | } | ||
823 | |||
824 | void KOListView::readSettings(KConfig *config, QString setting) | ||
825 | { | ||
826 | // qDebug("KOListView::readSettings "); | ||
827 | mListView->restoreLayout(config,setting); | ||
828 | } | ||
829 | |||
830 | void KOListView::writeSettings(KConfig *config, QString setting) | ||
831 | { | ||
832 | // qDebug("KOListView::writeSettings "); | ||
833 | mListView->saveLayout(config, setting); | ||
834 | } | ||
835 | |||
836 | void KOListView::processSelectionChange(QListViewItem *) | ||
837 | { | ||
838 | |||
839 | KOListViewItem *item = | ||
840 | static_cast<KOListViewItem *>( mListView->currentItem() ); | ||
841 | |||
842 | if ( !item ) { | ||
843 | emit incidenceSelected( 0 ); | ||
844 | } else { | ||
845 | emit incidenceSelected( item->data() ); | ||
846 | } | ||
847 | } | ||
848 | |||
849 | void KOListView::clearSelection() | ||
850 | { | ||
851 | mListView->selectAll( false ); | ||
852 | } | ||
853 | void KOListView::allSelection() | ||
854 | { | ||
855 | mListView->selectAll( true ); | ||
856 | } | ||
857 | |||
858 | void KOListView::clear() | ||
859 | { | ||
860 | mListView->clear(); | ||
861 | mUidDict.clear(); | ||
862 | } | ||
863 | |||
864 | Incidence* KOListView::currentItem() | ||
865 | { | ||
866 | if ( mListView->currentItem() ) | ||
867 | return ((KOListViewItem*) mListView->currentItem())->data(); | ||
868 | return 0; | ||
869 | } | ||
870 | void KOListView::keyPressEvent ( QKeyEvent *e) | ||
871 | { | ||
872 | |||
873 | if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { | ||
874 | deleteAll(); | ||
875 | return; | ||
876 | } | ||
877 | |||
878 | e->ignore(); | ||
879 | } | ||
880 | void KOListViewListView::keyPressEvent ( QKeyEvent *e) | ||
881 | { | ||
882 | |||
883 | switch ( e->key() ) { | ||
884 | case Qt::Key_Down: | ||
885 | if ( e->state() == ShiftButton ) { | ||
886 | QListViewItem* cn = currentItem(); | ||
887 | if ( !cn ) | ||
888 | cn = firstChild(); | ||
889 | if ( !cn ) | ||
890 | return; | ||
891 | while ( cn->nextSibling() ) | ||
892 | cn = cn->nextSibling(); | ||
893 | setCurrentItem ( cn ); | ||
894 | ensureItemVisible ( cn ); | ||
895 | |||
896 | e->accept(); | ||
897 | return; | ||
898 | } | ||
899 | if ( e->state() == ControlButton ) { | ||
900 | int count = childCount (); | ||
901 | int jump = count / 5; | ||
902 | QListViewItem* cn; | ||
903 | cn = currentItem(); | ||
904 | if ( ! cn ) | ||
905 | return; | ||
906 | if ( jump == 0 ) | ||
907 | jump = 1; | ||
908 | while ( jump && cn->nextSibling() ) { | ||
909 | cn = cn->nextSibling(); | ||
910 | --jump; | ||
911 | } | ||
912 | setCurrentItem ( cn ); | ||
913 | ensureItemVisible ( cn ); | ||
914 | |||
915 | } else | ||
916 | QListView::keyPressEvent ( e ) ; | ||
917 | e->accept(); | ||
918 | break; | ||
919 | |||
920 | case Qt::Key_Up: | ||
921 | if ( e->state() == ShiftButton ) { | ||
922 | QListViewItem* cn = firstChild(); | ||
923 | if ( cn ) { | ||
924 | setCurrentItem ( cn ); | ||
925 | ensureItemVisible ( cn ); | ||
926 | } | ||
927 | e->accept(); | ||
928 | return; | ||
929 | } | ||
930 | if ( e->state() == ControlButton ) { | ||
931 | int count = childCount (); | ||
932 | int jump = count / 5; | ||
933 | QListViewItem* cn; | ||
934 | cn = currentItem(); | ||
935 | if ( ! cn ) | ||
936 | return; | ||
937 | if ( jump == 0 ) | ||
938 | jump = 1; | ||
939 | while ( jump && cn->itemAbove ()) { | ||
940 | cn = cn->itemAbove (); | ||
941 | --jump; | ||
942 | } | ||
943 | setCurrentItem ( cn ); | ||
944 | ensureItemVisible ( cn ); | ||
945 | } else | ||
946 | QListView::keyPressEvent ( e ) ; | ||
947 | e->accept(); | ||
948 | break; | ||
949 | case Qt::Key_I: { | ||
950 | QListViewItem* cn; | ||
951 | cn = currentItem(); | ||
952 | if ( cn ) { | ||
953 | KOListViewItem* ci = (KOListViewItem*)( cn ); | ||
954 | if ( ci ){ | ||
955 | emit showIncidence( ci->data()); | ||
956 | cn = cn->nextSibling(); | ||
957 | if ( cn ) { | ||
958 | setCurrentItem ( cn ); | ||
959 | ensureItemVisible ( cn ); | ||
960 | } | ||
961 | } | ||
962 | } | ||
963 | e->accept(); | ||
964 | } | ||
965 | break; | ||
966 | case Qt::Key_Return: | ||
967 | case Qt::Key_Enter: | ||
968 | { | ||
969 | QListViewItem* cn; | ||
970 | cn = currentItem(); | ||
971 | if ( cn ) { | ||
972 | KOListViewItem* ci = (KOListViewItem*)( cn ); | ||
973 | if ( ci ){ | ||
974 | if ( e->state() == ShiftButton ) | ||
975 | ci->setSelected( false ); | ||
976 | else | ||
977 | ci->setSelected( true ); | ||
978 | cn = cn->nextSibling(); | ||
979 | if ( cn ) { | ||
980 | setCurrentItem ( cn ); | ||
981 | ensureItemVisible ( cn ); | ||
982 | } | ||
983 | } | ||
984 | } | ||
985 | e->accept(); | ||
986 | } | ||
987 | break; | ||
988 | default: | ||
989 | e->ignore(); | ||
990 | } | ||
991 | } | ||
992 | KOListViewListView::KOListViewListView(KOListView * lv ) | ||
993 | : KListView( lv ) | ||
994 | { | ||
995 | #ifndef DESKTOP_VERSION | ||
996 | QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); | ||
997 | #endif | ||
998 | setSelectionMode( QListView::Multi ); | ||
999 | setMultiSelection( true); | ||
1000 | mAllowPopupMenu = true; | ||
1001 | mMouseDown = false; | ||
1002 | |||
1003 | } | ||
1004 | void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) | ||
1005 | { | ||
1006 | if (!e) return; | ||
1007 | QPoint vp = contentsToViewport(e->pos()); | ||
1008 | QListViewItem *item = itemAt(vp); | ||
1009 | if (!item) { | ||
1010 | emit newEvent(); | ||
1011 | return; | ||
1012 | } | ||
1013 | KListView::contentsMouseDoubleClickEvent(e); | ||
1014 | } | ||
1015 | |||
1016 | |||
1017 | void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) | ||
1018 | { | ||
1019 | //qDebug("contentsMousePressEvent++++ "); | ||
1020 | if (! mMouseDown ) { | ||
1021 | mAllowPopupMenu = true; | ||
1022 | mYMousePos = mapToGlobal( (e->pos())).y(); | ||
1023 | } | ||
1024 | if ( e->button() == RightButton && mMouseDown ) | ||
1025 | return; | ||
1026 | if ( e->button() == LeftButton ) | ||
1027 | mMouseDown = true; | ||
1028 | KListView::contentsMousePressEvent( e ); | ||
1029 | } | ||
1030 | void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) | ||
1031 | { | ||
1032 | //qDebug("contentsMouseReleaseEv---- "); | ||
1033 | if ( ! mMouseDown ) { | ||
1034 | if ( e->button() == RightButton && ! mAllowPopupMenu ) | ||
1035 | return; | ||
1036 | QListViewItem* ci = currentItem(); | ||
1037 | if ( ci ) | ||
1038 | ci->setSelected( true ); | ||
1039 | KListView::contentsMouseReleaseEvent(e); | ||
1040 | return; | ||
1041 | } | ||
1042 | if ( e->button() == LeftButton ) | ||
1043 | mMouseDown = false; | ||
1044 | if ( e->button() == RightButton && ! mAllowPopupMenu ) | ||
1045 | return; | ||
1046 | if ( e->button() == RightButton ) { | ||
1047 | QListViewItem* ci = currentItem(); | ||
1048 | if ( ci ) | ||
1049 | ci->setSelected( true ); | ||
1050 | } | ||
1051 | KListView::contentsMouseReleaseEvent(e); | ||
1052 | } | ||
1053 | void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) | ||
1054 | { | ||
1055 | // qDebug("contentsMouseMoveEv....... "); | ||
1056 | // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() ); | ||
1057 | int diff = mYMousePos - mapToGlobal( (e->pos())).y(); | ||
1058 | if ( diff < 0 ) diff = -diff; | ||
1059 | if ( diff > 20 ) | ||
1060 | mAllowPopupMenu = false; | ||
1061 | KListView::contentsMouseMoveEvent(e); | ||
1062 | } | ||