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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/*
This file is part of KitchenSync.
Copyright (c) 2007 Tobias Koenig <[email protected]>
Copyright (c) 2007 Anirudh Ramesh <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
*/
#include "configguisunbird.h"
#include <tqdom.h>
#include <tqtabwidget.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqsizepolicy.h>
#include <tqptrlist.h>
#include <tqspinbox.h>
#include <tqwidget.h>
#include <kurlrequester.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kdialog.h>
#include <tdelocale.h>
#include <tdefile.h>
ConfigGuiSunbird::ConfigGuiSunbird( const QSync::Member &member, TQWidget *parent )
: ConfigGui( member, parent )
{
TQTabWidget *tabWidget = new TQTabWidget( this );
topLayout()->addWidget( tabWidget );
mLocalWidget = new TQWidget( tabWidget );
mLocalLayout = new TQVBoxLayout( mLocalWidget, KDialog::spacingHint() );
mWebdavWidget = new TQWidget( tabWidget );
mWebdavLayout = new TQVBoxLayout( mWebdavWidget, KDialog::spacingHint() );
tabWidget->addTab( mLocalWidget, i18n( "Local Calendars" ) );
tabWidget->addTab( mWebdavWidget, i18n( "WebDAV Calendars" ) );
KPushButton *mLocalAddButton = new KPushButton( mLocalWidget );
mLocalAddButton->setText( i18n( "Add new calendar" ) );
mLocalAddButton->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
mLocalLayout->addWidget( mLocalAddButton );
connect( mLocalAddButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( addLocalCalendar() ) );
KPushButton *mWebdavAddButton = new KPushButton( mWebdavWidget );
mWebdavAddButton->setText( i18n( "Add new calendar" ) );
mWebdavAddButton->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
mWebdavLayout->addWidget( mWebdavAddButton );
connect( mWebdavAddButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( addWebdavCalendar() ) );
mLocalSpacer = new TQSpacerItem( 20, 40, TQSizePolicy::Expanding );
mLocalLayout->addItem( mLocalSpacer );
mWebdavSpacer = new TQSpacerItem( 20, 40, TQSizePolicy::Expanding );
mWebdavLayout->addItem( mWebdavSpacer );
}
void ConfigGuiSunbird::load( const TQString &xml )
{
TQString path;
TQString url;
TQString username;
TQString password;
TQString defaultcal;
TQString days;
TQDomDocument doc;
doc.setContent( xml );
TQDomElement docElement = doc.documentElement();
TQDomNode node;
for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
TQDomElement element = node.toElement();
if ( element.tagName() == "file" ) {
TQDomAttr pathAttr = element.attributeNode( "path" );
path = pathAttr.value();
TQDomAttr defaultAttr = element.attributeNode( "default" );
defaultcal = defaultAttr.value();
TQDomAttr daysAttr = element.attributeNode( "deletedaysold" );
days = daysAttr.value();
LocalCalendar *cal = new LocalCalendar( path, defaultcal, days, mLocalWidget );
mLocalLayout->removeItem( mLocalSpacer );
cal->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
mLocalLayout->addWidget( cal );
mLocalLayout->addItem( mLocalSpacer );
mLocalList.append( cal );
connect( cal, TQT_SIGNAL( deleteRequest( LocalCalendar* ) ), TQT_SLOT( delLocalCalendar( LocalCalendar* ) ) );
cal->show();
} else if ( element.tagName() == "webdav" ) {
TQDomAttr urlAttr = element.attributeNode( "url" );
url = urlAttr.value();
TQDomAttr unameAttr = element.attributeNode( "username" );
username = unameAttr.value();
TQDomAttr pwordAttr = element.attributeNode( "password" );
password = pwordAttr.value();
TQDomAttr defaultAttr = element.attributeNode( "default" );
defaultcal = defaultAttr.value();
TQDomAttr daysAttr = element.attributeNode( "deletedaysold" );
days = daysAttr.value();
WebdavCalendar *cal = new WebdavCalendar( username, password,
url, defaultcal, days, mWebdavWidget );
mWebdavLayout->removeItem( mWebdavSpacer );
cal->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
mWebdavLayout->addWidget( cal );
mWebdavLayout->addItem( mWebdavSpacer );
mWebdavList.append( cal );
connect( cal, TQT_SIGNAL( deleteRequest( WebdavCalendar* ) ), TQT_SLOT( delWebdavCalendar( WebdavCalendar* ) ) );
cal->show();
}
}
}
TQString ConfigGuiSunbird::save() const
{
TQString config = "<config>\n";
for ( uint i = 0; i < mLocalList.count(); ++i ) {
LocalCalendar *lcal = mLocalList[ i ];
config += TQString( "<file " );
config += TQString( "path=\"%1\" " ).arg( lcal->mPathRequester->url() );
if ( lcal->mDaysCheckBox->isChecked() ) {
config += TQString( "deletedaysold=\"%1\" " ).arg( lcal->mDaysSpinBox->value() );
}
if ( lcal->mDefaultCheckBox->isChecked() ) {
config += TQString( "default=\"1\" " );
}
config += TQString( "/>\n" );
}
for ( uint i = 0; i < mWebdavList.count(); ++i ) {
WebdavCalendar *wcal = mWebdavList[ i ];
config += TQString( "<webdav " );
config += TQString( "username=\"%1\" " ).arg( wcal->mUsername->text() );
config += TQString( "password=\"%1\" " ).arg( wcal->mPassword->text() );
config += TQString( "url=\"%1\" " ).arg( wcal->mUrl->text() );
if ( wcal->mDaysCheckBox->isChecked() ) {
config += TQString( "deletedaysold=\"%1\" " ).arg( wcal->mDaysSpinBox->value() );
}
if ( wcal->mDefaultCheckBox->isChecked() ) {
config += TQString( "default=\"1\" " );
}
config += TQString( "/>\n" );
}
config += "</config>";
return config;
}
void ConfigGuiSunbird::addLocalCalendar()
{
LocalCalendar *cal = new LocalCalendar( mLocalWidget );
mLocalLayout->removeItem( mLocalSpacer );
cal->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
mLocalLayout->addWidget( cal );
mLocalLayout->addItem( mLocalSpacer );
mLocalList.append( cal );
connect( cal, TQT_SIGNAL( deleteRequest( LocalCalendar* ) ), TQT_SLOT( delLocalCalendar( LocalCalendar* ) ) );
cal->show();
}
void ConfigGuiSunbird::delLocalCalendar( LocalCalendar *calendar )
{
mLocalList.remove( calendar );
calendar->deleteLater();
}
void ConfigGuiSunbird::addWebdavCalendar()
{
WebdavCalendar *cal = new WebdavCalendar( mWebdavWidget );
mWebdavLayout->removeItem( mWebdavSpacer );
cal->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
mWebdavLayout->addWidget( cal );
mWebdavLayout->addItem( mWebdavSpacer );
mWebdavList.append( cal );
connect( cal, TQT_SIGNAL( deleteRequest( WebdavCalendar* ) ), TQT_SLOT( delWebdavCalendar( WebdavCalendar* ) ) );
cal->show();
}
void ConfigGuiSunbird::delWebdavCalendar( WebdavCalendar *calendar )
{
mWebdavList.remove( calendar );
calendar->deleteLater();
}
LocalCalendar::LocalCalendar( TQWidget *parent )
: TQWidget( parent )
{
initGui();
}
LocalCalendar::LocalCalendar( const TQString &path, const TQString &defaultcal, const TQString &days, TQWidget *parent )
: TQWidget( parent )
{
initGui();
mPathRequester->setURL( path );
mDefaultCheckBox->setChecked( defaultcal.toInt() == 1 );
if ( !days.isEmpty() ) {
mDaysCheckBox->setChecked( true );
mDaysSpinBox->setEnabled( true );
mDaysSpinBox->setValue( days.toInt() );
}
}
void LocalCalendar::initGui()
{
TQBoxLayout *bottomLayout = new TQHBoxLayout();
mDaysCheckBox = new TQCheckBox( this );
mDaysCheckBox->setText( i18n( "Sync only events newer than" ) );
mDaysSpinBox = new TQSpinBox( this );
mDaysSpinBox->setDisabled( true );
mDaysSpinBox->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
connect( mDaysCheckBox, TQT_SIGNAL( toggled( bool ) ),
this, TQT_SLOT( toggleDays( bool ) ) );
bottomLayout->addWidget( mDaysCheckBox );
bottomLayout->addWidget( mDaysSpinBox );
bottomLayout->addWidget( new TQLabel( i18n( "day(s)" ), this ) );
TQGridLayout *localLayout = new TQGridLayout( this );
mPathRequester = new KURLRequester( this );
KPushButton *removeButton = new KPushButton( this );
removeButton->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
removeButton->setText( i18n( "Remove" ) );
connect( removeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( deleteWidget() ) );
mDefaultCheckBox = new TQCheckBox( this );
mDefaultCheckBox->setText( i18n( "Set as Default" ) );
localLayout->addItem( new TQSpacerItem( 40, 20, TQSizePolicy::Expanding ), 0, 0 );
localLayout->addWidget( new TQLabel( i18n( "Location:" ), this ), 1, 0 );
localLayout->addWidget( mPathRequester, 1, 1 );
localLayout->addItem( new TQSpacerItem( 40, 20, TQSizePolicy::Fixed ), 1, 2 );
localLayout->addWidget( removeButton, 1, 3 );
localLayout->addMultiCellLayout( bottomLayout, 2, 2, 0, 2 );
localLayout->addWidget( mDefaultCheckBox, 2, 3 );
}
void LocalCalendar::deleteWidget()
{
emit deleteRequest( this );
}
WebdavCalendar::WebdavCalendar( TQWidget *parent )
: TQWidget( parent )
{
initGui();
};
WebdavCalendar::WebdavCalendar( const TQString &username, const TQString &password, const TQString &url,
const TQString &defaultcal, const TQString &days, TQWidget *parent )
: TQWidget( parent )
{
initGui();
mUsername->setText( username );
mPassword->setText( password );
mUrl->setText( url );
mDefaultCheckBox->setChecked( defaultcal.toInt() == 1 );
if ( !days.isEmpty() ) {
mDaysCheckBox->setChecked( true );
mDaysSpinBox->setEnabled( true );
mDaysSpinBox->setValue( days.toInt() );
}
}
void WebdavCalendar::initGui()
{
TQBoxLayout *bottomLayout = new TQHBoxLayout();
mDaysCheckBox = new TQCheckBox( this );
mDaysCheckBox->setText( i18n( "Sync only events newer than" ) );
mDaysSpinBox = new TQSpinBox( this );
mDaysSpinBox->setDisabled( true );
mDaysSpinBox->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
connect( mDaysCheckBox, TQT_SIGNAL( toggled( bool ) ),
this, TQT_SLOT( toggleDays( bool ) ) );
bottomLayout->addWidget( mDaysCheckBox );
bottomLayout->addWidget( mDaysSpinBox );
bottomLayout->addWidget( new TQLabel( i18n( "day(s)" ), this ) );
TQGridLayout *webdavLayout = new TQGridLayout();
mUrl = new KLineEdit( this );
mUsername = new KLineEdit( this );
mPassword = new KLineEdit( this );
mPassword->setEchoMode( KLineEdit::Password );
KPushButton *removeButton = new KPushButton( this );
removeButton->setText( i18n( "Remove" ) );
connect( removeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( deleteWidget() ) );
mDefaultCheckBox = new TQCheckBox( this );
mDefaultCheckBox->setText( i18n( "Set as Default" ) );
webdavLayout->addWidget( new TQLabel( i18n( "Location:" ), this ), 0, 0 );
webdavLayout->addWidget( mUrl, 0, 1 );
webdavLayout->addItem( new TQSpacerItem( 40, 20, TQSizePolicy::Fixed ), 0, 2 );
webdavLayout->addWidget( removeButton, 0, 3 );
webdavLayout->addMultiCellLayout( bottomLayout, 1, 1, 0, 1 );
webdavLayout->addWidget( mDefaultCheckBox, 1, 3 );
TQGridLayout *mainLayout = new TQGridLayout( this );
mainLayout->addItem( new TQSpacerItem( 40, 20, TQSizePolicy::Fixed ), 0, 0 );
mainLayout->addMultiCellLayout( webdavLayout, 1, 1, 0, 4 );
mainLayout->addWidget( new TQLabel( i18n( "Username:" ), this ), 2, 0 );
mainLayout->addWidget( mUsername, 2, 1 );
mainLayout->addItem( new TQSpacerItem( 40, 20, TQSizePolicy::Fixed ), 2, 2 );
mainLayout->addWidget( new TQLabel( i18n( "Password:" ), this ), 2, 3 );
mainLayout->addWidget( mPassword, 2, 4 );
}
void WebdavCalendar::deleteWidget()
{
emit deleteRequest( this );
}
void LocalCalendar::toggleDays( bool state )
{
mDaysSpinBox->setEnabled( state );
}
void WebdavCalendar::toggleDays( bool state )
{
mDaysSpinBox->setEnabled( state );
}
#include "configguisunbird.moc"
|