korganizer

koprefsdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <qlayout.h>
00027 #include <qlabel.h>
00028 #include <qgroupbox.h>
00029 #include <qbuttongroup.h>
00030 #include <qlineedit.h>
00031 #include <qslider.h>
00032 #include <qfile.h>
00033 #include <qcombobox.h>
00034 #include <qhbox.h>
00035 #include <qvbox.h>
00036 #include <qgrid.h>
00037 #include <qspinbox.h>
00038 #include <qcheckbox.h>
00039 #include <qradiobutton.h>
00040 #include <qpushbutton.h>
00041 #include <qstrlist.h>
00042 #include <qlistview.h>
00043 #include <qtabwidget.h>
00044 #include <qwhatsthis.h>
00045 
00046 #include <kcolorbutton.h>
00047 #include <kdebug.h>
00048 #include <klocale.h>
00049 #include <kglobal.h>
00050 #include <kmessagebox.h>
00051 #include <kiconloader.h>
00052 #include <kemailsettings.h>
00053 #include <kcalendarsystem.h>
00054 #include <ktrader.h>
00055 #include <kpushbutton.h>
00056 #include <kocore.h>
00057 #include <libkcal/calendarresources.h>
00058 #include <kstandarddirs.h>
00059 #include <ksimpleconfig.h>
00060 #include <kholidays.h>
00061 
00062 #if defined(USE_SOLARIS)
00063 #include <sys/param.h>
00064 
00065 #define ZONEINFODIR    "/usr/share/lib/zoneinfo"
00066 #define INITFILE       "/etc/default/init"
00067 #endif
00068 
00069 #include "koprefs.h"
00070 
00071 #include "koprefsdialog.h"
00072 #include "kogroupwareprefspage.h"
00073 #include "ktimeedit.h"
00074 #include "koglobals.h"
00075 #include "stdcalendar.h"
00076 #include <kdepimmacros.h>
00077 
00078 
00079 KOPrefsDialogMain::KOPrefsDialogMain( QWidget *parent, const char *name )
00080   : KPrefsModule( KOPrefs::instance(), parent, name )
00081 {
00082   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00083 
00084   QVBox *topFrame = new QVBox( this );
00085   topTopLayout->addWidget( topFrame );
00086 
00087   topFrame->setSpacing( KDialog::spacingHint() );
00088 
00089   KPrefsWidBool *emailControlCenter =
00090       addWidBool( KOPrefs::instance()->emailControlCenterItem(), topFrame );
00091   connect(emailControlCenter->checkBox(),SIGNAL(toggled(bool)),
00092           SLOT(toggleEmailSettings(bool)));
00093 
00094   mUserEmailSettings = new QGrid( 2, topFrame );
00095 
00096   addWidString( KOPrefs::instance()->userNameItem(), mUserEmailSettings );
00097   addWidString( KOPrefs::instance()->userEmailItem(), mUserEmailSettings );
00098 
00099   QGroupBox *saveGroup = new QGroupBox(1,Horizontal,i18n("Saving Calendar"),
00100                                            topFrame);
00101 
00102   addWidBool( KOPrefs::instance()->htmlWithSaveItem(), saveGroup );
00103 
00104   KPrefsWidBool *autoSave = addWidBool( KOPrefs::instance()->autoSaveItem(), saveGroup );
00105 
00106   QHBox *intervalBox = new QHBox( saveGroup );
00107   addWidInt( KOPrefs::instance()->autoSaveIntervalItem(), intervalBox );
00108   connect( autoSave->checkBox(), SIGNAL( toggled( bool ) ),
00109            intervalBox, SLOT( setEnabled( bool ) ) );
00110   intervalBox->setSpacing( KDialog::spacingHint() );
00111   new QWidget( intervalBox );
00112 
00113   addWidBool( KOPrefs::instance()->confirmItem(), topFrame );
00114   addWidRadios( KOPrefs::instance()->destinationItem(), topFrame);
00115 
00116   topTopLayout->addStretch( 1 );
00117 
00118   load();
00119 }
00120 
00121 void KOPrefsDialogMain::toggleEmailSettings( bool on )
00122 {
00123   mUserEmailSettings->setEnabled( !on );
00124 /*  if (on) {
00125     KEMailSettings settings;
00126     mNameEdit->setText( settings.getSetting(KEMailSettings::RealName) );
00127     mEmailEdit->setText( settings.getSetting(KEMailSettings::EmailAddress) );
00128   } else {
00129     mNameEdit->setText( KOPrefs::instance()->mName );
00130     mEmailEdit->setText( KOPrefs::instance()->mEmail );
00131   }*/
00132 }
00133 
00134 extern "C"
00135 {
00136   KDE_EXPORT KCModule *create_korganizerconfigmain( QWidget *parent, const char * )
00137   {
00138     return new KOPrefsDialogMain( parent, "kcmkorganizermain" );
00139   }
00140 }
00141 
00142 
00143 class KOPrefsDialogTime : public KPrefsModule
00144 {
00145   public:
00146     KOPrefsDialogTime( QWidget *parent, const char *name )
00147       : KPrefsModule( KOPrefs::instance(), parent, name )
00148     {
00149       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00150 
00151       QWidget *topFrame = new QWidget( this );
00152       topTopLayout->addWidget( topFrame );
00153 
00154       QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
00155       topLayout->setSpacing( KDialog::spacingHint() );
00156 
00157       QHBox *timeZoneBox = new QHBox( topFrame );
00158       topLayout->addMultiCellWidget( timeZoneBox, 0, 0, 0, 1 );
00159 
00160       QLabel *timeZoneLabel = new QLabel( i18n("Timezone:"), timeZoneBox );
00161       QString whatsThis = i18n( "Select your timezone from the list of "
00162                                 "locations on this drop down box. If your city "
00163                                 "is not listed, select one which shares the "
00164                                 "same timezone. KOrganizer will automatically "
00165                                 "adjust for daylight savings." );
00166       QWhatsThis::add( timeZoneLabel, whatsThis );
00167       mTimeZoneCombo = new QComboBox( timeZoneBox );
00168 
00169       connect( mTimeZoneCombo, SIGNAL( activated( int ) ),
00170                SLOT( slotWidChanged() ) );
00171 
00172       FILE *f;
00173       char tempstring[101] = "Unknown";
00174       QString sCurrentlySet(i18n("Unknown"));
00175       int nCurrentlySet = 0;
00176       QStringList list;
00177 
00178       // read the currently set time zone
00179     #if defined(USE_SOLARIS)       // MARCO
00180         char buf[MAXPATHLEN];
00181 
00182         snprintf(buf, MAXPATHLEN,
00183                 "/bin/fgrep 'TZ=' %s | /bin/head -n 1 | /bin/cut -b 4-",
00184                 INITFILE);
00185 
00186         if (f = popen(buf, "r"))
00187           {
00188            if (fgets(buf, MAXPATHLEN - 1, f) != NULL)
00189              {
00190                buf[strlen(buf) - 1] = '\0';
00191                sCurrentlySet = QString(buf);
00192              }
00193            pclose(f);
00194           }
00195     #else
00196       if((f = fopen("/etc/timezone", "r")) != NULL) {
00197         // get the currently set timezone
00198         fgets(tempstring, 100, f);
00199         tempstring[strlen(tempstring) - 1] = '\0';
00200         sCurrentlySet = QString(tempstring);
00201         fclose(f);
00202       }
00203     #endif // !USE_SOLARIS
00204 
00205       mTimeZoneCombo->insertItem(i18n("[No selection]"));
00206 
00207       // Read all system time zones
00208     #if defined(USE_SOLARIS)       // MARCO
00209         snprintf(buf, MAXPATHLEN,
00210                "/bin/find %s \\( -name src -prune \\) -o -type f -print | /bin/cut -b %d-",
00211                ZONEINFODIR, strlen(ZONEINFODIR) + 2);
00212 
00213         if (f = popen(buf, "r"))
00214           {
00215            while(fgets(buf, MAXPATHLEN - 1, f) != NULL)
00216              {
00217                buf[strlen(buf) - 1] = '\0';
00218                list.append(buf);
00219              }
00220            pclose(f);
00221           }
00222 
00223     #else
00224       f = popen("grep -e  ^[^#] /usr/share/zoneinfo/zone.tab | cut -f 3","r");
00225       if (!f) return;
00226       while(fgets(tempstring, 100, f) != NULL) {
00227         tempstring[strlen(tempstring)-1] = '\0';
00228         list.append(i18n(tempstring));
00229         tzonenames << tempstring;
00230       }
00231       pclose(f);
00232     #endif // !USE_SOLARIS
00233       list.sort();
00234 
00235       mTimeZoneCombo->insertStringList(list);
00236 
00237         // find the currently set time zone and select it
00238       for ( int i = 0; i < mTimeZoneCombo->count(); ++i )
00239         {
00240           if (mTimeZoneCombo->text(i) == sCurrentlySet)
00241             {
00242              nCurrentlySet = i;
00243              break;
00244             }
00245         }
00246 
00247       mTimeZoneCombo->setCurrentItem(nCurrentlySet);
00248       QWhatsThis::add( mTimeZoneCombo, whatsThis );
00249 
00250       // holiday region selection
00251       QHBox *holidayRegBox = new QHBox( topFrame );
00252       topLayout->addMultiCellWidget( holidayRegBox, 1, 1, 0, 1 );
00253 
00254       QLabel *holidayLabel = new QLabel( i18n( "Use holiday region:" ), holidayRegBox );
00255       whatsThis = i18n( "Select from which region you want to use the "
00256                         "holidays here. Defined holidays are shown as "
00257                         "non-working days in the date navigator, the "
00258                         "agenda view, etc." );
00259       QWhatsThis::add( holidayLabel, whatsThis );
00260 
00261       mHolidayCombo = new QComboBox( holidayRegBox );
00262       connect( mHolidayCombo, SIGNAL( activated( int ) ),
00263                SLOT( slotWidChanged() ) );
00264 
00265       QWhatsThis::add( mHolidayCombo, whatsThis );
00266 
00267       QString currentHolidayName;
00268       QStringList holidayList;
00269       QStringList countryList = KHolidays::locations();
00270       QStringList::ConstIterator it;
00271 
00272       for ( it = countryList.begin(); it != countryList.end(); ++it ) {
00273         QString countryFile = locate( "locale",
00274                                       "l10n/" + (*it) + "/entry.desktop" );
00275         QString regionName;
00276         if ( !countryFile.isEmpty() ) {
00277           KSimpleConfig cfg( countryFile );
00278           cfg.setGroup( "KCM Locale" );
00279           regionName = cfg.readEntry( "Name" );
00280         }
00281         if (regionName.isEmpty()) regionName = (*it);
00282 
00283         holidayList << regionName;
00284         mRegionMap[regionName] = (*it); //store region for saving to config file
00285 
00286         if ( KOGlobals::self()->holidays()
00287              && ((*it) == KOGlobals::self()->holidays()->location()) )
00288           currentHolidayName = regionName;
00289       }
00290       holidayList.sort();
00291       holidayList.push_front( i18n("(None)") );  //be able to disable holidays
00292 
00293       mHolidayCombo->insertStringList(holidayList);
00294 
00295       for (int i=0; i < mHolidayCombo->count(); ++i) {
00296         if ( mHolidayCombo->text(i) == currentHolidayName ) {
00297           mHolidayCombo->setCurrentItem(i);
00298           break;
00299         }
00300       }
00301 
00302       KPrefsWidTime *dayBegins =
00303         addWidTime( KOPrefs::instance()->dayBeginsItem(), topFrame );
00304       topLayout->addWidget( dayBegins->label(), 2, 0 );
00305       topLayout->addWidget( dayBegins->timeEdit(), 2, 1 );
00306 
00307       KPrefsWidTime *defaultTime =
00308         addWidTime( KOPrefs::instance()->startTimeItem(), topFrame );
00309       topLayout->addWidget( defaultTime->label(), 3, 0);
00310       topLayout->addWidget( defaultTime->timeEdit(), 3, 1);
00311 
00312       KPrefsWidDuration *defaultDuration =
00313         addWidDuration( KOPrefs::instance()->defaultDurationItem(), topFrame );
00314       topLayout->addWidget( defaultDuration->label(), 4, 0 );
00315       topLayout->addWidget( defaultDuration->timeEdit(), 4, 1 );
00316 
00317       QStringList alarmList;
00318       alarmList << i18n( "1 minute" ) << i18n( "5 minutes" )
00319                 << i18n( "10 minutes" ) << i18n( "15 minutes" )
00320                 << i18n( "30 minutes" );
00321       QLabel *alarmLabel = new QLabel( i18n( "Default reminder time:" ), topFrame);
00322       topLayout->addWidget( alarmLabel, 5, 0 );
00323       QWhatsThis::add( alarmLabel,
00324                        i18n( "Enter the default reminder time here." ) );
00325       mAlarmTimeCombo = new QComboBox( topFrame );
00326       QWhatsThis::add( mAlarmTimeCombo,
00327                        i18n( "Enter the default reminder time here." ) );
00328       connect( mAlarmTimeCombo, SIGNAL( activated( int ) ),
00329                SLOT( slotWidChanged() ) );
00330       mAlarmTimeCombo->insertStringList( alarmList );
00331       topLayout->addWidget( mAlarmTimeCombo, 5, 1 );
00332 
00333 
00334       QGroupBox *workingHoursGroup = new QGroupBox(1,Horizontal,
00335                                                    i18n("Working Hours"),
00336                                                    topFrame);
00337       topLayout->addMultiCellWidget( workingHoursGroup, 6, 6, 0, 1 );
00338 
00339       QHBox *workDaysBox = new QHBox( workingHoursGroup );
00340       // Respect start of week setting
00341       int weekStart=KGlobal::locale()->weekStartDay();
00342       for ( int i = 0; i < 7; ++i ) {
00343         const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00344         QString weekDayName = calSys->weekDayName( (i + weekStart + 6)%7 + 1, true );
00345         if ( KOPrefs::instance()->mCompactDialogs ) {
00346           weekDayName = weekDayName.left( 1 );
00347         }
00348         int index = ( i + weekStart + 6 ) % 7;
00349         mWorkDays[ index ] = new QCheckBox( weekDayName, workDaysBox );
00350         QWhatsThis::add( mWorkDays[ index ],
00351                          i18n( "Check this box to make KOrganizer mark the "
00352                                "working hours for this day of the week. "
00353                                "If this is a work day for you, check "
00354                                "this box, or the working hours will not be "
00355                                "marked with color." ) );
00356 
00357         connect( mWorkDays[ index ], SIGNAL( stateChanged( int ) ),
00358                SLOT( slotWidChanged() ) );
00359       }
00360 
00361       QHBox *workStartBox = new QHBox(workingHoursGroup);
00362       addWidTime( KOPrefs::instance()->workingHoursStartItem(), workStartBox );
00363 
00364       QHBox *workEndBox = new QHBox(workingHoursGroup);
00365       addWidTime( KOPrefs::instance()->workingHoursEndItem(), workEndBox );
00366 
00367 
00368       addWidBool( KOPrefs::instance()->excludeHolidaysItem(),
00369                   workingHoursGroup );
00370 
00371       topLayout->setRowStretch(7,1);
00372 
00373       load();
00374     }
00375 
00376   protected:
00377     void usrReadConfig()
00378     {
00379       setCombo( mTimeZoneCombo,
00380                 i18n( KOPrefs::instance()->mTimeZoneId.utf8() ) );
00381 
00382       mAlarmTimeCombo->setCurrentItem( KOPrefs::instance()->mAlarmTime );
00383       for ( int i = 0; i < 7; ++i ) {
00384         mWorkDays[i]->setChecked( (1<<i) & (KOPrefs::instance()->mWorkWeekMask) );
00385       }
00386     }
00387 
00388     void usrWriteConfig()
00389     {
00390       // Find untranslated selected zone
00391       QStringList::Iterator tz;
00392       for ( tz = tzonenames.begin(); tz != tzonenames.end(); ++tz )
00393         if (mTimeZoneCombo->currentText() == i18n((*tz).utf8()))
00394           break;
00395       if (tz != tzonenames.end())
00396         KOPrefs::instance()->mTimeZoneId = (*tz);
00397       else
00398         KOPrefs::instance()->mTimeZoneId = mTimeZoneCombo->currentText();
00399 
00400       KOPrefs::instance()->mHolidays = ( mHolidayCombo->currentItem() == 0 ) ?  // (None)
00401                                        QString::null :
00402                                        mRegionMap[mHolidayCombo->currentText()];
00403 
00404       KOPrefs::instance()->mAlarmTime = mAlarmTimeCombo->currentItem();
00405       int mask = 0;
00406       for ( int i = 0; i < 7; ++i ) {
00407         if (mWorkDays[i]->isChecked()) mask = mask | (1<<i);
00408       }
00409       KOPrefs::instance()->mWorkWeekMask = mask;
00410       KOPrefs::instance()->writeConfig();
00411     }
00412 
00413     void setCombo( QComboBox *combo, const QString &text,
00414                    const QStringList *tags = 0 )
00415     {
00416       if (tags) {
00417         int i = tags->findIndex(text);
00418         if (i > 0) combo->setCurrentItem(i);
00419       } else {
00420         for(int i=0;i<combo->count();++i) {
00421           if (combo->text(i) == text) {
00422             combo->setCurrentItem(i);
00423             break;
00424           }
00425         }
00426       }
00427     }
00428 
00429   private:
00430     QComboBox    *mTimeZoneCombo;
00431     QStringList   tzonenames;
00432     QComboBox    *mHolidayCombo;
00433     QMap<QString,QString> mRegionMap;
00434     QComboBox    *mAlarmTimeCombo;
00435     QCheckBox    *mWorkDays[7];
00436 };
00437 
00438 extern "C"
00439 {
00440   KCModule *create_korganizerconfigtime( QWidget *parent, const char * )
00441   {
00442     KGlobal::locale()->insertCatalogue( "timezones" );
00443     return new KOPrefsDialogTime( parent, "kcmkorganizertime" );
00444   }
00445 }
00446 
00447 
00448 class KOPrefsDialogViews : public KPrefsModule
00449 {
00450   public:
00451     KOPrefsDialogViews( QWidget *parent, const char *name )
00452       : KPrefsModule( KOPrefs::instance(), parent, name )
00453     {
00454       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00455 
00456       QWidget *topFrame = new QWidget( this );
00457       topTopLayout->addWidget( topFrame );
00458 
00459       QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00460       topLayout->setSpacing( KDialog::spacingHint() );
00461 
00462       KPrefsWidBool *enableToolTips =
00463           addWidBool( KOPrefs::instance()->enableToolTipsItem(), topFrame );
00464       topLayout->addWidget( enableToolTips->checkBox() );
00465 
00466       KPrefsWidBool *showTodosAgenda =
00467           addWidBool( KOPrefs::instance()->showAllDayTodoItem(), topFrame );
00468       topLayout->addWidget( showTodosAgenda->checkBox() );
00469 
00470       /*** Date Navigator Group ***/
00471       QGroupBox *dateNavGroup = new QGroupBox( 1, Horizontal,
00472                                                i18n("Date Navigator"),
00473                                                topFrame );
00474       addWidBool( KOPrefs::instance()->dailyRecurItem(), dateNavGroup );
00475       addWidBool( KOPrefs::instance()->weeklyRecurItem(), dateNavGroup );
00476       topLayout->addWidget( dateNavGroup );
00477 
00478 
00479       /*** Agenda View Group ***/
00480       QGroupBox *agendaGroup = new QGroupBox( 1, Horizontal,
00481                                               i18n("Agenda View"),
00482                                               topFrame );
00483 
00484       QHBox *hourSizeBox = new QHBox( agendaGroup );
00485       KPrefsWidInt *hourSize =
00486           addWidInt( KOPrefs::instance()->hourSizeItem(), hourSizeBox );
00487       hourSize->spinBox()->setSuffix(i18n("suffix in the hour size spin box", " pixel"));
00488       // horizontal spacer:
00489       new QWidget( hourSizeBox );
00490 
00491       QHBox *nextDaysBox = new QHBox( agendaGroup );
00492       KPrefsWidInt *nextDays =
00493         addWidInt( KOPrefs::instance()->nextXDaysItem(), nextDaysBox );
00494       nextDays->spinBox()->setSuffix(i18n("suffix in the N days spin box", " days"));
00495       new QWidget( nextDaysBox );
00496 
00497       KPrefsWidBool *marcusBainsEnabled =
00498           addWidBool( KOPrefs::instance()->marcusBainsEnabledItem(), agendaGroup );
00499 
00500       KPrefsWidBool *marcusBainsShowSeconds =
00501           addWidBool( KOPrefs::instance()->marcusBainsShowSecondsItem(), agendaGroup );
00502       connect( marcusBainsEnabled->checkBox(), SIGNAL( toggled( bool ) ),
00503                marcusBainsShowSeconds->checkBox(), SLOT( setEnabled( bool ) ) );
00504 
00505       addWidBool( KOPrefs::instance()->selectionStartsEditorItem(), agendaGroup );
00506 
00507       addWidBool( KOPrefs::instance()->agendaViewUsesResourceColorItem(), agendaGroup );
00508 
00509       topLayout->addWidget( agendaGroup );
00510 
00511 
00512       /*** Month View Group ***/
00513       QGroupBox *monthGroup = new QGroupBox( 1, Horizontal,
00514                                              i18n("Month View"),
00515                                              topFrame );
00516       addWidBool( KOPrefs::instance()->enableMonthScrollItem(), monthGroup );
00517       addWidBool( KOPrefs::instance()->fullViewMonthItem(), monthGroup );
00518       addWidBool( KOPrefs::instance()->monthViewUsesCategoryColorItem(),
00519                       monthGroup );
00520       addWidBool( KOPrefs::instance()->monthViewUsesResourceColorItem(), monthGroup );
00521       topLayout->addWidget( monthGroup );
00522 
00523 
00524       /*** Todo View Group ***/
00525       QGroupBox *todoGroup = new QGroupBox( 1, Horizontal,
00526                                             i18n("To-do View"),
00527                                             topFrame );
00528       addWidBool( KOPrefs::instance()->fullViewTodoItem(), todoGroup );
00529       addWidBool( KOPrefs::instance()->recordTodosInJournalsItem(), todoGroup );
00530       topLayout->addWidget( todoGroup );
00531 
00532       topLayout->addStretch( 1 );
00533 
00534       load();
00535     }
00536 };
00537 
00538 extern "C"
00539 {
00540   KCModule *create_korganizerconfigviews( QWidget *parent, const char * )
00541   {
00542     return new KOPrefsDialogViews( parent, "kcmkorganizerviews" );
00543   }
00544 }
00545 
00546 
00547 class KOPrefsDialogFonts : public KPrefsModule
00548 {
00549   public:
00550     KOPrefsDialogFonts( QWidget *parent, const char *name )
00551       : KPrefsModule( KOPrefs::instance(), parent, name )
00552     {
00553       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00554 
00555       QWidget *topFrame = new QWidget( this );
00556       topTopLayout->addWidget( topFrame );
00557 
00558       QGridLayout *topLayout = new QGridLayout(topFrame,5,3);
00559       topLayout->setSpacing( KDialog::spacingHint() );
00560 
00561       KPrefsWidFont *timeBarFont =
00562           addWidFont( KOPrefs::instance()->timeBarFontItem(), topFrame,
00563                       KGlobal::locale()->formatTime( QTime( 12, 34 ) ) );
00564       topLayout->addWidget(timeBarFont->label(),0,0);
00565       topLayout->addWidget(timeBarFont->preview(),0,1);
00566       topLayout->addWidget(timeBarFont->button(),0,2);
00567 
00568       KPrefsWidFont *monthViewFont =
00569           addWidFont( KOPrefs::instance()->monthViewFontItem(), topFrame,
00570                       KGlobal::locale()->formatTime(QTime(12,34)) + " " +
00571                       i18n("Event text") );
00572 
00573       topLayout->addWidget(monthViewFont->label(),1,0);
00574       topLayout->addWidget(monthViewFont->preview(),1,1);
00575       topLayout->addWidget(monthViewFont->button(),1,2);
00576 
00577       KPrefsWidFont *agendaViewFont =
00578           addWidFont( KOPrefs::instance()->agendaViewFontItem(),
00579                       topFrame, i18n("Event text") );
00580       topLayout->addWidget(agendaViewFont->label(),2,0);
00581       topLayout->addWidget(agendaViewFont->preview(),2,1);
00582       topLayout->addWidget(agendaViewFont->button(),2,2);
00583 
00584       KPrefsWidFont *marcusBainsFont =
00585           addWidFont( KOPrefs::instance()->marcusBainsFontItem(), topFrame,
00586                       KGlobal::locale()->formatTime( QTime( 12, 34, 23 ) ) );
00587       topLayout->addWidget(marcusBainsFont->label(),3,0);
00588       topLayout->addWidget(marcusBainsFont->preview(),3,1);
00589       topLayout->addWidget(marcusBainsFont->button(),3,2);
00590 
00591       topLayout->setColStretch(1,1);
00592       topLayout->setRowStretch(4,1);
00593 
00594       load();
00595     }
00596 };
00597 
00598 extern "C"
00599 {
00600   KCModule *create_korganizerconfigfonts( QWidget *parent, const char * )
00601   {
00602     return new KOPrefsDialogFonts( parent, "kcmkorganizerfonts" );
00603   }
00604 }
00605 
00606 
00607 KOPrefsDialogColors::KOPrefsDialogColors( QWidget *parent, const char *name )
00608       : KPrefsModule( KOPrefs::instance(), parent, name )
00609 {
00610   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00611 
00612   QWidget *topFrame = new QWidget( this );
00613   topTopLayout->addWidget( topFrame );
00614 
00615   QGridLayout *topLayout = new QGridLayout(topFrame,7,2);
00616   topLayout->setSpacing( KDialog::spacingHint() );
00617 
00618   // Holiday Color
00619   KPrefsWidColor *holidayColor =
00620       addWidColor( KOPrefs::instance()->holidayColorItem(), topFrame );
00621   topLayout->addWidget(holidayColor->label(),0,0);
00622   topLayout->addWidget(holidayColor->button(),0,1);
00623 
00624   // Highlight Color
00625   KPrefsWidColor *highlightColor =
00626       addWidColor( KOPrefs::instance()->highlightColorItem(), topFrame );
00627   topLayout->addWidget(highlightColor->label(),1,0);
00628   topLayout->addWidget(highlightColor->button(),1,1);
00629 
00630   KPrefsWidColor *eventColor =
00631       addWidColor( KOPrefs::instance()->eventColorItem(), topFrame );
00632   topLayout->addWidget(eventColor->label(),2,0);
00633   topLayout->addWidget(eventColor->button(),2,1);
00634 
00635   // agenda view background color
00636   KPrefsWidColor *agendaBgColor =
00637       addWidColor( KOPrefs::instance()->agendaBgColorItem(), topFrame );
00638   topLayout->addWidget(agendaBgColor->label(),3,0);
00639   topLayout->addWidget(agendaBgColor->button(),3,1);
00640 
00641   // working hours color
00642   KPrefsWidColor *workingHoursColor =
00643       addWidColor( KOPrefs::instance()->workingHoursColorItem(), topFrame );
00644   topLayout->addWidget(workingHoursColor->label(),4,0);
00645   topLayout->addWidget(workingHoursColor->button(),4,1);
00646 
00647   // Todo due today color
00648   KPrefsWidColor *todoDueTodayColor =
00649       addWidColor( KOPrefs::instance()->todoDueTodayColorItem(), topFrame );
00650   topLayout->addWidget(todoDueTodayColor->label(),5,0);
00651   topLayout->addWidget(todoDueTodayColor->button(),5,1);
00652 
00653   // Todo overdue color
00654   KPrefsWidColor *todoOverdueColor =
00655       addWidColor( KOPrefs::instance()->todoOverdueColorItem(), topFrame );
00656   topLayout->addWidget(todoOverdueColor->label(),6,0);
00657   topLayout->addWidget(todoOverdueColor->button(),6,1);
00658 
00659   // categories colors
00660   QGroupBox *categoryGroup = new QGroupBox(1,Horizontal,i18n("Categories"),
00661                                            topFrame);
00662   topLayout->addMultiCellWidget(categoryGroup,7,7,0,1);
00663 
00664   mCategoryCombo = new QComboBox(categoryGroup);
00665   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00666   QWhatsThis::add( mCategoryCombo,
00667                    i18n( "Select here the event category you want to modify. "
00668                          "You can change the selected category color using "
00669                          "the button below." ) );
00670   connect(mCategoryCombo,SIGNAL(activated(int)),SLOT(updateCategoryColor()));
00671 
00672   mCategoryButton = new KColorButton(categoryGroup);
00673   QWhatsThis::add( mCategoryButton,
00674                    i18n( "Choose here the color of the event category selected "
00675                          "using the combo box above." ) );
00676   connect(mCategoryButton,SIGNAL(changed(const QColor &)),SLOT(setCategoryColor()));
00677   updateCategoryColor();
00678 
00679   // resources colors
00680   QGroupBox *resourceGroup = new QGroupBox(1,Horizontal,i18n("Resources"),
00681                                            topFrame);
00682   topLayout->addMultiCellWidget(resourceGroup,8,8,0,1);
00683 
00684   mResourceCombo = new QComboBox(resourceGroup);
00685   QWhatsThis::add( mResourceCombo,
00686                    i18n( "Select here resource you want to modify. "
00687                          "You can change the selected resource color using "
00688                          "the button below." ) );
00689   connect(mResourceCombo,SIGNAL(activated(int)),SLOT(updateResourceColor()));
00690 
00691   mResourceButton = new KColorButton(resourceGroup);
00692   QWhatsThis::add( mResourceButton,
00693                    i18n( "Choose here the color of the resource selected "
00694                          "using the combo box above." ) );
00695   connect(mResourceButton,SIGNAL(changed(const QColor &)),SLOT(setResourceColor()));
00696   updateResources();
00697 
00698   topLayout->setRowStretch(9,1);
00699 
00700   load();
00701 }
00702 
00703 void KOPrefsDialogColors::usrWriteConfig()
00704 {
00705   QDictIterator<QColor> itCat(mCategoryDict);
00706   while (itCat.current()) {
00707     KOPrefs::instance()->setCategoryColor(itCat.currentKey(),*itCat.current());
00708     ++itCat;
00709   }
00710 
00711   QDictIterator<QColor> itRes(mResourceDict);
00712   while (itRes.current()) {
00713     KOPrefs::instance()->setResourceColor(itRes.currentKey(),*itRes.current());
00714     ++itRes;
00715   }
00716 }
00717 
00718 void KOPrefsDialogColors::usrReadConfig()
00719 {
00720   updateCategories();
00721   updateResources();
00722 }
00723 
00724 void KOPrefsDialogColors::updateCategories()
00725 {
00726   mCategoryCombo->clear();
00727   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00728   updateCategoryColor();
00729 }
00730 
00731 void KOPrefsDialogColors::setCategoryColor()
00732 {
00733   mCategoryDict.replace(mCategoryCombo->currentText(), new QColor(mCategoryButton->color()));
00734   slotWidChanged();
00735 }
00736 
00737 void KOPrefsDialogColors::updateCategoryColor()
00738 {
00739   QString cat = mCategoryCombo->currentText();
00740   QColor *color = mCategoryDict.find(cat);
00741   if (!color) {
00742     color = KOPrefs::instance()->categoryColor(cat);
00743   }
00744   if (color) {
00745     mCategoryButton->setColor(*color);
00746   }
00747 }
00748 
00749 void KOPrefsDialogColors::updateResources()
00750 {
00751   mResourceCombo->clear();
00752   mResourceIdentifier.clear();
00753   kdDebug( 5850) << "KOPrefsDialogColors::updateResources()" << endl;
00754 
00755   KCal::CalendarResourceManager *manager = KOrg::StdCalendar::self()->resourceManager();
00756 
00757   kdDebug(5850) << "Loading Calendar resources...:" << endl;
00758   KCal::CalendarResourceManager::Iterator it;
00759   for( it = manager->begin(); it != manager->end(); ++it ) {
00760     if ( !(*it)->subresources().isEmpty() ) {
00761       QStringList subresources = (*it)->subresources();
00762       for ( uint i = 0; i < subresources.count(); ++i ) {
00763         QString resource = subresources[ i ];
00764         if ( (*it)->subresourceActive( resource ) ) {
00765           mResourceCombo->insertItem( (*it)->labelForSubresource( resource ) );
00766           mResourceIdentifier.append( resource );
00767         }
00768       }
00769     }
00770 
00771     mResourceCombo->insertItem( (*it)->resourceName() );
00772     mResourceIdentifier.append( (*it)->identifier() );
00773   }
00774 
00775   updateResourceColor();
00776 }
00777 
00778 void KOPrefsDialogColors::setResourceColor()
00779 {
00780   kdDebug( 5850) << "KOPrefsDialogColors::setResorceColor()" << endl;
00781 
00782   mResourceDict.replace( mResourceIdentifier[mResourceCombo->currentItem()],
00783     new QColor( mResourceButton->color() ) );
00784   slotWidChanged();
00785 }
00786 
00787 void KOPrefsDialogColors::updateResourceColor()
00788 {
00789   kdDebug( 5850 ) << "KOPrefsDialogColors::updateResourceColor()" << endl;
00790   QString res= mResourceIdentifier[mResourceCombo->currentItem()];
00791   QColor *color = mCategoryDict.find(res);
00792   if( !color )  {
00793     color = KOPrefs::instance()->resourceColor( res );
00794   }
00795   if( color ) {
00796     mResourceButton->setColor(*color);
00797   }
00798 }
00799 extern "C"
00800 {
00801   KCModule *create_korganizerconfigcolors( QWidget *parent, const char * )
00802   {
00803     return new KOPrefsDialogColors( parent, "kcmkorganizercolors" );
00804   }
00805 }
00806 
00807 
00808 KOPrefsDialogGroupScheduling::KOPrefsDialogGroupScheduling( QWidget *parent, const char *name )
00809   : KPrefsModule( KOPrefs::instance(), parent, name )
00810 {
00811   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00812 
00813   QWidget *topFrame = new QWidget( this );
00814   topTopLayout->addWidget( topFrame );
00815 
00816   QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
00817   topLayout->setSpacing( KDialog::spacingHint() );
00818 
00819   KPrefsWidBool *useGroupwareBool =
00820       addWidBool( KOPrefs::instance()->useGroupwareCommunicationItem(),
00821       topFrame );
00822   topLayout->addMultiCellWidget(useGroupwareBool->checkBox(),0,0,0,1);
00823   // FIXME: This radio button should only be available when KMail is chosen
00824 //   connect(thekmailradiobuttonupthere,SIGNAL(toggled(bool)),
00825 //           useGroupwareBool->checkBox(), SLOT(enabled(bool)));
00826 
00827   KPrefsWidBool *bcc =
00828       addWidBool( KOPrefs::instance()->bccItem(), topFrame );
00829   topLayout->addMultiCellWidget(bcc->checkBox(),1,1,0,1);
00830 
00831   KPrefsWidRadios *mailClientGroup =
00832       addWidRadios( KOPrefs::instance()->mailClientItem(), topFrame );
00833   topLayout->addMultiCellWidget(mailClientGroup->groupBox(),2,2,0,1);
00834 
00835 
00836 #if 0
00837   KPrefsWidRadios *schedulerGroup =
00838       addWidRadios(i18n("Scheduler Mail Client"),KOPrefs::instance()->mIMIPScheduler,
00839                    topFrame);
00840   schedulerGroup->addRadio("Dummy"); // Only for debugging
00841   schedulerGroup->addRadio(i18n("Mail client"));
00842 
00843   topLayout->addMultiCellWidget(schedulerGroup->groupBox(),0,0,0,1);
00844 #endif
00845 
00846   QLabel *aMailsLabel = new QLabel(i18n("Additional email addresses:"),topFrame);
00847   QString whatsThis = i18n( "Add, edit or remove additional e-mails addresses "
00848                             "here. These email addresses are the ones you "
00849                             "have in addition to the one set in personal "
00850                             "preferences. If you are an attendee of one event, "
00851                             "but use another email address there, you need to "
00852                             "list this address here so KOrganizer can "
00853                             "recognize it as yours." );
00854   QWhatsThis::add( aMailsLabel, whatsThis );
00855   topLayout->addMultiCellWidget(aMailsLabel,3,3,0,1);
00856   mAMails = new QListView(topFrame);
00857   QWhatsThis::add( mAMails, whatsThis );
00858 
00859   mAMails->addColumn(i18n("Email"),300);
00860   topLayout->addMultiCellWidget(mAMails,4,4,0,1);
00861 
00862   QLabel *aEmailsEditLabel = new QLabel(i18n("Additional email address:"),topFrame);
00863   whatsThis = i18n( "Edit additional e-mails addresses here. To edit an "
00864                     "address select it from the list above "
00865                     "or press the \"New\" button below. These email "
00866                     "addresses are the ones you have in addition to the "
00867                     "one set in personal preferences." );
00868   QWhatsThis::add( aEmailsEditLabel, whatsThis );
00869   topLayout->addWidget(aEmailsEditLabel,5,0);
00870   aEmailsEdit = new QLineEdit(topFrame);
00871   QWhatsThis::add( aEmailsEdit, whatsThis );
00872   aEmailsEdit->setEnabled(false);
00873   topLayout->addWidget(aEmailsEdit,5,1);
00874 
00875   QPushButton *add = new QPushButton(i18n("New"),topFrame,"new");
00876   whatsThis = i18n( "Press this button to add a new entry to the "
00877                     "additional e-mail addresses list. Use the edit "
00878                     "box above to edit the new entry." );
00879   QWhatsThis::add( add, whatsThis );
00880   topLayout->addWidget(add,6,0);
00881   QPushButton *del = new QPushButton(i18n("Remove"),topFrame,"remove");
00882   QWhatsThis::add( del, whatsThis );
00883   topLayout->addWidget(del,6,1);
00884 
00885   //topLayout->setRowStretch(2,1);
00886   connect(add, SIGNAL( clicked() ), this, SLOT(addItem()) );
00887   connect(del, SIGNAL( clicked() ), this, SLOT(removeItem()) );
00888   connect(aEmailsEdit,SIGNAL( textChanged(const QString&) ), this,SLOT(updateItem()));
00889   connect(mAMails,SIGNAL(selectionChanged(QListViewItem *)),SLOT(updateInput()));
00890 
00891   load();
00892 }
00893 
00894 void KOPrefsDialogGroupScheduling::usrReadConfig()
00895 {
00896   mAMails->clear();
00897   for ( QStringList::Iterator it = KOPrefs::instance()->mAdditionalMails.begin();
00898             it != KOPrefs::instance()->mAdditionalMails.end(); ++it ) {
00899     QListViewItem *item = new QListViewItem(mAMails);
00900     item->setText(0,*it);
00901     mAMails->insertItem(item);
00902   }
00903 }
00904 
00905 void KOPrefsDialogGroupScheduling::usrWriteConfig()
00906 {
00907   KOPrefs::instance()->mAdditionalMails.clear();
00908   QListViewItem *item;
00909   item = mAMails->firstChild();
00910   while (item)
00911   {
00912     KOPrefs::instance()->mAdditionalMails.append( item->text(0) );
00913     item = item->nextSibling();
00914   }
00915 }
00916 
00917 void KOPrefsDialogGroupScheduling::addItem()
00918 {
00919   aEmailsEdit->setEnabled(true);
00920   QListViewItem *item = new QListViewItem(mAMails);
00921   mAMails->insertItem(item);
00922   mAMails->setSelected(item,true);
00923   aEmailsEdit->setText(i18n("(EmptyEmail)"));
00924   slotWidChanged();
00925 }
00926 
00927 void KOPrefsDialogGroupScheduling::removeItem()
00928 {
00929   QListViewItem *item;
00930   item = mAMails->selectedItem();
00931   if (!item) return;
00932   mAMails->takeItem(item);
00933   item = mAMails->selectedItem();
00934   if (!item) {
00935     aEmailsEdit->setText("");
00936     aEmailsEdit->setEnabled(false);
00937   }
00938   if (mAMails->childCount() == 0) {
00939     aEmailsEdit->setEnabled(false);
00940   }
00941   slotWidChanged();
00942 }
00943 
00944 void KOPrefsDialogGroupScheduling::updateItem()
00945 {
00946   QListViewItem *item;
00947   item = mAMails->selectedItem();
00948   if (!item) return;
00949   item->setText(0,aEmailsEdit->text());
00950   slotWidChanged();
00951 }
00952 
00953 void KOPrefsDialogGroupScheduling::updateInput()
00954 {
00955   QListViewItem *item;
00956   item = mAMails->selectedItem();
00957   if (!item) return;
00958   aEmailsEdit->setEnabled(true);
00959   aEmailsEdit->setText(item->text(0));
00960 }
00961 
00962 extern "C"
00963 {
00964   KCModule *create_korganizerconfiggroupscheduling( QWidget *parent,
00965                                                      const char * )
00966   {
00967     return new KOPrefsDialogGroupScheduling( parent,
00968                                              "kcmkorganizergroupscheduling" );
00969   }
00970 }
00971 
00972 
00973 KOPrefsDialogGroupwareScheduling::KOPrefsDialogGroupwareScheduling( QWidget *parent, const char *name )
00974   : KPrefsModule( KOPrefs::instance(), parent, name )
00975 {
00976   mGroupwarePage = new KOGroupwarePrefsPage( this );
00977   connect( mGroupwarePage, SIGNAL( changed() ), SLOT( slotWidChanged() ) );
00978   ( new QVBoxLayout( this ) )->addWidget( mGroupwarePage );
00979 
00980   load();
00981 }
00982 
00983 void KOPrefsDialogGroupwareScheduling::usrReadConfig()
00984 {
00985   mGroupwarePage->publishEnable->setChecked( KOPrefs::instance()->mFreeBusyPublishAuto );
00986   mGroupwarePage->publishDelay->setValue( KOPrefs::instance()->mFreeBusyPublishDelay );
00987   mGroupwarePage->publishDays->setValue( KOPrefs::instance()->mFreeBusyPublishDays );
00988 
00989   mGroupwarePage->publishUrl->setText( KOPrefs::instance()->mFreeBusyPublishUrl );
00990   mGroupwarePage->publishUser->setText( KOPrefs::instance()->mFreeBusyPublishUser );
00991   mGroupwarePage->publishPassword->setText( KOPrefs::instance()->mFreeBusyPublishPassword );
00992   mGroupwarePage->publishSavePassword->setChecked( KOPrefs::instance()->mFreeBusyPublishSavePassword );
00993 
00994   mGroupwarePage->retrieveEnable->setChecked( KOPrefs::instance()->mFreeBusyRetrieveAuto );
00995   mGroupwarePage->fullDomainRetrieval->setChecked( KOPrefs::instance()->mFreeBusyFullDomainRetrieval );
00996   mGroupwarePage->retrieveUrl->setText( KOPrefs::instance()->mFreeBusyRetrieveUrl );
00997   mGroupwarePage->retrieveUser->setText( KOPrefs::instance()->mFreeBusyRetrieveUser );
00998   mGroupwarePage->retrievePassword->setText( KOPrefs::instance()->mFreeBusyRetrievePassword );
00999   mGroupwarePage->retrieveSavePassword->setChecked( KOPrefs::instance()->mFreeBusyRetrieveSavePassword );
01000 }
01001 
01002 void KOPrefsDialogGroupwareScheduling::usrWriteConfig()
01003 {
01004   KOPrefs::instance()->mFreeBusyPublishAuto = mGroupwarePage->publishEnable->isChecked();
01005   KOPrefs::instance()->mFreeBusyPublishDelay = mGroupwarePage->publishDelay->value();
01006   KOPrefs::instance()->mFreeBusyPublishDays = mGroupwarePage->publishDays->value();
01007 
01008   KOPrefs::instance()->mFreeBusyPublishUrl = mGroupwarePage->publishUrl->text();
01009   KOPrefs::instance()->mFreeBusyPublishUser = mGroupwarePage->publishUser->text();
01010   KOPrefs::instance()->mFreeBusyPublishPassword = mGroupwarePage->publishPassword->text();
01011   KOPrefs::instance()->mFreeBusyPublishSavePassword = mGroupwarePage->publishSavePassword->isChecked();
01012 
01013   KOPrefs::instance()->mFreeBusyRetrieveAuto = mGroupwarePage->retrieveEnable->isChecked();
01014   KOPrefs::instance()->mFreeBusyFullDomainRetrieval = mGroupwarePage->fullDomainRetrieval->isChecked();
01015   KOPrefs::instance()->mFreeBusyRetrieveUrl = mGroupwarePage->retrieveUrl->text();
01016   KOPrefs::instance()->mFreeBusyRetrieveUser = mGroupwarePage->retrieveUser->text();
01017   KOPrefs::instance()->mFreeBusyRetrievePassword = mGroupwarePage->retrievePassword->text();
01018   KOPrefs::instance()->mFreeBusyRetrieveSavePassword = mGroupwarePage->retrieveSavePassword->isChecked();
01019 }
01020 
01021 extern "C"
01022 {
01023   KCModule *create_korganizerconfigfreebusy( QWidget *parent, const char * )
01024   {
01025     return new KOPrefsDialogGroupwareScheduling( parent,
01026                                                  "kcmkorganizerfreebusy" );
01027   }
01028 }
01029 
01030 
01031 
01032 class PluginItem : public QCheckListItem {
01033   public:
01034     PluginItem( QListView *parent, KService::Ptr service ) :
01035       QCheckListItem( parent, service->name(), QCheckListItem::CheckBox ), mService( service )
01036     {}
01037     KService::Ptr service() { return mService; }
01038   private:
01039     KService::Ptr mService;
01040 };
01041 
01042 
01046 KOPrefsDialogPlugins::KOPrefsDialogPlugins( QWidget *parent, const char* name )
01047   : KPrefsModule( KOPrefs::instance(), parent, name )
01048 {
01049   QBoxLayout *topTopLayout = new QVBoxLayout( this );
01050 
01051   QWidget *topFrame = new QWidget( this );
01052   topTopLayout->addWidget( topFrame );
01053   QBoxLayout *topLayout = new QVBoxLayout( topFrame );
01054   topLayout->setSpacing( KDialog::spacingHint() );
01055 
01056   mListView = new QListView( topFrame );
01057   mListView->addColumn( i18n("Name") );
01058   mListView->setResizeMode( QListView::LastColumn );
01059   topLayout->addWidget( mListView );
01060 
01061   mDescription = new QLabel( topFrame );
01062   mDescription->setAlignment( QLabel::NoAccel | QLabel::WordBreak | QLabel::AlignVCenter );
01063   mDescription->setFrameShape( QLabel::Panel );
01064   mDescription->setFrameShadow( QLabel::Sunken );
01065   mDescription->setMinimumSize( QSize( 0, 55 ) );
01066   mDescription->setSizePolicy(
01067          QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0,
01068                       0, 0, mDescription->sizePolicy().hasHeightForWidth() ) );
01069   topLayout->addWidget( mDescription );
01070 
01071 
01072   QWidget *buttonRow = new QWidget( topFrame );
01073   QBoxLayout *buttonRowLayout = new QHBoxLayout( buttonRow );
01074   mConfigureButton = new KPushButton( KGuiItem( i18n("Configure &Plugin..."),
01075       "configure", QString::null, i18n("This button allows you to configure"
01076       " the plugin that you have selected in the list above") ), buttonRow );
01077 
01078   buttonRowLayout->addWidget( mConfigureButton );
01079   buttonRowLayout->addItem( new QSpacerItem(1, 1,  QSizePolicy::Expanding) );
01080   topLayout->addWidget( buttonRow );
01081   connect( mConfigureButton, SIGNAL( clicked() ), SLOT( configure() ) );
01082 
01083   connect( mListView, SIGNAL( selectionChanged( QListViewItem* ) ),
01084            SLOT( selectionChanged( QListViewItem* ) ) );
01085   connect( mListView, SIGNAL( clicked( QListViewItem* ) ),
01086            SLOT( slotWidChanged() ) );
01087 
01088   load();
01089 //  usrReadConfig();
01090   selectionChanged( 0 );
01091 }
01092 
01093 void KOPrefsDialogPlugins::usrReadConfig()
01094 {
01095   mListView->clear();
01096   KTrader::OfferList plugins = KOCore::self()->availablePlugins();
01097   plugins += KOCore::self()->availableParts();
01098 
01099   QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
01100 
01101   KTrader::OfferList::ConstIterator it;
01102   for( it = plugins.begin(); it != plugins.end(); ++it ) {
01103     QCheckListItem *item = new PluginItem( mListView, *it );
01104     if ( selectedPlugins.find( (*it)->desktopEntryName() ) !=
01105                                selectedPlugins.end() ) {
01106       item->setOn( true );
01107     }
01108   }
01109 }
01110 
01111 void KOPrefsDialogPlugins::usrWriteConfig()
01112 {
01113   QStringList selectedPlugins;
01114 
01115   PluginItem *item = static_cast<PluginItem *>( mListView->firstChild() );
01116   while( item ) {
01117     if( item->isOn() ) {
01118       selectedPlugins.append( item->service()->desktopEntryName() );
01119     }
01120     item = static_cast<PluginItem *>( item->nextSibling() );
01121   }
01122   KOPrefs::instance()->mSelectedPlugins = selectedPlugins;
01123 }
01124 
01125 void KOPrefsDialogPlugins::configure()
01126 {
01127   PluginItem *item = static_cast<PluginItem *>( mListView->selectedItem() );
01128   if ( !item ) return;
01129 
01130   KOrg::Plugin *plugin = KOCore::self()->loadPlugin( item->service() );
01131 
01132   if ( plugin ) {
01133     plugin->configure( this );
01134     delete plugin;
01135   } else {
01136     KMessageBox::sorry( this, i18n( "Unable to configure this plugin" ),
01137                         "PluginConfigUnable" );
01138   }
01139 }
01140 
01141 void KOPrefsDialogPlugins::selectionChanged( QListViewItem *i )
01142 {
01143   PluginItem *item = dynamic_cast<PluginItem*>( i );
01144   if ( !item ) {
01145     mConfigureButton->setEnabled( false );
01146     mDescription->setText( QString::null );
01147     return;
01148   }
01149 
01150   QVariant variant = item->service()->property( "X-KDE-KOrganizer-HasSettings" );
01151 
01152   bool hasSettings = true;
01153   if ( variant.isValid() )
01154     hasSettings = variant.toBool();
01155 
01156   mDescription->setText( item->service()->comment() );
01157   mConfigureButton->setEnabled( hasSettings );
01158 
01159   slotWidChanged();
01160 }
01161 
01162 extern "C"
01163 {
01164   KCModule *create_korganizerconfigplugins( QWidget *parent, const char * )
01165   {
01166     return new KOPrefsDialogPlugins( parent,
01167                                      "kcmkorganizerplugins" );
01168   }
01169 }
01170 
01171 
01172 extern "C"
01173 {
01174   KCModule *create_korgdesignerfields( QWidget *parent, const char * ) {
01175     return new KOPrefsDesignerFields( parent, "kcmkorgdesignerfields" );
01176   }
01177 }
01178 
01179 KOPrefsDesignerFields::KOPrefsDesignerFields( QWidget *parent, const char *name )
01180   : KCMDesignerFields( parent, name )
01181 {
01182 }
01183 
01184 QString KOPrefsDesignerFields::localUiDir()
01185 {
01186   QString dir = locateLocal( "data", "korganizer/designer/event/");
01187   kdDebug() << "KOPrefsDesignerFields::localUiDir(): " << dir << endl;
01188   return dir;
01189 }
01190 
01191 QString KOPrefsDesignerFields::uiPath()
01192 {
01193   return "korganizer/designer/event/";
01194 }
01195 
01196 void KOPrefsDesignerFields::writeActivePages( const QStringList &activePages )
01197 {
01198   KOPrefs::instance()->setActiveDesignerFields( activePages );
01199   KOPrefs::instance()->writeConfig();
01200 }
01201 
01202 QStringList KOPrefsDesignerFields::readActivePages()
01203 {
01204   return KOPrefs::instance()->activeDesignerFields();
01205 }
01206 
01207 QString KOPrefsDesignerFields::applicationName()
01208 {
01209   return "KORGANIZER";
01210 }
01211 
01212 #include "koprefsdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys