summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/configpage.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp
index 1a3a22c..02c5fb1 100644
--- a/microkde/kresources/configpage.cpp
+++ b/microkde/kresources/configpage.cpp
@@ -1,554 +1,554 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qgroupbox.h> 31#include <qgroupbox.h>
32#include <qinputdialog.h> 32#include <qinputdialog.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qlayout.h> 34#include <qlayout.h>
35 35
36#include <kapplication.h> 36#include <kapplication.h>
37#include <kcombobox.h> 37#include <kcombobox.h>
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kmessagebox.h> 40#include <kmessagebox.h>
41#include <ksimpleconfig.h> 41#include <ksimpleconfig.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kurlrequester.h> 43#include <kurlrequester.h>
44#include <klistview.h> 44#include <klistview.h>
45#include <kbuttonbox.h> 45#include <kbuttonbox.h>
46//US #include <ktrader.h> 46//US #include <ktrader.h>
47 47
48#include "resource.h" 48#include "resource.h"
49#include "configdialog.h" 49#include "configdialog.h"
50 50
51#include "configpage.h" 51#include "configpage.h"
52 52
53//US 53//US
54#include <qpushbutton.h> 54#include <qpushbutton.h>
55#include <qfile.h> 55#include <qfile.h>
56#include <kglobal.h> 56#include <kglobal.h>
57 57
58using namespace KRES; 58using namespace KRES;
59 59
60const QString ConfigPage::syncfamily = "syncprofiles"; 60const QString ConfigPage::syncfamily = "syncprofiles";
61 61
62 62
63class ConfigViewItem : public QCheckListItem 63class ConfigViewItem : public QCheckListItem
64{ 64{
65 public: 65 public:
66 ConfigViewItem( QListView *parent, Resource* resource ) : 66 ConfigViewItem( QListView *parent, Resource* resource ) :
67 QCheckListItem( parent, resource->resourceName(), CheckBox ), 67 QCheckListItem( parent, resource->resourceName(), CheckBox ),
68 mResource( resource ), 68 mResource( resource ),
69 mIsStandard( false ) 69 mIsStandard( false )
70 { 70 {
71 setText( 1, mResource->type() ); 71 setText( 1, mResource->type() );
72 setOn( mResource->isActive() ); 72 setOn( mResource->isActive() );
73 } 73 }
74 74
75 void setStandard( bool value ) 75 void setStandard( bool value )
76 { 76 {
77 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); 77 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) );
78 mIsStandard = value; 78 mIsStandard = value;
79 } 79 }
80 80
81 bool standard() const { return mIsStandard; } 81 bool standard() const { return mIsStandard; }
82 bool readOnly() const { return mResource->readOnly(); } 82 bool readOnly() const { return mResource->readOnly(); }
83 83
84 Resource *resource() { return mResource; } 84 Resource *resource() { return mResource; }
85 85
86 private: 86 private:
87 Resource* mResource; 87 Resource* mResource;
88 88
89 bool mIsStandard; 89 bool mIsStandard;
90}; 90};
91 91
92ConfigPage::ConfigPage( QWidget *parent, const char *name ) 92ConfigPage::ConfigPage( QWidget *parent, const char *name )
93 : QWidget( parent, name ), 93 : QWidget( parent, name ),
94 mCurrentManager( 0 ), 94 mCurrentManager( 0 ),
95 mCurrentConfig( 0 ) 95 mCurrentConfig( 0 )
96{ 96{
97 setCaption( i18n( "Resource Configuration" ) ); 97 setCaption( i18n( "Resource Configuration" ) );
98 98
99 QVBoxLayout *mainLayout = new QVBoxLayout( this ); 99 QVBoxLayout *mainLayout = new QVBoxLayout( this );
100 100
101 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); 101 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this );
102 groupBox->setColumnLayout(0, Qt::Vertical ); 102 groupBox->setColumnLayout(0, Qt::Vertical );
103 groupBox->layout()->setSpacing( 6 ); 103 groupBox->layout()->setSpacing( 3 );
104 groupBox->layout()->setMargin( 11 ); 104 groupBox->layout()->setMargin( 5 );
105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); 105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 );
106 106
107//US mFamilyCombo = new KComboBox( false, groupBox ); 107//US mFamilyCombo = new KComboBox( false, groupBox );
108 mFamilyCombo = new KComboBox( groupBox ); 108 mFamilyCombo = new KComboBox( groupBox );
109 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); 109 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
110 110
111 mListView = new KListView( groupBox ); 111 mListView = new KListView( groupBox );
112 mListView->setAllColumnsShowFocus( true ); 112 mListView->setAllColumnsShowFocus( true );
113 mListView->addColumn( i18n( "Name" ) ); 113 mListView->addColumn( i18n( "Name" ) );
114 mListView->addColumn( i18n( "Type" ) ); 114 mListView->addColumn( i18n( "Type" ) );
115 mListView->addColumn( i18n( "Standard" ) ); 115 mListView->addColumn( i18n( "Standard" ) );
116 116
117//US groupBoxLayout->addWidget( mListView, 1, 0 ); 117//US groupBoxLayout->addWidget( mListView, 1, 0 );
118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); 118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 );
119 119
120 120
121 mAddButton = new QPushButton( i18n( "&Add..." ), this ); 121 mAddButton = new QPushButton( i18n( "&Add..." ), groupBox );
122 groupBoxLayout->addWidget( mAddButton, 2, 0 ); 122 groupBoxLayout->addWidget( mAddButton, 2, 0 );
123 mRemoveButton = new QPushButton( i18n( "&Remove" ), this ); 123 mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox );
124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); 124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 );
125 mEditButton = new QPushButton( i18n( "&Edit..." ), this ); 125 mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox );
126 groupBoxLayout->addWidget( mEditButton, 3, 0 ); 126 groupBoxLayout->addWidget( mEditButton, 3, 0 );
127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), this ); 127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox );
128 groupBoxLayout->addWidget( mStandardButton, 3, 1 ); 128 groupBoxLayout->addWidget( mStandardButton, 3, 1 );
129 129
130 mRemoveButton->setEnabled( false ); 130 mRemoveButton->setEnabled( false );
131 mEditButton->setEnabled( false ); 131 mEditButton->setEnabled( false );
132 mStandardButton->setEnabled( false ); 132 mStandardButton->setEnabled( false );
133 133
134 134
135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); 135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) );
136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); 136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) );
137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); 137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) );
138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); 138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) );
139 139
140 140
141 mainLayout->addWidget( groupBox ); 141 mainLayout->addWidget( groupBox );
142 142
143 connect( mFamilyCombo, SIGNAL( activated( int ) ), 143 connect( mFamilyCombo, SIGNAL( activated( int ) ),
144 SLOT( slotFamilyChanged( int ) ) ); 144 SLOT( slotFamilyChanged( int ) ) );
145 connect( mListView, SIGNAL( selectionChanged() ), 145 connect( mListView, SIGNAL( selectionChanged() ),
146 SLOT( slotSelectionChanged() ) ); 146 SLOT( slotSelectionChanged() ) );
147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ), 147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
148 SLOT( slotItemClicked( QListViewItem * ) ) ); 148 SLOT( slotItemClicked( QListViewItem * ) ) );
149 149
150 mLastItem = 0; 150 mLastItem = 0;
151 151
152//US mConfig = new KConfig( "kcmkresourcesrc" ); 152//US mConfig = new KConfig( "kcmkresourcesrc" );
153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); 153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") );
154 mConfig->setGroup( "General" ); 154 mConfig->setGroup( "General" );
155 155
156 load(); 156 load();
157} 157}
158 158
159ConfigPage::~ConfigPage() 159ConfigPage::~ConfigPage()
160{ 160{
161 QValueList<ResourcePageInfo>::Iterator it; 161 QValueList<ResourcePageInfo>::Iterator it;
162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { 162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
163 (*it).mManager->removeListener( this ); 163 (*it).mManager->removeListener( this );
164 delete (*it).mManager; 164 delete (*it).mManager;
165 delete (*it).mConfig; 165 delete (*it).mConfig;
166 } 166 }
167 167
168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); 168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
169 delete mConfig; 169 delete mConfig;
170 mConfig = 0; 170 mConfig = 0;
171} 171}
172 172
173void ConfigPage::load() 173void ConfigPage::load()
174{ 174{
175 kdDebug(5650) << "ConfigPage::load()" << endl; 175 kdDebug(5650) << "ConfigPage::load()" << endl;
176 176
177 mListView->clear(); 177 mListView->clear();
178 178
179//US we remove the dynamic pluginloader, and set the one family we need (contact) manually. 179//US we remove the dynamic pluginloader, and set the one family we need (contact) manually.
180 180
181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); 181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
182//US KTrader::OfferList::ConstIterator it; 182//US KTrader::OfferList::ConstIterator it;
183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) { 183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) {
184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); 184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" );
185//US QString family = tmp.toString(); 185//US QString family = tmp.toString();
186 QStringList families; 186 QStringList families;
187 families << "contact" << syncfamily; 187 families << "contact" << syncfamily;
188 188
189 189
190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) 190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it )
191 { 191 {
192 QString family = (*it); 192 QString family = (*it);
193 if ( !family.isEmpty() ) { 193 if ( !family.isEmpty() ) {
194 if ( !mFamilyMap.contains( family ) ) { 194 if ( !mFamilyMap.contains( family ) ) {
195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); 195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) );
196 if ( mCurrentManager ) { 196 if ( mCurrentManager ) {
197 mFamilyMap.append( family ); 197 mFamilyMap.append( family );
198 mCurrentManager->addListener( this ); 198 mCurrentManager->addListener( this );
199 199
200 ResourcePageInfo info; 200 ResourcePageInfo info;
201 info.mManager = mCurrentManager; 201 info.mManager = mCurrentManager;
202 QString configDir = KGlobal::dirs()->saveLocation( "config" ); 202 QString configDir = KGlobal::dirs()->saveLocation( "config" );
203 //QString configDir = KStandardDirs::appDir() + "/config"; 203 //QString configDir = KStandardDirs::appDir() + "/config";
204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { 204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) {
205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); 205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) );
206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { 206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) {
207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); 207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) );
208 } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) { 208 } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) {
209 info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) ); 209 info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) );
210 } else { 210 } else {
211 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); 211 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
212 info.mConfig = new KConfig( configFile ); 212 info.mConfig = new KConfig( configFile );
213 } 213 }
214 info.mManager->readConfig( info.mConfig ); 214 info.mManager->readConfig( info.mConfig );
215 215
216 mInfoMap.append( info ); 216 mInfoMap.append( info );
217 } 217 }
218 } 218 }
219 } 219 }
220 } 220 }
221 mCurrentManager = 0; 221 mCurrentManager = 0;
222 222
223 mFamilyCombo->insertStringList( mFamilyMap ); 223 mFamilyCombo->insertStringList( mFamilyMap );
224 224
225 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); 225 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
226 mFamilyCombo->setCurrentItem( currentFamily ); 226 mFamilyCombo->setCurrentItem( currentFamily );
227 slotFamilyChanged( currentFamily ); 227 slotFamilyChanged( currentFamily );
228} 228}
229 229
230void ConfigPage::save() 230void ConfigPage::save()
231{ 231{
232 saveResourceSettings(); 232 saveResourceSettings();
233 233
234 QValueList<ResourcePageInfo>::Iterator it; 234 QValueList<ResourcePageInfo>::Iterator it;
235 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) 235 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it )
236 (*it).mManager->writeConfig( (*it).mConfig ); 236 (*it).mManager->writeConfig( (*it).mConfig );
237 237
238 emit changed( false ); 238 emit changed( false );
239} 239}
240 240
241void ConfigPage::defaults() 241void ConfigPage::defaults()
242{ 242{
243} 243}
244 244
245void ConfigPage::slotFamilyChanged( int pos ) 245void ConfigPage::slotFamilyChanged( int pos )
246{ 246{
247 if ( pos < 0 || pos >= (int)mFamilyMap.count() ) 247 if ( pos < 0 || pos >= (int)mFamilyMap.count() )
248 return; 248 return;
249 249
250 saveResourceSettings(); 250 saveResourceSettings();
251 251
252 mFamily = mFamilyMap[ pos ]; 252 mFamily = mFamilyMap[ pos ];
253 253
254//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); 254//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1());
255 255
256 mCurrentManager = mInfoMap[ pos ].mManager; 256 mCurrentManager = mInfoMap[ pos ].mManager;
257 mCurrentConfig = mInfoMap[ pos ].mConfig; 257 mCurrentConfig = mInfoMap[ pos ].mConfig;
258 258
259 if ( !mCurrentManager ) 259 if ( !mCurrentManager )
260 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; 260 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl;
261 261
262 mListView->clear(); 262 mListView->clear();
263 263
264 if ( mCurrentManager->isEmpty() ) { 264 if ( mCurrentManager->isEmpty() ) {
265//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); 265//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager );
266 266
267 defaults(); 267 defaults();
268 } 268 }
269 269
270 Resource *standardResource = mCurrentManager->standardResource(); 270 Resource *standardResource = mCurrentManager->standardResource();
271 271
272//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); 272//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1());
273 273
274 274
275 Manager<Resource>::Iterator it; 275 Manager<Resource>::Iterator it;
276 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { 276 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) {
277 ConfigViewItem *item = new ConfigViewItem( mListView, *it ); 277 ConfigViewItem *item = new ConfigViewItem( mListView, *it );
278 if ( *it == standardResource ) 278 if ( *it == standardResource )
279 item->setStandard( true ); 279 item->setStandard( true );
280 } 280 }
281 281
282 if ( mListView->childCount() == 0 ) { 282 if ( mListView->childCount() == 0 ) {
283//US qDebug("ConfigPage::slotFamilyChanged 4.5 "); 283//US qDebug("ConfigPage::slotFamilyChanged 4.5 ");
284 284
285 defaults(); 285 defaults();
286 emit changed( true ); 286 emit changed( true );
287 mCurrentManager->writeConfig( mCurrentConfig ); 287 mCurrentManager->writeConfig( mCurrentConfig );
288 } else { 288 } else {
289//US qDebug("ConfigPage::slotFamilyChanged 4.6 "); 289//US qDebug("ConfigPage::slotFamilyChanged 4.6 ");
290 290
291 if ( !standardResource ) { 291 if ( !standardResource ) {
292 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); 292 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) );
293 293
294//US qDebug("ConfigPage::slotFamilyChanged 4.7" ); 294//US qDebug("ConfigPage::slotFamilyChanged 4.7" );
295 295
296 } 296 }
297 297
298 emit changed( false ); 298 emit changed( false );
299 } 299 }
300} 300}
301 301
302void ConfigPage::slotAdd() 302void ConfigPage::slotAdd()
303{ 303{
304 if ( !mCurrentManager ) 304 if ( !mCurrentManager )
305 return; 305 return;
306 306
307 QStringList types = mCurrentManager->resourceTypeNames(); 307 QStringList types = mCurrentManager->resourceTypeNames();
308 QStringList descs = mCurrentManager->resourceTypeDescriptions(); 308 QStringList descs = mCurrentManager->resourceTypeDescriptions();
309 bool ok = false; 309 bool ok = false;
310 310
311 QString desc; 311 QString desc;
312 312
313 if (mFamily == syncfamily) 313 if (mFamily == syncfamily)
314 { 314 {
315 desc = QInputDialog::getItem( i18n( "Sync Configuration" ), 315 desc = QInputDialog::getItem( i18n( "Sync Configuration" ),
316 i18n( "Select resource type for the new sync profile:" ), descs, 0, 316 i18n( "Select resource type for the new sync profile:" ), descs, 0,
317 false, &ok, this ); 317 false, &ok, this );
318 } 318 }
319 else 319 else
320 { 320 {
321 desc = QInputDialog::getItem( i18n( "Resource Configuration" ), 321 desc = QInputDialog::getItem( i18n( "Resource Configuration" ),
322 i18n( "Select type of the new resource:" ), descs, 0, 322 i18n( "Select type of the new resource:" ), descs, 0,
323 false, &ok, this ); 323 false, &ok, this );
324 } 324 }
325 325
326 if ( !ok ) 326 if ( !ok )
327 return; 327 return;
328 328
329 QString type = types[ descs.findIndex( desc ) ]; 329 QString type = types[ descs.findIndex( desc ) ];
330 330
331 // Create new resource 331 // Create new resource
332 Resource *resource = mCurrentManager->createResource( type ); 332 Resource *resource = mCurrentManager->createResource( type );
333 if ( !resource ) { 333 if ( !resource ) {
334 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") 334 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.")
335 .arg( type ) ); 335 .arg( type ) );
336 return; 336 return;
337 } 337 }
338 338
339 if (mFamily == syncfamily) 339 if (mFamily == syncfamily)
340 { 340 {
341 resource->setResourceName( type + "-syncprofile" ); 341 resource->setResourceName( type + "-syncprofile" );
342 } 342 }
343 else 343 else
344 { 344 {
345 resource->setResourceName( type + "-resource" ); 345 resource->setResourceName( type + "-resource" );
346 } 346 }
347 347
348 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 348 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
349 349
350 if ( dlg.exec() ) { 350 if ( dlg.exec() ) {
351 mCurrentManager->add( resource ); 351 mCurrentManager->add( resource );
352 352
353 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 353 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
354 354
355 mLastItem = item; 355 mLastItem = item;
356 356
357 // if there are only read-only resources we'll set this resource 357 // if there are only read-only resources we'll set this resource
358 // as standard resource 358 // as standard resource
359 if ( !resource->readOnly() ) { 359 if ( !resource->readOnly() ) {
360 bool onlyReadOnly = true; 360 bool onlyReadOnly = true;
361 QListViewItem *it = mListView->firstChild(); 361 QListViewItem *it = mListView->firstChild();
362 while ( it != 0 ) { 362 while ( it != 0 ) {
363 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); 363 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it );
364 if ( !confIt->readOnly() && confIt != item ) 364 if ( !confIt->readOnly() && confIt != item )
365 onlyReadOnly = false; 365 onlyReadOnly = false;
366 366
367 it = it->itemBelow(); 367 it = it->itemBelow();
368 } 368 }
369 369
370 if ( onlyReadOnly ) 370 if ( onlyReadOnly )
371 item->setStandard( true ); 371 item->setStandard( true );
372 } 372 }
373 373
374 emit changed( true ); 374 emit changed( true );
375 } else { 375 } else {
376 delete resource; 376 delete resource;
377 resource = 0; 377 resource = 0;
378 } 378 }
379} 379}
380 380
381void ConfigPage::slotRemove() 381void ConfigPage::slotRemove()
382{ 382{
383 if ( !mCurrentManager ) 383 if ( !mCurrentManager )
384 return; 384 return;
385 385
386 QListViewItem *item = mListView->currentItem(); 386 QListViewItem *item = mListView->currentItem();
387 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); 387 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item );
388 388
389 if ( !confItem ) 389 if ( !confItem )
390 return; 390 return;
391 391
392 if ( confItem->standard() ) { 392 if ( confItem->standard() ) {
393 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); 393 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) );
394 return; 394 return;
395 } 395 }
396 396
397 mCurrentManager->remove( confItem->resource() ); 397 mCurrentManager->remove( confItem->resource() );
398 398
399 if ( item == mLastItem ) 399 if ( item == mLastItem )
400 mLastItem = 0; 400 mLastItem = 0;
401 401
402 mListView->takeItem( item ); 402 mListView->takeItem( item );
403 delete item; 403 delete item;
404 404
405 emit changed( true ); 405 emit changed( true );
406} 406}
407 407
408void ConfigPage::slotEdit() 408void ConfigPage::slotEdit()
409{ 409{
410 if ( !mCurrentManager ) 410 if ( !mCurrentManager )
411 return; 411 return;
412 412
413 QListViewItem *item = mListView->currentItem(); 413 QListViewItem *item = mListView->currentItem();
414 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 414 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
415 if ( !configItem ) 415 if ( !configItem )
416 return; 416 return;
417 417
418 Resource *resource = configItem->resource(); 418 Resource *resource = configItem->resource();
419 419
420 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 420 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
421 421
422 if ( dlg.exec() ) { 422 if ( dlg.exec() ) {
423 configItem->setText( 0, resource->resourceName() ); 423 configItem->setText( 0, resource->resourceName() );
424 configItem->setText( 1, resource->type() ); 424 configItem->setText( 1, resource->type() );
425 425
426 if ( configItem->standard() && configItem->readOnly() ) { 426 if ( configItem->standard() && configItem->readOnly() ) {
427 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); 427 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) );
428 configItem->setStandard( false ); 428 configItem->setStandard( false );
429 } 429 }
430 430
431 mCurrentManager->resourceChanged( resource ); 431 mCurrentManager->resourceChanged( resource );
432 emit changed( true ); 432 emit changed( true );
433 } 433 }
434} 434}
435 435
436void ConfigPage::slotStandard() 436void ConfigPage::slotStandard()
437{ 437{
438 if ( !mCurrentManager ) 438 if ( !mCurrentManager )
439 return; 439 return;
440 440
441 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); 441 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() );
442 if ( !item ) 442 if ( !item )
443 return; 443 return;
444 444
445 if ( item->readOnly() ) { 445 if ( item->readOnly() ) {
446 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); 446 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) );
447 return; 447 return;
448 } 448 }
449 449
450 if ( !item->isOn() ) { 450 if ( !item->isOn() ) {
451 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); 451 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) );
452 return; 452 return;
453 } 453 }
454 454
455 QListViewItem *it = mListView->firstChild(); 455 QListViewItem *it = mListView->firstChild();
456 while ( it != 0 ) { 456 while ( it != 0 ) {
457 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); 457 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it );
458 if ( configItem->standard() ) 458 if ( configItem->standard() )
459 configItem->setStandard( false ); 459 configItem->setStandard( false );
460 it = it->itemBelow(); 460 it = it->itemBelow();
461 } 461 }
462 462
463 item->setStandard( true ); 463 item->setStandard( true );
464 mCurrentManager->setStandardResource( item->resource() ); 464 mCurrentManager->setStandardResource( item->resource() );
465 emit changed( true ); 465 emit changed( true );
466 466
467} 467}
468 468
469void ConfigPage::slotSelectionChanged() 469void ConfigPage::slotSelectionChanged()
470{ 470{
471 bool state = ( mListView->currentItem() != 0 ); 471 bool state = ( mListView->currentItem() != 0 );
472 472
473 mRemoveButton->setEnabled( state ); 473 mRemoveButton->setEnabled( state );
474 mEditButton->setEnabled( state ); 474 mEditButton->setEnabled( state );
475 mStandardButton->setEnabled( state ); 475 mStandardButton->setEnabled( state );
476} 476}
477 477
478void ConfigPage::resourceAdded( Resource* resource ) 478void ConfigPage::resourceAdded( Resource* resource )
479{ 479{
480 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1()); 480 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1());
481 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl; 481 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl;
482 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 482 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
483 483
484 // FIXME: this sucks. This should be in the config file, 484 // FIXME: this sucks. This should be in the config file,
485 // or application-dependent, in which case it's always Off 485 // or application-dependent, in which case it's always Off
486 item->setOn( false ); 486 item->setOn( false );
487 487
488 mLastItem = item; 488 mLastItem = item;
489 489
490 emit changed( true ); 490 emit changed( true );
491} 491}
492 492
493void ConfigPage::resourceModified( Resource* resource ) 493void ConfigPage::resourceModified( Resource* resource )
494{ 494{
495 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1()); 495 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1());
496 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl; 496 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl;
497} 497}
498 498
499void ConfigPage::resourceDeleted( Resource* resource ) 499void ConfigPage::resourceDeleted( Resource* resource )
500{ 500{
501 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); 501 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1());
502 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl; 502 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl;
503} 503}
504 504
505void ConfigPage::slotItemClicked( QListViewItem *item ) 505void ConfigPage::slotItemClicked( QListViewItem *item )
506{ 506{
507 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); 507 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item );
508 if ( !configItem ) return; 508 if ( !configItem ) return;
509 509
510 if ( configItem->standard() && !configItem->isOn() ) { 510 if ( configItem->standard() && !configItem->isOn() ) {
511 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); 511 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) );
512 configItem->setOn( true ); 512 configItem->setOn( true );
513 return; 513 return;
514 } 514 }
515 515
516 if ( configItem->isOn() != configItem->resource()->isActive() ) { 516 if ( configItem->isOn() != configItem->resource()->isActive() ) {
517 emit changed( true ); 517 emit changed( true );
518 } 518 }
519} 519}
520 520
521void ConfigPage::saveResourceSettings() 521void ConfigPage::saveResourceSettings()
522{ 522{
523 qDebug("ConfigPage::saveResourceSettings() begin"); 523 qDebug("ConfigPage::saveResourceSettings() begin");
524 524
525 if ( mCurrentManager ) { 525 if ( mCurrentManager ) {
526 526
527 QListViewItem *item = mListView->firstChild(); 527 QListViewItem *item = mListView->firstChild();
528 while ( item ) { 528 while ( item ) {
529 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 529 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
530 530
531 // check if standard resource 531 // check if standard resource
532 if ( configItem->standard() && !configItem->readOnly() && 532 if ( configItem->standard() && !configItem->readOnly() &&
533 configItem->isOn() ) { 533 configItem->isOn() ) {
534 534
535 mCurrentManager->setStandardResource( configItem->resource() ); 535 mCurrentManager->setStandardResource( configItem->resource() );
536 } 536 }
537 537
538 // check if active or passive resource 538 // check if active or passive resource
539 configItem->resource()->setActive( configItem->isOn() ); 539 configItem->resource()->setActive( configItem->isOn() );
540 540
541 item = item->nextSibling(); 541 item = item->nextSibling();
542 } 542 }
543 mCurrentManager->writeConfig( mCurrentConfig ); 543 mCurrentManager->writeConfig( mCurrentConfig );
544 544
545 if ( !mCurrentManager->standardResource() ) 545 if ( !mCurrentManager->standardResource() )
546 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); 546 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) );
547 } 547 }
548 548
549 qDebug("ConfigPage::saveResourceSettings() end"); 549 qDebug("ConfigPage::saveResourceSettings() end");
550 550
551} 551}
552 552
553//US #include "configpage.moc" 553//US #include "configpage.moc"
554 554