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       addWidCombo( KOPrefs::instance()->agendaViewColorsItem(), agendaGroup );
00543 
00544       addWidCombo( KOPrefs::instance()->agendaViewCalendarDisplayItem(), agendaGroup );
00545 
00546       topLayout->addWidget( agendaGroup );
00547 
00548       /*** Month View Group ***/
00549       QGroupBox *monthGroup = new QGroupBox( 1, Horizontal,
00550                                              i18n("Month View"),
00551                                              topFrame );
00552       addWidBool( KOPrefs::instance()->enableMonthScrollItem(), monthGroup );
00553       addWidBool( KOPrefs::instance()->fullViewMonthItem(), monthGroup );
00554       addWidCombo( KOPrefs::instance()->monthItemColorsItem(), monthGroup );
00555       topLayout->addWidget( monthGroup );
00556 
00557 
00558       /*** Todo View Group ***/
00559       QGroupBox *todoGroup = new QGroupBox( 1, Horizontal,
00560                                             i18n("To-do View"),
00561                                             topFrame );
00562       addWidBool( KOPrefs::instance()->fullViewTodoItem(), todoGroup );
00563       addWidBool( KOPrefs::instance()->recordTodosInJournalsItem(), todoGroup );
00564       topLayout->addWidget( todoGroup );
00565 
00566       topLayout->addStretch( 1 );
00567 
00568       load();
00569     }
00570 };
00571 
00572 extern "C"
00573 {
00574   KCModule *create_korganizerconfigviews( QWidget *parent, const char * )
00575   {
00576     return new KOPrefsDialogViews( parent, "kcmkorganizerviews" );
00577   }
00578 }
00579 
00580 
00581 class KOPrefsDialogFonts : public KPrefsModule
00582 {
00583   public:
00584     KOPrefsDialogFonts( QWidget *parent, const char *name )
00585       : KPrefsModule( KOPrefs::instance(), parent, name )
00586     {
00587       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00588 
00589       QWidget *topFrame = new QWidget( this );
00590       topTopLayout->addWidget( topFrame );
00591 
00592       QGridLayout *topLayout = new QGridLayout(topFrame,5,3);
00593       topLayout->setSpacing( KDialog::spacingHint() );
00594 
00595       KPrefsWidFont *timeBarFont =
00596           addWidFont( KOPrefs::instance()->timeBarFontItem(), topFrame,
00597                       KGlobal::locale()->formatTime( QTime( 12, 34 ) ) );
00598       topLayout->addWidget(timeBarFont->label(),0,0);
00599       topLayout->addWidget(timeBarFont->preview(),0,1);
00600       topLayout->addWidget(timeBarFont->button(),0,2);
00601 
00602       KPrefsWidFont *monthViewFont =
00603           addWidFont( KOPrefs::instance()->monthViewFontItem(), topFrame,
00604                       KGlobal::locale()->formatTime(QTime(12,34)) + " " +
00605                       i18n("Event text") );
00606 
00607       topLayout->addWidget(monthViewFont->label(),1,0);
00608       topLayout->addWidget(monthViewFont->preview(),1,1);
00609       topLayout->addWidget(monthViewFont->button(),1,2);
00610 
00611       KPrefsWidFont *agendaViewFont =
00612           addWidFont( KOPrefs::instance()->agendaViewFontItem(),
00613                       topFrame, i18n("Event text") );
00614       topLayout->addWidget(agendaViewFont->label(),2,0);
00615       topLayout->addWidget(agendaViewFont->preview(),2,1);
00616       topLayout->addWidget(agendaViewFont->button(),2,2);
00617 
00618       KPrefsWidFont *marcusBainsFont =
00619           addWidFont( KOPrefs::instance()->marcusBainsFontItem(), topFrame,
00620                       KGlobal::locale()->formatTime( QTime( 12, 34, 23 ) ) );
00621       topLayout->addWidget(marcusBainsFont->label(),3,0);
00622       topLayout->addWidget(marcusBainsFont->preview(),3,1);
00623       topLayout->addWidget(marcusBainsFont->button(),3,2);
00624 
00625       topLayout->setColStretch(1,1);
00626       topLayout->setRowStretch(4,1);
00627 
00628       load();
00629     }
00630 };
00631 
00632 extern "C"
00633 {
00634   KCModule *create_korganizerconfigfonts( QWidget *parent, const char * )
00635   {
00636     return new KOPrefsDialogFonts( parent, "kcmkorganizerfonts" );
00637   }
00638 }
00639 
00640 
00641 KOPrefsDialogColors::KOPrefsDialogColors( QWidget *parent, const char *name )
00642       : KPrefsModule( KOPrefs::instance(), parent, name )
00643 {
00644   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00645 
00646   QWidget *topFrame = new QWidget( this );
00647   topTopLayout->addWidget( topFrame );
00648 
00649   QGridLayout *topLayout = new QGridLayout(topFrame,7,2);
00650   topLayout->setSpacing( KDialog::spacingHint() );
00651 
00652   // Holiday Color
00653   KPrefsWidColor *holidayColor =
00654       addWidColor( KOPrefs::instance()->holidayColorItem(), topFrame );
00655   topLayout->addWidget(holidayColor->label(),0,0);
00656   topLayout->addWidget(holidayColor->button(),0,1);
00657 
00658   // Highlight Color
00659   KPrefsWidColor *highlightColor =
00660       addWidColor( KOPrefs::instance()->highlightColorItem(), topFrame );
00661   topLayout->addWidget(highlightColor->label(),1,0);
00662   topLayout->addWidget(highlightColor->button(),1,1);
00663 
00664   // agenda view background color
00665   KPrefsWidColor *agendaBgColor =
00666       addWidColor( KOPrefs::instance()->agendaBgColorItem(), topFrame );
00667   topLayout->addWidget(agendaBgColor->label(),2,0);
00668   topLayout->addWidget(agendaBgColor->button(),2,1);
00669 
00670   // working hours color
00671   KPrefsWidColor *workingHoursColor =
00672       addWidColor( KOPrefs::instance()->workingHoursColorItem(), topFrame );
00673   topLayout->addWidget(workingHoursColor->label(),3,0);
00674   topLayout->addWidget(workingHoursColor->button(),3,1);
00675 
00676   // Todo due today color
00677   KPrefsWidColor *todoDueTodayColor =
00678       addWidColor( KOPrefs::instance()->todoDueTodayColorItem(), topFrame );
00679   topLayout->addWidget(todoDueTodayColor->label(),4,0);
00680   topLayout->addWidget(todoDueTodayColor->button(),4,1);
00681 
00682   // Todo overdue color
00683   KPrefsWidColor *todoOverdueColor =
00684       addWidColor( KOPrefs::instance()->todoOverdueColorItem(), topFrame );
00685   topLayout->addWidget(todoOverdueColor->label(),5,0);
00686   topLayout->addWidget(todoOverdueColor->button(),5,1);
00687 
00688   // "No Category" color
00689   KPrefsWidColor *unsetCategoryColor =
00690     addWidColor( KOPrefs::instance()->unsetCategoryColorItem(), topFrame );
00691   topLayout->addWidget( unsetCategoryColor->label(), 6, 0 );
00692   topLayout->addWidget( unsetCategoryColor->button(), 6, 1 );
00693 
00694   // categories colors
00695   QGroupBox *categoryGroup = new QGroupBox(1,Horizontal,i18n("Categories"),
00696                                            topFrame);
00697   topLayout->addMultiCellWidget(categoryGroup,7,7,0,1);
00698 
00699 
00700   mCategoryCombo = new QComboBox(categoryGroup);
00701   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00702   QWhatsThis::add( mCategoryCombo,
00703                    i18n( "Select here the event category you want to modify. "
00704                          "You can change the selected category color using "
00705                          "the button below." ) );
00706   connect(mCategoryCombo,SIGNAL(activated(int)),SLOT(updateCategoryColor()));
00707 
00708   mCategoryButton = new KColorButton(categoryGroup);
00709   QWhatsThis::add( mCategoryButton,
00710                    i18n( "Choose here the color of the event category selected "
00711                          "using the combo box above." ) );
00712   connect(mCategoryButton,SIGNAL(changed(const QColor &)),SLOT(setCategoryColor()));
00713   updateCategoryColor();
00714 
00715   // resources colors
00716   QGroupBox *resourceGroup = new QGroupBox(1,Horizontal,i18n("Resources"),
00717                                            topFrame);
00718   topLayout->addMultiCellWidget(resourceGroup,8,8,0,1);
00719 
00720   mResourceCombo = new QComboBox(resourceGroup);
00721   QWhatsThis::add( mResourceCombo,
00722                    i18n( "Select here resource you want to modify. "
00723                          "You can change the selected resource color using "
00724                          "the button below." ) );
00725   connect(mResourceCombo,SIGNAL(activated(int)),SLOT(updateResourceColor()));
00726 
00727   mResourceButton = new KColorButton(resourceGroup);
00728   QWhatsThis::add( mResourceButton,
00729                    i18n( "Choose here the color of the resource selected "
00730                          "using the combo box above." ) );
00731   connect(mResourceButton,SIGNAL(changed(const QColor &)),SLOT(setResourceColor()));
00732   updateResources();
00733 
00734   topLayout->setRowStretch(9,1);
00735 
00736   load();
00737 }
00738 
00739 void KOPrefsDialogColors::usrWriteConfig()
00740 {
00741   QDictIterator<QColor> itCat(mCategoryDict);
00742   while (itCat.current()) {
00743     KOPrefs::instance()->setCategoryColor(itCat.currentKey(),*itCat.current());
00744     ++itCat;
00745   }
00746 
00747   QDictIterator<QColor> itRes(mResourceDict);
00748   while (itRes.current()) {
00749     KOPrefs::instance()->setResourceColor(itRes.currentKey(),*itRes.current());
00750     ++itRes;
00751   }
00752 }
00753 
00754 void KOPrefsDialogColors::usrReadConfig()
00755 {
00756   updateCategories();
00757   updateResources();
00758 }
00759 
00760 void KOPrefsDialogColors::updateCategories()
00761 {
00762   mCategoryCombo->clear();
00763   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00764   updateCategoryColor();
00765 }
00766 
00767 void KOPrefsDialogColors::setCategoryColor()
00768 {
00769   mCategoryDict.replace(mCategoryCombo->currentText(), new QColor(mCategoryButton->color()));
00770   slotWidChanged();
00771 }
00772 
00773 void KOPrefsDialogColors::updateCategoryColor()
00774 {
00775   QString cat = mCategoryCombo->currentText();
00776   QColor *color = mCategoryDict.find(cat);
00777   if (!color) {
00778     color = KOPrefs::instance()->categoryColor(cat);
00779   }
00780   if (color) {
00781     mCategoryButton->setColor(*color);
00782   }
00783 }
00784 
00785 void KOPrefsDialogColors::updateResources()
00786 {
00787   mResourceCombo->clear();
00788   mResourceIdentifier.clear();
00789   kdDebug( 5850) << "KOPrefsDialogColors::updateResources()" << endl;
00790 
00791   KCal::CalendarResourceManager *manager = KOrg::StdCalendar::self()->resourceManager();
00792 
00793   kdDebug(5850) << "Loading Calendar resources...:" << endl;
00794   KCal::CalendarResourceManager::Iterator it;
00795   for( it = manager->begin(); it != manager->end(); ++it ) {
00796     if ( !(*it)->subresources().isEmpty() ) {
00797       QStringList subresources = (*it)->subresources();
00798       for ( uint i = 0; i < subresources.count(); ++i ) {
00799         QString resource = subresources[ i ];
00800         if ( (*it)->subresourceActive( resource ) ) {
00801           mResourceCombo->insertItem( (*it)->labelForSubresource( resource ) );
00802           mResourceIdentifier.append( resource );
00803         }
00804       }
00805     }
00806 
00807     mResourceCombo->insertItem( (*it)->resourceName() );
00808     mResourceIdentifier.append( (*it)->identifier() );
00809   }
00810 
00811   updateResourceColor();
00812 }
00813 
00814 void KOPrefsDialogColors::setResourceColor()
00815 {
00816   kdDebug( 5850) << "KOPrefsDialogColors::setResorceColor()" << endl;
00817 
00818   mResourceDict.replace( mResourceIdentifier[mResourceCombo->currentItem()],
00819     new QColor( mResourceButton->color() ) );
00820   slotWidChanged();
00821 }
00822 
00823 void KOPrefsDialogColors::updateResourceColor()
00824 {
00825   kdDebug( 5850 ) << "KOPrefsDialogColors::updateResourceColor()" << endl;
00826   QString res= mResourceIdentifier[mResourceCombo->currentItem()];
00827   QColor *color = mCategoryDict.find(res);
00828   if( !color )  {
00829     color = KOPrefs::instance()->resourceColor( res );
00830   }
00831   if( color ) {
00832     mResourceButton->setColor(*color);
00833   }
00834 }
00835 extern "C"
00836 {
00837   KCModule *create_korganizerconfigcolors( QWidget *parent, const char * )
00838   {
00839     return new KOPrefsDialogColors( parent, "kcmkorganizercolors" );
00840   }
00841 }
00842 
00843 
00844 KOPrefsDialogGroupScheduling::KOPrefsDialogGroupScheduling( QWidget *parent, const char *name )
00845   : KPrefsModule( KOPrefs::instance(), parent, name )
00846 {
00847   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00848 
00849   QWidget *topFrame = new QWidget( this );
00850   topTopLayout->addWidget( topFrame );
00851 
00852   QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
00853   topLayout->setSpacing( KDialog::spacingHint() );
00854 
00855   KPrefsWidBool *useGroupwareBool =
00856       addWidBool( KOPrefs::instance()->useGroupwareCommunicationItem(),
00857       topFrame );
00858   topLayout->addMultiCellWidget(useGroupwareBool->checkBox(),0,0,0,1);
00859   // FIXME: This radio button should only be available when KMail is chosen
00860 //   connect(thekmailradiobuttonupthere,SIGNAL(toggled(bool)),
00861 //           useGroupwareBool->checkBox(), SLOT(enabled(bool)));
00862 
00863   KPrefsWidBool *bcc =
00864       addWidBool( KOPrefs::instance()->bccItem(), topFrame );
00865   topLayout->addMultiCellWidget(bcc->checkBox(),1,1,0,1);
00866 
00867   KPrefsWidRadios *mailClientGroup =
00868       addWidRadios( KOPrefs::instance()->mailClientItem(), topFrame );
00869   topLayout->addMultiCellWidget(mailClientGroup->groupBox(),2,2,0,1);
00870 
00871 
00872 #if 0
00873   KPrefsWidRadios *schedulerGroup =
00874       addWidRadios(i18n("Scheduler Mail Client"),KOPrefs::instance()->mIMIPScheduler,
00875                    topFrame);
00876   schedulerGroup->addRadio("Dummy"); // Only for debugging
00877   schedulerGroup->addRadio(i18n("Mail client"));
00878 
00879   topLayout->addMultiCellWidget(schedulerGroup->groupBox(),0,0,0,1);
00880 #endif
00881 
00882   QLabel *aMailsLabel = new QLabel(i18n("Additional email addresses:"),topFrame);
00883   QString whatsThis = i18n( "Add, edit or remove additional e-mails addresses "
00884                             "here. These email addresses are the ones you "
00885                             "have in addition to the one set in personal "
00886                             "preferences. If you are an attendee of one event, "
00887                             "but use another email address there, you need to "
00888                             "list this address here so KOrganizer can "
00889                             "recognize it as yours." );
00890   QWhatsThis::add( aMailsLabel, whatsThis );
00891   topLayout->addMultiCellWidget(aMailsLabel,3,3,0,1);
00892   mAMails = new QListView(topFrame);
00893   QWhatsThis::add( mAMails, whatsThis );
00894 
00895   mAMails->addColumn(i18n("Email"),300);
00896   topLayout->addMultiCellWidget(mAMails,4,4,0,1);
00897 
00898   QLabel *aEmailsEditLabel = new QLabel(i18n("Additional email address:"),topFrame);
00899   whatsThis = i18n( "Edit additional e-mails addresses here. To edit an "
00900                     "address select it from the list above "
00901                     "or press the \"New\" button below. These email "
00902                     "addresses are the ones you have in addition to the "
00903                     "one set in personal preferences." );
00904   QWhatsThis::add( aEmailsEditLabel, whatsThis );
00905   topLayout->addWidget(aEmailsEditLabel,5,0);
00906   aEmailsEdit = new QLineEdit(topFrame);
00907   QWhatsThis::add( aEmailsEdit, whatsThis );
00908   aEmailsEdit->setEnabled(false);
00909   topLayout->addWidget(aEmailsEdit,5,1);
00910 
00911   QPushButton *add = new QPushButton(i18n("New"),topFrame,"new");
00912   whatsThis = i18n( "Press this button to add a new entry to the "
00913                     "additional e-mail addresses list. Use the edit "
00914                     "box above to edit the new entry." );
00915   QWhatsThis::add( add, whatsThis );
00916   topLayout->addWidget(add,6,0);
00917   QPushButton *del = new QPushButton(i18n("Remove"),topFrame,"remove");
00918   QWhatsThis::add( del, whatsThis );
00919   topLayout->addWidget(del,6,1);
00920 
00921   //topLayout->setRowStretch(2,1);
00922   connect(add, SIGNAL( clicked() ), this, SLOT(addItem()) );
00923   connect(del, SIGNAL( clicked() ), this, SLOT(removeItem()) );
00924   connect(aEmailsEdit,SIGNAL( textChanged(const QString&) ), this,SLOT(updateItem()));
00925   connect(mAMails,SIGNAL(selectionChanged(QListViewItem *)),SLOT(updateInput()));
00926 
00927   load();
00928 }
00929 
00930 void KOPrefsDialogGroupScheduling::usrReadConfig()
00931 {
00932   mAMails->clear();
00933   for ( QStringList::Iterator it = KOPrefs::instance()->mAdditionalMails.begin();
00934             it != KOPrefs::instance()->mAdditionalMails.end(); ++it ) {
00935     QListViewItem *item = new QListViewItem(mAMails);
00936     item->setText(0,*it);
00937     mAMails->insertItem(item);
00938   }
00939 }
00940 
00941 void KOPrefsDialogGroupScheduling::usrWriteConfig()
00942 {
00943   KOPrefs::instance()->mAdditionalMails.clear();
00944   QListViewItem *item;
00945   item = mAMails->firstChild();
00946   while (item)
00947   {
00948     KOPrefs::instance()->mAdditionalMails.append( item->text(0) );
00949     item = item->nextSibling();
00950   }
00951 }
00952 
00953 void KOPrefsDialogGroupScheduling::addItem()
00954 {
00955   aEmailsEdit->setEnabled(true);
00956   QListViewItem *item = new QListViewItem(mAMails);
00957   mAMails->insertItem(item);
00958   mAMails->setSelected(item,true);
00959   aEmailsEdit->setText(i18n("(EmptyEmail)"));
00960   slotWidChanged();
00961 }
00962 
00963 void KOPrefsDialogGroupScheduling::removeItem()
00964 {
00965   QListViewItem *item;
00966   item = mAMails->selectedItem();
00967   if (!item) return;
00968   mAMails->takeItem(item);
00969   item = mAMails->selectedItem();
00970   if (!item) {
00971     aEmailsEdit->setText("");
00972     aEmailsEdit->setEnabled(false);
00973   }
00974   if (mAMails->childCount() == 0) {
00975     aEmailsEdit->setEnabled(false);
00976   }
00977   slotWidChanged();
00978 }
00979 
00980 void KOPrefsDialogGroupScheduling::updateItem()
00981 {
00982   QListViewItem *item;
00983   item = mAMails->selectedItem();
00984   if (!item) return;
00985   item->setText(0,aEmailsEdit->text());
00986   slotWidChanged();
00987 }
00988 
00989 void KOPrefsDialogGroupScheduling::updateInput()
00990 {
00991   QListViewItem *item;
00992   item = mAMails->selectedItem();
00993   if (!item) return;
00994   aEmailsEdit->setEnabled(true);
00995   aEmailsEdit->setText(item->text(0));
00996 }
00997 
00998 extern "C"
00999 {
01000   KCModule *create_korganizerconfiggroupscheduling( QWidget *parent,
01001                                                      const char * )
01002   {
01003     return new KOPrefsDialogGroupScheduling( parent,
01004                                              "kcmkorganizergroupscheduling" );
01005   }
01006 }
01007 
01008 
01009 KOPrefsDialogGroupwareScheduling::KOPrefsDialogGroupwareScheduling( QWidget *parent, const char *name )
01010   : KPrefsModule( KOPrefs::instance(), parent, name )
01011 {
01012   mGroupwarePage = new KOGroupwarePrefsPage( this );
01013   connect( mGroupwarePage, SIGNAL( changed() ), SLOT( slotWidChanged() ) );
01014   ( new QVBoxLayout( this ) )->addWidget( mGroupwarePage );
01015 
01016   load();
01017 }
01018 
01019 void KOPrefsDialogGroupwareScheduling::usrReadConfig()
01020 {
01021   mGroupwarePage->publishEnable->setChecked( KOPrefs::instance()->mFreeBusyPublishAuto );
01022   mGroupwarePage->publishDelay->setValue( KOPrefs::instance()->mFreeBusyPublishDelay );
01023   mGroupwarePage->publishDays->setValue( KOPrefs::instance()->mFreeBusyPublishDays );
01024 
01025   mGroupwarePage->publishUrl->setText( KOPrefs::instance()->mFreeBusyPublishUrl );
01026   mGroupwarePage->publishUser->setText( KOPrefs::instance()->mFreeBusyPublishUser );
01027   mGroupwarePage->publishPassword->setText( KOPrefs::instance()->mFreeBusyPublishPassword );
01028   mGroupwarePage->publishSavePassword->setChecked( KOPrefs::instance()->mFreeBusyPublishSavePassword );
01029 
01030   mGroupwarePage->retrieveEnable->setChecked( KOPrefs::instance()->mFreeBusyRetrieveAuto );
01031   mGroupwarePage->fullDomainRetrieval->setChecked( KOPrefs::instance()->mFreeBusyFullDomainRetrieval );
01032   mGroupwarePage->retrieveUrl->setText( KOPrefs::instance()->mFreeBusyRetrieveUrl );
01033   mGroupwarePage->retrieveUser->setText( KOPrefs::instance()->mFreeBusyRetrieveUser );
01034   mGroupwarePage->retrievePassword->setText( KOPrefs::instance()->mFreeBusyRetrievePassword );
01035   mGroupwarePage->retrieveSavePassword->setChecked( KOPrefs::instance()->mFreeBusyRetrieveSavePassword );
01036 }
01037 
01038 void KOPrefsDialogGroupwareScheduling::usrWriteConfig()
01039 {
01040   KOPrefs::instance()->mFreeBusyPublishAuto = mGroupwarePage->publishEnable->isChecked();
01041   KOPrefs::instance()->mFreeBusyPublishDelay = mGroupwarePage->publishDelay->value();
01042   KOPrefs::instance()->mFreeBusyPublishDays = mGroupwarePage->publishDays->value();
01043 
01044   KOPrefs::instance()->mFreeBusyPublishUrl = mGroupwarePage->publishUrl->text();
01045   KOPrefs::instance()->mFreeBusyPublishUser = mGroupwarePage->publishUser->text();
01046   KOPrefs::instance()->mFreeBusyPublishPassword = mGroupwarePage->publishPassword->text();
01047   KOPrefs::instance()->mFreeBusyPublishSavePassword = mGroupwarePage->publishSavePassword->isChecked();
01048 
01049   KOPrefs::instance()->mFreeBusyRetrieveAuto = mGroupwarePage->retrieveEnable->isChecked();
01050   KOPrefs::instance()->mFreeBusyFullDomainRetrieval = mGroupwarePage->fullDomainRetrieval->isChecked();
01051   KOPrefs::instance()->mFreeBusyRetrieveUrl = mGroupwarePage->retrieveUrl->text();
01052   KOPrefs::instance()->mFreeBusyRetrieveUser = mGroupwarePage->retrieveUser->text();
01053   KOPrefs::instance()->mFreeBusyRetrievePassword = mGroupwarePage->retrievePassword->text();
01054   KOPrefs::instance()->mFreeBusyRetrieveSavePassword = mGroupwarePage->retrieveSavePassword->isChecked();
01055 
01056   // clear the url cache for our user
01057   QString configFile = locateLocal( "data", "korganizer/freebusyurls" );
01058   KConfig cfg( configFile );
01059   cfg.deleteGroup( KOPrefs::instance()->email() );
01060 }
01061 
01062 extern "C"
01063 {
01064   KCModule *create_korganizerconfigfreebusy( QWidget *parent, const char * )
01065   {
01066     return new KOPrefsDialogGroupwareScheduling( parent,
01067                                                  "kcmkorganizerfreebusy" );
01068   }
01069 }
01070 
01071 
01072 
01073 class PluginItem : public QCheckListItem {
01074   public:
01075     PluginItem( QListView *parent, KService::Ptr service ) :
01076       QCheckListItem( parent, service->name(), QCheckListItem::CheckBox ), mService( service )
01077     {}
01078     KService::Ptr service() { return mService; }
01079   private:
01080     KService::Ptr mService;
01081 };
01082 
01083 
01087 KOPrefsDialogPlugins::KOPrefsDialogPlugins( QWidget *parent, const char* name )
01088   : KPrefsModule( KOPrefs::instance(), parent, name )
01089 {
01090   QBoxLayout *topTopLayout = new QVBoxLayout( this );
01091 
01092   QWidget *topFrame = new QWidget( this );
01093   topTopLayout->addWidget( topFrame );
01094   QBoxLayout *topLayout = new QVBoxLayout( topFrame );
01095   topLayout->setSpacing( KDialog::spacingHint() );
01096 
01097   mListView = new QListView( topFrame );
01098   mListView->addColumn( i18n("Name") );
01099   mListView->setResizeMode( QListView::LastColumn );
01100   topLayout->addWidget( mListView );
01101 
01102   mDescription = new QLabel( topFrame );
01103   mDescription->setAlignment( QLabel::NoAccel | QLabel::WordBreak | QLabel::AlignVCenter );
01104   mDescription->setFrameShape( QLabel::Panel );
01105   mDescription->setFrameShadow( QLabel::Sunken );
01106   mDescription->setMinimumSize( QSize( 0, 55 ) );
01107   mDescription->setSizePolicy(
01108          QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0,
01109                       0, 0, mDescription->sizePolicy().hasHeightForWidth() ) );
01110   topLayout->addWidget( mDescription );
01111 
01112 
01113   QWidget *buttonRow = new QWidget( topFrame );
01114   QBoxLayout *buttonRowLayout = new QHBoxLayout( buttonRow );
01115   mConfigureButton = new KPushButton( KGuiItem( i18n("Configure &Plugin..."),
01116       "configure", QString::null, i18n("This button allows you to configure"
01117       " the plugin that you have selected in the list above") ), buttonRow );
01118 
01119   buttonRowLayout->addWidget( mConfigureButton );
01120   buttonRowLayout->addItem( new QSpacerItem(1, 1,  QSizePolicy::Expanding) );
01121   topLayout->addWidget( buttonRow );
01122   connect( mConfigureButton, SIGNAL( clicked() ), SLOT( configure() ) );
01123 
01124   connect( mListView, SIGNAL( selectionChanged( QListViewItem* ) ),
01125            SLOT( selectionChanged( QListViewItem* ) ) );
01126   connect( mListView, SIGNAL( clicked( QListViewItem* ) ),
01127            SLOT( slotWidChanged() ) );
01128 
01129   load();
01130 //  usrReadConfig();
01131   selectionChanged( 0 );
01132 }
01133 
01134 void KOPrefsDialogPlugins::usrReadConfig()
01135 {
01136   mListView->clear();
01137   KTrader::OfferList plugins = KOCore::self()->availablePlugins();
01138   plugins += KOCore::self()->availableParts();
01139 
01140   QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
01141 
01142   KTrader::OfferList::ConstIterator it;
01143   for( it = plugins.begin(); it != plugins.end(); ++it ) {
01144     QCheckListItem *item = new PluginItem( mListView, *it );
01145     if ( selectedPlugins.find( (*it)->desktopEntryName() ) !=
01146                                selectedPlugins.end() ) {
01147       item->setOn( true );
01148     }
01149   }
01150 }
01151 
01152 void KOPrefsDialogPlugins::usrWriteConfig()
01153 {
01154   QStringList selectedPlugins;
01155 
01156   PluginItem *item = static_cast<PluginItem *>( mListView->firstChild() );
01157   while( item ) {
01158     if( item->isOn() ) {
01159       selectedPlugins.append( item->service()->desktopEntryName() );
01160     }
01161     item = static_cast<PluginItem *>( item->nextSibling() );
01162   }
01163   KOPrefs::instance()->mSelectedPlugins = selectedPlugins;
01164 }
01165 
01166 void KOPrefsDialogPlugins::configure()
01167 {
01168   PluginItem *item = static_cast<PluginItem *>( mListView->selectedItem() );
01169   if ( !item ) return;
01170 
01171   KOrg::Plugin *plugin = KOCore::self()->loadPlugin( item->service() );
01172 
01173   if ( plugin ) {
01174     plugin->configure( this );
01175     delete plugin;
01176   } else {
01177     KMessageBox::sorry( this, i18n( "Unable to configure this plugin" ),
01178                         "PluginConfigUnable" );
01179   }
01180 }
01181 
01182 void KOPrefsDialogPlugins::selectionChanged( QListViewItem *i )
01183 {
01184   PluginItem *item = dynamic_cast<PluginItem*>( i );
01185   if ( !item ) {
01186     mConfigureButton->setEnabled( false );
01187     mDescription->setText( QString::null );
01188     return;
01189   }
01190 
01191   QVariant variant = item->service()->property( "X-KDE-KOrganizer-HasSettings" );
01192 
01193   bool hasSettings = true;
01194   if ( variant.isValid() )
01195     hasSettings = variant.toBool();
01196 
01197   mDescription->setText( item->service()->comment() );
01198   mConfigureButton->setEnabled( hasSettings );
01199 
01200   slotWidChanged();
01201 }
01202 
01203 extern "C"
01204 {
01205   KCModule *create_korganizerconfigplugins( QWidget *parent, const char * )
01206   {
01207     return new KOPrefsDialogPlugins( parent,
01208                                      "kcmkorganizerplugins" );
01209   }
01210 }
01211 
01212 
01213 extern "C"
01214 {
01215   KCModule *create_korgdesignerfields( QWidget *parent, const char * ) {
01216     return new KOPrefsDesignerFields( parent, "kcmkorgdesignerfields" );
01217   }
01218 }
01219 
01220 KOPrefsDesignerFields::KOPrefsDesignerFields( QWidget *parent, const char *name )
01221   : KCMDesignerFields( parent, name )
01222 {
01223 }
01224 
01225 QString KOPrefsDesignerFields::localUiDir()
01226 {
01227   QString dir = locateLocal( "data", "korganizer/designer/event/");
01228   kdDebug() << "KOPrefsDesignerFields::localUiDir(): " << dir << endl;
01229   return dir;
01230 }
01231 
01232 QString KOPrefsDesignerFields::uiPath()
01233 {
01234   return "korganizer/designer/event/";
01235 }
01236 
01237 void KOPrefsDesignerFields::writeActivePages( const QStringList &activePages )
01238 {
01239   KOPrefs::instance()->setActiveDesignerFields( activePages );
01240   KOPrefs::instance()->writeConfig();
01241 }
01242 
01243 QStringList KOPrefsDesignerFields::readActivePages()
01244 {
01245   return KOPrefs::instance()->activeDesignerFields();
01246 }
01247 
01248 QString KOPrefsDesignerFields::applicationName()
01249 {
01250   return "KORGANIZER";
01251 }
01252 
01253 #include "koprefsdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys