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