Diffstat (limited to 'microkde/kresources/configpage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kresources/configpage.cpp | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 8782ffd..912c62e 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp | |||
@@ -12,24 +12,31 @@ | |||
12 | 12 | ||
13 | This library is distributed in the hope that it will be useful, | 13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 16 | Library General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | ||
25 | Enhanced Version of the file for platform independent KDE tools. | ||
26 | Copyright (c) 2004 Ulf Schenk | ||
27 | |||
28 | $Id$ | ||
29 | */ | ||
30 | |||
24 | #include <qgroupbox.h> | 31 | #include <qgroupbox.h> |
25 | #include <qinputdialog.h> | 32 | #include <qinputdialog.h> |
26 | #include <qlabel.h> | 33 | #include <qlabel.h> |
27 | #include <qlayout.h> | 34 | #include <qlayout.h> |
28 | 35 | ||
29 | #include <kapplication.h> | 36 | #include <kapplication.h> |
30 | #include <kcombobox.h> | 37 | #include <kcombobox.h> |
31 | #include <kdebug.h> | 38 | #include <kdebug.h> |
32 | #include <klocale.h> | 39 | #include <klocale.h> |
33 | #include <kmessagebox.h> | 40 | #include <kmessagebox.h> |
34 | #include <ksimpleconfig.h> | 41 | #include <ksimpleconfig.h> |
35 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
@@ -41,24 +48,27 @@ | |||
41 | #include "resource.h" | 48 | #include "resource.h" |
42 | #include "configdialog.h" | 49 | #include "configdialog.h" |
43 | 50 | ||
44 | #include "configpage.h" | 51 | #include "configpage.h" |
45 | 52 | ||
46 | //US | 53 | //US |
47 | #include <qpushbutton.h> | 54 | #include <qpushbutton.h> |
48 | #include <qfile.h> | 55 | #include <qfile.h> |
49 | #include <kglobal.h> | 56 | #include <kglobal.h> |
50 | 57 | ||
51 | using namespace KRES; | 58 | using namespace KRES; |
52 | 59 | ||
60 | const QString ConfigPage::syncfamily = "syncprofiles"; | ||
61 | |||
62 | |||
53 | class ConfigViewItem : public QCheckListItem | 63 | class ConfigViewItem : public QCheckListItem |
54 | { | 64 | { |
55 | public: | 65 | public: |
56 | ConfigViewItem( QListView *parent, Resource* resource ) : | 66 | ConfigViewItem( QListView *parent, Resource* resource ) : |
57 | QCheckListItem( parent, resource->resourceName(), CheckBox ), | 67 | QCheckListItem( parent, resource->resourceName(), CheckBox ), |
58 | mResource( resource ), | 68 | mResource( resource ), |
59 | mIsStandard( false ) | 69 | mIsStandard( false ) |
60 | { | 70 | { |
61 | setText( 1, mResource->type() ); | 71 | setText( 1, mResource->type() ); |
62 | setOn( mResource->isActive() ); | 72 | setOn( mResource->isActive() ); |
63 | } | 73 | } |
64 | 74 | ||
@@ -155,31 +165,33 @@ void ConfigPage::load() | |||
155 | kdDebug(5650) << "ConfigPage::load()" << endl; | 165 | kdDebug(5650) << "ConfigPage::load()" << endl; |
156 | 166 | ||
157 | mListView->clear(); | 167 | mListView->clear(); |
158 | 168 | ||
159 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. | 169 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. |
160 | 170 | ||
161 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); | 171 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); |
162 | //US KTrader::OfferList::ConstIterator it; | 172 | //US KTrader::OfferList::ConstIterator it; |
163 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 173 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
164 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); | 174 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); |
165 | //US QString family = tmp.toString(); | 175 | //US QString family = tmp.toString(); |
166 | QStringList families; | 176 | QStringList families; |
167 | families << "contact" << "sync-contacts"; | 177 | families << "contact" << syncfamily; |
178 | |||
179 | |||
168 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) | 180 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) |
169 | { | 181 | { |
170 | QString family = (*it); | 182 | QString family = (*it); |
171 | if ( !family.isEmpty() ) { | 183 | if ( !family.isEmpty() ) { |
172 | if ( !mFamilyMap.contains( family ) ) { | 184 | if ( !mFamilyMap.contains( family ) ) { |
173 | mCurrentManager = new Manager<Resource>( family ); | 185 | mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); |
174 | if ( mCurrentManager ) { | 186 | if ( mCurrentManager ) { |
175 | mFamilyMap.append( family ); | 187 | mFamilyMap.append( family ); |
176 | mCurrentManager->addListener( this ); | 188 | mCurrentManager->addListener( this ); |
177 | 189 | ||
178 | ResourcePageInfo info; | 190 | ResourcePageInfo info; |
179 | info.mManager = mCurrentManager; | 191 | info.mManager = mCurrentManager; |
180 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); | 192 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); |
181 | //QString configDir = KStandardDirs::appDir() + "/config"; | 193 | //QString configDir = KStandardDirs::appDir() + "/config"; |
182 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { | 194 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { |
183 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); | 195 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); |
184 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { | 196 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { |
185 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); | 197 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); |
@@ -219,82 +231,95 @@ void ConfigPage::defaults() | |||
219 | } | 231 | } |
220 | 232 | ||
221 | void ConfigPage::slotFamilyChanged( int pos ) | 233 | void ConfigPage::slotFamilyChanged( int pos ) |
222 | { | 234 | { |
223 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) | 235 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) |
224 | return; | 236 | return; |
225 | 237 | ||
226 | saveResourceSettings(); | 238 | saveResourceSettings(); |
227 | 239 | ||
228 | mFamily = mFamilyMap[ pos ]; | 240 | mFamily = mFamilyMap[ pos ]; |
229 | 241 | ||
230 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); | 242 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); |
231 | 243 | ||
232 | mCurrentManager = mInfoMap[ pos ].mManager; | 244 | mCurrentManager = mInfoMap[ pos ].mManager; |
233 | mCurrentConfig = mInfoMap[ pos ].mConfig; | 245 | mCurrentConfig = mInfoMap[ pos ].mConfig; |
234 | 246 | ||
235 | if ( !mCurrentManager ) | 247 | if ( !mCurrentManager ) |
236 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; | 248 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; |
237 | 249 | ||
238 | mListView->clear(); | 250 | mListView->clear(); |
239 | 251 | ||
240 | if ( mCurrentManager->isEmpty() ) { | 252 | if ( mCurrentManager->isEmpty() ) { |
241 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); | 253 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); |
242 | 254 | ||
243 | defaults(); | 255 | defaults(); |
244 | } | 256 | } |
245 | 257 | ||
246 | Resource *standardResource = mCurrentManager->standardResource(); | 258 | Resource *standardResource = mCurrentManager->standardResource(); |
247 | 259 | ||
248 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); | 260 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); |
249 | 261 | ||
250 | 262 | ||
251 | Manager<Resource>::Iterator it; | 263 | Manager<Resource>::Iterator it; |
252 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { | 264 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { |
253 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); | 265 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); |
254 | if ( *it == standardResource ) | 266 | if ( *it == standardResource ) |
255 | item->setStandard( true ); | 267 | item->setStandard( true ); |
256 | } | 268 | } |
257 | 269 | ||
258 | if ( mListView->childCount() == 0 ) { | 270 | if ( mListView->childCount() == 0 ) { |
259 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); | 271 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); |
260 | 272 | ||
261 | defaults(); | 273 | defaults(); |
262 | emit changed( true ); | 274 | emit changed( true ); |
263 | mCurrentManager->writeConfig( mCurrentConfig ); | 275 | mCurrentManager->writeConfig( mCurrentConfig ); |
264 | } else { | 276 | } else { |
265 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); | 277 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); |
266 | 278 | ||
267 | if ( !standardResource ) { | 279 | if ( !standardResource ) { |
268 | KMessageBox::sorry( this, i18n( "There is no standard resource! Please select one." ) ); | 280 | KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); |
269 | 281 | ||
270 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); | 282 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); |
271 | 283 | ||
272 | } | 284 | } |
273 | 285 | ||
274 | emit changed( false ); | 286 | emit changed( false ); |
275 | } | 287 | } |
276 | } | 288 | } |
277 | 289 | ||
278 | void ConfigPage::slotAdd() | 290 | void ConfigPage::slotAdd() |
279 | { | 291 | { |
280 | if ( !mCurrentManager ) | 292 | if ( !mCurrentManager ) |
281 | return; | 293 | return; |
282 | 294 | ||
283 | QStringList types = mCurrentManager->resourceTypeNames(); | 295 | QStringList types = mCurrentManager->resourceTypeNames(); |
284 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); | 296 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); |
285 | bool ok = false; | 297 | bool ok = false; |
286 | QString desc = QInputDialog::getItem( i18n( "Resource Configuration" ), | 298 | |
287 | i18n( "Please select type of the new resource:" ), descs, 0, | 299 | QString desc; |
300 | |||
301 | if (mFamily == syncfamily) | ||
302 | { | ||
303 | desc = QInputDialog::getItem( i18n( "Sync Configuration" ), | ||
304 | i18n( "Please select resource type for new sync profile:" ), descs, 0, | ||
305 | false, &ok, this ); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | desc = QInputDialog::getItem( i18n( "Resource Configuration" ), | ||
310 | i18n( "Please select type of the new resource:" ), descs, 0, | ||
288 | false, &ok, this ); | 311 | false, &ok, this ); |
312 | } | ||
313 | |||
289 | if ( !ok ) | 314 | if ( !ok ) |
290 | return; | 315 | return; |
291 | 316 | ||
292 | QString type = types[ descs.findIndex( desc ) ]; | 317 | QString type = types[ descs.findIndex( desc ) ]; |
293 | 318 | ||
294 | // Create new resource | 319 | // Create new resource |
295 | Resource *resource = mCurrentManager->createResource( type ); | 320 | Resource *resource = mCurrentManager->createResource( type ); |
296 | if ( !resource ) { | 321 | if ( !resource ) { |
297 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") | 322 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") |
298 | .arg( type ) ); | 323 | .arg( type ) ); |
299 | return; | 324 | return; |
300 | } | 325 | } |
@@ -371,49 +396,49 @@ void ConfigPage::slotEdit() | |||
371 | if ( !configItem ) | 396 | if ( !configItem ) |
372 | return; | 397 | return; |
373 | 398 | ||
374 | Resource *resource = configItem->resource(); | 399 | Resource *resource = configItem->resource(); |
375 | 400 | ||
376 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); | 401 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); |
377 | 402 | ||
378 | if ( dlg.exec() ) { | 403 | if ( dlg.exec() ) { |
379 | configItem->setText( 0, resource->resourceName() ); | 404 | configItem->setText( 0, resource->resourceName() ); |
380 | configItem->setText( 1, resource->type() ); | 405 | configItem->setText( 1, resource->type() ); |
381 | 406 | ||
382 | if ( configItem->standard() && configItem->readOnly() ) { | 407 | if ( configItem->standard() && configItem->readOnly() ) { |
383 | KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); | 408 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); |
384 | configItem->setStandard( false ); | 409 | configItem->setStandard( false ); |
385 | } | 410 | } |
386 | 411 | ||
387 | mCurrentManager->resourceChanged( resource ); | 412 | mCurrentManager->resourceChanged( resource ); |
388 | emit changed( true ); | 413 | emit changed( true ); |
389 | } | 414 | } |
390 | } | 415 | } |
391 | 416 | ||
392 | void ConfigPage::slotStandard() | 417 | void ConfigPage::slotStandard() |
393 | { | 418 | { |
394 | if ( !mCurrentManager ) | 419 | if ( !mCurrentManager ) |
395 | return; | 420 | return; |
396 | 421 | ||
397 | ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); | 422 | ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); |
398 | if ( !item ) | 423 | if ( !item ) |
399 | return; | 424 | return; |
400 | 425 | ||
401 | if ( item->readOnly() ) { | 426 | if ( item->readOnly() ) { |
402 | KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); | 427 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); |
403 | return; | 428 | return; |
404 | } | 429 | } |
405 | 430 | ||
406 | if ( !item->isOn() ) { | 431 | if ( !item->isOn() ) { |
407 | KMessageBox::sorry( this, i18n( "You cannot use an inactive resource as standard!" ) ); | 432 | KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); |
408 | return; | 433 | return; |
409 | } | 434 | } |
410 | 435 | ||
411 | QListViewItem *it = mListView->firstChild(); | 436 | QListViewItem *it = mListView->firstChild(); |
412 | while ( it != 0 ) { | 437 | while ( it != 0 ) { |
413 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); | 438 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); |
414 | if ( configItem->standard() ) | 439 | if ( configItem->standard() ) |
415 | configItem->setStandard( false ); | 440 | configItem->setStandard( false ); |
416 | it = it->itemBelow(); | 441 | it = it->itemBelow(); |
417 | } | 442 | } |
418 | 443 | ||
419 | item->setStandard( true ); | 444 | item->setStandard( true ); |
@@ -455,56 +480,56 @@ void ConfigPage::resourceModified( Resource* resource ) | |||
455 | void ConfigPage::resourceDeleted( Resource* resource ) | 480 | void ConfigPage::resourceDeleted( Resource* resource ) |
456 | { | 481 | { |
457 | qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); | 482 | qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); |
458 | kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl; | 483 | kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl; |
459 | } | 484 | } |
460 | 485 | ||
461 | void ConfigPage::slotItemClicked( QListViewItem *item ) | 486 | void ConfigPage::slotItemClicked( QListViewItem *item ) |
462 | { | 487 | { |
463 | ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); | 488 | ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); |
464 | if ( !configItem ) return; | 489 | if ( !configItem ) return; |
465 | 490 | ||
466 | if ( configItem->standard() && !configItem->isOn() ) { | 491 | if ( configItem->standard() && !configItem->isOn() ) { |
467 | KMessageBox::sorry( this, i18n( "You cannot deactivate the standard resource. Choose another standard resource first." ) ); | 492 | KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); |
468 | configItem->setOn( true ); | 493 | configItem->setOn( true ); |
469 | return; | 494 | return; |
470 | } | 495 | } |
471 | 496 | ||
472 | if ( configItem->isOn() != configItem->resource()->isActive() ) { | 497 | if ( configItem->isOn() != configItem->resource()->isActive() ) { |
473 | emit changed( true ); | 498 | emit changed( true ); |
474 | } | 499 | } |
475 | } | 500 | } |
476 | 501 | ||
477 | void ConfigPage::saveResourceSettings() | 502 | void ConfigPage::saveResourceSettings() |
478 | { | 503 | { |
479 | qDebug("ConfigPage::saveResourceSettings() begin"); | 504 | qDebug("ConfigPage::saveResourceSettings() begin"); |
480 | 505 | ||
481 | if ( mCurrentManager ) { | 506 | if ( mCurrentManager ) { |
482 | 507 | ||
483 | QListViewItem *item = mListView->firstChild(); | 508 | QListViewItem *item = mListView->firstChild(); |
484 | while ( item ) { | 509 | while ( item ) { |
485 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); | 510 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); |
486 | 511 | ||
487 | // check if standard resource | 512 | // check if standard resource |
488 | if ( configItem->standard() && !configItem->readOnly() && | 513 | if ( configItem->standard() && !configItem->readOnly() && |
489 | configItem->isOn() ) { | 514 | configItem->isOn() ) { |
490 | 515 | ||
491 | mCurrentManager->setStandardResource( configItem->resource() ); | 516 | mCurrentManager->setStandardResource( configItem->resource() ); |
492 | } | 517 | } |
493 | 518 | ||
494 | // check if active or passive resource | 519 | // check if active or passive resource |
495 | configItem->resource()->setActive( configItem->isOn() ); | 520 | configItem->resource()->setActive( configItem->isOn() ); |
496 | 521 | ||
497 | item = item->nextSibling(); | 522 | item = item->nextSibling(); |
498 | } | 523 | } |
499 | mCurrentManager->writeConfig( mCurrentConfig ); | 524 | mCurrentManager->writeConfig( mCurrentConfig ); |
500 | 525 | ||
501 | if ( !mCurrentManager->standardResource() ) | 526 | if ( !mCurrentManager->standardResource() ) |
502 | KMessageBox::sorry( this, i18n( "There is no valid standard resource! Please select one which is neither read-only nor inactive." ) ); | 527 | KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); |
503 | } | 528 | } |
504 | 529 | ||
505 | qDebug("ConfigPage::saveResourceSettings() end"); | 530 | qDebug("ConfigPage::saveResourceSettings() end"); |
506 | 531 | ||
507 | } | 532 | } |
508 | 533 | ||
509 | //US #include "configpage.moc" | 534 | //US #include "configpage.moc" |
510 | 535 | ||