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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
/*
This file is part of tdepim.
Copyright (c) 2004 Cornelius Schumacher <[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 "groupwisewizard.h"
#include "groupwiseconfig.h"
#include "kmailchanges.h"
#include "tderesources/groupwise/tdeabc_groupwiseprefs.h"
#include "tderesources/groupwise/tdeabc_resourcegroupwise.h"
#include "tderesources/groupwise/kcal_groupwiseprefsbase.h"
#include "tderesources/groupwise/kcal_resourcegroupwise.h"
#include <libkcal/resourcecalendar.h>
#include <libemailfunctions/email.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqspinbox.h>
#include <tqgroupbox.h>
TQString serverUrl()
{
TQString url;
if ( GroupwiseConfig::self()->useHttps() ) url = "https";
else url = "http";
url += "://" + GroupwiseConfig::self()->host() + ":" +
TQString::number( GroupwiseConfig::self()->port() ) + GroupwiseConfig::self()->path();
return url;
}
class CreateGroupwiseKcalResource : public TDEConfigPropagator::Change
{
public:
CreateGroupwiseKcalResource()
: TDEConfigPropagator::Change( i18n("Create GroupWise Calendar Resource") )
{
}
void apply()
{
KCal::CalendarResourceManager m( "calendar" );
m.readConfig();
KCal::ResourceGroupwise *r = new KCal::ResourceGroupwise();
r->setResourceName( i18n("GroupWise") );
r->prefs()->setUrl( serverUrl() );
r->prefs()->setUser( GroupwiseConfig::self()->user() );
r->prefs()->setPassword( GroupwiseConfig::self()->password() );
r->setSavePolicy( KCal::ResourceCached::SaveDelayed );
r->setReloadPolicy( KCal::ResourceCached::ReloadInterval );
r->setReloadInterval( 20 );
m.add( r );
m.writeConfig();
GroupwiseConfig::self()->setKcalResource( r->identifier() );
}
};
class UpdateGroupwiseKcalResource : public TDEConfigPropagator::Change
{
public:
UpdateGroupwiseKcalResource()
: TDEConfigPropagator::Change( i18n("Update GroupWise Calendar Resource") )
{
}
void apply()
{
KCal::CalendarResourceManager m( "calendar" );
m.readConfig();
KCal::CalendarResourceManager::Iterator it;
for ( it = m.begin(); it != m.end(); ++it ) {
if ( (*it)->identifier() == GroupwiseConfig::kcalResource() ) {
KCal::ResourceGroupwise *r = static_cast<KCal::ResourceGroupwise *>( *it );
r->prefs()->setUrl( serverUrl() );
r->prefs()->setUser( GroupwiseConfig::self()->user() );
r->prefs()->setPassword( GroupwiseConfig::self()->password() );
r->setSavePolicy( KCal::ResourceCached::SaveDelayed );
r->setReloadPolicy( KCal::ResourceCached::ReloadInterval );
r->setReloadInterval( 20 );
}
}
m.writeConfig();
}
};
class CreateGroupwiseTdeabcResource : public TDEConfigPropagator::Change
{
public:
CreateGroupwiseTdeabcResource()
: TDEConfigPropagator::Change( i18n("Create GroupWise Addressbook Resource") )
{
}
void apply()
{
KRES::Manager<TDEABC::Resource> m( "contact" );
m.readConfig();
TQString url = serverUrl();
TQString user( GroupwiseConfig::self()->user() );
TQString password( GroupwiseConfig::self()->password() );
TDEABC::ResourceGroupwise *r = new TDEABC::ResourceGroupwise( url, user,
password,
TQStringList(),
TQString() );
r->setResourceName( i18n("GroupWise") );
m.add( r );
m.writeConfig();
GroupwiseConfig::self()->setTdeabcResource( r->identifier() );
}
};
class UpdateGroupwiseTdeabcResource : public TDEConfigPropagator::Change
{
public:
UpdateGroupwiseTdeabcResource()
: TDEConfigPropagator::Change( i18n("Update GroupWise Addressbook Resource") )
{
}
void apply()
{
KRES::Manager<TDEABC::Resource> m( "contact" );
m.readConfig();
KRES::Manager<TDEABC::Resource>::Iterator it;
for ( it = m.begin(); it != m.end(); ++it ) {
if ( (*it)->identifier() == GroupwiseConfig::tdeabcResource() ) {
TDEABC::ResourceGroupwise *r = static_cast<TDEABC::ResourceGroupwise *>( *it );
r->prefs()->setUrl( serverUrl() );
r->prefs()->setUser( GroupwiseConfig::self()->user() );
r->prefs()->setPassword( GroupwiseConfig::self()->password() );
}
}
m.writeConfig();
}
};
class GroupwisePropagator : public TDEConfigPropagator
{
public:
GroupwisePropagator()
: TDEConfigPropagator( GroupwiseConfig::self(), "groupwise.kcfg" )
{
}
~GroupwisePropagator()
{
GroupwiseConfig::self()->writeConfig();
}
protected:
class Writer : public CreateDisconnectedImapAccount::CustomWriter
{
public:
void writeFolder( TDEConfig &, int ) {}
void writeIds( int accountId, int transportId )
{
GroupwiseConfig::setKMailAccountId( accountId );
GroupwiseConfig::setKMailTransportId( transportId );
}
};
void addCustomChanges( Change::List &changes )
{
ChangeConfig *c = new ChangeConfig;
c->file = "korganizerrc";
c->group = "FreeBusy";
c->name = "FreeBusyRetrieveUrl";
c->value = "groupwise://" + GroupwiseConfig::self()->host() + GroupwiseConfig::self()->path() +
"/freebusy/";
changes.append( c );
KCal::CalendarResourceManager m1( "calendar" );
m1.readConfig();
KCal::CalendarResourceManager::Iterator it;
for ( it = m1.begin(); it != m1.end(); ++it ) {
if ( (*it)->type() == "groupwise" ) break;
}
if ( it == m1.end() ) {
changes.append( new CreateGroupwiseKcalResource );
} else {
if ( (*it)->identifier() == GroupwiseConfig::kcalResource() ) {
KCal::GroupwisePrefsBase *prefs =
static_cast<KCal::ResourceGroupwise *>( *it )->prefs();
if ( prefs->url() != serverUrl() ||
prefs->port() != GroupwiseConfig::self()->port() ||
prefs->user() != GroupwiseConfig::user() ||
prefs->password() != GroupwiseConfig::password() ) {
changes.append( new UpdateGroupwiseKcalResource );
}
}
}
KRES::Manager<TDEABC::Resource> m2( "contact" );
m2.readConfig();
KRES::Manager<TDEABC::Resource>::Iterator it2;
for ( it2 = m2.begin(); it2 != m2.end(); ++it2 ) {
if ( (*it2)->type() == "groupwise" ) break;
}
if ( it2 == m2.end() ) {
changes.append( new CreateGroupwiseTdeabcResource );
} else {
if ( (*it2)->identifier() == GroupwiseConfig::tdeabcResource() ) {
TDEABC::GroupwisePrefs *prefs = static_cast<TDEABC::ResourceGroupwise *>( *it2 )->prefs();
if ( prefs->url() != serverUrl() ||
prefs->user() != GroupwiseConfig::user() ||
prefs->password() != GroupwiseConfig::password() ) {
changes.append( new UpdateGroupwiseTdeabcResource );
}
}
}
if ( GroupwiseConfig::createEmailAccount() ) {
CreateDisconnectedImapAccount *ca =
new CreateDisconnectedImapAccount( i18n("GroupWise") );
ca->setServer( GroupwiseConfig::host() );
ca->setUser( GroupwiseConfig::user() );
ca->setPassword( GroupwiseConfig::password() );
ca->setRealName( GroupwiseConfig::fullName() );
TQString email = GroupwiseConfig::email();
if ( !email.isEmpty() ) ca->setEmail( email );
ca->enableSavePassword( true );
ca->enableSieve( false );
ca->setEncryption( CreateDisconnectedImapAccount::TLS );
ca->setAuthenticationSend( CreateDisconnectedImapAccount::LOGIN );
ca->setSmtpPort( 25 );
ca->setExistingAccountId( GroupwiseConfig::kMailAccountId() );
ca->setExistingTransportId( GroupwiseConfig::kMailTransportId() );
ca->setCustomWriter( new Writer );
changes.append( ca );
}
}
};
GroupwiseWizard::GroupwiseWizard() : TDEConfigWizard( new GroupwisePropagator )
{
TQFrame *page = createWizardPage( i18n("Novell GroupWise") );
TQGridLayout *topLayout = new TQGridLayout( page );
topLayout->setSpacing( spacingHint() );
TQLabel *label = new TQLabel( i18n("Server name:"), page );
topLayout->addWidget( label, 0, 0 );
mServerEdit = new KLineEdit( page );
topLayout->addWidget( mServerEdit, 0, 1 );
label = new TQLabel( i18n("Path to SOAP interface:"), page );
topLayout->addWidget( label, 1, 0 );
mPathEdit = new KLineEdit( page );
topLayout->addWidget( mPathEdit, 1, 1 );
label = new TQLabel( i18n("Port:"), page );
topLayout->addWidget( label, 2, 0 );
mPortEdit = new TQSpinBox( 1, 65536, 1, page );
topLayout->addWidget( mPortEdit, 2, 1 );
label = new TQLabel( i18n("User name:"), page );
topLayout->addWidget( label, 3, 0 );
mUserEdit = new KLineEdit( page );
topLayout->addWidget( mUserEdit, 3, 1 );
label = new TQLabel( i18n("Password:"), page );
topLayout->addWidget( label, 4, 0 );
mPasswordEdit = new KLineEdit( page );
mPasswordEdit->setEchoMode( KLineEdit::Password );
topLayout->addWidget( mPasswordEdit, 4, 1 );
mSavePasswordCheck = new TQCheckBox( i18n("Save password"), page );
topLayout->addMultiCellWidget( mSavePasswordCheck, 5, 5, 0, 1 );
mSecureCheck = new TQCheckBox( i18n("Encrypt communication with server"),
page );
topLayout->addMultiCellWidget( mSecureCheck, 5, 5, 0, 1 );
topLayout->setRowStretch( 6, 1 );
mEmailPage = createWizardPage( i18n("Mail") );
topLayout = new TQGridLayout( mEmailPage );
topLayout->setSpacing( spacingHint() );
mEmailBox = new TQGroupBox( 1, Qt::Horizontal,
i18n("Create Mail Account"), mEmailPage );
mEmailBox->setCheckable( true );
topLayout->addWidget( mEmailBox, 0, 0 );
mEmailWidget = new TQWidget( mEmailBox );
connect( mEmailBox, TQT_SIGNAL( toggled( bool ) ), mEmailWidget,
TQT_SLOT( setEnabled( bool ) ) );
TQGridLayout *accountLayout= new TQGridLayout( mEmailWidget );
accountLayout->setSpacing( spacingHint() );
label = new TQLabel( i18n("Email address:"), mEmailWidget );
accountLayout->addWidget( label, 0, 0 );
mEmailEdit = new KLineEdit( mEmailWidget );
accountLayout->addWidget( mEmailEdit, 0, 1 );
label = new TQLabel( i18n("Full name:"), mEmailWidget );
accountLayout->addWidget( label, 1, 0 );
mFullNameEdit = new KLineEdit( mEmailWidget );
accountLayout->addWidget( mFullNameEdit, 1, 1 );
accountLayout->setRowStretch( 2, 1 );
connect( this, TQT_SIGNAL( aboutToShowPage( TQWidget * ) ),
TQT_SLOT( slotAboutToShowPage( TQWidget * ) ) );
setupRulesPage();
setupChangesPage();
resize( 600, 400 );
}
GroupwiseWizard::~GroupwiseWizard()
{
}
TQString GroupwiseWizard::validate()
{
if( mServerEdit->text().isEmpty() ||
mPathEdit->text().isEmpty() ||
mPortEdit->text().isEmpty() ||
mUserEdit->text().isEmpty() ||
mPasswordEdit->text().isEmpty() )
return i18n( "Please fill in all fields." );
if ( mEmailBox->isChecked() ) {
if( !KPIM::isValidSimpleEmailAddress( mEmailEdit->text() ) )
return i18n("Invalid email address entered.");
if( mFullNameEdit->text().isEmpty() )
return i18n( "Please fill in all fields." );
}
return TQString();
}
void GroupwiseWizard::usrReadConfig()
{
mServerEdit->setText( GroupwiseConfig::self()->host() );
mPathEdit->setText( GroupwiseConfig::self()->path() );
mPortEdit->setValue( GroupwiseConfig::self()->port() );
mUserEdit->setText( GroupwiseConfig::self()->user() );
mPasswordEdit->setText( GroupwiseConfig::self()->password() );
mSavePasswordCheck->setChecked( GroupwiseConfig::self()->savePassword() );
mSecureCheck->setChecked( GroupwiseConfig::self()->useHttps() );
mEmailEdit->setText( GroupwiseConfig::self()->email() );
mFullNameEdit->setText( GroupwiseConfig::fullName() );
mEmailBox->setChecked( GroupwiseConfig::createEmailAccount() );
}
void GroupwiseWizard::usrWriteConfig()
{
GroupwiseConfig::self()->setHost( mServerEdit->text() );
GroupwiseConfig::self()->setPath( mPathEdit->text() );
GroupwiseConfig::self()->setPort( mPortEdit->value() );
GroupwiseConfig::self()->setUser( mUserEdit->text() );
GroupwiseConfig::self()->setPassword( mPasswordEdit->text() );
GroupwiseConfig::self()->setSavePassword( mSavePasswordCheck->isChecked() );
GroupwiseConfig::self()->setUseHttps( mSecureCheck->isChecked() );
GroupwiseConfig::setEmail( mEmailEdit->text() );
GroupwiseConfig::setFullName( mFullNameEdit->text() );
GroupwiseConfig::setCreateEmailAccount( mEmailBox->isChecked() );
}
void GroupwiseWizard::slotAboutToShowPage( TQWidget *page )
{
if ( page == mEmailPage ) {
if ( mEmailEdit->text().isEmpty() ) {
TQString host = GroupwiseConfig::host();
int pos = host.findRev( "." );
if ( pos > 0 ) pos = host.findRev( ".", pos - 1 );
if ( pos > 0 ) host = host.mid( pos + 1 );
TQString email = GroupwiseConfig::user() + "@" + host;
mEmailEdit->setText( email );
}
}
}
#include "groupwisewizard.moc"
|