-rw-r--r-- | microkde/kresources/configpage.cpp | 28 |
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 | |||
@@ -9,217 +9,227 @@ | |||
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 <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 | ||
58 | using namespace KRES; | 58 | using namespace KRES; |
59 | 59 | ||
60 | const QString ConfigPage::syncfamily = "syncprofiles"; | 60 | const QString ConfigPage::syncfamily = "syncprofiles"; |
61 | 61 | ||
62 | 62 | ||
63 | class ConfigViewItem : public QCheckListItem | 63 | class 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 | ||
92 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) | 92 | ConfigPage::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 | ||
149 | ConfigPage::~ConfigPage() | 159 | ConfigPage::~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 | ||
163 | void ConfigPage::load() | 173 | void 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 | ||
218 | void ConfigPage::save() | 228 | void 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 | ||