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