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