summaryrefslogtreecommitdiffabout
path: root/korganizer/kofilterview.cpp
Unidiff
Diffstat (limited to 'korganizer/kofilterview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kofilterview.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/korganizer/kofilterview.cpp b/korganizer/kofilterview.cpp
index ff80afc..7ce3f1f 100644
--- a/korganizer/kofilterview.cpp
+++ b/korganizer/kofilterview.cpp
@@ -1,135 +1,136 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
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 <qcombobox.h> 25#include <qcombobox.h>
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qdialog.h> 29#include <qdialog.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32 32
33 33
34#include <libkcal/calfilter.h> 34#include <libkcal/calfilter.h>
35 35
36#include "kofilterview.h" 36#include "kofilterview.h"
37#include "koprefs.h" 37#include "koprefs.h"
38#include <kiconloader.h> 38#include <kiconloader.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <kglobalsettings.h>
40#include <kcolorbutton.h> 41#include <kcolorbutton.h>
41#include <kmessagebox.h> 42#include <kmessagebox.h>
42 43
43 44
44 45
45 46
46 47
47KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, 48KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent,
48 const char* name,WFlags fl ) 49 const char* name,WFlags fl )
49 : KOFilterView_base(parent,name,fl) 50 : KOFilterView_base(parent,name,fl)
50{ 51{
51 mFilters = filterList; 52 mFilters = filterList;
52 53
53 connect(mSelectionCombo,SIGNAL(activated(int)),SIGNAL(filterChanged())); 54 connect(mSelectionCombo,SIGNAL(activated(int)),SIGNAL(filterChanged()));
54 connect(mEnabledCheck,SIGNAL(clicked()),SIGNAL(filterChanged())); 55 connect(mEnabledCheck,SIGNAL(clicked()),SIGNAL(filterChanged()));
55 connect(mEditButton,SIGNAL(clicked()),SIGNAL(editFilters())); 56 connect(mEditButton,SIGNAL(clicked()),SIGNAL(editFilters()));
56} 57}
57 58
58KOFilterView::~KOFilterView() 59KOFilterView::~KOFilterView()
59{ 60{
60 // no need to delete child widgets, Qt does it all for us 61 // no need to delete child widgets, Qt does it all for us
61} 62}
62 63
63bool KOFilterView::filtersEnabled() 64bool KOFilterView::filtersEnabled()
64{ 65{
65 return mEnabledCheck->isChecked(); 66 return mEnabledCheck->isChecked();
66} 67}
67 68
68void KOFilterView::setFiltersEnabled(bool set) 69void KOFilterView::setFiltersEnabled(bool set)
69{ 70{
70 mEnabledCheck->setChecked(set); 71 mEnabledCheck->setChecked(set);
71 emit filterChanged(); 72 emit filterChanged();
72} 73}
73 74
74 75
75void KOFilterView::updateFilters() 76void KOFilterView::updateFilters()
76{ 77{
77 mSelectionCombo->clear(); 78 mSelectionCombo->clear();
78 79
79 CalFilter *filter = mFilters->first(); 80 CalFilter *filter = mFilters->first();
80 while(filter) { 81 while(filter) {
81 mSelectionCombo->insertItem(filter->name()); 82 mSelectionCombo->insertItem(filter->name());
82 filter = mFilters->next(); 83 filter = mFilters->next();
83 } 84 }
84} 85}
85 86
86CalFilter *KOFilterView::selectedFilter() 87CalFilter *KOFilterView::selectedFilter()
87{ 88{
88 CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); 89 CalFilter *f = mFilters->at(mSelectionCombo->currentItem());
89 return f; 90 return f;
90} 91}
91 92
92void KOFilterView::setSelectedFilter(QString filterName) 93void KOFilterView::setSelectedFilter(QString filterName)
93{ 94{
94 int filter_num = mSelectionCombo->count(); 95 int filter_num = mSelectionCombo->count();
95 int i; 96 int i;
96 for (i=0;i<filter_num;i++) { 97 for (i=0;i<filter_num;i++) {
97 if (mSelectionCombo->text(i)==filterName) 98 if (mSelectionCombo->text(i)==filterName)
98 mSelectionCombo->setCurrentItem(i); 99 mSelectionCombo->setCurrentItem(i);
99 } 100 }
100 emit filterChanged(); 101 emit filterChanged();
101} 102}
102void KOFilterView::setSelectedFilter( int fil ) 103void KOFilterView::setSelectedFilter( int fil )
103{ 104{
104 if ( fil >= mSelectionCombo->count() ) 105 if ( fil >= mSelectionCombo->count() )
105 return; 106 return;
106 mSelectionCombo->setCurrentItem( fil ); 107 mSelectionCombo->setCurrentItem( fil );
107 emit filterChanged(); 108 emit filterChanged();
108} 109}
109 110
110 111
111 112
112KOCalEditView::KOCalEditView(QWidget* parent, 113KOCalEditView::KOCalEditView(QWidget* parent,
113 const char* name ) 114 const char* name )
114 : QScrollView(parent,name) 115 : QScrollView(parent,name)
115{ 116{
116 mw = 0; 117 mw = 0;
117 setResizePolicy( AutoOneFit ); 118 setResizePolicy( AutoOneFit );
118 setFrameStyle ( QFrame::Panel | QFrame::Plain ); 119 setFrameStyle ( QFrame::Panel | QFrame::Plain );
119 setLineWidth ( 1 ); 120 setLineWidth ( 1 );
120 setMidLineWidth ( 1 ); 121 setMidLineWidth ( 1 );
121 setFocusPolicy(NoFocus); 122 setFocusPolicy(NoFocus);
122} 123}
123 124
124KOCalEditView::~KOCalEditView() 125KOCalEditView::~KOCalEditView()
125{ 126{
126 // no need to delete child widgets, Qt does it all for us 127 // no need to delete child widgets, Qt does it all for us
127} 128}
128void KOCalEditView::selectCal(int id ,bool b) 129void KOCalEditView::selectCal(int id ,bool b)
129{ 130{
130 KOPrefs::instance()->getCalendar( id )->isEnabled = b; 131 KOPrefs::instance()->getCalendar( id )->isEnabled = b;
131 emit calendarEnabled ( id, b ); 132 emit calendarEnabled ( id, b );
132 emit needsUpdate(); 133 emit needsUpdate();
133 134
134} 135}
135void KOCalEditView::selectStdCal( int id ) 136void KOCalEditView::selectStdCal( int id )
@@ -305,165 +306,181 @@ void KOCalEditView::readConfig()
305 if ( kkf->mErrorOnLoad || kkf->isReadOnly ) 306 if ( kkf->mErrorOnLoad || kkf->isReadOnly )
306 rb->setEnabled( false ); 307 rb->setEnabled( false );
307 KOCalCheckButton* cb = new KOCalCheckButton( mw ); 308 KOCalCheckButton* cb = new KOCalCheckButton( mw );
308 mainLayout->addWidget( cb,row,++iii );mEnabledB.append( cb ); 309 mainLayout->addWidget( cb,row,++iii );mEnabledB.append( cb );
309 cb->setChecked( kkf->isEnabled && !kkf->mErrorOnLoad ); 310 cb->setChecked( kkf->isEnabled && !kkf->mErrorOnLoad );
310 cb->setNum( kkf->mCalNumber ); 311 cb->setNum( kkf->mCalNumber );
311 if ( kkf->mErrorOnLoad ) 312 if ( kkf->mErrorOnLoad )
312 cb->setEnabled( false ); 313 cb->setEnabled( false );
313 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) ); 314 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) );
314 KOCalButton* name = new KOCalButton( mw ); 315 KOCalButton* name = new KOCalButton( mw );
315 name->setNum( kkf->mCalNumber ); 316 name->setNum( kkf->mCalNumber );
316 name->setText( kkf->mName ); 317 name->setText( kkf->mName );
317 mainLayout->addWidget( name,row,++iii ); 318 mainLayout->addWidget( name,row,++iii );
318 connect (name, SIGNAL (selectNum(int)), SLOT ( infoCal(int) ) ); 319 connect (name, SIGNAL (selectNum(int)), SLOT ( infoCal(int) ) );
319 //lab = new QLabel (" ", mw ); 320 //lab = new QLabel (" ", mw );
320 //mainLayout->addWidget( lab,row,++iii ); 321 //mainLayout->addWidget( lab,row,++iii );
321 cb = new KOCalCheckButton( mw ); 322 cb = new KOCalCheckButton( mw );
322 mainLayout->addWidget( cb,row,++iii );mAlarmB.append( cb ); 323 mainLayout->addWidget( cb,row,++iii );mAlarmB.append( cb );
323 cb->setChecked( kkf->isAlarmEnabled && !kkf->mErrorOnLoad); 324 cb->setChecked( kkf->isAlarmEnabled && !kkf->mErrorOnLoad);
324 cb->setNum( kkf->mCalNumber ); 325 cb->setNum( kkf->mCalNumber );
325 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) ); 326 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) );
326 if ( kkf->mErrorOnLoad ) 327 if ( kkf->mErrorOnLoad )
327 cb->setEnabled( false ); 328 cb->setEnabled( false );
328 cb = new KOCalCheckButton( mw ); 329 cb = new KOCalCheckButton( mw );
329 mainLayout->addWidget( cb,row,++iii );mROB.append( cb ); 330 mainLayout->addWidget( cb,row,++iii );mROB.append( cb );
330 cb->setChecked( kkf->isReadOnly ); 331 cb->setChecked( kkf->isReadOnly );
331 cb->setNum( kkf->mCalNumber ); 332 cb->setNum( kkf->mCalNumber );
332 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) ); 333 connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) );
333 if ( kkf->mErrorOnLoad ) 334 if ( kkf->mErrorOnLoad )
334 cb->setEnabled( false ); 335 cb->setEnabled( false );
335 if ( row > 1) { 336 if ( row > 1) {
336 KColorButton *colb = new KColorButton( mw ); 337 KColorButton *colb = new KColorButton( mw );
337 mainLayout->addWidget( colb,row,++iii ); 338 mainLayout->addWidget( colb,row,++iii );
338 colb->setID( kkf->mCalNumber ); 339 colb->setID( kkf->mCalNumber );
339 colb->setColor( kkf->mDefaultColor ); 340 colb->setColor( kkf->mDefaultColor );
340 connect (colb, SIGNAL (changedID(const QColor&, int )), SLOT ( setColor(const QColor&,int) ) ); 341 connect (colb, SIGNAL (changedID(const QColor&, int )), SLOT ( setColor(const QColor&,int) ) );
341 KOCalButton* calb = new KOCalButton( mw ); 342 KOCalButton* calb = new KOCalButton( mw );
342 mainLayout->addWidget( calb,row,++iii ); 343 mainLayout->addWidget( calb,row,++iii );
343 calb->setNum( kkf->mCalNumber ); 344 calb->setNum( kkf->mCalNumber );
344 calb->setPixmap ( SmallIcon("minus")); 345 calb->setPixmap ( SmallIcon("minus"));
345 connect (calb, SIGNAL (selectNum(int)), SLOT ( deleteCal(int) ) ); 346 connect (calb, SIGNAL (selectNum(int)), SLOT ( deleteCal(int) ) );
346 int hei = calb->sizeHint().height(); 347 int hei = calb->sizeHint().height();
347 //calb->setMaximumSize( hei*9/10, hei*9/10 ); 348 //calb->setMaximumSize( hei*9/10, hei*9/10 );
348 } 349 }
349 ++row; 350 ++row;
350 kkf = KOPrefs::instance()->mCalendars.next(); 351 kkf = KOPrefs::instance()->mCalendars.next();
351 } 352 }
352 if ( errorLoadStandard ) 353 if ( errorLoadStandard )
353 findNewStandard(); 354 findNewStandard();
354 lab = new QLabel ( "", mw ); 355 lab = new QLabel ( "", mw );
355 mainLayout->addWidget( lab,row,0 ); 356 mainLayout->addWidget( lab,row,0 );
356 mw->show(); 357 mw->show();
357 358
358} 359}
359 360
360void KOCalEditView::defaultInfo() 361void KOCalEditView::defaultInfo()
361{ 362{
362 KMessageBox::information( this, i18n("Please choose the <b>default calendar</b> in this column. Newly created or imported items are added to the default calendar.") ); 363 KMessageBox::information( this, i18n("Please choose the <b>default calendar</b> in this column. Newly created or imported items are added to the default calendar.") );
363} 364}
364void KOCalEditView::addCal() 365void KOCalEditView::addCal()
365{ 366{
366 bool tryagain = true; 367 bool tryagain = true;
367 QString name, file; 368 QString name, file;
368 while ( tryagain ) { 369 while ( tryagain ) {
369 KONewCalPrefs prefs ( this ); 370 KONewCalPrefs prefs ( this );
370 prefs.nameE->setText( name ); 371 prefs.nameE->setText( name );
371 prefs.url->setURL( file ); 372 prefs.url->setURL( file );
372 if ( ! prefs.exec() ) 373 if ( ! prefs.exec() )
373 return; 374 return;
374 name = prefs.calName(); 375 name = prefs.calName();
375 file = prefs.calFileName(); 376 file = prefs.calFileName();
376 tryagain = false; 377 tryagain = false;
377 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 378 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
378 while ( kkf ) { 379 while ( kkf ) {
379 if ( kkf->mName == name ) { 380 if ( kkf->mName == name ) {
380 KMessageBox::information( this, i18n("Sorry, the calendar name \n%1\nalready exists!\nPlease choose another name!").arg( name ) ); 381 KMessageBox::information( this, i18n("Sorry, the calendar name \n%1\nalready exists!\nPlease choose another name!").arg( name ) );
381 name = ""; 382 name = "";
382 tryagain = true; 383 tryagain = true;
383 break; 384 break;
384 } 385 }
385 if ( kkf->mFileName == file ) { 386 if ( kkf->mFileName == file ) {
386 KMessageBox::information( this, i18n("Sorry, the file \n%1\nis already loaded!\nPlease choose another file!").arg( KGlobal::formatMessage (file, 0 )) ); 387 KMessageBox::information( this, i18n("Sorry, the file \n%1\nis already loaded!\nPlease choose another file!").arg( KGlobal::formatMessage (file, 0 )) );
387 tryagain = true; 388 tryagain = true;
388 file = ""; 389 file = "";
389 break; 390 break;
390 } 391 }
391 kkf = KOPrefs::instance()->mCalendars.next(); 392 kkf = KOPrefs::instance()->mCalendars.next();
392 } 393 }
393 } 394 }
394 addCalendar ( name, file ); 395 addCalendar ( name, file );
395 QTimer::singleShot( 100, this, SIGNAL ( checkCalendar() ) ); 396 QTimer::singleShot( 100, this, SIGNAL ( checkCalendar() ) );
396} 397}
397int KOCalEditView::addCalendar( QString name, QString file, bool ask ) 398int KOCalEditView::addCalendar( QString name, QString file, bool ask )
398{ 399{
399 400
400 QFileInfo fi ( file ); 401 QFileInfo fi ( file );
402 QString absFile = file;
403 bool isRelative = false;
404 if ( fi.isRelative() ) {
405 isRelative = true;
406 absFile = KGlobalSettings::calendarDir()+file;
407 fi.setFile( absFile );
408 } else {
409 QString cd = KGlobalSettings::calendarDir();
410 if ( file.left( cd.length() ) == cd ) {
411 isRelative = true;
412 file = fi.fileName ();
413 fi.setFile( absFile );
414 }
415 }
401 if (!fi.exists() ) { 416 if (!fi.exists() ) {
402 if ( ask ) 417 if ( ask )
403 if ( KMessageBox::questionYesNo(this, i18n("The file\n%1\ndoes not exist!\nShall I create it for you?").arg( file ) )== KMessageBox::No ) 418 if ( KMessageBox::questionYesNo(this, i18n("The file\n%1\ndoes not exist!\nShall I create it for you?").arg( KGlobal::formatMessage (absFile,0) ) )== KMessageBox::No )
404 return 0; 419 return 0;
405 QFile fileIn( file ); 420 QFile fileIn( absFile );
406 if (!fileIn.open( IO_WriteOnly ) ) { 421 if (!fileIn.open( IO_WriteOnly ) ) {
407 KMessageBox::sorry( this, i18n("Sorry, cannot create the file\n%1!\nNo calendar added!").arg( file ) ); 422 KMessageBox::sorry( this, i18n("Sorry, cannot create the file\n%1!\nNo calendar added!").arg( file ) );
408 return 0; 423 return 0;
409 } 424 }
410 QTextStream tsIn( &fileIn ); 425 QTextStream tsIn( &fileIn );
411 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 426 tsIn.setCodec( QTextCodec::codecForName("utf8") );
412 tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n"; 427 tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n";
413 fileIn.close(); 428 fileIn.close();
414 } 429 }
415 KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); 430 KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar();
416 kkf->mName = name; 431 kkf->mName = name;
417 kkf->mFileName = file; 432 kkf->mFileName = absFile;
433 kkf->mSavedFileName = file;
434 kkf->isRelative = isRelative;
418 emit calendarAdded( kkf->mCalNumber ); 435 emit calendarAdded( kkf->mCalNumber );
419 if ( ask ) 436 if ( ask )
420 emit needsUpdate(); 437 emit needsUpdate();
421 QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); 438 QTimer::singleShot( 0, this, SLOT ( readConfig() ) );
422 return kkf->mCalNumber; 439 return kkf->mCalNumber;
423} 440}
424int KOCalEditView::getBirtdayID() 441int KOCalEditView::getBirtdayID()
425{ 442{
426 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 443 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
427 while ( kkf ) { 444 while ( kkf ) {
428 if ( kkf->mName == i18n("Birthdays") ) 445 if ( kkf->mName == i18n("Birthdays") )
429 return kkf->mCalNumber; 446 return kkf->mCalNumber;
430 kkf = KOPrefs::instance()->mCalendars.next(); 447 kkf = KOPrefs::instance()->mCalendars.next();
431 } 448 }
432 QString file = locateLocal( "data", "korganizer/birthdays.ics" ); 449 QString file = locateLocal( "data", "korganizer/birthdays.ics" );
433 return addCalendar( i18n("Birthdays"), file, false ); 450 return addCalendar( i18n("Birthdays"), file, false );
434} 451}
435 452
436void KOCalEditView::enableAll() 453void KOCalEditView::enableAll()
437{ 454{
438 toggleList( mEnabledB ); 455 toggleList( mEnabledB );
439} 456}
440void KOCalEditView::enableAlarm() 457void KOCalEditView::enableAlarm()
441{ 458{
442 toggleList( mAlarmB ); 459 toggleList( mAlarmB );
443} 460}
444void KOCalEditView::disableRO() 461void KOCalEditView::disableRO()
445{ 462{
446 toggleList( mROB, false ); 463 toggleList( mROB, false );
447} 464}
448void KOCalEditView::toggleList ( QPtrList<KOCalCheckButton> list , bool enable ) 465void KOCalEditView::toggleList ( QPtrList<KOCalCheckButton> list , bool enable )
449{ 466{
450 bool dis = !enable; 467 bool dis = !enable;
451 KOCalCheckButton* it = list.first(); 468 KOCalCheckButton* it = list.first();
452 while ( it ) { 469 while ( it ) {
453 if ( !it->isChecked() == enable && it->isEnabled() ) { 470 if ( !it->isChecked() == enable && it->isEnabled() ) {
454 dis = !dis; 471 dis = !dis;
455 break; 472 break;
456 } 473 }
457 it = list.next(); 474 it = list.next();
458 } 475 }
459 it = list.first(); 476 it = list.first();
460 while ( it ) { 477 while ( it ) {
461 if ( it->isEnabled() ) 478 if ( it->isEnabled() )
462 it->setChecked(dis); 479 it->setChecked(dis);
463 it = list.next(); 480 it = list.next();
464 } 481 }
465} 482}
466void KOCalEditView::deleteAll() 483void KOCalEditView::deleteAll()
467{ 484{
468 qDebug("delteAll"); 485 qDebug("delteAll");
469} 486}