summaryrefslogtreecommitdiffstats
path: root/tderesources/carddav/configwidgets.cpp
blob: d0e55a5f5ea156891ba3841333ccdfe2bea05475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*=========================================================================
| KABCDAV
|--------------------------------------------------------------------------
| (c) 2010  Timothy Pearson
|
| This project is released under the GNU General Public License.
| Please see the file COPYING for more details.
|--------------------------------------------------------------------------
| Automatic Reload / Automatic Save configuration widgets.
| The code is mostly taken from resourcecachedconfig.h/cpp files from
| the kcal library and changed to meet our requirements.
| The original copyright is below.
 ========================================================================*/
/*
  This file is part of the kcal library.

  Copyright (c) 2004 Cornelius Schumacher <[email protected]>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.
*/

#include "configwidgets.h"

#include <tdeabcresourcecached.h>

#include <tdelocale.h>
#include <kdebug.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
#include <tqbuttongroup.h>
#include <tqgroupbox.h>
#include <tqhbox.h>

using namespace TDEABC;

//@cond PRIVATE
class CardDavConfigPrivate
{
  public:
    CardDavConfigPrivate()
      : mGroup( 0 ),
        mIntervalSpin( 0 ) {}

    TQButtonGroup *mGroup;
    TQSpinBox *mIntervalSpin;
};

class CardDavReloadConfig::Private
  : public CardDavConfigPrivate
{
};

class CardDavSaveConfig::Private
  : public CardDavConfigPrivate
{
};
//@endcond

CardDavReloadConfig::CardDavReloadConfig( TQWidget *parent )
  : TQWidget( parent ), d( new TDEABC::CardDavReloadConfig::Private() )
{
  TQBoxLayout *topLayout = new TQVBoxLayout( this );

  //TQGroupBox *groupBox = new TQGroupBox( i18nc( "@title:group", "Automatic Reload" ), this );
  TQGroupBox *groupBox = new TQGroupBox( i18n( "Automatic Reload" ), this );
  topLayout->addWidget( groupBox );

  TQRadioButton *noAutomaticReload =
    new TQRadioButton(
      //i18nc( "@option:radio never reload the cache", "Never" ), groupBox );
      i18n( "Never" ), groupBox );
  TQRadioButton *automaticReloadOnStartup =
    new TQRadioButton(
      //i18nc( "@option:radio reload the cache on startup", "Only on startup" ), groupBox );
      i18n( "Only on startup" ), groupBox );
  TQRadioButton *intervalRadio =
    new TQRadioButton(
//       i18nc( "@option:radio reload the cache at regular intervals",
//              "Regular interval" ), groupBox );
      i18n( "Regular interval" ), groupBox );

  d->mGroup = new TQButtonGroup( this );
  d->mGroup->hide();
  d->mGroup->insert( intervalRadio, 2 );
  d->mGroup->insert( automaticReloadOnStartup, 1 );
  d->mGroup->insert( noAutomaticReload, 0 );

  connect( intervalRadio, TQT_SIGNAL( toggled( bool ) ),
           TQT_SLOT( slotIntervalToggled( bool ) ) );

  TQHBox *intervalBox = new TQHBox( groupBox );
  //new TQLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox );
  new TQLabel( i18n( "Interval in minutes:" ), intervalBox );
  d->mIntervalSpin = new TQSpinBox( intervalBox );
  d->mIntervalSpin->setRange( 1, 900 );
  d->mIntervalSpin->setEnabled( false );

  groupBox->setColumnLayout(1, Qt::Vertical);
  TQVBoxLayout *vbox = new TQVBoxLayout(groupBox->layout());
  vbox->addWidget(intervalRadio);
  vbox->addWidget(intervalBox);
  vbox->addWidget(automaticReloadOnStartup);
  vbox->addWidget(noAutomaticReload);
  vbox->addStretch(1);
}

CardDavReloadConfig::~CardDavReloadConfig()
{
   delete d;
}

void CardDavReloadConfig::loadSettings( ResourceCached *resource )
{
  d->mIntervalSpin->setValue( resource->reloadInterval() );
  d->mGroup->setButton( resource->reloadPolicy() );
}

void CardDavReloadConfig::saveSettings( ResourceCached *resource )
{
  resource->setReloadInterval( d->mIntervalSpin->value() );
  resource->setReloadPolicy( d->mGroup->selectedId() );
}

void CardDavReloadConfig::slotIntervalToggled( bool checked )
{
  if ( checked ) {
    d->mIntervalSpin->setEnabled( true );
  } else {
    d->mIntervalSpin->setEnabled( false );
  }
}

CardDavSaveConfig::CardDavSaveConfig( TQWidget *parent )
  : TQWidget( parent ), d( new TDEABC::CardDavSaveConfig::Private() )
{
  TQBoxLayout *topLayout = new TQVBoxLayout( this );

  //TQGroupBox *groupBox = new TQGroupBox( i18nc( "@title:group", "Automatic Save" ), this );
  TQGroupBox *groupBox = new TQGroupBox( i18n( "Automatic Save" ), this );
  d->mGroup = new TQButtonGroup( this );
  d->mGroup->hide();
  topLayout->addWidget( groupBox );

  TQRadioButton *never =
    new TQRadioButton(
      //i18nc( "@option:radio never save the cache automatically", "Never" ), groupBox );
      i18n( "Never" ), groupBox );
  TQRadioButton *onExit =
    new TQRadioButton(
      //i18nc( "@option:radio save the cache on exit", "Only on exit" ), groupBox );
      i18n( "Only on exit" ), groupBox );

  TQRadioButton *intervalRadio =
    new TQRadioButton(
      //i18nc( "@option:radio save the cache at regular intervals", "Regular interval" ), groupBox );
      i18n( "Regular interval" ), groupBox );

  d->mGroup = new TQButtonGroup( this );
  d->mGroup->hide();
  d->mGroup->insert( never, 0 );
  d->mGroup->insert( onExit, 1 );
  d->mGroup->insert( intervalRadio, 2 );

  connect( intervalRadio, TQT_SIGNAL( toggled( bool ) ),
           TQT_SLOT( slotIntervalToggled( bool ) ) );

  TQHBox *intervalBox = new TQHBox( groupBox );
  //new TQLabel( i18nc( "@label:spinbox", "Interval in minutes:" ), intervalBox );
  new TQLabel( i18n( "Interval in minutes:" ), intervalBox );
  d->mIntervalSpin = new TQSpinBox( intervalBox );
  d->mIntervalSpin->setRange( 1, 900 );
  d->mIntervalSpin->setEnabled( false );

  TQRadioButton *delay =
    new TQRadioButton(
//       i18nc( "@option:radio save the cache after some delay",
//              "Delayed after changes" ), groupBox );
      i18n( "Delayed after changes" ), groupBox );
  TQRadioButton *every =
    new TQRadioButton(
//       i18nc( "@option:radio save the cache after every modification",
//              "Immediately after changes" ), groupBox );
      i18n( "Immediately after changes" ), groupBox );
  d->mGroup->insert( delay, 3 );
  d->mGroup->insert( every, 4 );

  // hide unwanted widgets. They may be useful in future, so don't delete them for now.
  intervalRadio->hide();
  intervalBox->hide();

  groupBox->setColumnLayout(1, Qt::Vertical);
  TQVBoxLayout *vbox = new TQVBoxLayout(groupBox->layout());
  vbox->addWidget(delay);
  vbox->addWidget(every);
  vbox->addWidget(intervalRadio);
  vbox->addWidget(intervalBox);
  vbox->addWidget(onExit);
  vbox->addWidget(never);
  vbox->addStretch(1);
}

CardDavSaveConfig::~CardDavSaveConfig()
{
  delete d;
}

void CardDavSaveConfig::loadSettings( ResourceCached *resource )
{
  d->mIntervalSpin->setValue( resource->saveInterval() );
  d->mGroup->setButton( resource->savePolicy() );
}

void CardDavSaveConfig::saveSettings( ResourceCached *resource )
{
  resource->setSaveInterval( d->mIntervalSpin->value() );
  resource->setSavePolicy( d->mGroup->selectedId() );
}

void CardDavSaveConfig::slotIntervalToggled( bool checked )
{
  if ( checked ) {
    d->mIntervalSpin->setEnabled( true );
  } else {
    d->mIntervalSpin->setEnabled( false );
  }
}

#include "configwidgets.moc"

// EOF ========================================================================