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
|
/*
This file is part of kdepim.
Copyright (c) 2004 Tobias Koenig <[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 "egroupwarewizard.h"
#include "egroupwareconfig.h"
#include "kresources/egroupware/kabc_egroupwareprefs.h"
#include "kresources/egroupware/kabc_resourcexmlrpc.h"
#include "kresources/egroupware/kcal_egroupwareprefs.h"
#include "kresources/egroupware/kcal_resourcexmlrpc.h"
#include "kresources/egroupware/knotes_egroupwareprefs.h"
#include "kresources/egroupware/knotes_resourcexmlrpc.h"
#include <libkcal/resourcecalendar.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqwhatsthis.h>
static TQString createURL( const TQString &server, bool useSSL, const TQString &location )
{
KURL url;
if ( useSSL )
url.setProtocol( "https" );
else
url.setProtocol( "http" );
url.setHost( server );
url.setPath( "/" + location );
return url.url();
}
class CreateEGroupwareKabcResource : public KConfigPropagator::Change
{
public:
CreateEGroupwareKabcResource()
: KConfigPropagator::Change( i18n("Create eGroupware Addressbook Resource") )
{
}
void apply()
{
kdDebug() << "Create eGroupware Addressbook Resource" << endl;
KRES::Manager<KABC::Resource> manager( "contact" );
manager.readConfig();
TQString url = createURL( EGroupwareConfig::self()->server(), EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() );
KABC::ResourceXMLRPC *resource = new KABC::ResourceXMLRPC( url, EGroupwareConfig::self()->domain(),
EGroupwareConfig::self()->user(),
EGroupwareConfig::self()->password() );
resource->setResourceName( i18n( "eGroupware" ) );
manager.add( resource );
manager.writeConfig();
}
};
// TODO: fix the i18n strings after freeze...
class ChangeEGroupwareKabcResource : public KConfigPropagator::Change
{
public:
ChangeEGroupwareKabcResource( const TQString &identifier )
: KConfigPropagator::Change( i18n("Create eGroupware Addressbook Resource") ),
mIdentifier( identifier )
{
}
void apply()
{
kdDebug() << "Change eGroupware Addressbook Resource" << endl;
KRES::Manager<KABC::Resource> manager( "contact" );
manager.readConfig();
KRES::Manager<KABC::Resource>::Iterator it;
for ( it = manager.begin(); it != manager.end(); ++it ) {
if ( (*it)->identifier() == mIdentifier ) {
KABC::ResourceXMLRPC *resource = static_cast<KABC::ResourceXMLRPC*>( *it );
resource->prefs()->setUrl( createURL( EGroupwareConfig::self()->server(),
EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() ) );
resource->prefs()->setDomain( EGroupwareConfig::self()->domain() );
resource->prefs()->setUser( EGroupwareConfig::self()->user() );
resource->prefs()->setPassword( EGroupwareConfig::self()->password() );
manager.change( resource );
manager.writeConfig();
return;
}
}
}
private:
TQString mIdentifier;
};
class CreateEGroupwareKcalResource : public KConfigPropagator::Change
{
public:
CreateEGroupwareKcalResource()
: KConfigPropagator::Change( i18n( "Create eGroupware Calendar Resource" ) )
{
}
void apply()
{
kdDebug() << "Create eGroupware Calendar Resource" << endl;
KCal::CalendarResourceManager manager( "calendar" );
manager.readConfig();
KCal::ResourceXMLRPC *resource = new KCal::ResourceXMLRPC();
resource->setResourceName( i18n( "eGroupware" ) );
resource->prefs()->setUrl( createURL( EGroupwareConfig::self()->server(), EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() ) );
resource->prefs()->setDomain( EGroupwareConfig::self()->domain() );
resource->prefs()->setUser( EGroupwareConfig::self()->user() );
resource->prefs()->setPassword( EGroupwareConfig::self()->password() );
manager.add( resource );
manager.writeConfig();
}
};
class ChangeEGroupwareKcalResource : public KConfigPropagator::Change
{
public:
ChangeEGroupwareKcalResource( const TQString &identifier )
: KConfigPropagator::Change( i18n( "Create eGroupware Calendar Resource" ) ),
mIdentifier( identifier )
{
}
void apply()
{
kdDebug() << "Change eGroupware Calendar Resource" << endl;
KCal::CalendarResourceManager manager( "calendar" );
manager.readConfig();
KCal::CalendarResourceManager::Iterator it;
for ( it = manager.begin(); it != manager.end(); ++it ) {
if ( (*it)->identifier() == mIdentifier ) {
KCal::ResourceXMLRPC *resource = static_cast<KCal::ResourceXMLRPC*>( *it );
resource->prefs()->setUrl( createURL( EGroupwareConfig::self()->server(),
EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() ) );
resource->prefs()->setDomain( EGroupwareConfig::self()->domain() );
resource->prefs()->setUser( EGroupwareConfig::self()->user() );
resource->prefs()->setPassword( EGroupwareConfig::self()->password() );
manager.change( resource );
manager.writeConfig();
return;
}
}
}
private:
TQString mIdentifier;
};
class CreateEGroupwareKnotesResource : public KConfigPropagator::Change
{
public:
CreateEGroupwareKnotesResource()
: KConfigPropagator::Change( i18n("Create eGroupware Notes Resource") )
{
}
void apply()
{
kdDebug() << "Create eGroupware notes Resource" << endl;
KRES::Manager<ResourceNotes> manager( "notes" );
manager.readConfig();
TQString url = createURL( EGroupwareConfig::self()->server(), EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() );
KNotes::ResourceXMLRPC *resource = new KNotes::ResourceXMLRPC();
resource->setResourceName( i18n( "eGroupware" ) );
resource->prefs()->setUrl( createURL( EGroupwareConfig::self()->server(), EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() ) );
resource->prefs()->setDomain( EGroupwareConfig::self()->domain() );
resource->prefs()->setUser( EGroupwareConfig::self()->user() );
resource->prefs()->setPassword( EGroupwareConfig::self()->password() );
manager.add( resource );
manager.writeConfig();
}
};
class ChangeEGroupwareKnotesResource : public KConfigPropagator::Change
{
public:
ChangeEGroupwareKnotesResource( const TQString &identifier )
: KConfigPropagator::Change( i18n("Create eGroupware Notes Resource") ),
mIdentifier( identifier )
{
}
void apply()
{
kdDebug() << "Change eGroupware Notes Resource" << endl;
KRES::Manager<ResourceNotes> manager( "notes" );
manager.readConfig();
KRES::Manager<ResourceNotes>::Iterator it;
for ( it = manager.begin(); it != manager.end(); ++it ) {
if ( (*it)->identifier() == mIdentifier ) {
KNotes::ResourceXMLRPC *resource = static_cast<KNotes::ResourceXMLRPC*>( *it );
resource->prefs()->setUrl( createURL( EGroupwareConfig::self()->server(),
EGroupwareConfig::self()->useSSLConnection(), EGroupwareConfig::self()->xmlrpc_location() ) );
resource->prefs()->setDomain( EGroupwareConfig::self()->domain() );
resource->prefs()->setUser( EGroupwareConfig::self()->user() );
resource->prefs()->setPassword( EGroupwareConfig::self()->password() );
manager.change( resource );
manager.writeConfig();
return;
}
}
}
private:
TQString mIdentifier;
};
class EGroupwarePropagator : public KConfigPropagator
{
public:
EGroupwarePropagator()
: KConfigPropagator( EGroupwareConfig::self(), "egroupware.kcfg" )
{
}
protected:
void addCustomChanges( Change::List &changes )
{
KCal::CalendarResourceManager kcalManager( "calendar" );
kcalManager.readConfig();
KCal::CalendarResourceManager::Iterator kcalIt;
for ( kcalIt = kcalManager.begin(); kcalIt != kcalManager.end(); ++kcalIt ) {
if ( (*kcalIt)->type() == "xmlrpc" ) break;
}
if ( kcalIt == kcalManager.end() ) {
changes.append( new CreateEGroupwareKcalResource );
} else {
changes.append( new ChangeEGroupwareKcalResource( (*kcalIt)->identifier() ) );
}
KRES::Manager<KABC::Resource> kabcManager( "contact" );
kabcManager.readConfig();
KRES::Manager<KABC::Resource>::Iterator kabcIt;
for ( kabcIt = kabcManager.begin(); kabcIt != kabcManager.end(); ++kabcIt ) {
if ( (*kabcIt)->type() == "xmlrpc" ) break;
}
if ( kabcIt == kabcManager.end() ) {
changes.append( new CreateEGroupwareKabcResource );
} else {
changes.append( new ChangeEGroupwareKabcResource( (*kabcIt)->identifier() ) );
}
KRES::Manager<ResourceNotes> knotesManager( "notes" );
knotesManager.readConfig();
KRES::Manager<ResourceNotes>::Iterator knotesIt;
for ( knotesIt = knotesManager.begin(); knotesIt != knotesManager.end(); ++knotesIt ) {
if ( (*knotesIt)->type() == "xmlrpc" ) break;
}
if ( knotesIt == knotesManager.end() ) {
changes.append( new CreateEGroupwareKnotesResource );
} else {
changes.append( new ChangeEGroupwareKnotesResource( (*knotesIt)->identifier() ) );
}
}
};
EGroupwareWizard::EGroupwareWizard() : KConfigWizard( new EGroupwarePropagator )
{
TQFrame *page = createWizardPage( i18n( "eGroupware Server" ) );
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 );
label->setBuddy( mServerEdit );
topLayout->addWidget( mServerEdit, 0, 1 );
label = new TQLabel( i18n( "&Domain name:" ), page );
topLayout->addWidget( label, 1, 0 );
mDomainEdit = new KLineEdit( page );
label->setBuddy( mDomainEdit );
topLayout->addWidget( mDomainEdit, 1, 1 );
label = new TQLabel( i18n( "&Username:" ), page );
topLayout->addWidget( label, 2, 0 );
mUserEdit = new KLineEdit( page );
label->setBuddy( mUserEdit );
topLayout->addWidget( mUserEdit, 2, 1 );
label = new TQLabel( i18n( "&Password:" ), page );
topLayout->addWidget( label, 3, 0 );
mPasswordEdit = new KLineEdit( page );
mPasswordEdit->setEchoMode( KLineEdit::Password );
label->setBuddy( mPasswordEdit );
topLayout->addWidget( mPasswordEdit, 3, 1 );
label = new TQLabel( i18n( "&Location xmlrpc.php on server:" ), page );
topLayout->addWidget( label, 4, 0 );
mXMLRPC = new KLineEdit( page );
mXMLRPC->setMinimumWidth( 175 );
label->setBuddy( mXMLRPC );
topLayout->addWidget( mXMLRPC, 4, 1 );
TQWhatsThis::add( label, i18n( "Some servers may not have the xmlrpc.php file in the 'egroupware' folder of the server. With this option it is possible to eventually change the path to that file. For most servers, the default value is OK." ) );
mUseSSLConnectionCheck = new TQCheckBox( i18n( "Use SS&L connection" ), page );
topLayout->addMultiCellWidget( mUseSSLConnectionCheck, 5, 5, 0, 1 );
topLayout->setRowStretch( 6, 1 );
setupRulesPage();
setupChangesPage();
resize( tqsizeHint() );
}
EGroupwareWizard::~EGroupwareWizard()
{
}
TQString EGroupwareWizard::validate()
{
if( !mXMLRPC->text().endsWith( "xmlrpc.php" ) )
return i18n( "Invalid path to xmlrpc.php entered." );
if( mServerEdit->text().isEmpty() ||
mDomainEdit->text().isEmpty() ||
mUserEdit->text().isEmpty() ||
mPasswordEdit->text().isEmpty() ||
mXMLRPC->text().isEmpty() )
return i18n( "Please fill in all fields." );
return TQString();
}
void EGroupwareWizard::usrReadConfig()
{
mServerEdit->setText( EGroupwareConfig::self()->server() );
mDomainEdit->setText( EGroupwareConfig::self()->domain() );
mUserEdit->setText( EGroupwareConfig::self()->user() );
mPasswordEdit->setText( EGroupwareConfig::self()->password() );
mXMLRPC->setText( EGroupwareConfig::self()->xmlrpc_location() );
mUseSSLConnectionCheck->setChecked( EGroupwareConfig::self()->useSSLConnection() );
}
void EGroupwareWizard::usrWriteConfig()
{
EGroupwareConfig::self()->setServer( mServerEdit->text() );
EGroupwareConfig::self()->setDomain( mDomainEdit->text() );
EGroupwareConfig::self()->setUser( mUserEdit->text() );
EGroupwareConfig::self()->setPassword( mPasswordEdit->text() );
EGroupwareConfig::self()->setXmlrpc_location( mXMLRPC->text() );
EGroupwareConfig::self()->setUseSSLConnection( mUseSSLConnectionCheck->isChecked() );
}
|