kontact

kcmkorgsummary.cpp

00001 /*
00002     This file is part of Kontact.
00003     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qbuttongroup.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qradiobutton.h>
00028 #include <qspinbox.h>
00029 
00030 #include <kaboutdata.h>
00031 #include <kapplication.h>
00032 #include <kaccelmanager.h>
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035 #include <kdialogbase.h>
00036 #include <klocale.h>
00037 
00038 #include "kcmkorgsummary.h"
00039 
00040 #include <kdepimmacros.h>
00041 
00042 extern "C"
00043 {
00044   KDE_EXPORT KCModule *create_korgsummary( QWidget *parent, const char * )
00045   {
00046     return new KCMKOrgSummary( parent, "kcmkorgsummary" );
00047   }
00048 }
00049 
00050 KCMKOrgSummary::KCMKOrgSummary( QWidget *parent, const char *name )
00051   : KCModule( parent, name )
00052 {
00053   initGUI();
00054 
00055   customDaysChanged( 1 );
00056 
00057   connect( mCalendarGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00058   connect( mCalendarGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
00059   connect( mTodoGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00060   connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( modified() ) );
00061   connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( customDaysChanged( int ) ) );
00062 
00063   KAcceleratorManager::manage( this );
00064 
00065   load();
00066 
00067   KAboutData *about = new KAboutData( I18N_NOOP( "kcmkorgsummary" ),
00068                                       I18N_NOOP( "Schedule Configuration Dialog" ),
00069                                       0, 0, KAboutData::License_GPL,
00070                                       I18N_NOOP( "(c) 2003 - 2004 Tobias Koenig" ) );
00071 
00072   about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00073   setAboutData( about );
00074 }
00075 
00076 void KCMKOrgSummary::modified()
00077 {
00078   emit changed( true );
00079 }
00080 
00081 void KCMKOrgSummary::buttonClicked( int id )
00082 {
00083   mCustomDays->setEnabled( id == 4 );
00084 }
00085 
00086 void KCMKOrgSummary::customDaysChanged( int value )
00087 {
00088   mCustomDays->setSuffix( i18n( " day",  " days", value ) );
00089 }
00090 
00091 void KCMKOrgSummary::initGUI()
00092 {
00093   QVBoxLayout *layout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00094 
00095   mCalendarGroup = new QButtonGroup( 0, Vertical, i18n( "Appointments" ), this );
00096   QVBoxLayout *boxLayout = new QVBoxLayout( mCalendarGroup->layout(),
00097                                             KDialog::spacingHint() );
00098 
00099   QLabel *label = new QLabel( i18n( "How many days should the calendar show at once?" ), mCalendarGroup );
00100   boxLayout->addWidget( label );
00101 
00102   QRadioButton *button = new QRadioButton( i18n( "One day" ), mCalendarGroup );
00103   boxLayout->addWidget( button );
00104 
00105   button = new QRadioButton( i18n( "Five days" ), mCalendarGroup );
00106   boxLayout->addWidget( button );
00107 
00108   button = new QRadioButton( i18n( "One week" ), mCalendarGroup );
00109   boxLayout->addWidget( button );
00110 
00111   button = new QRadioButton( i18n( "One month" ), mCalendarGroup );
00112   boxLayout->addWidget( button );
00113 
00114   QHBoxLayout *hbox = new QHBoxLayout( boxLayout, KDialog::spacingHint() );
00115 
00116   button = new QRadioButton( "", mCalendarGroup );
00117   hbox->addWidget( button );
00118 
00119   mCustomDays = new QSpinBox( 1, 365, 1, mCalendarGroup );
00120   mCustomDays->setEnabled( false );
00121   hbox->addWidget( mCustomDays );
00122 
00123   hbox->addStretch( 1 );
00124 
00125   layout->addWidget( mCalendarGroup );
00126 
00127   mTodoGroup = new QButtonGroup( 2, Horizontal, i18n( "To-dos" ), this );
00128   new QRadioButton( i18n( "Show all to-dos" ), mTodoGroup );
00129   new QRadioButton( i18n( "Show today's to-dos only" ), mTodoGroup );
00130 
00131   layout->addWidget( mTodoGroup );
00132 
00133   layout->addStretch();
00134 }
00135 
00136 void KCMKOrgSummary::load()
00137 {
00138   KConfig config( "kcmkorgsummaryrc" );
00139 
00140   config.setGroup( "Calendar" );
00141   int days = config.readNumEntry( "DaysToShow", 1 );
00142   if ( days == 1 )
00143     mCalendarGroup->setButton( 0 );
00144   else if ( days == 5 )
00145     mCalendarGroup->setButton( 1 );
00146   else if ( days == 7 )
00147     mCalendarGroup->setButton( 2 );
00148   else if ( days == 31 )
00149     mCalendarGroup->setButton( 3 );
00150   else {
00151     mCalendarGroup->setButton( 4 );
00152     mCustomDays->setValue( days );
00153     mCustomDays->setEnabled( true );
00154   }
00155 
00156   config.setGroup( "Todo" );
00157   bool allTodos = config.readBoolEntry( "ShowAllTodos", false );
00158 
00159   if ( allTodos )
00160     mTodoGroup->setButton( 0 );
00161   else
00162     mTodoGroup->setButton( 1 );
00163 
00164   emit changed( false );
00165 }
00166 
00167 void KCMKOrgSummary::save()
00168 {
00169   KConfig config( "kcmkorgsummaryrc" );
00170 
00171   config.setGroup( "Calendar" );
00172 
00173   int days;
00174   switch ( mCalendarGroup->selectedId() ) {
00175     case 0: days = 1; break;
00176     case 1: days = 5; break;
00177     case 2: days = 7; break;
00178     case 3: days = 31; break;
00179     case 4:
00180     default: days = mCustomDays->value(); break;
00181   }
00182   config.writeEntry( "DaysToShow", days );
00183 
00184   config.setGroup( "Todo" );
00185   config.writeEntry( "ShowAllTodos", mTodoGroup->selectedId() == 0 );
00186 
00187   config.sync();
00188 
00189   emit changed( false );
00190 }
00191 
00192 void KCMKOrgSummary::defaults()
00193 {
00194   mCalendarGroup->setButton( 0 );
00195   mTodoGroup->setButton( 1 );
00196 
00197   emit changed( true );
00198 }
00199 
00200 #include "kcmkorgsummary.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys