summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-02 22:23:36 (UTC)
committer ulf69 <ulf69>2004-08-02 22:23:36 (UTC)
commitcaccbdef7506ed596669c35009bd6d5634ee6ee1 (patch) (unidiff)
treec45c1ff5cc2dd236dfe96ef087c1eaeb28d7b382
parent5a7175ae22a89b28699983e8f97b7896d45f26e1 (diff)
downloadkdepimpi-caccbdef7506ed596669c35009bd6d5634ee6ee1.zip
kdepimpi-caccbdef7506ed596669c35009bd6d5634ee6ee1.tar.gz
kdepimpi-caccbdef7506ed596669c35009bd6d5634ee6ee1.tar.bz2
optimized layout for SL5500
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/configpage.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp
index 912c62e..2fe021d 100644
--- a/microkde/kresources/configpage.cpp
+++ b/microkde/kresources/configpage.cpp
@@ -1,535 +1,545 @@
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( 6 );
104 groupBox->layout()->setMargin( 11 ); 104 groupBox->layout()->setMargin( 11 );
105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 2, 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 groupBoxLayout->addWidget( mListView, 1, 0 ); 117//US groupBoxLayout->addWidget( mListView, 1, 0 );
118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 );
119
120
121 mAddButton = new QPushButton( i18n( "&Add..." ), this );
122 groupBoxLayout->addWidget( mAddButton, 2, 0 );
123 mRemoveButton = new QPushButton( i18n( "&Remove" ), this );
124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 );
125 mEditButton = new QPushButton( i18n( "&Edit..." ), this );
126 groupBoxLayout->addWidget( mEditButton, 3, 0 );
127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), this );
128 groupBoxLayout->addWidget( mStandardButton, 3, 1 );
118 129
119 KButtonBox *buttonBox = new KButtonBox( groupBox, Vertical );
120 mAddButton = buttonBox->addButton( i18n( "&Add..." ), this, SLOT(slotAdd()) );
121 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT(slotRemove()) );
122 mRemoveButton->setEnabled( false ); 130 mRemoveButton->setEnabled( false );
123 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT(slotEdit()) );
124 mEditButton->setEnabled( false ); 131 mEditButton->setEnabled( false );
125 mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), this, SLOT(slotStandard()) );
126 mStandardButton->setEnabled( false ); 132 mStandardButton->setEnabled( false );
127 buttonBox->layout();
128 133
129 groupBoxLayout->addWidget( buttonBox, 1, 1 ); 134
135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) );
136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) );
137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) );
138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) );
139
130 140
131 mainLayout->addWidget( groupBox ); 141 mainLayout->addWidget( groupBox );
132 142
133 connect( mFamilyCombo, SIGNAL( activated( int ) ), 143 connect( mFamilyCombo, SIGNAL( activated( int ) ),
134 SLOT( slotFamilyChanged( int ) ) ); 144 SLOT( slotFamilyChanged( int ) ) );
135 connect( mListView, SIGNAL( selectionChanged() ), 145 connect( mListView, SIGNAL( selectionChanged() ),
136 SLOT( slotSelectionChanged() ) ); 146 SLOT( slotSelectionChanged() ) );
137 connect( mListView, SIGNAL( clicked( QListViewItem * ) ), 147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
138 SLOT( slotItemClicked( QListViewItem * ) ) ); 148 SLOT( slotItemClicked( QListViewItem * ) ) );
139 149
140 mLastItem = 0; 150 mLastItem = 0;
141 151
142//US mConfig = new KConfig( "kcmkresourcesrc" ); 152//US mConfig = new KConfig( "kcmkresourcesrc" );
143 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); 153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") );
144 mConfig->setGroup( "General" ); 154 mConfig->setGroup( "General" );
145 155
146 load(); 156 load();
147} 157}
148 158
149ConfigPage::~ConfigPage() 159ConfigPage::~ConfigPage()
150{ 160{
151 QValueList<ResourcePageInfo>::Iterator it; 161 QValueList<ResourcePageInfo>::Iterator it;
152 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { 162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
153 (*it).mManager->removeListener( this ); 163 (*it).mManager->removeListener( this );
154 delete (*it).mManager; 164 delete (*it).mManager;
155 delete (*it).mConfig; 165 delete (*it).mConfig;
156 } 166 }
157 167
158 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); 168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
159 delete mConfig; 169 delete mConfig;
160 mConfig = 0; 170 mConfig = 0;
161} 171}
162 172
163void ConfigPage::load() 173void ConfigPage::load()
164{ 174{
165 kdDebug(5650) << "ConfigPage::load()" << endl; 175 kdDebug(5650) << "ConfigPage::load()" << endl;
166 176
167 mListView->clear(); 177 mListView->clear();
168 178
169//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.
170 180
171//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); 181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
172//US KTrader::OfferList::ConstIterator it; 182//US KTrader::OfferList::ConstIterator it;
173//US for ( it = plugins.begin(); it != plugins.end(); ++it ) { 183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) {
174//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); 184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" );
175//US QString family = tmp.toString(); 185//US QString family = tmp.toString();
176 QStringList families; 186 QStringList families;
177 families << "contact" << syncfamily; 187 families << "contact" << syncfamily;
178 188
179 189
180 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) 190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it )
181 { 191 {
182 QString family = (*it); 192 QString family = (*it);
183 if ( !family.isEmpty() ) { 193 if ( !family.isEmpty() ) {
184 if ( !mFamilyMap.contains( family ) ) { 194 if ( !mFamilyMap.contains( family ) ) {
185 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); 195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) );
186 if ( mCurrentManager ) { 196 if ( mCurrentManager ) {
187 mFamilyMap.append( family ); 197 mFamilyMap.append( family );
188 mCurrentManager->addListener( this ); 198 mCurrentManager->addListener( this );
189 199
190 ResourcePageInfo info; 200 ResourcePageInfo info;
191 info.mManager = mCurrentManager; 201 info.mManager = mCurrentManager;
192 QString configDir = KGlobal::dirs()->saveLocation( "config" ); 202 QString configDir = KGlobal::dirs()->saveLocation( "config" );
193 //QString configDir = KStandardDirs::appDir() + "/config"; 203 //QString configDir = KStandardDirs::appDir() + "/config";
194 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { 204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) {
195 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); 205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) );
196 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { 206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) {
197 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); 207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) );
198 } else { 208 } else {
199 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); 209 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
200 info.mConfig = new KConfig( configFile ); 210 info.mConfig = new KConfig( configFile );
201 } 211 }
202 info.mManager->readConfig( info.mConfig ); 212 info.mManager->readConfig( info.mConfig );
203 213
204 mInfoMap.append( info ); 214 mInfoMap.append( info );
205 } 215 }
206 } 216 }
207 } 217 }
208 } 218 }
209 mCurrentManager = 0; 219 mCurrentManager = 0;
210 220
211 mFamilyCombo->insertStringList( mFamilyMap ); 221 mFamilyCombo->insertStringList( mFamilyMap );
212 222
213 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); 223 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
214 mFamilyCombo->setCurrentItem( currentFamily ); 224 mFamilyCombo->setCurrentItem( currentFamily );
215 slotFamilyChanged( currentFamily ); 225 slotFamilyChanged( currentFamily );
216} 226}
217 227
218void ConfigPage::save() 228void ConfigPage::save()
219{ 229{
220 saveResourceSettings(); 230 saveResourceSettings();
221 231
222 QValueList<ResourcePageInfo>::Iterator it; 232 QValueList<ResourcePageInfo>::Iterator it;
223 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) 233 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it )
224 (*it).mManager->writeConfig( (*it).mConfig ); 234 (*it).mManager->writeConfig( (*it).mConfig );
225 235
226 emit changed( false ); 236 emit changed( false );
227} 237}
228 238
229void ConfigPage::defaults() 239void ConfigPage::defaults()
230{ 240{
231} 241}
232 242
233void ConfigPage::slotFamilyChanged( int pos ) 243void ConfigPage::slotFamilyChanged( int pos )
234{ 244{
235 if ( pos < 0 || pos >= (int)mFamilyMap.count() ) 245 if ( pos < 0 || pos >= (int)mFamilyMap.count() )
236 return; 246 return;
237 247
238 saveResourceSettings(); 248 saveResourceSettings();
239 249
240 mFamily = mFamilyMap[ pos ]; 250 mFamily = mFamilyMap[ pos ];
241 251
242//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); 252//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1());
243 253
244 mCurrentManager = mInfoMap[ pos ].mManager; 254 mCurrentManager = mInfoMap[ pos ].mManager;
245 mCurrentConfig = mInfoMap[ pos ].mConfig; 255 mCurrentConfig = mInfoMap[ pos ].mConfig;
246 256
247 if ( !mCurrentManager ) 257 if ( !mCurrentManager )
248 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; 258 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl;
249 259
250 mListView->clear(); 260 mListView->clear();
251 261
252 if ( mCurrentManager->isEmpty() ) { 262 if ( mCurrentManager->isEmpty() ) {
253//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); 263//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager );
254 264
255 defaults(); 265 defaults();
256 } 266 }
257 267
258 Resource *standardResource = mCurrentManager->standardResource(); 268 Resource *standardResource = mCurrentManager->standardResource();
259 269
260//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); 270//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1());
261 271
262 272
263 Manager<Resource>::Iterator it; 273 Manager<Resource>::Iterator it;
264 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { 274 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) {
265 ConfigViewItem *item = new ConfigViewItem( mListView, *it ); 275 ConfigViewItem *item = new ConfigViewItem( mListView, *it );
266 if ( *it == standardResource ) 276 if ( *it == standardResource )
267 item->setStandard( true ); 277 item->setStandard( true );
268 } 278 }
269 279
270 if ( mListView->childCount() == 0 ) { 280 if ( mListView->childCount() == 0 ) {
271//US qDebug("ConfigPage::slotFamilyChanged 4.5 "); 281//US qDebug("ConfigPage::slotFamilyChanged 4.5 ");
272 282
273 defaults(); 283 defaults();
274 emit changed( true ); 284 emit changed( true );
275 mCurrentManager->writeConfig( mCurrentConfig ); 285 mCurrentManager->writeConfig( mCurrentConfig );
276 } else { 286 } else {
277//US qDebug("ConfigPage::slotFamilyChanged 4.6 "); 287//US qDebug("ConfigPage::slotFamilyChanged 4.6 ");
278 288
279 if ( !standardResource ) { 289 if ( !standardResource ) {
280 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); 290 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) );
281 291
282//US qDebug("ConfigPage::slotFamilyChanged 4.7" ); 292//US qDebug("ConfigPage::slotFamilyChanged 4.7" );
283 293
284 } 294 }
285 295
286 emit changed( false ); 296 emit changed( false );
287 } 297 }
288} 298}
289 299
290void ConfigPage::slotAdd() 300void ConfigPage::slotAdd()
291{ 301{
292 if ( !mCurrentManager ) 302 if ( !mCurrentManager )
293 return; 303 return;
294 304
295 QStringList types = mCurrentManager->resourceTypeNames(); 305 QStringList types = mCurrentManager->resourceTypeNames();
296 QStringList descs = mCurrentManager->resourceTypeDescriptions(); 306 QStringList descs = mCurrentManager->resourceTypeDescriptions();
297 bool ok = false; 307 bool ok = false;
298 308
299 QString desc; 309 QString desc;
300 310
301 if (mFamily == syncfamily) 311 if (mFamily == syncfamily)
302 { 312 {
303 desc = QInputDialog::getItem( i18n( "Sync Configuration" ), 313 desc = QInputDialog::getItem( i18n( "Sync Configuration" ),
304 i18n( "Please select resource type for new sync profile:" ), descs, 0, 314 i18n( "Please select resource type for new sync profile:" ), descs, 0,
305 false, &ok, this ); 315 false, &ok, this );
306 } 316 }
307 else 317 else
308 { 318 {
309 desc = QInputDialog::getItem( i18n( "Resource Configuration" ), 319 desc = QInputDialog::getItem( i18n( "Resource Configuration" ),
310 i18n( "Please select type of the new resource:" ), descs, 0, 320 i18n( "Please select type of the new resource:" ), descs, 0,
311 false, &ok, this ); 321 false, &ok, this );
312 } 322 }
313 323
314 if ( !ok ) 324 if ( !ok )
315 return; 325 return;
316 326
317 QString type = types[ descs.findIndex( desc ) ]; 327 QString type = types[ descs.findIndex( desc ) ];
318 328
319 // Create new resource 329 // Create new resource
320 Resource *resource = mCurrentManager->createResource( type ); 330 Resource *resource = mCurrentManager->createResource( type );
321 if ( !resource ) { 331 if ( !resource ) {
322 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") 332 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.")
323 .arg( type ) ); 333 .arg( type ) );
324 return; 334 return;
325 } 335 }
326 336
327 resource->setResourceName( type + "-resource" ); 337 resource->setResourceName( type + "-resource" );
328 338
329 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 339 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
330 340
331 if ( dlg.exec() ) { 341 if ( dlg.exec() ) {
332 mCurrentManager->add( resource ); 342 mCurrentManager->add( resource );
333 343
334 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 344 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
335 345
336 mLastItem = item; 346 mLastItem = item;
337 347
338 // if there are only read-only resources we'll set this resource 348 // if there are only read-only resources we'll set this resource
339 // as standard resource 349 // as standard resource
340 if ( !resource->readOnly() ) { 350 if ( !resource->readOnly() ) {
341 bool onlyReadOnly = true; 351 bool onlyReadOnly = true;
342 QListViewItem *it = mListView->firstChild(); 352 QListViewItem *it = mListView->firstChild();
343 while ( it != 0 ) { 353 while ( it != 0 ) {
344 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); 354 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it );
345 if ( !confIt->readOnly() && confIt != item ) 355 if ( !confIt->readOnly() && confIt != item )
346 onlyReadOnly = false; 356 onlyReadOnly = false;
347 357
348 it = it->itemBelow(); 358 it = it->itemBelow();
349 } 359 }
350 360
351 if ( onlyReadOnly ) 361 if ( onlyReadOnly )
352 item->setStandard( true ); 362 item->setStandard( true );
353 } 363 }
354 364
355 emit changed( true ); 365 emit changed( true );
356 } else { 366 } else {
357 delete resource; 367 delete resource;
358 resource = 0; 368 resource = 0;
359 } 369 }
360} 370}
361 371
362void ConfigPage::slotRemove() 372void ConfigPage::slotRemove()
363{ 373{
364 if ( !mCurrentManager ) 374 if ( !mCurrentManager )
365 return; 375 return;
366 376
367 QListViewItem *item = mListView->currentItem(); 377 QListViewItem *item = mListView->currentItem();
368 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); 378 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item );
369 379
370 if ( !confItem ) 380 if ( !confItem )
371 return; 381 return;
372 382
373 if ( confItem->standard() ) { 383 if ( confItem->standard() ) {
374 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); 384 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) );
375 return; 385 return;
376 } 386 }
377 387
378 mCurrentManager->remove( confItem->resource() ); 388 mCurrentManager->remove( confItem->resource() );
379 389
380 if ( item == mLastItem ) 390 if ( item == mLastItem )
381 mLastItem = 0; 391 mLastItem = 0;
382 392
383 mListView->takeItem( item ); 393 mListView->takeItem( item );
384 delete item; 394 delete item;
385 395
386 emit changed( true ); 396 emit changed( true );
387} 397}
388 398
389void ConfigPage::slotEdit() 399void ConfigPage::slotEdit()
390{ 400{
391 if ( !mCurrentManager ) 401 if ( !mCurrentManager )
392 return; 402 return;
393 403
394 QListViewItem *item = mListView->currentItem(); 404 QListViewItem *item = mListView->currentItem();
395 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 405 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
396 if ( !configItem ) 406 if ( !configItem )
397 return; 407 return;
398 408
399 Resource *resource = configItem->resource(); 409 Resource *resource = configItem->resource();
400 410
401 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 411 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
402 412
403 if ( dlg.exec() ) { 413 if ( dlg.exec() ) {
404 configItem->setText( 0, resource->resourceName() ); 414 configItem->setText( 0, resource->resourceName() );
405 configItem->setText( 1, resource->type() ); 415 configItem->setText( 1, resource->type() );
406 416
407 if ( configItem->standard() && configItem->readOnly() ) { 417 if ( configItem->standard() && configItem->readOnly() ) {
408 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); 418 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) );
409 configItem->setStandard( false ); 419 configItem->setStandard( false );
410 } 420 }
411 421
412 mCurrentManager->resourceChanged( resource ); 422 mCurrentManager->resourceChanged( resource );
413 emit changed( true ); 423 emit changed( true );
414 } 424 }
415} 425}
416 426
417void ConfigPage::slotStandard() 427void ConfigPage::slotStandard()
418{ 428{
419 if ( !mCurrentManager ) 429 if ( !mCurrentManager )
420 return; 430 return;
421 431
422 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); 432 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() );
423 if ( !item ) 433 if ( !item )
424 return; 434 return;
425 435
426 if ( item->readOnly() ) { 436 if ( item->readOnly() ) {
427 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); 437 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) );
428 return; 438 return;
429 } 439 }
430 440
431 if ( !item->isOn() ) { 441 if ( !item->isOn() ) {
432 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); 442 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) );
433 return; 443 return;
434 } 444 }
435 445
436 QListViewItem *it = mListView->firstChild(); 446 QListViewItem *it = mListView->firstChild();
437 while ( it != 0 ) { 447 while ( it != 0 ) {
438 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); 448 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it );
439 if ( configItem->standard() ) 449 if ( configItem->standard() )
440 configItem->setStandard( false ); 450 configItem->setStandard( false );
441 it = it->itemBelow(); 451 it = it->itemBelow();
442 } 452 }
443 453
444 item->setStandard( true ); 454 item->setStandard( true );
445 mCurrentManager->setStandardResource( item->resource() ); 455 mCurrentManager->setStandardResource( item->resource() );
446 emit changed( true ); 456 emit changed( true );
447 457
448} 458}
449 459
450void ConfigPage::slotSelectionChanged() 460void ConfigPage::slotSelectionChanged()
451{ 461{
452 bool state = ( mListView->currentItem() != 0 ); 462 bool state = ( mListView->currentItem() != 0 );
453 463
454 mRemoveButton->setEnabled( state ); 464 mRemoveButton->setEnabled( state );
455 mEditButton->setEnabled( state ); 465 mEditButton->setEnabled( state );
456 mStandardButton->setEnabled( state ); 466 mStandardButton->setEnabled( state );
457} 467}
458 468
459void ConfigPage::resourceAdded( Resource* resource ) 469void ConfigPage::resourceAdded( Resource* resource )
460{ 470{
461 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1()); 471 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1());
462 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl; 472 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl;
463 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 473 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
464 474
465 // FIXME: this sucks. This should be in the config file, 475 // FIXME: this sucks. This should be in the config file,
466 // or application-dependent, in which case it's always Off 476 // or application-dependent, in which case it's always Off
467 item->setOn( false ); 477 item->setOn( false );
468 478
469 mLastItem = item; 479 mLastItem = item;
470 480
471 emit changed( true ); 481 emit changed( true );
472} 482}
473 483
474void ConfigPage::resourceModified( Resource* resource ) 484void ConfigPage::resourceModified( Resource* resource )
475{ 485{
476 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1()); 486 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1());
477 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl; 487 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl;
478} 488}
479 489
480void ConfigPage::resourceDeleted( Resource* resource ) 490void ConfigPage::resourceDeleted( Resource* resource )
481{ 491{
482 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); 492 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1());
483 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl; 493 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl;
484} 494}
485 495
486void ConfigPage::slotItemClicked( QListViewItem *item ) 496void ConfigPage::slotItemClicked( QListViewItem *item )
487{ 497{
488 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); 498 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item );
489 if ( !configItem ) return; 499 if ( !configItem ) return;
490 500
491 if ( configItem->standard() && !configItem->isOn() ) { 501 if ( configItem->standard() && !configItem->isOn() ) {
492 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); 502 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) );
493 configItem->setOn( true ); 503 configItem->setOn( true );
494 return; 504 return;
495 } 505 }
496 506
497 if ( configItem->isOn() != configItem->resource()->isActive() ) { 507 if ( configItem->isOn() != configItem->resource()->isActive() ) {
498 emit changed( true ); 508 emit changed( true );
499 } 509 }
500} 510}
501 511
502void ConfigPage::saveResourceSettings() 512void ConfigPage::saveResourceSettings()
503{ 513{
504 qDebug("ConfigPage::saveResourceSettings() begin"); 514 qDebug("ConfigPage::saveResourceSettings() begin");
505 515
506 if ( mCurrentManager ) { 516 if ( mCurrentManager ) {
507 517
508 QListViewItem *item = mListView->firstChild(); 518 QListViewItem *item = mListView->firstChild();
509 while ( item ) { 519 while ( item ) {
510 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 520 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
511 521
512 // check if standard resource 522 // check if standard resource
513 if ( configItem->standard() && !configItem->readOnly() && 523 if ( configItem->standard() && !configItem->readOnly() &&
514 configItem->isOn() ) { 524 configItem->isOn() ) {
515 525
516 mCurrentManager->setStandardResource( configItem->resource() ); 526 mCurrentManager->setStandardResource( configItem->resource() );
517 } 527 }
518 528
519 // check if active or passive resource 529 // check if active or passive resource
520 configItem->resource()->setActive( configItem->isOn() ); 530 configItem->resource()->setActive( configItem->isOn() );
521 531
522 item = item->nextSibling(); 532 item = item->nextSibling();
523 } 533 }
524 mCurrentManager->writeConfig( mCurrentConfig ); 534 mCurrentManager->writeConfig( mCurrentConfig );
525 535
526 if ( !mCurrentManager->standardResource() ) 536 if ( !mCurrentManager->standardResource() )
527 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); 537 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) );
528 } 538 }
529 539
530 qDebug("ConfigPage::saveResourceSettings() end"); 540 qDebug("ConfigPage::saveResourceSettings() end");
531 541
532} 542}
533 543
534//US #include "configpage.moc" 544//US #include "configpage.moc"
535 545