2 This file is part of kdepim.
4 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "groupwisewizard.h"
23 #include "groupwiseconfig.h"
24 #include "kmailchanges.h"
26 #include "kresources/groupwise/kabc_groupwiseprefs.h"
27 #include "kresources/groupwise/kabc_resourcegroupwise.h"
28 #include "kresources/groupwise/kcal_groupwiseprefsbase.h"
29 #include "kresources/groupwise/kcal_resourcegroupwise.h"
31 #include <kcal/resourcecalendar.h>
32 #include <kpimutils/email.h>
34 #include <klineedit.h>
46 if ( GroupwiseConfig::self()->useHttps() ) url
= "https";
48 url
+= "://" + GroupwiseConfig::self()->host() + ':' +
49 QString::number( GroupwiseConfig::self()->port() ) + GroupwiseConfig::self()->path();
53 class CreateGroupwiseKcalResource
: public KConfigPropagator::Change
56 CreateGroupwiseKcalResource()
57 : KConfigPropagator::Change( i18n("Create GroupWise Calendar Resource") )
63 KCal::CalendarResourceManager
m( "calendar" );
66 KCal::ResourceGroupwise
*r
= new KCal::ResourceGroupwise();
68 r
->setResourceName( i18n("GroupWise") );
69 r
->prefs()->setUrl( serverUrl() );
70 r
->prefs()->setUser( GroupwiseConfig::self()->user() );
71 r
->prefs()->setPassword( GroupwiseConfig::self()->password() );
72 r
->setSavePolicy( KCal::ResourceCached::SaveDelayed
);
73 r
->setReloadPolicy( KCal::ResourceCached::ReloadInterval
);
74 r
->setReloadInterval( 20 );
79 GroupwiseConfig::self()->setKcalResource( r
->identifier() );
83 class UpdateGroupwiseKcalResource
: public KConfigPropagator::Change
86 UpdateGroupwiseKcalResource()
87 : KConfigPropagator::Change( i18n("Update GroupWise Calendar Resource") )
93 KCal::CalendarResourceManager
m( "calendar" );
96 KCal::CalendarResourceManager::Iterator it
;
97 for ( it
= m
.begin(); it
!= m
.end(); ++it
) {
98 if ( (*it
)->identifier() == GroupwiseConfig::kcalResource() ) {
99 KCal::ResourceGroupwise
*r
= static_cast<KCal::ResourceGroupwise
*>( *it
);
100 r
->prefs()->setUrl( serverUrl() );
101 r
->prefs()->setUser( GroupwiseConfig::self()->user() );
102 r
->prefs()->setPassword( GroupwiseConfig::self()->password() );
103 // TODO: don't change existing policy
104 r
->setSavePolicy( KCal::ResourceCached::SaveDelayed
);
105 r
->setReloadPolicy( KCal::ResourceCached::ReloadInterval
);
106 r
->setReloadInterval( 20 );
113 class CreateGroupwiseKabcResource
: public KConfigPropagator::Change
116 CreateGroupwiseKabcResource()
117 : KConfigPropagator::Change( i18n("Create GroupWise Addressbook Resource") )
123 KRES::Manager
<KABC::Resource
> m( "contact" );
126 QString url
= serverUrl();
127 QString
user( GroupwiseConfig::self()->user() );
128 QString
password( GroupwiseConfig::self()->password() );
130 KABC::ResourceGroupwise
*r
= new KABC::ResourceGroupwise( url
, user
,
134 r
->setResourceName( i18n("GroupWise") );
138 GroupwiseConfig::self()->setKabcResource( r
->identifier() );
142 class UpdateGroupwiseKabcResource
: public KConfigPropagator::Change
145 UpdateGroupwiseKabcResource()
146 : KConfigPropagator::Change( i18n("Update GroupWise Addressbook Resource") )
152 KRES::Manager
<KABC::Resource
> m( "contact" );
155 KRES::Manager
<KABC::Resource
>::Iterator it
;
156 for ( it
= m
.begin(); it
!= m
.end(); ++it
) {
157 if ( (*it
)->identifier() == GroupwiseConfig::kabcResource() ) {
158 KABC::ResourceGroupwise
*r
= static_cast<KABC::ResourceGroupwise
*>( *it
);
159 r
->prefs()->setUrl( serverUrl() );
160 r
->prefs()->setUser( GroupwiseConfig::self()->user() );
161 r
->prefs()->setPassword( GroupwiseConfig::self()->password() );
169 class GroupwisePropagator
: public KConfigPropagator
172 GroupwisePropagator()
173 : KConfigPropagator( GroupwiseConfig::self(), "groupwise.kcfg" )
177 ~GroupwisePropagator()
179 GroupwiseConfig::self()->writeConfig();
183 class Writer
: public CreateDisconnectedImapAccount::CustomWriter
186 void writeFolder( KConfig
&, int ) {}
187 void writeIds( int accountId
, int transportId
)
189 GroupwiseConfig::setKMailAccountId( accountId
);
190 GroupwiseConfig::setKMailTransportId( transportId
);
194 void addCustomChanges( Change::List
&changes
)
196 ChangeConfig
*c
= new ChangeConfig
;
197 c
->file
= "korganizerrc";
198 c
->group
= "FreeBusy";
199 c
->name
= "FreeBusyRetrieveUrl";
200 c
->value
= "groupwise://" + GroupwiseConfig::self()->host() + GroupwiseConfig::self()->path() +
204 KCal::CalendarResourceManager
m1( "calendar" );
206 KCal::CalendarResourceManager::Iterator it
;
207 for ( it
= m1
.begin(); it
!= m1
.end(); ++it
) {
208 if ( (*it
)->type() == "groupwise" ) break;
210 if ( it
== m1
.end() ) {
211 changes
.append( new CreateGroupwiseKcalResource
);
213 if ( (*it
)->identifier() == GroupwiseConfig::kcalResource() ) {
214 KCal::GroupwisePrefsBase
*prefs
=
215 static_cast<KCal::ResourceGroupwise
*>( *it
)->prefs();
216 if ( prefs
->url() != serverUrl() ||
217 prefs
->port() != GroupwiseConfig::self()->port() ||
218 prefs
->user() != GroupwiseConfig::user() ||
219 prefs
->password() != GroupwiseConfig::password() ) {
220 changes
.append( new UpdateGroupwiseKcalResource
);
225 KRES::Manager
<KABC::Resource
> m2( "contact" );
227 KRES::Manager
<KABC::Resource
>::Iterator it2
;
228 for ( it2
= m2
.begin(); it2
!= m2
.end(); ++it2
) {
229 if ( (*it2
)->type() == "groupwise" ) break;
231 if ( it2
== m2
.end() ) {
232 changes
.append( new CreateGroupwiseKabcResource
);
234 if ( (*it2
)->identifier() == GroupwiseConfig::kabcResource() ) {
235 KABC::GroupwisePrefs
*prefs
= static_cast<KABC::ResourceGroupwise
*>( *it2
)->prefs();
236 if ( prefs
->url() != serverUrl() ||
237 prefs
->user() != GroupwiseConfig::user() ||
238 prefs
->password() != GroupwiseConfig::password() ) {
239 changes
.append( new UpdateGroupwiseKabcResource
);
244 if ( GroupwiseConfig::createEmailAccount() ) {
245 CreateDisconnectedImapAccount
*ca
=
246 new CreateDisconnectedImapAccount( i18n("GroupWise") );
248 ca
->setServer( GroupwiseConfig::host() );
249 ca
->setUser( GroupwiseConfig::user() );
250 ca
->setPassword( GroupwiseConfig::password() );
251 ca
->setRealName( GroupwiseConfig::fullName() );
252 QString email
= GroupwiseConfig::email();
253 if ( !email
.isEmpty() ) ca
->setEmail( email
);
254 ca
->enableSavePassword( true );
255 ca
->enableSieve( false );
256 ca
->setEncryption( CreateDisconnectedImapAccount::SSL
);
257 ca
->setAuthentication( CreateDisconnectedImapAccount::PLAIN
);
258 ca
->setAuthenticationSend( CreateDisconnectedImapAccount::PLAIN
);
259 ca
->setSmtpPort( 25 );
261 ca
->setExistingAccountId( GroupwiseConfig::kMailAccountId() );
262 ca
->setExistingTransportId( GroupwiseConfig::kMailTransportId() );
264 ca
->setCustomWriter( new Writer
);
266 changes
.append( ca
);
271 GroupwiseWizard::GroupwiseWizard() : KConfigWizard( new GroupwisePropagator
)
273 QWidget
*page
= createWizardPage( i18n("Novell GroupWise") );
275 QGridLayout
*topLayout
= new QGridLayout
;
276 topLayout
->setSpacing( spacingHint() );
277 page
->setLayout(topLayout
);
279 QLabel
*label
= new QLabel( i18n("Server name:"));
280 topLayout
->addWidget( label
, 0, 0 );
281 mServerEdit
= new KLineEdit
;
282 topLayout
->addWidget( mServerEdit
, 0, 1 );
284 label
= new QLabel( i18n("Path to SOAP interface:"));
285 topLayout
->addWidget( label
, 1, 0 );
286 mPathEdit
= new KLineEdit
;
287 topLayout
->addWidget( mPathEdit
, 1, 1 );
289 label
= new QLabel( i18n("Port:"));
290 topLayout
->addWidget( label
, 2, 0 );
291 mPortEdit
= new QSpinBox( 1, 65536, 1, this );
292 topLayout
->addWidget( mPortEdit
, 2, 1 );
294 label
= new QLabel( i18n("User name:") );
295 topLayout
->addWidget( label
, 3, 0 );
296 mUserEdit
= new KLineEdit
;
297 topLayout
->addWidget( mUserEdit
, 3, 1 );
299 label
= new QLabel( i18n("Password:"));
300 topLayout
->addWidget( label
, 4, 0 );
301 mPasswordEdit
= new KLineEdit
;
302 mPasswordEdit
->setEchoMode( KLineEdit::Password
);
303 topLayout
->addWidget( mPasswordEdit
, 4, 1 );
305 mSavePasswordCheck
= new QCheckBox( i18n("Save password"));
306 topLayout
->addWidget( mSavePasswordCheck
, 5, 0, 1, 2 );
308 mSecureCheck
= new QCheckBox( i18n("Encrypt communication with server"));
309 topLayout
->addWidget( mSecureCheck
, 5, 0, 2, 2 );
311 topLayout
->setRowStretch( 6, 1 );
314 mEmailPage
= createWizardPage( i18n("Mail") );
316 topLayout
= new QGridLayout
;
317 topLayout
->setSpacing( spacingHint() );
318 mEmailPage
->setLayout(topLayout
);
320 mEmailBox
= new QGroupBox( i18n("Create Mail Account"));
321 mEmailBox
->setCheckable( true );
322 topLayout
->addWidget( mEmailBox
, 0, 0 );
324 QGridLayout
*accountLayout
= new QGridLayout
;
325 accountLayout
->setSpacing( spacingHint() );
327 label
= new QLabel( i18n("Email address:"));
328 accountLayout
->addWidget( label
, 0, 0 );
330 mEmailEdit
= new KLineEdit
;
331 accountLayout
->addWidget( mEmailEdit
, 0, 1 );
333 label
= new QLabel( i18n("Full name:"));
334 accountLayout
->addWidget( label
, 1, 0 );
336 mFullNameEdit
= new KLineEdit
;
337 accountLayout
->addWidget( mFullNameEdit
, 1, 1 );
339 accountLayout
->setRowStretch( 2, 1 );
341 mEmailBox
->setLayout(accountLayout
);
343 connect( this, SIGNAL( currentPageChanged( KPageWidgetItem
*, KPageWidgetItem
* ) ),
344 SLOT( slotAboutToShowPage( KPageWidgetItem
*, KPageWidgetItem
* ) ) );
353 GroupwiseWizard::~GroupwiseWizard()
357 QString
GroupwiseWizard::validate()
359 if( mServerEdit
->text().isEmpty() ||
360 mPathEdit
->text().isEmpty() ||
361 mPortEdit
->text().isEmpty() ||
362 mUserEdit
->text().isEmpty() ||
363 mPasswordEdit
->text().isEmpty() )
364 return i18n( "Please fill in all fields." );
366 if ( mEmailBox
->isChecked() ) {
367 if( !KPIMUtils::isValidSimpleAddress( mEmailEdit
->text() ) )
368 return i18n("Invalid email address entered.");
369 if( mFullNameEdit
->text().isEmpty() )
370 return i18n( "Please fill in all fields." );
376 void GroupwiseWizard::usrReadConfig()
378 mServerEdit
->setText( GroupwiseConfig::self()->host() );
379 mPathEdit
->setText( GroupwiseConfig::self()->path() );
380 mPortEdit
->setValue( GroupwiseConfig::self()->port() );
381 mUserEdit
->setText( GroupwiseConfig::self()->user() );
382 mPasswordEdit
->setText( GroupwiseConfig::self()->password() );
383 mSavePasswordCheck
->setChecked( GroupwiseConfig::self()->savePassword() );
384 mSecureCheck
->setChecked( GroupwiseConfig::self()->useHttps() );
385 mEmailEdit
->setText( GroupwiseConfig::self()->email() );
386 mFullNameEdit
->setText( GroupwiseConfig::fullName() );
387 mEmailBox
->setChecked( GroupwiseConfig::createEmailAccount() );
390 void GroupwiseWizard::usrWriteConfig()
392 GroupwiseConfig::self()->setHost( mServerEdit
->text() );
393 GroupwiseConfig::self()->setPath( mPathEdit
->text() );
394 GroupwiseConfig::self()->setPort( mPortEdit
->value() );
395 GroupwiseConfig::self()->setUser( mUserEdit
->text() );
396 GroupwiseConfig::self()->setPassword( mPasswordEdit
->text() );
397 GroupwiseConfig::self()->setSavePassword( mSavePasswordCheck
->isChecked() );
398 GroupwiseConfig::self()->setUseHttps( mSecureCheck
->isChecked() );
399 GroupwiseConfig::setEmail( mEmailEdit
->text() );
400 GroupwiseConfig::setFullName( mFullNameEdit
->text() );
401 GroupwiseConfig::setCreateEmailAccount( mEmailBox
->isChecked() );
404 void GroupwiseWizard::slotAboutToShowPage( KPageWidgetItem
* page
, KPageWidgetItem
* )
406 if ( page
->widget() == mEmailPage
) {
407 if ( mEmailEdit
->text().isEmpty() ) {
408 QString host
= mServerEdit
->text();
409 int pos
= host
.lastIndexOf( "." );
410 if ( pos
> 0 ) pos
= host
.lastIndexOf( ".", pos
- 1 );
411 if ( pos
> 0 ) host
= host
.mid( pos
+ 1 );
412 QString email
= mUserEdit
->text() + '@' + host
;
413 mEmailEdit
->setText( email
);
418 #include "groupwisewizard.moc"