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