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