1 | /* |
2 | This file is part of the kcal library. |
3 | |
4 | Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | #include "resourcecached.h" |
22 | |
23 | #include <khbox.h> |
24 | #include <klocalizedstring.h> |
25 | #include <kdebug.h> |
26 | #include "resourcecachedconfig.h" |
27 | |
28 | #include <QLayout> |
29 | #include <QRadioButton> |
30 | #include <QSpinBox> |
31 | #include <QLabel> |
32 | #include <QVBoxLayout> |
33 | #include <QBoxLayout> |
34 | #include <QCheckBox> |
35 | #include <QButtonGroup> |
36 | #include <QGroupBox> |
37 | |
38 | |
39 | using namespace KCal; |
40 | |
41 | //@cond PRIVATE |
42 | class ResourceCachedConfigPrivate |
43 | { |
44 | public: |
45 | ResourceCachedConfigPrivate() |
46 | : mGroup( 0 ), |
47 | mIntervalSpin( 0 ) {} |
48 | |
49 | QButtonGroup *mGroup; |
50 | QSpinBox *mIntervalSpin; |
51 | }; |
52 | |
53 | class KCal::ResourceCachedReloadConfig::Private |
54 | : public ResourceCachedConfigPrivate |
55 | { |
56 | }; |
57 | |
58 | class KCal::ResourceCachedSaveConfig::Private |
59 | : public ResourceCachedConfigPrivate |
60 | { |
61 | }; |
62 | //@endcond |
63 | |
64 | ResourceCachedReloadConfig::ResourceCachedReloadConfig( QWidget *parent ) |
65 | : QWidget( parent ), d( new KCal::ResourceCachedReloadConfig::Private() ) |
66 | { |
67 | QBoxLayout *topLayout = new QVBoxLayout( this ); |
68 | |
69 | QGroupBox *groupBox = new QGroupBox( i18nc( "@title:group" , "Automatic Reload" ), this ); |
70 | topLayout->addWidget( groupBox ); |
71 | QRadioButton *noAutomaticReload = |
72 | new QRadioButton( |
73 | i18nc( "@option:radio never reload the cache" , "Never" ), groupBox ); |
74 | QRadioButton *automaticReloadOnStartup = |
75 | new QRadioButton( |
76 | i18nc( "@option:radio reload the cache on startup" , "On startup" ), groupBox ); |
77 | QRadioButton *intervalRadio = |
78 | new QRadioButton( |
79 | i18nc( "@option:radio reload the cache at regular intervals" , |
80 | "Regular interval" ), groupBox ); |
81 | d->mGroup = new QButtonGroup( this ); |
82 | d->mGroup->addButton( noAutomaticReload, 0 ); |
83 | d->mGroup->addButton( automaticReloadOnStartup, 1 ); |
84 | d->mGroup->addButton( intervalRadio, 2 ); |
85 | |
86 | connect( intervalRadio, SIGNAL(toggled(bool)), |
87 | SLOT(slotIntervalToggled(bool)) ); |
88 | |
89 | KHBox *intervalBox = new KHBox; |
90 | new QLabel( i18nc( "@label:spinbox" , "Interval in minutes:" ), intervalBox ); |
91 | d->mIntervalSpin = new QSpinBox( intervalBox ); |
92 | d->mIntervalSpin->setRange( 1, 900 ); |
93 | d->mIntervalSpin->setEnabled( false ); |
94 | |
95 | QVBoxLayout *vbox = new QVBoxLayout; |
96 | vbox->addWidget(noAutomaticReload); |
97 | vbox->addWidget(automaticReloadOnStartup); |
98 | vbox->addWidget(intervalRadio); |
99 | vbox->addWidget(intervalBox); |
100 | vbox->addStretch(1); |
101 | groupBox->setLayout(vbox); |
102 | } |
103 | |
104 | ResourceCachedReloadConfig::~ResourceCachedReloadConfig() |
105 | { |
106 | delete d; |
107 | } |
108 | |
109 | void ResourceCachedReloadConfig::loadSettings( ResourceCached *resource ) |
110 | { |
111 | d->mGroup->button( resource->reloadPolicy() )->setChecked( true ); |
112 | d->mIntervalSpin->setValue( resource->reloadInterval() ); |
113 | } |
114 | |
115 | void ResourceCachedReloadConfig::saveSettings( ResourceCached *resource ) |
116 | { |
117 | resource->setReloadPolicy( d->mGroup->checkedId() ); |
118 | resource->setReloadInterval( d->mIntervalSpin->value() ); |
119 | } |
120 | |
121 | void ResourceCachedReloadConfig::slotIntervalToggled( bool checked ) |
122 | { |
123 | if ( checked ) { |
124 | d->mIntervalSpin->setEnabled( true ); |
125 | } else { |
126 | d->mIntervalSpin->setEnabled( false ); |
127 | } |
128 | } |
129 | |
130 | ResourceCachedSaveConfig::ResourceCachedSaveConfig( QWidget *parent ) |
131 | : QWidget( parent ), d( new KCal::ResourceCachedSaveConfig::Private() ) |
132 | { |
133 | QBoxLayout *topLayout = new QVBoxLayout( this ); |
134 | |
135 | QGroupBox *groupBox = new QGroupBox( i18nc( "@title:group" , "Automatic Save" ), this ); |
136 | d->mGroup = new QButtonGroup( this ); |
137 | topLayout->addWidget( groupBox ); |
138 | QRadioButton *never = |
139 | new QRadioButton( |
140 | i18nc( "@option:radio never save the cache automatically" , "Never" ), groupBox ); |
141 | QRadioButton *onExit = |
142 | new QRadioButton( |
143 | i18nc( "@option:radio save the cache on exit" , "On exit" ), groupBox ); |
144 | |
145 | QRadioButton *intervalRadio = |
146 | new QRadioButton( |
147 | i18nc( "@option:radio save the cache at regular intervals" , "Regular interval" ), groupBox ); |
148 | |
149 | d->mGroup = new QButtonGroup( this ); |
150 | d->mGroup->addButton( never, 0 ); |
151 | d->mGroup->addButton( onExit, 1 ); |
152 | d->mGroup->addButton( intervalRadio, 2 ); |
153 | |
154 | connect( intervalRadio, SIGNAL(toggled(bool)), |
155 | SLOT(slotIntervalToggled(bool)) ); |
156 | |
157 | KHBox *intervalBox = new KHBox; |
158 | new QLabel( i18nc( "@label:spinbox" , "Interval in minutes:" ), intervalBox ); |
159 | d->mIntervalSpin = new QSpinBox( intervalBox ); |
160 | d->mIntervalSpin->setRange( 1, 900 ); |
161 | d->mIntervalSpin->setEnabled( false ); |
162 | |
163 | QRadioButton *delay = |
164 | new QRadioButton( |
165 | i18nc( "@option:radio save the cache after some delay" , |
166 | "Delayed after changes" ), groupBox ); |
167 | QRadioButton *every = |
168 | new QRadioButton( |
169 | i18nc( "@option:radio save the cache after every modification" , |
170 | "On every change" ), groupBox ); |
171 | d->mGroup->addButton( delay, 3 ); |
172 | d->mGroup->addButton( every, 4 ); |
173 | |
174 | QVBoxLayout *vbox = new QVBoxLayout; |
175 | vbox->addWidget(never); |
176 | vbox->addWidget(onExit); |
177 | vbox->addWidget(intervalRadio); |
178 | vbox->addWidget(intervalBox); |
179 | vbox->addWidget(delay); |
180 | vbox->addWidget(every); |
181 | vbox->addStretch(1); |
182 | groupBox->setLayout(vbox); |
183 | |
184 | } |
185 | |
186 | ResourceCachedSaveConfig::~ResourceCachedSaveConfig() |
187 | { |
188 | delete d; |
189 | } |
190 | |
191 | void ResourceCachedSaveConfig::loadSettings( ResourceCached *resource ) |
192 | { |
193 | d->mGroup->button( resource->savePolicy() )->setChecked( true ); |
194 | d->mIntervalSpin->setValue( resource->saveInterval() ); |
195 | } |
196 | |
197 | void ResourceCachedSaveConfig::saveSettings( ResourceCached *resource ) |
198 | { |
199 | resource->setSavePolicy( d->mGroup->checkedId() ); |
200 | resource->setSaveInterval( d->mIntervalSpin->value() ); |
201 | } |
202 | |
203 | void ResourceCachedSaveConfig::slotIntervalToggled( bool checked ) |
204 | { |
205 | if ( checked ) { |
206 | d->mIntervalSpin->setEnabled( true ); |
207 | } else { |
208 | d->mIntervalSpin->setEnabled( false ); |
209 | } |
210 | } |
211 | |