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