KCal Library
resourcecachedconfig.cpp
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library 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 GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #include "resourcecached.h" 00022 00023 #include <khbox.h> 00024 #include <klocale.h> 00025 #include <kdebug.h> 00026 00027 #include <QtGui/QLayout> 00028 #include <QtGui/QRadioButton> 00029 #include <QtGui/QSpinBox> 00030 #include <QtGui/QLabel> 00031 #include <QtGui/QVBoxLayout> 00032 #include <QtGui/QBoxLayout> 00033 #include <QtGui/QCheckBox> 00034 #include <QtGui/QButtonGroup> 00035 #include <QtGui/QGroupBox> 00036 00037 #include "resourcecachedconfig.moc" 00038 00039 using namespace KCal; 00040 00041 //@cond PRIVATE 00042 class ResourceCachedConfigPrivate 00043 { 00044 public: 00045 ResourceCachedConfigPrivate() 00046 : mGroup( 0 ), 00047 mIntervalSpin( 0 ) {} 00048 00049 QButtonGroup *mGroup; 00050 QSpinBox *mIntervalSpin; 00051 }; 00052 00053 class KCal::ResourceCachedReloadConfig::Private 00054 : public ResourceCachedConfigPrivate 00055 { 00056 }; 00057 00058 class KCal::ResourceCachedSaveConfig::Private 00059 : public ResourceCachedConfigPrivate 00060 { 00061 }; 00062 //@endcond 00063 00064 ResourceCachedReloadConfig::ResourceCachedReloadConfig( QWidget *parent ) 00065 : QWidget( parent ), d( new KCal::ResourceCachedReloadConfig::Private() ) 00066 { 00067 QBoxLayout *topLayout = new QVBoxLayout( this ); 00068 00069 QGroupBox *groupBox = new QGroupBox( i18nc( "@title:group", "Automatic Reload" ), this ); 00070 topLayout->addWidget( groupBox ); 00071 QRadioButton *noAutomaticReload = 00072 new QRadioButton( 00073 i18nc( "@option:radio never reload the cache", "Never" ), groupBox ); 00074 QRadioButton *automaticReloadOnStartup = 00075 new QRadioButton( 00076 i18nc( "@option:radio reload the cache on startup", "On startup" ), groupBox ); 00077 QRadioButton *intervalRadio = 00078 new QRadioButton( 00079 i18nc( "@option:radio reload the cache at regular intervals", 00080 "Regular interval" ), groupBox ); 00081 d->mGroup = new QButtonGroup( this ); 00082 d->mGroup->addButton( noAutomaticReload, 0 ); 00083 d->mGroup->addButton( automaticReloadOnStartup, 1 ); 00084 d->mGroup->addButton( intervalRadio, 2 ); 00085 00086 connect( intervalRadio, SIGNAL( toggled( bool ) ), 00087 SLOT( slotIntervalToggled( bool ) ) ); 00088 00089 KHBox *intervalBox = new KHBox; 00090 new QLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox ); 00091 d->mIntervalSpin = new QSpinBox( intervalBox ); 00092 d->mIntervalSpin->setRange( 1, 900 ); 00093 d->mIntervalSpin->setEnabled( false ); 00094 00095 QVBoxLayout *vbox = new QVBoxLayout; 00096 vbox->addWidget(noAutomaticReload); 00097 vbox->addWidget(automaticReloadOnStartup); 00098 vbox->addWidget(intervalRadio); 00099 vbox->addWidget(intervalBox); 00100 vbox->addStretch(1); 00101 groupBox->setLayout(vbox); 00102 } 00103 00104 ResourceCachedReloadConfig::~ResourceCachedReloadConfig() 00105 { 00106 delete d; 00107 } 00108 00109 void ResourceCachedReloadConfig::loadSettings( ResourceCached *resource ) 00110 { 00111 d->mGroup->button( resource->reloadPolicy() )->setChecked( true ); 00112 d->mIntervalSpin->setValue( resource->reloadInterval() ); 00113 } 00114 00115 void ResourceCachedReloadConfig::saveSettings( ResourceCached *resource ) 00116 { 00117 resource->setReloadPolicy( d->mGroup->checkedId() ); 00118 resource->setReloadInterval( d->mIntervalSpin->value() ); 00119 } 00120 00121 void ResourceCachedReloadConfig::slotIntervalToggled( bool checked ) 00122 { 00123 if ( checked ) { 00124 d->mIntervalSpin->setEnabled( true ); 00125 } else { 00126 d->mIntervalSpin->setEnabled( false ); 00127 } 00128 } 00129 00130 ResourceCachedSaveConfig::ResourceCachedSaveConfig( QWidget *parent ) 00131 : QWidget( parent ), d( new KCal::ResourceCachedSaveConfig::Private() ) 00132 { 00133 QBoxLayout *topLayout = new QVBoxLayout( this ); 00134 00135 QGroupBox *groupBox = new QGroupBox( i18nc( "@title:group", "Automatic Save" ), this ); 00136 d->mGroup = new QButtonGroup( this ); 00137 topLayout->addWidget( groupBox ); 00138 QRadioButton *never = 00139 new QRadioButton( 00140 i18nc( "@option:radio never save the cache automatically", "Never" ), groupBox ); 00141 QRadioButton *onExit = 00142 new QRadioButton( 00143 i18nc( "@option:radio save the cache on exit", "On exit" ), groupBox ); 00144 00145 QRadioButton *intervalRadio = 00146 new QRadioButton( 00147 i18nc( "@option:radio save the cache at regular intervals", "Regular interval" ), groupBox ); 00148 00149 d->mGroup = new QButtonGroup( this ); 00150 d->mGroup->addButton( never, 0 ); 00151 d->mGroup->addButton( onExit, 1 ); 00152 d->mGroup->addButton( intervalRadio, 2 ); 00153 00154 connect( intervalRadio, SIGNAL( toggled( bool ) ), 00155 SLOT( slotIntervalToggled( bool ) ) ); 00156 00157 KHBox *intervalBox = new KHBox; 00158 new QLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox ); 00159 d->mIntervalSpin = new QSpinBox( intervalBox ); 00160 d->mIntervalSpin->setRange( 1, 900 ); 00161 d->mIntervalSpin->setEnabled( false ); 00162 00163 QRadioButton *delay = 00164 new QRadioButton( 00165 i18nc( "@option:radio save the cache after some delay", 00166 "Delayed after changes" ), groupBox ); 00167 QRadioButton *every = 00168 new QRadioButton( 00169 i18nc( "@option:radio save the cache after every modification", 00170 "On every change" ), groupBox ); 00171 d->mGroup->addButton( delay, 3 ); 00172 d->mGroup->addButton( every, 4 ); 00173 00174 QVBoxLayout *vbox = new QVBoxLayout; 00175 vbox->addWidget(never); 00176 vbox->addWidget(onExit); 00177 vbox->addWidget(intervalRadio); 00178 vbox->addWidget(intervalBox); 00179 vbox->addWidget(delay); 00180 vbox->addWidget(every); 00181 vbox->addStretch(1); 00182 groupBox->setLayout(vbox); 00183 00184 } 00185 00186 ResourceCachedSaveConfig::~ResourceCachedSaveConfig() 00187 { 00188 delete d; 00189 } 00190 00191 void ResourceCachedSaveConfig::loadSettings( ResourceCached *resource ) 00192 { 00193 d->mGroup->button( resource->savePolicy() )->setChecked( true ); 00194 d->mIntervalSpin->setValue( resource->saveInterval() ); 00195 } 00196 00197 void ResourceCachedSaveConfig::saveSettings( ResourceCached *resource ) 00198 { 00199 resource->setSavePolicy( d->mGroup->checkedId() ); 00200 resource->setSaveInterval( d->mIntervalSpin->value() ); 00201 } 00202 00203 void ResourceCachedSaveConfig::slotIntervalToggled( bool checked ) 00204 { 00205 if ( checked ) { 00206 d->mIntervalSpin->setEnabled( true ); 00207 } else { 00208 d->mIntervalSpin->setEnabled( false ); 00209 } 00210 }