-rw-r--r-- | microkde/kconfig.cpp | 4 | ||||
-rw-r--r-- | microkde/kdecore/kstandarddirs.cpp | 2 | ||||
-rw-r--r-- | microkde/kdeui/kactioncollection.cpp | 5 | ||||
-rw-r--r-- | microkde/kdeui/klistview.cpp | 2 |
4 files changed, 7 insertions, 6 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index ba41f6c..5b685d3 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp | |||
@@ -1,547 +1,547 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include <qwidget.h> | 3 | #include <qwidget.h> |
4 | 4 | ||
5 | #include "kdebug.h" | 5 | #include "kdebug.h" |
6 | 6 | ||
7 | #include "kurl.h" | 7 | #include "kurl.h" |
8 | #include "kstandarddirs.h" | 8 | #include "kstandarddirs.h" |
9 | #include "kconfig.h" | 9 | #include "kconfig.h" |
10 | 10 | ||
11 | QString KConfig::mGroup = ""; | 11 | QString KConfig::mGroup = ""; |
12 | //QString KConfig::mGroup = "General"; | 12 | //QString KConfig::mGroup = "General"; |
13 | 13 | ||
14 | KConfig::KConfig( const QString &fileName ) | 14 | KConfig::KConfig( const QString &fileName ) |
15 | : mFileName( fileName ), mDirty( false ) | 15 | : mFileName( fileName ), mDirty( false ) |
16 | { | 16 | { |
17 | 17 | ||
18 | mTempGroup = ""; | 18 | mTempGroup = ""; |
19 | load(); | 19 | load(); |
20 | 20 | ||
21 | } | 21 | } |
22 | 22 | ||
23 | 23 | ||
24 | KConfig::~KConfig() | 24 | KConfig::~KConfig() |
25 | { | 25 | { |
26 | sync(); | 26 | sync(); |
27 | } | 27 | } |
28 | // we need the temp group for plugins on windows | 28 | // we need the temp group for plugins on windows |
29 | void KConfig::setTempGroup( const QString &group ) | 29 | void KConfig::setTempGroup( const QString &group ) |
30 | { | 30 | { |
31 | mTempGroup = group; | 31 | mTempGroup = group; |
32 | 32 | ||
33 | if ( mTempGroup.right( 1 ) != "/" ) mTempGroup += "/"; | 33 | if ( mTempGroup.right( 1 ) != "/" ) mTempGroup += "/"; |
34 | } | 34 | } |
35 | 35 | ||
36 | 36 | ||
37 | QString KConfig::tempGroup() const { | 37 | QString KConfig::tempGroup() const { |
38 | return mTempGroup; | 38 | return mTempGroup; |
39 | } | 39 | } |
40 | 40 | ||
41 | void KConfig::setGroup( const QString &group ) | 41 | void KConfig::setGroup( const QString &group ) |
42 | { | 42 | { |
43 | 43 | ||
44 | 44 | ||
45 | mGroup = group; | 45 | mGroup = group; |
46 | 46 | ||
47 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; | 47 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; |
48 | } | 48 | } |
49 | 49 | ||
50 | //US | 50 | //US |
51 | QString KConfig::group() const { | 51 | QString KConfig::group() const { |
52 | return mGroup; | 52 | return mGroup; |
53 | } | 53 | } |
54 | 54 | ||
55 | //US added method | 55 | //US added method |
56 | QValueList<int> KConfig::readIntListEntry( const QString & key) | 56 | QValueList<int> KConfig::readIntListEntry( const QString & key) |
57 | { | 57 | { |
58 | // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); | 58 | // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); |
59 | 59 | ||
60 | QValueList<int> result; | 60 | QValueList<int> result; |
61 | 61 | ||
62 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); | 62 | QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); |
63 | 63 | ||
64 | if ( mit == mStringMap.end() ) { | 64 | if ( mit == mStringMap.end() ) { |
65 | return result; | 65 | return result; |
66 | } | 66 | } |
67 | 67 | ||
68 | QStringList valuesAsStrings = QStringList::split(":", *mit ); | 68 | QStringList valuesAsStrings = QStringList::split(":", *mit ); |
69 | bool ok = false; | 69 | bool ok = false; |
70 | bool ok2 = true; | 70 | bool ok2 = true; |
71 | int val; | 71 | int val; |
72 | 72 | ||
73 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { | 73 | for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { |
74 | val = (*sit).toInt(&ok); | 74 | val = (*sit).toInt(&ok); |
75 | result << val; | 75 | result << val; |
76 | if (ok == false) { | 76 | if (ok == false) { |
77 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); | 77 | qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); |
78 | ok2 = false; | 78 | ok2 = false; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | if (ok2 == false) | 82 | if (ok2 == false) |
83 | { | 83 | { |
84 | 84 | ||
85 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); | 85 | qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); |
86 | } | 86 | } |
87 | 87 | ||
88 | return result; | 88 | return result; |
89 | } | 89 | } |
90 | 90 | ||
91 | int KConfig::readNumEntry( const QString & key, int def ) | 91 | int KConfig::readNumEntry( const QString & key, int def ) |
92 | { | 92 | { |
93 | QString res = readEntry(key, QString::number(def ) ); | 93 | QString res = readEntry(key, QString::number(def ) ); |
94 | bool ok = false; | 94 | bool ok = false; |
95 | int result = res.toInt(&ok); | 95 | int result = res.toInt(&ok); |
96 | if ( ok ) | 96 | if ( ok ) |
97 | return result; | 97 | return result; |
98 | return def; | 98 | return def; |
99 | } | 99 | } |
100 | 100 | ||
101 | QString KConfig::readEntry( const QString &key, const QString &def ) | 101 | QString KConfig::readEntry( const QString &key, const QString &def ) |
102 | { | 102 | { |
103 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 103 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
104 | 104 | ||
105 | if ( it == mStringMap.end() ) { | 105 | if ( it == mStringMap.end() ) { |
106 | return def; | 106 | return def; |
107 | } | 107 | } |
108 | 108 | ||
109 | return *it; | 109 | return *it; |
110 | } | 110 | } |
111 | 111 | ||
112 | QSize KConfig::readSizeEntry( const QString &key, QSize* def ) | 112 | QSize KConfig::readSizeEntry( const QString &key, QSize* def ) |
113 | { | 113 | { |
114 | QValueList<int> intlist = readIntListEntry(key); | 114 | QValueList<int> intlist = readIntListEntry(key); |
115 | 115 | ||
116 | if (intlist.count() < 2) | 116 | if (intlist.count() < 2) |
117 | { | 117 | { |
118 | if (def) | 118 | if (def) |
119 | return *def; | 119 | return *def; |
120 | else | 120 | else |
121 | return QSize(); | 121 | return QSize(); |
122 | } | 122 | } |
123 | 123 | ||
124 | QSize ret; | 124 | QSize ret; |
125 | ret.setWidth(intlist[0]); | 125 | ret.setWidth(intlist[0]); |
126 | ret.setHeight(intlist[1]); | 126 | ret.setHeight(intlist[1]); |
127 | 127 | ||
128 | return ret; | 128 | return ret; |
129 | } | 129 | } |
130 | 130 | ||
131 | QStringList KConfig::readListEntry( const QString &key ) | 131 | QStringList KConfig::readListEntry( const QString &key ) |
132 | { | 132 | { |
133 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | 133 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); |
134 | 134 | ||
135 | if ( it == mStringMap.end() ) { | 135 | if ( it == mStringMap.end() ) { |
136 | return QStringList(); | 136 | return QStringList(); |
137 | } | 137 | } |
138 | return QStringList::split(":", *it ); | 138 | return QStringList::split(":", *it ); |
139 | 139 | ||
140 | } | 140 | } |
141 | 141 | ||
142 | bool KConfig::readBoolEntry( const QString &key, bool def ) | 142 | bool KConfig::readBoolEntry( const QString &key, bool def ) |
143 | { | 143 | { |
144 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | 144 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); |
145 | 145 | ||
146 | if ( it == mBoolMap.end() ) { | 146 | if ( it == mBoolMap.end() ) { |
147 | return def; | 147 | return def; |
148 | } | 148 | } |
149 | 149 | ||
150 | return *it; | 150 | return *it; |
151 | } | 151 | } |
152 | 152 | ||
153 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) | 153 | QColor KConfig::readColorEntry( const QString & e, QColor *def ) |
154 | { | 154 | { |
155 | 155 | ||
156 | QStringList l; | 156 | QStringList l; |
157 | l = readListEntry( e ); | 157 | l = readListEntry( e ); |
158 | if (l.count() != 3 ) { | 158 | if (l.count() != 3 ) { |
159 | if ( def ) | 159 | if ( def ) |
160 | return *def; | 160 | return *def; |
161 | else | 161 | else |
162 | return QColor(); | 162 | return QColor(); |
163 | } | 163 | } |
164 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); | 164 | QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); |
165 | return c; | 165 | return c; |
166 | } | 166 | } |
167 | 167 | ||
168 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) | 168 | QFont KConfig::readFontEntry( const QString & e, QFont *def ) |
169 | { | 169 | { |
170 | QStringList font = readListEntry( e ); | 170 | QStringList font = readListEntry( e ); |
171 | if ( font.isEmpty() ) | 171 | if ( font.isEmpty() ) |
172 | return *def; | 172 | return *def; |
173 | QFont f; | 173 | QFont f; |
174 | f.setFamily( font[0]); | 174 | f.setFamily( font[0]); |
175 | f.setBold ( font[1] == "bold"); | 175 | f.setBold ( font[1] == "bold"); |
176 | f.setPointSize ( font[2].toInt()); | 176 | f.setPointSize ( font[2].toInt()); |
177 | f.setItalic( font[3] == "italic" ); | 177 | f.setItalic( font[3] == "italic" ); |
178 | return f; | 178 | return f; |
179 | } | 179 | } |
180 | 180 | ||
181 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) | 181 | QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) |
182 | { | 182 | { |
183 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); | 183 | QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); |
184 | 184 | ||
185 | if ( it == mDateTimeMap.end() ) { | 185 | if ( it == mDateTimeMap.end() ) { |
186 | if ( def ) return *def; | 186 | if ( def ) return *def; |
187 | else return QDateTime(); | 187 | else return QDateTime(); |
188 | } | 188 | } |
189 | 189 | ||
190 | return *it; | 190 | return *it; |
191 | } | 191 | } |
192 | 192 | ||
193 | //US added method | 193 | //US added method |
194 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) | 194 | void KConfig::writeEntry( const QString &key, const QValueList<int> &value) |
195 | { | 195 | { |
196 | QStringList valuesAsStrings; | 196 | QStringList valuesAsStrings; |
197 | 197 | ||
198 | QValueList<int>::ConstIterator it; | 198 | QValueList<int>::ConstIterator it; |
199 | 199 | ||
200 | for( it = value.begin(); it != value.end(); ++it ) | 200 | for( it = value.begin(); it != value.end(); ++it ) |
201 | { | 201 | { |
202 | valuesAsStrings << QString::number(*it); | 202 | valuesAsStrings << QString::number(*it); |
203 | } | 203 | } |
204 | 204 | ||
205 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); | 205 | mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); |
206 | mDirty = true; | 206 | mDirty = true; |
207 | } | 207 | } |
208 | 208 | ||
209 | void KConfig::writeEntry( const QString & key , int num ) | 209 | void KConfig::writeEntry( const QString & key , int num ) |
210 | { | 210 | { |
211 | writeEntry( key, QString::number ( num ) ); | 211 | writeEntry( key, QString::number ( num ) ); |
212 | } | 212 | } |
213 | 213 | ||
214 | void KConfig::writeEntry( const QString &key, const QString &value ) | 214 | void KConfig::writeEntry( const QString &key, const QString &value ) |
215 | { | 215 | { |
216 | mStringMap.insert( mGroup + key, value ); | 216 | mStringMap.insert( mGroup + key, value ); |
217 | 217 | ||
218 | mDirty = true; | 218 | mDirty = true; |
219 | } | 219 | } |
220 | 220 | ||
221 | void KConfig::writeEntry( const QString &key, const QStringList &value ) | 221 | void KConfig::writeEntry( const QString &key, const QStringList &value ) |
222 | { | 222 | { |
223 | mStringMap.insert( mGroup + key, value.join(":") ); | 223 | mStringMap.insert( mGroup + key, value.join(":") ); |
224 | 224 | ||
225 | mDirty = true; | 225 | mDirty = true; |
226 | } | 226 | } |
227 | 227 | ||
228 | void KConfig::writeEntry( const QString &key, bool value) | 228 | void KConfig::writeEntry( const QString &key, bool value) |
229 | { | 229 | { |
230 | mBoolMap.insert( mGroup + key, value ); | 230 | mBoolMap.insert( mGroup + key, value ); |
231 | 231 | ||
232 | mDirty = true; | 232 | mDirty = true; |
233 | } | 233 | } |
234 | 234 | ||
235 | void KConfig::writeEntry( const QString & e, const QColor & c ) | 235 | void KConfig::writeEntry( const QString & e, const QColor & c ) |
236 | { | 236 | { |
237 | QStringList l; | 237 | QStringList l; |
238 | l.append( QString::number ( c.red() ) ); | 238 | l.append( QString::number ( c.red() ) ); |
239 | l.append( QString::number ( c.green() ) ); | 239 | l.append( QString::number ( c.green() ) ); |
240 | l.append( QString::number ( c.blue() ) ); | 240 | l.append( QString::number ( c.blue() ) ); |
241 | writeEntry( e, l ); | 241 | writeEntry( e, l ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void KConfig::writeEntry( const QString & e, const QSize & s ) | 244 | void KConfig::writeEntry( const QString & e, const QSize & s ) |
245 | { | 245 | { |
246 | QValueList<int> intlist; | 246 | QValueList<int> intlist; |
247 | intlist << s.width() << s.height(); | 247 | intlist << s.width() << s.height(); |
248 | writeEntry( e, intlist ); | 248 | writeEntry( e, intlist ); |
249 | } | 249 | } |
250 | 250 | ||
251 | void KConfig::writeEntry( const QString & e , const QFont & f ) | 251 | void KConfig::writeEntry( const QString & e , const QFont & f ) |
252 | { | 252 | { |
253 | QStringList font; | 253 | QStringList font; |
254 | font.append( f.family()); | 254 | font.append( f.family()); |
255 | font.append( (!f.bold ()?"nonbold":"bold") ); | 255 | font.append( (!f.bold ()?"nonbold":"bold") ); |
256 | font.append( QString::number ( f.pointSize () ) ); | 256 | font.append( QString::number ( f.pointSize () ) ); |
257 | font.append( !f.italic ()?"nonitalic":"italic" ); | 257 | font.append( !f.italic ()?"nonitalic":"italic" ); |
258 | writeEntry( e, font ); | 258 | writeEntry( e, font ); |
259 | } | 259 | } |
260 | 260 | ||
261 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) | 261 | void KConfig::writeEntry( const QString &key, const QDateTime &dt ) |
262 | { | 262 | { |
263 | mDateTimeMap.insert( mGroup + key, dt ); | 263 | mDateTimeMap.insert( mGroup + key, dt ); |
264 | } | 264 | } |
265 | 265 | ||
266 | void KConfig::load() | 266 | void KConfig::load() |
267 | { | 267 | { |
268 | 268 | ||
269 | 269 | ||
270 | QFile f( mFileName ); | 270 | QFile f( mFileName ); |
271 | if ( !f.open( IO_ReadOnly ) ) { | 271 | if ( !f.open( IO_ReadOnly ) ) { |
272 | qDebug("KConfig: could not open file %s ",mFileName.latin1() ); | 272 | //qDebug("KConfig: could not open file %s ",mFileName.latin1() ); |
273 | return; | 273 | return; |
274 | } | 274 | } |
275 | 275 | ||
276 | mBoolMap.clear(); | 276 | mBoolMap.clear(); |
277 | mStringMap.clear(); | 277 | mStringMap.clear(); |
278 | 278 | ||
279 | QTextStream t( &f ); | 279 | QTextStream t( &f ); |
280 | 280 | ||
281 | QString line = t.readLine(); | 281 | QString line = t.readLine(); |
282 | 282 | ||
283 | while ( !line.isNull() ) { | 283 | while ( !line.isNull() ) { |
284 | QStringList tokens = QStringList::split( ",", line ); | 284 | QStringList tokens = QStringList::split( ",", line ); |
285 | if ( tokens[0] == "bool" ) { | 285 | if ( tokens[0] == "bool" ) { |
286 | bool value = false; | 286 | bool value = false; |
287 | if ( tokens[2] == "1" ) value = true; | 287 | if ( tokens[2] == "1" ) value = true; |
288 | mBoolMap.insert( tokens[1], value ); | 288 | mBoolMap.insert( tokens[1], value ); |
289 | } else if ( tokens[0] == "QString" ) { | 289 | } else if ( tokens[0] == "QString" ) { |
290 | QString value = tokens[2]; | 290 | QString value = tokens[2]; |
291 | mStringMap.insert( tokens[1], value ); | 291 | mStringMap.insert( tokens[1], value ); |
292 | } else if ( tokens[0] == "QDateTime" ) { | 292 | } else if ( tokens[0] == "QDateTime" ) { |
293 | #if 0 | 293 | #if 0 |
294 | int year = tokens[2].toInt(); | 294 | int year = tokens[2].toInt(); |
295 | QDateTime dt( QDate( year, | 295 | QDateTime dt( QDate( year, |
296 | tokens[3].toInt(), | 296 | tokens[3].toInt(), |
297 | tokens[4].toInt() ), | 297 | tokens[4].toInt() ), |
298 | QTime( tokens[5].toInt(), tokens[6].toInt(), | 298 | QTime( tokens[5].toInt(), tokens[6].toInt(), |
299 | tokens[7].toInt() ) ); | 299 | tokens[7].toInt() ) ); |
300 | mDateTimeMap.insert( tokens[1], dt ); | 300 | mDateTimeMap.insert( tokens[1], dt ); |
301 | #endif | 301 | #endif |
302 | } | 302 | } |
303 | 303 | ||
304 | line = t.readLine(); | 304 | line = t.readLine(); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | void KConfig::sync() | 308 | void KConfig::sync() |
309 | { | 309 | { |
310 | 310 | ||
311 | if ( !mDirty ) return; | 311 | if ( !mDirty ) return; |
312 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); | 312 | //qDebug("KConfig::sync() %s ",mFileName.latin1() ); |
313 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; | 313 | //kdDebug() << "KConfig::sync(): " << mFileName << endl; |
314 | 314 | ||
315 | //US I took the following code from a newer version of KDE | 315 | //US I took the following code from a newer version of KDE |
316 | // Create the containing dir if needed | 316 | // Create the containing dir if needed |
317 | KURL path; | 317 | KURL path; |
318 | path.setPath(mFileName); | 318 | path.setPath(mFileName); |
319 | QString dir=path.directory(); | 319 | QString dir=path.directory(); |
320 | KStandardDirs::makeDir(dir); | 320 | KStandardDirs::makeDir(dir); |
321 | 321 | ||
322 | QFile f( mFileName ); | 322 | QFile f( mFileName ); |
323 | if ( !f.open( IO_WriteOnly ) ) { | 323 | if ( !f.open( IO_WriteOnly ) ) { |
324 | 324 | ||
325 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); | 325 | qDebug("KConfig::sync() Can't open file %s ",mFileName.latin1() ); |
326 | 326 | ||
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | 329 | ||
330 | QTextStream t( &f ); | 330 | QTextStream t( &f ); |
331 | 331 | ||
332 | QMap<QString,bool>::ConstIterator itBool; | 332 | QMap<QString,bool>::ConstIterator itBool; |
333 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { | 333 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { |
334 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; | 334 | t << "bool," << itBool.key() << "," << ( *itBool ? "1" : "0" ) << endl; |
335 | } | 335 | } |
336 | 336 | ||
337 | QMap<QString,QString>::ConstIterator itString; | 337 | QMap<QString,QString>::ConstIterator itString; |
338 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { | 338 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { |
339 | t << "QString," << itString.key() << "," << (*itString ) << endl; | 339 | t << "QString," << itString.key() << "," << (*itString ) << endl; |
340 | } | 340 | } |
341 | 341 | ||
342 | QMap<QString,QDateTime>::ConstIterator itDateTime; | 342 | QMap<QString,QDateTime>::ConstIterator itDateTime; |
343 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { | 343 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) { |
344 | QDateTime dt = *itDateTime; | 344 | QDateTime dt = *itDateTime; |
345 | t << "QDateTime," << itDateTime.key() << "," | 345 | t << "QDateTime," << itDateTime.key() << "," |
346 | << dt.date().year() << "," | 346 | << dt.date().year() << "," |
347 | << dt.date().month() << "," | 347 | << dt.date().month() << "," |
348 | << dt.date().day() << "," | 348 | << dt.date().day() << "," |
349 | << dt.time().hour() << "," | 349 | << dt.time().hour() << "," |
350 | << dt.time().minute() << "," | 350 | << dt.time().minute() << "," |
351 | << dt.time().second() << endl; | 351 | << dt.time().second() << endl; |
352 | } | 352 | } |
353 | 353 | ||
354 | f.close(); | 354 | f.close(); |
355 | 355 | ||
356 | mDirty = false; | 356 | mDirty = false; |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | //US I took the following deleteGroup method from a newer version from KDE. | 360 | //US I took the following deleteGroup method from a newer version from KDE. |
361 | /** | 361 | /** |
362 | * Deletes a configuration entry group | 362 | * Deletes a configuration entry group |
363 | * | 363 | * |
364 | * If the group is not empty and bDeep is false, nothing gets | 364 | * If the group is not empty and bDeep is false, nothing gets |
365 | * deleted and false is returned. | 365 | * deleted and false is returned. |
366 | * If this group is the current group and it is deleted, the | 366 | * If this group is the current group and it is deleted, the |
367 | * current group is undefined and should be set with setGroup() | 367 | * current group is undefined and should be set with setGroup() |
368 | * before the next operation on the configuration object. | 368 | * before the next operation on the configuration object. |
369 | * | 369 | * |
370 | * @param group The name of the group | 370 | * @param group The name of the group |
371 | * returns true if we deleted at least one entry. | 371 | * returns true if we deleted at least one entry. |
372 | */ | 372 | */ |
373 | bool KConfig::deleteGroup( const QString& group) | 373 | bool KConfig::deleteGroup( const QString& group) |
374 | { | 374 | { |
375 | bool dirty = false; | 375 | bool dirty = false; |
376 | int pos; | 376 | int pos; |
377 | 377 | ||
378 | QMap<QString,bool>::Iterator itBool = mBoolMap.begin(); | 378 | QMap<QString,bool>::Iterator itBool = mBoolMap.begin(); |
379 | QMap<QString,bool>::Iterator delBool; | 379 | QMap<QString,bool>::Iterator delBool; |
380 | 380 | ||
381 | while ( itBool != mBoolMap.end() ) { | 381 | while ( itBool != mBoolMap.end() ) { |
382 | pos = itBool.key().find( group ); | 382 | pos = itBool.key().find( group ); |
383 | if (pos == 0) { | 383 | if (pos == 0) { |
384 | delBool = itBool; | 384 | delBool = itBool; |
385 | ++itBool; | 385 | ++itBool; |
386 | mBoolMap.remove(delBool); | 386 | mBoolMap.remove(delBool); |
387 | dirty = true; | 387 | dirty = true; |
388 | } else | 388 | } else |
389 | ++itBool; | 389 | ++itBool; |
390 | 390 | ||
391 | } | 391 | } |
392 | /* | 392 | /* |
393 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 393 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
394 | { | 394 | { |
395 | pos = itBool.key().find( group ); | 395 | pos = itBool.key().find( group ); |
396 | if (pos == 0) { | 396 | if (pos == 0) { |
397 | mBoolMap.remove(itBool); | 397 | mBoolMap.remove(itBool); |
398 | dirty = true; | 398 | dirty = true; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | */ | 401 | */ |
402 | QMap<QString,QString>::Iterator itString = mStringMap.begin(); | 402 | QMap<QString,QString>::Iterator itString = mStringMap.begin(); |
403 | QMap<QString,QString>::Iterator delString ; | 403 | QMap<QString,QString>::Iterator delString ; |
404 | while( itString != mStringMap.end() ) { | 404 | while( itString != mStringMap.end() ) { |
405 | pos = itString.key().find( group ); | 405 | pos = itString.key().find( group ); |
406 | if (pos == 0) { | 406 | if (pos == 0) { |
407 | delString = itString; | 407 | delString = itString; |
408 | ++itString; | 408 | ++itString; |
409 | mStringMap.remove(delString); | 409 | mStringMap.remove(delString); |
410 | //qDebug("delte++++++++++++++++++ "); | 410 | //qDebug("delte++++++++++++++++++ "); |
411 | dirty = true; | 411 | dirty = true; |
412 | } else | 412 | } else |
413 | ++itString; | 413 | ++itString; |
414 | 414 | ||
415 | } | 415 | } |
416 | /* this leads to a memory access violation | 416 | /* this leads to a memory access violation |
417 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 417 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
418 | { | 418 | { |
419 | pos = itString.key().find( group ); | 419 | pos = itString.key().find( group ); |
420 | if (pos == 0) { | 420 | if (pos == 0) { |
421 | mStringMap.remove(itString); | 421 | mStringMap.remove(itString); |
422 | dirty = true; | 422 | dirty = true; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | */ | 425 | */ |
426 | QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); | 426 | QMap<QString,QDateTime>::Iterator itDateTime= mDateTimeMap.begin(); |
427 | QMap<QString,QDateTime>::Iterator delDateTime; | 427 | QMap<QString,QDateTime>::Iterator delDateTime; |
428 | while ( itDateTime != mDateTimeMap.end() ) { | 428 | while ( itDateTime != mDateTimeMap.end() ) { |
429 | pos = itDateTime.key().find( group ); | 429 | pos = itDateTime.key().find( group ); |
430 | if (pos == 0) { | 430 | if (pos == 0) { |
431 | delDateTime = itDateTime; | 431 | delDateTime = itDateTime; |
432 | ++itDateTime; | 432 | ++itDateTime; |
433 | mDateTimeMap.remove(delDateTime); | 433 | mDateTimeMap.remove(delDateTime); |
434 | dirty = true; | 434 | dirty = true; |
435 | } else | 435 | } else |
436 | ++itDateTime; | 436 | ++itDateTime; |
437 | 437 | ||
438 | } | 438 | } |
439 | /* | 439 | /* |
440 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 440 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
441 | { | 441 | { |
442 | pos = itDateTime.key().find( group ); | 442 | pos = itDateTime.key().find( group ); |
443 | if (pos == 0) { | 443 | if (pos == 0) { |
444 | mDateTimeMap.remove(itDateTime); | 444 | mDateTimeMap.remove(itDateTime); |
445 | dirty = true; | 445 | dirty = true; |
446 | } | 446 | } |
447 | } | 447 | } |
448 | */ | 448 | */ |
449 | 449 | ||
450 | if (dirty) | 450 | if (dirty) |
451 | mDirty = true; | 451 | mDirty = true; |
452 | 452 | ||
453 | return dirty; | 453 | return dirty; |
454 | 454 | ||
455 | } | 455 | } |
456 | 456 | ||
457 | //US I took the following hasGroup method from a newer version from KDE. | 457 | //US I took the following hasGroup method from a newer version from KDE. |
458 | /** | 458 | /** |
459 | * Returns true if the specified group is known about. | 459 | * Returns true if the specified group is known about. |
460 | * | 460 | * |
461 | * @param group The group to search for. | 461 | * @param group The group to search for. |
462 | * @return Whether the group exists. | 462 | * @return Whether the group exists. |
463 | */ | 463 | */ |
464 | bool KConfig::hasGroup(const QString &group) const | 464 | bool KConfig::hasGroup(const QString &group) const |
465 | { | 465 | { |
466 | QMap<QString,bool>::ConstIterator itBool; | 466 | QMap<QString,bool>::ConstIterator itBool; |
467 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) | 467 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) |
468 | { | 468 | { |
469 | if (itBool.key().find( group ) == 0) { | 469 | if (itBool.key().find( group ) == 0) { |
470 | return true; | 470 | return true; |
471 | } | 471 | } |
472 | } | 472 | } |
473 | 473 | ||
474 | QMap<QString,QString>::ConstIterator itString; | 474 | QMap<QString,QString>::ConstIterator itString; |
475 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) | 475 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) |
476 | { | 476 | { |
477 | if (itString.key().find( group ) == 0) { | 477 | if (itString.key().find( group ) == 0) { |
478 | return true; | 478 | return true; |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | QMap<QString,QDateTime>::ConstIterator itDateTime; | 482 | QMap<QString,QDateTime>::ConstIterator itDateTime; |
483 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) | 483 | for( itDateTime = mDateTimeMap.begin(); itDateTime != mDateTimeMap.end(); ++itDateTime ) |
484 | { | 484 | { |
485 | if (itDateTime.key().find( group ) == 0) { | 485 | if (itDateTime.key().find( group ) == 0) { |
486 | return true; | 486 | return true; |
487 | } | 487 | } |
488 | } | 488 | } |
489 | 489 | ||
490 | return false; | 490 | return false; |
491 | } | 491 | } |
492 | 492 | ||
493 | void KConfig::deleteEntry( const QString &key) | 493 | void KConfig::deleteEntry( const QString &key) |
494 | { | 494 | { |
495 | bool dirty = false; | 495 | bool dirty = false; |
496 | 496 | ||
497 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 497 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
498 | if ( itBool != mBoolMap.end() ) { | 498 | if ( itBool != mBoolMap.end() ) { |
499 | mBoolMap.remove(itBool); | 499 | mBoolMap.remove(itBool); |
500 | dirty = true; | 500 | dirty = true; |
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 504 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
505 | if ( itString != mStringMap.end() ) { | 505 | if ( itString != mStringMap.end() ) { |
506 | mStringMap.remove(itString); | 506 | mStringMap.remove(itString); |
507 | dirty = true; | 507 | dirty = true; |
508 | } | 508 | } |
509 | 509 | ||
510 | 510 | ||
511 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 511 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
512 | if ( itDateTime != mDateTimeMap.end() ) { | 512 | if ( itDateTime != mDateTimeMap.end() ) { |
513 | mDateTimeMap.remove(itDateTime); | 513 | mDateTimeMap.remove(itDateTime); |
514 | dirty = true; | 514 | dirty = true; |
515 | } | 515 | } |
516 | 516 | ||
517 | if (dirty) | 517 | if (dirty) |
518 | mDirty = true; | 518 | mDirty = true; |
519 | 519 | ||
520 | } | 520 | } |
521 | 521 | ||
522 | //US | 522 | //US |
523 | QString KConfig::getFileName() | 523 | QString KConfig::getFileName() |
524 | { | 524 | { |
525 | return mFileName; | 525 | return mFileName; |
526 | } | 526 | } |
527 | 527 | ||
528 | bool KConfig::hasKey( const QString &key) | 528 | bool KConfig::hasKey( const QString &key) |
529 | { | 529 | { |
530 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); | 530 | QMap<QString,bool>::Iterator itBool = mBoolMap.find( mGroup + key ); |
531 | if ( itBool != mBoolMap.end() ) { | 531 | if ( itBool != mBoolMap.end() ) { |
532 | return true; | 532 | return true; |
533 | } | 533 | } |
534 | 534 | ||
535 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); | 535 | QMap<QString,QString>::Iterator itString = mStringMap.find( mGroup + key ); |
536 | if ( itString != mStringMap.end() ) { | 536 | if ( itString != mStringMap.end() ) { |
537 | return true; | 537 | return true; |
538 | } | 538 | } |
539 | 539 | ||
540 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); | 540 | QMap<QString,QDateTime>::Iterator itDateTime = mDateTimeMap.find( mGroup + key ); |
541 | if ( itDateTime != mDateTimeMap.end() ) { | 541 | if ( itDateTime != mDateTimeMap.end() ) { |
542 | return true; | 542 | return true; |
543 | } | 543 | } |
544 | 544 | ||
545 | return false; | 545 | return false; |
546 | } | 546 | } |
547 | 547 | ||
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp index 1c3e0ae..4c03c15 100644 --- a/microkde/kdecore/kstandarddirs.cpp +++ b/microkde/kdecore/kstandarddirs.cpp | |||
@@ -1,1662 +1,1662 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> | 2 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> |
3 | Copyright (C) 1999 Stephan Kulow <coolo@kde.org> | 3 | Copyright (C) 1999 Stephan Kulow <coolo@kde.org> |
4 | Copyright (C) 1999 Waldo Bastian <bastian@kde.org> | 4 | Copyright (C) 1999 Waldo Bastian <bastian@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License version 2 as published by the Free Software Foundation. | 8 | License version 2 as published by the Free Software Foundation. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> | 22 | * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> |
23 | * Version:$Id$ | 23 | * Version:$Id$ |
24 | * Generated:Thu Mar 5 16:05:28 EST 1998 | 24 | * Generated:Thu Mar 5 16:05:28 EST 1998 |
25 | */ | 25 | */ |
26 | 26 | ||
27 | //US #include "config.h" | 27 | //US #include "config.h" |
28 | 28 | ||
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | #include <assert.h> | 30 | #include <assert.h> |
31 | //US#include <errno.h> | 31 | //US#include <errno.h> |
32 | //US #ifdef HAVE_SYS_STAT_H | 32 | //US #ifdef HAVE_SYS_STAT_H |
33 | //US #include <sys/stat.h> | 33 | //US #include <sys/stat.h> |
34 | //US #endif | 34 | //US #endif |
35 | //US#include <sys/types.h> | 35 | //US#include <sys/types.h> |
36 | //US#include <dirent.h> | 36 | //US#include <dirent.h> |
37 | //US#include <pwd.h> | 37 | //US#include <pwd.h> |
38 | 38 | ||
39 | #include <qregexp.h> | 39 | #include <qregexp.h> |
40 | #include <qasciidict.h> | 40 | #include <qasciidict.h> |
41 | #include <qdict.h> | 41 | #include <qdict.h> |
42 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qfileinfo.h> | 43 | #include <qfileinfo.h> |
44 | #include <qstring.h> | 44 | #include <qstring.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qapplication.h> | 46 | #include <qapplication.h> |
47 | 47 | ||
48 | #include <qstringlist.h> | 48 | #include <qstringlist.h> |
49 | 49 | ||
50 | #include "kstandarddirs.h" | 50 | #include "kstandarddirs.h" |
51 | #include "kconfig.h" | 51 | #include "kconfig.h" |
52 | #include "kdebug.h" | 52 | #include "kdebug.h" |
53 | //US #include "kinstance.h" | 53 | //US #include "kinstance.h" |
54 | #include "kshell.h" | 54 | #include "kshell.h" |
55 | //US#include <sys/param.h> | 55 | //US#include <sys/param.h> |
56 | //US#include <unistd.h> | 56 | //US#include <unistd.h> |
57 | 57 | ||
58 | //US | 58 | //US |
59 | QString KStandardDirs::mAppDir = QString::null; | 59 | QString KStandardDirs::mAppDir = QString::null; |
60 | 60 | ||
61 | 61 | ||
62 | template class QDict<QStringList>; | 62 | template class QDict<QStringList>; |
63 | 63 | ||
64 | #if 0 | 64 | #if 0 |
65 | #include <qtextedit.h> | 65 | #include <qtextedit.h> |
66 | void ddd( QString op ) | 66 | void ddd( QString op ) |
67 | { | 67 | { |
68 | static QTextEdit * dot = 0; | 68 | static QTextEdit * dot = 0; |
69 | if ( ! dot ) | 69 | if ( ! dot ) |
70 | dot = new QTextEdit(); | 70 | dot = new QTextEdit(); |
71 | 71 | ||
72 | dot->show(); | 72 | dot->show(); |
73 | 73 | ||
74 | dot->append( op ); | 74 | dot->append( op ); |
75 | 75 | ||
76 | } | 76 | } |
77 | #endif | 77 | #endif |
78 | class KStandardDirs::KStandardDirsPrivate | 78 | class KStandardDirs::KStandardDirsPrivate |
79 | { | 79 | { |
80 | public: | 80 | public: |
81 | KStandardDirsPrivate() | 81 | KStandardDirsPrivate() |
82 | : restrictionsActive(false), | 82 | : restrictionsActive(false), |
83 | dataRestrictionActive(false) | 83 | dataRestrictionActive(false) |
84 | { } | 84 | { } |
85 | 85 | ||
86 | bool restrictionsActive; | 86 | bool restrictionsActive; |
87 | bool dataRestrictionActive; | 87 | bool dataRestrictionActive; |
88 | QAsciiDict<bool> restrictions; | 88 | QAsciiDict<bool> restrictions; |
89 | QStringList xdgdata_prefixes; | 89 | QStringList xdgdata_prefixes; |
90 | QStringList xdgconf_prefixes; | 90 | QStringList xdgconf_prefixes; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | static const char* const types[] = {"html", "icon", "apps", "sound", | 93 | static const char* const types[] = {"html", "icon", "apps", "sound", |
94 | "data", "locale", "services", "mime", | 94 | "data", "locale", "services", "mime", |
95 | "servicetypes", "config", "exe", "tmp", | 95 | "servicetypes", "config", "exe", "tmp", |
96 | "wallpaper", "lib", "pixmap", "templates", | 96 | "wallpaper", "lib", "pixmap", "templates", |
97 | "module", "qtplugins", | 97 | "module", "qtplugins", |
98 | "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; | 98 | "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; |
99 | 99 | ||
100 | static int tokenize( QStringList& token, const QString& str, | 100 | static int tokenize( QStringList& token, const QString& str, |
101 | const QString& delim ); | 101 | const QString& delim ); |
102 | 102 | ||
103 | KStandardDirs::KStandardDirs( ) : addedCustoms(false) | 103 | KStandardDirs::KStandardDirs( ) : addedCustoms(false) |
104 | { | 104 | { |
105 | d = new KStandardDirsPrivate; | 105 | d = new KStandardDirsPrivate; |
106 | dircache.setAutoDelete(true); | 106 | dircache.setAutoDelete(true); |
107 | relatives.setAutoDelete(true); | 107 | relatives.setAutoDelete(true); |
108 | absolutes.setAutoDelete(true); | 108 | absolutes.setAutoDelete(true); |
109 | savelocations.setAutoDelete(true); | 109 | savelocations.setAutoDelete(true); |
110 | addKDEDefaults(); | 110 | addKDEDefaults(); |
111 | } | 111 | } |
112 | 112 | ||
113 | KStandardDirs::~KStandardDirs() | 113 | KStandardDirs::~KStandardDirs() |
114 | { | 114 | { |
115 | delete d; | 115 | delete d; |
116 | } | 116 | } |
117 | 117 | ||
118 | bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const | 118 | bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const |
119 | { | 119 | { |
120 | if (!d || !d->restrictionsActive) | 120 | if (!d || !d->restrictionsActive) |
121 | return false; | 121 | return false; |
122 | 122 | ||
123 | if (d->restrictions[type]) | 123 | if (d->restrictions[type]) |
124 | return true; | 124 | return true; |
125 | 125 | ||
126 | if (strcmp(type, "data")==0) | 126 | if (strcmp(type, "data")==0) |
127 | { | 127 | { |
128 | applyDataRestrictions(relPath); | 128 | applyDataRestrictions(relPath); |
129 | if (d->dataRestrictionActive) | 129 | if (d->dataRestrictionActive) |
130 | { | 130 | { |
131 | d->dataRestrictionActive = false; | 131 | d->dataRestrictionActive = false; |
132 | return true; | 132 | return true; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | return false; | 135 | return false; |
136 | } | 136 | } |
137 | 137 | ||
138 | void KStandardDirs::applyDataRestrictions(const QString &relPath) const | 138 | void KStandardDirs::applyDataRestrictions(const QString &relPath) const |
139 | { | 139 | { |
140 | QString key; | 140 | QString key; |
141 | int i = relPath.find('/'); | 141 | int i = relPath.find('/'); |
142 | if (i != -1) | 142 | if (i != -1) |
143 | key = "data_"+relPath.left(i); | 143 | key = "data_"+relPath.left(i); |
144 | else | 144 | else |
145 | key = "data_"+relPath; | 145 | key = "data_"+relPath; |
146 | 146 | ||
147 | if (d && d->restrictions[key.latin1()]) | 147 | if (d && d->restrictions[key.latin1()]) |
148 | d->dataRestrictionActive = true; | 148 | d->dataRestrictionActive = true; |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | QStringList KStandardDirs::allTypes() const | 152 | QStringList KStandardDirs::allTypes() const |
153 | { | 153 | { |
154 | QStringList list; | 154 | QStringList list; |
155 | for (int i = 0; types[i] != 0; ++i) | 155 | for (int i = 0; types[i] != 0; ++i) |
156 | list.append(QString::fromLatin1(types[i])); | 156 | list.append(QString::fromLatin1(types[i])); |
157 | return list; | 157 | return list; |
158 | } | 158 | } |
159 | 159 | ||
160 | void KStandardDirs::addPrefix( const QString& _dir ) | 160 | void KStandardDirs::addPrefix( const QString& _dir ) |
161 | { | 161 | { |
162 | if (_dir.isNull()) | 162 | if (_dir.isNull()) |
163 | return; | 163 | return; |
164 | 164 | ||
165 | QString dir = _dir; | 165 | QString dir = _dir; |
166 | if (dir.at(dir.length() - 1) != '/') | 166 | if (dir.at(dir.length() - 1) != '/') |
167 | dir += '/'; | 167 | dir += '/'; |
168 | 168 | ||
169 | if (!prefixes.contains(dir)) { | 169 | if (!prefixes.contains(dir)) { |
170 | prefixes.append(dir); | 170 | prefixes.append(dir); |
171 | dircache.clear(); | 171 | dircache.clear(); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) | 175 | void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) |
176 | { | 176 | { |
177 | if (_dir.isNull()) | 177 | if (_dir.isNull()) |
178 | return; | 178 | return; |
179 | 179 | ||
180 | QString dir = _dir; | 180 | QString dir = _dir; |
181 | if (dir.at(dir.length() - 1) != '/') | 181 | if (dir.at(dir.length() - 1) != '/') |
182 | dir += '/'; | 182 | dir += '/'; |
183 | 183 | ||
184 | if (!d->xdgconf_prefixes.contains(dir)) { | 184 | if (!d->xdgconf_prefixes.contains(dir)) { |
185 | d->xdgconf_prefixes.append(dir); | 185 | d->xdgconf_prefixes.append(dir); |
186 | dircache.clear(); | 186 | dircache.clear(); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void KStandardDirs::addXdgDataPrefix( const QString& _dir ) | 190 | void KStandardDirs::addXdgDataPrefix( const QString& _dir ) |
191 | { | 191 | { |
192 | if (_dir.isNull()) | 192 | if (_dir.isNull()) |
193 | return; | 193 | return; |
194 | 194 | ||
195 | QString dir = _dir; | 195 | QString dir = _dir; |
196 | if (dir.at(dir.length() - 1) != '/') | 196 | if (dir.at(dir.length() - 1) != '/') |
197 | dir += '/'; | 197 | dir += '/'; |
198 | 198 | ||
199 | if (!d->xdgdata_prefixes.contains(dir)) { | 199 | if (!d->xdgdata_prefixes.contains(dir)) { |
200 | d->xdgdata_prefixes.append(dir); | 200 | d->xdgdata_prefixes.append(dir); |
201 | dircache.clear(); | 201 | dircache.clear(); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | QString KStandardDirs::kfsstnd_prefixes() | 206 | QString KStandardDirs::kfsstnd_prefixes() |
207 | { | 207 | { |
208 | return prefixes.join(":"); | 208 | return prefixes.join(":"); |
209 | } | 209 | } |
210 | 210 | ||
211 | bool KStandardDirs::addResourceType( const char *type, | 211 | bool KStandardDirs::addResourceType( const char *type, |
212 | const QString& relativename ) | 212 | const QString& relativename ) |
213 | { | 213 | { |
214 | if (relativename.isNull()) | 214 | if (relativename.isNull()) |
215 | return false; | 215 | return false; |
216 | 216 | ||
217 | QStringList *rels = relatives.find(type); | 217 | QStringList *rels = relatives.find(type); |
218 | if (!rels) { | 218 | if (!rels) { |
219 | rels = new QStringList(); | 219 | rels = new QStringList(); |
220 | relatives.insert(type, rels); | 220 | relatives.insert(type, rels); |
221 | } | 221 | } |
222 | QString copy = relativename; | 222 | QString copy = relativename; |
223 | if (copy.at(copy.length() - 1) != '/') | 223 | if (copy.at(copy.length() - 1) != '/') |
224 | copy += '/'; | 224 | copy += '/'; |
225 | if (!rels->contains(copy)) { | 225 | if (!rels->contains(copy)) { |
226 | rels->prepend(copy); | 226 | rels->prepend(copy); |
227 | dircache.remove(type); // clean the cache | 227 | dircache.remove(type); // clean the cache |
228 | return true; | 228 | return true; |
229 | } | 229 | } |
230 | return false; | 230 | return false; |
231 | } | 231 | } |
232 | 232 | ||
233 | bool KStandardDirs::addResourceDir( const char *type, | 233 | bool KStandardDirs::addResourceDir( const char *type, |
234 | const QString& absdir) | 234 | const QString& absdir) |
235 | { | 235 | { |
236 | QStringList *paths = absolutes.find(type); | 236 | QStringList *paths = absolutes.find(type); |
237 | if (!paths) { | 237 | if (!paths) { |
238 | paths = new QStringList(); | 238 | paths = new QStringList(); |
239 | absolutes.insert(type, paths); | 239 | absolutes.insert(type, paths); |
240 | } | 240 | } |
241 | QString copy = absdir; | 241 | QString copy = absdir; |
242 | if (copy.at(copy.length() - 1) != '/') | 242 | if (copy.at(copy.length() - 1) != '/') |
243 | copy += '/'; | 243 | copy += '/'; |
244 | 244 | ||
245 | if (!paths->contains(copy)) { | 245 | if (!paths->contains(copy)) { |
246 | paths->append(copy); | 246 | paths->append(copy); |
247 | dircache.remove(type); // clean the cache | 247 | dircache.remove(type); // clean the cache |
248 | return true; | 248 | return true; |
249 | } | 249 | } |
250 | return false; | 250 | return false; |
251 | } | 251 | } |
252 | 252 | ||
253 | QString KStandardDirs::findResource( const char *type, | 253 | QString KStandardDirs::findResource( const char *type, |
254 | const QString& filename ) const | 254 | const QString& filename ) const |
255 | { | 255 | { |
256 | if (filename.at(0) == '/') | 256 | if (filename.at(0) == '/') |
257 | return filename; // absolute dirs are absolute dirs, right? :-/ | 257 | return filename; // absolute dirs are absolute dirs, right? :-/ |
258 | 258 | ||
259 | #if 0 | 259 | #if 0 |
260 | kdDebug() << "Find resource: " << type << endl; | 260 | kdDebug() << "Find resource: " << type << endl; |
261 | for (QStringList::ConstIterator pit = prefixes.begin(); | 261 | for (QStringList::ConstIterator pit = prefixes.begin(); |
262 | pit != prefixes.end(); | 262 | pit != prefixes.end(); |
263 | pit++) | 263 | pit++) |
264 | { | 264 | { |
265 | kdDebug() << "Prefix: " << *pit << endl; | 265 | kdDebug() << "Prefix: " << *pit << endl; |
266 | } | 266 | } |
267 | #endif | 267 | #endif |
268 | 268 | ||
269 | QString dir = findResourceDir(type, filename); | 269 | QString dir = findResourceDir(type, filename); |
270 | if (dir.isNull()) | 270 | if (dir.isNull()) |
271 | return dir; | 271 | return dir; |
272 | else return dir + filename; | 272 | else return dir + filename; |
273 | } | 273 | } |
274 | /*US | 274 | /*US |
275 | static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) | 275 | static Q_UINT32 updateHash(const QString &file, Q_UINT32 hash) |
276 | { | 276 | { |
277 | QCString cFile = QFile::encodeName(file); | 277 | QCString cFile = QFile::encodeName(file); |
278 | //US struct stat buff; | 278 | //US struct stat buff; |
279 | //US if ((access(cFile, R_OK) == 0) && | 279 | //US if ((access(cFile, R_OK) == 0) && |
280 | //US (stat( cFile, &buff ) == 0) && | 280 | //US (stat( cFile, &buff ) == 0) && |
281 | //US (S_ISREG( buff.st_mode ))) | 281 | //US (S_ISREG( buff.st_mode ))) |
282 | QFileInfo pathfnInfo(cFile); | 282 | QFileInfo pathfnInfo(cFile); |
283 | if (( pathfnInfo.isReadable() == true ) && | 283 | if (( pathfnInfo.isReadable() == true ) && |
284 | ( pathfnInfo.isFile()) ) | 284 | ( pathfnInfo.isFile()) ) |
285 | { | 285 | { |
286 | //US hash = hash + (Q_UINT32) buff.st_ctime; | 286 | //US hash = hash + (Q_UINT32) buff.st_ctime; |
287 | hash = hash + (Q_UINT32) pathfnInfo.lastModified(); | 287 | hash = hash + (Q_UINT32) pathfnInfo.lastModified(); |
288 | } | 288 | } |
289 | return hash; | 289 | return hash; |
290 | } | 290 | } |
291 | */ | 291 | */ |
292 | /*US | 292 | /*US |
293 | Q_UINT32 KStandardDirs::calcResourceHash( const char *type, | 293 | Q_UINT32 KStandardDirs::calcResourceHash( const char *type, |
294 | const QString& filename, bool deep) const | 294 | const QString& filename, bool deep) const |
295 | { | 295 | { |
296 | Q_UINT32 hash = 0; | 296 | Q_UINT32 hash = 0; |
297 | 297 | ||
298 | if (filename.at(0) == '/') | 298 | if (filename.at(0) == '/') |
299 | { | 299 | { |
300 | // absolute dirs are absolute dirs, right? :-/ | 300 | // absolute dirs are absolute dirs, right? :-/ |
301 | return updateHash(filename, hash); | 301 | return updateHash(filename, hash); |
302 | } | 302 | } |
303 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) | 303 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) |
304 | applyDataRestrictions(filename); | 304 | applyDataRestrictions(filename); |
305 | QStringList candidates = resourceDirs(type); | 305 | QStringList candidates = resourceDirs(type); |
306 | QString fullPath; | 306 | QString fullPath; |
307 | 307 | ||
308 | for (QStringList::ConstIterator it = candidates.begin(); | 308 | for (QStringList::ConstIterator it = candidates.begin(); |
309 | it != candidates.end(); it++) | 309 | it != candidates.end(); it++) |
310 | { | 310 | { |
311 | hash = updateHash(*it + filename, hash); | 311 | hash = updateHash(*it + filename, hash); |
312 | if (!deep && hash) | 312 | if (!deep && hash) |
313 | return hash; | 313 | return hash; |
314 | } | 314 | } |
315 | return hash; | 315 | return hash; |
316 | } | 316 | } |
317 | */ | 317 | */ |
318 | 318 | ||
319 | QStringList KStandardDirs::findDirs( const char *type, | 319 | QStringList KStandardDirs::findDirs( const char *type, |
320 | const QString& reldir ) const | 320 | const QString& reldir ) const |
321 | { | 321 | { |
322 | QStringList list; | 322 | QStringList list; |
323 | 323 | ||
324 | checkConfig(); | 324 | checkConfig(); |
325 | 325 | ||
326 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) | 326 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) |
327 | applyDataRestrictions(reldir); | 327 | applyDataRestrictions(reldir); |
328 | QStringList candidates = resourceDirs(type); | 328 | QStringList candidates = resourceDirs(type); |
329 | QDir testdir; | 329 | QDir testdir; |
330 | 330 | ||
331 | for (QStringList::ConstIterator it = candidates.begin(); | 331 | for (QStringList::ConstIterator it = candidates.begin(); |
332 | it != candidates.end(); it++) { | 332 | it != candidates.end(); it++) { |
333 | testdir.setPath(*it + reldir); | 333 | testdir.setPath(*it + reldir); |
334 | if (testdir.exists()) | 334 | if (testdir.exists()) |
335 | list.append(testdir.absPath() + '/'); | 335 | list.append(testdir.absPath() + '/'); |
336 | } | 336 | } |
337 | 337 | ||
338 | return list; | 338 | return list; |
339 | } | 339 | } |
340 | 340 | ||
341 | QString KStandardDirs::findResourceDir( const char *type, | 341 | QString KStandardDirs::findResourceDir( const char *type, |
342 | const QString& filename) const | 342 | const QString& filename) const |
343 | { | 343 | { |
344 | #ifndef NDEBUG | 344 | #ifndef NDEBUG |
345 | if (filename.isEmpty()) { | 345 | if (filename.isEmpty()) { |
346 | kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; | 346 | kdWarning() << "filename for type " << type << " in KStandardDirs::findResourceDir is not supposed to be empty!!" << endl; |
347 | return QString::null; | 347 | return QString::null; |
348 | } | 348 | } |
349 | #endif | 349 | #endif |
350 | 350 | ||
351 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) | 351 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) |
352 | applyDataRestrictions(filename); | 352 | applyDataRestrictions(filename); |
353 | QStringList candidates = resourceDirs(type); | 353 | QStringList candidates = resourceDirs(type); |
354 | QString fullPath; | 354 | QString fullPath; |
355 | #ifdef DESKTOP_VERSION | 355 | #ifdef DESKTOP_VERSION |
356 | #ifdef _WIN32_ | 356 | #ifdef _WIN32_ |
357 | candidates.prepend( qApp->applicationDirPath () +"\\"); | 357 | candidates.prepend( qApp->applicationDirPath () +"\\"); |
358 | #else | 358 | #else |
359 | candidates.prepend( qApp->applicationDirPath () +"/"); | 359 | candidates.prepend( qApp->applicationDirPath () +"/"); |
360 | #endif | 360 | #endif |
361 | #endif | 361 | #endif |
362 | for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) | 362 | for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) |
363 | { | 363 | { |
364 | //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); | 364 | //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); |
365 | if (exists(*it + filename)) | 365 | if (exists(*it + filename)) |
366 | return *it; | 366 | return *it; |
367 | } | 367 | } |
368 | 368 | ||
369 | #ifndef NDEBUG | 369 | #ifndef NDEBUG |
370 | if(false && type != "locale") | 370 | if(false && type != "locale") |
371 | qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); | 371 | qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); |
372 | 372 | ||
373 | #endif | 373 | #endif |
374 | 374 | ||
375 | return QString::null; | 375 | return QString::null; |
376 | } | 376 | } |
377 | 377 | ||
378 | bool KStandardDirs::exists(const QString &fullPath) | 378 | bool KStandardDirs::exists(const QString &fullPath) |
379 | { | 379 | { |
380 | //US struct stat buff; | 380 | //US struct stat buff; |
381 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 381 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
382 | 382 | ||
383 | //US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) | 383 | //US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) |
384 | if (fullPathInfo.isReadable()) | 384 | if (fullPathInfo.isReadable()) |
385 | { | 385 | { |
386 | if (fullPath.at(fullPath.length() - 1) != '/') { | 386 | if (fullPath.at(fullPath.length() - 1) != '/') { |
387 | //US if (S_ISREG( buff.st_mode )) | 387 | //US if (S_ISREG( buff.st_mode )) |
388 | if (fullPathInfo.isFile()) | 388 | if (fullPathInfo.isFile()) |
389 | return true; | 389 | return true; |
390 | } | 390 | } |
391 | else { | 391 | else { |
392 | //US if (S_ISDIR( buff.st_mode )) | 392 | //US if (S_ISDIR( buff.st_mode )) |
393 | if (fullPathInfo.isDir()) | 393 | if (fullPathInfo.isDir()) |
394 | return true; | 394 | return true; |
395 | } | 395 | } |
396 | } | 396 | } |
397 | return false; | 397 | return false; |
398 | } | 398 | } |
399 | 399 | ||
400 | static void lookupDirectory(const QString& path, const QString &relPart, | 400 | static void lookupDirectory(const QString& path, const QString &relPart, |
401 | const QRegExp ®exp, | 401 | const QRegExp ®exp, |
402 | QStringList& list, | 402 | QStringList& list, |
403 | QStringList& relList, | 403 | QStringList& relList, |
404 | bool recursive, bool uniq) | 404 | bool recursive, bool uniq) |
405 | { | 405 | { |
406 | QString pattern = regexp.pattern(); | 406 | QString pattern = regexp.pattern(); |
407 | if (recursive || pattern.contains('?') || pattern.contains('*')) | 407 | if (recursive || pattern.contains('?') || pattern.contains('*')) |
408 | { | 408 | { |
409 | // We look for a set of files. | 409 | // We look for a set of files. |
410 | //US DIR *dp = opendir( QFile::encodeName(path)); | 410 | //US DIR *dp = opendir( QFile::encodeName(path)); |
411 | QDir dp(QFile::encodeName(path)); | 411 | QDir dp(QFile::encodeName(path)); |
412 | 412 | ||
413 | if (!dp.exists()) | 413 | if (!dp.exists()) |
414 | return; | 414 | return; |
415 | static int iii = 0; | 415 | static int iii = 0; |
416 | ++iii; | 416 | ++iii; |
417 | if ( iii == 5 ) | 417 | if ( iii == 5 ) |
418 | abort(); | 418 | abort(); |
419 | assert(path.at(path.length() - 1) == '/'); | 419 | assert(path.at(path.length() - 1) == '/'); |
420 | 420 | ||
421 | //US struct dirent *ep; | 421 | //US struct dirent *ep; |
422 | //US struct stat buff; | 422 | //US struct stat buff; |
423 | 423 | ||
424 | QString _dot("."); | 424 | QString _dot("."); |
425 | QString _dotdot(".."); | 425 | QString _dotdot(".."); |
426 | 426 | ||
427 | //US while( ( ep = readdir( dp ) ) != 0L ) | 427 | //US while( ( ep = readdir( dp ) ) != 0L ) |
428 | QStringList direntries = dp.entryList(); | 428 | QStringList direntries = dp.entryList(); |
429 | QStringList::Iterator it = direntries.begin(); | 429 | QStringList::Iterator it = direntries.begin(); |
430 | 430 | ||
431 | while ( it != list.end() ) // for each file... | 431 | while ( it != list.end() ) // for each file... |
432 | { | 432 | { |
433 | 433 | ||
434 | //US QString fn( QFile::decodeName(ep->d_name)); | 434 | //US QString fn( QFile::decodeName(ep->d_name)); |
435 | QString fn = (*it); // dp.entryList already decodes | 435 | QString fn = (*it); // dp.entryList already decodes |
436 | it++; | 436 | it++; |
437 | if ( fn.isNull() ) | 437 | if ( fn.isNull() ) |
438 | break; | 438 | break; |
439 | 439 | ||
440 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) | 440 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) |
441 | continue; | 441 | continue; |
442 | 442 | ||
443 | /*US | 443 | /*US |
444 | if (!recursive && !regexp.exactMatch(fn)) | 444 | if (!recursive && !regexp.exactMatch(fn)) |
445 | continue; // No match | 445 | continue; // No match |
446 | */ | 446 | */ |
447 | //US this should do the same: | 447 | //US this should do the same: |
448 | int pos = regexp.match(fn); | 448 | int pos = regexp.match(fn); |
449 | if (!recursive && !pos == 0) | 449 | if (!recursive && !pos == 0) |
450 | continue; // No match | 450 | continue; // No match |
451 | 451 | ||
452 | QString pathfn = path + fn; | 452 | QString pathfn = path + fn; |
453 | /*US | 453 | /*US |
454 | if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { | 454 | if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { |
455 | kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; | 455 | kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; |
456 | continue; // Couldn't stat (e.g. no read permissions) | 456 | continue; // Couldn't stat (e.g. no read permissions) |
457 | } | 457 | } |
458 | 458 | ||
459 | if ( recursive ) | 459 | if ( recursive ) |
460 | { | 460 | { |
461 | if ( S_ISDIR( buff.st_mode )) { | 461 | if ( S_ISDIR( buff.st_mode )) { |
462 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); | 462 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); |
463 | } | 463 | } |
464 | */ | 464 | */ |
465 | //US replacement: | 465 | //US replacement: |
466 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); | 466 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); |
467 | if ( pathfnInfo.isReadable() == false ) | 467 | if ( pathfnInfo.isReadable() == false ) |
468 | { | 468 | { |
469 | //US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; | 469 | //US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; |
470 | continue; // Couldn't stat (e.g. no read permissions) | 470 | continue; // Couldn't stat (e.g. no read permissions) |
471 | } | 471 | } |
472 | 472 | ||
473 | if ( recursive ) | 473 | if ( recursive ) |
474 | { | 474 | { |
475 | if ( pathfnInfo.isDir()) { | 475 | if ( pathfnInfo.isDir()) { |
476 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); | 476 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); |
477 | } | 477 | } |
478 | 478 | ||
479 | 479 | ||
480 | /*US | 480 | /*US |
481 | if (!regexp.exactMatch(fn)) | 481 | if (!regexp.exactMatch(fn)) |
482 | continue; // No match | 482 | continue; // No match |
483 | */ | 483 | */ |
484 | //US this should do the same: | 484 | //US this should do the same: |
485 | pos = regexp.match(fn); | 485 | pos = regexp.match(fn); |
486 | if (!pos == 0) | 486 | if (!pos == 0) |
487 | continue; // No match | 487 | continue; // No match |
488 | } | 488 | } |
489 | 489 | ||
490 | //US if ( S_ISREG( buff.st_mode)) | 490 | //US if ( S_ISREG( buff.st_mode)) |
491 | if ( pathfnInfo.isFile()) | 491 | if ( pathfnInfo.isFile()) |
492 | { | 492 | { |
493 | if (!uniq || !relList.contains(relPart + fn)) | 493 | if (!uniq || !relList.contains(relPart + fn)) |
494 | { | 494 | { |
495 | list.append( pathfn ); | 495 | list.append( pathfn ); |
496 | relList.append( relPart + fn ); | 496 | relList.append( relPart + fn ); |
497 | } | 497 | } |
498 | } | 498 | } |
499 | } | 499 | } |
500 | //US closedir( dp ); | 500 | //US closedir( dp ); |
501 | } | 501 | } |
502 | else | 502 | else |
503 | { | 503 | { |
504 | // We look for a single file. | 504 | // We look for a single file. |
505 | QString fn = pattern; | 505 | QString fn = pattern; |
506 | QString pathfn = path + fn; | 506 | QString pathfn = path + fn; |
507 | //US struct stat buff; | 507 | //US struct stat buff; |
508 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); | 508 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); |
509 | 509 | ||
510 | 510 | ||
511 | //US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) | 511 | //US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) |
512 | if ( pathfnInfo.isReadable() == false ) | 512 | if ( pathfnInfo.isReadable() == false ) |
513 | return; // File not found | 513 | return; // File not found |
514 | 514 | ||
515 | //US if ( S_ISREG( buff.st_mode)) | 515 | //US if ( S_ISREG( buff.st_mode)) |
516 | if ( pathfnInfo.isFile()) | 516 | if ( pathfnInfo.isFile()) |
517 | { | 517 | { |
518 | if (!uniq || !relList.contains(relPart + fn)) | 518 | if (!uniq || !relList.contains(relPart + fn)) |
519 | { | 519 | { |
520 | list.append( pathfn ); | 520 | list.append( pathfn ); |
521 | relList.append( relPart + fn ); | 521 | relList.append( relPart + fn ); |
522 | } | 522 | } |
523 | } | 523 | } |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | static void lookupPrefix(const QString& prefix, const QString& relpath, | 527 | static void lookupPrefix(const QString& prefix, const QString& relpath, |
528 | const QString& relPart, | 528 | const QString& relPart, |
529 | const QRegExp ®exp, | 529 | const QRegExp ®exp, |
530 | QStringList& list, | 530 | QStringList& list, |
531 | QStringList& relList, | 531 | QStringList& relList, |
532 | bool recursive, bool uniq) | 532 | bool recursive, bool uniq) |
533 | { | 533 | { |
534 | if (relpath.isNull()) { | 534 | if (relpath.isNull()) { |
535 | lookupDirectory(prefix, relPart, regexp, list, | 535 | lookupDirectory(prefix, relPart, regexp, list, |
536 | relList, recursive, uniq); | 536 | relList, recursive, uniq); |
537 | return; | 537 | return; |
538 | } | 538 | } |
539 | QString path; | 539 | QString path; |
540 | QString rest; | 540 | QString rest; |
541 | 541 | ||
542 | if (relpath.length()) | 542 | if (relpath.length()) |
543 | { | 543 | { |
544 | int slash = relpath.find('/'); | 544 | int slash = relpath.find('/'); |
545 | if (slash < 0) | 545 | if (slash < 0) |
546 | rest = relpath.left(relpath.length() - 1); | 546 | rest = relpath.left(relpath.length() - 1); |
547 | else { | 547 | else { |
548 | path = relpath.left(slash); | 548 | path = relpath.left(slash); |
549 | rest = relpath.mid(slash + 1); | 549 | rest = relpath.mid(slash + 1); |
550 | } | 550 | } |
551 | } | 551 | } |
552 | assert(prefix.at(prefix.length() - 1) == '/'); | 552 | assert(prefix.at(prefix.length() - 1) == '/'); |
553 | 553 | ||
554 | //US struct stat buff; | 554 | //US struct stat buff; |
555 | 555 | ||
556 | if (path.contains('*') || path.contains('?')) { | 556 | if (path.contains('*') || path.contains('?')) { |
557 | QRegExp pathExp(path, true, true); | 557 | QRegExp pathExp(path, true, true); |
558 | //USDIR *dp = opendir( QFile::encodeName(prefix) ); | 558 | //USDIR *dp = opendir( QFile::encodeName(prefix) ); |
559 | QDir dp(QFile::encodeName(prefix)); | 559 | QDir dp(QFile::encodeName(prefix)); |
560 | 560 | ||
561 | //USif (!dp) | 561 | //USif (!dp) |
562 | if (!dp.exists()) | 562 | if (!dp.exists()) |
563 | { | 563 | { |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | 566 | ||
567 | //USstruct dirent *ep; | 567 | //USstruct dirent *ep; |
568 | 568 | ||
569 | QString _dot("."); | 569 | QString _dot("."); |
570 | QString _dotdot(".."); | 570 | QString _dotdot(".."); |
571 | 571 | ||
572 | //USwhile( ( ep = readdir( dp ) ) != 0L ) | 572 | //USwhile( ( ep = readdir( dp ) ) != 0L ) |
573 | QStringList direntries = dp.entryList(); | 573 | QStringList direntries = dp.entryList(); |
574 | QStringList::Iterator it = direntries.begin(); | 574 | QStringList::Iterator it = direntries.begin(); |
575 | 575 | ||
576 | while ( it != list.end() ) // for each file... | 576 | while ( it != list.end() ) // for each file... |
577 | { | 577 | { |
578 | //US QString fn( QFile::decodeName(ep->d_name)); | 578 | //US QString fn( QFile::decodeName(ep->d_name)); |
579 | QString fn = (*it); // dp.entryList() already encodes the strings | 579 | QString fn = (*it); // dp.entryList() already encodes the strings |
580 | it++; | 580 | it++; |
581 | 581 | ||
582 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') | 582 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') |
583 | continue; | 583 | continue; |
584 | 584 | ||
585 | #ifdef DESKTOP_VERSION | 585 | #ifdef DESKTOP_VERSION |
586 | 586 | ||
587 | if (pathExp.search(fn) == -1) | 587 | if (pathExp.search(fn) == -1) |
588 | continue; // No match | 588 | continue; // No match |
589 | 589 | ||
590 | #else | 590 | #else |
591 | //US this should do the same: | 591 | //US this should do the same: |
592 | if (pathExp.find(fn, 0) == -1) | 592 | if (pathExp.find(fn, 0) == -1) |
593 | continue; // No match | 593 | continue; // No match |
594 | #endif | 594 | #endif |
595 | QString rfn = relPart+fn; | 595 | QString rfn = relPart+fn; |
596 | fn = prefix + fn; | 596 | fn = prefix + fn; |
597 | //US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) | 597 | //US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) |
598 | QFileInfo fnInfo(QFile::encodeName(fn)); | 598 | QFileInfo fnInfo(QFile::encodeName(fn)); |
599 | if ( fnInfo.isReadable() == false ) | 599 | if ( fnInfo.isReadable() == false ) |
600 | { | 600 | { |
601 | //US kdDebug() << "Error statting " << fn << " : " << perror << endl; | 601 | //US kdDebug() << "Error statting " << fn << " : " << perror << endl; |
602 | continue; // Couldn't stat (e.g. no permissions) | 602 | continue; // Couldn't stat (e.g. no permissions) |
603 | } | 603 | } |
604 | //US if ( S_ISDIR( buff.st_mode )) | 604 | //US if ( S_ISDIR( buff.st_mode )) |
605 | if ( fnInfo.isDir() ) | 605 | if ( fnInfo.isDir() ) |
606 | 606 | ||
607 | lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); | 607 | lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); |
608 | } | 608 | } |
609 | 609 | ||
610 | //USclosedir( dp ); | 610 | //USclosedir( dp ); |
611 | } else { | 611 | } else { |
612 | // Don't stat, if the dir doesn't exist we will find out | 612 | // Don't stat, if the dir doesn't exist we will find out |
613 | // when we try to open it. | 613 | // when we try to open it. |
614 | lookupPrefix(prefix + path + '/', rest, | 614 | lookupPrefix(prefix + path + '/', rest, |
615 | relPart + path + '/', regexp, list, | 615 | relPart + path + '/', regexp, list, |
616 | relList, recursive, uniq); | 616 | relList, recursive, uniq); |
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | QStringList | 620 | QStringList |
621 | KStandardDirs::findAllResources( const char *type, | 621 | KStandardDirs::findAllResources( const char *type, |
622 | const QString& filter, | 622 | const QString& filter, |
623 | bool recursive, | 623 | bool recursive, |
624 | bool uniq, | 624 | bool uniq, |
625 | QStringList &relList) const | 625 | QStringList &relList) const |
626 | { | 626 | { |
627 | QStringList list; | 627 | QStringList list; |
628 | if (filter.at(0) == '/') // absolute paths we return | 628 | if (filter.at(0) == '/') // absolute paths we return |
629 | { | 629 | { |
630 | list.append( filter); | 630 | list.append( filter); |
631 | return list; | 631 | return list; |
632 | } | 632 | } |
633 | 633 | ||
634 | QString filterPath; | 634 | QString filterPath; |
635 | QString filterFile; | 635 | QString filterFile; |
636 | 636 | ||
637 | if (filter.length()) | 637 | if (filter.length()) |
638 | { | 638 | { |
639 | int slash = filter.findRev('/'); | 639 | int slash = filter.findRev('/'); |
640 | if (slash < 0) | 640 | if (slash < 0) |
641 | filterFile = filter; | 641 | filterFile = filter; |
642 | else { | 642 | else { |
643 | filterPath = filter.left(slash + 1); | 643 | filterPath = filter.left(slash + 1); |
644 | filterFile = filter.mid(slash + 1); | 644 | filterFile = filter.mid(slash + 1); |
645 | } | 645 | } |
646 | } | 646 | } |
647 | checkConfig(); | 647 | checkConfig(); |
648 | 648 | ||
649 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) | 649 | if (d && d->restrictionsActive && (strcmp(type, "data")==0)) |
650 | applyDataRestrictions(filter); | 650 | applyDataRestrictions(filter); |
651 | QStringList candidates = resourceDirs(type); | 651 | QStringList candidates = resourceDirs(type); |
652 | if (filterFile.isEmpty()) | 652 | if (filterFile.isEmpty()) |
653 | filterFile = "*"; | 653 | filterFile = "*"; |
654 | 654 | ||
655 | QRegExp regExp(filterFile, true, true); | 655 | QRegExp regExp(filterFile, true, true); |
656 | for (QStringList::ConstIterator it = candidates.begin(); | 656 | for (QStringList::ConstIterator it = candidates.begin(); |
657 | it != candidates.end(); it++) | 657 | it != candidates.end(); it++) |
658 | { | 658 | { |
659 | lookupPrefix(*it, filterPath, "", regExp, list, | 659 | lookupPrefix(*it, filterPath, "", regExp, list, |
660 | relList, recursive, uniq); | 660 | relList, recursive, uniq); |
661 | } | 661 | } |
662 | return list; | 662 | return list; |
663 | } | 663 | } |
664 | 664 | ||
665 | QStringList | 665 | QStringList |
666 | KStandardDirs::findAllResources( const char *type, | 666 | KStandardDirs::findAllResources( const char *type, |
667 | const QString& filter, | 667 | const QString& filter, |
668 | bool recursive, | 668 | bool recursive, |
669 | bool uniq) const | 669 | bool uniq) const |
670 | { | 670 | { |
671 | QStringList relList; | 671 | QStringList relList; |
672 | return findAllResources(type, filter, recursive, uniq, relList); | 672 | return findAllResources(type, filter, recursive, uniq, relList); |
673 | } | 673 | } |
674 | 674 | ||
675 | QString | 675 | QString |
676 | KStandardDirs::realPath(const QString &dirname) | 676 | KStandardDirs::realPath(const QString &dirname) |
677 | { | 677 | { |
678 | #ifdef _WIN32_ | 678 | #ifdef _WIN32_ |
679 | return dirname; | 679 | return dirname; |
680 | #else | 680 | #else |
681 | //US char realpath_buffer[MAXPATHLEN + 1]; | 681 | //US char realpath_buffer[MAXPATHLEN + 1]; |
682 | //US memset(realpath_buffer, 0, MAXPATHLEN + 1); | 682 | //US memset(realpath_buffer, 0, MAXPATHLEN + 1); |
683 | char realpath_buffer[250 + 1]; | 683 | char realpath_buffer[250 + 1]; |
684 | memset(realpath_buffer, 0, 250 + 1); | 684 | memset(realpath_buffer, 0, 250 + 1); |
685 | 685 | ||
686 | /* If the path contains symlinks, get the real name */ | 686 | /* If the path contains symlinks, get the real name */ |
687 | if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) { | 687 | if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) { |
688 | // succes, use result from realpath | 688 | // succes, use result from realpath |
689 | int len = strlen(realpath_buffer); | 689 | int len = strlen(realpath_buffer); |
690 | realpath_buffer[len] = '/'; | 690 | realpath_buffer[len] = '/'; |
691 | realpath_buffer[len+1] = 0; | 691 | realpath_buffer[len+1] = 0; |
692 | return QFile::decodeName(realpath_buffer); | 692 | return QFile::decodeName(realpath_buffer); |
693 | } | 693 | } |
694 | 694 | ||
695 | return dirname; | 695 | return dirname; |
696 | #endif | 696 | #endif |
697 | } | 697 | } |
698 | /*US | 698 | /*US |
699 | void KStandardDirs::createSpecialResource(const char *type) | 699 | void KStandardDirs::createSpecialResource(const char *type) |
700 | { | 700 | { |
701 | char hostname[256]; | 701 | char hostname[256]; |
702 | hostname[0] = 0; | 702 | hostname[0] = 0; |
703 | gethostname(hostname, 255); | 703 | gethostname(hostname, 255); |
704 | QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); | 704 | QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); |
705 | char link[1024]; | 705 | char link[1024]; |
706 | link[1023] = 0; | 706 | link[1023] = 0; |
707 | int result = readlink(QFile::encodeName(dir).data(), link, 1023); | 707 | int result = readlink(QFile::encodeName(dir).data(), link, 1023); |
708 | if ((result == -1) && (errno == ENOENT)) | 708 | if ((result == -1) && (errno == ENOENT)) |
709 | { | 709 | { |
710 | QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); | 710 | QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); |
711 | if (srv.isEmpty()) | 711 | if (srv.isEmpty()) |
712 | srv = findExe(QString::fromLatin1("lnusertemp")); | 712 | srv = findExe(QString::fromLatin1("lnusertemp")); |
713 | if (!srv.isEmpty()) | 713 | if (!srv.isEmpty()) |
714 | { | 714 | { |
715 | system(QFile::encodeName(srv)+" "+type); | 715 | system(QFile::encodeName(srv)+" "+type); |
716 | result = readlink(QFile::encodeName(dir).data(), link, 1023); | 716 | result = readlink(QFile::encodeName(dir).data(), link, 1023); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | if (result > 0) | 719 | if (result > 0) |
720 | { | 720 | { |
721 | link[result] = 0; | 721 | link[result] = 0; |
722 | if (link[0] == '/') | 722 | if (link[0] == '/') |
723 | dir = QFile::decodeName(link); | 723 | dir = QFile::decodeName(link); |
724 | else | 724 | else |
725 | dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); | 725 | dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); |
726 | } | 726 | } |
727 | addResourceDir(type, dir+'/'); | 727 | addResourceDir(type, dir+'/'); |
728 | } | 728 | } |
729 | */ | 729 | */ |
730 | 730 | ||
731 | QStringList KStandardDirs::resourceDirs(const char *type) const | 731 | QStringList KStandardDirs::resourceDirs(const char *type) const |
732 | { | 732 | { |
733 | QStringList *candidates = dircache.find(type); | 733 | QStringList *candidates = dircache.find(type); |
734 | 734 | ||
735 | if (!candidates) { // filling cache | 735 | if (!candidates) { // filling cache |
736 | /*US | 736 | /*US |
737 | if (strcmp(type, "socket") == 0) | 737 | if (strcmp(type, "socket") == 0) |
738 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); | 738 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); |
739 | else if (strcmp(type, "tmp") == 0) | 739 | else if (strcmp(type, "tmp") == 0) |
740 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); | 740 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); |
741 | else if (strcmp(type, "cache") == 0) | 741 | else if (strcmp(type, "cache") == 0) |
742 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); | 742 | const_cast<KStandardDirs *>(this)->createSpecialResource(type); |
743 | */ | 743 | */ |
744 | QDir testdir; | 744 | QDir testdir; |
745 | 745 | ||
746 | candidates = new QStringList(); | 746 | candidates = new QStringList(); |
747 | QStringList *dirs; | 747 | QStringList *dirs; |
748 | 748 | ||
749 | bool restrictionActive = false; | 749 | bool restrictionActive = false; |
750 | if (d && d->restrictionsActive) | 750 | if (d && d->restrictionsActive) |
751 | { | 751 | { |
752 | if (d->dataRestrictionActive) | 752 | if (d->dataRestrictionActive) |
753 | restrictionActive = true; | 753 | restrictionActive = true; |
754 | else if (d->restrictions["all"]) | 754 | else if (d->restrictions["all"]) |
755 | restrictionActive = true; | 755 | restrictionActive = true; |
756 | else if (d->restrictions[type]) | 756 | else if (d->restrictions[type]) |
757 | restrictionActive = true; | 757 | restrictionActive = true; |
758 | d->dataRestrictionActive = false; // Reset | 758 | d->dataRestrictionActive = false; // Reset |
759 | } | 759 | } |
760 | 760 | ||
761 | dirs = relatives.find(type); | 761 | dirs = relatives.find(type); |
762 | if (dirs) | 762 | if (dirs) |
763 | { | 763 | { |
764 | bool local = true; | 764 | bool local = true; |
765 | const QStringList *prefixList = 0; | 765 | const QStringList *prefixList = 0; |
766 | if (strncmp(type, "xdgdata-", 8) == 0) | 766 | if (strncmp(type, "xdgdata-", 8) == 0) |
767 | prefixList = &(d->xdgdata_prefixes); | 767 | prefixList = &(d->xdgdata_prefixes); |
768 | else if (strncmp(type, "xdgconf-", 8) == 0) | 768 | else if (strncmp(type, "xdgconf-", 8) == 0) |
769 | prefixList = &(d->xdgconf_prefixes); | 769 | prefixList = &(d->xdgconf_prefixes); |
770 | else | 770 | else |
771 | prefixList = &prefixes; | 771 | prefixList = &prefixes; |
772 | 772 | ||
773 | for (QStringList::ConstIterator pit = prefixList->begin(); | 773 | for (QStringList::ConstIterator pit = prefixList->begin(); |
774 | pit != prefixList->end(); | 774 | pit != prefixList->end(); |
775 | pit++) | 775 | pit++) |
776 | { | 776 | { |
777 | for (QStringList::ConstIterator it = dirs->begin(); | 777 | for (QStringList::ConstIterator it = dirs->begin(); |
778 | it != dirs->end(); ++it) { | 778 | it != dirs->end(); ++it) { |
779 | QString path = realPath(*pit + *it); | 779 | QString path = realPath(*pit + *it); |
780 | testdir.setPath(path); | 780 | testdir.setPath(path); |
781 | if (local && restrictionActive) | 781 | if (local && restrictionActive) |
782 | continue; | 782 | continue; |
783 | if ((local || testdir.exists()) && !candidates->contains(path)) | 783 | if ((local || testdir.exists()) && !candidates->contains(path)) |
784 | candidates->append(path); | 784 | candidates->append(path); |
785 | } | 785 | } |
786 | local = false; | 786 | local = false; |
787 | } | 787 | } |
788 | } | 788 | } |
789 | dirs = absolutes.find(type); | 789 | dirs = absolutes.find(type); |
790 | if (dirs) | 790 | if (dirs) |
791 | for (QStringList::ConstIterator it = dirs->begin(); | 791 | for (QStringList::ConstIterator it = dirs->begin(); |
792 | it != dirs->end(); ++it) | 792 | it != dirs->end(); ++it) |
793 | { | 793 | { |
794 | testdir.setPath(*it); | 794 | testdir.setPath(*it); |
795 | if (testdir.exists()) | 795 | if (testdir.exists()) |
796 | { | 796 | { |
797 | QString filename = realPath(*it); | 797 | QString filename = realPath(*it); |
798 | if (!candidates->contains(filename)) | 798 | if (!candidates->contains(filename)) |
799 | candidates->append(filename); | 799 | candidates->append(filename); |
800 | } | 800 | } |
801 | } | 801 | } |
802 | dircache.insert(type, candidates); | 802 | dircache.insert(type, candidates); |
803 | } | 803 | } |
804 | 804 | ||
805 | #if 0 | 805 | #if 0 |
806 | kdDebug() << "found dirs for resource " << type << ":" << endl; | 806 | kdDebug() << "found dirs for resource " << type << ":" << endl; |
807 | for (QStringList::ConstIterator pit = candidates->begin(); | 807 | for (QStringList::ConstIterator pit = candidates->begin(); |
808 | pit != candidates->end(); | 808 | pit != candidates->end(); |
809 | pit++) | 809 | pit++) |
810 | { | 810 | { |
811 | fprintf(stderr, "%s\n", (*pit).latin1()); | 811 | fprintf(stderr, "%s\n", (*pit).latin1()); |
812 | } | 812 | } |
813 | #endif | 813 | #endif |
814 | 814 | ||
815 | 815 | ||
816 | return *candidates; | 816 | return *candidates; |
817 | } | 817 | } |
818 | 818 | ||
819 | /*US | 819 | /*US |
820 | QString KStandardDirs::findExe( const QString& appname, | 820 | QString KStandardDirs::findExe( const QString& appname, |
821 | const QString& pstr, bool ignore) | 821 | const QString& pstr, bool ignore) |
822 | { | 822 | { |
823 | QFileInfo info; | 823 | QFileInfo info; |
824 | 824 | ||
825 | // absolute path ? | 825 | // absolute path ? |
826 | if (appname.startsWith(QString::fromLatin1("/"))) | 826 | if (appname.startsWith(QString::fromLatin1("/"))) |
827 | { | 827 | { |
828 | info.setFile( appname ); | 828 | info.setFile( appname ); |
829 | if( info.exists() && ( ignore || info.isExecutable() ) | 829 | if( info.exists() && ( ignore || info.isExecutable() ) |
830 | && info.isFile() ) { | 830 | && info.isFile() ) { |
831 | return appname; | 831 | return appname; |
832 | } | 832 | } |
833 | return QString::null; | 833 | return QString::null; |
834 | } | 834 | } |
835 | 835 | ||
836 | //US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname); | 836 | //US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname); |
837 | QString p = QString("%1/%2").arg(appname).arg(appname); | 837 | QString p = QString("%1/%2").arg(appname).arg(appname); |
838 | qDebug("KStandardDirs::findExe this is probably wrong"); | 838 | qDebug("KStandardDirs::findExe this is probably wrong"); |
839 | 839 | ||
840 | info.setFile( p ); | 840 | info.setFile( p ); |
841 | if( info.exists() && ( ignore || info.isExecutable() ) | 841 | if( info.exists() && ( ignore || info.isExecutable() ) |
842 | && ( info.isFile() || info.isSymLink() ) ) { | 842 | && ( info.isFile() || info.isSymLink() ) ) { |
843 | return p; | 843 | return p; |
844 | } | 844 | } |
845 | 845 | ||
846 | QStringList tokens; | 846 | QStringList tokens; |
847 | p = pstr; | 847 | p = pstr; |
848 | 848 | ||
849 | if( p.isNull() ) { | 849 | if( p.isNull() ) { |
850 | p = getenv( "PATH" ); | 850 | p = getenv( "PATH" ); |
851 | } | 851 | } |
852 | 852 | ||
853 | tokenize( tokens, p, ":\b" ); | 853 | tokenize( tokens, p, ":\b" ); |
854 | 854 | ||
855 | // split path using : or \b as delimiters | 855 | // split path using : or \b as delimiters |
856 | for( unsigned i = 0; i < tokens.count(); i++ ) { | 856 | for( unsigned i = 0; i < tokens.count(); i++ ) { |
857 | p = tokens[ i ]; | 857 | p = tokens[ i ]; |
858 | 858 | ||
859 | if ( p[ 0 ] == '~' ) | 859 | if ( p[ 0 ] == '~' ) |
860 | { | 860 | { |
861 | int len = p.find( '/' ); | 861 | int len = p.find( '/' ); |
862 | if ( len == -1 ) | 862 | if ( len == -1 ) |
863 | len = p.length(); | 863 | len = p.length(); |
864 | if ( len == 1 ) | 864 | if ( len == 1 ) |
865 | p.replace( 0, 1, QDir::homeDirPath() ); | 865 | p.replace( 0, 1, QDir::homeDirPath() ); |
866 | else | 866 | else |
867 | { | 867 | { |
868 | QString user = p.mid( 1, len - 1 ); | 868 | QString user = p.mid( 1, len - 1 ); |
869 | struct passwd *dir = getpwnam( user.local8Bit().data() ); | 869 | struct passwd *dir = getpwnam( user.local8Bit().data() ); |
870 | if ( dir && strlen( dir->pw_dir ) ) | 870 | if ( dir && strlen( dir->pw_dir ) ) |
871 | p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) ); | 871 | p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) ); |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | p += "/"; | 875 | p += "/"; |
876 | p += appname; | 876 | p += appname; |
877 | 877 | ||
878 | // Check for executable in this tokenized path | 878 | // Check for executable in this tokenized path |
879 | info.setFile( p ); | 879 | info.setFile( p ); |
880 | 880 | ||
881 | if( info.exists() && ( ignore || info.isExecutable() ) | 881 | if( info.exists() && ( ignore || info.isExecutable() ) |
882 | && ( info.isFile() || info.isSymLink() ) ) { | 882 | && ( info.isFile() || info.isSymLink() ) ) { |
883 | return p; | 883 | return p; |
884 | } | 884 | } |
885 | } | 885 | } |
886 | 886 | ||
887 | // If we reach here, the executable wasn't found. | 887 | // If we reach here, the executable wasn't found. |
888 | // So return empty string. | 888 | // So return empty string. |
889 | 889 | ||
890 | return QString::null; | 890 | return QString::null; |
891 | } | 891 | } |
892 | 892 | ||
893 | int KStandardDirs::findAllExe( QStringList& list, const QString& appname, | 893 | int KStandardDirs::findAllExe( QStringList& list, const QString& appname, |
894 | const QString& pstr, bool ignore ) | 894 | const QString& pstr, bool ignore ) |
895 | { | 895 | { |
896 | QString p = pstr; | 896 | QString p = pstr; |
897 | QFileInfo info; | 897 | QFileInfo info; |
898 | QStringList tokens; | 898 | QStringList tokens; |
899 | 899 | ||
900 | if( p.isNull() ) { | 900 | if( p.isNull() ) { |
901 | p = getenv( "PATH" ); | 901 | p = getenv( "PATH" ); |
902 | } | 902 | } |
903 | 903 | ||
904 | list.clear(); | 904 | list.clear(); |
905 | tokenize( tokens, p, ":\b" ); | 905 | tokenize( tokens, p, ":\b" ); |
906 | 906 | ||
907 | for ( unsigned i = 0; i < tokens.count(); i++ ) { | 907 | for ( unsigned i = 0; i < tokens.count(); i++ ) { |
908 | p = tokens[ i ]; | 908 | p = tokens[ i ]; |
909 | p += "/"; | 909 | p += "/"; |
910 | p += appname; | 910 | p += appname; |
911 | 911 | ||
912 | info.setFile( p ); | 912 | info.setFile( p ); |
913 | 913 | ||
914 | if( info.exists() && (ignore || info.isExecutable()) | 914 | if( info.exists() && (ignore || info.isExecutable()) |
915 | && info.isFile() ) { | 915 | && info.isFile() ) { |
916 | list.append( p ); | 916 | list.append( p ); |
917 | } | 917 | } |
918 | 918 | ||
919 | } | 919 | } |
920 | 920 | ||
921 | return list.count(); | 921 | return list.count(); |
922 | } | 922 | } |
923 | */ | 923 | */ |
924 | 924 | ||
925 | static int tokenize( QStringList& tokens, const QString& str, | 925 | static int tokenize( QStringList& tokens, const QString& str, |
926 | const QString& delim ) | 926 | const QString& delim ) |
927 | { | 927 | { |
928 | int len = str.length(); | 928 | int len = str.length(); |
929 | QString token = ""; | 929 | QString token = ""; |
930 | 930 | ||
931 | for( int index = 0; index < len; index++) | 931 | for( int index = 0; index < len; index++) |
932 | { | 932 | { |
933 | if ( delim.find( str[ index ] ) >= 0 ) | 933 | if ( delim.find( str[ index ] ) >= 0 ) |
934 | { | 934 | { |
935 | tokens.append( token ); | 935 | tokens.append( token ); |
936 | token = ""; | 936 | token = ""; |
937 | } | 937 | } |
938 | else | 938 | else |
939 | { | 939 | { |
940 | token += str[ index ]; | 940 | token += str[ index ]; |
941 | } | 941 | } |
942 | } | 942 | } |
943 | if ( token.length() > 0 ) | 943 | if ( token.length() > 0 ) |
944 | { | 944 | { |
945 | tokens.append( token ); | 945 | tokens.append( token ); |
946 | } | 946 | } |
947 | 947 | ||
948 | return tokens.count(); | 948 | return tokens.count(); |
949 | } | 949 | } |
950 | 950 | ||
951 | QString KStandardDirs::kde_default(const char *type) { | 951 | QString KStandardDirs::kde_default(const char *type) { |
952 | if (!strcmp(type, "data")) | 952 | if (!strcmp(type, "data")) |
953 | return "apps/"; | 953 | return "apps/"; |
954 | if (!strcmp(type, "html")) | 954 | if (!strcmp(type, "html")) |
955 | return "share/doc/HTML/"; | 955 | return "share/doc/HTML/"; |
956 | if (!strcmp(type, "icon")) | 956 | if (!strcmp(type, "icon")) |
957 | return "share/icons/"; | 957 | return "share/icons/"; |
958 | if (!strcmp(type, "config")) | 958 | if (!strcmp(type, "config")) |
959 | return "config/"; | 959 | return "config/"; |
960 | if (!strcmp(type, "pixmap")) | 960 | if (!strcmp(type, "pixmap")) |
961 | return "share/pixmaps/"; | 961 | return "share/pixmaps/"; |
962 | if (!strcmp(type, "apps")) | 962 | if (!strcmp(type, "apps")) |
963 | return "share/applnk/"; | 963 | return "share/applnk/"; |
964 | if (!strcmp(type, "sound")) | 964 | if (!strcmp(type, "sound")) |
965 | return "share/sounds/"; | 965 | return "share/sounds/"; |
966 | if (!strcmp(type, "locale")) | 966 | if (!strcmp(type, "locale")) |
967 | return "share/locale/"; | 967 | return "share/locale/"; |
968 | if (!strcmp(type, "services")) | 968 | if (!strcmp(type, "services")) |
969 | return "share/services/"; | 969 | return "share/services/"; |
970 | if (!strcmp(type, "servicetypes")) | 970 | if (!strcmp(type, "servicetypes")) |
971 | return "share/servicetypes/"; | 971 | return "share/servicetypes/"; |
972 | if (!strcmp(type, "mime")) | 972 | if (!strcmp(type, "mime")) |
973 | return "share/mimelnk/"; | 973 | return "share/mimelnk/"; |
974 | if (!strcmp(type, "cgi")) | 974 | if (!strcmp(type, "cgi")) |
975 | return "cgi-bin/"; | 975 | return "cgi-bin/"; |
976 | if (!strcmp(type, "wallpaper")) | 976 | if (!strcmp(type, "wallpaper")) |
977 | return "share/wallpapers/"; | 977 | return "share/wallpapers/"; |
978 | if (!strcmp(type, "templates")) | 978 | if (!strcmp(type, "templates")) |
979 | return "share/templates/"; | 979 | return "share/templates/"; |
980 | if (!strcmp(type, "exe")) | 980 | if (!strcmp(type, "exe")) |
981 | return "bin/"; | 981 | return "bin/"; |
982 | if (!strcmp(type, "lib")) | 982 | if (!strcmp(type, "lib")) |
983 | return "lib/"; | 983 | return "lib/"; |
984 | if (!strcmp(type, "module")) | 984 | if (!strcmp(type, "module")) |
985 | return "lib/kde3/"; | 985 | return "lib/kde3/"; |
986 | if (!strcmp(type, "qtplugins")) | 986 | if (!strcmp(type, "qtplugins")) |
987 | return "lib/kde3/plugins"; | 987 | return "lib/kde3/plugins"; |
988 | if (!strcmp(type, "xdgdata-apps")) | 988 | if (!strcmp(type, "xdgdata-apps")) |
989 | return "applications/"; | 989 | return "applications/"; |
990 | if (!strcmp(type, "xdgdata-dirs")) | 990 | if (!strcmp(type, "xdgdata-dirs")) |
991 | return "desktop-directories/"; | 991 | return "desktop-directories/"; |
992 | if (!strcmp(type, "xdgconf-menu")) | 992 | if (!strcmp(type, "xdgconf-menu")) |
993 | return "menus/"; | 993 | return "menus/"; |
994 | if (!strcmp(type, "tmp")) | 994 | if (!strcmp(type, "tmp")) |
995 | return "tmp/"; | 995 | return "tmp/"; |
996 | 996 | ||
997 | qFatal("unknown resource type %s", type); | 997 | qFatal("unknown resource type %s", type); |
998 | return QString::null; | 998 | return QString::null; |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | QString KStandardDirs::saveLocation(const char *type, | 1001 | QString KStandardDirs::saveLocation(const char *type, |
1002 | const QString& suffix, | 1002 | const QString& suffix, |
1003 | bool create) const | 1003 | bool create) const |
1004 | { | 1004 | { |
1005 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); | 1005 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); |
1006 | //return ""; | 1006 | //return ""; |
1007 | checkConfig(); | 1007 | checkConfig(); |
1008 | 1008 | ||
1009 | QString *pPath = savelocations.find(type); | 1009 | QString *pPath = savelocations.find(type); |
1010 | if (!pPath) | 1010 | if (!pPath) |
1011 | { | 1011 | { |
1012 | QStringList *dirs = relatives.find(type); | 1012 | QStringList *dirs = relatives.find(type); |
1013 | if (!dirs && ( | 1013 | if (!dirs && ( |
1014 | (strcmp(type, "socket") == 0) || | 1014 | (strcmp(type, "socket") == 0) || |
1015 | (strcmp(type, "tmp") == 0) || | 1015 | (strcmp(type, "tmp") == 0) || |
1016 | (strcmp(type, "cache") == 0) )) | 1016 | (strcmp(type, "cache") == 0) )) |
1017 | { | 1017 | { |
1018 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. | 1018 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. |
1019 | dirs = relatives.find(type); // Search again. | 1019 | dirs = relatives.find(type); // Search again. |
1020 | } | 1020 | } |
1021 | if (dirs) | 1021 | if (dirs) |
1022 | { | 1022 | { |
1023 | // Check for existance of typed directory + suffix | 1023 | // Check for existance of typed directory + suffix |
1024 | if (strncmp(type, "xdgdata-", 8) == 0) | 1024 | if (strncmp(type, "xdgdata-", 8) == 0) |
1025 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); | 1025 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); |
1026 | else if (strncmp(type, "xdgconf-", 8) == 0) | 1026 | else if (strncmp(type, "xdgconf-", 8) == 0) |
1027 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); | 1027 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); |
1028 | else | 1028 | else |
1029 | pPath = new QString(realPath(localkdedir() + dirs->last())); | 1029 | pPath = new QString(realPath(localkdedir() + dirs->last())); |
1030 | } | 1030 | } |
1031 | else { | 1031 | else { |
1032 | dirs = absolutes.find(type); | 1032 | dirs = absolutes.find(type); |
1033 | if (!dirs) | 1033 | if (!dirs) |
1034 | qFatal("KStandardDirs: The resource type %s is not registered", type); | 1034 | qFatal("KStandardDirs: The resource type %s is not registered", type); |
1035 | pPath = new QString(realPath(dirs->last())); | 1035 | pPath = new QString(realPath(dirs->last())); |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | savelocations.insert(type, pPath); | 1038 | savelocations.insert(type, pPath); |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | QString fullPath = *pPath + suffix; | 1041 | QString fullPath = *pPath + suffix; |
1042 | //US struct stat st; | 1042 | //US struct stat st; |
1043 | //US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) | 1043 | //US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) |
1044 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 1044 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
1045 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) | 1045 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) |
1046 | 1046 | ||
1047 | 1047 | ||
1048 | { | 1048 | { |
1049 | if(!create) { | 1049 | if(!create) { |
1050 | #ifndef NDEBUG | 1050 | #ifndef NDEBUG |
1051 | qDebug("save location %s doesn't exist", fullPath.latin1()); | 1051 | qDebug("save location %s doesn't exist", fullPath.latin1()); |
1052 | #endif | 1052 | #endif |
1053 | return fullPath; | 1053 | return fullPath; |
1054 | } | 1054 | } |
1055 | if(!makeDir(fullPath, 0700)) { | 1055 | if(!makeDir(fullPath, 0700)) { |
1056 | qWarning("failed to create %s", fullPath.latin1()); | 1056 | qWarning("failed to create %s", fullPath.latin1()); |
1057 | return fullPath; | 1057 | return fullPath; |
1058 | } | 1058 | } |
1059 | dircache.remove(type); | 1059 | dircache.remove(type); |
1060 | } | 1060 | } |
1061 | return fullPath; | 1061 | return fullPath; |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) | 1064 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) |
1065 | { | 1065 | { |
1066 | QString fullPath = absPath; | 1066 | QString fullPath = absPath; |
1067 | int i = absPath.findRev('/'); | 1067 | int i = absPath.findRev('/'); |
1068 | if (i != -1) | 1068 | if (i != -1) |
1069 | { | 1069 | { |
1070 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize | 1070 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | QStringList candidates = resourceDirs(type); | 1073 | QStringList candidates = resourceDirs(type); |
1074 | 1074 | ||
1075 | for (QStringList::ConstIterator it = candidates.begin(); | 1075 | for (QStringList::ConstIterator it = candidates.begin(); |
1076 | it != candidates.end(); it++) | 1076 | it != candidates.end(); it++) |
1077 | if (fullPath.startsWith(*it)) | 1077 | if (fullPath.startsWith(*it)) |
1078 | { | 1078 | { |
1079 | return fullPath.mid((*it).length()); | 1079 | return fullPath.mid((*it).length()); |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | return absPath; | 1082 | return absPath; |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | 1085 | ||
1086 | bool KStandardDirs::makeDir(const QString& dir2, int mode) | 1086 | bool KStandardDirs::makeDir(const QString& dir2, int mode) |
1087 | { | 1087 | { |
1088 | QString dir = QDir::convertSeparators( dir2 ); | 1088 | QString dir = QDir::convertSeparators( dir2 ); |
1089 | #if 0 | 1089 | #if 0 |
1090 | //LR | 1090 | //LR |
1091 | 1091 | ||
1092 | // we want an absolute path | 1092 | // we want an absolute path |
1093 | if (dir.at(0) != '/') | 1093 | if (dir.at(0) != '/') |
1094 | return false; | 1094 | return false; |
1095 | 1095 | ||
1096 | QString target = dir; | 1096 | QString target = dir; |
1097 | uint len = target.length(); | 1097 | uint len = target.length(); |
1098 | 1098 | ||
1099 | // append trailing slash if missing | 1099 | // append trailing slash if missing |
1100 | if (dir.at(len - 1) != '/') | 1100 | if (dir.at(len - 1) != '/') |
1101 | target += '/'; | 1101 | target += '/'; |
1102 | 1102 | ||
1103 | QString base(""); | 1103 | QString base(""); |
1104 | uint i = 1; | 1104 | uint i = 1; |
1105 | 1105 | ||
1106 | while( i < len ) | 1106 | while( i < len ) |
1107 | { | 1107 | { |
1108 | //US struct stat st; | 1108 | //US struct stat st; |
1109 | int pos = target.find('/', i); | 1109 | int pos = target.find('/', i); |
1110 | base += target.mid(i - 1, pos - i + 1); | 1110 | base += target.mid(i - 1, pos - i + 1); |
1111 | QCString baseEncoded = QFile::encodeName(base); | 1111 | QCString baseEncoded = QFile::encodeName(base); |
1112 | // bail out if we encountered a problem | 1112 | // bail out if we encountered a problem |
1113 | //US if (stat(baseEncoded, &st) != 0) | 1113 | //US if (stat(baseEncoded, &st) != 0) |
1114 | QFileInfo baseEncodedInfo(baseEncoded); | 1114 | QFileInfo baseEncodedInfo(baseEncoded); |
1115 | if (!baseEncodedInfo.exists()) | 1115 | if (!baseEncodedInfo.exists()) |
1116 | { | 1116 | { |
1117 | // Directory does not exist.... | 1117 | // Directory does not exist.... |
1118 | // Or maybe a dangling symlink ? | 1118 | // Or maybe a dangling symlink ? |
1119 | //US if (lstat(baseEncoded, &st) == 0) | 1119 | //US if (lstat(baseEncoded, &st) == 0) |
1120 | if (baseEncodedInfo.isSymLink()) { | 1120 | if (baseEncodedInfo.isSymLink()) { |
1121 | //US (void)unlink(baseEncoded); // try removing | 1121 | //US (void)unlink(baseEncoded); // try removing |
1122 | QFile(baseEncoded).remove(); | 1122 | QFile(baseEncoded).remove(); |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) | 1125 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) |
1126 | QDir dirObj; | 1126 | QDir dirObj; |
1127 | if ( dirObj.mkdir(baseEncoded) != true ) | 1127 | if ( dirObj.mkdir(baseEncoded) != true ) |
1128 | { | 1128 | { |
1129 | //US perror("trying to create local folder"); | 1129 | //US perror("trying to create local folder"); |
1130 | return false; // Couldn't create it :-( | 1130 | return false; // Couldn't create it :-( |
1131 | } | 1131 | } |
1132 | } | 1132 | } |
1133 | i = pos + 1; | 1133 | i = pos + 1; |
1134 | } | 1134 | } |
1135 | return true; | 1135 | return true; |
1136 | #endif | 1136 | #endif |
1137 | 1137 | ||
1138 | // ******************************************** | 1138 | // ******************************************** |
1139 | // new code for WIN32 | 1139 | // new code for WIN32 |
1140 | QDir dirObj; | 1140 | QDir dirObj; |
1141 | 1141 | ||
1142 | 1142 | ||
1143 | // we want an absolute path | 1143 | // we want an absolute path |
1144 | #ifndef _WIN32_ | 1144 | #ifndef _WIN32_ |
1145 | if (dir.at(0) != '/') | 1145 | if (dir.at(0) != '/') |
1146 | return false; | 1146 | return false; |
1147 | #endif | 1147 | #endif |
1148 | 1148 | ||
1149 | QString target = dir; | 1149 | QString target = dir; |
1150 | uint len = target.length(); | 1150 | uint len = target.length(); |
1151 | #ifndef _WIN32_ | 1151 | #ifndef _WIN32_ |
1152 | // append trailing slash if missing | 1152 | // append trailing slash if missing |
1153 | if (dir.at(len - 1) != '/') | 1153 | if (dir.at(len - 1) != '/') |
1154 | target += '/'; | 1154 | target += '/'; |
1155 | #endif | 1155 | #endif |
1156 | 1156 | ||
1157 | QString base(""); | 1157 | QString base(""); |
1158 | uint i = 1; | 1158 | uint i = 1; |
1159 | 1159 | ||
1160 | while( i < len ) | 1160 | while( i < len ) |
1161 | { | 1161 | { |
1162 | //US struct stat st; | 1162 | //US struct stat st; |
1163 | #ifndef _WIN32_ | 1163 | #ifndef _WIN32_ |
1164 | int pos = target.find('/', i); | 1164 | int pos = target.find('/', i); |
1165 | #else | 1165 | #else |
1166 | int pos = target.find('\\', i); | 1166 | int pos = target.find('\\', i); |
1167 | #endif | 1167 | #endif |
1168 | if ( pos < 0 ) | 1168 | if ( pos < 0 ) |
1169 | return true; | 1169 | return true; |
1170 | base += target.mid(i - 1, pos - i + 1); | 1170 | base += target.mid(i - 1, pos - i + 1); |
1171 | //QMessageBox::information( 0,"cap111", base, 1 ); | 1171 | //QMessageBox::information( 0,"cap111", base, 1 ); |
1172 | /*US | 1172 | /*US |
1173 | QCString baseEncoded = QFile::encodeName(base); | 1173 | QCString baseEncoded = QFile::encodeName(base); |
1174 | // bail out if we encountered a problem | 1174 | // bail out if we encountered a problem |
1175 | if (stat(baseEncoded, &st) != 0) | 1175 | if (stat(baseEncoded, &st) != 0) |
1176 | { | 1176 | { |
1177 | // Directory does not exist.... | 1177 | // Directory does not exist.... |
1178 | // Or maybe a dangling symlink ? | 1178 | // Or maybe a dangling symlink ? |
1179 | if (lstat(baseEncoded, &st) == 0) | 1179 | if (lstat(baseEncoded, &st) == 0) |
1180 | (void)unlink(baseEncoded); // try removing | 1180 | (void)unlink(baseEncoded); // try removing |
1181 | 1181 | ||
1182 | 1182 | ||
1183 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { | 1183 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { |
1184 | perror("trying to create local folder"); | 1184 | perror("trying to create local folder"); |
1185 | return false; // Couldn't create it :-( | 1185 | return false; // Couldn't create it :-( |
1186 | } | 1186 | } |
1187 | } | 1187 | } |
1188 | */ | 1188 | */ |
1189 | 1189 | ||
1190 | if (dirObj.exists(base) == false) | 1190 | if (dirObj.exists(base) == false) |
1191 | { | 1191 | { |
1192 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); | 1192 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); |
1193 | if (dirObj.mkdir(base) != true) | 1193 | if (dirObj.mkdir(base) != true) |
1194 | { | 1194 | { |
1195 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); | 1195 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); |
1196 | return false; | 1196 | return false; |
1197 | } | 1197 | } |
1198 | } | 1198 | } |
1199 | 1199 | ||
1200 | i = pos + 1; | 1200 | i = pos + 1; |
1201 | } | 1201 | } |
1202 | return true; | 1202 | return true; |
1203 | 1203 | ||
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | static QString readEnvPath(const char *env) | 1206 | static QString readEnvPath(const char *env) |
1207 | { | 1207 | { |
1208 | //#ifdef _WIN32_ | 1208 | //#ifdef _WIN32_ |
1209 | // return ""; | 1209 | // return ""; |
1210 | //#else | 1210 | //#else |
1211 | QCString c_path; | 1211 | QCString c_path; |
1212 | if ( getenv(env) != NULL ) | 1212 | if ( getenv(env) != NULL ) |
1213 | c_path = QString ( getenv(env) ); | 1213 | c_path = QString ( getenv(env) ); |
1214 | if (c_path.isEmpty()) | 1214 | if (c_path.isEmpty()) |
1215 | return QString::null; | 1215 | return QString::null; |
1216 | return QFile::decodeName(c_path); | 1216 | return QFile::decodeName(c_path); |
1217 | //#endif | 1217 | //#endif |
1218 | 1218 | ||
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | void KStandardDirs::addKDEDefaults() | 1221 | void KStandardDirs::addKDEDefaults() |
1222 | { | 1222 | { |
1223 | 1223 | ||
1224 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); | 1224 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); |
1225 | //return; | 1225 | //return; |
1226 | QStringList kdedirList; | 1226 | QStringList kdedirList; |
1227 | 1227 | ||
1228 | // begin KDEDIRS | 1228 | // begin KDEDIRS |
1229 | QString kdedirs = readEnvPath("MICROKDEDIRS"); | 1229 | QString kdedirs = readEnvPath("MICROKDEDIRS"); |
1230 | if (!kdedirs.isEmpty()) | 1230 | if (!kdedirs.isEmpty()) |
1231 | { | 1231 | { |
1232 | tokenize(kdedirList, kdedirs, ":"); | 1232 | tokenize(kdedirList, kdedirs, ":"); |
1233 | } | 1233 | } |
1234 | else | 1234 | else |
1235 | { | 1235 | { |
1236 | QString kdedir = readEnvPath("MICROKDEDIR"); | 1236 | QString kdedir = readEnvPath("MICROKDEDIR"); |
1237 | if (!kdedir.isEmpty()) | 1237 | if (!kdedir.isEmpty()) |
1238 | { | 1238 | { |
1239 | kdedir = KShell::tildeExpand(kdedir); | 1239 | kdedir = KShell::tildeExpand(kdedir); |
1240 | kdedirList.append(kdedir); | 1240 | kdedirList.append(kdedir); |
1241 | } | 1241 | } |
1242 | } | 1242 | } |
1243 | //US kdedirList.append(KDEDIR); | 1243 | //US kdedirList.append(KDEDIR); |
1244 | //US for embedded, add qtopia dir as kdedir | 1244 | //US for embedded, add qtopia dir as kdedir |
1245 | 1245 | ||
1246 | #ifndef DESKTOP_VERSION | 1246 | #ifndef DESKTOP_VERSION |
1247 | QString tmp = readEnvPath("QPEDIR"); | 1247 | QString tmp = readEnvPath("QPEDIR"); |
1248 | if (!tmp.isEmpty()) | 1248 | if (!tmp.isEmpty()) |
1249 | kdedirList.append(tmp); | 1249 | kdedirList.append(tmp); |
1250 | 1250 | ||
1251 | tmp = readEnvPath("QTDIR"); | 1251 | tmp = readEnvPath("QTDIR"); |
1252 | if (!tmp.isEmpty()) | 1252 | if (!tmp.isEmpty()) |
1253 | kdedirList.append(tmp); | 1253 | kdedirList.append(tmp); |
1254 | 1254 | ||
1255 | tmp = readEnvPath("OPIEDIR"); | 1255 | tmp = readEnvPath("OPIEDIR"); |
1256 | if (!tmp.isEmpty()) | 1256 | if (!tmp.isEmpty()) |
1257 | kdedirList.append(tmp); | 1257 | kdedirList.append(tmp); |
1258 | 1258 | ||
1259 | #endif | 1259 | #endif |
1260 | 1260 | ||
1261 | #ifdef __KDE_EXECPREFIX | 1261 | #ifdef __KDE_EXECPREFIX |
1262 | QString execPrefix(__KDE_EXECPREFIX); | 1262 | QString execPrefix(__KDE_EXECPREFIX); |
1263 | if (execPrefix!="NONE") | 1263 | if (execPrefix!="NONE") |
1264 | kdedirList.append(execPrefix); | 1264 | kdedirList.append(execPrefix); |
1265 | #endif | 1265 | #endif |
1266 | 1266 | ||
1267 | QString localKdeDir; | 1267 | QString localKdeDir; |
1268 | 1268 | ||
1269 | //US if (getuid()) | 1269 | //US if (getuid()) |
1270 | if (true) | 1270 | if (true) |
1271 | { | 1271 | { |
1272 | localKdeDir = readEnvPath("MICROKDEHOME"); | 1272 | localKdeDir = readEnvPath("MICROKDEHOME"); |
1273 | if (!localKdeDir.isEmpty()) | 1273 | if (!localKdeDir.isEmpty()) |
1274 | { | 1274 | { |
1275 | #ifdef _WIN32_ | 1275 | #ifdef _WIN32_ |
1276 | if (localKdeDir.at(localKdeDir.length()-1) != '\\') | 1276 | if (localKdeDir.at(localKdeDir.length()-1) != '\\') |
1277 | localKdeDir += '\\'; | 1277 | localKdeDir += '\\'; |
1278 | #else | 1278 | #else |
1279 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1279 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1280 | localKdeDir += '/'; | 1280 | localKdeDir += '/'; |
1281 | #endif | 1281 | #endif |
1282 | //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 ); | 1282 | //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 ); |
1283 | } | 1283 | } |
1284 | else | 1284 | else |
1285 | { | 1285 | { |
1286 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; | 1286 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; |
1287 | } | 1287 | } |
1288 | } | 1288 | } |
1289 | else | 1289 | else |
1290 | { | 1290 | { |
1291 | // We treat root different to prevent root messing up the | 1291 | // We treat root different to prevent root messing up the |
1292 | // file permissions in the users home directory. | 1292 | // file permissions in the users home directory. |
1293 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); | 1293 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); |
1294 | if (!localKdeDir.isEmpty()) | 1294 | if (!localKdeDir.isEmpty()) |
1295 | { | 1295 | { |
1296 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1296 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1297 | localKdeDir += '/'; | 1297 | localKdeDir += '/'; |
1298 | } | 1298 | } |
1299 | else | 1299 | else |
1300 | { | 1300 | { |
1301 | //US struct passwd *pw = getpwuid(0); | 1301 | //US struct passwd *pw = getpwuid(0); |
1302 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; | 1302 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; |
1303 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); | 1303 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); |
1304 | } | 1304 | } |
1305 | 1305 | ||
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | //US localKdeDir = appDir(); | 1308 | //US localKdeDir = appDir(); |
1309 | 1309 | ||
1310 | //US | 1310 | //US |
1311 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); | 1311 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); |
1312 | if (localKdeDir != "-/") | 1312 | if (localKdeDir != "-/") |
1313 | { | 1313 | { |
1314 | localKdeDir = KShell::tildeExpand(localKdeDir); | 1314 | localKdeDir = KShell::tildeExpand(localKdeDir); |
1315 | addPrefix(localKdeDir); | 1315 | addPrefix(localKdeDir); |
1316 | } | 1316 | } |
1317 | 1317 | ||
1318 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1318 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1319 | it != kdedirList.end(); it++) | 1319 | it != kdedirList.end(); it++) |
1320 | { | 1320 | { |
1321 | QString dir = KShell::tildeExpand(*it); | 1321 | QString dir = KShell::tildeExpand(*it); |
1322 | addPrefix(dir); | 1322 | addPrefix(dir); |
1323 | } | 1323 | } |
1324 | // end KDEDIRS | 1324 | // end KDEDIRS |
1325 | 1325 | ||
1326 | // begin XDG_CONFIG_XXX | 1326 | // begin XDG_CONFIG_XXX |
1327 | QStringList xdgdirList; | 1327 | QStringList xdgdirList; |
1328 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); | 1328 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); |
1329 | if (!xdgdirs.isEmpty()) | 1329 | if (!xdgdirs.isEmpty()) |
1330 | { | 1330 | { |
1331 | tokenize(xdgdirList, xdgdirs, ":"); | 1331 | tokenize(xdgdirList, xdgdirs, ":"); |
1332 | } | 1332 | } |
1333 | else | 1333 | else |
1334 | { | 1334 | { |
1335 | xdgdirList.clear(); | 1335 | xdgdirList.clear(); |
1336 | xdgdirList.append("/etc/xdg"); | 1336 | xdgdirList.append("/etc/xdg"); |
1337 | } | 1337 | } |
1338 | 1338 | ||
1339 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); | 1339 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); |
1340 | if (!localXdgDir.isEmpty()) | 1340 | if (!localXdgDir.isEmpty()) |
1341 | { | 1341 | { |
1342 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1342 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1343 | localXdgDir += '/'; | 1343 | localXdgDir += '/'; |
1344 | } | 1344 | } |
1345 | else | 1345 | else |
1346 | { | 1346 | { |
1347 | //US if (getuid()) | 1347 | //US if (getuid()) |
1348 | if (true) | 1348 | if (true) |
1349 | { | 1349 | { |
1350 | localXdgDir = QDir::homeDirPath() + "/.config/"; | 1350 | localXdgDir = QDir::homeDirPath() + "/.config/"; |
1351 | } | 1351 | } |
1352 | else | 1352 | else |
1353 | { | 1353 | { |
1354 | //US struct passwd *pw = getpwuid(0); | 1354 | //US struct passwd *pw = getpwuid(0); |
1355 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; | 1355 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; |
1356 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); | 1356 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); |
1357 | } | 1357 | } |
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1360 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1361 | addXdgConfigPrefix(localXdgDir); | 1361 | addXdgConfigPrefix(localXdgDir); |
1362 | 1362 | ||
1363 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1363 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1364 | it != xdgdirList.end(); it++) | 1364 | it != xdgdirList.end(); it++) |
1365 | { | 1365 | { |
1366 | QString dir = KShell::tildeExpand(*it); | 1366 | QString dir = KShell::tildeExpand(*it); |
1367 | addXdgConfigPrefix(dir); | 1367 | addXdgConfigPrefix(dir); |
1368 | } | 1368 | } |
1369 | // end XDG_CONFIG_XXX | 1369 | // end XDG_CONFIG_XXX |
1370 | 1370 | ||
1371 | // begin XDG_DATA_XXX | 1371 | // begin XDG_DATA_XXX |
1372 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); | 1372 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); |
1373 | if (!xdgdirs.isEmpty()) | 1373 | if (!xdgdirs.isEmpty()) |
1374 | { | 1374 | { |
1375 | tokenize(xdgdirList, xdgdirs, ":"); | 1375 | tokenize(xdgdirList, xdgdirs, ":"); |
1376 | } | 1376 | } |
1377 | else | 1377 | else |
1378 | { | 1378 | { |
1379 | xdgdirList.clear(); | 1379 | xdgdirList.clear(); |
1380 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1380 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1381 | it != kdedirList.end(); it++) | 1381 | it != kdedirList.end(); it++) |
1382 | { | 1382 | { |
1383 | QString dir = *it; | 1383 | QString dir = *it; |
1384 | if (dir.at(dir.length()-1) != '/') | 1384 | if (dir.at(dir.length()-1) != '/') |
1385 | dir += '/'; | 1385 | dir += '/'; |
1386 | xdgdirList.append(dir+"share/"); | 1386 | xdgdirList.append(dir+"share/"); |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | xdgdirList.append("/usr/local/share/"); | 1389 | xdgdirList.append("/usr/local/share/"); |
1390 | xdgdirList.append("/usr/share/"); | 1390 | xdgdirList.append("/usr/share/"); |
1391 | } | 1391 | } |
1392 | 1392 | ||
1393 | localXdgDir = readEnvPath("XDG_DATA_HOME"); | 1393 | localXdgDir = readEnvPath("XDG_DATA_HOME"); |
1394 | if (!localXdgDir.isEmpty()) | 1394 | if (!localXdgDir.isEmpty()) |
1395 | { | 1395 | { |
1396 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1396 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1397 | localXdgDir += '/'; | 1397 | localXdgDir += '/'; |
1398 | } | 1398 | } |
1399 | else | 1399 | else |
1400 | { | 1400 | { |
1401 | //US if (getuid()) | 1401 | //US if (getuid()) |
1402 | if (true) | 1402 | if (true) |
1403 | { | 1403 | { |
1404 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; | 1404 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; |
1405 | } | 1405 | } |
1406 | else | 1406 | else |
1407 | { | 1407 | { |
1408 | //US struct passwd *pw = getpwuid(0); | 1408 | //US struct passwd *pw = getpwuid(0); |
1409 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; | 1409 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; |
1410 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); | 1410 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); |
1411 | } | 1411 | } |
1412 | } | 1412 | } |
1413 | 1413 | ||
1414 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1414 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1415 | addXdgDataPrefix(localXdgDir); | 1415 | addXdgDataPrefix(localXdgDir); |
1416 | 1416 | ||
1417 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1417 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1418 | it != xdgdirList.end(); it++) | 1418 | it != xdgdirList.end(); it++) |
1419 | { | 1419 | { |
1420 | QString dir = KShell::tildeExpand(*it); | 1420 | QString dir = KShell::tildeExpand(*it); |
1421 | 1421 | ||
1422 | addXdgDataPrefix(dir); | 1422 | addXdgDataPrefix(dir); |
1423 | } | 1423 | } |
1424 | // end XDG_DATA_XXX | 1424 | // end XDG_DATA_XXX |
1425 | 1425 | ||
1426 | 1426 | ||
1427 | uint index = 0; | 1427 | uint index = 0; |
1428 | while (types[index] != 0) { | 1428 | while (types[index] != 0) { |
1429 | addResourceType(types[index], kde_default(types[index])); | 1429 | addResourceType(types[index], kde_default(types[index])); |
1430 | index++; | 1430 | index++; |
1431 | } | 1431 | } |
1432 | 1432 | ||
1433 | addResourceDir("home", QDir::homeDirPath()); | 1433 | addResourceDir("home", QDir::homeDirPath()); |
1434 | } | 1434 | } |
1435 | 1435 | ||
1436 | void KStandardDirs::checkConfig() const | 1436 | void KStandardDirs::checkConfig() const |
1437 | { | 1437 | { |
1438 | /*US | 1438 | /*US |
1439 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) | 1439 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) |
1440 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); | 1440 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); |
1441 | */ | 1441 | */ |
1442 | if (!addedCustoms && KGlobal::config()) | 1442 | if (!addedCustoms && KGlobal::config()) |
1443 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); | 1443 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); |
1444 | } | 1444 | } |
1445 | 1445 | ||
1446 | bool KStandardDirs::addCustomized(KConfig *config) | 1446 | bool KStandardDirs::addCustomized(KConfig *config) |
1447 | { | 1447 | { |
1448 | if (addedCustoms) // there are already customized entries | 1448 | if (addedCustoms) // there are already customized entries |
1449 | return false; // we just quite and hope they are the right ones | 1449 | return false; // we just quite and hope they are the right ones |
1450 | 1450 | ||
1451 | // save the numbers of config directories. If this changes, | 1451 | // save the numbers of config directories. If this changes, |
1452 | // we will return true to give KConfig a chance to reparse | 1452 | // we will return true to give KConfig a chance to reparse |
1453 | uint configdirs = resourceDirs("config").count(); | 1453 | uint configdirs = resourceDirs("config").count(); |
1454 | 1454 | ||
1455 | // reading the prefixes in | 1455 | // reading the prefixes in |
1456 | QString oldGroup = config->group(); | 1456 | QString oldGroup = config->group(); |
1457 | config->setGroup("Directories"); | 1457 | config->setGroup("Directories"); |
1458 | 1458 | ||
1459 | QStringList list; | 1459 | QStringList list; |
1460 | QStringList::ConstIterator it; | 1460 | QStringList::ConstIterator it; |
1461 | list = config->readListEntry("prefixes"); | 1461 | list = config->readListEntry("prefixes"); |
1462 | for (it = list.begin(); it != list.end(); it++) | 1462 | for (it = list.begin(); it != list.end(); it++) |
1463 | addPrefix(*it); | 1463 | addPrefix(*it); |
1464 | 1464 | ||
1465 | // iterating over all entries in the group Directories | 1465 | // iterating over all entries in the group Directories |
1466 | // to find entries that start with dir_$type | 1466 | // to find entries that start with dir_$type |
1467 | /*US | 1467 | /*US |
1468 | QMap<QString, QString> entries = config->entryMap("Directories"); | 1468 | QMap<QString, QString> entries = config->entryMap("Directories"); |
1469 | 1469 | ||
1470 | QMap<QString, QString>::ConstIterator it2; | 1470 | QMap<QString, QString>::ConstIterator it2; |
1471 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1471 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1472 | { | 1472 | { |
1473 | QString key = it2.key(); | 1473 | QString key = it2.key(); |
1474 | if (key.left(4) == "dir_") { | 1474 | if (key.left(4) == "dir_") { |
1475 | // generate directory list, there may be more than 1. | 1475 | // generate directory list, there may be more than 1. |
1476 | QStringList dirs = QStringList::split(',', *it2); | 1476 | QStringList dirs = QStringList::split(',', *it2); |
1477 | QStringList::Iterator sIt(dirs.begin()); | 1477 | QStringList::Iterator sIt(dirs.begin()); |
1478 | QString resType = key.mid(4, key.length()); | 1478 | QString resType = key.mid(4, key.length()); |
1479 | for (; sIt != dirs.end(); ++sIt) { | 1479 | for (; sIt != dirs.end(); ++sIt) { |
1480 | addResourceDir(resType.latin1(), *sIt); | 1480 | addResourceDir(resType.latin1(), *sIt); |
1481 | } | 1481 | } |
1482 | } | 1482 | } |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | // Process KIOSK restrictions. | 1485 | // Process KIOSK restrictions. |
1486 | config->setGroup("KDE Resource Restrictions"); | 1486 | config->setGroup("KDE Resource Restrictions"); |
1487 | entries = config->entryMap("KDE Resource Restrictions"); | 1487 | entries = config->entryMap("KDE Resource Restrictions"); |
1488 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1488 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1489 | { | 1489 | { |
1490 | QString key = it2.key(); | 1490 | QString key = it2.key(); |
1491 | if (!config->readBoolEntry(key, true)) | 1491 | if (!config->readBoolEntry(key, true)) |
1492 | { | 1492 | { |
1493 | d->restrictionsActive = true; | 1493 | d->restrictionsActive = true; |
1494 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do | 1494 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do |
1495 | dircache.remove(key.latin1()); | 1495 | dircache.remove(key.latin1()); |
1496 | } | 1496 | } |
1497 | } | 1497 | } |
1498 | */ | 1498 | */ |
1499 | // save it for future calls - that will return | 1499 | // save it for future calls - that will return |
1500 | addedCustoms = true; | 1500 | addedCustoms = true; |
1501 | config->setGroup(oldGroup); | 1501 | config->setGroup(oldGroup); |
1502 | 1502 | ||
1503 | // return true if the number of config dirs changed | 1503 | // return true if the number of config dirs changed |
1504 | return (resourceDirs("config").count() != configdirs); | 1504 | return (resourceDirs("config").count() != configdirs); |
1505 | } | 1505 | } |
1506 | 1506 | ||
1507 | QString KStandardDirs::localkdedir() const | 1507 | QString KStandardDirs::localkdedir() const |
1508 | { | 1508 | { |
1509 | // Return the prefix to use for saving | 1509 | // Return the prefix to use for saving |
1510 | return prefixes.first(); | 1510 | return prefixes.first(); |
1511 | } | 1511 | } |
1512 | 1512 | ||
1513 | QString KStandardDirs::localxdgdatadir() const | 1513 | QString KStandardDirs::localxdgdatadir() const |
1514 | { | 1514 | { |
1515 | // Return the prefix to use for saving | 1515 | // Return the prefix to use for saving |
1516 | return d->xdgdata_prefixes.first(); | 1516 | return d->xdgdata_prefixes.first(); |
1517 | } | 1517 | } |
1518 | 1518 | ||
1519 | QString KStandardDirs::localxdgconfdir() const | 1519 | QString KStandardDirs::localxdgconfdir() const |
1520 | { | 1520 | { |
1521 | // Return the prefix to use for saving | 1521 | // Return the prefix to use for saving |
1522 | return d->xdgconf_prefixes.first(); | 1522 | return d->xdgconf_prefixes.first(); |
1523 | } | 1523 | } |
1524 | 1524 | ||
1525 | void KStandardDirs::setAppDir( const QString &appDir ) | 1525 | void KStandardDirs::setAppDir( const QString &appDir ) |
1526 | { | 1526 | { |
1527 | mAppDir = appDir; | 1527 | mAppDir = appDir; |
1528 | 1528 | ||
1529 | if ( mAppDir.right( 1 ) != "/" ) | 1529 | if ( mAppDir.right( 1 ) != "/" ) |
1530 | mAppDir += "/"; | 1530 | mAppDir += "/"; |
1531 | } | 1531 | } |
1532 | 1532 | ||
1533 | QString KStandardDirs::appDir() | 1533 | QString KStandardDirs::appDir() |
1534 | { | 1534 | { |
1535 | return mAppDir; | 1535 | return mAppDir; |
1536 | } | 1536 | } |
1537 | 1537 | ||
1538 | // just to make code more readable without macros | 1538 | // just to make code more readable without macros |
1539 | QString locate( const char *type, | 1539 | QString locate( const char *type, |
1540 | const QString& filename/*US , const KInstance* inst*/ ) | 1540 | const QString& filename/*US , const KInstance* inst*/ ) |
1541 | { | 1541 | { |
1542 | //US return inst->dirs()->findResource(type, filename); | 1542 | //US return inst->dirs()->findResource(type, filename); |
1543 | return KGlobal::dirs()->findResource(type, filename); | 1543 | return KGlobal::dirs()->findResource(type, filename); |
1544 | } | 1544 | } |
1545 | 1545 | ||
1546 | QString locateLocal( const char *type, | 1546 | QString locateLocal( const char *type, |
1547 | const QString& filename/*US , const KInstance* inst*/ ) | 1547 | const QString& filename/*US , const KInstance* inst*/ ) |
1548 | { | 1548 | { |
1549 | 1549 | ||
1550 | QString path = locateLocal(type, filename, true /*US, inst*/); | 1550 | QString path = locateLocal(type, filename, true /*US, inst*/); |
1551 | 1551 | ||
1552 | 1552 | ||
1553 | /* | 1553 | /* |
1554 | static int ccc = 0; | 1554 | static int ccc = 0; |
1555 | ++ccc; | 1555 | ++ccc; |
1556 | if ( ccc > 13 ) | 1556 | if ( ccc > 13 ) |
1557 | abort(); | 1557 | abort(); |
1558 | */ | 1558 | */ |
1559 | qDebug("locatelocal: %s" , path.latin1()); | 1559 | //qDebug("locatelocal: %s" , path.latin1()); |
1560 | return path; | 1560 | return path; |
1561 | 1561 | ||
1562 | /*US why do we put all files into one directory. It is quit complicated. | 1562 | /*US why do we put all files into one directory. It is quit complicated. |
1563 | why not staying with the original directorystructure ? | 1563 | why not staying with the original directorystructure ? |
1564 | 1564 | ||
1565 | 1565 | ||
1566 | QString escapedFilename = filename; | 1566 | QString escapedFilename = filename; |
1567 | escapedFilename.replace( QRegExp( "/" ), "_" ); | 1567 | escapedFilename.replace( QRegExp( "/" ), "_" ); |
1568 | 1568 | ||
1569 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; | 1569 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; |
1570 | 1570 | ||
1571 | kdDebug() << "locate: '" << path << "'" << endl; | 1571 | kdDebug() << "locate: '" << path << "'" << endl; |
1572 | qDebug("locate: %s" , path.latin1()); | 1572 | qDebug("locate: %s" , path.latin1()); |
1573 | return path; | 1573 | return path; |
1574 | */ | 1574 | */ |
1575 | //US so my proposal is this: | 1575 | //US so my proposal is this: |
1576 | 1576 | ||
1577 | // QString escapedFilename = filename; | 1577 | // QString escapedFilename = filename; |
1578 | // escapedFilename.replace( QRegExp( "/" ), "_" ); | 1578 | // escapedFilename.replace( QRegExp( "/" ), "_" ); |
1579 | 1579 | ||
1580 | #if 0 | 1580 | #if 0 |
1581 | #ifdef _WIN32_ | 1581 | #ifdef _WIN32_ |
1582 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); | 1582 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); |
1583 | #else | 1583 | #else |
1584 | QString path = KStandardDirs::appDir() + type + "/" + filename; | 1584 | QString path = KStandardDirs::appDir() + type + "/" + filename; |
1585 | #endif | 1585 | #endif |
1586 | 1586 | ||
1587 | //US Create the containing dir if needed | 1587 | //US Create the containing dir if needed |
1588 | QFileInfo fi ( path ); | 1588 | QFileInfo fi ( path ); |
1589 | 1589 | ||
1590 | // QString dir=pathurl.directory(); | 1590 | // QString dir=pathurl.directory(); |
1591 | //QMessageBox::information( 0,"path", path, 1 ); | 1591 | //QMessageBox::information( 0,"path", path, 1 ); |
1592 | 1592 | ||
1593 | #ifdef _WIN32_ | 1593 | #ifdef _WIN32_ |
1594 | KStandardDirs::makeDir(path); | 1594 | KStandardDirs::makeDir(path); |
1595 | #else | 1595 | #else |
1596 | KStandardDirs::makeDir(fi.dirPath( true )); | 1596 | KStandardDirs::makeDir(fi.dirPath( true )); |
1597 | #endif | 1597 | #endif |
1598 | 1598 | ||
1599 | qDebug("locate22: %s" , path.latin1()); | 1599 | qDebug("locate22: %s" , path.latin1()); |
1600 | return path; | 1600 | return path; |
1601 | 1601 | ||
1602 | #endif | 1602 | #endif |
1603 | 1603 | ||
1604 | } | 1604 | } |
1605 | 1605 | ||
1606 | QString locateLocal( const char *type, | 1606 | QString locateLocal( const char *type, |
1607 | const QString& filename, bool createDir/*US , const KInstance* inst*/ ) | 1607 | const QString& filename, bool createDir/*US , const KInstance* inst*/ ) |
1608 | { | 1608 | { |
1609 | // try to find slashes. If there are some, we have to | 1609 | // try to find slashes. If there are some, we have to |
1610 | // create the subdir first | 1610 | // create the subdir first |
1611 | int slash = filename.findRev('/')+1; | 1611 | int slash = filename.findRev('/')+1; |
1612 | if (!slash) // only one filename | 1612 | if (!slash) // only one filename |
1613 | //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; | 1613 | //USreturn inst->dirs()->saveLocation(type, QString::null, createDir) + filename; |
1614 | return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; | 1614 | return KGlobal::dirs()->saveLocation(type, QString::null, createDir) + filename; |
1615 | 1615 | ||
1616 | // split path from filename | 1616 | // split path from filename |
1617 | QString dir = filename.left(slash); | 1617 | QString dir = filename.left(slash); |
1618 | QString file = filename.mid(slash); | 1618 | QString file = filename.mid(slash); |
1619 | //US return inst->dirs()->saveLocation(type, dir, createDir) + file; | 1619 | //US return inst->dirs()->saveLocation(type, dir, createDir) + file; |
1620 | return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; | 1620 | return KGlobal::dirs()->saveLocation(type, dir, createDir) + file; |
1621 | 1621 | ||
1622 | // *************************************************************** | 1622 | // *************************************************************** |
1623 | #if 0 | 1623 | #if 0 |
1624 | 1624 | ||
1625 | /*US why do we put all files into one directory. It is quit complicated. | 1625 | /*US why do we put all files into one directory. It is quit complicated. |
1626 | why not staying with the original directorystructure ? | 1626 | why not staying with the original directorystructure ? |
1627 | 1627 | ||
1628 | 1628 | ||
1629 | QString escapedFilename = filename; | 1629 | QString escapedFilename = filename; |
1630 | escapedFilename.replace( QRegExp( "/" ), "_" ); | 1630 | escapedFilename.replace( QRegExp( "/" ), "_" ); |
1631 | 1631 | ||
1632 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; | 1632 | QString path = KStandardDirs::appDir() + type + "_" + escapedFilename; |
1633 | 1633 | ||
1634 | kdDebug() << "locate: '" << path << "'" << endl; | 1634 | kdDebug() << "locate: '" << path << "'" << endl; |
1635 | qDebug("locate: %s" , path.latin1()); | 1635 | qDebug("locate: %s" , path.latin1()); |
1636 | return path; | 1636 | return path; |
1637 | */ | 1637 | */ |
1638 | //US so my proposal is this: | 1638 | //US so my proposal is this: |
1639 | 1639 | ||
1640 | // QString escapedFilename = filename; | 1640 | // QString escapedFilename = filename; |
1641 | // escapedFilename.replace( QRegExp( "/" ), "_" ); | 1641 | // escapedFilename.replace( QRegExp( "/" ), "_" ); |
1642 | 1642 | ||
1643 | #ifdef _WIN32_ | 1643 | #ifdef _WIN32_ |
1644 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); | 1644 | QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename); |
1645 | #else | 1645 | #else |
1646 | QString path = KStandardDirs::appDir() + type + "/" + filename; | 1646 | QString path = KStandardDirs::appDir() + type + "/" + filename; |
1647 | #endif | 1647 | #endif |
1648 | 1648 | ||
1649 | //US Create the containing dir if needed | 1649 | //US Create the containing dir if needed |
1650 | KURL pathurl; | 1650 | KURL pathurl; |
1651 | pathurl.setPath(path); | 1651 | pathurl.setPath(path); |
1652 | QString dir=pathurl.directory(); | 1652 | QString dir=pathurl.directory(); |
1653 | //QMessageBox::information( 0,"path", path, 1 ); | 1653 | //QMessageBox::information( 0,"path", path, 1 ); |
1654 | #ifdef _WIN32_ | 1654 | #ifdef _WIN32_ |
1655 | KStandardDirs::makeDir(path); | 1655 | KStandardDirs::makeDir(path); |
1656 | #else | 1656 | #else |
1657 | KStandardDirs::makeDir(dir); | 1657 | KStandardDirs::makeDir(dir); |
1658 | #endif | 1658 | #endif |
1659 | 1659 | ||
1660 | return path; | 1660 | return path; |
1661 | #endif | 1661 | #endif |
1662 | } | 1662 | } |
diff --git a/microkde/kdeui/kactioncollection.cpp b/microkde/kdeui/kactioncollection.cpp index b819e76..69e5d02 100644 --- a/microkde/kdeui/kactioncollection.cpp +++ b/microkde/kdeui/kactioncollection.cpp | |||
@@ -1,839 +1,840 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> | 2 | Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> |
3 | (C) 1999 Simon Hausmann <hausmann@kde.org> | 3 | (C) 1999 Simon Hausmann <hausmann@kde.org> |
4 | (C) 2000 Nicolas Hadacek <haadcek@kde.org> | 4 | (C) 2000 Nicolas Hadacek <haadcek@kde.org> |
5 | (C) 2000 Kurt Granroth <granroth@kde.org> | 5 | (C) 2000 Kurt Granroth <granroth@kde.org> |
6 | (C) 2000 Michael Koch <koch@kde.org> | 6 | (C) 2000 Michael Koch <koch@kde.org> |
7 | (C) 2001 Holger Freyther <freyther@kde.org> | 7 | (C) 2001 Holger Freyther <freyther@kde.org> |
8 | (C) 2002 Ellis Whitehead <ellis@kde.org> | 8 | (C) 2002 Ellis Whitehead <ellis@kde.org> |
9 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | 9 | (C) 2002 Joseph Wenninger <jowenn@kde.org> |
10 | 10 | ||
11 | This library is free software; you can redistribute it and/or | 11 | This library is free software; you can redistribute it and/or |
12 | modify it under the terms of the GNU Library General Public | 12 | modify it under the terms of the GNU Library General Public |
13 | License version 2 as published by the Free Software Foundation. | 13 | License version 2 as published by the Free Software Foundation. |
14 | 14 | ||
15 | This library is distributed in the hope that it will be useful, | 15 | This library is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | Library General Public License for more details. | 18 | Library General Public License for more details. |
19 | 19 | ||
20 | You should have received a copy of the GNU Library General Public License | 20 | You should have received a copy of the GNU Library General Public License |
21 | along with this library; see the file COPYING.LIB. If not, write to | 21 | along with this library; see the file COPYING.LIB. If not, write to |
22 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 22 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
23 | Boston, MA 02111-1307, USA. | 23 | Boston, MA 02111-1307, USA. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "kactioncollection.h" | 26 | #include "kactioncollection.h" |
27 | //US#include "kactionshortcutlist.h" | 27 | //US#include "kactionshortcutlist.h" |
28 | 28 | ||
29 | #include <qptrdict.h> | 29 | #include <qptrdict.h> |
30 | //US#include <qvariant.h> | 30 | //US#include <qvariant.h> |
31 | 31 | ||
32 | //US#include <kaccel.h> | 32 | //US#include <kaccel.h> |
33 | //US#include <kaccelbase.h> | 33 | //US#include <kaccelbase.h> |
34 | //US#include <kapplication.h> | 34 | //US#include <kapplication.h> |
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | //US#include <kxmlguifactory.h> | 36 | //US#include <kxmlguifactory.h> |
37 | 37 | ||
38 | //US I included the following files | 38 | //US I included the following files |
39 | #include <qasciidict.h> | 39 | #include <qasciidict.h> |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include "kaction.h" | 41 | #include "kaction.h" |
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | #include <qobject.h> | 43 | #include <qobject.h> |
44 | #include <qwidget.h> | 44 | #include <qwidget.h> |
45 | 45 | ||
46 | class KActionCollection::KActionCollectionPrivate | 46 | class KActionCollection::KActionCollectionPrivate |
47 | { | 47 | { |
48 | public: | 48 | public: |
49 | KActionCollectionPrivate() | 49 | KActionCollectionPrivate() |
50 | { | 50 | { |
51 | //US m_instance = 0; | 51 | //US m_instance = 0; |
52 | //m_bOneKAccelOnly = false; | 52 | //m_bOneKAccelOnly = false; |
53 | //m_iWidgetCurrent = 0; | 53 | //m_iWidgetCurrent = 0; |
54 | m_bAutoConnectShortcuts = true; | 54 | m_bAutoConnectShortcuts = true; |
55 | m_widget = 0; | 55 | m_widget = 0; |
56 | m_kaccel = m_builderKAccel = 0; | 56 | m_kaccel = m_builderKAccel = 0; |
57 | m_dctHighlightContainers.setAutoDelete( true ); | 57 | m_dctHighlightContainers.setAutoDelete( true ); |
58 | m_highlight = false; | 58 | m_highlight = false; |
59 | m_currentHighlightAction = 0; | 59 | m_currentHighlightAction = 0; |
60 | m_statusCleared = true; | 60 | m_statusCleared = true; |
61 | } | 61 | } |
62 | 62 | ||
63 | //US KInstance *m_instance; | 63 | //US KInstance *m_instance; |
64 | //US QString m_sXMLFile; | 64 | //US QString m_sXMLFile; |
65 | bool m_bAutoConnectShortcuts; | 65 | bool m_bAutoConnectShortcuts; |
66 | //bool m_bOneKAccelOnly; | 66 | //bool m_bOneKAccelOnly; |
67 | //int m_iWidgetCurrent; | 67 | //int m_iWidgetCurrent; |
68 | //QValueList<QWidget*> m_widgetList; | 68 | //QValueList<QWidget*> m_widgetList; |
69 | //QValueList<KAccel*> m_kaccelList; | 69 | //QValueList<KAccel*> m_kaccelList; |
70 | QValueList<KActionCollection*> m_docList; | 70 | QValueList<KActionCollection*> m_docList; |
71 | QWidget *m_widget; | 71 | QWidget *m_widget; |
72 | KAccel *m_kaccel; | 72 | KAccel *m_kaccel; |
73 | KAccel *m_builderKAccel; | 73 | KAccel *m_builderKAccel; |
74 | 74 | ||
75 | QAsciiDict<KAction> m_actionDict; | 75 | QAsciiDict<KAction> m_actionDict; |
76 | QPtrDict< QPtrList<KAction> > m_dctHighlightContainers; | 76 | QPtrDict< QPtrList<KAction> > m_dctHighlightContainers; |
77 | bool m_highlight; | 77 | bool m_highlight; |
78 | KAction *m_currentHighlightAction; | 78 | KAction *m_currentHighlightAction; |
79 | bool m_statusCleared; | 79 | bool m_statusCleared; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | KActionCollection::KActionCollection( QWidget *parent, const char *name /*US, | 82 | KActionCollection::KActionCollection( QWidget *parent, const char *name /*US, |
83 | KInstance *instance */) | 83 | KInstance *instance */) |
84 | : QObject( (QObject*)parent, name ) | 84 | : QObject( (QObject*)parent, name ) |
85 | { | 85 | { |
86 | kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis | 86 | kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis |
87 | d = new KActionCollectionPrivate; | 87 | d = new KActionCollectionPrivate; |
88 | if( parent ) | 88 | if( parent ) |
89 | setWidget( parent ); | 89 | setWidget( parent ); |
90 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); | 90 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); |
91 | //US setInstance( instance ); | 91 | //US setInstance( instance ); |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | KActionCollection::KActionCollection( QWidget *watch, QObject* parent, const char *name /*US, | 95 | KActionCollection::KActionCollection( QWidget *watch, QObject* parent, const char *name /*US, |
96 | KInstance *instance */) | 96 | KInstance *instance */) |
97 | : QObject( parent, name ) | 97 | : QObject( parent, name ) |
98 | { | 98 | { |
99 | kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis | 99 | kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis |
100 | d = new KActionCollectionPrivate; | 100 | d = new KActionCollectionPrivate; |
101 | if( watch ) | 101 | if( watch ) |
102 | setWidget( watch ); | 102 | setWidget( watch ); |
103 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); | 103 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); |
104 | //US setInstance( instance ); | 104 | //US setInstance( instance ); |
105 | } | 105 | } |
106 | 106 | ||
107 | // KDE 4: remove | 107 | // KDE 4: remove |
108 | KActionCollection::KActionCollection( QObject *parent, const char *name /*US, | 108 | KActionCollection::KActionCollection( QObject *parent, const char *name /*US, |
109 | KInstance *instance */) | 109 | KInstance *instance */) |
110 | : QObject( parent, name ) | 110 | : QObject( parent, name ) |
111 | { | 111 | { |
112 | kdWarning(129) << "KActionCollection::KActionCollection( QObject *parent, const char *name, KInstance *instance )" << endl; //ellis | 112 | kdWarning(129) << "KActionCollection::KActionCollection( QObject *parent, const char *name, KInstance *instance )" << endl; //ellis |
113 | //US kdBacktrace not available | 113 | //US kdBacktrace not available |
114 | //US kdDebug(129) << kdBacktrace() << endl; | 114 | //US kdDebug(129) << kdBacktrace() << endl; |
115 | d = new KActionCollectionPrivate; | 115 | d = new KActionCollectionPrivate; |
116 | //US QWidget* w = dynamic_cast<QWidget*>( parent ); | 116 | //US QWidget* w = dynamic_cast<QWidget*>( parent ); |
117 | QWidget* w = (QWidget*)( parent ); | 117 | QWidget* w = (QWidget*)( parent ); |
118 | if( w ) | 118 | if( w ) |
119 | setWidget( w ); | 119 | setWidget( w ); |
120 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); | 120 | //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0); |
121 | //US setInstance( instance ); | 121 | //US setInstance( instance ); |
122 | } | 122 | } |
123 | 123 | ||
124 | KActionCollection::KActionCollection( const KActionCollection © ) | 124 | KActionCollection::KActionCollection( const KActionCollection © ) |
125 | : QObject() | 125 | : QObject() |
126 | { | 126 | { |
127 | kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl; | 127 | kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl; |
128 | d = new KActionCollectionPrivate; | 128 | d = new KActionCollectionPrivate; |
129 | *this = copy; | 129 | *this = copy; |
130 | } | 130 | } |
131 | // KDE 4: remove end | 131 | // KDE 4: remove end |
132 | 132 | ||
133 | KActionCollection::~KActionCollection() | 133 | KActionCollection::~KActionCollection() |
134 | { | 134 | { |
135 | kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl; | 135 | kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl; |
136 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { | 136 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { |
137 | KAction* pAction = it.current(); | 137 | KAction* pAction = it.current(); |
138 | if ( pAction->m_parentCollection == this ) | 138 | if ( pAction->m_parentCollection == this ) |
139 | pAction->m_parentCollection = 0L; | 139 | pAction->m_parentCollection = 0L; |
140 | } | 140 | } |
141 | 141 | ||
142 | //US delete d->m_kaccel; | 142 | //US delete d->m_kaccel; |
143 | //US delete d->m_builderKAccel; | 143 | //US delete d->m_builderKAccel; |
144 | delete d; d = 0; | 144 | delete d; d = 0; |
145 | } | 145 | } |
146 | 146 | ||
147 | void KActionCollection::setWidget( QWidget* w ) | 147 | void KActionCollection::setWidget( QWidget* w ) |
148 | { | 148 | { |
149 | //if ( d->m_actionDict.count() > 0 ) { | 149 | //if ( d->m_actionDict.count() > 0 ) { |
150 | // kdError(129) << "KActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; | 150 | // kdError(129) << "KActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; |
151 | // kdDebug(129) << kdBacktrace() << endl; | 151 | // kdDebug(129) << kdBacktrace() << endl; |
152 | //} | 152 | //} |
153 | //else | 153 | //else |
154 | if ( !d->m_widget ) { | 154 | if ( !d->m_widget ) { |
155 | d->m_widget = w; | 155 | d->m_widget = w; |
156 | qDebug("KActionCollection::setWidget: warning: KAccel is never used in microkde"); | 156 | //qDebug("KActionCollection::setWidget: warning: KAccel is never used in microkde"); |
157 | //US d->m_kaccel = new KAccel( w, this, "KActionCollection-KAccel" ); | 157 | //US d->m_kaccel = new KAccel( w, this, "KActionCollection-KAccel" ); |
158 | } | 158 | } |
159 | else if ( d->m_widget != w ) | 159 | else if ( d->m_widget != w ) |
160 | kdWarning(129) << "KActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl; | 160 | ; |
161 | |||
161 | } | 162 | } |
162 | 163 | ||
163 | void KActionCollection::setAutoConnectShortcuts( bool b ) | 164 | void KActionCollection::setAutoConnectShortcuts( bool b ) |
164 | { | 165 | { |
165 | d->m_bAutoConnectShortcuts = b; | 166 | d->m_bAutoConnectShortcuts = b; |
166 | } | 167 | } |
167 | 168 | ||
168 | bool KActionCollection::isAutoConnectShortcuts() | 169 | bool KActionCollection::isAutoConnectShortcuts() |
169 | { | 170 | { |
170 | return d->m_bAutoConnectShortcuts; | 171 | return d->m_bAutoConnectShortcuts; |
171 | } | 172 | } |
172 | 173 | ||
173 | bool KActionCollection::addDocCollection( KActionCollection* pDoc ) | 174 | bool KActionCollection::addDocCollection( KActionCollection* pDoc ) |
174 | { | 175 | { |
175 | d->m_docList.append( pDoc ); | 176 | d->m_docList.append( pDoc ); |
176 | return true; | 177 | return true; |
177 | } | 178 | } |
178 | 179 | ||
179 | void KActionCollection::beginXMLPlug( QWidget *widget ) | 180 | void KActionCollection::beginXMLPlug( QWidget *widget ) |
180 | { | 181 | { |
181 | qDebug("KActionCollection::beginXMLPlug has to be fixed"); | 182 | qDebug("KActionCollection::beginXMLPlug has to be fixed"); |
182 | /*US | 183 | /*US |
183 | kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl; | 184 | kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl; |
184 | 185 | ||
185 | if( widget && !d->m_builderKAccel ) { | 186 | if( widget && !d->m_builderKAccel ) { |
186 | d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" ); | 187 | d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" ); |
187 | } | 188 | } |
188 | */ | 189 | */ |
189 | } | 190 | } |
190 | 191 | ||
191 | void KActionCollection::endXMLPlug() | 192 | void KActionCollection::endXMLPlug() |
192 | { | 193 | { |
193 | kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl; | 194 | kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl; |
194 | //s_kaccelXML = 0; | 195 | //s_kaccelXML = 0; |
195 | } | 196 | } |
196 | 197 | ||
197 | void KActionCollection::prepareXMLUnplug() | 198 | void KActionCollection::prepareXMLUnplug() |
198 | { | 199 | { |
199 | qDebug("KActionCollection::prepareXMLUnplug has to be fixed"); | 200 | qDebug("KActionCollection::prepareXMLUnplug has to be fixed"); |
200 | /*US | 201 | /*US |
201 | kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl; | 202 | kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl; |
202 | unplugShortcuts( d->m_kaccel ); | 203 | unplugShortcuts( d->m_kaccel ); |
203 | 204 | ||
204 | if( d->m_builderKAccel ) { | 205 | if( d->m_builderKAccel ) { |
205 | unplugShortcuts( d->m_builderKAccel ); | 206 | unplugShortcuts( d->m_builderKAccel ); |
206 | delete d->m_builderKAccel; | 207 | delete d->m_builderKAccel; |
207 | d->m_builderKAccel = 0; | 208 | d->m_builderKAccel = 0; |
208 | } | 209 | } |
209 | */ | 210 | */ |
210 | } | 211 | } |
211 | 212 | ||
212 | void KActionCollection::unplugShortcuts( KAccel* kaccel ) | 213 | void KActionCollection::unplugShortcuts( KAccel* kaccel ) |
213 | { | 214 | { |
214 | qDebug("KActionCollection::unplugShortcuts has to be fixed"); | 215 | qDebug("KActionCollection::unplugShortcuts has to be fixed"); |
215 | /*US | 216 | /*US |
216 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { | 217 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { |
217 | KAction* pAction = it.current(); | 218 | KAction* pAction = it.current(); |
218 | pAction->removeKAccel( kaccel ); | 219 | pAction->removeKAccel( kaccel ); |
219 | } | 220 | } |
220 | 221 | ||
221 | for( uint i = 0; i < d->m_docList.count(); i++ ) | 222 | for( uint i = 0; i < d->m_docList.count(); i++ ) |
222 | d->m_docList[i]->unplugShortcuts( kaccel ); | 223 | d->m_docList[i]->unplugShortcuts( kaccel ); |
223 | */ | 224 | */ |
224 | 225 | ||
225 | } | 226 | } |
226 | 227 | ||
227 | /*void KActionCollection::addWidget( QWidget* w ) | 228 | /*void KActionCollection::addWidget( QWidget* w ) |
228 | { | 229 | { |
229 | if( !d->m_bOneKAccelOnly ) { | 230 | if( !d->m_bOneKAccelOnly ) { |
230 | kdDebug(129) << "KActionCollection::addWidget( " << w << " ): this = " << this << endl; | 231 | kdDebug(129) << "KActionCollection::addWidget( " << w << " ): this = " << this << endl; |
231 | for( uint i = 0; i < d->m_widgetList.count(); i++ ) { | 232 | for( uint i = 0; i < d->m_widgetList.count(); i++ ) { |
232 | if( d->m_widgetList[i] == w ) { | 233 | if( d->m_widgetList[i] == w ) { |
233 | d->m_iWidgetCurrent = i; | 234 | d->m_iWidgetCurrent = i; |
234 | return; | 235 | return; |
235 | } | 236 | } |
236 | } | 237 | } |
237 | d->m_iWidgetCurrent = d->m_widgetList.count(); | 238 | d->m_iWidgetCurrent = d->m_widgetList.count(); |
238 | d->m_widgetList.append( w ); | 239 | d->m_widgetList.append( w ); |
239 | d->m_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) ); | 240 | d->m_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) ); |
240 | } | 241 | } |
241 | } | 242 | } |
242 | 243 | ||
243 | void KActionCollection::removeWidget( QWidget* w ) | 244 | void KActionCollection::removeWidget( QWidget* w ) |
244 | { | 245 | { |
245 | if( !d->m_bOneKAccelOnly ) { | 246 | if( !d->m_bOneKAccelOnly ) { |
246 | kdDebug(129) << "KActionCollection::removeWidget( " << w << " ): this = " << this << endl; | 247 | kdDebug(129) << "KActionCollection::removeWidget( " << w << " ): this = " << this << endl; |
247 | for( uint i = 0; i < d->m_widgetList.count(); i++ ) { | 248 | for( uint i = 0; i < d->m_widgetList.count(); i++ ) { |
248 | if( d->m_widgetList[i] == w ) { | 249 | if( d->m_widgetList[i] == w ) { |
249 | // Remove KAccel object from children. | 250 | // Remove KAccel object from children. |
250 | KAccel* pKAccel = d->m_kaccelList[i]; | 251 | KAccel* pKAccel = d->m_kaccelList[i]; |
251 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { | 252 | for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) { |
252 | KAction* pAction = it.current(); | 253 | KAction* pAction = it.current(); |
253 | if ( pAction->m_parentCollection == this ) { | 254 | if ( pAction->m_parentCollection == this ) { |
254 | pAction->removeKAccel( pKAccel ); | 255 | pAction->removeKAccel( pKAccel ); |
255 | } | 256 | } |
256 | } | 257 | } |
257 | delete pKAccel; | 258 | delete pKAccel; |
258 | 259 | ||
259 | d->m_widgetList.remove( d->m_widgetList.at( i ) ); | 260 | d->m_widgetList.remove( d->m_widgetList.at( i ) ); |
260 | d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); | 261 | d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); |
261 | 262 | ||
262 | if( d->m_iWidgetCurrent == (int)i ) | 263 | if( d->m_iWidgetCurrent == (int)i ) |
263 | d->m_iWidgetCurrent = -1; | 264 | d->m_iWidgetCurrent = -1; |
264 | else if( d->m_iWidgetCurrent > (int)i ) | 265 | else if( d->m_iWidgetCurrent > (int)i ) |
265 | d->m_iWidgetCurrent--; | 266 | d->m_iWidgetCurrent--; |
266 | return; | 267 | return; |
267 | } | 268 | } |
268 | } | 269 | } |
269 | kdWarning(129) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl; | 270 | kdWarning(129) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl; |
270 | } | 271 | } |
271 | } | 272 | } |
272 | 273 | ||
273 | bool KActionCollection::ownsKAccel() const | 274 | bool KActionCollection::ownsKAccel() const |
274 | { | 275 | { |
275 | return d->m_bOneKAccelOnly; | 276 | return d->m_bOneKAccelOnly; |
276 | } | 277 | } |
277 | 278 | ||
278 | uint KActionCollection::widgetCount() const | 279 | uint KActionCollection::widgetCount() const |
279 | { | 280 | { |
280 | return d->m_widgetList.count(); | 281 | return d->m_widgetList.count(); |
281 | } | 282 | } |
282 | 283 | ||
283 | const KAccel* KActionCollection::widgetKAccel( uint i ) const | 284 | const KAccel* KActionCollection::widgetKAccel( uint i ) const |
284 | { | 285 | { |
285 | return d->m_kaccelList[i]; | 286 | return d->m_kaccelList[i]; |
286 | }*/ | 287 | }*/ |
287 | 288 | ||
288 | //US we are using no accelerators so far. So just setup an empty implementation. | 289 | //US we are using no accelerators so far. So just setup an empty implementation. |
289 | KAccel* KActionCollection::kaccel() | 290 | KAccel* KActionCollection::kaccel() |
290 | { | 291 | { |
291 | //if( d->m_kaccelList.count() > 0 ) | 292 | //if( d->m_kaccelList.count() > 0 ) |
292 | // return d->m_kaccelList[d->m_iWidgetCurrent]; | 293 | // return d->m_kaccelList[d->m_iWidgetCurrent]; |
293 | //else | 294 | //else |
294 | // return 0; | 295 | // return 0; |
295 | //US return d->m_kaccel; | 296 | //US return d->m_kaccel; |
296 | return 0; | 297 | return 0; |
297 | } | 298 | } |
298 | 299 | ||
299 | //US we are using no accelerators so far. So just setup an empty implementation. | 300 | //US we are using no accelerators so far. So just setup an empty implementation. |
300 | const KAccel* KActionCollection::kaccel() const | 301 | const KAccel* KActionCollection::kaccel() const |
301 | { | 302 | { |
302 | //if( d->m_kaccelList.count() > 0 ) | 303 | //if( d->m_kaccelList.count() > 0 ) |
303 | // return d->m_kaccelList[d->m_iWidgetCurrent]; | 304 | // return d->m_kaccelList[d->m_iWidgetCurrent]; |
304 | //else | 305 | //else |
305 | // return 0; | 306 | // return 0; |
306 | //USreturn d->m_kaccel; | 307 | //USreturn d->m_kaccel; |
307 | return 0; | 308 | return 0; |
308 | } | 309 | } |
309 | 310 | ||
310 | /*void KActionCollection::findMainWindow( QWidget *w ) | 311 | /*void KActionCollection::findMainWindow( QWidget *w ) |
311 | { | 312 | { |
312 | // Note: topLevelWidget() stops too early, we can't use it. | 313 | // Note: topLevelWidget() stops too early, we can't use it. |
313 | QWidget * tl = w; | 314 | QWidget * tl = w; |
314 | while ( tl->parentWidget() ) // lookup parent and store | 315 | while ( tl->parentWidget() ) // lookup parent and store |
315 | tl = tl->parentWidget(); | 316 | tl = tl->parentWidget(); |
316 | 317 | ||
317 | KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow | 318 | KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow |
318 | if (mw) | 319 | if (mw) |
319 | d->m_mainwindow = mw; | 320 | d->m_mainwindow = mw; |
320 | else | 321 | else |
321 | kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl; | 322 | kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl; |
322 | }*/ | 323 | }*/ |
323 | 324 | ||
324 | void KActionCollection::_insert( KAction* action ) | 325 | void KActionCollection::_insert( KAction* action ) |
325 | { | 326 | { |
326 | char unnamed_name[100]; | 327 | char unnamed_name[100]; |
327 | const char *name = action->name(); | 328 | const char *name = action->name(); |
328 | if( qstrcmp( name, "unnamed" ) == 0 ) | 329 | if( qstrcmp( name, "unnamed" ) == 0 ) |
329 | { | 330 | { |
330 | sprintf(unnamed_name, "unnamed-%p", (void *)action); | 331 | sprintf(unnamed_name, "unnamed-%p", (void *)action); |
331 | name = unnamed_name; | 332 | name = unnamed_name; |
332 | } | 333 | } |
333 | KAction *a = d->m_actionDict[ name ]; | 334 | KAction *a = d->m_actionDict[ name ]; |
334 | if ( a == action ) | 335 | if ( a == action ) |
335 | return; | 336 | return; |
336 | 337 | ||
337 | d->m_actionDict.insert( name, action ); | 338 | d->m_actionDict.insert( name, action ); |
338 | 339 | ||
339 | emit inserted( action ); | 340 | emit inserted( action ); |
340 | } | 341 | } |
341 | 342 | ||
342 | void KActionCollection::_remove( KAction* action ) | 343 | void KActionCollection::_remove( KAction* action ) |
343 | { | 344 | { |
344 | delete _take( action ); | 345 | delete _take( action ); |
345 | } | 346 | } |
346 | 347 | ||
347 | KAction* KActionCollection::_take( KAction* action ) | 348 | KAction* KActionCollection::_take( KAction* action ) |
348 | { | 349 | { |
349 | char unnamed_name[100]; | 350 | char unnamed_name[100]; |
350 | const char *name = action->name(); | 351 | const char *name = action->name(); |
351 | if( qstrcmp( name, "unnamed" ) == 0 ) | 352 | if( qstrcmp( name, "unnamed" ) == 0 ) |
352 | { | 353 | { |
353 | sprintf(unnamed_name, "unnamed-%p", (void *) action); | 354 | sprintf(unnamed_name, "unnamed-%p", (void *) action); |
354 | name = unnamed_name; | 355 | name = unnamed_name; |
355 | } | 356 | } |
356 | 357 | ||
357 | KAction *a = d->m_actionDict.take( name ); | 358 | KAction *a = d->m_actionDict.take( name ); |
358 | if ( !a || a != action ) | 359 | if ( !a || a != action ) |
359 | return 0; | 360 | return 0; |
360 | 361 | ||
361 | emit removed( action ); | 362 | emit removed( action ); |
362 | return a; | 363 | return a; |
363 | } | 364 | } |
364 | 365 | ||
365 | void KActionCollection::_clear() | 366 | void KActionCollection::_clear() |
366 | { | 367 | { |
367 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 368 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
368 | while ( it.current() ) | 369 | while ( it.current() ) |
369 | _remove( it.current() ); | 370 | _remove( it.current() ); |
370 | } | 371 | } |
371 | 372 | ||
372 | void KActionCollection::insert( KAction* action ) { _insert( action ); } | 373 | void KActionCollection::insert( KAction* action ) { _insert( action ); } |
373 | void KActionCollection::remove( KAction* action ) { _remove( action ); } | 374 | void KActionCollection::remove( KAction* action ) { _remove( action ); } |
374 | KAction* KActionCollection::take( KAction* action ) { return _take( action ); } | 375 | KAction* KActionCollection::take( KAction* action ) { return _take( action ); } |
375 | void KActionCollection::clear() { _clear(); } | 376 | void KActionCollection::clear() { _clear(); } |
376 | KAccel* KActionCollection::accel() { return kaccel(); } | 377 | KAccel* KActionCollection::accel() { return kaccel(); } |
377 | const KAccel* KActionCollection::accel() const { return kaccel(); } | 378 | const KAccel* KActionCollection::accel() const { return kaccel(); } |
378 | KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; } | 379 | KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; } |
379 | 380 | ||
380 | KAction* KActionCollection::action( const char* name, const char* classname ) const | 381 | KAction* KActionCollection::action( const char* name, const char* classname ) const |
381 | { | 382 | { |
382 | KAction* pAction = 0; | 383 | KAction* pAction = 0; |
383 | 384 | ||
384 | if ( !classname && name ) | 385 | if ( !classname && name ) |
385 | pAction = d->m_actionDict[ name ]; | 386 | pAction = d->m_actionDict[ name ]; |
386 | 387 | ||
387 | else { | 388 | else { |
388 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 389 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
389 | for( ; it.current(); ++it ) | 390 | for( ; it.current(); ++it ) |
390 | { | 391 | { |
391 | if ( ( !name || strcmp( it.current()->name(), name ) == 0 ) && | 392 | if ( ( !name || strcmp( it.current()->name(), name ) == 0 ) && |
392 | ( !classname || strcmp( it.current()->className(), classname ) == 0 ) ) { | 393 | ( !classname || strcmp( it.current()->className(), classname ) == 0 ) ) { |
393 | pAction = it.current(); | 394 | pAction = it.current(); |
394 | break; | 395 | break; |
395 | } | 396 | } |
396 | } | 397 | } |
397 | } | 398 | } |
398 | 399 | ||
399 | if( !pAction ) { | 400 | if( !pAction ) { |
400 | for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) | 401 | for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) |
401 | pAction = d->m_docList[i]->action( name, classname ); | 402 | pAction = d->m_docList[i]->action( name, classname ); |
402 | } | 403 | } |
403 | 404 | ||
404 | return pAction; | 405 | return pAction; |
405 | } | 406 | } |
406 | 407 | ||
407 | KAction* KActionCollection::action( int index ) const | 408 | KAction* KActionCollection::action( int index ) const |
408 | { | 409 | { |
409 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 410 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
410 | it += index; | 411 | it += index; |
411 | return it.current(); | 412 | return it.current(); |
412 | // return d->m_actions.at( index ); | 413 | // return d->m_actions.at( index ); |
413 | } | 414 | } |
414 | /*US | 415 | /*US |
415 | bool KActionCollection::readShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) | 416 | bool KActionCollection::readShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) |
416 | { | 417 | { |
417 | return KActionShortcutList(this).readSettings( sConfigGroup, pConfig ); | 418 | return KActionShortcutList(this).readSettings( sConfigGroup, pConfig ); |
418 | } | 419 | } |
419 | 420 | ||
420 | bool KActionCollection::writeShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) const | 421 | bool KActionCollection::writeShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) const |
421 | { | 422 | { |
422 | return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig ); | 423 | return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig ); |
423 | } | 424 | } |
424 | */ | 425 | */ |
425 | uint KActionCollection::count() const | 426 | uint KActionCollection::count() const |
426 | { | 427 | { |
427 | return d->m_actionDict.count(); | 428 | return d->m_actionDict.count(); |
428 | } | 429 | } |
429 | 430 | ||
430 | QStringList KActionCollection::groups() const | 431 | QStringList KActionCollection::groups() const |
431 | { | 432 | { |
432 | QStringList lst; | 433 | QStringList lst; |
433 | 434 | ||
434 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 435 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
435 | for( ; it.current(); ++it ) | 436 | for( ; it.current(); ++it ) |
436 | if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) | 437 | if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) |
437 | lst.append( it.current()->group() ); | 438 | lst.append( it.current()->group() ); |
438 | 439 | ||
439 | return lst; | 440 | return lst; |
440 | } | 441 | } |
441 | 442 | ||
442 | KActionPtrList KActionCollection::actions( const QString& group ) const | 443 | KActionPtrList KActionCollection::actions( const QString& group ) const |
443 | { | 444 | { |
444 | KActionPtrList lst; | 445 | KActionPtrList lst; |
445 | 446 | ||
446 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 447 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
447 | for( ; it.current(); ++it ) | 448 | for( ; it.current(); ++it ) |
448 | if ( it.current()->group() == group ) | 449 | if ( it.current()->group() == group ) |
449 | lst.append( it.current() ); | 450 | lst.append( it.current() ); |
450 | else if ( it.current()->group().isEmpty() && group.isEmpty() ) | 451 | else if ( it.current()->group().isEmpty() && group.isEmpty() ) |
451 | lst.append( it.current() ); | 452 | lst.append( it.current() ); |
452 | 453 | ||
453 | return lst; | 454 | return lst; |
454 | } | 455 | } |
455 | 456 | ||
456 | KActionPtrList KActionCollection::actions() const | 457 | KActionPtrList KActionCollection::actions() const |
457 | { | 458 | { |
458 | KActionPtrList lst; | 459 | KActionPtrList lst; |
459 | 460 | ||
460 | QAsciiDictIterator<KAction> it( d->m_actionDict ); | 461 | QAsciiDictIterator<KAction> it( d->m_actionDict ); |
461 | for( ; it.current(); ++it ) | 462 | for( ; it.current(); ++it ) |
462 | lst.append( it.current() ); | 463 | lst.append( it.current() ); |
463 | 464 | ||
464 | return lst; | 465 | return lst; |
465 | } | 466 | } |
466 | 467 | ||
467 | /*US we have no instance object. Use KGlobal instead | 468 | /*US we have no instance object. Use KGlobal instead |
468 | void KActionCollection::setInstance( KInstance *instance ) | 469 | void KActionCollection::setInstance( KInstance *instance ) |
469 | { | 470 | { |
470 | if ( instance ) | 471 | if ( instance ) |
471 | d->m_instance = instance; | 472 | d->m_instance = instance; |
472 | qDebug("KActionCollection::setInstance has to be fixed"); | 473 | qDebug("KActionCollection::setInstance has to be fixed"); |
473 | else | 474 | else |
474 | d->m_instance = KGlobal::instance(); | 475 | d->m_instance = KGlobal::instance(); |
475 | } | 476 | } |
476 | 477 | ||
477 | KInstance *KActionCollection::instance() const | 478 | KInstance *KActionCollection::instance() const |
478 | { | 479 | { |
479 | return d->m_instance; | 480 | return d->m_instance; |
480 | } | 481 | } |
481 | */ | 482 | */ |
482 | 483 | ||
483 | /*US we have no XML facility in microkde | 484 | /*US we have no XML facility in microkde |
484 | void KActionCollection::setXMLFile( const QString& sXMLFile ) | 485 | void KActionCollection::setXMLFile( const QString& sXMLFile ) |
485 | { | 486 | { |
486 | d->m_sXMLFile = sXMLFile; | 487 | d->m_sXMLFile = sXMLFile; |
487 | } | 488 | } |
488 | 489 | ||
489 | const QString& KActionCollection::xmlFile() const | 490 | const QString& KActionCollection::xmlFile() const |
490 | { | 491 | { |
491 | return d->m_sXMLFile; | 492 | return d->m_sXMLFile; |
492 | } | 493 | } |
493 | */ | 494 | */ |
494 | 495 | ||
495 | void KActionCollection::setHighlightingEnabled( bool enable ) | 496 | void KActionCollection::setHighlightingEnabled( bool enable ) |
496 | { | 497 | { |
497 | d->m_highlight = enable; | 498 | d->m_highlight = enable; |
498 | } | 499 | } |
499 | 500 | ||
500 | bool KActionCollection::highlightingEnabled() const | 501 | bool KActionCollection::highlightingEnabled() const |
501 | { | 502 | { |
502 | return d->m_highlight; | 503 | return d->m_highlight; |
503 | } | 504 | } |
504 | 505 | ||
505 | void KActionCollection::connectHighlight( QWidget *container, KAction *action ) | 506 | void KActionCollection::connectHighlight( QWidget *container, KAction *action ) |
506 | { | 507 | { |
507 | if ( !d->m_highlight ) | 508 | if ( !d->m_highlight ) |
508 | return; | 509 | return; |
509 | 510 | ||
510 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; | 511 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; |
511 | 512 | ||
512 | if ( !actionList ) | 513 | if ( !actionList ) |
513 | { | 514 | { |
514 | actionList = new QPtrList<KAction>; | 515 | actionList = new QPtrList<KAction>; |
515 | 516 | ||
516 | if ( container->inherits( "QPopupMenu" ) ) | 517 | if ( container->inherits( "QPopupMenu" ) ) |
517 | { | 518 | { |
518 | connect( container, SIGNAL( highlighted( int ) ), | 519 | connect( container, SIGNAL( highlighted( int ) ), |
519 | this, SLOT( slotMenuItemHighlighted( int ) ) ); | 520 | this, SLOT( slotMenuItemHighlighted( int ) ) ); |
520 | connect( container, SIGNAL( aboutToHide() ), | 521 | connect( container, SIGNAL( aboutToHide() ), |
521 | this, SLOT( slotMenuAboutToHide() ) ); | 522 | this, SLOT( slotMenuAboutToHide() ) ); |
522 | } | 523 | } |
523 | //US else if ( container->inherits( "KToolBar" ) ) | 524 | //US else if ( container->inherits( "KToolBar" ) ) |
524 | else if ( container->inherits( "QToolBar" ) ) | 525 | else if ( container->inherits( "QToolBar" ) ) |
525 | { | 526 | { |
526 | connect( container, SIGNAL( highlighted( int, bool ) ), | 527 | connect( container, SIGNAL( highlighted( int, bool ) ), |
527 | this, SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); | 528 | this, SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); |
528 | } | 529 | } |
529 | 530 | ||
530 | connect( container, SIGNAL( destroyed() ), | 531 | connect( container, SIGNAL( destroyed() ), |
531 | this, SLOT( slotDestroyed() ) ); | 532 | this, SLOT( slotDestroyed() ) ); |
532 | 533 | ||
533 | d->m_dctHighlightContainers.insert( container, actionList ); | 534 | d->m_dctHighlightContainers.insert( container, actionList ); |
534 | } | 535 | } |
535 | 536 | ||
536 | actionList->append( action ); | 537 | actionList->append( action ); |
537 | } | 538 | } |
538 | 539 | ||
539 | void KActionCollection::disconnectHighlight( QWidget *container, KAction *action ) | 540 | void KActionCollection::disconnectHighlight( QWidget *container, KAction *action ) |
540 | { | 541 | { |
541 | if ( !d->m_highlight ) | 542 | if ( !d->m_highlight ) |
542 | return; | 543 | return; |
543 | 544 | ||
544 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; | 545 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ]; |
545 | 546 | ||
546 | if ( !actionList ) | 547 | if ( !actionList ) |
547 | return; | 548 | return; |
548 | 549 | ||
549 | actionList->removeRef( action ); | 550 | actionList->removeRef( action ); |
550 | 551 | ||
551 | if ( actionList->count() == 0 ) | 552 | if ( actionList->count() == 0 ) |
552 | d->m_dctHighlightContainers.remove( container ); | 553 | d->m_dctHighlightContainers.remove( container ); |
553 | } | 554 | } |
554 | 555 | ||
555 | void KActionCollection::slotMenuItemHighlighted( int id ) | 556 | void KActionCollection::slotMenuItemHighlighted( int id ) |
556 | { | 557 | { |
557 | if ( !d->m_highlight ) | 558 | if ( !d->m_highlight ) |
558 | return; | 559 | return; |
559 | 560 | ||
560 | if ( d->m_currentHighlightAction ) | 561 | if ( d->m_currentHighlightAction ) |
561 | emit actionHighlighted( d->m_currentHighlightAction, false ); | 562 | emit actionHighlighted( d->m_currentHighlightAction, false ); |
562 | 563 | ||
563 | QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); | 564 | QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); |
564 | 565 | ||
565 | d->m_currentHighlightAction = findAction( container, id ); | 566 | d->m_currentHighlightAction = findAction( container, id ); |
566 | 567 | ||
567 | if ( !d->m_currentHighlightAction ) | 568 | if ( !d->m_currentHighlightAction ) |
568 | { | 569 | { |
569 | if ( !d->m_statusCleared ) | 570 | if ( !d->m_statusCleared ) |
570 | emit clearStatusText(); | 571 | emit clearStatusText(); |
571 | d->m_statusCleared = true; | 572 | d->m_statusCleared = true; |
572 | return; | 573 | return; |
573 | } | 574 | } |
574 | 575 | ||
575 | d->m_statusCleared = false; | 576 | d->m_statusCleared = false; |
576 | emit actionHighlighted( d->m_currentHighlightAction ); | 577 | emit actionHighlighted( d->m_currentHighlightAction ); |
577 | emit actionHighlighted( d->m_currentHighlightAction, true ); | 578 | emit actionHighlighted( d->m_currentHighlightAction, true ); |
578 | emit actionStatusText( d->m_currentHighlightAction->toolTip() ); | 579 | emit actionStatusText( d->m_currentHighlightAction->toolTip() ); |
579 | } | 580 | } |
580 | 581 | ||
581 | void KActionCollection::slotMenuAboutToHide() | 582 | void KActionCollection::slotMenuAboutToHide() |
582 | { | 583 | { |
583 | if ( d->m_currentHighlightAction ) | 584 | if ( d->m_currentHighlightAction ) |
584 | emit actionHighlighted( d->m_currentHighlightAction, false ); | 585 | emit actionHighlighted( d->m_currentHighlightAction, false ); |
585 | d->m_currentHighlightAction = 0; | 586 | d->m_currentHighlightAction = 0; |
586 | 587 | ||
587 | if ( !d->m_statusCleared ) | 588 | if ( !d->m_statusCleared ) |
588 | emit clearStatusText(); | 589 | emit clearStatusText(); |
589 | d->m_statusCleared = true; | 590 | d->m_statusCleared = true; |
590 | } | 591 | } |
591 | 592 | ||
592 | void KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) | 593 | void KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) |
593 | { | 594 | { |
594 | if ( !d->m_highlight ) | 595 | if ( !d->m_highlight ) |
595 | return; | 596 | return; |
596 | 597 | ||
597 | QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); | 598 | QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) ); |
598 | 599 | ||
599 | KAction *action = findAction( container, id ); | 600 | KAction *action = findAction( container, id ); |
600 | 601 | ||
601 | if ( !action ) | 602 | if ( !action ) |
602 | { | 603 | { |
603 | d->m_currentHighlightAction = 0; | 604 | d->m_currentHighlightAction = 0; |
604 | // use tooltip groups for toolbar status text stuff instead (Simon) | 605 | // use tooltip groups for toolbar status text stuff instead (Simon) |
605 | // emit clearStatusText(); | 606 | // emit clearStatusText(); |
606 | return; | 607 | return; |
607 | } | 608 | } |
608 | 609 | ||
609 | emit actionHighlighted( action, highlight ); | 610 | emit actionHighlighted( action, highlight ); |
610 | 611 | ||
611 | if ( highlight ) | 612 | if ( highlight ) |
612 | d->m_currentHighlightAction = action; | 613 | d->m_currentHighlightAction = action; |
613 | else | 614 | else |
614 | { | 615 | { |
615 | d->m_currentHighlightAction = 0; | 616 | d->m_currentHighlightAction = 0; |
616 | // emit clearStatusText(); | 617 | // emit clearStatusText(); |
617 | } | 618 | } |
618 | } | 619 | } |
619 | 620 | ||
620 | void KActionCollection::slotDestroyed() | 621 | void KActionCollection::slotDestroyed() |
621 | { | 622 | { |
622 | d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<QObject *>(sender()) ) ); | 623 | d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<QObject *>(sender()) ) ); |
623 | } | 624 | } |
624 | 625 | ||
625 | KAction *KActionCollection::findAction( QWidget *container, int id ) | 626 | KAction *KActionCollection::findAction( QWidget *container, int id ) |
626 | { | 627 | { |
627 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ]; | 628 | QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ]; |
628 | 629 | ||
629 | if ( !actionList ) | 630 | if ( !actionList ) |
630 | return 0; | 631 | return 0; |
631 | 632 | ||
632 | QPtrListIterator<KAction> it( *actionList ); | 633 | QPtrListIterator<KAction> it( *actionList ); |
633 | for (; it.current(); ++it ) | 634 | for (; it.current(); ++it ) |
634 | if ( it.current()->isPlugged( container, id ) ) | 635 | if ( it.current()->isPlugged( container, id ) ) |
635 | return it.current(); | 636 | return it.current(); |
636 | 637 | ||
637 | return 0; | 638 | return 0; |
638 | } | 639 | } |
639 | 640 | ||
640 | // KDE 4: remove | 641 | // KDE 4: remove |
641 | KActionCollection KActionCollection::operator+(const KActionCollection &c ) const | 642 | KActionCollection KActionCollection::operator+(const KActionCollection &c ) const |
642 | { | 643 | { |
643 | kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl; | 644 | kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl; |
644 | KActionCollection ret( *this ); | 645 | KActionCollection ret( *this ); |
645 | 646 | ||
646 | QValueList<KAction *> actions = c.actions(); | 647 | QValueList<KAction *> actions = c.actions(); |
647 | QValueList<KAction *>::ConstIterator it = actions.begin(); | 648 | QValueList<KAction *>::ConstIterator it = actions.begin(); |
648 | QValueList<KAction *>::ConstIterator end = actions.end(); | 649 | QValueList<KAction *>::ConstIterator end = actions.end(); |
649 | for (; it != end; ++it ) | 650 | for (; it != end; ++it ) |
650 | ret.insert( *it ); | 651 | ret.insert( *it ); |
651 | 652 | ||
652 | return ret; | 653 | return ret; |
653 | } | 654 | } |
654 | 655 | ||
655 | KActionCollection &KActionCollection::operator=( const KActionCollection © ) | 656 | KActionCollection &KActionCollection::operator=( const KActionCollection © ) |
656 | { | 657 | { |
657 | kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl; | 658 | kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl; |
658 | //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly; | 659 | //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly; |
659 | //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; | 660 | //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; |
660 | //d->m_widgetList = copy.d->m_widgetList; | 661 | //d->m_widgetList = copy.d->m_widgetList; |
661 | //d->m_kaccelList = copy.d->m_kaccelList; | 662 | //d->m_kaccelList = copy.d->m_kaccelList; |
662 | d->m_widget = copy.d->m_widget; | 663 | d->m_widget = copy.d->m_widget; |
663 | d->m_kaccel = copy.d->m_kaccel; | 664 | d->m_kaccel = copy.d->m_kaccel; |
664 | d->m_actionDict = copy.d->m_actionDict; | 665 | d->m_actionDict = copy.d->m_actionDict; |
665 | //US setInstance( copy.instance() ); | 666 | //US setInstance( copy.instance() ); |
666 | return *this; | 667 | return *this; |
667 | } | 668 | } |
668 | 669 | ||
669 | KActionCollection &KActionCollection::operator+=( const KActionCollection &c ) | 670 | KActionCollection &KActionCollection::operator+=( const KActionCollection &c ) |
670 | { | 671 | { |
671 | kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl; | 672 | kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl; |
672 | QAsciiDictIterator<KAction> it(c.d->m_actionDict); | 673 | QAsciiDictIterator<KAction> it(c.d->m_actionDict); |
673 | for ( ; it.current(); ++it ) | 674 | for ( ; it.current(); ++it ) |
674 | insert( it.current() ); | 675 | insert( it.current() ); |
675 | 676 | ||
676 | return *this; | 677 | return *this; |
677 | } | 678 | } |
678 | // KDE 4: remove end | 679 | // KDE 4: remove end |
679 | 680 | ||
680 | //--------------------------------------------------------------------- | 681 | //--------------------------------------------------------------------- |
681 | // KActionShortcutList | 682 | // KActionShortcutList |
682 | //--------------------------------------------------------------------- | 683 | //--------------------------------------------------------------------- |
683 | /*US | 684 | /*US |
684 | KActionShortcutList::KActionShortcutList( KActionCollection* pColl ) | 685 | KActionShortcutList::KActionShortcutList( KActionCollection* pColl ) |
685 | : m_actions( *pColl ) | 686 | : m_actions( *pColl ) |
686 | { } | 687 | { } |
687 | KActionShortcutList::~KActionShortcutList() | 688 | KActionShortcutList::~KActionShortcutList() |
688 | { } | 689 | { } |
689 | uint KActionShortcutList::count() const | 690 | uint KActionShortcutList::count() const |
690 | { return m_actions.count(); } | 691 | { return m_actions.count(); } |
691 | QString KActionShortcutList::name( uint i ) const | 692 | QString KActionShortcutList::name( uint i ) const |
692 | { return m_actions.action(i)->name(); } | 693 | { return m_actions.action(i)->name(); } |
693 | QString KActionShortcutList::label( uint i ) const | 694 | QString KActionShortcutList::label( uint i ) const |
694 | { return m_actions.action(i)->text(); } | 695 | { return m_actions.action(i)->text(); } |
695 | QString KActionShortcutList::whatsThis( uint i ) const | 696 | QString KActionShortcutList::whatsThis( uint i ) const |
696 | { return m_actions.action(i)->whatsThis(); } | 697 | { return m_actions.action(i)->whatsThis(); } |
697 | const KShortcut& KActionShortcutList::shortcut( uint i ) const | 698 | const KShortcut& KActionShortcutList::shortcut( uint i ) const |
698 | { return m_actions.action(i)->shortcut(); } | 699 | { return m_actions.action(i)->shortcut(); } |
699 | const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const | 700 | const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const |
700 | { return m_actions.action(i)->shortcutDefault(); } | 701 | { return m_actions.action(i)->shortcutDefault(); } |
701 | bool KActionShortcutList::isConfigurable( uint i ) const | 702 | bool KActionShortcutList::isConfigurable( uint i ) const |
702 | { return m_actions.action(i)->isShortcutConfigurable(); } | 703 | { return m_actions.action(i)->isShortcutConfigurable(); } |
703 | bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut ) | 704 | bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut ) |
704 | { return m_actions.action(i)->setShortcut( cut ); } | 705 | { return m_actions.action(i)->setShortcut( cut ); } |
705 | const KInstance* KActionShortcutList::instance() const | 706 | const KInstance* KActionShortcutList::instance() const |
706 | { return m_actions.instance(); } | 707 | { return m_actions.instance(); } |
707 | QVariant KActionShortcutList::getOther( Other, uint ) const | 708 | QVariant KActionShortcutList::getOther( Other, uint ) const |
708 | { return QVariant(); } | 709 | { return QVariant(); } |
709 | bool KActionShortcutList::setOther( Other, uint, QVariant ) | 710 | bool KActionShortcutList::setOther( Other, uint, QVariant ) |
710 | { return false; } | 711 | { return false; } |
711 | 712 | ||
712 | bool KActionShortcutList::save() const | 713 | bool KActionShortcutList::save() const |
713 | { | 714 | { |
714 | kdDebug(129) << "KActionShortcutList::save(): xmlFile = " << m_actions.xmlFile() << endl; | 715 | kdDebug(129) << "KActionShortcutList::save(): xmlFile = " << m_actions.xmlFile() << endl; |
715 | 716 | ||
716 | if( m_actions.xmlFile().isEmpty() ) | 717 | if( m_actions.xmlFile().isEmpty() ) |
717 | return writeSettings(); | 718 | return writeSettings(); |
718 | 719 | ||
719 | QString tagActionProp = QString::fromLatin1("ActionProperties"); | 720 | QString tagActionProp = QString::fromLatin1("ActionProperties"); |
720 | QString tagAction = QString::fromLatin1("Action"); | 721 | QString tagAction = QString::fromLatin1("Action"); |
721 | QString attrName = QString::fromLatin1("name"); | 722 | QString attrName = QString::fromLatin1("name"); |
722 | QString attrShortcut = QString::fromLatin1("shortcut"); | 723 | QString attrShortcut = QString::fromLatin1("shortcut"); |
723 | QString attrAccel = QString::fromLatin1("accel"); // Depricated attribute | 724 | QString attrAccel = QString::fromLatin1("accel"); // Depricated attribute |
724 | 725 | ||
725 | // Read XML file | 726 | // Read XML file |
726 | QString sXml( KXMLGUIFactory::readConfigFile( m_actions.xmlFile(), false, instance() ) ); | 727 | QString sXml( KXMLGUIFactory::readConfigFile( m_actions.xmlFile(), false, instance() ) ); |
727 | QDomDocument doc; | 728 | QDomDocument doc; |
728 | doc.setContent( sXml ); | 729 | doc.setContent( sXml ); |
729 | 730 | ||
730 | // Process XML data | 731 | // Process XML data |
731 | 732 | ||
732 | // first, lets see if we have existing properties | 733 | // first, lets see if we have existing properties |
733 | QDomElement elem; | 734 | QDomElement elem; |
734 | QDomElement it = doc.documentElement(); | 735 | QDomElement it = doc.documentElement(); |
735 | // KXMLGUIFactory::removeDOMComments( it ); <-- What was this for? --ellis | 736 | // KXMLGUIFactory::removeDOMComments( it ); <-- What was this for? --ellis |
736 | it = it.firstChild().toElement(); | 737 | it = it.firstChild().toElement(); |
737 | for( ; !it.isNull(); it = it.nextSibling().toElement() ) { | 738 | for( ; !it.isNull(); it = it.nextSibling().toElement() ) { |
738 | if( it.tagName() == tagActionProp ) { | 739 | if( it.tagName() == tagActionProp ) { |
739 | elem = it; | 740 | elem = it; |
740 | break; | 741 | break; |
741 | } | 742 | } |
742 | } | 743 | } |
743 | 744 | ||
744 | // if there was none, create one | 745 | // if there was none, create one |
745 | if( elem.isNull() ) { | 746 | if( elem.isNull() ) { |
746 | elem = doc.createElement( tagActionProp ); | 747 | elem = doc.createElement( tagActionProp ); |
747 | doc.documentElement().appendChild( elem ); | 748 | doc.documentElement().appendChild( elem ); |
748 | } | 749 | } |
749 | 750 | ||
750 | // now, iterate through our actions | 751 | // now, iterate through our actions |
751 | uint nSize = count(); | 752 | uint nSize = count(); |
752 | for( uint i = 0; i < nSize; i++ ) { | 753 | for( uint i = 0; i < nSize; i++ ) { |
753 | const QString& sName = name(i); | 754 | const QString& sName = name(i); |
754 | 755 | ||
755 | bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); | 756 | bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); |
756 | //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; | 757 | //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; |
757 | 758 | ||
758 | // now see if this element already exists | 759 | // now see if this element already exists |
759 | QDomElement act_elem; | 760 | QDomElement act_elem; |
760 | for( it = elem.firstChild().toElement(); !it.isNull(); it = it.nextSibling().toElement() ) { | 761 | for( it = elem.firstChild().toElement(); !it.isNull(); it = it.nextSibling().toElement() ) { |
761 | if( it.attribute( attrName ) == sName ) { | 762 | if( it.attribute( attrName ) == sName ) { |
762 | act_elem = it; | 763 | act_elem = it; |
763 | break; | 764 | break; |
764 | } | 765 | } |
765 | } | 766 | } |
766 | 767 | ||
767 | // nope, create a new one | 768 | // nope, create a new one |
768 | if( act_elem.isNull() ) { | 769 | if( act_elem.isNull() ) { |
769 | if( bSameAsDefault ) | 770 | if( bSameAsDefault ) |
770 | continue; | 771 | continue; |
771 | //kdDebug(129) << "\tnode doesn't exist." << endl; | 772 | //kdDebug(129) << "\tnode doesn't exist." << endl; |
772 | act_elem = doc.createElement( tagAction ); | 773 | act_elem = doc.createElement( tagAction ); |
773 | act_elem.setAttribute( attrName, sName ); | 774 | act_elem.setAttribute( attrName, sName ); |
774 | } | 775 | } |
775 | 776 | ||
776 | act_elem.removeAttribute( attrAccel ); | 777 | act_elem.removeAttribute( attrAccel ); |
777 | if( bSameAsDefault ) { | 778 | if( bSameAsDefault ) { |
778 | act_elem.removeAttribute( attrShortcut ); | 779 | act_elem.removeAttribute( attrShortcut ); |
779 | //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; | 780 | //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; |
780 | if( act_elem.attributes().count() == 1 ) | 781 | if( act_elem.attributes().count() == 1 ) |
781 | elem.removeChild( act_elem ); | 782 | elem.removeChild( act_elem ); |
782 | } else { | 783 | } else { |
783 | act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); | 784 | act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); |
784 | elem.appendChild( act_elem ); | 785 | elem.appendChild( act_elem ); |
785 | } | 786 | } |
786 | } | 787 | } |
787 | 788 | ||
788 | // Write back to XML file | 789 | // Write back to XML file |
789 | return KXMLGUIFactory::saveConfigFile( doc, m_actions.xmlFile(), instance() ); | 790 | return KXMLGUIFactory::saveConfigFile( doc, m_actions.xmlFile(), instance() ); |
790 | } | 791 | } |
791 | 792 | ||
792 | //--------------------------------------------------------------------- | 793 | //--------------------------------------------------------------------- |
793 | // KActionPtrShortcutList | 794 | // KActionPtrShortcutList |
794 | //--------------------------------------------------------------------- | 795 | //--------------------------------------------------------------------- |
795 | 796 | ||
796 | KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list ) | 797 | KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list ) |
797 | : m_actions( list ) | 798 | : m_actions( list ) |
798 | { } | 799 | { } |
799 | KActionPtrShortcutList::~KActionPtrShortcutList() | 800 | KActionPtrShortcutList::~KActionPtrShortcutList() |
800 | { } | 801 | { } |
801 | uint KActionPtrShortcutList::count() const | 802 | uint KActionPtrShortcutList::count() const |
802 | { return m_actions.count(); } | 803 | { return m_actions.count(); } |
803 | QString KActionPtrShortcutList::name( uint i ) const | 804 | QString KActionPtrShortcutList::name( uint i ) const |
804 | { return m_actions[i]->name(); } | 805 | { return m_actions[i]->name(); } |
805 | QString KActionPtrShortcutList::label( uint i ) const | 806 | QString KActionPtrShortcutList::label( uint i ) const |
806 | { return m_actions[i]->text(); } | 807 | { return m_actions[i]->text(); } |
807 | QString KActionPtrShortcutList::whatsThis( uint i ) const | 808 | QString KActionPtrShortcutList::whatsThis( uint i ) const |
808 | { return m_actions[i]->whatsThis(); } | 809 | { return m_actions[i]->whatsThis(); } |
809 | const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const | 810 | const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const |
810 | { return m_actions[i]->shortcut(); } | 811 | { return m_actions[i]->shortcut(); } |
811 | const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const | 812 | const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const |
812 | { return m_actions[i]->shortcutDefault(); } | 813 | { return m_actions[i]->shortcutDefault(); } |
813 | bool KActionPtrShortcutList::isConfigurable( uint i ) const | 814 | bool KActionPtrShortcutList::isConfigurable( uint i ) const |
814 | { return m_actions[i]->isShortcutConfigurable(); } | 815 | { return m_actions[i]->isShortcutConfigurable(); } |
815 | bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut ) | 816 | bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut ) |
816 | { return m_actions[i]->setShortcut( cut ); } | 817 | { return m_actions[i]->setShortcut( cut ); } |
817 | QVariant KActionPtrShortcutList::getOther( Other, uint ) const | 818 | QVariant KActionPtrShortcutList::getOther( Other, uint ) const |
818 | { return QVariant(); } | 819 | { return QVariant(); } |
819 | bool KActionPtrShortcutList::setOther( Other, uint, QVariant ) | 820 | bool KActionPtrShortcutList::setOther( Other, uint, QVariant ) |
820 | { return false; } | 821 | { return false; } |
821 | bool KActionPtrShortcutList::save() const | 822 | bool KActionPtrShortcutList::save() const |
822 | { return false; } | 823 | { return false; } |
823 | 824 | ||
824 | void KActionShortcutList::virtual_hook( int id, void* data ) | 825 | void KActionShortcutList::virtual_hook( int id, void* data ) |
825 | { KShortcutList::virtual_hook( id, data ); } | 826 | { KShortcutList::virtual_hook( id, data ); } |
826 | 827 | ||
827 | void KActionPtrShortcutList::virtual_hook( int id, void* data ) | 828 | void KActionPtrShortcutList::virtual_hook( int id, void* data ) |
828 | { KShortcutList::virtual_hook( id, data ); } | 829 | { KShortcutList::virtual_hook( id, data ); } |
829 | */ | 830 | */ |
830 | 831 | ||
831 | void KActionCollection::virtual_hook( int, void* ) | 832 | void KActionCollection::virtual_hook( int, void* ) |
832 | { /*BASE::virtual_hook( id, data );*/ } | 833 | { /*BASE::virtual_hook( id, data );*/ } |
833 | 834 | ||
834 | /* vim: et sw=2 ts=2 | 835 | /* vim: et sw=2 ts=2 |
835 | */ | 836 | */ |
836 | 837 | ||
837 | /*US | 838 | /*US |
838 | #include "kactioncollection.moc" | 839 | #include "kactioncollection.moc" |
839 | */ | 840 | */ |
diff --git a/microkde/kdeui/klistview.cpp b/microkde/kdeui/klistview.cpp index b53a88a..2856f2d 100644 --- a/microkde/kdeui/klistview.cpp +++ b/microkde/kdeui/klistview.cpp | |||
@@ -1,2191 +1,2191 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> | 2 | Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> |
3 | Copyright (C) 2000 Charles Samuels <charles@kde.org> | 3 | Copyright (C) 2000 Charles Samuels <charles@kde.org> |
4 | Copyright (C) 2000 Peter Putzer | 4 | Copyright (C) 2000 Peter Putzer |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License version 2 as published by the Free Software Foundation. | 8 | License version 2 as published by the Free Software Foundation. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdragobject.h> | 21 | #include <qdragobject.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | #include <qheader.h> | 23 | #include <qheader.h> |
24 | #include <qcursor.h> | 24 | #include <qcursor.h> |
25 | #include <qtooltip.h> | 25 | #include <qtooltip.h> |
26 | #include <qstyle.h> | 26 | #include <qstyle.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | 28 | ||
29 | #include <kglobalsettings.h> | 29 | #include <kglobalsettings.h> |
30 | #include <kconfig.h> | 30 | #include <kconfig.h> |
31 | #include <kconfigbase.h> | 31 | #include <kconfigbase.h> |
32 | //US #include <kcursor.h> | 32 | //US #include <kcursor.h> |
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | //US #include <kipc.h> | 34 | //US #include <kipc.h> |
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #ifdef _WIN32_ | 36 | #ifdef _WIN32_ |
37 | #define Q_WS_QWS | 37 | #define Q_WS_QWS |
38 | #endif | 38 | #endif |
39 | #ifndef _WIN32_ | 39 | #ifndef _WIN32_ |
40 | #define private public | 40 | #define private public |
41 | #include <qlistview.h> | 41 | #include <qlistview.h> |
42 | #undef private | 42 | #undef private |
43 | #endif | 43 | #endif |
44 | #include "klistview.h" | 44 | #include "klistview.h" |
45 | //US #include "klistviewlineedit.h" | 45 | //US #include "klistviewlineedit.h" |
46 | #ifndef DESKTOP_VERSION | 46 | #ifndef DESKTOP_VERSION |
47 | #include <qpe/qpeapplication.h> | 47 | #include <qpe/qpeapplication.h> |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | // /*US | 50 | // /*US |
51 | class KListView::Tooltip : public QToolTip | 51 | class KListView::Tooltip : public QToolTip |
52 | { | 52 | { |
53 | public: | 53 | public: |
54 | Tooltip (KListView* parent, QToolTipGroup* group = 0L); | 54 | Tooltip (KListView* parent, QToolTipGroup* group = 0L); |
55 | virtual ~Tooltip () {} | 55 | virtual ~Tooltip () {} |
56 | 56 | ||
57 | protected: | 57 | protected: |
58 | // */ | 58 | // */ |
59 | /** | 59 | /** |
60 | * Reimplemented from QToolTip for internal reasons. | 60 | * Reimplemented from QToolTip for internal reasons. |
61 | */ | 61 | */ |
62 | // /*US | 62 | // /*US |
63 | virtual void maybeTip (const QPoint&); | 63 | virtual void maybeTip (const QPoint&); |
64 | 64 | ||
65 | private: | 65 | private: |
66 | KListView* mParent; | 66 | KListView* mParent; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group) | 69 | KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group) |
70 | : QToolTip (parent, group), | 70 | : QToolTip (parent, group), |
71 | mParent (parent) | 71 | mParent (parent) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | void KListView::Tooltip::maybeTip (const QPoint&) | 75 | void KListView::Tooltip::maybeTip (const QPoint&) |
76 | { | 76 | { |
77 | // FIXME | 77 | // FIXME |
78 | } | 78 | } |
79 | // */ | 79 | // */ |
80 | 80 | ||
81 | class KListView::KListViewPrivate | 81 | class KListView::KListViewPrivate |
82 | { | 82 | { |
83 | public: | 83 | public: |
84 | KListViewPrivate (KListView* listview) | 84 | KListViewPrivate (KListView* listview) |
85 | : pCurrentItem (0L), | 85 | : pCurrentItem (0L), |
86 | autoSelectDelay(1), | 86 | autoSelectDelay(1), |
87 | //US dragDelay (KGlobalSettings::dndEventDelay()), | 87 | //US dragDelay (KGlobalSettings::dndEventDelay()), |
88 | 88 | ||
89 | dragDelay (10), | 89 | dragDelay (10), |
90 | //US editor (new KListViewLineEdit (listview)), | 90 | //US editor (new KListViewLineEdit (listview)), |
91 | cursorInExecuteArea(false), | 91 | cursorInExecuteArea(false), |
92 | bUseSingle(false), | 92 | bUseSingle(false), |
93 | bChangeCursorOverItem(false), | 93 | bChangeCursorOverItem(false), |
94 | itemsMovable (true), | 94 | itemsMovable (true), |
95 | selectedBySimpleMove(false), | 95 | selectedBySimpleMove(false), |
96 | selectedUsingMouse(false), | 96 | selectedUsingMouse(false), |
97 | showContextMenusOnPress(true), | 97 | showContextMenusOnPress(true), |
98 | itemsRenameable (false), | 98 | itemsRenameable (false), |
99 | validDrag (false), | 99 | validDrag (false), |
100 | dragEnabled (false), | 100 | dragEnabled (false), |
101 | autoOpen (true), | 101 | autoOpen (true), |
102 | dropVisualizer (true), | 102 | dropVisualizer (true), |
103 | dropHighlighter (false), | 103 | dropHighlighter (false), |
104 | createChildren (true), | 104 | createChildren (true), |
105 | pressedOnSelected (false), | 105 | pressedOnSelected (false), |
106 | wasShiftEvent (false), | 106 | wasShiftEvent (false), |
107 | fullWidth (false), | 107 | fullWidth (false), |
108 | sortAscending(true), | 108 | sortAscending(true), |
109 | tabRename(true), | 109 | tabRename(true), |
110 | sortColumn(0), | 110 | sortColumn(0), |
111 | selectionDirection(0), | 111 | selectionDirection(0), |
112 | tooltipColumn (0), | 112 | tooltipColumn (0), |
113 | selectionMode (Single), | 113 | selectionMode (Single), |
114 | //US contextMenuKey (KGlobalSettings::contextMenuKey()), | 114 | //US contextMenuKey (KGlobalSettings::contextMenuKey()), |
115 | //US showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()), | 115 | //US showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()), |
116 | mDropVisualizerWidth (4) | 116 | mDropVisualizerWidth (4) |
117 | { | 117 | { |
118 | renameable += 0; | 118 | renameable += 0; |
119 | //US connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(doneEditing(QListViewItem*,int))); | 119 | //US connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(doneEditing(QListViewItem*,int))); |
120 | } | 120 | } |
121 | 121 | ||
122 | ~KListViewPrivate () | 122 | ~KListViewPrivate () |
123 | { | 123 | { |
124 | //US delete editor; | 124 | //US delete editor; |
125 | } | 125 | } |
126 | 126 | ||
127 | QListViewItem* pCurrentItem; | 127 | QListViewItem* pCurrentItem; |
128 | 128 | ||
129 | QTimer autoSelect; | 129 | QTimer autoSelect; |
130 | int autoSelectDelay; | 130 | int autoSelectDelay; |
131 | 131 | ||
132 | QTimer dragExpand; | 132 | QTimer dragExpand; |
133 | QListViewItem* dragOverItem; | 133 | QListViewItem* dragOverItem; |
134 | QPoint dragOverPoint; | 134 | QPoint dragOverPoint; |
135 | 135 | ||
136 | QPoint startDragPos; | 136 | QPoint startDragPos; |
137 | int dragDelay; | 137 | int dragDelay; |
138 | 138 | ||
139 | //US KListViewLineEdit *editor; | 139 | //US KListViewLineEdit *editor; |
140 | QValueList<int> renameable; | 140 | QValueList<int> renameable; |
141 | 141 | ||
142 | bool cursorInExecuteArea:1; | 142 | bool cursorInExecuteArea:1; |
143 | bool bUseSingle:1; | 143 | bool bUseSingle:1; |
144 | bool bChangeCursorOverItem:1; | 144 | bool bChangeCursorOverItem:1; |
145 | bool itemsMovable:1; | 145 | bool itemsMovable:1; |
146 | bool selectedBySimpleMove : 1; | 146 | bool selectedBySimpleMove : 1; |
147 | bool selectedUsingMouse:1; | 147 | bool selectedUsingMouse:1; |
148 | bool itemsRenameable:1; | 148 | bool itemsRenameable:1; |
149 | bool validDrag:1; | 149 | bool validDrag:1; |
150 | bool dragEnabled:1; | 150 | bool dragEnabled:1; |
151 | bool autoOpen:1; | 151 | bool autoOpen:1; |
152 | bool dropVisualizer:1; | 152 | bool dropVisualizer:1; |
153 | bool dropHighlighter:1; | 153 | bool dropHighlighter:1; |
154 | bool createChildren:1; | 154 | bool createChildren:1; |
155 | bool pressedOnSelected:1; | 155 | bool pressedOnSelected:1; |
156 | bool wasShiftEvent:1; | 156 | bool wasShiftEvent:1; |
157 | bool fullWidth:1; | 157 | bool fullWidth:1; |
158 | bool sortAscending:1; | 158 | bool sortAscending:1; |
159 | bool tabRename:1; | 159 | bool tabRename:1; |
160 | 160 | ||
161 | int sortColumn; | 161 | int sortColumn; |
162 | 162 | ||
163 | //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX | 163 | //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX |
164 | int selectionDirection; | 164 | int selectionDirection; |
165 | int tooltipColumn; | 165 | int tooltipColumn; |
166 | 166 | ||
167 | SelectionModeExt selectionMode; | 167 | SelectionModeExt selectionMode; |
168 | int contextMenuKey; | 168 | int contextMenuKey; |
169 | bool showContextMenusOnPress; | 169 | bool showContextMenusOnPress; |
170 | 170 | ||
171 | QRect mOldDropVisualizer; | 171 | QRect mOldDropVisualizer; |
172 | int mDropVisualizerWidth; | 172 | int mDropVisualizerWidth; |
173 | QRect mOldDropHighlighter; | 173 | QRect mOldDropHighlighter; |
174 | QListViewItem *afterItemDrop; | 174 | QListViewItem *afterItemDrop; |
175 | QListViewItem *parentItemDrop; | 175 | QListViewItem *parentItemDrop; |
176 | 176 | ||
177 | QColor alternateBackground; | 177 | QColor alternateBackground; |
178 | }; | 178 | }; |
179 | 179 | ||
180 | /*US | 180 | /*US |
181 | KListViewLineEdit::KListViewLineEdit(KListView *parent) | 181 | KListViewLineEdit::KListViewLineEdit(KListView *parent) |
182 | : KLineEdit(parent->viewport()), item(0), col(0), p(parent) | 182 | : KLineEdit(parent->viewport()), item(0), col(0), p(parent) |
183 | { | 183 | { |
184 | setFrame( false ); | 184 | setFrame( false ); |
185 | hide(); | 185 | hide(); |
186 | connect( parent, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() )); | 186 | connect( parent, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() )); |
187 | } | 187 | } |
188 | 188 | ||
189 | KListViewLineEdit::~KListViewLineEdit() | 189 | KListViewLineEdit::~KListViewLineEdit() |
190 | { | 190 | { |
191 | } | 191 | } |
192 | 192 | ||
193 | void KListViewLineEdit::load(QListViewItem *i, int c) | 193 | void KListViewLineEdit::load(QListViewItem *i, int c) |
194 | { | 194 | { |
195 | item=i; | 195 | item=i; |
196 | col=c; | 196 | col=c; |
197 | 197 | ||
198 | QRect rect(p->itemRect(i)); | 198 | QRect rect(p->itemRect(i)); |
199 | setText(item->text(c)); | 199 | setText(item->text(c)); |
200 | 200 | ||
201 | int fieldX = rect.x() - 1; | 201 | int fieldX = rect.x() - 1; |
202 | int fieldW = p->columnWidth(col) + 2; | 202 | int fieldW = p->columnWidth(col) + 2; |
203 | 203 | ||
204 | int pos = p->header()->mapToIndex(col); | 204 | int pos = p->header()->mapToIndex(col); |
205 | for ( int index = 0; index < pos; index++ ) | 205 | for ( int index = 0; index < pos; index++ ) |
206 | fieldX += p->columnWidth( p->header()->mapToSection( index )); | 206 | fieldX += p->columnWidth( p->header()->mapToSection( index )); |
207 | 207 | ||
208 | if ( col == 0 ) { | 208 | if ( col == 0 ) { |
209 | int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); | 209 | int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); |
210 | d *= p->treeStepSize(); | 210 | d *= p->treeStepSize(); |
211 | fieldX += d; | 211 | fieldX += d; |
212 | fieldW -= d; | 212 | fieldW -= d; |
213 | } | 213 | } |
214 | 214 | ||
215 | if ( i->pixmap( col ) ) {// add width of pixmap | 215 | if ( i->pixmap( col ) ) {// add width of pixmap |
216 | int d = i->pixmap( col )->width(); | 216 | int d = i->pixmap( col )->width(); |
217 | fieldX += d; | 217 | fieldX += d; |
218 | fieldW -= d; | 218 | fieldW -= d; |
219 | } | 219 | } |
220 | 220 | ||
221 | setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); | 221 | setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); |
222 | show(); | 222 | show(); |
223 | setFocus(); | 223 | setFocus(); |
224 | } | 224 | } |
225 | */ | 225 | */ |
226 | /*Helper functions to for | 226 | /*Helper functions to for |
227 | *tabOrderedRename functionality. | 227 | *tabOrderedRename functionality. |
228 | */ | 228 | */ |
229 | 229 | ||
230 | static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir) | 230 | static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir) |
231 | { | 231 | { |
232 | if (pi) | 232 | if (pi) |
233 | { | 233 | { |
234 | //Find the next renameable column in the current row | 234 | //Find the next renameable column in the current row |
235 | for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) | 235 | for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) |
236 | if (pl->isRenameable(start)) | 236 | if (pl->isRenameable(start)) |
237 | return start; | 237 | return start; |
238 | } | 238 | } |
239 | 239 | ||
240 | return -1; | 240 | return -1; |
241 | } | 241 | } |
242 | 242 | ||
243 | static QListViewItem *prevItem (QListViewItem *pi) | 243 | static QListViewItem *prevItem (QListViewItem *pi) |
244 | { | 244 | { |
245 | QListViewItem *pa = pi->itemAbove(); | 245 | QListViewItem *pa = pi->itemAbove(); |
246 | 246 | ||
247 | /*Does what the QListViewItem::previousSibling() | 247 | /*Does what the QListViewItem::previousSibling() |
248 | *of my dreams would do. | 248 | *of my dreams would do. |
249 | */ | 249 | */ |
250 | if (pa && pa->parent() == pi->parent()) | 250 | if (pa && pa->parent() == pi->parent()) |
251 | return pa; | 251 | return pa; |
252 | 252 | ||
253 | return NULL; | 253 | return NULL; |
254 | } | 254 | } |
255 | 255 | ||
256 | static QListViewItem *lastQChild (QListViewItem *pi) | 256 | static QListViewItem *lastQChild (QListViewItem *pi) |
257 | { | 257 | { |
258 | if (pi) | 258 | if (pi) |
259 | { | 259 | { |
260 | /*Since there's no QListViewItem::lastChild(). | 260 | /*Since there's no QListViewItem::lastChild(). |
261 | *This finds the last sibling for the given | 261 | *This finds the last sibling for the given |
262 | *item. | 262 | *item. |
263 | */ | 263 | */ |
264 | for (QListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) | 264 | for (QListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) |
265 | pi = pt; | 265 | pi = pt; |
266 | } | 266 | } |
267 | 267 | ||
268 | return pi; | 268 | return pi; |
269 | } | 269 | } |
270 | /*US | 270 | /*US |
271 | void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward) | 271 | void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward) |
272 | { | 272 | { |
273 | const int ncols = p->columns(); | 273 | const int ncols = p->columns(); |
274 | const int dir = forward ? +1 : -1; | 274 | const int dir = forward ? +1 : -1; |
275 | const int restart = forward ? 0 : (ncols - 1); | 275 | const int restart = forward ? 0 : (ncols - 1); |
276 | QListViewItem *top = (pitem && pitem->parent()) | 276 | QListViewItem *top = (pitem && pitem->parent()) |
277 | ? pitem->parent()->firstChild() | 277 | ? pitem->parent()->firstChild() |
278 | : p->firstChild(); | 278 | : p->firstChild(); |
279 | QListViewItem *pi = pitem; | 279 | QListViewItem *pi = pitem; |
280 | 280 | ||
281 | terminate(); //Save current changes | 281 | terminate(); //Save current changes |
282 | 282 | ||
283 | do | 283 | do |
284 | { | 284 | { |
285 | */ | 285 | */ |
286 | /*Check the rest of the current row for an editable column, | 286 | /*Check the rest of the current row for an editable column, |
287 | *if that fails, check the entire next/previous row. The | 287 | *if that fails, check the entire next/previous row. The |
288 | *last case goes back to the first item in the current branch | 288 | *last case goes back to the first item in the current branch |
289 | *or the last item in the current branch depending on the | 289 | *or the last item in the current branch depending on the |
290 | *direction. | 290 | *direction. |
291 | */ | 291 | */ |
292 | /*US | 292 | /*US |
293 | if ((column = nextCol(p, pi, column + dir, dir)) != -1 || | 293 | if ((column = nextCol(p, pi, column + dir, dir)) != -1 || |
294 | (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || | 294 | (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || |
295 | (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) | 295 | (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) |
296 | { | 296 | { |
297 | if (pi) | 297 | if (pi) |
298 | { | 298 | { |
299 | p->setCurrentItem(pi); //Calls terminate | 299 | p->setCurrentItem(pi); //Calls terminate |
300 | p->rename(pi, column); | 300 | p->rename(pi, column); |
301 | */ | 301 | */ |
302 | /*Some listviews may override rename() to | 302 | /*Some listviews may override rename() to |
303 | *prevent certain items from being renamed, | 303 | *prevent certain items from being renamed, |
304 | *if this is done, [m_]item will be NULL | 304 | *if this is done, [m_]item will be NULL |
305 | *after the rename() call... try again. | 305 | *after the rename() call... try again. |
306 | */ | 306 | */ |
307 | /*US | 307 | /*US |
308 | if (!item) | 308 | if (!item) |
309 | continue; | 309 | continue; |
310 | 310 | ||
311 | break; | 311 | break; |
312 | } | 312 | } |
313 | } | 313 | } |
314 | } | 314 | } |
315 | while (pi && !item); | 315 | while (pi && !item); |
316 | } | 316 | } |
317 | */ | 317 | */ |
318 | 318 | ||
319 | /*US | 319 | /*US |
320 | #ifdef KeyPress | 320 | #ifdef KeyPress |
321 | #undef KeyPress | 321 | #undef KeyPress |
322 | #endif | 322 | #endif |
323 | 323 | ||
324 | bool KListViewLineEdit::event (QEvent *pe) | 324 | bool KListViewLineEdit::event (QEvent *pe) |
325 | { | 325 | { |
326 | if (pe->type() == QEvent::KeyPress) | 326 | if (pe->type() == QEvent::KeyPress) |
327 | { | 327 | { |
328 | QKeyEvent *k = (QKeyEvent *) pe; | 328 | QKeyEvent *k = (QKeyEvent *) pe; |
329 | 329 | ||
330 | if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && | 330 | if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && |
331 | p->tabOrderedRenaming() && p->itemsRenameable() && | 331 | p->tabOrderedRenaming() && p->itemsRenameable() && |
332 | !(k->state() & ControlButton || k->state() & AltButton)) | 332 | !(k->state() & ControlButton || k->state() & AltButton)) |
333 | { | 333 | { |
334 | selectNextCell(item, col, | 334 | selectNextCell(item, col, |
335 | (k->key() == Key_Tab && !(k->state() & ShiftButton))); | 335 | (k->key() == Key_Tab && !(k->state() & ShiftButton))); |
336 | return true; | 336 | return true; |
337 | } | 337 | } |
338 | } | 338 | } |
339 | 339 | ||
340 | return KLineEdit::event(pe); | 340 | return KLineEdit::event(pe); |
341 | } | 341 | } |
342 | 342 | ||
343 | void KListViewLineEdit::keyPressEvent(QKeyEvent *e) | 343 | void KListViewLineEdit::keyPressEvent(QKeyEvent *e) |
344 | { | 344 | { |
345 | if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) | 345 | if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) |
346 | terminate(true); | 346 | terminate(true); |
347 | else if(e->key() == Qt::Key_Escape) | 347 | else if(e->key() == Qt::Key_Escape) |
348 | terminate(false); | 348 | terminate(false); |
349 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) | 349 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) |
350 | { | 350 | { |
351 | terminate(true); | 351 | terminate(true); |
352 | KLineEdit::keyPressEvent(e); | 352 | KLineEdit::keyPressEvent(e); |
353 | } | 353 | } |
354 | else | 354 | else |
355 | KLineEdit::keyPressEvent(e); | 355 | KLineEdit::keyPressEvent(e); |
356 | } | 356 | } |
357 | 357 | ||
358 | void KListViewLineEdit::terminate() | 358 | void KListViewLineEdit::terminate() |
359 | { | 359 | { |
360 | terminate(true); | 360 | terminate(true); |
361 | } | 361 | } |
362 | 362 | ||
363 | void KListViewLineEdit::terminate(bool commit) | 363 | void KListViewLineEdit::terminate(bool commit) |
364 | { | 364 | { |
365 | if ( item ) | 365 | if ( item ) |
366 | { | 366 | { |
367 | //kdDebug() << "KListViewLineEdit::terminate " << commit << endl; | 367 | //kdDebug() << "KListViewLineEdit::terminate " << commit << endl; |
368 | if (commit) | 368 | if (commit) |
369 | item->setText(col, text()); | 369 | item->setText(col, text()); |
370 | int c=col; | 370 | int c=col; |
371 | QListViewItem *i=item; | 371 | QListViewItem *i=item; |
372 | col=0; | 372 | col=0; |
373 | item=0; | 373 | item=0; |
374 | hide(); // will call focusOutEvent, that's why we set item=0 before | 374 | hide(); // will call focusOutEvent, that's why we set item=0 before |
375 | emit done(i,c); | 375 | emit done(i,c); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | 378 | ||
379 | void KListViewLineEdit::focusOutEvent(QFocusEvent *ev) | 379 | void KListViewLineEdit::focusOutEvent(QFocusEvent *ev) |
380 | { | 380 | { |
381 | QFocusEvent * focusEv = static_cast<QFocusEvent*>(ev); | 381 | QFocusEvent * focusEv = static_cast<QFocusEvent*>(ev); |
382 | // Don't let a RMB close the editor | 382 | // Don't let a RMB close the editor |
383 | if (focusEv->reason() != QFocusEvent::Popup && focusEv->reason() != QFocusEvent::ActiveWindow) | 383 | if (focusEv->reason() != QFocusEvent::Popup && focusEv->reason() != QFocusEvent::ActiveWindow) |
384 | terminate(true); | 384 | terminate(true); |
385 | } | 385 | } |
386 | 386 | ||
387 | void KListViewLineEdit::paintEvent( QPaintEvent *e ) | 387 | void KListViewLineEdit::paintEvent( QPaintEvent *e ) |
388 | { | 388 | { |
389 | KLineEdit::paintEvent( e ); | 389 | KLineEdit::paintEvent( e ); |
390 | 390 | ||
391 | if ( !frame() ) { | 391 | if ( !frame() ) { |
392 | QPainter p( this ); | 392 | QPainter p( this ); |
393 | p.setClipRegion( e->region() ); | 393 | p.setClipRegion( e->region() ); |
394 | p.drawRect( rect() ); | 394 | p.drawRect( rect() ); |
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | // selection changed -> terminate. As our "item" can be already deleted, | 398 | // selection changed -> terminate. As our "item" can be already deleted, |
399 | // we can't call terminate(false), because that would emit done() with | 399 | // we can't call terminate(false), because that would emit done() with |
400 | // a dangling pointer to "item". | 400 | // a dangling pointer to "item". |
401 | void KListViewLineEdit::slotSelectionChanged() | 401 | void KListViewLineEdit::slotSelectionChanged() |
402 | { | 402 | { |
403 | item = 0; | 403 | item = 0; |
404 | col = 0; | 404 | col = 0; |
405 | hide(); | 405 | hide(); |
406 | } | 406 | } |
407 | */ | 407 | */ |
408 | 408 | ||
409 | KListView::KListView( QWidget *parent, const char *name ) | 409 | KListView::KListView( QWidget *parent, const char *name ) |
410 | : QListView( parent, name ), | 410 | : QListView( parent, name ), |
411 | d (new KListViewPrivate (this)) | 411 | d (new KListViewPrivate (this)) |
412 | { | 412 | { |
413 | #ifndef DESKTOP_VERSION | 413 | #ifndef DESKTOP_VERSION |
414 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 414 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
415 | #endif | 415 | #endif |
416 | //US setDragAutoScroll(true); | 416 | //US setDragAutoScroll(true); |
417 | 417 | ||
418 | connect( this, SIGNAL( onViewport() ), | 418 | connect( this, SIGNAL( onViewport() ), |
419 | this, SLOT( slotOnViewport() ) ); | 419 | this, SLOT( slotOnViewport() ) ); |
420 | connect( this, SIGNAL( onItem( QListViewItem * ) ), | 420 | connect( this, SIGNAL( onItem( QListViewItem * ) ), |
421 | this, SLOT( slotOnItem( QListViewItem * ) ) ); | 421 | this, SLOT( slotOnItem( QListViewItem * ) ) ); |
422 | 422 | ||
423 | connect (this, SIGNAL(contentsMoving(int,int)), | 423 | connect (this, SIGNAL(contentsMoving(int,int)), |
424 | this, SLOT(cleanDropVisualizer())); | 424 | this, SLOT(cleanDropVisualizer())); |
425 | connect (this, SIGNAL(contentsMoving(int,int)), | 425 | connect (this, SIGNAL(contentsMoving(int,int)), |
426 | this, SLOT(cleanItemHighlighter())); | 426 | this, SLOT(cleanItemHighlighter())); |
427 | 427 | ||
428 | /*US | 428 | /*US |
429 | slotSettingsChanged(KApplication::SETTINGS_MOUSE); | 429 | slotSettingsChanged(KApplication::SETTINGS_MOUSE); |
430 | 430 | ||
431 | if (kapp) | 431 | if (kapp) |
432 | { | 432 | { |
433 | connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); | 433 | connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); |
434 | kapp->addKipcEventMask( KIPC::SettingsChanged ); | 434 | kapp->addKipcEventMask( KIPC::SettingsChanged ); |
435 | } | 435 | } |
436 | */ | 436 | */ |
437 | slotSettingsChanged(1); //US do this to initialize the connections | 437 | slotSettingsChanged(1); //US do this to initialize the connections |
438 | 438 | ||
439 | 439 | ||
440 | connect(&d->autoSelect, SIGNAL( timeout() ), | 440 | connect(&d->autoSelect, SIGNAL( timeout() ), |
441 | this, SLOT( slotAutoSelect() ) ); | 441 | this, SLOT( slotAutoSelect() ) ); |
442 | connect(&d->dragExpand, SIGNAL( timeout() ), | 442 | connect(&d->dragExpand, SIGNAL( timeout() ), |
443 | this, SLOT( slotDragExpand() ) ); | 443 | this, SLOT( slotDragExpand() ) ); |
444 | 444 | ||
445 | // context menu handling | 445 | // context menu handling |
446 | if (d->showContextMenusOnPress) | 446 | if (d->showContextMenusOnPress) |
447 | { | 447 | { |
448 | connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), | 448 | connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), |
449 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 449 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
450 | } | 450 | } |
451 | else | 451 | else |
452 | { | 452 | { |
453 | connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), | 453 | connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), |
454 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 454 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
455 | } | 455 | } |
456 | 456 | ||
457 | connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)), | 457 | connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)), |
458 | this, SLOT (emitContextMenu (KListView*, QListViewItem*))); | 458 | this, SLOT (emitContextMenu (KListView*, QListViewItem*))); |
459 | 459 | ||
460 | 460 | ||
461 | //qDebug("KListView::KListView make alternate color configurable"); | 461 | //qDebug("KListView::KListView make alternate color configurable"); |
462 | //US d->alternateBackground = KGlobalSettings::alternateBackgroundColor(); | 462 | //US d->alternateBackground = KGlobalSettings::alternateBackgroundColor(); |
463 | d->alternateBackground = QColor(240, 240, 240); | 463 | d->alternateBackground = QColor(240, 240, 240); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | 467 | ||
468 | KListView::~KListView() | 468 | KListView::~KListView() |
469 | { | 469 | { |
470 | delete d; | 470 | delete d; |
471 | } | 471 | } |
472 | 472 | ||
473 | bool KListView::isExecuteArea( const QPoint& point ) | 473 | bool KListView::isExecuteArea( const QPoint& point ) |
474 | { | 474 | { |
475 | if ( itemAt( point ) ) | 475 | if ( itemAt( point ) ) |
476 | return isExecuteArea( point.x() ); | 476 | return isExecuteArea( point.x() ); |
477 | 477 | ||
478 | return false; | 478 | return false; |
479 | } | 479 | } |
480 | 480 | ||
481 | bool KListView::isExecuteArea( int x ) | 481 | bool KListView::isExecuteArea( int x ) |
482 | { | 482 | { |
483 | if( allColumnsShowFocus() ) | 483 | if( allColumnsShowFocus() ) |
484 | return true; | 484 | return true; |
485 | else { | 485 | else { |
486 | int offset = 0; | 486 | int offset = 0; |
487 | int width = columnWidth( 0 ); | 487 | int width = columnWidth( 0 ); |
488 | int pos = header()->mapToIndex( 0 ); | 488 | int pos = header()->mapToIndex( 0 ); |
489 | 489 | ||
490 | for ( int index = 0; index < pos; index++ ) | 490 | for ( int index = 0; index < pos; index++ ) |
491 | offset += columnWidth( header()->mapToSection( index ) ); | 491 | offset += columnWidth( header()->mapToSection( index ) ); |
492 | 492 | ||
493 | x += contentsX(); // in case of a horizontal scrollbar | 493 | x += contentsX(); // in case of a horizontal scrollbar |
494 | return ( x > offset && x < ( offset + width ) ); | 494 | return ( x > offset && x < ( offset + width ) ); |
495 | } | 495 | } |
496 | } | 496 | } |
497 | 497 | ||
498 | void KListView::slotOnItem( QListViewItem *item ) | 498 | void KListView::slotOnItem( QListViewItem *item ) |
499 | { | 499 | { |
500 | QPoint vp = viewport()->mapFromGlobal( QCursor::pos() ); | 500 | QPoint vp = viewport()->mapFromGlobal( QCursor::pos() ); |
501 | if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { | 501 | if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { |
502 | d->autoSelect.start( d->autoSelectDelay, true ); | 502 | d->autoSelect.start( d->autoSelectDelay, true ); |
503 | d->pCurrentItem = item; | 503 | d->pCurrentItem = item; |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void KListView::slotOnViewport() | 507 | void KListView::slotOnViewport() |
508 | { | 508 | { |
509 | if ( d->bChangeCursorOverItem ) | 509 | if ( d->bChangeCursorOverItem ) |
510 | viewport()->unsetCursor(); | 510 | viewport()->unsetCursor(); |
511 | 511 | ||
512 | d->autoSelect.stop(); | 512 | d->autoSelect.stop(); |
513 | d->pCurrentItem = 0L; | 513 | d->pCurrentItem = 0L; |
514 | } | 514 | } |
515 | 515 | ||
516 | void KListView::slotSettingsChanged(int category) | 516 | void KListView::slotSettingsChanged(int category) |
517 | { | 517 | { |
518 | qDebug("KListView::slotSettingsChanged has to be verified"); | 518 | //qDebug("KListView::slotSettingsChanged has to be verified"); |
519 | /*US | 519 | /*US |
520 | 520 | ||
521 | switch (category) | 521 | switch (category) |
522 | { | 522 | { |
523 | case KApplication::SETTINGS_MOUSE: | 523 | case KApplication::SETTINGS_MOUSE: |
524 | d->dragDelay = KGlobalSettings::dndEventDelay(); | 524 | d->dragDelay = KGlobalSettings::dndEventDelay(); |
525 | d->bUseSingle = KGlobalSettings::singleClick(); | 525 | d->bUseSingle = KGlobalSettings::singleClick(); |
526 | 526 | ||
527 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 527 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
528 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); | 528 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); |
529 | 529 | ||
530 | if( d->bUseSingle ) | 530 | if( d->bUseSingle ) |
531 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 531 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
532 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); | 532 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); |
533 | 533 | ||
534 | d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); | 534 | d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); |
535 | d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); | 535 | d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); |
536 | 536 | ||
537 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) | 537 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) |
538 | viewport()->unsetCursor(); | 538 | viewport()->unsetCursor(); |
539 | 539 | ||
540 | break; | 540 | break; |
541 | 541 | ||
542 | case KApplication::SETTINGS_POPUPMENU: | 542 | case KApplication::SETTINGS_POPUPMENU: |
543 | d->contextMenuKey = KGlobalSettings::contextMenuKey (); | 543 | d->contextMenuKey = KGlobalSettings::contextMenuKey (); |
544 | d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress (); | 544 | d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress (); |
545 | 545 | ||
546 | if (d->showContextMenusOnPress) | 546 | if (d->showContextMenusOnPress) |
547 | { | 547 | { |
548 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 548 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
549 | 549 | ||
550 | connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), | 550 | connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), |
551 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 551 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
552 | } | 552 | } |
553 | else | 553 | else |
554 | { | 554 | { |
555 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 555 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
556 | 556 | ||
557 | connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), | 557 | connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), |
558 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 558 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
559 | } | 559 | } |
560 | break; | 560 | break; |
561 | 561 | ||
562 | default: | 562 | default: |
563 | break; | 563 | break; |
564 | } | 564 | } |
565 | */ | 565 | */ |
566 | 566 | ||
567 | if( d->bUseSingle ) | 567 | if( d->bUseSingle ) |
568 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 568 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
569 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); | 569 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); |
570 | 570 | ||
571 | } | 571 | } |
572 | 572 | ||
573 | void KListView::slotAutoSelect() | 573 | void KListView::slotAutoSelect() |
574 | { | 574 | { |
575 | // check that the item still exists | 575 | // check that the item still exists |
576 | if( itemIndex( d->pCurrentItem ) == -1 ) | 576 | if( itemIndex( d->pCurrentItem ) == -1 ) |
577 | return; | 577 | return; |
578 | 578 | ||
579 | if (!isActiveWindow()) | 579 | if (!isActiveWindow()) |
580 | { | 580 | { |
581 | d->autoSelect.stop(); | 581 | d->autoSelect.stop(); |
582 | return; | 582 | return; |
583 | } | 583 | } |
584 | 584 | ||
585 | //Give this widget the keyboard focus. | 585 | //Give this widget the keyboard focus. |
586 | if( !hasFocus() ) | 586 | if( !hasFocus() ) |
587 | setFocus(); | 587 | setFocus(); |
588 | 588 | ||
589 | QListViewItem* previousItem = currentItem(); | 589 | QListViewItem* previousItem = currentItem(); |
590 | setCurrentItem( d->pCurrentItem ); | 590 | setCurrentItem( d->pCurrentItem ); |
591 | 591 | ||
592 | #if 0 | 592 | #if 0 |
593 | #ifndef Q_WS_QWS | 593 | #ifndef Q_WS_QWS |
594 | // FIXME(E): Implement for Qt Embedded | 594 | // FIXME(E): Implement for Qt Embedded |
595 | if( d->pCurrentItem ) { | 595 | if( d->pCurrentItem ) { |
596 | //Shift pressed? | 596 | //Shift pressed? |
597 | if( (keybstate & ShiftMask) ) { | 597 | if( (keybstate & ShiftMask) ) { |
598 | bool block = signalsBlocked(); | 598 | bool block = signalsBlocked(); |
599 | blockSignals( true ); | 599 | blockSignals( true ); |
600 | 600 | ||
601 | //No Ctrl? Then clear before! | 601 | //No Ctrl? Then clear before! |
602 | if( !(keybstate & ControlMask) ) | 602 | if( !(keybstate & ControlMask) ) |
603 | clearSelection(); | 603 | clearSelection(); |
604 | 604 | ||
605 | bool select = !d->pCurrentItem->isSelected(); | 605 | bool select = !d->pCurrentItem->isSelected(); |
606 | bool update = viewport()->isUpdatesEnabled(); | 606 | bool update = viewport()->isUpdatesEnabled(); |
607 | viewport()->setUpdatesEnabled( false ); | 607 | viewport()->setUpdatesEnabled( false ); |
608 | 608 | ||
609 | bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); | 609 | bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); |
610 | QListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); | 610 | QListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); |
611 | for ( ; lit.current(); ++lit ) { | 611 | for ( ; lit.current(); ++lit ) { |
612 | if ( down && lit.current() == d->pCurrentItem ) { | 612 | if ( down && lit.current() == d->pCurrentItem ) { |
613 | d->pCurrentItem->setSelected( select ); | 613 | d->pCurrentItem->setSelected( select ); |
614 | break; | 614 | break; |
615 | } | 615 | } |
616 | if ( !down && lit.current() == previousItem ) { | 616 | if ( !down && lit.current() == previousItem ) { |
617 | previousItem->setSelected( select ); | 617 | previousItem->setSelected( select ); |
618 | break; | 618 | break; |
619 | } | 619 | } |
620 | lit.current()->setSelected( select ); | 620 | lit.current()->setSelected( select ); |
621 | } | 621 | } |
622 | 622 | ||
623 | blockSignals( block ); | 623 | blockSignals( block ); |
624 | viewport()->setUpdatesEnabled( update ); | 624 | viewport()->setUpdatesEnabled( update ); |
625 | triggerUpdate(); | 625 | triggerUpdate(); |
626 | 626 | ||
627 | emit selectionChanged(); | 627 | emit selectionChanged(); |
628 | 628 | ||
629 | if( selectionMode() == QListView::Single ) | 629 | if( selectionMode() == QListView::Single ) |
630 | emit selectionChanged( d->pCurrentItem ); | 630 | emit selectionChanged( d->pCurrentItem ); |
631 | } | 631 | } |
632 | else if( (keybstate & ControlMask) ) | 632 | else if( (keybstate & ControlMask) ) |
633 | setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); | 633 | setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); |
634 | else { | 634 | else { |
635 | bool block = signalsBlocked(); | 635 | bool block = signalsBlocked(); |
636 | blockSignals( true ); | 636 | blockSignals( true ); |
637 | 637 | ||
638 | if( !d->pCurrentItem->isSelected() ) | 638 | if( !d->pCurrentItem->isSelected() ) |
639 | clearSelection(); | 639 | clearSelection(); |
640 | 640 | ||
641 | blockSignals( block ); | 641 | blockSignals( block ); |
642 | 642 | ||
643 | setSelected( d->pCurrentItem, true ); | 643 | setSelected( d->pCurrentItem, true ); |
644 | } | 644 | } |
645 | } | 645 | } |
646 | else | 646 | else |
647 | kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl; | 647 | kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl; |
648 | #endif | 648 | #endif |
649 | #endif | 649 | #endif |
650 | } | 650 | } |
651 | 651 | ||
652 | void KListView::slotHeaderChanged() | 652 | void KListView::slotHeaderChanged() |
653 | { | 653 | { |
654 | if (d->fullWidth && columns()) | 654 | if (d->fullWidth && columns()) |
655 | { | 655 | { |
656 | int w = 0; | 656 | int w = 0; |
657 | for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i); | 657 | for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i); |
658 | setColumnWidth( columns() - 1, viewport()->width() - w - 1 ); | 658 | setColumnWidth( columns() - 1, viewport()->width() - w - 1 ); |
659 | } | 659 | } |
660 | } | 660 | } |
661 | 661 | ||
662 | void KListView::emitExecute( QListViewItem *item, const QPoint &pos, int c ) | 662 | void KListView::emitExecute( QListViewItem *item, const QPoint &pos, int c ) |
663 | { | 663 | { |
664 | if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { | 664 | if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { |
665 | 665 | ||
666 | // Double click mode ? | 666 | // Double click mode ? |
667 | if ( !d->bUseSingle ) | 667 | if ( !d->bUseSingle ) |
668 | { | 668 | { |
669 | emit executed( item ); | 669 | emit executed( item ); |
670 | emit executed( item, pos, c ); | 670 | emit executed( item, pos, c ); |
671 | } | 671 | } |
672 | else | 672 | else |
673 | { | 673 | { |
674 | #if 0 | 674 | #if 0 |
675 | #ifndef Q_WS_QWS | 675 | #ifndef Q_WS_QWS |
676 | // FIXME(E): Implement for Qt Embedded | 676 | // FIXME(E): Implement for Qt Embedded |
677 | Window root; | 677 | Window root; |
678 | Window child; | 678 | Window child; |
679 | int root_x, root_y, win_x, win_y; | 679 | int root_x, root_y, win_x, win_y; |
680 | uint keybstate; | 680 | uint keybstate; |
681 | XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child, | 681 | XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child, |
682 | &root_x, &root_y, &win_x, &win_y, &keybstate ); | 682 | &root_x, &root_y, &win_x, &win_y, &keybstate ); |
683 | 683 | ||
684 | d->autoSelect.stop(); | 684 | d->autoSelect.stop(); |
685 | 685 | ||
686 | //Dont emit executed if in SC mode and Shift or Ctrl are pressed | 686 | //Dont emit executed if in SC mode and Shift or Ctrl are pressed |
687 | if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { | 687 | if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { |
688 | emit executed( item ); | 688 | emit executed( item ); |
689 | emit executed( item, pos, c ); | 689 | emit executed( item, pos, c ); |
690 | } | 690 | } |
691 | #endif | 691 | #endif |
692 | #endif | 692 | #endif |
693 | } | 693 | } |
694 | } | 694 | } |
695 | } | 695 | } |
696 | 696 | ||
697 | void KListView::focusInEvent( QFocusEvent *fe ) | 697 | void KListView::focusInEvent( QFocusEvent *fe ) |
698 | { | 698 | { |
699 | // kdDebug()<<"KListView::focusInEvent()"<<endl; | 699 | // kdDebug()<<"KListView::focusInEvent()"<<endl; |
700 | QListView::focusInEvent( fe ); | 700 | QListView::focusInEvent( fe ); |
701 | if ((d->selectedBySimpleMove) | 701 | if ((d->selectedBySimpleMove) |
702 | && (d->selectionMode == FileManager) | 702 | && (d->selectionMode == FileManager) |
703 | && (fe->reason()!=QFocusEvent::Popup) | 703 | && (fe->reason()!=QFocusEvent::Popup) |
704 | && (fe->reason()!=QFocusEvent::ActiveWindow) | 704 | && (fe->reason()!=QFocusEvent::ActiveWindow) |
705 | && (currentItem()!=0)) | 705 | && (currentItem()!=0)) |
706 | { | 706 | { |
707 | currentItem()->setSelected(true); | 707 | currentItem()->setSelected(true); |
708 | currentItem()->repaint(); | 708 | currentItem()->repaint(); |
709 | emit selectionChanged(); | 709 | emit selectionChanged(); |
710 | }; | 710 | }; |
711 | } | 711 | } |
712 | 712 | ||
713 | void KListView::focusOutEvent( QFocusEvent *fe ) | 713 | void KListView::focusOutEvent( QFocusEvent *fe ) |
714 | { | 714 | { |
715 | cleanDropVisualizer(); | 715 | cleanDropVisualizer(); |
716 | cleanItemHighlighter(); | 716 | cleanItemHighlighter(); |
717 | 717 | ||
718 | d->autoSelect.stop(); | 718 | d->autoSelect.stop(); |
719 | 719 | ||
720 | if ((d->selectedBySimpleMove) | 720 | if ((d->selectedBySimpleMove) |
721 | && (d->selectionMode == FileManager) | 721 | && (d->selectionMode == FileManager) |
722 | && (fe->reason()!=QFocusEvent::Popup) | 722 | && (fe->reason()!=QFocusEvent::Popup) |
723 | && (fe->reason()!=QFocusEvent::ActiveWindow) | 723 | && (fe->reason()!=QFocusEvent::ActiveWindow) |
724 | && (currentItem()!=0) | 724 | && (currentItem()!=0) |
725 | /*US && (!d->editor->isVisible()) */ | 725 | /*US && (!d->editor->isVisible()) */ |
726 | ) | 726 | ) |
727 | { | 727 | { |
728 | currentItem()->setSelected(false); | 728 | currentItem()->setSelected(false); |
729 | currentItem()->repaint(); | 729 | currentItem()->repaint(); |
730 | emit selectionChanged(); | 730 | emit selectionChanged(); |
731 | }; | 731 | }; |
732 | 732 | ||
733 | QListView::focusOutEvent( fe ); | 733 | QListView::focusOutEvent( fe ); |
734 | } | 734 | } |
735 | 735 | ||
736 | void KListView::leaveEvent( QEvent *e ) | 736 | void KListView::leaveEvent( QEvent *e ) |
737 | { | 737 | { |
738 | d->autoSelect.stop(); | 738 | d->autoSelect.stop(); |
739 | 739 | ||
740 | QListView::leaveEvent( e ); | 740 | QListView::leaveEvent( e ); |
741 | } | 741 | } |
742 | 742 | ||
743 | bool KListView::event( QEvent *e ) | 743 | bool KListView::event( QEvent *e ) |
744 | { | 744 | { |
745 | if (e->type() == QEvent::ApplicationPaletteChange) { | 745 | if (e->type() == QEvent::ApplicationPaletteChange) { |
746 | qDebug("KListView::event make alternate color configurable"); | 746 | qDebug("KListView::event make alternate color configurable"); |
747 | //US d->alternateBackground=KGlobalSettings::alternateBackgroundColor(); | 747 | //US d->alternateBackground=KGlobalSettings::alternateBackgroundColor(); |
748 | d->alternateBackground = QColor(240, 240, 240); | 748 | d->alternateBackground = QColor(240, 240, 240); |
749 | } | 749 | } |
750 | 750 | ||
751 | return QListView::event(e); | 751 | return QListView::event(e); |
752 | } | 752 | } |
753 | 753 | ||
754 | void KListView::contentsMousePressEvent( QMouseEvent *e ) | 754 | void KListView::contentsMousePressEvent( QMouseEvent *e ) |
755 | { | 755 | { |
756 | if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) | 756 | if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) |
757 | { | 757 | { |
758 | bool block = signalsBlocked(); | 758 | bool block = signalsBlocked(); |
759 | blockSignals( true ); | 759 | blockSignals( true ); |
760 | 760 | ||
761 | clearSelection(); | 761 | clearSelection(); |
762 | 762 | ||
763 | blockSignals( block ); | 763 | blockSignals( block ); |
764 | } | 764 | } |
765 | else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) | 765 | else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) |
766 | { | 766 | { |
767 | d->selectedBySimpleMove=false; | 767 | d->selectedBySimpleMove=false; |
768 | d->selectedUsingMouse=true; | 768 | d->selectedUsingMouse=true; |
769 | if (currentItem()!=0) | 769 | if (currentItem()!=0) |
770 | { | 770 | { |
771 | currentItem()->setSelected(false); | 771 | currentItem()->setSelected(false); |
772 | currentItem()->repaint(); | 772 | currentItem()->repaint(); |
773 | // emit selectionChanged(); | 773 | // emit selectionChanged(); |
774 | }; | 774 | }; |
775 | }; | 775 | }; |
776 | 776 | ||
777 | QPoint p( contentsToViewport( e->pos() ) ); | 777 | QPoint p( contentsToViewport( e->pos() ) ); |
778 | QListViewItem *at = itemAt (p); | 778 | QListViewItem *at = itemAt (p); |
779 | 779 | ||
780 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) | 780 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) |
781 | bool rootDecoClicked = at | 781 | bool rootDecoClicked = at |
782 | && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + | 782 | && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + |
783 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) | 783 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) |
784 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); | 784 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); |
785 | 785 | ||
786 | if (e->button() == LeftButton && !rootDecoClicked) | 786 | if (e->button() == LeftButton && !rootDecoClicked) |
787 | { | 787 | { |
788 | //Start a drag | 788 | //Start a drag |
789 | d->startDragPos = e->pos(); | 789 | d->startDragPos = e->pos(); |
790 | 790 | ||
791 | if (at) | 791 | if (at) |
792 | { | 792 | { |
793 | d->validDrag = true; | 793 | d->validDrag = true; |
794 | d->pressedOnSelected = at->isSelected(); | 794 | d->pressedOnSelected = at->isSelected(); |
795 | } | 795 | } |
796 | } | 796 | } |
797 | 797 | ||
798 | QListView::contentsMousePressEvent( e ); | 798 | QListView::contentsMousePressEvent( e ); |
799 | } | 799 | } |
800 | 800 | ||
801 | void KListView::contentsMouseMoveEvent( QMouseEvent *e ) | 801 | void KListView::contentsMouseMoveEvent( QMouseEvent *e ) |
802 | { | 802 | { |
803 | if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) { | 803 | if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) { |
804 | QListView::contentsMouseMoveEvent (e); | 804 | QListView::contentsMouseMoveEvent (e); |
805 | return; | 805 | return; |
806 | } | 806 | } |
807 | 807 | ||
808 | QPoint vp = contentsToViewport(e->pos()); | 808 | QPoint vp = contentsToViewport(e->pos()); |
809 | QListViewItem *item = itemAt( vp ); | 809 | QListViewItem *item = itemAt( vp ); |
810 | 810 | ||
811 | //do we process cursor changes at all? | 811 | //do we process cursor changes at all? |
812 | if ( item && d->bChangeCursorOverItem && d->bUseSingle ) | 812 | if ( item && d->bChangeCursorOverItem && d->bUseSingle ) |
813 | { | 813 | { |
814 | //Cursor moved on a new item or in/out the execute area | 814 | //Cursor moved on a new item or in/out the execute area |
815 | if( (item != d->pCurrentItem) || | 815 | if( (item != d->pCurrentItem) || |
816 | (isExecuteArea(vp) != d->cursorInExecuteArea) ) | 816 | (isExecuteArea(vp) != d->cursorInExecuteArea) ) |
817 | { | 817 | { |
818 | d->cursorInExecuteArea = isExecuteArea(vp); | 818 | d->cursorInExecuteArea = isExecuteArea(vp); |
819 | qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet"); | 819 | qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet"); |
820 | /*US | 820 | /*US |
821 | if( d->cursorInExecuteArea ) //cursor moved in execute area | 821 | if( d->cursorInExecuteArea ) //cursor moved in execute area |
822 | viewport()->setCursor( KCursor::handCursor() ); | 822 | viewport()->setCursor( KCursor::handCursor() ); |
823 | else //cursor moved out of execute area | 823 | else //cursor moved out of execute area |
824 | viewport()->unsetCursor(); | 824 | viewport()->unsetCursor(); |
825 | */ | 825 | */ |
826 | } | 826 | } |
827 | } | 827 | } |
828 | 828 | ||
829 | bool dragOn = dragEnabled(); | 829 | bool dragOn = dragEnabled(); |
830 | QPoint newPos = e->pos(); | 830 | QPoint newPos = e->pos(); |
831 | if (dragOn && d->validDrag && | 831 | if (dragOn && d->validDrag && |
832 | (newPos.x() > d->startDragPos.x()+d->dragDelay || | 832 | (newPos.x() > d->startDragPos.x()+d->dragDelay || |
833 | newPos.x() < d->startDragPos.x()-d->dragDelay || | 833 | newPos.x() < d->startDragPos.x()-d->dragDelay || |
834 | newPos.y() > d->startDragPos.y()+d->dragDelay || | 834 | newPos.y() > d->startDragPos.y()+d->dragDelay || |
835 | newPos.y() < d->startDragPos.y()-d->dragDelay)) | 835 | newPos.y() < d->startDragPos.y()-d->dragDelay)) |
836 | //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) | 836 | //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) |
837 | { | 837 | { |
838 | QListView::contentsMouseReleaseEvent( 0 ); | 838 | QListView::contentsMouseReleaseEvent( 0 ); |
839 | startDrag(); | 839 | startDrag(); |
840 | d->startDragPos = QPoint(); | 840 | d->startDragPos = QPoint(); |
841 | d->validDrag = false; | 841 | d->validDrag = false; |
842 | } | 842 | } |
843 | } | 843 | } |
844 | 844 | ||
845 | void KListView::contentsMouseReleaseEvent( QMouseEvent *e ) | 845 | void KListView::contentsMouseReleaseEvent( QMouseEvent *e ) |
846 | { | 846 | { |
847 | if (e->button() == LeftButton) | 847 | if (e->button() == LeftButton) |
848 | { | 848 | { |
849 | // If the row was already selected, maybe we want to start an in-place editing | 849 | // If the row was already selected, maybe we want to start an in-place editing |
850 | if ( d->pressedOnSelected && itemsRenameable() ) | 850 | if ( d->pressedOnSelected && itemsRenameable() ) |
851 | { | 851 | { |
852 | QPoint p( contentsToViewport( e->pos() ) ); | 852 | QPoint p( contentsToViewport( e->pos() ) ); |
853 | QListViewItem *at = itemAt (p); | 853 | QListViewItem *at = itemAt (p); |
854 | if ( at ) | 854 | if ( at ) |
855 | { | 855 | { |
856 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) | 856 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) |
857 | bool rootDecoClicked = | 857 | bool rootDecoClicked = |
858 | ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + | 858 | ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + |
859 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) | 859 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) |
860 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); | 860 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); |
861 | 861 | ||
862 | if (!rootDecoClicked) | 862 | if (!rootDecoClicked) |
863 | { | 863 | { |
864 | int col = header()->mapToLogical( header()->cellAt( p.x() ) ); | 864 | int col = header()->mapToLogical( header()->cellAt( p.x() ) ); |
865 | if ( d->renameable.contains(col) ) | 865 | if ( d->renameable.contains(col) ) |
866 | rename(at, col); | 866 | rename(at, col); |
867 | } | 867 | } |
868 | } | 868 | } |
869 | } | 869 | } |
870 | 870 | ||
871 | d->pressedOnSelected = false; | 871 | d->pressedOnSelected = false; |
872 | d->validDrag = false; | 872 | d->validDrag = false; |
873 | d->startDragPos = QPoint(); | 873 | d->startDragPos = QPoint(); |
874 | } | 874 | } |
875 | QListView::contentsMouseReleaseEvent( e ); | 875 | QListView::contentsMouseReleaseEvent( e ); |
876 | } | 876 | } |
877 | 877 | ||
878 | void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e ) | 878 | void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e ) |
879 | { | 879 | { |
880 | // We don't want to call the parent method because it does setOpen, | 880 | // We don't want to call the parent method because it does setOpen, |
881 | // whereas we don't do it in single click mode... (David) | 881 | // whereas we don't do it in single click mode... (David) |
882 | //QListView::contentsMouseDoubleClickEvent( e ); | 882 | //QListView::contentsMouseDoubleClickEvent( e ); |
883 | 883 | ||
884 | QPoint vp = contentsToViewport(e->pos()); | 884 | QPoint vp = contentsToViewport(e->pos()); |
885 | QListViewItem *item = itemAt( vp ); | 885 | QListViewItem *item = itemAt( vp ); |
886 | emit QListView::doubleClicked( item ); // we do it now | 886 | emit QListView::doubleClicked( item ); // we do it now |
887 | 887 | ||
888 | int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; | 888 | int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; |
889 | 889 | ||
890 | if( item ) { | 890 | if( item ) { |
891 | emit doubleClicked( item, e->globalPos(), col ); | 891 | emit doubleClicked( item, e->globalPos(), col ); |
892 | 892 | ||
893 | if( (e->button() == LeftButton) && !d->bUseSingle ) | 893 | if( (e->button() == LeftButton) && !d->bUseSingle ) |
894 | emitExecute( item, e->globalPos(), col ); | 894 | emitExecute( item, e->globalPos(), col ); |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c ) | 898 | void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c ) |
899 | { | 899 | { |
900 | if( (btn == LeftButton) && item ) | 900 | if( (btn == LeftButton) && item ) |
901 | emitExecute(item, pos, c); | 901 | emitExecute(item, pos, c); |
902 | } | 902 | } |
903 | 903 | ||
904 | void KListView::contentsDropEvent(QDropEvent* e) | 904 | void KListView::contentsDropEvent(QDropEvent* e) |
905 | { | 905 | { |
906 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); | 906 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); |
907 | /*US | 907 | /*US |
908 | cleanDropVisualizer(); | 908 | cleanDropVisualizer(); |
909 | cleanItemHighlighter(); | 909 | cleanItemHighlighter(); |
910 | d->dragExpand.stop(); | 910 | d->dragExpand.stop(); |
911 | 911 | ||
912 | if (acceptDrag (e)) | 912 | if (acceptDrag (e)) |
913 | { | 913 | { |
914 | e->acceptAction(); | 914 | e->acceptAction(); |
915 | QListViewItem *afterme; | 915 | QListViewItem *afterme; |
916 | QListViewItem *parent; | 916 | QListViewItem *parent; |
917 | findDrop(e->pos(), parent, afterme); | 917 | findDrop(e->pos(), parent, afterme); |
918 | 918 | ||
919 | if (e->source() == viewport() && itemsMovable()) | 919 | if (e->source() == viewport() && itemsMovable()) |
920 | movableDropEvent(parent, afterme); | 920 | movableDropEvent(parent, afterme); |
921 | else | 921 | else |
922 | { | 922 | { |
923 | 923 | ||
924 | emit dropped(e, afterme); | 924 | emit dropped(e, afterme); |
925 | emit dropped(this, e, afterme); | 925 | emit dropped(this, e, afterme); |
926 | emit dropped(e, parent, afterme); | 926 | emit dropped(e, parent, afterme); |
927 | emit dropped(this, e, parent, afterme); | 927 | emit dropped(this, e, parent, afterme); |
928 | 928 | ||
929 | } | 929 | } |
930 | } | 930 | } |
931 | */ | 931 | */ |
932 | 932 | ||
933 | } | 933 | } |
934 | 934 | ||
935 | void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme) | 935 | void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme) |
936 | { | 936 | { |
937 | QPtrList<QListViewItem> items, afterFirsts, afterNows; | 937 | QPtrList<QListViewItem> items, afterFirsts, afterNows; |
938 | QListViewItem *current=currentItem(); | 938 | QListViewItem *current=currentItem(); |
939 | bool hasMoved=false; | 939 | bool hasMoved=false; |
940 | for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) | 940 | for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) |
941 | { | 941 | { |
942 | iNext=i->itemBelow(); | 942 | iNext=i->itemBelow(); |
943 | if (!i->isSelected()) | 943 | if (!i->isSelected()) |
944 | continue; | 944 | continue; |
945 | 945 | ||
946 | // don't drop an item after itself, or else | 946 | // don't drop an item after itself, or else |
947 | // it moves to the top of the list | 947 | // it moves to the top of the list |
948 | if (i==afterme) | 948 | if (i==afterme) |
949 | continue; | 949 | continue; |
950 | 950 | ||
951 | i->setSelected(false); | 951 | i->setSelected(false); |
952 | 952 | ||
953 | QListViewItem *afterFirst = i->itemAbove(); | 953 | QListViewItem *afterFirst = i->itemAbove(); |
954 | 954 | ||
955 | if (!hasMoved) | 955 | if (!hasMoved) |
956 | { | 956 | { |
957 | emit aboutToMove(); | 957 | emit aboutToMove(); |
958 | hasMoved=true; | 958 | hasMoved=true; |
959 | } | 959 | } |
960 | 960 | ||
961 | moveItem(i, parent, afterme); | 961 | moveItem(i, parent, afterme); |
962 | 962 | ||
963 | // ###### This should include the new parent !!! -> KDE 3.0 | 963 | // ###### This should include the new parent !!! -> KDE 3.0 |
964 | // If you need this right now, have a look at keditbookmarks. | 964 | // If you need this right now, have a look at keditbookmarks. |
965 | emit moved(i, afterFirst, afterme); | 965 | emit moved(i, afterFirst, afterme); |
966 | 966 | ||
967 | items.append (i); | 967 | items.append (i); |
968 | afterFirsts.append (afterFirst); | 968 | afterFirsts.append (afterFirst); |
969 | afterNows.append (afterme); | 969 | afterNows.append (afterme); |
970 | 970 | ||
971 | afterme = i; | 971 | afterme = i; |
972 | } | 972 | } |
973 | clearSelection(); | 973 | clearSelection(); |
974 | for (QListViewItem *i=items.first(); i != 0; i=items.next() ) | 974 | for (QListViewItem *i=items.first(); i != 0; i=items.next() ) |
975 | i->setSelected(true); | 975 | i->setSelected(true); |
976 | if (current) | 976 | if (current) |
977 | setCurrentItem(current); | 977 | setCurrentItem(current); |
978 | 978 | ||
979 | emit moved(items,afterFirsts,afterNows); | 979 | emit moved(items,afterFirsts,afterNows); |
980 | 980 | ||
981 | if (firstChild()) | 981 | if (firstChild()) |
982 | emit moved(); | 982 | emit moved(); |
983 | } | 983 | } |
984 | 984 | ||
985 | void KListView::contentsDragMoveEvent(QDragMoveEvent *event) | 985 | void KListView::contentsDragMoveEvent(QDragMoveEvent *event) |
986 | { | 986 | { |
987 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); | 987 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); |
988 | /*US | 988 | /*US |
989 | if (acceptDrag(event)) | 989 | if (acceptDrag(event)) |
990 | { | 990 | { |
991 | event->acceptAction(); | 991 | event->acceptAction(); |
992 | //Clean up the view | 992 | //Clean up the view |
993 | 993 | ||
994 | findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); | 994 | findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); |
995 | QPoint vp = contentsToViewport( event->pos() ); | 995 | QPoint vp = contentsToViewport( event->pos() ); |
996 | QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; | 996 | QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; |
997 | 997 | ||
998 | if ( item != d->dragOverItem ) | 998 | if ( item != d->dragOverItem ) |
999 | { | 999 | { |
1000 | d->dragExpand.stop(); | 1000 | d->dragExpand.stop(); |
1001 | d->dragOverItem = item; | 1001 | d->dragOverItem = item; |
1002 | d->dragOverPoint = vp; | 1002 | d->dragOverPoint = vp; |
1003 | if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) | 1003 | if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) |
1004 | d->dragExpand.start( QApplication::startDragTime(), true ); | 1004 | d->dragExpand.start( QApplication::startDragTime(), true ); |
1005 | } | 1005 | } |
1006 | if (dropVisualizer()) | 1006 | if (dropVisualizer()) |
1007 | { | 1007 | { |
1008 | QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); | 1008 | QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); |
1009 | if (tmpRect != d->mOldDropVisualizer) | 1009 | if (tmpRect != d->mOldDropVisualizer) |
1010 | { | 1010 | { |
1011 | cleanDropVisualizer(); | 1011 | cleanDropVisualizer(); |
1012 | d->mOldDropVisualizer=tmpRect; | 1012 | d->mOldDropVisualizer=tmpRect; |
1013 | viewport()->repaint(tmpRect); | 1013 | viewport()->repaint(tmpRect); |
1014 | } | 1014 | } |
1015 | } | 1015 | } |
1016 | if (dropHighlighter()) | 1016 | if (dropHighlighter()) |
1017 | { | 1017 | { |
1018 | QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop); | 1018 | QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop); |
1019 | if (tmpRect != d->mOldDropHighlighter) | 1019 | if (tmpRect != d->mOldDropHighlighter) |
1020 | { | 1020 | { |
1021 | cleanItemHighlighter(); | 1021 | cleanItemHighlighter(); |
1022 | d->mOldDropHighlighter=tmpRect; | 1022 | d->mOldDropHighlighter=tmpRect; |
1023 | viewport()->repaint(tmpRect); | 1023 | viewport()->repaint(tmpRect); |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | } | 1026 | } |
1027 | else | 1027 | else |
1028 | event->ignore(); | 1028 | event->ignore(); |
1029 | */ | 1029 | */ |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | void KListView::slotDragExpand() | 1032 | void KListView::slotDragExpand() |
1033 | { | 1033 | { |
1034 | if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) | 1034 | if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) |
1035 | d->dragOverItem->setOpen( true ); | 1035 | d->dragOverItem->setOpen( true ); |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | void KListView::contentsDragLeaveEvent (QDragLeaveEvent*) | 1038 | void KListView::contentsDragLeaveEvent (QDragLeaveEvent*) |
1039 | { | 1039 | { |
1040 | d->dragExpand.stop(); | 1040 | d->dragExpand.stop(); |
1041 | cleanDropVisualizer(); | 1041 | cleanDropVisualizer(); |
1042 | cleanItemHighlighter(); | 1042 | cleanItemHighlighter(); |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | void KListView::cleanDropVisualizer() | 1045 | void KListView::cleanDropVisualizer() |
1046 | { | 1046 | { |
1047 | if (d->mOldDropVisualizer.isValid()) | 1047 | if (d->mOldDropVisualizer.isValid()) |
1048 | { | 1048 | { |
1049 | QRect rect=d->mOldDropVisualizer; | 1049 | QRect rect=d->mOldDropVisualizer; |
1050 | d->mOldDropVisualizer = QRect(); | 1050 | d->mOldDropVisualizer = QRect(); |
1051 | viewport()->repaint(rect, true); | 1051 | viewport()->repaint(rect, true); |
1052 | } | 1052 | } |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | int KListView::depthToPixels( int depth ) | 1055 | int KListView::depthToPixels( int depth ) |
1056 | { | 1056 | { |
1057 | return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); | 1057 | return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after) | 1060 | void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after) |
1061 | { | 1061 | { |
1062 | QPoint p (contentsToViewport(pos)); | 1062 | QPoint p (contentsToViewport(pos)); |
1063 | 1063 | ||
1064 | // Get the position to put it in | 1064 | // Get the position to put it in |
1065 | QListViewItem *atpos = itemAt(p); | 1065 | QListViewItem *atpos = itemAt(p); |
1066 | 1066 | ||
1067 | QListViewItem *above; | 1067 | QListViewItem *above; |
1068 | if (!atpos) // put it at the end | 1068 | if (!atpos) // put it at the end |
1069 | above = lastItem(); | 1069 | above = lastItem(); |
1070 | else | 1070 | else |
1071 | { | 1071 | { |
1072 | // Get the closest item before us ('atpos' or the one above, if any) | 1072 | // Get the closest item before us ('atpos' or the one above, if any) |
1073 | if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) | 1073 | if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) |
1074 | above = atpos->itemAbove(); | 1074 | above = atpos->itemAbove(); |
1075 | else | 1075 | else |
1076 | above = atpos; | 1076 | above = atpos; |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | if (above) | 1079 | if (above) |
1080 | { | 1080 | { |
1081 | // Now, we know we want to go after "above". But as a child or as a sibling ? | 1081 | // Now, we know we want to go after "above". But as a child or as a sibling ? |
1082 | // We have to ask the "above" item if it accepts children. | 1082 | // We have to ask the "above" item if it accepts children. |
1083 | if (above->isExpandable()) | 1083 | if (above->isExpandable()) |
1084 | { | 1084 | { |
1085 | // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children | 1085 | // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children |
1086 | if (p.x() >= depthToPixels( above->depth() + 1 ) || | 1086 | if (p.x() >= depthToPixels( above->depth() + 1 ) || |
1087 | (above->isOpen() && above->childCount() > 0) ) | 1087 | (above->isOpen() && above->childCount() > 0) ) |
1088 | { | 1088 | { |
1089 | parent = above; | 1089 | parent = above; |
1090 | after = 0L; | 1090 | after = 0L; |
1091 | return; | 1091 | return; |
1092 | } | 1092 | } |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | // Ok, there's one more level of complexity. We may want to become a new | 1095 | // Ok, there's one more level of complexity. We may want to become a new |
1096 | // sibling, but of an upper-level group, rather than the "above" item | 1096 | // sibling, but of an upper-level group, rather than the "above" item |
1097 | QListViewItem * betterAbove = above->parent(); | 1097 | QListViewItem * betterAbove = above->parent(); |
1098 | QListViewItem * last = above; | 1098 | QListViewItem * last = above; |
1099 | while ( betterAbove ) | 1099 | while ( betterAbove ) |
1100 | { | 1100 | { |
1101 | // We are allowed to become a sibling of "betterAbove" only if we are | 1101 | // We are allowed to become a sibling of "betterAbove" only if we are |
1102 | // after its last child | 1102 | // after its last child |
1103 | if ( last->nextSibling() == 0 ) | 1103 | if ( last->nextSibling() == 0 ) |
1104 | { | 1104 | { |
1105 | if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) | 1105 | if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) |
1106 | above = betterAbove; // store this one, but don't stop yet, there may be a better one | 1106 | above = betterAbove; // store this one, but don't stop yet, there may be a better one |
1107 | else | 1107 | else |
1108 | break; // not enough on the left, so stop | 1108 | break; // not enough on the left, so stop |
1109 | last = betterAbove; | 1109 | last = betterAbove; |
1110 | betterAbove = betterAbove->parent(); // up one level | 1110 | betterAbove = betterAbove->parent(); // up one level |
1111 | } else | 1111 | } else |
1112 | break; // we're among the child of betterAbove, not after the last one | 1112 | break; // we're among the child of betterAbove, not after the last one |
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | // set as sibling | 1115 | // set as sibling |
1116 | after = above; | 1116 | after = above; |
1117 | parent = after ? after->parent() : 0L ; | 1117 | parent = after ? after->parent() : 0L ; |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | QListViewItem* KListView::lastChild () const | 1120 | QListViewItem* KListView::lastChild () const |
1121 | { | 1121 | { |
1122 | QListViewItem* lastchild = firstChild(); | 1122 | QListViewItem* lastchild = firstChild(); |
1123 | 1123 | ||
1124 | if (lastchild) | 1124 | if (lastchild) |
1125 | for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); | 1125 | for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); |
1126 | 1126 | ||
1127 | return lastchild; | 1127 | return lastchild; |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | QListViewItem *KListView::lastItem() const | 1130 | QListViewItem *KListView::lastItem() const |
1131 | { | 1131 | { |
1132 | QListViewItem* last = lastChild(); | 1132 | QListViewItem* last = lastChild(); |
1133 | 1133 | ||
1134 | for (QListViewItemIterator it (last); it.current(); ++it) | 1134 | for (QListViewItemIterator it (last); it.current(); ++it) |
1135 | last = it.current(); | 1135 | last = it.current(); |
1136 | 1136 | ||
1137 | return last; | 1137 | return last; |
1138 | } | 1138 | } |
1139 | 1139 | ||
1140 | KLineEdit *KListView::renameLineEdit() const | 1140 | KLineEdit *KListView::renameLineEdit() const |
1141 | { | 1141 | { |
1142 | //US return d->editor; | 1142 | //US return d->editor; |
1143 | qDebug("KListView::renameLineEdit returns 0. Might crash"); | 1143 | qDebug("KListView::renameLineEdit returns 0. Might crash"); |
1144 | return 0; | 1144 | return 0; |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | void KListView::startDrag() | 1147 | void KListView::startDrag() |
1148 | { | 1148 | { |
1149 | qDebug("KListView::startDrag drag&drop not supported yet."); | 1149 | qDebug("KListView::startDrag drag&drop not supported yet."); |
1150 | /*US | 1150 | /*US |
1151 | QDragObject *drag = dragObject(); | 1151 | QDragObject *drag = dragObject(); |
1152 | 1152 | ||
1153 | if (!drag) | 1153 | if (!drag) |
1154 | return; | 1154 | return; |
1155 | 1155 | ||
1156 | if (drag->drag() && drag->target() != viewport()) | 1156 | if (drag->drag() && drag->target() != viewport()) |
1157 | emit moved(); | 1157 | emit moved(); |
1158 | */ | 1158 | */ |
1159 | } | 1159 | } |
1160 | 1160 | ||
1161 | QDragObject *KListView::dragObject() | 1161 | QDragObject *KListView::dragObject() |
1162 | { | 1162 | { |
1163 | if (!currentItem()) | 1163 | if (!currentItem()) |
1164 | return 0; | 1164 | return 0; |
1165 | 1165 | ||
1166 | return new QStoredDrag("application/x-qlistviewitem", viewport()); | 1166 | return new QStoredDrag("application/x-qlistviewitem", viewport()); |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | void KListView::setItemsMovable(bool b) | 1169 | void KListView::setItemsMovable(bool b) |
1170 | { | 1170 | { |
1171 | d->itemsMovable=b; | 1171 | d->itemsMovable=b; |
1172 | } | 1172 | } |
1173 | 1173 | ||
1174 | bool KListView::itemsMovable() const | 1174 | bool KListView::itemsMovable() const |
1175 | { | 1175 | { |
1176 | return d->itemsMovable; | 1176 | return d->itemsMovable; |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | void KListView::setItemsRenameable(bool b) | 1179 | void KListView::setItemsRenameable(bool b) |
1180 | { | 1180 | { |
1181 | d->itemsRenameable=b; | 1181 | d->itemsRenameable=b; |
1182 | } | 1182 | } |
1183 | 1183 | ||
1184 | bool KListView::itemsRenameable() const | 1184 | bool KListView::itemsRenameable() const |
1185 | { | 1185 | { |
1186 | return d->itemsRenameable; | 1186 | return d->itemsRenameable; |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | 1189 | ||
1190 | void KListView::setDragEnabled(bool b) | 1190 | void KListView::setDragEnabled(bool b) |
1191 | { | 1191 | { |
1192 | d->dragEnabled=b; | 1192 | d->dragEnabled=b; |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | bool KListView::dragEnabled() const | 1195 | bool KListView::dragEnabled() const |
1196 | { | 1196 | { |
1197 | return d->dragEnabled; | 1197 | return d->dragEnabled; |
1198 | } | 1198 | } |
1199 | 1199 | ||
1200 | void KListView::setAutoOpen(bool b) | 1200 | void KListView::setAutoOpen(bool b) |
1201 | { | 1201 | { |
1202 | d->autoOpen=b; | 1202 | d->autoOpen=b; |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | bool KListView::autoOpen() const | 1205 | bool KListView::autoOpen() const |
1206 | { | 1206 | { |
1207 | return d->autoOpen; | 1207 | return d->autoOpen; |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | bool KListView::dropVisualizer() const | 1210 | bool KListView::dropVisualizer() const |
1211 | { | 1211 | { |
1212 | return d->dropVisualizer; | 1212 | return d->dropVisualizer; |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | void KListView::setDropVisualizer(bool b) | 1215 | void KListView::setDropVisualizer(bool b) |
1216 | { | 1216 | { |
1217 | d->dropVisualizer=b; | 1217 | d->dropVisualizer=b; |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | QPtrList<QListViewItem> KListView::selectedItems() const | 1220 | QPtrList<QListViewItem> KListView::selectedItems() const |
1221 | { | 1221 | { |
1222 | QPtrList<QListViewItem> list; | 1222 | QPtrList<QListViewItem> list; |
1223 | for (QListViewItem *i=firstChild(); i!=0; i=i->itemBelow()) | 1223 | for (QListViewItem *i=firstChild(); i!=0; i=i->itemBelow()) |
1224 | if (i->isSelected()) list.append(i); | 1224 | if (i->isSelected()) list.append(i); |
1225 | return list; | 1225 | return list; |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | 1228 | ||
1229 | void KListView::moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after) | 1229 | void KListView::moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after) |
1230 | { | 1230 | { |
1231 | // sanity check - don't move a item into it's own child structure | 1231 | // sanity check - don't move a item into it's own child structure |
1232 | QListViewItem *i = parent; | 1232 | QListViewItem *i = parent; |
1233 | while(i) | 1233 | while(i) |
1234 | { | 1234 | { |
1235 | if(i == item) | 1235 | if(i == item) |
1236 | return; | 1236 | return; |
1237 | i = i->parent(); | 1237 | i = i->parent(); |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | // Basically reimplementing the QListViewItem(QListViewItem*, QListViewItem*) constructor | 1240 | // Basically reimplementing the QListViewItem(QListViewItem*, QListViewItem*) constructor |
1241 | // in here, without ever deleting the item. | 1241 | // in here, without ever deleting the item. |
1242 | if (item->parent()) | 1242 | if (item->parent()) |
1243 | item->parent()->takeItem(item); | 1243 | item->parent()->takeItem(item); |
1244 | else | 1244 | else |
1245 | takeItem(item); | 1245 | takeItem(item); |
1246 | 1246 | ||
1247 | if (parent) | 1247 | if (parent) |
1248 | parent->insertItem(item); | 1248 | parent->insertItem(item); |
1249 | else | 1249 | else |
1250 | insertItem(item); | 1250 | insertItem(item); |
1251 | 1251 | ||
1252 | if (after) | 1252 | if (after) |
1253 | ;//item->moveToJustAfter(after); | 1253 | ;//item->moveToJustAfter(after); |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | void KListView::contentsDragEnterEvent(QDragEnterEvent *event) | 1256 | void KListView::contentsDragEnterEvent(QDragEnterEvent *event) |
1257 | { | 1257 | { |
1258 | qDebug("KListView::contentsDragEnterEvent drag&drop not supported yet."); | 1258 | qDebug("KListView::contentsDragEnterEvent drag&drop not supported yet."); |
1259 | /*US | 1259 | /*US |
1260 | if (acceptDrag (event)) | 1260 | if (acceptDrag (event)) |
1261 | event->accept(); | 1261 | event->accept(); |
1262 | */ | 1262 | */ |
1263 | } | 1263 | } |
1264 | 1264 | ||
1265 | void KListView::setDropVisualizerWidth (int w) | 1265 | void KListView::setDropVisualizerWidth (int w) |
1266 | { | 1266 | { |
1267 | d->mDropVisualizerWidth = w > 0 ? w : 1; | 1267 | d->mDropVisualizerWidth = w > 0 ? w : 1; |
1268 | } | 1268 | } |
1269 | 1269 | ||
1270 | QRect KListView::drawDropVisualizer(QPainter *p, QListViewItem *parent, | 1270 | QRect KListView::drawDropVisualizer(QPainter *p, QListViewItem *parent, |
1271 | QListViewItem *after) | 1271 | QListViewItem *after) |
1272 | { | 1272 | { |
1273 | QRect insertmarker; | 1273 | QRect insertmarker; |
1274 | 1274 | ||
1275 | if (!after && !parent) | 1275 | if (!after && !parent) |
1276 | insertmarker = QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); | 1276 | insertmarker = QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); |
1277 | else | 1277 | else |
1278 | { | 1278 | { |
1279 | int level = 0; | 1279 | int level = 0; |
1280 | if (after) | 1280 | if (after) |
1281 | { | 1281 | { |
1282 | QListViewItem* it = 0L; | 1282 | QListViewItem* it = 0L; |
1283 | if (after->isOpen()) | 1283 | if (after->isOpen()) |
1284 | { | 1284 | { |
1285 | // Look for the last child (recursively) | 1285 | // Look for the last child (recursively) |
1286 | it = after->firstChild(); | 1286 | it = after->firstChild(); |
1287 | if (it) | 1287 | if (it) |
1288 | while (it->nextSibling() || it->firstChild()) | 1288 | while (it->nextSibling() || it->firstChild()) |
1289 | if ( it->nextSibling() ) | 1289 | if ( it->nextSibling() ) |
1290 | it = it->nextSibling(); | 1290 | it = it->nextSibling(); |
1291 | else | 1291 | else |
1292 | it = it->firstChild(); | 1292 | it = it->firstChild(); |
1293 | } | 1293 | } |
1294 | 1294 | ||
1295 | insertmarker = itemRect (it ? it : after); | 1295 | insertmarker = itemRect (it ? it : after); |
1296 | level = after->depth(); | 1296 | level = after->depth(); |
1297 | } | 1297 | } |
1298 | else if (parent) | 1298 | else if (parent) |
1299 | { | 1299 | { |
1300 | insertmarker = itemRect (parent); | 1300 | insertmarker = itemRect (parent); |
1301 | level = parent->depth() + 1; | 1301 | level = parent->depth() + 1; |
1302 | } | 1302 | } |
1303 | insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); | 1303 | insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); |
1304 | insertmarker.setRight (viewport()->width()); | 1304 | insertmarker.setRight (viewport()->width()); |
1305 | insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); | 1305 | insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); |
1306 | insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); | 1306 | insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); |
1307 | } | 1307 | } |
1308 | 1308 | ||
1309 | // This is not used anymore, at least by KListView itself (see viewportPaintEvent) | 1309 | // This is not used anymore, at least by KListView itself (see viewportPaintEvent) |
1310 | // Remove for KDE 3.0. | 1310 | // Remove for KDE 3.0. |
1311 | if (p) | 1311 | if (p) |
1312 | p->fillRect(insertmarker, Dense4Pattern); | 1312 | p->fillRect(insertmarker, Dense4Pattern); |
1313 | 1313 | ||
1314 | return insertmarker; | 1314 | return insertmarker; |
1315 | } | 1315 | } |
1316 | 1316 | ||
1317 | QRect KListView::drawItemHighlighter(QPainter *painter, QListViewItem *item) | 1317 | QRect KListView::drawItemHighlighter(QPainter *painter, QListViewItem *item) |
1318 | { | 1318 | { |
1319 | QRect r; | 1319 | QRect r; |
1320 | 1320 | ||
1321 | if (item) | 1321 | if (item) |
1322 | { | 1322 | { |
1323 | r = itemRect(item); | 1323 | r = itemRect(item); |
1324 | r.setLeft(r.left()+(item->depth()+1)*treeStepSize()); | 1324 | r.setLeft(r.left()+(item->depth()+1)*treeStepSize()); |
1325 | if (painter) { | 1325 | if (painter) { |
1326 | //US style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(), | 1326 | //US style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(), |
1327 | //US QStyle::Style_FocusAtBorder, colorGroup().highlight()); | 1327 | //US QStyle::Style_FocusAtBorder, colorGroup().highlight()); |
1328 | const QColor* pHighl = &(colorGroup().highlight()); | 1328 | const QColor* pHighl = &(colorGroup().highlight()); |
1329 | //LR style().drawFocusRect(painter, r, colorGroup(), pHighl, true); | 1329 | //LR style().drawFocusRect(painter, r, colorGroup(), pHighl, true); |
1330 | 1330 | ||
1331 | qDebug("KListView::drawItemHighlighter has to be verified"); | 1331 | qDebug("KListView::drawItemHighlighter has to be verified"); |
1332 | 1332 | ||
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | } | 1335 | } |
1336 | 1336 | ||
1337 | return r; | 1337 | return r; |
1338 | } | 1338 | } |
1339 | 1339 | ||
1340 | void KListView::cleanItemHighlighter () | 1340 | void KListView::cleanItemHighlighter () |
1341 | { | 1341 | { |
1342 | if (d->mOldDropHighlighter.isValid()) | 1342 | if (d->mOldDropHighlighter.isValid()) |
1343 | { | 1343 | { |
1344 | QRect rect=d->mOldDropHighlighter; | 1344 | QRect rect=d->mOldDropHighlighter; |
1345 | d->mOldDropHighlighter = QRect(); | 1345 | d->mOldDropHighlighter = QRect(); |
1346 | viewport()->repaint(rect, true); | 1346 | viewport()->repaint(rect, true); |
1347 | } | 1347 | } |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KListView::rename(QListViewItem *item, int c) | 1350 | void KListView::rename(QListViewItem *item, int c) |
1351 | { | 1351 | { |
1352 | if (d->renameable.contains(c)) | 1352 | if (d->renameable.contains(c)) |
1353 | { | 1353 | { |
1354 | ensureItemVisible(item); | 1354 | ensureItemVisible(item); |
1355 | //US d->editor->load(item,c); | 1355 | //US d->editor->load(item,c); |
1356 | qDebug("KListView::rename has to be verified"); | 1356 | qDebug("KListView::rename has to be verified"); |
1357 | 1357 | ||
1358 | } | 1358 | } |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | bool KListView::isRenameable (int col) const | 1361 | bool KListView::isRenameable (int col) const |
1362 | { | 1362 | { |
1363 | return d->renameable.contains(col); | 1363 | return d->renameable.contains(col); |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | void KListView::setRenameable (int col, bool yesno) | 1366 | void KListView::setRenameable (int col, bool yesno) |
1367 | { | 1367 | { |
1368 | if (col>=header()->count()) return; | 1368 | if (col>=header()->count()) return; |
1369 | 1369 | ||
1370 | d->renameable.remove(col); | 1370 | d->renameable.remove(col); |
1371 | if (yesno && d->renameable.find(col)==d->renameable.end()) | 1371 | if (yesno && d->renameable.find(col)==d->renameable.end()) |
1372 | d->renameable+=col; | 1372 | d->renameable+=col; |
1373 | else if (!yesno && d->renameable.find(col)!=d->renameable.end()) | 1373 | else if (!yesno && d->renameable.find(col)!=d->renameable.end()) |
1374 | d->renameable.remove(col); | 1374 | d->renameable.remove(col); |
1375 | } | 1375 | } |
1376 | 1376 | ||
1377 | void KListView::doneEditing(QListViewItem *item, int row) | 1377 | void KListView::doneEditing(QListViewItem *item, int row) |
1378 | { | 1378 | { |
1379 | emit itemRenamed(item, item->text(row), row); | 1379 | emit itemRenamed(item, item->text(row), row); |
1380 | emit itemRenamed(item); | 1380 | emit itemRenamed(item); |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | bool KListView::acceptDrag(QDropEvent* e) const | 1383 | bool KListView::acceptDrag(QDropEvent* e) const |
1384 | { | 1384 | { |
1385 | qDebug("KListView::acceptDrag drag&drop not supported yet"); | 1385 | qDebug("KListView::acceptDrag drag&drop not supported yet"); |
1386 | //US return acceptDrops() && itemsMovable() && (e->source()==viewport()); | 1386 | //US return acceptDrops() && itemsMovable() && (e->source()==viewport()); |
1387 | return false; | 1387 | return false; |
1388 | } | 1388 | } |
1389 | 1389 | ||
1390 | void KListView::setCreateChildren(bool b) | 1390 | void KListView::setCreateChildren(bool b) |
1391 | { | 1391 | { |
1392 | d->createChildren=b; | 1392 | d->createChildren=b; |
1393 | } | 1393 | } |
1394 | 1394 | ||
1395 | bool KListView::createChildren() const | 1395 | bool KListView::createChildren() const |
1396 | { | 1396 | { |
1397 | return d->createChildren; | 1397 | return d->createChildren; |
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | 1400 | ||
1401 | int KListView::tooltipColumn() const | 1401 | int KListView::tooltipColumn() const |
1402 | { | 1402 | { |
1403 | return d->tooltipColumn; | 1403 | return d->tooltipColumn; |
1404 | } | 1404 | } |
1405 | 1405 | ||
1406 | void KListView::setTooltipColumn(int column) | 1406 | void KListView::setTooltipColumn(int column) |
1407 | { | 1407 | { |
1408 | d->tooltipColumn=column; | 1408 | d->tooltipColumn=column; |
1409 | } | 1409 | } |
1410 | 1410 | ||
1411 | void KListView::setDropHighlighter(bool b) | 1411 | void KListView::setDropHighlighter(bool b) |
1412 | { | 1412 | { |
1413 | d->dropHighlighter=b; | 1413 | d->dropHighlighter=b; |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | bool KListView::dropHighlighter() const | 1416 | bool KListView::dropHighlighter() const |
1417 | { | 1417 | { |
1418 | return d->dropHighlighter; | 1418 | return d->dropHighlighter; |
1419 | } | 1419 | } |
1420 | 1420 | ||
1421 | bool KListView::showTooltip(QListViewItem *item, const QPoint &, int column) const | 1421 | bool KListView::showTooltip(QListViewItem *item, const QPoint &, int column) const |
1422 | { | 1422 | { |
1423 | return ((tooltip(item, column).length()>0) && (column==tooltipColumn())); | 1423 | return ((tooltip(item, column).length()>0) && (column==tooltipColumn())); |
1424 | } | 1424 | } |
1425 | 1425 | ||
1426 | QString KListView::tooltip(QListViewItem *item, int column) const | 1426 | QString KListView::tooltip(QListViewItem *item, int column) const |
1427 | { | 1427 | { |
1428 | return item->text(column); | 1428 | return item->text(column); |
1429 | } | 1429 | } |
1430 | 1430 | ||
1431 | void KListView::setTabOrderedRenaming(bool b) | 1431 | void KListView::setTabOrderedRenaming(bool b) |
1432 | { | 1432 | { |
1433 | d->tabRename = b; | 1433 | d->tabRename = b; |
1434 | } | 1434 | } |
1435 | 1435 | ||
1436 | bool KListView::tabOrderedRenaming() const | 1436 | bool KListView::tabOrderedRenaming() const |
1437 | { | 1437 | { |
1438 | return d->tabRename; | 1438 | return d->tabRename; |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | void KListView::keyPressEvent (QKeyEvent* e) | 1441 | void KListView::keyPressEvent (QKeyEvent* e) |
1442 | { | 1442 | { |
1443 | //don't we need a contextMenuModifier too ? (aleXXX) | 1443 | //don't we need a contextMenuModifier too ? (aleXXX) |
1444 | if (e->key() == d->contextMenuKey) | 1444 | if (e->key() == d->contextMenuKey) |
1445 | { | 1445 | { |
1446 | emit menuShortCutPressed (this, currentItem()); | 1446 | emit menuShortCutPressed (this, currentItem()); |
1447 | return; | 1447 | return; |
1448 | } | 1448 | } |
1449 | if (e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace) | 1449 | if (e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace) |
1450 | { | 1450 | { |
1451 | emit signalDelete ( ); | 1451 | emit signalDelete ( ); |
1452 | return; | 1452 | return; |
1453 | } | 1453 | } |
1454 | 1454 | ||
1455 | if (d->selectionMode != FileManager) | 1455 | if (d->selectionMode != FileManager) |
1456 | QListView::keyPressEvent (e); | 1456 | QListView::keyPressEvent (e); |
1457 | else | 1457 | else |
1458 | fileManagerKeyPressEvent (e); | 1458 | fileManagerKeyPressEvent (e); |
1459 | } | 1459 | } |
1460 | 1460 | ||
1461 | void KListView::activateAutomaticSelection() | 1461 | void KListView::activateAutomaticSelection() |
1462 | { | 1462 | { |
1463 | d->selectedBySimpleMove=true; | 1463 | d->selectedBySimpleMove=true; |
1464 | d->selectedUsingMouse=false; | 1464 | d->selectedUsingMouse=false; |
1465 | if (currentItem()!=0) | 1465 | if (currentItem()!=0) |
1466 | { | 1466 | { |
1467 | selectAll(false); | 1467 | selectAll(false); |
1468 | currentItem()->setSelected(true); | 1468 | currentItem()->setSelected(true); |
1469 | currentItem()->repaint(); | 1469 | currentItem()->repaint(); |
1470 | emit selectionChanged(); | 1470 | emit selectionChanged(); |
1471 | }; | 1471 | }; |
1472 | } | 1472 | } |
1473 | 1473 | ||
1474 | void KListView::deactivateAutomaticSelection() | 1474 | void KListView::deactivateAutomaticSelection() |
1475 | { | 1475 | { |
1476 | d->selectedBySimpleMove=false; | 1476 | d->selectedBySimpleMove=false; |
1477 | } | 1477 | } |
1478 | 1478 | ||
1479 | bool KListView::automaticSelection() const | 1479 | bool KListView::automaticSelection() const |
1480 | { | 1480 | { |
1481 | return d->selectedBySimpleMove; | 1481 | return d->selectedBySimpleMove; |
1482 | } | 1482 | } |
1483 | 1483 | ||
1484 | void KListView::fileManagerKeyPressEvent (QKeyEvent* e) | 1484 | void KListView::fileManagerKeyPressEvent (QKeyEvent* e) |
1485 | { | 1485 | { |
1486 | //don't care whether it's on the keypad or not | 1486 | //don't care whether it's on the keypad or not |
1487 | int e_state=(e->state() & ~Keypad); | 1487 | int e_state=(e->state() & ~Keypad); |
1488 | 1488 | ||
1489 | int oldSelectionDirection(d->selectionDirection); | 1489 | int oldSelectionDirection(d->selectionDirection); |
1490 | 1490 | ||
1491 | if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) | 1491 | if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) |
1492 | && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) | 1492 | && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) |
1493 | { | 1493 | { |
1494 | if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) | 1494 | if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) |
1495 | selectAll(FALSE); | 1495 | selectAll(FALSE); |
1496 | d->selectionDirection=0; | 1496 | d->selectionDirection=0; |
1497 | d->wasShiftEvent = (e_state == ShiftButton); | 1497 | d->wasShiftEvent = (e_state == ShiftButton); |
1498 | }; | 1498 | }; |
1499 | 1499 | ||
1500 | //d->wasShiftEvent = (e_state == ShiftButton); | 1500 | //d->wasShiftEvent = (e_state == ShiftButton); |
1501 | 1501 | ||
1502 | 1502 | ||
1503 | QListViewItem* item = currentItem(); | 1503 | QListViewItem* item = currentItem(); |
1504 | if (item==0) return; | 1504 | if (item==0) return; |
1505 | 1505 | ||
1506 | QListViewItem* repaintItem1 = item; | 1506 | QListViewItem* repaintItem1 = item; |
1507 | QListViewItem* repaintItem2 = 0L; | 1507 | QListViewItem* repaintItem2 = 0L; |
1508 | QListViewItem* visItem = 0L; | 1508 | QListViewItem* visItem = 0L; |
1509 | 1509 | ||
1510 | QListViewItem* nextItem = 0L; | 1510 | QListViewItem* nextItem = 0L; |
1511 | int items = 0; | 1511 | int items = 0; |
1512 | 1512 | ||
1513 | bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); | 1513 | bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); |
1514 | int selectedItems(0); | 1514 | int selectedItems(0); |
1515 | for (QListViewItem *tmpItem=firstChild(); tmpItem!=0; tmpItem=tmpItem->nextSibling()) | 1515 | for (QListViewItem *tmpItem=firstChild(); tmpItem!=0; tmpItem=tmpItem->nextSibling()) |
1516 | if (tmpItem->isSelected()) selectedItems++; | 1516 | if (tmpItem->isSelected()) selectedItems++; |
1517 | 1517 | ||
1518 | if (((selectedItems==0) || ((selectedItems==1) && (d->selectedUsingMouse))) | 1518 | if (((selectedItems==0) || ((selectedItems==1) && (d->selectedUsingMouse))) |
1519 | && (e_state==NoButton) | 1519 | && (e_state==NoButton) |
1520 | && ((e->key()==Key_Down) | 1520 | && ((e->key()==Key_Down) |
1521 | || (e->key()==Key_Up) | 1521 | || (e->key()==Key_Up) |
1522 | || (e->key()==Key_Next) | 1522 | || (e->key()==Key_Next) |
1523 | || (e->key()==Key_Prior) | 1523 | || (e->key()==Key_Prior) |
1524 | || (e->key()==Key_Home) | 1524 | || (e->key()==Key_Home) |
1525 | || (e->key()==Key_End))) | 1525 | || (e->key()==Key_End))) |
1526 | { | 1526 | { |
1527 | d->selectedBySimpleMove=true; | 1527 | d->selectedBySimpleMove=true; |
1528 | d->selectedUsingMouse=false; | 1528 | d->selectedUsingMouse=false; |
1529 | } | 1529 | } |
1530 | else if (selectedItems>1) | 1530 | else if (selectedItems>1) |
1531 | d->selectedBySimpleMove=false; | 1531 | d->selectedBySimpleMove=false; |
1532 | 1532 | ||
1533 | bool emitSelectionChanged(false); | 1533 | bool emitSelectionChanged(false); |
1534 | 1534 | ||
1535 | switch (e->key()) | 1535 | switch (e->key()) |
1536 | { | 1536 | { |
1537 | case Key_Escape: | 1537 | case Key_Escape: |
1538 | selectAll(FALSE); | 1538 | selectAll(FALSE); |
1539 | emitSelectionChanged=TRUE; | 1539 | emitSelectionChanged=TRUE; |
1540 | break; | 1540 | break; |
1541 | 1541 | ||
1542 | case Key_Space: | 1542 | case Key_Space: |
1543 | //toggle selection of current item | 1543 | //toggle selection of current item |
1544 | if (d->selectedBySimpleMove) | 1544 | if (d->selectedBySimpleMove) |
1545 | d->selectedBySimpleMove=false; | 1545 | d->selectedBySimpleMove=false; |
1546 | item->setSelected(!item->isSelected()); | 1546 | item->setSelected(!item->isSelected()); |
1547 | emitSelectionChanged=TRUE; | 1547 | emitSelectionChanged=TRUE; |
1548 | break; | 1548 | break; |
1549 | 1549 | ||
1550 | case Key_Insert: | 1550 | case Key_Insert: |
1551 | //toggle selection of current item and move to the next item | 1551 | //toggle selection of current item and move to the next item |
1552 | if (d->selectedBySimpleMove) | 1552 | if (d->selectedBySimpleMove) |
1553 | { | 1553 | { |
1554 | d->selectedBySimpleMove=false; | 1554 | d->selectedBySimpleMove=false; |
1555 | if (!item->isSelected()) item->setSelected(TRUE); | 1555 | if (!item->isSelected()) item->setSelected(TRUE); |
1556 | } | 1556 | } |
1557 | else | 1557 | else |
1558 | { | 1558 | { |
1559 | item->setSelected(!item->isSelected()); | 1559 | item->setSelected(!item->isSelected()); |
1560 | }; | 1560 | }; |
1561 | 1561 | ||
1562 | nextItem=item->itemBelow(); | 1562 | nextItem=item->itemBelow(); |
1563 | 1563 | ||
1564 | if (nextItem!=0) | 1564 | if (nextItem!=0) |
1565 | { | 1565 | { |
1566 | repaintItem2=nextItem; | 1566 | repaintItem2=nextItem; |
1567 | visItem=nextItem; | 1567 | visItem=nextItem; |
1568 | setCurrentItem(nextItem); | 1568 | setCurrentItem(nextItem); |
1569 | }; | 1569 | }; |
1570 | d->selectionDirection=1; | 1570 | d->selectionDirection=1; |
1571 | emitSelectionChanged=TRUE; | 1571 | emitSelectionChanged=TRUE; |
1572 | break; | 1572 | break; |
1573 | 1573 | ||
1574 | case Key_Down: | 1574 | case Key_Down: |
1575 | nextItem=item->itemBelow(); | 1575 | nextItem=item->itemBelow(); |
1576 | //toggle selection of current item and move to the next item | 1576 | //toggle selection of current item and move to the next item |
1577 | if (shiftOrCtrl) | 1577 | if (shiftOrCtrl) |
1578 | { | 1578 | { |
1579 | d->selectionDirection=1; | 1579 | d->selectionDirection=1; |
1580 | if (d->selectedBySimpleMove) | 1580 | if (d->selectedBySimpleMove) |
1581 | d->selectedBySimpleMove=false; | 1581 | d->selectedBySimpleMove=false; |
1582 | else | 1582 | else |
1583 | { | 1583 | { |
1584 | if (oldSelectionDirection!=-1) | 1584 | if (oldSelectionDirection!=-1) |
1585 | { | 1585 | { |
1586 | item->setSelected(!item->isSelected()); | 1586 | item->setSelected(!item->isSelected()); |
1587 | emitSelectionChanged=TRUE; | 1587 | emitSelectionChanged=TRUE; |
1588 | }; | 1588 | }; |
1589 | }; | 1589 | }; |
1590 | } | 1590 | } |
1591 | else if ((d->selectedBySimpleMove) && (nextItem!=0)) | 1591 | else if ((d->selectedBySimpleMove) && (nextItem!=0)) |
1592 | { | 1592 | { |
1593 | item->setSelected(false); | 1593 | item->setSelected(false); |
1594 | emitSelectionChanged=TRUE; | 1594 | emitSelectionChanged=TRUE; |
1595 | }; | 1595 | }; |
1596 | 1596 | ||
1597 | if (nextItem!=0) | 1597 | if (nextItem!=0) |
1598 | { | 1598 | { |
1599 | if (d->selectedBySimpleMove) | 1599 | if (d->selectedBySimpleMove) |
1600 | nextItem->setSelected(true); | 1600 | nextItem->setSelected(true); |
1601 | repaintItem2=nextItem; | 1601 | repaintItem2=nextItem; |
1602 | visItem=nextItem; | 1602 | visItem=nextItem; |
1603 | setCurrentItem(nextItem); | 1603 | setCurrentItem(nextItem); |
1604 | }; | 1604 | }; |
1605 | break; | 1605 | break; |
1606 | 1606 | ||
1607 | case Key_Up: | 1607 | case Key_Up: |
1608 | nextItem=item->itemAbove(); | 1608 | nextItem=item->itemAbove(); |
1609 | d->selectionDirection=-1; | 1609 | d->selectionDirection=-1; |
1610 | //move to the prev. item and toggle selection of this one | 1610 | //move to the prev. item and toggle selection of this one |
1611 | // => No, can't select the last item, with this. For symmetry, let's | 1611 | // => No, can't select the last item, with this. For symmetry, let's |
1612 | // toggle selection and THEN move up, just like we do in down (David) | 1612 | // toggle selection and THEN move up, just like we do in down (David) |
1613 | if (shiftOrCtrl) | 1613 | if (shiftOrCtrl) |
1614 | { | 1614 | { |
1615 | if (d->selectedBySimpleMove) | 1615 | if (d->selectedBySimpleMove) |
1616 | d->selectedBySimpleMove=false; | 1616 | d->selectedBySimpleMove=false; |
1617 | else | 1617 | else |
1618 | { | 1618 | { |
1619 | if (oldSelectionDirection!=1) | 1619 | if (oldSelectionDirection!=1) |
1620 | { | 1620 | { |
1621 | item->setSelected(!item->isSelected()); | 1621 | item->setSelected(!item->isSelected()); |
1622 | emitSelectionChanged=TRUE; | 1622 | emitSelectionChanged=TRUE; |
1623 | }; | 1623 | }; |
1624 | } | 1624 | } |
1625 | } | 1625 | } |
1626 | else if ((d->selectedBySimpleMove) && (nextItem!=0)) | 1626 | else if ((d->selectedBySimpleMove) && (nextItem!=0)) |
1627 | { | 1627 | { |
1628 | item->setSelected(false); | 1628 | item->setSelected(false); |
1629 | emitSelectionChanged=TRUE; | 1629 | emitSelectionChanged=TRUE; |
1630 | }; | 1630 | }; |
1631 | 1631 | ||
1632 | if (nextItem!=0) | 1632 | if (nextItem!=0) |
1633 | { | 1633 | { |
1634 | if (d->selectedBySimpleMove) | 1634 | if (d->selectedBySimpleMove) |
1635 | nextItem->setSelected(true); | 1635 | nextItem->setSelected(true); |
1636 | repaintItem2=nextItem; | 1636 | repaintItem2=nextItem; |
1637 | visItem=nextItem; | 1637 | visItem=nextItem; |
1638 | setCurrentItem(nextItem); | 1638 | setCurrentItem(nextItem); |
1639 | }; | 1639 | }; |
1640 | break; | 1640 | break; |
1641 | 1641 | ||
1642 | case Key_End: | 1642 | case Key_End: |
1643 | //move to the last item and toggle selection of all items inbetween | 1643 | //move to the last item and toggle selection of all items inbetween |
1644 | nextItem=item; | 1644 | nextItem=item; |
1645 | if (d->selectedBySimpleMove) | 1645 | if (d->selectedBySimpleMove) |
1646 | item->setSelected(false); | 1646 | item->setSelected(false); |
1647 | if (shiftOrCtrl) | 1647 | if (shiftOrCtrl) |
1648 | d->selectedBySimpleMove=false; | 1648 | d->selectedBySimpleMove=false; |
1649 | 1649 | ||
1650 | while(nextItem!=0) | 1650 | while(nextItem!=0) |
1651 | { | 1651 | { |
1652 | if (shiftOrCtrl) | 1652 | if (shiftOrCtrl) |
1653 | nextItem->setSelected(!nextItem->isSelected()); | 1653 | nextItem->setSelected(!nextItem->isSelected()); |
1654 | if (nextItem->itemBelow()==0) | 1654 | if (nextItem->itemBelow()==0) |
1655 | { | 1655 | { |
1656 | if (d->selectedBySimpleMove) | 1656 | if (d->selectedBySimpleMove) |
1657 | nextItem->setSelected(true); | 1657 | nextItem->setSelected(true); |
1658 | repaintItem2=nextItem; | 1658 | repaintItem2=nextItem; |
1659 | visItem=nextItem; | 1659 | visItem=nextItem; |
1660 | setCurrentItem(nextItem); | 1660 | setCurrentItem(nextItem); |
1661 | } | 1661 | } |
1662 | nextItem=nextItem->itemBelow(); | 1662 | nextItem=nextItem->itemBelow(); |
1663 | } | 1663 | } |
1664 | emitSelectionChanged=TRUE; | 1664 | emitSelectionChanged=TRUE; |
1665 | break; | 1665 | break; |
1666 | 1666 | ||
1667 | case Key_Home: | 1667 | case Key_Home: |
1668 | // move to the first item and toggle selection of all items inbetween | 1668 | // move to the first item and toggle selection of all items inbetween |
1669 | nextItem = firstChild(); | 1669 | nextItem = firstChild(); |
1670 | visItem = nextItem; | 1670 | visItem = nextItem; |
1671 | repaintItem2 = visItem; | 1671 | repaintItem2 = visItem; |
1672 | if (d->selectedBySimpleMove) | 1672 | if (d->selectedBySimpleMove) |
1673 | item->setSelected(false); | 1673 | item->setSelected(false); |
1674 | if (shiftOrCtrl) | 1674 | if (shiftOrCtrl) |
1675 | { | 1675 | { |
1676 | d->selectedBySimpleMove=false; | 1676 | d->selectedBySimpleMove=false; |
1677 | 1677 | ||
1678 | while ( nextItem != item ) | 1678 | while ( nextItem != item ) |
1679 | { | 1679 | { |
1680 | nextItem->setSelected( !nextItem->isSelected() ); | 1680 | nextItem->setSelected( !nextItem->isSelected() ); |
1681 | nextItem = nextItem->itemBelow(); | 1681 | nextItem = nextItem->itemBelow(); |
1682 | } | 1682 | } |
1683 | item->setSelected( !item->isSelected() ); | 1683 | item->setSelected( !item->isSelected() ); |
1684 | } | 1684 | } |
1685 | setCurrentItem( firstChild() ); | 1685 | setCurrentItem( firstChild() ); |
1686 | emitSelectionChanged=TRUE; | 1686 | emitSelectionChanged=TRUE; |
1687 | break; | 1687 | break; |
1688 | 1688 | ||
1689 | case Key_Next: | 1689 | case Key_Next: |
1690 | items=visibleHeight()/item->height(); | 1690 | items=visibleHeight()/item->height(); |
1691 | nextItem=item; | 1691 | nextItem=item; |
1692 | if (d->selectedBySimpleMove) | 1692 | if (d->selectedBySimpleMove) |
1693 | item->setSelected(false); | 1693 | item->setSelected(false); |
1694 | if (shiftOrCtrl) | 1694 | if (shiftOrCtrl) |
1695 | { | 1695 | { |
1696 | d->selectedBySimpleMove=false; | 1696 | d->selectedBySimpleMove=false; |
1697 | d->selectionDirection=1; | 1697 | d->selectionDirection=1; |
1698 | }; | 1698 | }; |
1699 | 1699 | ||
1700 | for (int i=0; i<items; i++) | 1700 | for (int i=0; i<items; i++) |
1701 | { | 1701 | { |
1702 | if (shiftOrCtrl) | 1702 | if (shiftOrCtrl) |
1703 | nextItem->setSelected(!nextItem->isSelected()); | 1703 | nextItem->setSelected(!nextItem->isSelected()); |
1704 | //the end | 1704 | //the end |
1705 | if ((i==items-1) || (nextItem->itemBelow()==0)) | 1705 | if ((i==items-1) || (nextItem->itemBelow()==0)) |
1706 | 1706 | ||
1707 | { | 1707 | { |
1708 | if (shiftOrCtrl) | 1708 | if (shiftOrCtrl) |
1709 | nextItem->setSelected(!nextItem->isSelected()); | 1709 | nextItem->setSelected(!nextItem->isSelected()); |
1710 | if (d->selectedBySimpleMove) | 1710 | if (d->selectedBySimpleMove) |
1711 | nextItem->setSelected(true); | 1711 | nextItem->setSelected(true); |
1712 | ensureItemVisible(nextItem); | 1712 | ensureItemVisible(nextItem); |
1713 | setCurrentItem(nextItem); | 1713 | setCurrentItem(nextItem); |
1714 | update(); | 1714 | update(); |
1715 | if ((shiftOrCtrl) || (d->selectedBySimpleMove)) | 1715 | if ((shiftOrCtrl) || (d->selectedBySimpleMove)) |
1716 | { | 1716 | { |
1717 | emit selectionChanged(); | 1717 | emit selectionChanged(); |
1718 | } | 1718 | } |
1719 | return; | 1719 | return; |
1720 | } | 1720 | } |
1721 | nextItem=nextItem->itemBelow(); | 1721 | nextItem=nextItem->itemBelow(); |
1722 | } | 1722 | } |
1723 | break; | 1723 | break; |
1724 | 1724 | ||
1725 | case Key_Prior: | 1725 | case Key_Prior: |
1726 | items=visibleHeight()/item->height(); | 1726 | items=visibleHeight()/item->height(); |
1727 | nextItem=item; | 1727 | nextItem=item; |
1728 | if (d->selectedBySimpleMove) | 1728 | if (d->selectedBySimpleMove) |
1729 | item->setSelected(false); | 1729 | item->setSelected(false); |
1730 | if (shiftOrCtrl) | 1730 | if (shiftOrCtrl) |
1731 | { | 1731 | { |
1732 | d->selectionDirection=-1; | 1732 | d->selectionDirection=-1; |
1733 | d->selectedBySimpleMove=false; | 1733 | d->selectedBySimpleMove=false; |
1734 | }; | 1734 | }; |
1735 | 1735 | ||
1736 | for (int i=0; i<items; i++) | 1736 | for (int i=0; i<items; i++) |
1737 | { | 1737 | { |
1738 | if ((nextItem!=item) &&(shiftOrCtrl)) | 1738 | if ((nextItem!=item) &&(shiftOrCtrl)) |
1739 | nextItem->setSelected(!nextItem->isSelected()); | 1739 | nextItem->setSelected(!nextItem->isSelected()); |
1740 | //the end | 1740 | //the end |
1741 | if ((i==items-1) || (nextItem->itemAbove()==0)) | 1741 | if ((i==items-1) || (nextItem->itemAbove()==0)) |
1742 | 1742 | ||
1743 | { | 1743 | { |
1744 | if (d->selectedBySimpleMove) | 1744 | if (d->selectedBySimpleMove) |
1745 | nextItem->setSelected(true); | 1745 | nextItem->setSelected(true); |
1746 | ensureItemVisible(nextItem); | 1746 | ensureItemVisible(nextItem); |
1747 | setCurrentItem(nextItem); | 1747 | setCurrentItem(nextItem); |
1748 | update(); | 1748 | update(); |
1749 | if ((shiftOrCtrl) || (d->selectedBySimpleMove)) | 1749 | if ((shiftOrCtrl) || (d->selectedBySimpleMove)) |
1750 | { | 1750 | { |
1751 | emit selectionChanged(); | 1751 | emit selectionChanged(); |
1752 | } | 1752 | } |
1753 | return; | 1753 | return; |
1754 | } | 1754 | } |
1755 | nextItem=nextItem->itemAbove(); | 1755 | nextItem=nextItem->itemAbove(); |
1756 | } | 1756 | } |
1757 | break; | 1757 | break; |
1758 | 1758 | ||
1759 | case Key_Minus: | 1759 | case Key_Minus: |
1760 | if ( item->isOpen() ) | 1760 | if ( item->isOpen() ) |
1761 | setOpen( item, FALSE ); | 1761 | setOpen( item, FALSE ); |
1762 | break; | 1762 | break; |
1763 | case Key_Plus: | 1763 | case Key_Plus: |
1764 | if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) | 1764 | if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) |
1765 | setOpen( item, TRUE ); | 1765 | setOpen( item, TRUE ); |
1766 | break; | 1766 | break; |
1767 | default: | 1767 | default: |
1768 | bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) | 1768 | bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) |
1769 | && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); | 1769 | && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); |
1770 | 1770 | ||
1771 | bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); | 1771 | bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); |
1772 | if (realKey && selectCurrentItem) | 1772 | if (realKey && selectCurrentItem) |
1773 | item->setSelected(false); | 1773 | item->setSelected(false); |
1774 | //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) | 1774 | //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) |
1775 | QListView::SelectionMode oldSelectionMode = selectionMode(); | 1775 | QListView::SelectionMode oldSelectionMode = selectionMode(); |
1776 | setSelectionMode (QListView::Multi); | 1776 | setSelectionMode (QListView::Multi); |
1777 | QListView::keyPressEvent (e); | 1777 | QListView::keyPressEvent (e); |
1778 | setSelectionMode (oldSelectionMode); | 1778 | setSelectionMode (oldSelectionMode); |
1779 | if (realKey && selectCurrentItem) | 1779 | if (realKey && selectCurrentItem) |
1780 | { | 1780 | { |
1781 | currentItem()->setSelected(true); | 1781 | currentItem()->setSelected(true); |
1782 | emitSelectionChanged=TRUE; | 1782 | emitSelectionChanged=TRUE; |
1783 | } | 1783 | } |
1784 | repaintItem2=currentItem(); | 1784 | repaintItem2=currentItem(); |
1785 | if (realKey) | 1785 | if (realKey) |
1786 | visItem=currentItem(); | 1786 | visItem=currentItem(); |
1787 | break; | 1787 | break; |
1788 | } | 1788 | } |
1789 | 1789 | ||
1790 | if (visItem) | 1790 | if (visItem) |
1791 | ensureItemVisible(visItem); | 1791 | ensureItemVisible(visItem); |
1792 | 1792 | ||
1793 | QRect ir; | 1793 | QRect ir; |
1794 | if (repaintItem1) | 1794 | if (repaintItem1) |
1795 | ir = ir.unite( itemRect(repaintItem1) ); | 1795 | ir = ir.unite( itemRect(repaintItem1) ); |
1796 | if (repaintItem2) | 1796 | if (repaintItem2) |
1797 | ir = ir.unite( itemRect(repaintItem2) ); | 1797 | ir = ir.unite( itemRect(repaintItem2) ); |
1798 | 1798 | ||
1799 | if ( !ir.isEmpty() ) | 1799 | if ( !ir.isEmpty() ) |
1800 | { // rectangle to be repainted | 1800 | { // rectangle to be repainted |
1801 | if ( ir.x() < 0 ) | 1801 | if ( ir.x() < 0 ) |
1802 | ir.moveBy( -ir.x(), 0 ); | 1802 | ir.moveBy( -ir.x(), 0 ); |
1803 | viewport()->repaint( ir, FALSE ); | 1803 | viewport()->repaint( ir, FALSE ); |
1804 | } | 1804 | } |
1805 | /*if (repaintItem1) | 1805 | /*if (repaintItem1) |
1806 | repaintItem1->repaint(); | 1806 | repaintItem1->repaint(); |
1807 | if (repaintItem2) | 1807 | if (repaintItem2) |
1808 | repaintItem2->repaint();*/ | 1808 | repaintItem2->repaint();*/ |
1809 | update(); | 1809 | update(); |
1810 | if (emitSelectionChanged) | 1810 | if (emitSelectionChanged) |
1811 | emit selectionChanged(); | 1811 | emit selectionChanged(); |
1812 | } | 1812 | } |
1813 | 1813 | ||
1814 | void KListView::setSelectionModeExt (SelectionModeExt mode) | 1814 | void KListView::setSelectionModeExt (SelectionModeExt mode) |
1815 | { | 1815 | { |
1816 | d->selectionMode = mode; | 1816 | d->selectionMode = mode; |
1817 | 1817 | ||
1818 | switch (mode) | 1818 | switch (mode) |
1819 | { | 1819 | { |
1820 | case Single: | 1820 | case Single: |
1821 | case Multi: | 1821 | case Multi: |
1822 | case Extended: | 1822 | case Extended: |
1823 | case NoSelection: | 1823 | case NoSelection: |
1824 | setSelectionMode (static_cast<QListView::SelectionMode>(static_cast<int>(mode))); | 1824 | setSelectionMode (static_cast<QListView::SelectionMode>(static_cast<int>(mode))); |
1825 | break; | 1825 | break; |
1826 | 1826 | ||
1827 | case FileManager: | 1827 | case FileManager: |
1828 | setSelectionMode (QListView::Extended); | 1828 | setSelectionMode (QListView::Extended); |
1829 | break; | 1829 | break; |
1830 | 1830 | ||
1831 | default: | 1831 | default: |
1832 | kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; | 1832 | kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; |
1833 | break; | 1833 | break; |
1834 | } | 1834 | } |
1835 | } | 1835 | } |
1836 | 1836 | ||
1837 | KListView::SelectionModeExt KListView::selectionModeExt () const | 1837 | KListView::SelectionModeExt KListView::selectionModeExt () const |
1838 | { | 1838 | { |
1839 | return d->selectionMode; | 1839 | return d->selectionMode; |
1840 | } | 1840 | } |
1841 | 1841 | ||
1842 | int KListView::itemIndex( const QListViewItem *item ) const | 1842 | int KListView::itemIndex( const QListViewItem *item ) const |
1843 | { | 1843 | { |
1844 | if ( !item ) | 1844 | if ( !item ) |
1845 | return -1; | 1845 | return -1; |
1846 | 1846 | ||
1847 | if ( item == firstChild() ) | 1847 | if ( item == firstChild() ) |
1848 | return 0; | 1848 | return 0; |
1849 | else { | 1849 | else { |
1850 | QListViewItemIterator it(firstChild()); | 1850 | QListViewItemIterator it(firstChild()); |
1851 | uint j = 0; | 1851 | uint j = 0; |
1852 | for (; it.current() && it.current() != item; ++it, ++j ); | 1852 | for (; it.current() && it.current() != item; ++it, ++j ); |
1853 | 1853 | ||
1854 | if( !it.current() ) | 1854 | if( !it.current() ) |
1855 | return -1; | 1855 | return -1; |
1856 | 1856 | ||
1857 | return j; | 1857 | return j; |
1858 | } | 1858 | } |
1859 | } | 1859 | } |
1860 | 1860 | ||
1861 | QListViewItem* KListView::itemAtIndex(int index) | 1861 | QListViewItem* KListView::itemAtIndex(int index) |
1862 | { | 1862 | { |
1863 | if (index<0) | 1863 | if (index<0) |
1864 | return 0; | 1864 | return 0; |
1865 | 1865 | ||
1866 | int j(0); | 1866 | int j(0); |
1867 | for (QListViewItemIterator it=firstChild(); it.current(); it++) | 1867 | for (QListViewItemIterator it=firstChild(); it.current(); it++) |
1868 | { | 1868 | { |
1869 | if (j==index) | 1869 | if (j==index) |
1870 | return it.current(); | 1870 | return it.current(); |
1871 | j++; | 1871 | j++; |
1872 | }; | 1872 | }; |
1873 | return 0; | 1873 | return 0; |
1874 | } | 1874 | } |
1875 | 1875 | ||
1876 | 1876 | ||
1877 | void KListView::emitContextMenu (KListView*, QListViewItem* i) | 1877 | void KListView::emitContextMenu (KListView*, QListViewItem* i) |
1878 | { | 1878 | { |
1879 | QPoint p; | 1879 | QPoint p; |
1880 | qDebug("KListView::emitContextMenu "); | 1880 | qDebug("KListView::emitContextMenu "); |
1881 | 1881 | ||
1882 | if (i) | 1882 | if (i) |
1883 | p = viewport()->mapToGlobal(itemRect(i).center()); | 1883 | p = viewport()->mapToGlobal(itemRect(i).center()); |
1884 | else | 1884 | else |
1885 | p = mapToGlobal(rect().center()); | 1885 | p = mapToGlobal(rect().center()); |
1886 | 1886 | ||
1887 | emit contextMenu (this, i, p); | 1887 | emit contextMenu (this, i, p); |
1888 | } | 1888 | } |
1889 | 1889 | ||
1890 | void KListView::emitContextMenu (QListViewItem* i, const QPoint& p, int) | 1890 | void KListView::emitContextMenu (QListViewItem* i, const QPoint& p, int) |
1891 | { | 1891 | { |
1892 | qDebug("KListView::emitContextMenu "); | 1892 | qDebug("KListView::emitContextMenu "); |
1893 | emit contextMenu (this, i, p); | 1893 | emit contextMenu (this, i, p); |
1894 | } | 1894 | } |
1895 | 1895 | ||
1896 | void KListView::setAcceptDrops (bool val) | 1896 | void KListView::setAcceptDrops (bool val) |
1897 | { | 1897 | { |
1898 | QListView::setAcceptDrops (val); | 1898 | QListView::setAcceptDrops (val); |
1899 | viewport()->setAcceptDrops (val); | 1899 | viewport()->setAcceptDrops (val); |
1900 | } | 1900 | } |
1901 | 1901 | ||
1902 | int KListView::dropVisualizerWidth () const | 1902 | int KListView::dropVisualizerWidth () const |
1903 | { | 1903 | { |
1904 | return d->mDropVisualizerWidth; | 1904 | return d->mDropVisualizerWidth; |
1905 | } | 1905 | } |
1906 | 1906 | ||
1907 | 1907 | ||
1908 | void KListView::viewportPaintEvent(QPaintEvent *e) | 1908 | void KListView::viewportPaintEvent(QPaintEvent *e) |
1909 | { | 1909 | { |
1910 | QListView::viewportPaintEvent(e); | 1910 | QListView::viewportPaintEvent(e); |
1911 | 1911 | ||
1912 | if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) | 1912 | if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) |
1913 | { | 1913 | { |
1914 | QPainter painter(viewport()); | 1914 | QPainter painter(viewport()); |
1915 | 1915 | ||
1916 | // This is where we actually draw the drop-visualizer | 1916 | // This is where we actually draw the drop-visualizer |
1917 | painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); | 1917 | painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); |
1918 | } | 1918 | } |
1919 | if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) | 1919 | if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) |
1920 | { | 1920 | { |
1921 | QPainter painter(viewport()); | 1921 | QPainter painter(viewport()); |
1922 | 1922 | ||
1923 | qDebug("KListView::viewportPaintEvent has to be verified"); | 1923 | qDebug("KListView::viewportPaintEvent has to be verified"); |
1924 | 1924 | ||
1925 | // This is where we actually draw the drop-highlighter | 1925 | // This is where we actually draw the drop-highlighter |
1926 | //US style().drawPrimitive(QStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), | 1926 | //US style().drawPrimitive(QStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), |
1927 | //US QStyle::Style_FocusAtBorder); | 1927 | //US QStyle::Style_FocusAtBorder); |
1928 | 1928 | ||
1929 | //LR style().drawFocusRect(&painter, d->mOldDropHighlighter, colorGroup(), (const QColor*)0, true); | 1929 | //LR style().drawFocusRect(&painter, d->mOldDropHighlighter, colorGroup(), (const QColor*)0, true); |
1930 | 1930 | ||
1931 | 1931 | ||
1932 | } | 1932 | } |
1933 | } | 1933 | } |
1934 | 1934 | ||
1935 | void KListView::setFullWidth() | 1935 | void KListView::setFullWidth() |
1936 | { | 1936 | { |
1937 | setFullWidth(true); | 1937 | setFullWidth(true); |
1938 | } | 1938 | } |
1939 | 1939 | ||
1940 | void KListView::setFullWidth(bool fullWidth) | 1940 | void KListView::setFullWidth(bool fullWidth) |
1941 | { | 1941 | { |
1942 | d->fullWidth = fullWidth; | 1942 | d->fullWidth = fullWidth; |
1943 | //US header()->setStretchEnabled(fullWidth, columns()-1); | 1943 | //US header()->setStretchEnabled(fullWidth, columns()-1); |
1944 | } | 1944 | } |
1945 | 1945 | ||
1946 | bool KListView::fullWidth() const | 1946 | bool KListView::fullWidth() const |
1947 | { | 1947 | { |
1948 | return d->fullWidth; | 1948 | return d->fullWidth; |
1949 | } | 1949 | } |
1950 | 1950 | ||
1951 | int KListView::addColumn(const QString& label, int width) | 1951 | int KListView::addColumn(const QString& label, int width) |
1952 | { | 1952 | { |
1953 | int result = QListView::addColumn(label, width); | 1953 | int result = QListView::addColumn(label, width); |
1954 | if (d->fullWidth) { | 1954 | if (d->fullWidth) { |
1955 | //US header()->setStretchEnabled(false, columns()-2); | 1955 | //US header()->setStretchEnabled(false, columns()-2); |
1956 | //US header()->setStretchEnabled(true, columns()-1); | 1956 | //US header()->setStretchEnabled(true, columns()-1); |
1957 | } | 1957 | } |
1958 | return result; | 1958 | return result; |
1959 | } | 1959 | } |
1960 | 1960 | ||
1961 | int KListView::addColumn(const QIconSet& iconset, const QString& label, int width) | 1961 | int KListView::addColumn(const QIconSet& iconset, const QString& label, int width) |
1962 | { | 1962 | { |
1963 | int result = QListView::addColumn(iconset, label, width); | 1963 | int result = QListView::addColumn(iconset, label, width); |
1964 | if (d->fullWidth) { | 1964 | if (d->fullWidth) { |
1965 | //US header()->setStretchEnabled(false, columns()-2); | 1965 | //US header()->setStretchEnabled(false, columns()-2); |
1966 | //US header()->setStretchEnabled(true, columns()-1); | 1966 | //US header()->setStretchEnabled(true, columns()-1); |
1967 | } | 1967 | } |
1968 | return result; | 1968 | return result; |
1969 | } | 1969 | } |
1970 | 1970 | ||
1971 | void KListView::removeColumn(int index) | 1971 | void KListView::removeColumn(int index) |
1972 | { | 1972 | { |
1973 | QListView::removeColumn(index); | 1973 | QListView::removeColumn(index); |
1974 | //US if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); | 1974 | //US if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); |
1975 | } | 1975 | } |
1976 | 1976 | ||
1977 | void KListView::viewportResizeEvent(QResizeEvent* e) | 1977 | void KListView::viewportResizeEvent(QResizeEvent* e) |
1978 | { | 1978 | { |
1979 | QListView::viewportResizeEvent(e); | 1979 | QListView::viewportResizeEvent(e); |
1980 | } | 1980 | } |
1981 | 1981 | ||
1982 | const QColor &KListView::alternateBackground() const | 1982 | const QColor &KListView::alternateBackground() const |
1983 | { | 1983 | { |
1984 | return d->alternateBackground; | 1984 | return d->alternateBackground; |
1985 | } | 1985 | } |
1986 | 1986 | ||
1987 | void KListView::setAlternateBackground(const QColor &c) | 1987 | void KListView::setAlternateBackground(const QColor &c) |
1988 | { | 1988 | { |
1989 | d->alternateBackground = c; | 1989 | d->alternateBackground = c; |
1990 | repaint(); | 1990 | repaint(); |
1991 | } | 1991 | } |
1992 | 1992 | ||
1993 | void KListView::saveLayout(KConfig *config, const QString &group) const | 1993 | void KListView::saveLayout(KConfig *config, const QString &group) const |
1994 | { | 1994 | { |
1995 | KConfigGroupSaver saver(config, group); | 1995 | KConfigGroupSaver saver(config, group); |
1996 | QStringList widths, order; | 1996 | QStringList widths, order; |
1997 | for (int i = 0; i < columns(); ++i) | 1997 | for (int i = 0; i < columns(); ++i) |
1998 | { | 1998 | { |
1999 | widths << QString::number(columnWidth(i)); | 1999 | widths << QString::number(columnWidth(i)); |
2000 | order << QString::number(header()->mapToIndex(i)); | 2000 | order << QString::number(header()->mapToIndex(i)); |
2001 | } | 2001 | } |
2002 | config->writeEntry("ColumnWidths", widths); | 2002 | config->writeEntry("ColumnWidths", widths); |
2003 | config->writeEntry("ColumnOrder", order); | 2003 | config->writeEntry("ColumnOrder", order); |
2004 | config->writeEntry("SortColumn", d->sortColumn); | 2004 | config->writeEntry("SortColumn", d->sortColumn); |
2005 | config->writeEntry("SortAscending", d->sortAscending); | 2005 | config->writeEntry("SortAscending", d->sortAscending); |
2006 | } | 2006 | } |
2007 | 2007 | ||
2008 | void KListView::restoreLayout(KConfig *config, const QString &group) | 2008 | void KListView::restoreLayout(KConfig *config, const QString &group) |
2009 | { | 2009 | { |
2010 | KConfigGroupSaver saver(config, group); | 2010 | KConfigGroupSaver saver(config, group); |
2011 | QStringList cols = config->readListEntry("ColumnWidths"); | 2011 | QStringList cols = config->readListEntry("ColumnWidths"); |
2012 | int i = 0; | 2012 | int i = 0; |
2013 | for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) | 2013 | for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) |
2014 | setColumnWidth(i++, (*it).toInt()); | 2014 | setColumnWidth(i++, (*it).toInt()); |
2015 | 2015 | ||
2016 | cols = config->readListEntry("ColumnOrder"); | 2016 | cols = config->readListEntry("ColumnOrder"); |
2017 | i = 0; | 2017 | i = 0; |
2018 | for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) | 2018 | for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) |
2019 | header()->moveSection(i++, (*it).toInt()); | 2019 | header()->moveSection(i++, (*it).toInt()); |
2020 | 2020 | ||
2021 | /*US I changed the following code, because hasKey is not available. | 2021 | /*US I changed the following code, because hasKey is not available. |
2022 | !!! check if my version is correct | 2022 | !!! check if my version is correct |
2023 | if (config->hasKey("SortColumn")) | 2023 | if (config->hasKey("SortColumn")) |
2024 | setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); | 2024 | setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); |
2025 | */ | 2025 | */ |
2026 | QStringList langLst = config->readListEntry( "SortColumn" ); | 2026 | QStringList langLst = config->readListEntry( "SortColumn" ); |
2027 | if (!langLst.isEmpty()) | 2027 | if (!langLst.isEmpty()) |
2028 | setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); | 2028 | setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); |
2029 | } | 2029 | } |
2030 | 2030 | ||
2031 | void KListView::setSorting(int column, bool ascending) | 2031 | void KListView::setSorting(int column, bool ascending) |
2032 | { | 2032 | { |
2033 | d->sortColumn = column; | 2033 | d->sortColumn = column; |
2034 | d->sortAscending = ascending; | 2034 | d->sortAscending = ascending; |
2035 | QListView::setSorting(column, ascending); | 2035 | QListView::setSorting(column, ascending); |
2036 | } | 2036 | } |
2037 | 2037 | ||
2038 | int KListView::columnSorted(void) const | 2038 | int KListView::columnSorted(void) const |
2039 | { | 2039 | { |
2040 | return d->sortColumn; | 2040 | return d->sortColumn; |
2041 | } | 2041 | } |
2042 | 2042 | ||
2043 | bool KListView::ascendingSort(void) const | 2043 | bool KListView::ascendingSort(void) const |
2044 | { | 2044 | { |
2045 | return d->sortAscending; | 2045 | return d->sortAscending; |
2046 | } | 2046 | } |
2047 | 2047 | ||
2048 | KListViewItem::KListViewItem(QListView *parent) | 2048 | KListViewItem::KListViewItem(QListView *parent) |
2049 | : QListViewItem(parent) | 2049 | : QListViewItem(parent) |
2050 | { | 2050 | { |
2051 | init(); | 2051 | init(); |
2052 | } | 2052 | } |
2053 | 2053 | ||
2054 | KListViewItem::KListViewItem(QListViewItem *parent) | 2054 | KListViewItem::KListViewItem(QListViewItem *parent) |
2055 | : QListViewItem(parent) | 2055 | : QListViewItem(parent) |
2056 | { | 2056 | { |
2057 | init(); | 2057 | init(); |
2058 | } | 2058 | } |
2059 | 2059 | ||
2060 | KListViewItem::KListViewItem(QListView *parent, QListViewItem *after) | 2060 | KListViewItem::KListViewItem(QListView *parent, QListViewItem *after) |
2061 | : QListViewItem(parent, after) | 2061 | : QListViewItem(parent, after) |
2062 | { | 2062 | { |
2063 | init(); | 2063 | init(); |
2064 | } | 2064 | } |
2065 | 2065 | ||
2066 | KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after) | 2066 | KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after) |
2067 | : QListViewItem(parent, after) | 2067 | : QListViewItem(parent, after) |
2068 | { | 2068 | { |
2069 | init(); | 2069 | init(); |
2070 | } | 2070 | } |
2071 | 2071 | ||
2072 | KListViewItem::KListViewItem(QListView *parent, | 2072 | KListViewItem::KListViewItem(QListView *parent, |
2073 | QString label1, QString label2, QString label3, QString label4, | 2073 | QString label1, QString label2, QString label3, QString label4, |
2074 | QString label5, QString label6, QString label7, QString label8) | 2074 | QString label5, QString label6, QString label7, QString label8) |
2075 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 2075 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
2076 | { | 2076 | { |
2077 | init(); | 2077 | init(); |
2078 | } | 2078 | } |
2079 | 2079 | ||
2080 | KListViewItem::KListViewItem(QListViewItem *parent, | 2080 | KListViewItem::KListViewItem(QListViewItem *parent, |
2081 | QString label1, QString label2, QString label3, QString label4, | 2081 | QString label1, QString label2, QString label3, QString label4, |
2082 | QString label5, QString label6, QString label7, QString label8) | 2082 | QString label5, QString label6, QString label7, QString label8) |
2083 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 2083 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
2084 | { | 2084 | { |
2085 | init(); | 2085 | init(); |
2086 | } | 2086 | } |
2087 | 2087 | ||
2088 | KListViewItem::KListViewItem(QListView *parent, QListViewItem *after, | 2088 | KListViewItem::KListViewItem(QListView *parent, QListViewItem *after, |
2089 | QString label1, QString label2, QString label3, QString label4, | 2089 | QString label1, QString label2, QString label3, QString label4, |
2090 | QString label5, QString label6, QString label7, QString label8) | 2090 | QString label5, QString label6, QString label7, QString label8) |
2091 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 2091 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
2092 | { | 2092 | { |
2093 | init(); | 2093 | init(); |
2094 | } | 2094 | } |
2095 | 2095 | ||
2096 | KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after, | 2096 | KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after, |
2097 | QString label1, QString label2, QString label3, QString label4, | 2097 | QString label1, QString label2, QString label3, QString label4, |
2098 | QString label5, QString label6, QString label7, QString label8) | 2098 | QString label5, QString label6, QString label7, QString label8) |
2099 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 2099 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
2100 | { | 2100 | { |
2101 | init(); | 2101 | init(); |
2102 | } | 2102 | } |
2103 | 2103 | ||
2104 | KListViewItem::~KListViewItem() | 2104 | KListViewItem::~KListViewItem() |
2105 | { | 2105 | { |
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | void KListViewItem::init() | 2108 | void KListViewItem::init() |
2109 | { | 2109 | { |
2110 | m_known = false; | 2110 | m_known = false; |
2111 | } | 2111 | } |
2112 | 2112 | ||
2113 | const QColor &KListViewItem::backgroundColor() | 2113 | const QColor &KListViewItem::backgroundColor() |
2114 | { | 2114 | { |
2115 | if (isAlternate()) | 2115 | if (isAlternate()) |
2116 | return static_cast< KListView* >(listView())->alternateBackground(); | 2116 | return static_cast< KListView* >(listView())->alternateBackground(); |
2117 | return listView()->viewport()->colorGroup().base(); | 2117 | return listView()->viewport()->colorGroup().base(); |
2118 | } | 2118 | } |
2119 | 2119 | ||
2120 | bool KListViewItem::isAlternate() | 2120 | bool KListViewItem::isAlternate() |
2121 | { | 2121 | { |
2122 | KListView *lv = static_cast<KListView *>(listView()); | 2122 | KListView *lv = static_cast<KListView *>(listView()); |
2123 | if (lv && lv->alternateBackground().isValid()) | 2123 | if (lv && lv->alternateBackground().isValid()) |
2124 | { | 2124 | { |
2125 | KListViewItem *above = 0; | 2125 | KListViewItem *above = 0; |
2126 | //US above = dynamic_cast<KListViewItem *>(itemAbove()); | 2126 | //US above = dynamic_cast<KListViewItem *>(itemAbove()); |
2127 | above = (KListViewItem *)(itemAbove()); | 2127 | above = (KListViewItem *)(itemAbove()); |
2128 | m_known = above ? above->m_known : true; | 2128 | m_known = above ? above->m_known : true; |
2129 | if (m_known) | 2129 | if (m_known) |
2130 | { | 2130 | { |
2131 | m_odd = above ? !above->m_odd : false; | 2131 | m_odd = above ? !above->m_odd : false; |
2132 | } | 2132 | } |
2133 | else | 2133 | else |
2134 | { | 2134 | { |
2135 | KListViewItem *item; | 2135 | KListViewItem *item; |
2136 | bool previous = true; | 2136 | bool previous = true; |
2137 | if (parent()) | 2137 | if (parent()) |
2138 | { | 2138 | { |
2139 | //US item = dynamic_cast<KListViewItem *>(parent()); | 2139 | //US item = dynamic_cast<KListViewItem *>(parent()); |
2140 | item = (KListViewItem *)(parent()); | 2140 | item = (KListViewItem *)(parent()); |
2141 | if (item) | 2141 | if (item) |
2142 | previous = item->m_odd; | 2142 | previous = item->m_odd; |
2143 | //US item = dynamic_cast<KListViewItem *>(parent()->firstChild()); | 2143 | //US item = dynamic_cast<KListViewItem *>(parent()->firstChild()); |
2144 | item = (KListViewItem *)(parent()->firstChild()); | 2144 | item = (KListViewItem *)(parent()->firstChild()); |
2145 | } | 2145 | } |
2146 | else | 2146 | else |
2147 | { | 2147 | { |
2148 | //US item = dynamic_cast<KListViewItem *>(lv->firstChild()); | 2148 | //US item = dynamic_cast<KListViewItem *>(lv->firstChild()); |
2149 | item = (KListViewItem *)(lv->firstChild()); | 2149 | item = (KListViewItem *)(lv->firstChild()); |
2150 | } | 2150 | } |
2151 | 2151 | ||
2152 | while(item) | 2152 | while(item) |
2153 | { | 2153 | { |
2154 | item->m_odd = previous = !previous; | 2154 | item->m_odd = previous = !previous; |
2155 | item->m_known = true; | 2155 | item->m_known = true; |
2156 | //US item = dynamic_cast<KListViewItem *>(item->nextSibling()); | 2156 | //US item = dynamic_cast<KListViewItem *>(item->nextSibling()); |
2157 | item = (KListViewItem *)(item->nextSibling()); | 2157 | item = (KListViewItem *)(item->nextSibling()); |
2158 | } | 2158 | } |
2159 | } | 2159 | } |
2160 | return m_odd; | 2160 | return m_odd; |
2161 | } | 2161 | } |
2162 | return false; | 2162 | return false; |
2163 | } | 2163 | } |
2164 | 2164 | ||
2165 | void KListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 2165 | void KListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
2166 | { | 2166 | { |
2167 | QColorGroup _cg = cg; | 2167 | QColorGroup _cg = cg; |
2168 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 2168 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
2169 | if (pm && !pm->isNull()) | 2169 | if (pm && !pm->isNull()) |
2170 | { | 2170 | { |
2171 | _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm)); | 2171 | _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm)); |
2172 | QPoint o = p->brushOrigin(); | 2172 | QPoint o = p->brushOrigin(); |
2173 | p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() ); | 2173 | p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() ); |
2174 | } | 2174 | } |
2175 | else if (isAlternate()) { | 2175 | else if (isAlternate()) { |
2176 | //US if (listView()->viewport()->backgroundMode()==Qt::FixedColor) | 2176 | //US if (listView()->viewport()->backgroundMode()==Qt::FixedColor) |
2177 | if (listView()->viewport()->backgroundMode()==QWidget::PaletteBackground) | 2177 | if (listView()->viewport()->backgroundMode()==QWidget::PaletteBackground) |
2178 | _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground()); | 2178 | _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground()); |
2179 | else | 2179 | else |
2180 | _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground()); | 2180 | _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground()); |
2181 | } | 2181 | } |
2182 | QListViewItem::paintCell(p, _cg, column, width, alignment); | 2182 | QListViewItem::paintCell(p, _cg, column, width, alignment); |
2183 | } | 2183 | } |
2184 | 2184 | ||
2185 | void KListView::virtual_hook( int, void* ) | 2185 | void KListView::virtual_hook( int, void* ) |
2186 | { /*BASE::virtual_hook( id, data );*/ } | 2186 | { /*BASE::virtual_hook( id, data );*/ } |
2187 | 2187 | ||
2188 | //US #include "klistview.moc" | 2188 | //US #include "klistview.moc" |
2189 | //US #include "klistviewlineedit.moc" | 2189 | //US #include "klistviewlineedit.moc" |
2190 | 2190 | ||
2191 | // vim: ts=2 sw=2 et | 2191 | // vim: ts=2 sw=2 et |