korganizer

koprefsdialog.cpp

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