-rw-r--r-- | microkde/kresources/configpage.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 0f1469d..8782ffd 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp | |||
@@ -1,385 +1,388 @@ | |||
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 | #include <qgroupbox.h> | 24 | #include <qgroupbox.h> |
25 | #include <qinputdialog.h> | 25 | #include <qinputdialog.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | 28 | ||
29 | #include <kapplication.h> | 29 | #include <kapplication.h> |
30 | #include <kcombobox.h> | 30 | #include <kcombobox.h> |
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kmessagebox.h> | 33 | #include <kmessagebox.h> |
34 | #include <ksimpleconfig.h> | 34 | #include <ksimpleconfig.h> |
35 | #include <kstandarddirs.h> | 35 | #include <kstandarddirs.h> |
36 | #include <kurlrequester.h> | 36 | #include <kurlrequester.h> |
37 | #include <klistview.h> | 37 | #include <klistview.h> |
38 | #include <kbuttonbox.h> | 38 | #include <kbuttonbox.h> |
39 | //US #include <ktrader.h> | 39 | //US #include <ktrader.h> |
40 | 40 | ||
41 | #include "resource.h" | 41 | #include "resource.h" |
42 | #include "configdialog.h" | 42 | #include "configdialog.h" |
43 | 43 | ||
44 | #include "configpage.h" | 44 | #include "configpage.h" |
45 | 45 | ||
46 | //US | 46 | //US |
47 | #include <qpushbutton.h> | 47 | #include <qpushbutton.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | #include <kglobal.h> | 49 | #include <kglobal.h> |
50 | 50 | ||
51 | using namespace KRES; | 51 | using namespace KRES; |
52 | 52 | ||
53 | class ConfigViewItem : public QCheckListItem | 53 | class ConfigViewItem : public QCheckListItem |
54 | { | 54 | { |
55 | public: | 55 | public: |
56 | ConfigViewItem( QListView *parent, Resource* resource ) : | 56 | ConfigViewItem( QListView *parent, Resource* resource ) : |
57 | QCheckListItem( parent, resource->resourceName(), CheckBox ), | 57 | QCheckListItem( parent, resource->resourceName(), CheckBox ), |
58 | mResource( resource ), | 58 | mResource( resource ), |
59 | mIsStandard( false ) | 59 | mIsStandard( false ) |
60 | { | 60 | { |
61 | setText( 1, mResource->type() ); | 61 | setText( 1, mResource->type() ); |
62 | setOn( mResource->isActive() ); | 62 | setOn( mResource->isActive() ); |
63 | } | 63 | } |
64 | 64 | ||
65 | void setStandard( bool value ) | 65 | void setStandard( bool value ) |
66 | { | 66 | { |
67 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); | 67 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); |
68 | mIsStandard = value; | 68 | mIsStandard = value; |
69 | } | 69 | } |
70 | 70 | ||
71 | bool standard() const { return mIsStandard; } | 71 | bool standard() const { return mIsStandard; } |
72 | bool readOnly() const { return mResource->readOnly(); } | 72 | bool readOnly() const { return mResource->readOnly(); } |
73 | 73 | ||
74 | Resource *resource() { return mResource; } | 74 | Resource *resource() { return mResource; } |
75 | 75 | ||
76 | private: | 76 | private: |
77 | Resource* mResource; | 77 | Resource* mResource; |
78 | 78 | ||
79 | bool mIsStandard; | 79 | bool mIsStandard; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) | 82 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) |
83 | : QWidget( parent, name ), | 83 | : QWidget( parent, name ), |
84 | mCurrentManager( 0 ), | 84 | mCurrentManager( 0 ), |
85 | mCurrentConfig( 0 ) | 85 | mCurrentConfig( 0 ) |
86 | { | 86 | { |
87 | setCaption( i18n( "Resource Configuration" ) ); | 87 | setCaption( i18n( "Resource Configuration" ) ); |
88 | 88 | ||
89 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); | 89 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); |
90 | 90 | ||
91 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); | 91 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); |
92 | groupBox->setColumnLayout(0, Qt::Vertical ); | 92 | groupBox->setColumnLayout(0, Qt::Vertical ); |
93 | groupBox->layout()->setSpacing( 6 ); | 93 | groupBox->layout()->setSpacing( 6 ); |
94 | groupBox->layout()->setMargin( 11 ); | 94 | groupBox->layout()->setMargin( 11 ); |
95 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 2, 2 ); | 95 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 2, 2 ); |
96 | 96 | ||
97 | //US mFamilyCombo = new KComboBox( false, groupBox ); | 97 | //US mFamilyCombo = new KComboBox( false, groupBox ); |
98 | mFamilyCombo = new KComboBox( groupBox ); | 98 | mFamilyCombo = new KComboBox( groupBox ); |
99 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); | 99 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); |
100 | 100 | ||
101 | mListView = new KListView( groupBox ); | 101 | mListView = new KListView( groupBox ); |
102 | mListView->setAllColumnsShowFocus( true ); | 102 | mListView->setAllColumnsShowFocus( true ); |
103 | mListView->addColumn( i18n( "Name" ) ); | 103 | mListView->addColumn( i18n( "Name" ) ); |
104 | mListView->addColumn( i18n( "Type" ) ); | 104 | mListView->addColumn( i18n( "Type" ) ); |
105 | mListView->addColumn( i18n( "Standard" ) ); | 105 | mListView->addColumn( i18n( "Standard" ) ); |
106 | 106 | ||
107 | groupBoxLayout->addWidget( mListView, 1, 0 ); | 107 | groupBoxLayout->addWidget( mListView, 1, 0 ); |
108 | 108 | ||
109 | KButtonBox *buttonBox = new KButtonBox( groupBox, Vertical ); | 109 | KButtonBox *buttonBox = new KButtonBox( groupBox, Vertical ); |
110 | mAddButton = buttonBox->addButton( i18n( "&Add..." ), this, SLOT(slotAdd()) ); | 110 | mAddButton = buttonBox->addButton( i18n( "&Add..." ), this, SLOT(slotAdd()) ); |
111 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT(slotRemove()) ); | 111 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT(slotRemove()) ); |
112 | mRemoveButton->setEnabled( false ); | 112 | mRemoveButton->setEnabled( false ); |
113 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT(slotEdit()) ); | 113 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT(slotEdit()) ); |
114 | mEditButton->setEnabled( false ); | 114 | mEditButton->setEnabled( false ); |
115 | mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), this, SLOT(slotStandard()) ); | 115 | mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), this, SLOT(slotStandard()) ); |
116 | mStandardButton->setEnabled( false ); | 116 | mStandardButton->setEnabled( false ); |
117 | buttonBox->layout(); | 117 | buttonBox->layout(); |
118 | 118 | ||
119 | groupBoxLayout->addWidget( buttonBox, 1, 1 ); | 119 | groupBoxLayout->addWidget( buttonBox, 1, 1 ); |
120 | 120 | ||
121 | mainLayout->addWidget( groupBox ); | 121 | mainLayout->addWidget( groupBox ); |
122 | 122 | ||
123 | connect( mFamilyCombo, SIGNAL( activated( int ) ), | 123 | connect( mFamilyCombo, SIGNAL( activated( int ) ), |
124 | SLOT( slotFamilyChanged( int ) ) ); | 124 | SLOT( slotFamilyChanged( int ) ) ); |
125 | connect( mListView, SIGNAL( selectionChanged() ), | 125 | connect( mListView, SIGNAL( selectionChanged() ), |
126 | SLOT( slotSelectionChanged() ) ); | 126 | SLOT( slotSelectionChanged() ) ); |
127 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), | 127 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), |
128 | SLOT( slotItemClicked( QListViewItem * ) ) ); | 128 | SLOT( slotItemClicked( QListViewItem * ) ) ); |
129 | 129 | ||
130 | mLastItem = 0; | 130 | mLastItem = 0; |
131 | 131 | ||
132 | //US mConfig = new KConfig( "kcmkresourcesrc" ); | 132 | //US mConfig = new KConfig( "kcmkresourcesrc" ); |
133 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); | 133 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); |
134 | mConfig->setGroup( "General" ); | 134 | mConfig->setGroup( "General" ); |
135 | 135 | ||
136 | load(); | 136 | load(); |
137 | } | 137 | } |
138 | 138 | ||
139 | ConfigPage::~ConfigPage() | 139 | ConfigPage::~ConfigPage() |
140 | { | 140 | { |
141 | QValueList<ResourcePageInfo>::Iterator it; | 141 | QValueList<ResourcePageInfo>::Iterator it; |
142 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { | 142 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { |
143 | (*it).mManager->removeListener( this ); | 143 | (*it).mManager->removeListener( this ); |
144 | delete (*it).mManager; | 144 | delete (*it).mManager; |
145 | delete (*it).mConfig; | 145 | delete (*it).mConfig; |
146 | } | 146 | } |
147 | 147 | ||
148 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); | 148 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); |
149 | delete mConfig; | 149 | delete mConfig; |
150 | mConfig = 0; | 150 | mConfig = 0; |
151 | } | 151 | } |
152 | 152 | ||
153 | void ConfigPage::load() | 153 | void ConfigPage::load() |
154 | { | 154 | { |
155 | kdDebug(5650) << "ConfigPage::load()" << endl; | 155 | kdDebug(5650) << "ConfigPage::load()" << endl; |
156 | 156 | ||
157 | mListView->clear(); | 157 | mListView->clear(); |
158 | 158 | ||
159 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. | 159 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. |
160 | 160 | ||
161 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); | 161 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); |
162 | //US KTrader::OfferList::ConstIterator it; | 162 | //US KTrader::OfferList::ConstIterator it; |
163 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 163 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
164 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); | 164 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); |
165 | //US QString family = tmp.toString(); | 165 | //US QString family = tmp.toString(); |
166 | 166 | QStringList families; | |
167 | QString family = "contact"; | 167 | families << "contact" << "sync-contacts"; |
168 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) | ||
169 | { | ||
170 | QString family = (*it); | ||
168 | if ( !family.isEmpty() ) { | 171 | if ( !family.isEmpty() ) { |
169 | if ( !mFamilyMap.contains( family ) ) { | 172 | if ( !mFamilyMap.contains( family ) ) { |
170 | mCurrentManager = new Manager<Resource>( family ); | 173 | mCurrentManager = new Manager<Resource>( family ); |
171 | if ( mCurrentManager ) { | 174 | if ( mCurrentManager ) { |
172 | mFamilyMap.append( family ); | 175 | mFamilyMap.append( family ); |
173 | mCurrentManager->addListener( this ); | 176 | mCurrentManager->addListener( this ); |
174 | 177 | ||
175 | ResourcePageInfo info; | 178 | ResourcePageInfo info; |
176 | info.mManager = mCurrentManager; | 179 | info.mManager = mCurrentManager; |
177 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); | 180 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); |
178 | //QString configDir = KStandardDirs::appDir() + "/config"; | 181 | //QString configDir = KStandardDirs::appDir() + "/config"; |
179 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { | 182 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { |
180 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); | 183 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); |
181 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { | 184 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { |
182 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); | 185 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); |
183 | } else { | 186 | } else { |
184 | QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); | 187 | QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); |
185 | info.mConfig = new KConfig( configFile ); | 188 | info.mConfig = new KConfig( configFile ); |
186 | } | 189 | } |
187 | info.mManager->readConfig( info.mConfig ); | 190 | info.mManager->readConfig( info.mConfig ); |
188 | 191 | ||
189 | mInfoMap.append( info ); | 192 | mInfoMap.append( info ); |
190 | } | 193 | } |
191 | } | 194 | } |
192 | } | 195 | } |
193 | //US } | 196 | } |
194 | mCurrentManager = 0; | 197 | mCurrentManager = 0; |
195 | 198 | ||
196 | mFamilyCombo->insertStringList( mFamilyMap ); | 199 | mFamilyCombo->insertStringList( mFamilyMap ); |
197 | 200 | ||
198 | int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); | 201 | int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); |
199 | mFamilyCombo->setCurrentItem( currentFamily ); | 202 | mFamilyCombo->setCurrentItem( currentFamily ); |
200 | slotFamilyChanged( currentFamily ); | 203 | slotFamilyChanged( currentFamily ); |
201 | } | 204 | } |
202 | 205 | ||
203 | void ConfigPage::save() | 206 | void ConfigPage::save() |
204 | { | 207 | { |
205 | saveResourceSettings(); | 208 | saveResourceSettings(); |
206 | 209 | ||
207 | QValueList<ResourcePageInfo>::Iterator it; | 210 | QValueList<ResourcePageInfo>::Iterator it; |
208 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) | 211 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) |
209 | (*it).mManager->writeConfig( (*it).mConfig ); | 212 | (*it).mManager->writeConfig( (*it).mConfig ); |
210 | 213 | ||
211 | emit changed( false ); | 214 | emit changed( false ); |
212 | } | 215 | } |
213 | 216 | ||
214 | void ConfigPage::defaults() | 217 | void ConfigPage::defaults() |
215 | { | 218 | { |
216 | } | 219 | } |
217 | 220 | ||
218 | void ConfigPage::slotFamilyChanged( int pos ) | 221 | void ConfigPage::slotFamilyChanged( int pos ) |
219 | { | 222 | { |
220 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) | 223 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) |
221 | return; | 224 | return; |
222 | 225 | ||
223 | saveResourceSettings(); | 226 | saveResourceSettings(); |
224 | 227 | ||
225 | mFamily = mFamilyMap[ pos ]; | 228 | mFamily = mFamilyMap[ pos ]; |
226 | 229 | ||
227 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); | 230 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); |
228 | 231 | ||
229 | mCurrentManager = mInfoMap[ pos ].mManager; | 232 | mCurrentManager = mInfoMap[ pos ].mManager; |
230 | mCurrentConfig = mInfoMap[ pos ].mConfig; | 233 | mCurrentConfig = mInfoMap[ pos ].mConfig; |
231 | 234 | ||
232 | if ( !mCurrentManager ) | 235 | if ( !mCurrentManager ) |
233 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; | 236 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; |
234 | 237 | ||
235 | mListView->clear(); | 238 | mListView->clear(); |
236 | 239 | ||
237 | if ( mCurrentManager->isEmpty() ) { | 240 | if ( mCurrentManager->isEmpty() ) { |
238 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); | 241 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); |
239 | 242 | ||
240 | defaults(); | 243 | defaults(); |
241 | } | 244 | } |
242 | 245 | ||
243 | Resource *standardResource = mCurrentManager->standardResource(); | 246 | Resource *standardResource = mCurrentManager->standardResource(); |
244 | 247 | ||
245 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); | 248 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); |
246 | 249 | ||
247 | 250 | ||
248 | Manager<Resource>::Iterator it; | 251 | Manager<Resource>::Iterator it; |
249 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { | 252 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { |
250 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); | 253 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); |
251 | if ( *it == standardResource ) | 254 | if ( *it == standardResource ) |
252 | item->setStandard( true ); | 255 | item->setStandard( true ); |
253 | } | 256 | } |
254 | 257 | ||
255 | if ( mListView->childCount() == 0 ) { | 258 | if ( mListView->childCount() == 0 ) { |
256 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); | 259 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); |
257 | 260 | ||
258 | defaults(); | 261 | defaults(); |
259 | emit changed( true ); | 262 | emit changed( true ); |
260 | mCurrentManager->writeConfig( mCurrentConfig ); | 263 | mCurrentManager->writeConfig( mCurrentConfig ); |
261 | } else { | 264 | } else { |
262 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); | 265 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); |
263 | 266 | ||
264 | if ( !standardResource ) { | 267 | if ( !standardResource ) { |
265 | KMessageBox::sorry( this, i18n( "There is no standard resource! Please select one." ) ); | 268 | KMessageBox::sorry( this, i18n( "There is no standard resource! Please select one." ) ); |
266 | 269 | ||
267 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); | 270 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); |
268 | 271 | ||
269 | } | 272 | } |
270 | 273 | ||
271 | emit changed( false ); | 274 | emit changed( false ); |
272 | } | 275 | } |
273 | } | 276 | } |
274 | 277 | ||
275 | void ConfigPage::slotAdd() | 278 | void ConfigPage::slotAdd() |
276 | { | 279 | { |
277 | if ( !mCurrentManager ) | 280 | if ( !mCurrentManager ) |
278 | return; | 281 | return; |
279 | 282 | ||
280 | QStringList types = mCurrentManager->resourceTypeNames(); | 283 | QStringList types = mCurrentManager->resourceTypeNames(); |
281 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); | 284 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); |
282 | bool ok = false; | 285 | bool ok = false; |
283 | QString desc = QInputDialog::getItem( i18n( "Resource Configuration" ), | 286 | QString desc = QInputDialog::getItem( i18n( "Resource Configuration" ), |
284 | i18n( "Please select type of the new resource:" ), descs, 0, | 287 | i18n( "Please select type of the new resource:" ), descs, 0, |
285 | false, &ok, this ); | 288 | false, &ok, this ); |
286 | if ( !ok ) | 289 | if ( !ok ) |
287 | return; | 290 | return; |
288 | 291 | ||
289 | QString type = types[ descs.findIndex( desc ) ]; | 292 | QString type = types[ descs.findIndex( desc ) ]; |
290 | 293 | ||
291 | // Create new resource | 294 | // Create new resource |
292 | Resource *resource = mCurrentManager->createResource( type ); | 295 | Resource *resource = mCurrentManager->createResource( type ); |
293 | if ( !resource ) { | 296 | if ( !resource ) { |
294 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") | 297 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") |
295 | .arg( type ) ); | 298 | .arg( type ) ); |
296 | return; | 299 | return; |
297 | } | 300 | } |
298 | 301 | ||
299 | resource->setResourceName( type + "-resource" ); | 302 | resource->setResourceName( type + "-resource" ); |
300 | 303 | ||
301 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); | 304 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); |
302 | 305 | ||
303 | if ( dlg.exec() ) { | 306 | if ( dlg.exec() ) { |
304 | mCurrentManager->add( resource ); | 307 | mCurrentManager->add( resource ); |
305 | 308 | ||
306 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); | 309 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); |
307 | 310 | ||
308 | mLastItem = item; | 311 | mLastItem = item; |
309 | 312 | ||
310 | // if there are only read-only resources we'll set this resource | 313 | // if there are only read-only resources we'll set this resource |
311 | // as standard resource | 314 | // as standard resource |
312 | if ( !resource->readOnly() ) { | 315 | if ( !resource->readOnly() ) { |
313 | bool onlyReadOnly = true; | 316 | bool onlyReadOnly = true; |
314 | QListViewItem *it = mListView->firstChild(); | 317 | QListViewItem *it = mListView->firstChild(); |
315 | while ( it != 0 ) { | 318 | while ( it != 0 ) { |
316 | ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); | 319 | ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); |
317 | if ( !confIt->readOnly() && confIt != item ) | 320 | if ( !confIt->readOnly() && confIt != item ) |
318 | onlyReadOnly = false; | 321 | onlyReadOnly = false; |
319 | 322 | ||
320 | it = it->itemBelow(); | 323 | it = it->itemBelow(); |
321 | } | 324 | } |
322 | 325 | ||
323 | if ( onlyReadOnly ) | 326 | if ( onlyReadOnly ) |
324 | item->setStandard( true ); | 327 | item->setStandard( true ); |
325 | } | 328 | } |
326 | 329 | ||
327 | emit changed( true ); | 330 | emit changed( true ); |
328 | } else { | 331 | } else { |
329 | delete resource; | 332 | delete resource; |
330 | resource = 0; | 333 | resource = 0; |
331 | } | 334 | } |
332 | } | 335 | } |
333 | 336 | ||
334 | void ConfigPage::slotRemove() | 337 | void ConfigPage::slotRemove() |
335 | { | 338 | { |
336 | if ( !mCurrentManager ) | 339 | if ( !mCurrentManager ) |
337 | return; | 340 | return; |
338 | 341 | ||
339 | QListViewItem *item = mListView->currentItem(); | 342 | QListViewItem *item = mListView->currentItem(); |
340 | ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); | 343 | ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); |
341 | 344 | ||
342 | if ( !confItem ) | 345 | if ( !confItem ) |
343 | return; | 346 | return; |
344 | 347 | ||
345 | if ( confItem->standard() ) { | 348 | if ( confItem->standard() ) { |
346 | KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); | 349 | KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); |
347 | return; | 350 | return; |
348 | } | 351 | } |
349 | 352 | ||
350 | mCurrentManager->remove( confItem->resource() ); | 353 | mCurrentManager->remove( confItem->resource() ); |
351 | 354 | ||
352 | if ( item == mLastItem ) | 355 | if ( item == mLastItem ) |
353 | mLastItem = 0; | 356 | mLastItem = 0; |
354 | 357 | ||
355 | mListView->takeItem( item ); | 358 | mListView->takeItem( item ); |
356 | delete item; | 359 | delete item; |
357 | 360 | ||
358 | emit changed( true ); | 361 | emit changed( true ); |
359 | } | 362 | } |
360 | 363 | ||
361 | void ConfigPage::slotEdit() | 364 | void ConfigPage::slotEdit() |
362 | { | 365 | { |
363 | if ( !mCurrentManager ) | 366 | if ( !mCurrentManager ) |
364 | return; | 367 | return; |
365 | 368 | ||
366 | QListViewItem *item = mListView->currentItem(); | 369 | QListViewItem *item = mListView->currentItem(); |
367 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); | 370 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); |
368 | if ( !configItem ) | 371 | if ( !configItem ) |
369 | return; | 372 | return; |
370 | 373 | ||
371 | Resource *resource = configItem->resource(); | 374 | Resource *resource = configItem->resource(); |
372 | 375 | ||
373 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); | 376 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); |
374 | 377 | ||
375 | if ( dlg.exec() ) { | 378 | if ( dlg.exec() ) { |
376 | configItem->setText( 0, resource->resourceName() ); | 379 | configItem->setText( 0, resource->resourceName() ); |
377 | configItem->setText( 1, resource->type() ); | 380 | configItem->setText( 1, resource->type() ); |
378 | 381 | ||
379 | if ( configItem->standard() && configItem->readOnly() ) { | 382 | if ( configItem->standard() && configItem->readOnly() ) { |
380 | KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); | 383 | KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); |
381 | configItem->setStandard( false ); | 384 | configItem->setStandard( false ); |
382 | } | 385 | } |
383 | 386 | ||
384 | mCurrentManager->resourceChanged( resource ); | 387 | mCurrentManager->resourceChanged( resource ); |
385 | emit changed( true ); | 388 | emit changed( true ); |