korganizer Library API Documentation

koprefsdialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qlayout.h>
00026 #include <qlabel.h>
00027 #include <qgroupbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qlineedit.h>
00030 #include <qslider.h>
00031 #include <qfile.h>
00032 #include <qcombobox.h>
00033 #include <qhbox.h>
00034 #include <qspinbox.h>
00035 #include <qcheckbox.h>
00036 #include <qradiobutton.h>
00037 #include <qpushbutton.h>
00038 #include <qstrlist.h>
00039 #include <qlistview.h>
00040 #include <qtabwidget.h>
00041 #include <qwhatsthis.h>
00042 
00043 #include <kcolorbutton.h>
00044 #include <kdebug.h>
00045 #include <klocale.h>
00046 #include <kglobal.h>
00047 #include <kmessagebox.h>
00048 #include <kiconloader.h>
00049 #include <kemailsettings.h>
00050 #include <kcalendarsystem.h>
00051 #include <libkcal/calendarresources.h>
00052 #include <kocore.h>
00053 
00054 #if defined(USE_SOLARIS)
00055 #include <sys/param.h>
00056 
00057 #define ZONEINFODIR    "/usr/share/lib/zoneinfo"
00058 #define INITFILE       "/etc/default/init"
00059 #endif
00060 
00061 #include "koprefs.h"
00062 
00063 #include "koprefsdialog.h"
00064 #include "kogroupwareprefspage.h"
00065 #include "ktimeedit.h"
00066 #include "koglobals.h"
00067 #include "stdcalendar.h"
00068 
00069 
00070 KOPrefsDialogMain::KOPrefsDialogMain( QWidget *parent, const char *name )
00071   : KPrefsModule( KOPrefs::instance(), parent, name )
00072 {
00073   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00074 
00075   QWidget *topFrame = new QWidget( this );
00076   topTopLayout->addWidget( topFrame );
00077 
00078   QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
00079   topLayout->setSpacing( KDialog::spacingHint() );
00080 
00081   KPrefsWidBool *emailControlCenter =
00082       addWidBool( KOPrefs::instance()->emailControlCenterItem(), topFrame );
00083   topLayout->addMultiCellWidget(emailControlCenter->checkBox(),0,0,0,1);
00084   connect(emailControlCenter->checkBox(),SIGNAL(toggled(bool)),
00085           SLOT(toggleEmailSettings(bool)));
00086 
00087   mNameEdit = new QLineEdit(topFrame);
00088   connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
00089            SLOT( slotWidChanged() ) );
00090   mNameLabel = new QLabel(mNameEdit, i18n("Full &name:"), topFrame);
00091   topLayout->addWidget(mNameLabel,1,0);
00092   topLayout->addWidget(mNameEdit,1,1);
00093 
00094   mEmailEdit = new QLineEdit(topFrame);
00095   connect( mEmailEdit, SIGNAL( textChanged( const QString & ) ),
00096            SLOT( slotWidChanged() ) );
00097   mEmailLabel = new QLabel(mEmailEdit, i18n("E&mail address:"),topFrame);
00098   topLayout->addWidget(mEmailLabel,2,0);
00099   topLayout->addWidget(mEmailEdit,2,1);
00100 
00101   KPrefsWidBool *bcc =
00102       addWidBool( KOPrefs::instance()->bccItem(), topFrame );
00103   topLayout->addMultiCellWidget(bcc->checkBox(),4,4,0,1);
00104 
00105 
00106   QGroupBox *autoSaveGroup = new QGroupBox(1,Horizontal,i18n("Auto-Save"),
00107                                            topFrame);
00108   topLayout->addMultiCellWidget(autoSaveGroup,6,6,0,1);
00109 
00110   addWidBool( KOPrefs::instance()->autoSaveItem(), autoSaveGroup );
00111 
00112   QHBox *intervalBox = new QHBox(autoSaveGroup);
00113   intervalBox->setSpacing( KDialog::spacingHint() );
00114 
00115   QLabel *autoSaveIntervalLabel = new QLabel(i18n("Save &interval in minutes:"),intervalBox);
00116   mAutoSaveIntervalSpin = new QSpinBox(0,500,1,intervalBox);
00117   connect( mAutoSaveIntervalSpin, SIGNAL( valueChanged( int ) ),
00118            SLOT( slotWidChanged() ) );
00119   autoSaveIntervalLabel->setBuddy(mAutoSaveIntervalSpin);
00120 
00121   KPrefsWidBool *confirmCheck =
00122       addWidBool( KOPrefs::instance()->confirmItem(), topFrame );
00123   topLayout->addMultiCellWidget(confirmCheck->checkBox(),7,7,0,1);
00124 
00125   KPrefsWidRadios *mailClientGroup =
00126       addWidRadios( KOPrefs::instance()->mailClientItem(), topFrame );
00127   topLayout->addMultiCellWidget(mailClientGroup->groupBox(),11,11,0,1);
00128 
00129   KPrefsWidBool *useGroupwareBool =
00130       addWidBool( KOPrefs::instance()->useGroupwareCommunicationItem(),
00131       topFrame );
00132   topLayout->addMultiCellWidget(useGroupwareBool->checkBox(),12,12,0,1);
00133   // TODO: This radio button should only be available when KMail is chosen
00134 //   connect(thekmailradiobuttonupthere,SIGNAL(toggled(bool)),
00135 //           useGroupwareBool->checkBox(), SLOT(enabled(bool)));
00136 
00137   KPrefsWidBool *htmlsave =
00138       addWidBool( KOPrefs::instance()->htmlWithSaveItem(),
00139                   topFrame );
00140   topLayout->addMultiCellWidget(htmlsave->checkBox(),13,13,0,1);
00141 
00142   KPrefsWidRadios *destinationGroup =
00143       addWidRadios( KOPrefs::instance()->destinationItem(),
00144                    topFrame);
00145   topLayout->addMultiCellWidget(destinationGroup->groupBox(),14,14,0,1);
00146 
00147   topLayout->setRowStretch(15,1);
00148 
00149   load();
00150 }
00151 
00152 void KOPrefsDialogMain::usrReadConfig()
00153 {
00154   mNameEdit->setText(KOPrefs::instance()->fullName());
00155   mEmailEdit->setText(KOPrefs::instance()->email());
00156 
00157   mAutoSaveIntervalSpin->setValue(KOPrefs::instance()->mAutoSaveInterval);
00158 }
00159 
00160 void KOPrefsDialogMain::usrWriteConfig()
00161 {
00162   KOPrefs::instance()->setFullName(mNameEdit->text());
00163   KOPrefs::instance()->setEmail(mEmailEdit->text());
00164 
00165   KOPrefs::instance()->mAutoSaveInterval = mAutoSaveIntervalSpin->value();
00166 }
00167 
00168 void KOPrefsDialogMain::toggleEmailSettings( bool on )
00169 {
00170   if (on) {
00171     mEmailEdit->setEnabled(false);
00172     mNameEdit->setEnabled(false);
00173     mEmailLabel->setEnabled(false);
00174     mNameLabel->setEnabled(false);
00175 
00176     KEMailSettings settings;
00177     mNameEdit->setText(settings.getSetting(KEMailSettings::RealName));
00178     mEmailEdit->setText(settings.getSetting(KEMailSettings::EmailAddress));
00179   } else {
00180     mEmailEdit->setEnabled(true);
00181     mNameEdit->setEnabled(true);
00182     mEmailLabel->setEnabled(true);
00183     mNameLabel->setEnabled(true);
00184 
00185     mNameEdit->setText( KOPrefs::instance()->mName );
00186     mEmailEdit->setText( KOPrefs::instance()->mEmail );
00187   }
00188 }
00189 
00190 extern "C"
00191 {
00192   KCModule *create_korganizerconfigmain( QWidget *parent, const char * )
00193   {
00194     return new KOPrefsDialogMain( parent, "kcmkorganizermain" );
00195   }
00196 }
00197 
00198 
00199 class KOPrefsDialogTime : public KPrefsModule
00200 {
00201   public:
00202     KOPrefsDialogTime( QWidget *parent, const char *name )
00203       : KPrefsModule( KOPrefs::instance(), parent, name )
00204     {
00205       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00206 
00207       QWidget *topFrame = new QWidget( this );
00208       topTopLayout->addWidget( topFrame );
00209 
00210       QGridLayout *topLayout = new QGridLayout(topFrame,5,2);
00211       topLayout->setSpacing( KDialog::spacingHint() );
00212 
00213       QHBox *timeZoneBox = new QHBox( topFrame );
00214       topLayout->addMultiCellWidget( timeZoneBox, 0, 0, 0, 1 );
00215 
00216       new QLabel( i18n("Timezone:"), timeZoneBox );
00217       mTimeZoneCombo = new QComboBox( timeZoneBox );
00218       connect( mTimeZoneCombo, SIGNAL( activated( int ) ),
00219                SLOT( slotWidChanged() ) );
00220 
00221       FILE *f;
00222       char tempstring[101] = "Unknown";
00223       QString sCurrentlySet(i18n("Unknown"));
00224       int nCurrentlySet = 0;
00225       QStringList list;
00226 
00227       // read the currently set time zone
00228     #if defined(USE_SOLARIS)       // MARCO
00229         char buf[MAXPATHLEN];
00230 
00231         snprintf(buf, MAXPATHLEN,
00232                 "/bin/fgrep 'TZ=' %s | /bin/head -n 1 | /bin/cut -b 4-",
00233                 INITFILE);
00234 
00235         if (f = popen(buf, "r"))
00236           {
00237            if (fgets(buf, MAXPATHLEN - 1, f) != NULL)
00238              {
00239                buf[strlen(buf) - 1] = '\0';
00240                sCurrentlySet = QString(buf);
00241              }
00242            pclose(f);
00243           }
00244     #else
00245       if((f = fopen("/etc/timezone", "r")) != NULL) {
00246         // get the currently set timezone
00247         fgets(tempstring, 100, f);
00248         tempstring[strlen(tempstring) - 1] = '\0';
00249         sCurrentlySet = QString(tempstring);
00250         fclose(f);
00251       }
00252     #endif // !USE_SOLARIS
00253 
00254       mTimeZoneCombo->insertItem(i18n("[No selection]"));
00255 
00256       // Read all system time zones
00257     #if defined(USE_SOLARIS)       // MARCO
00258         snprintf(buf, MAXPATHLEN,
00259                "/bin/find %s \\( -name src -prune \\) -o -type f -print | /bin/cut -b %d-",
00260                ZONEINFODIR, strlen(ZONEINFODIR) + 2);
00261 
00262         if (f = popen(buf, "r"))
00263           {
00264            while(fgets(buf, MAXPATHLEN - 1, f) != NULL)
00265              {
00266                buf[strlen(buf) - 1] = '\0';
00267                list.append(buf);
00268              }
00269            pclose(f);
00270           }
00271 
00272     #else
00273       f = popen("grep -e  ^[^#] /usr/share/zoneinfo/zone.tab | cut -f 3","r");
00274       if (!f) return;
00275       while(fgets(tempstring, 100, f) != NULL) {
00276         tempstring[strlen(tempstring)-1] = '\0';
00277         list.append(i18n(tempstring));
00278         tzonenames << tempstring;
00279       }
00280       pclose(f);
00281     #endif // !USE_SOLARIS
00282       list.sort();
00283 
00284       mTimeZoneCombo->insertStringList(list);
00285 
00286         // find the currently set time zone and select it
00287       for (int i = 0; i < mTimeZoneCombo->count(); i++)
00288         {
00289           if (mTimeZoneCombo->text(i) == sCurrentlySet)
00290             {
00291              nCurrentlySet = i;
00292              break;
00293             }
00294         }
00295 
00296       mTimeZoneCombo->setCurrentItem(nCurrentlySet);
00297 
00298       KPrefsWidTime *dayBegins =
00299         addWidTime( KOPrefs::instance()->dayBeginsItem(), topFrame );
00300       topLayout->addWidget( dayBegins->label(), 1, 0 );
00301       topLayout->addWidget(dayBegins->timeEdit(), 1, 1 );
00302 
00303       KPrefsWidTime *defaultTime =
00304             addWidTime( KOPrefs::instance()->startTimeItem(), topFrame );
00305       topLayout->addWidget( defaultTime->label(), 2, 0);
00306       topLayout->addWidget( defaultTime->timeEdit(), 2, 1);
00307 
00308       KPrefsWidTime *defaultDuration =
00309             addWidTime( KOPrefs::instance()->defaultDurationItem(), topFrame );
00310       topLayout->addWidget( defaultDuration->label(), 3, 0);
00311       topLayout->addWidget( defaultDuration->timeEdit(), 3, 1);
00312 
00313       QStringList alarmList;
00314       alarmList << i18n("1 minute") << i18n("5 minutes") << i18n("10 minutes")
00315                 << i18n("15 minutes") << i18n("30 minutes");
00316       topLayout->addWidget(new QLabel(i18n("Default alarm time:"),topFrame),
00317                            4,0);
00318       mAlarmTimeCombo = new QComboBox(topFrame);
00319       connect( mAlarmTimeCombo, SIGNAL( activated( int ) ),
00320                SLOT( slotWidChanged() ) );
00321       mAlarmTimeCombo->insertStringList(alarmList);
00322       topLayout->addWidget(mAlarmTimeCombo,4,1);
00323 
00324 
00325       QGroupBox *workingHoursGroup = new QGroupBox(1,Horizontal,
00326                                                    i18n("Working Hours"),
00327                                                    topFrame);
00328       topLayout->addMultiCellWidget(workingHoursGroup,5,5,0,1);
00329 
00330       QHBox *workDaysBox = new QHBox( workingHoursGroup );
00331       // Respect start of week setting
00332       int weekStart=KGlobal::locale()->weekStartDay();
00333       for ( int i = 0; i < 7; ++i ) {
00334         const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00335         QString weekDayName = calSys->weekDayName( (i + weekStart + 6)%7 + 1, true );
00336         if ( KOPrefs::instance()->mCompactDialogs ) {
00337           weekDayName = weekDayName.left( 1 );
00338         }
00339         mWorkDays[ (i + weekStart + 6)%7 ] = new QCheckBox( weekDayName, workDaysBox );
00340       }
00341       for ( int i = 0; i < 7; ++i ) {
00342         connect( mWorkDays[i], SIGNAL( stateChanged( int ) ),
00343                SLOT( slotWidChanged() ) );
00344       }
00345 
00346       QHBox *workStartBox = new QHBox(workingHoursGroup);
00347       addWidTime( KOPrefs::instance()->workingHoursStartItem(), workStartBox );
00348 
00349       QHBox *workEndBox = new QHBox(workingHoursGroup);
00350       addWidTime( KOPrefs::instance()->workingHoursEndItem(), workEndBox );
00351 
00352 
00353       addWidBool( KOPrefs::instance()->excludeHolidaysItem(),
00354                   workingHoursGroup );
00355 
00356       topLayout->setRowStretch(7,1);
00357 
00358       load();
00359     }
00360 
00361   protected:
00362     void usrReadConfig()
00363     {
00364       setCombo(mTimeZoneCombo,i18n(KOPrefs::instance()->mTimeZoneId.utf8()));
00365 
00366       mAlarmTimeCombo->setCurrentItem(KOPrefs::instance()->mAlarmTime);
00367       for ( int i = 0; i < 7; ++i ) {
00368         mWorkDays[i]->setChecked( (1<<i) & (KOPrefs::instance()->mWorkWeekMask) );
00369       }
00370     }
00371 
00372     void usrWriteConfig()
00373     {
00374       // Find untranslated selected zone
00375       QStringList::Iterator tz;
00376       for (tz = tzonenames.begin(); tz != tzonenames.end(); tz++)
00377         if (mTimeZoneCombo->currentText() == i18n((*tz).utf8()))
00378           break;
00379       if (tz != tzonenames.end())
00380         KOPrefs::instance()->mTimeZoneId = (*tz);
00381       else
00382         KOPrefs::instance()->mTimeZoneId = mTimeZoneCombo->currentText();
00383 
00384       KOPrefs::instance()->mAlarmTime = mAlarmTimeCombo->currentItem();
00385       int mask = 0;
00386       for ( int i = 0; i < 7; ++i ) {
00387         if (mWorkDays[i]->isChecked()) mask = mask | (1<<i);
00388       }
00389       KOPrefs::instance()->mWorkWeekMask = mask;
00390       KOPrefs::instance()->writeConfig();
00391     }
00392 
00393     void setCombo( QComboBox *combo, const QString &text,
00394                    const QStringList *tags = 0 )
00395     {
00396       if (tags) {
00397         int i = tags->findIndex(text);
00398         if (i > 0) combo->setCurrentItem(i);
00399       } else {
00400         for(int i=0;i<combo->count();++i) {
00401           if (combo->text(i) == text) {
00402             combo->setCurrentItem(i);
00403             break;
00404           }
00405         }
00406       }
00407     }
00408 
00409   private:
00410     QComboBox    *mTimeZoneCombo;
00411     QStringList   tzonenames;
00412     QComboBox    *mAlarmTimeCombo;
00413     QCheckBox    *mWorkDays[7];
00414 };
00415 
00416 extern "C"
00417 {
00418   KCModule *create_korganizerconfigtime( QWidget *parent, const char * )
00419   {
00420     KGlobal::locale()->insertCatalogue( "timezones" );
00421     return new KOPrefsDialogTime( parent, "kcmkorganizertime" );
00422   }
00423 }
00424 
00425 
00426 class KOPrefsDialogViews : public KPrefsModule
00427 {
00428   public:
00429     KOPrefsDialogViews( QWidget *parent, const char *name )
00430       : KPrefsModule( KOPrefs::instance(), parent, name )
00431     {
00432       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00433 
00434       QWidget *topFrame = new QWidget( this );
00435       topTopLayout->addWidget( topFrame );
00436 
00437       QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00438       topLayout->setSpacing( KDialog::spacingHint() );
00439 
00440       KPrefsWidBool *enableToolTips =
00441           addWidBool( KOPrefs::instance()->enableToolTipsItem(), topFrame );
00442       topLayout->addWidget( enableToolTips->checkBox() );
00443 
00444       KPrefsWidBool *showTodosAgenda =
00445           addWidBool( KOPrefs::instance()->showAllDayTodoItem(), topFrame );
00446       topLayout->addWidget( showTodosAgenda->checkBox() );
00447 
00448       /*** Date Navigator Group ***/
00449       QGroupBox *dateNavGroup = new QGroupBox( 1, Horizontal,
00450                                                i18n("Date Navigator"),
00451                                                topFrame );
00452       addWidBool( KOPrefs::instance()->dailyRecurItem(), dateNavGroup );
00453       addWidBool( KOPrefs::instance()->weeklyRecurItem(), dateNavGroup );
00454       topLayout->addWidget( dateNavGroup );
00455 
00456 
00457       /*** Agenda View Group ***/
00458       QGroupBox *agendaGroup = new QGroupBox( 1, Horizontal,
00459                                               i18n("Agenda View"),
00460                                               topFrame );
00461 
00462       QHBox *hourSizeBox = new QHBox( agendaGroup );
00463       KPrefsWidInt *hourSize =
00464           addWidInt( KOPrefs::instance()->hourSizeItem(), hourSizeBox );
00465       hourSize->spinBox()->setSuffix(i18n("suffix in the hour size spin box", " pixel"));
00466       new QWidget( hourSizeBox );
00467 
00468       QHBox *nextDaysBox = new QHBox( agendaGroup );
00469       KPrefsWidInt *nextDays =
00470         addWidInt( KOPrefs::instance()->nextXDaysItem(), nextDaysBox );
00471       nextDays->spinBox()->setSuffix(i18n("suffix in the N days spin box", " days"));
00472       new QWidget( nextDaysBox );
00473 
00474       KPrefsWidBool *marcusBainsEnabled =
00475           addWidBool( KOPrefs::instance()->marcusBainsEnabledItem(), agendaGroup );
00476 
00477       KPrefsWidBool *marcusBainsShowSeconds =
00478           addWidBool( KOPrefs::instance()->marcusBainsShowSecondsItem(), agendaGroup );
00479       connect( marcusBainsEnabled->checkBox(), SIGNAL( toggled( bool ) ),
00480                marcusBainsShowSeconds->checkBox(), SLOT( setEnabled( bool ) ) );
00481 
00482       addWidBool( KOPrefs::instance()->selectionStartsEditorItem(), agendaGroup );
00483 
00484       addWidBool( KOPrefs::instance()->agendaViewUsesResourceColorItem(), agendaGroup );
00485 
00486       topLayout->addWidget( agendaGroup );
00487 
00488 
00489       /*** Month View Group ***/
00490       QGroupBox *monthGroup = new QGroupBox( 1, Horizontal,
00491                                              i18n("Month View"),
00492                                              topFrame );
00493       addWidBool( KOPrefs::instance()->enableMonthScrollItem(), monthGroup );
00494       addWidBool( KOPrefs::instance()->fullViewMonthItem(), monthGroup );
00495       addWidBool( KOPrefs::instance()->monthViewUsesCategoryColorItem(),
00496                       monthGroup );
00497       addWidBool( KOPrefs::instance()->monthViewUsesResourceColorItem(), monthGroup );
00498       topLayout->addWidget( monthGroup );
00499 
00500 
00501       /*** Todo View Group ***/
00502       QGroupBox *todoGroup = new QGroupBox( 1, Horizontal,
00503                                             i18n("Todo View"),
00504                                             topFrame );
00505       addWidBool( KOPrefs::instance()->fullViewTodoItem(), todoGroup );
00506       topLayout->addWidget( todoGroup );
00507 
00508       topLayout->addStretch( 1 );
00509 
00510       load();
00511     }
00512 };
00513 
00514 extern "C"
00515 {
00516   KCModule *create_korganizerconfigviews( QWidget *parent, const char * )
00517   {
00518     return new KOPrefsDialogViews( parent, "kcmkorganizerviews" );
00519   }
00520 }
00521 
00522 
00523 class KOPrefsDialogFonts : public KPrefsModule
00524 {
00525   public:
00526     KOPrefsDialogFonts( QWidget *parent, const char *name )
00527       : KPrefsModule( KOPrefs::instance(), parent, name )
00528     {
00529       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00530 
00531       QWidget *topFrame = new QWidget( this );
00532       topTopLayout->addWidget( topFrame );
00533 
00534       QGridLayout *topLayout = new QGridLayout(topFrame,5,3);
00535       topLayout->setSpacing( KDialog::spacingHint() );
00536 
00537       KPrefsWidFont *timeBarFont =
00538           addWidFont( KOPrefs::instance()->timeBarFontItem(), topFrame,
00539                       KGlobal::locale()->formatTime( QTime( 12, 34 ) ) );
00540       topLayout->addWidget(timeBarFont->label(),0,0);
00541       topLayout->addWidget(timeBarFont->preview(),0,1);
00542       topLayout->addWidget(timeBarFont->button(),0,2);
00543 
00544       KPrefsWidFont *monthViewFont =
00545           addWidFont( KOPrefs::instance()->monthViewFontItem(), topFrame,
00546                       KGlobal::locale()->formatTime(QTime(12,34)) + " " +
00547                       i18n("Event text") );
00548 
00549       topLayout->addWidget(monthViewFont->label(),1,0);
00550       topLayout->addWidget(monthViewFont->preview(),1,1);
00551       topLayout->addWidget(monthViewFont->button(),1,2);
00552 
00553       KPrefsWidFont *agendaViewFont =
00554           addWidFont( KOPrefs::instance()->agendaViewFontItem(),
00555                       topFrame, i18n("Event text") );
00556       topLayout->addWidget(agendaViewFont->label(),2,0);
00557       topLayout->addWidget(agendaViewFont->preview(),2,1);
00558       topLayout->addWidget(agendaViewFont->button(),2,2);
00559 
00560       KPrefsWidFont *marcusBainsFont =
00561           addWidFont( KOPrefs::instance()->marcusBainsFontItem(), topFrame,
00562                       KGlobal::locale()->formatTime( QTime( 12, 34, 23 ) ) );
00563       topLayout->addWidget(marcusBainsFont->label(),3,0);
00564       topLayout->addWidget(marcusBainsFont->preview(),3,1);
00565       topLayout->addWidget(marcusBainsFont->button(),3,2);
00566 
00567       topLayout->setColStretch(1,1);
00568       topLayout->setRowStretch(4,1);
00569 
00570       load();
00571     }
00572 };
00573 
00574 extern "C"
00575 {
00576   KCModule *create_korganizerconfigfonts( QWidget *parent, const char * )
00577   {
00578     return new KOPrefsDialogFonts( parent, "kcmkorganizerfonts" );
00579   }
00580 }
00581 
00582 
00583 KOPrefsDialogColors::KOPrefsDialogColors( QWidget *parent, const char *name )
00584       : KPrefsModule( KOPrefs::instance(), parent, name )
00585 {
00586   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00587 
00588   QWidget *topFrame = new QWidget( this );
00589   topTopLayout->addWidget( topFrame );
00590 
00591   QGridLayout *topLayout = new QGridLayout(topFrame,7,2);
00592   topLayout->setSpacing( KDialog::spacingHint() );
00593 
00594   // Holiday Color
00595   KPrefsWidColor *holidayColor =
00596       addWidColor( KOPrefs::instance()->holidayColorItem(), topFrame );
00597   topLayout->addWidget(holidayColor->label(),0,0);
00598   topLayout->addWidget(holidayColor->button(),0,1);
00599 
00600   // Highlight Color
00601   KPrefsWidColor *highlightColor =
00602       addWidColor( KOPrefs::instance()->highlightColorItem(), topFrame );
00603   topLayout->addWidget(highlightColor->label(),1,0);
00604   topLayout->addWidget(highlightColor->button(),1,1);
00605 
00606   KPrefsWidColor *eventColor =
00607       addWidColor( KOPrefs::instance()->eventColorItem(), topFrame );
00608   topLayout->addWidget(eventColor->label(),2,0);
00609   topLayout->addWidget(eventColor->button(),2,1);
00610 
00611   // agenda view background color
00612   KPrefsWidColor *agendaBgColor =
00613       addWidColor( KOPrefs::instance()->agendaBgColorItem(), topFrame );
00614   topLayout->addWidget(agendaBgColor->label(),3,0);
00615   topLayout->addWidget(agendaBgColor->button(),3,1);
00616 
00617   // working hours color
00618   KPrefsWidColor *workingHoursColor =
00619       addWidColor( KOPrefs::instance()->workingHoursColorItem(), topFrame );
00620   topLayout->addWidget(workingHoursColor->label(),4,0);
00621   topLayout->addWidget(workingHoursColor->button(),4,1);
00622 
00623   // Todo due today color
00624   KPrefsWidColor *todoDueTodayColor =
00625       addWidColor( KOPrefs::instance()->todoDueTodayColorItem(), topFrame );
00626   topLayout->addWidget(todoDueTodayColor->label(),5,0);
00627   topLayout->addWidget(todoDueTodayColor->button(),5,1);
00628 
00629   // Todo overdue color
00630   KPrefsWidColor *todoOverdueColor =
00631       addWidColor( KOPrefs::instance()->todoOverdueColorItem(), topFrame );
00632   topLayout->addWidget(todoOverdueColor->label(),6,0);
00633   topLayout->addWidget(todoOverdueColor->button(),6,1);
00634 
00635   // categories colors
00636   QGroupBox *categoryGroup = new QGroupBox(1,Horizontal,i18n("Categories"),
00637                                            topFrame);
00638   topLayout->addMultiCellWidget(categoryGroup,7,7,0,1);
00639 
00640   mCategoryCombo = new QComboBox(categoryGroup);
00641   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00642   connect(mCategoryCombo,SIGNAL(activated(int)),SLOT(updateCategoryColor()));
00643 
00644   mCategoryButton = new KColorButton(categoryGroup);
00645   connect(mCategoryButton,SIGNAL(changed(const QColor &)),SLOT(setCategoryColor()));
00646   updateCategoryColor();
00647 
00648   // resources colors
00649   QGroupBox *resourceGroup = new QGroupBox(1,Horizontal,i18n("Resources"),
00650                                            topFrame);
00651   topLayout->addMultiCellWidget(resourceGroup,8,8,0,1);
00652 
00653   mResourceCombo = new QComboBox(resourceGroup);
00654   QWhatsThis::add( mResourceCombo,
00655                    i18n( "Select here resource you want to modify. "
00656                          "You can change the selected resource color using "
00657                          "the button below." ) );
00658   connect(mResourceCombo,SIGNAL(activated(int)),SLOT(updateResourceColor()));
00659 
00660   mResourceButton = new KColorButton(resourceGroup);
00661   QWhatsThis::add( mResourceButton,
00662                    i18n( "Choose here the color of the resource selected "
00663                          "using the combo box above." ) );
00664   connect(mResourceButton,SIGNAL(changed(const QColor &)),SLOT(setResourceColor()));
00665   updateResources();
00666 
00667   topLayout->setRowStretch(9,1);
00668 
00669   load();
00670 }
00671 
00672 void KOPrefsDialogColors::usrWriteConfig()
00673 {
00674   QDictIterator<QColor> itCat(mCategoryDict);
00675   while (itCat.current()) {
00676     KOPrefs::instance()->setCategoryColor(itCat.currentKey(),*itCat.current());
00677     ++itCat;
00678   }
00679 
00680   QDictIterator<QColor> itRes(mResourceDict);
00681   while (itRes.current()) {
00682     KOPrefs::instance()->setResourceColor(itRes.currentKey(),*itRes.current());
00683     ++itRes;
00684   }
00685 }
00686 
00687 void KOPrefsDialogColors::usrReadConfig()
00688 {
00689   updateCategories();
00690   updateResources();
00691 }
00692 
00693 void KOPrefsDialogColors::updateCategories()
00694 {
00695   mCategoryCombo->clear();
00696   mCategoryCombo->insertStringList(KOPrefs::instance()->mCustomCategories);
00697   updateCategoryColor();
00698 }
00699 
00700 void KOPrefsDialogColors::setCategoryColor()
00701 {
00702   mCategoryDict.replace(mCategoryCombo->currentText(), new QColor(mCategoryButton->color()));
00703 }
00704 
00705 void KOPrefsDialogColors::updateCategoryColor()
00706 {
00707   QString cat = mCategoryCombo->currentText();
00708   QColor *color = mCategoryDict.find(cat);
00709   if (!color) {
00710     color = KOPrefs::instance()->categoryColor(cat);
00711   }
00712   if (color) {
00713     mCategoryButton->setColor(*color);
00714     slotWidChanged();
00715   }
00716 }
00717 
00718 void KOPrefsDialogColors::updateResources()
00719 {
00720   mResourceCombo->clear();
00721   mResourceIdentifier.clear();
00722   kdDebug( 5850) << "KOPrefsDialogColors::updateResources()" << endl;
00723 
00724   KCal::CalendarResourceManager *manager = KOrg::StdCalendar::self()->resourceManager();
00725 
00726   kdDebug(5850) << "Loading Calendar resources...:" << endl;
00727   KCal::CalendarResourceManager::Iterator it;
00728   for( it = manager->begin(); it != manager->end(); ++it ) {
00729     if ( !(*it)->subresources().isEmpty() ) {
00730       QStringList subresources = (*it)->subresources();
00731       for ( uint i = 0; i < subresources.count(); ++i ) {
00732         QString resource = subresources[ i ];
00733         if ( (*it)->subresourceActive( resource ) ) {
00734           mResourceCombo->insertItem( (*it)->labelForSubresource( resource ) );
00735           mResourceIdentifier.append( resource );
00736         }
00737       }
00738     }
00739 
00740     mResourceCombo->insertItem( (*it)->resourceName() );
00741     mResourceIdentifier.append( (*it)->identifier() );
00742   }
00743 
00744   updateResourceColor();
00745 }
00746 
00747 void KOPrefsDialogColors::setResourceColor()
00748 {
00749   kdDebug( 5850) << "KOPrefsDialogColors::setResorceColor()" << endl;
00750 
00751   mResourceDict.replace( mResourceIdentifier[mResourceCombo->currentItem()],
00752     new QColor( mResourceButton->color() ) );
00753   slotWidChanged();
00754 }
00755 
00756 void KOPrefsDialogColors::updateResourceColor()
00757 {
00758   kdDebug( 5850 ) << "KOPrefsDialogColors::updateResourceColor()" << endl;
00759   QString res= mResourceIdentifier[mResourceCombo->currentItem()];
00760   QColor *color = mCategoryDict.find(res);
00761   if( !color )  {
00762     color = KOPrefs::instance()->resourceColor( res );
00763   }
00764   if( color ) {
00765     mResourceButton->setColor(*color);
00766   }
00767 }
00768 
00769 extern "C"
00770 {
00771   KCModule *create_korganizerconfigcolors( QWidget *parent, const char * )
00772   {
00773     return new KOPrefsDialogColors( parent, "kcmkorganizercolors" );
00774   }
00775 }
00776 
00777 
00778 class KOPrefsDialogPrinting : public KPrefsModule
00779 {
00780   public:
00781     KOPrefsDialogPrinting( QWidget *parent, const char *name )
00782       : KPrefsModule( KOPrefs::instance(), parent, name )
00783     {
00784       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00785 
00786       QWidget *topFrame = new QWidget( this );
00787       topTopLayout->addWidget( topFrame );
00788 
00789       QGridLayout *topLayout = new QGridLayout( topFrame, 5, 2 );
00790       topLayout->setSpacing( KDialog::spacingHint() );
00791 
00792       topLayout->setRowStretch( 4, 1 );
00793 
00794       load();
00795     }
00796 };
00797 
00798 extern "C"
00799 {
00800   KCModule *create_korganizerconfigprinting( QWidget *parent, const char * )
00801   {
00802     return new KOPrefsDialogPrinting( parent, "kcmkorganizerprinting" );
00803   }
00804 }
00805 
00806 
00807 KOPrefsDialogGroupScheduling::KOPrefsDialogGroupScheduling( QWidget *parent, const char *name )
00808   : KPrefsModule( KOPrefs::instance(), parent, name )
00809 {
00810   QBoxLayout *topTopLayout = new QVBoxLayout( this );
00811 
00812   QWidget *topFrame = new QWidget( this );
00813   topTopLayout->addWidget( topFrame );
00814 
00815   QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
00816   topLayout->setSpacing( KDialog::spacingHint() );
00817 
00818 #if 0
00819   KPrefsWidRadios *schedulerGroup =
00820       addWidRadios(i18n("Scheduler Mail Client"),KOPrefs::instance()->mIMIPScheduler,
00821                    topFrame);
00822   schedulerGroup->addRadio("Dummy"); // Only for debugging
00823   schedulerGroup->addRadio(i18n("Mail client"));
00824 
00825   topLayout->addMultiCellWidget(schedulerGroup->groupBox(),0,0,0,1);
00826 #endif
00827 
00828   KPrefsWidRadios *sendGroup =
00829       addWidRadios( KOPrefs::instance()->iMIPSendItem(),
00830                     topFrame );
00831 
00832   topLayout->addMultiCellWidget(sendGroup->groupBox(),1,1,0,1);
00833 
00834   topLayout->addMultiCellWidget(new QLabel(i18n("Additional email addresses:"),topFrame),2,2,0,1);
00835   mAMails = new QListView(topFrame);
00836   mAMails->addColumn(i18n("Email"),300);
00837   topLayout->addMultiCellWidget(mAMails,3,3,0,1);
00838 
00839   topLayout->addWidget(new QLabel(i18n("Additional email address:"),topFrame),4,0);
00840   aEmailsEdit = new QLineEdit(topFrame);
00841   aEmailsEdit->setEnabled(false);
00842   topLayout->addWidget(aEmailsEdit,4,1);
00843 
00844   QPushButton *add = new QPushButton(i18n("New"),topFrame,"new");
00845   topLayout->addWidget(add,5,0);
00846   QPushButton *del = new QPushButton(i18n("Remove"),topFrame,"remove");
00847   topLayout->addWidget(del,5,1);
00848 
00849   //topLayout->setRowStretch(2,1);
00850   connect(add, SIGNAL( clicked() ), this, SLOT(addItem()) );
00851   connect(del, SIGNAL( clicked() ), this, SLOT(removeItem()) );
00852   connect(aEmailsEdit,SIGNAL( textChanged(const QString&) ), this,SLOT(updateItem()));
00853   connect(mAMails,SIGNAL(selectionChanged(QListViewItem *)),SLOT(updateInput()));
00854 
00855   load();
00856 }
00857 
00858 void KOPrefsDialogGroupScheduling::usrReadConfig()
00859 {
00860   mAMails->clear();
00861   for ( QStringList::Iterator it = KOPrefs::instance()->mAdditionalMails.begin();
00862             it != KOPrefs::instance()->mAdditionalMails.end(); ++it ) {
00863     QListViewItem *item = new QListViewItem(mAMails);
00864     item->setText(0,*it);
00865     mAMails->insertItem(item);
00866   }
00867 }
00868 
00869 void KOPrefsDialogGroupScheduling::usrWriteConfig()
00870 {
00871   KOPrefs::instance()->mAdditionalMails.clear();
00872   QListViewItem *item;
00873   item = mAMails->firstChild();
00874   while (item)
00875   {
00876     KOPrefs::instance()->mAdditionalMails.append( item->text(0) );
00877     item = item->nextSibling();
00878   }
00879 }
00880 
00881 void KOPrefsDialogGroupScheduling::addItem()
00882 {
00883   aEmailsEdit->setEnabled(true);
00884   QListViewItem *item = new QListViewItem(mAMails);
00885   mAMails->insertItem(item);
00886   mAMails->setSelected(item,true);
00887   aEmailsEdit->setText(i18n("(EmptyEmail)"));
00888   slotWidChanged();
00889 }
00890 
00891 void KOPrefsDialogGroupScheduling::removeItem()
00892 {
00893   QListViewItem *item;
00894   item = mAMails->selectedItem();
00895   if (!item) return;
00896   mAMails->takeItem(item);
00897   item = mAMails->selectedItem();
00898   if (!item) {
00899     aEmailsEdit->setText("");
00900     aEmailsEdit->setEnabled(false);
00901   }
00902   if (mAMails->childCount() == 0) {
00903     aEmailsEdit->setEnabled(false);
00904   }
00905   slotWidChanged();
00906 }
00907 
00908 void KOPrefsDialogGroupScheduling::updateItem()
00909 {
00910   QListViewItem *item;
00911   item = mAMails->selectedItem();
00912   if (!item) return;
00913   item->setText(0,aEmailsEdit->text());
00914   slotWidChanged();
00915 }
00916 
00917 void KOPrefsDialogGroupScheduling::updateInput()
00918 {
00919   QListViewItem *item;
00920   item = mAMails->selectedItem();
00921   if (!item) return;
00922   aEmailsEdit->setEnabled(true);
00923   aEmailsEdit->setText(item->text(0));
00924 }
00925 
00926 extern "C"
00927 {
00928   KCModule *create_korganizerconfiggroupscheduling( QWidget *parent,
00929                                                      const char * )
00930   {
00931     return new KOPrefsDialogGroupScheduling( parent,
00932                                              "kcmkorganizergroupscheduling" );
00933   }
00934 }
00935 
00936 
00937 class KOPrefsDialogGroupAutomation : public KPrefsModule
00938 {
00939   public:
00940     KOPrefsDialogGroupAutomation( QWidget *parent, const char *name )
00941       : KPrefsModule( KOPrefs::instance(), parent, name )
00942     {
00943       QBoxLayout *topTopLayout = new QVBoxLayout( this );
00944 
00945       QWidget *topFrame = new QWidget( this );
00946       topTopLayout->addWidget( topFrame );
00947 
00948       QGridLayout *topLayout = new QGridLayout(topFrame,6,1);
00949       topLayout->setSpacing( KDialog::spacingHint() );
00950 
00951       KPrefsWidRadios *autoRefreshGroup =
00952           addWidRadios( KOPrefs::instance()->iMIPAutoRefreshItem(), topFrame );
00953       topLayout->addMultiCellWidget(autoRefreshGroup->groupBox(),0,0,0,0);
00954 
00955       KPrefsWidRadios *autoInsertGroup =
00956           addWidRadios( KOPrefs::instance()->iMIPAutoInsertReplyItem(),
00957                         topFrame );
00958       autoInsertGroup->addRadio(i18n("Never"));
00959       autoInsertGroup->addRadio(i18n("If attendee is in addressbook"));
00960       //autoInsertGroup->addRadio(i18n("selected emails"));
00961       topLayout->addMultiCellWidget(autoInsertGroup->groupBox(),1,1,0,0);
00962 
00963       KPrefsWidRadios *autoRequestGroup =
00964           addWidRadios( KOPrefs::instance()->iMIPAutoInsertRequestItem(),
00965                         topFrame );
00966       autoRequestGroup->addRadio(i18n("Never"));
00967       autoRequestGroup->addRadio(i18n("If organizer is in addressbook"));
00968       //autoInsertGroup->addRadio(i18n("selected emails"));
00969       topLayout->addMultiCellWidget(autoRequestGroup->groupBox(),2,2,0,0);
00970 
00971       KPrefsWidRadios *autoFreeBusyGroup =
00972           addWidRadios( KOPrefs::instance()->iMIPAutoFreeBusyItem(), topFrame );
00973       autoFreeBusyGroup->addRadio(i18n("Never"));
00974       autoFreeBusyGroup->addRadio(i18n("If requested from an email in addressbook"));
00975       //autoFreeBusyGroup->addRadio(i18n("selected emails"));
00976       topLayout->addMultiCellWidget(autoFreeBusyGroup->groupBox(),3,3,0,0);
00977 
00978       KPrefsWidRadios *autoFreeBusyReplyGroup =
00979           addWidRadios( KOPrefs::instance()->iMIPAutoFreeBusyReplyItem(),
00980                         topFrame );
00981       autoFreeBusyReplyGroup->addRadio(i18n("Never"));
00982       autoFreeBusyReplyGroup->addRadio(i18n("If attendee is in addressbook"));
00983       //autoFreeBusyGroup->addRadio(i18n("selected emails"));
00984       topLayout->addMultiCellWidget(autoFreeBusyReplyGroup->groupBox(),4,4,0,0);
00985 
00986       topLayout->setRowStretch( 5, 1 );
00987 
00988       load();
00989     }
00990 };
00991 
00992 extern "C"
00993 {
00994   KCModule *create_korganizerconfiggroupautomation( QWidget *parent,
00995                                                     const char * )
00996   {
00997     return new KOPrefsDialogGroupAutomation( parent,
00998                                              "kcmkorganizergroupautomation" );
00999   }
01000 }
01001 
01002 // TODO: find replacement for showing printer tab
01003 #if 0
01004 void KOPrefsDialog::showPrinterTab()
01005 {
01006   showPage(pageIndex(mPrinterTab));
01007 }
01008 #endif
01009 
01010 
01011 KOPrefsDialogGroupwareScheduling::KOPrefsDialogGroupwareScheduling( QWidget *parent, const char *name )
01012   : KPrefsModule( KOPrefs::instance(), parent, name )
01013 {
01014   mGroupwarePage = new KOGroupwarePrefsPage( this );
01015   connect( mGroupwarePage, SIGNAL( changed() ), SLOT( slotWidChanged() ) );
01016   ( new QVBoxLayout( this ) )->addWidget( mGroupwarePage );
01017 
01018   load();
01019 }
01020 
01021 void KOPrefsDialogGroupwareScheduling::usrReadConfig()
01022 {
01023   mGroupwarePage->publishEnable->setChecked( KOPrefs::instance()->mFreeBusyPublishAuto );
01024   mGroupwarePage->publishDelay->setValue( KOPrefs::instance()->mFreeBusyPublishDelay );
01025   mGroupwarePage->publishDays->setValue( KOPrefs::instance()->mFreeBusyPublishDays );
01026 
01027   mGroupwarePage->publishUrl->setText( KOPrefs::instance()->mFreeBusyPublishUrl );
01028   mGroupwarePage->publishUser->setText( KOPrefs::instance()->mFreeBusyPublishUser );
01029   mGroupwarePage->publishPassword->setText( KOPrefs::instance()->mFreeBusyPublishPassword );
01030   mGroupwarePage->publishSavePassword->setChecked( KOPrefs::instance()->mFreeBusyPublishSavePassword );
01031 
01032   mGroupwarePage->retrieveEnable->setChecked( KOPrefs::instance()->mFreeBusyRetrieveAuto );
01033   mGroupwarePage->fullDomainRetrieval->setChecked( KOPrefs::instance()->mFreeBusyFullDomainRetrieval );
01034   mGroupwarePage->retrieveUrl->setText( KOPrefs::instance()->mFreeBusyRetrieveUrl );
01035   mGroupwarePage->retrieveUser->setText( KOPrefs::instance()->mFreeBusyRetrieveUser );
01036   mGroupwarePage->retrievePassword->setText( KOPrefs::instance()->mFreeBusyRetrievePassword );
01037   mGroupwarePage->retrieveSavePassword->setChecked( KOPrefs::instance()->mFreeBusyRetrieveSavePassword );
01038 }
01039 
01040 void KOPrefsDialogGroupwareScheduling::usrWriteConfig()
01041 {
01042   KOPrefs::instance()->mFreeBusyPublishAuto = mGroupwarePage->publishEnable->isChecked();
01043   KOPrefs::instance()->mFreeBusyPublishDelay = mGroupwarePage->publishDelay->value();
01044   KOPrefs::instance()->mFreeBusyPublishDays = mGroupwarePage->publishDays->value();
01045 
01046   KOPrefs::instance()->mFreeBusyPublishUrl = mGroupwarePage->publishUrl->text();
01047   KOPrefs::instance()->mFreeBusyPublishUser = mGroupwarePage->publishUser->text();
01048   KOPrefs::instance()->mFreeBusyPublishPassword = mGroupwarePage->publishPassword->text();
01049   KOPrefs::instance()->mFreeBusyPublishSavePassword = mGroupwarePage->publishSavePassword->isChecked();
01050 
01051   KOPrefs::instance()->mFreeBusyRetrieveAuto = mGroupwarePage->retrieveEnable->isChecked();
01052   KOPrefs::instance()->mFreeBusyFullDomainRetrieval = mGroupwarePage->fullDomainRetrieval->isChecked();
01053   KOPrefs::instance()->mFreeBusyRetrieveUrl = mGroupwarePage->retrieveUrl->text();
01054   KOPrefs::instance()->mFreeBusyRetrieveUser = mGroupwarePage->retrieveUser->text();
01055   KOPrefs::instance()->mFreeBusyRetrievePassword = mGroupwarePage->retrievePassword->text();
01056   KOPrefs::instance()->mFreeBusyRetrieveSavePassword = mGroupwarePage->retrieveSavePassword->isChecked();
01057 }
01058 
01059 extern "C"
01060 {
01061   KCModule *create_korganizerconfigfreebusy( QWidget *parent, const char * )
01062   {
01063     return new KOPrefsDialogGroupwareScheduling( parent,
01064                          "kcmkorganizerfreebusy" );
01065   }
01066 }
01067 
01068 
01069 #include "koprefsdialog.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:43:14 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003