author | harlekin <harlekin> | 2002-09-09 18:14:37 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-09-09 18:14:37 (UTC) |
commit | 3044db24e632adbcf5dbbf1874944d54cee7c8e3 (patch) (unidiff) | |
tree | 9961a3531e7fd16709002f82faa7494dd3dafed3 | |
parent | 2e56c4b88cfb1ebdbc0d952791af48c870f9f14b (diff) | |
download | opie-3044db24e632adbcf5dbbf1874944d54cee7c8e3.zip opie-3044db24e632adbcf5dbbf1874944d54cee7c8e3.tar.gz opie-3044db24e632adbcf5dbbf1874944d54cee7c8e3.tar.bz2 |
add preloaded app control needed to runningappsbar
-rw-r--r-- | library/applnk.cpp | 29 | ||||
-rw-r--r-- | library/applnk.h | 5 |
2 files changed, 31 insertions, 3 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 778ccab..9498f84 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp | |||
@@ -101,764 +101,787 @@ int AppLnk::smallIconSize() | |||
101 | 101 | ||
102 | 102 | ||
103 | /*! | 103 | /*! |
104 | Sets the size used for large icons to \a big pixels. | 104 | Sets the size used for large icons to \a big pixels. |
105 | Only affects AppLnk objects created after the call. | 105 | Only affects AppLnk objects created after the call. |
106 | */ | 106 | */ |
107 | void AppLnk::setBigIconSize(int big) | 107 | void AppLnk::setBigIconSize(int big) |
108 | { | 108 | { |
109 | bigSize = big; | 109 | bigSize = big; |
110 | } | 110 | } |
111 | 111 | ||
112 | /*! | 112 | /*! |
113 | Returns the size used for large icons. | 113 | Returns the size used for large icons. |
114 | */ | 114 | */ |
115 | int AppLnk::bigIconSize() | 115 | int AppLnk::bigIconSize() |
116 | { | 116 | { |
117 | return bigSize; | 117 | return bigSize; |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | /*! | 121 | /*! |
122 | \fn QString AppLnk::name() const | 122 | \fn QString AppLnk::name() const |
123 | 123 | ||
124 | Returns the Name property. | 124 | Returns the Name property. |
125 | */ | 125 | */ |
126 | /*! | 126 | /*! |
127 | \fn QString AppLnk::exec() const | 127 | \fn QString AppLnk::exec() const |
128 | 128 | ||
129 | Returns the Exec property. This is the executable program associated | 129 | Returns the Exec property. This is the executable program associated |
130 | with the AppLnk. | 130 | with the AppLnk. |
131 | */ | 131 | */ |
132 | /*! | 132 | /*! |
133 | \fn QString AppLnk::rotation() const | 133 | \fn QString AppLnk::rotation() const |
134 | 134 | ||
135 | Returns the Rotation property. | 135 | Returns the Rotation property. |
136 | */ | 136 | */ |
137 | /*! | 137 | /*! |
138 | \fn QString AppLnk::comment() const | 138 | \fn QString AppLnk::comment() const |
139 | 139 | ||
140 | Returns the Comment property. | 140 | Returns the Comment property. |
141 | */ | 141 | */ |
142 | /*! | 142 | /*! |
143 | \fn QStringList AppLnk::mimeTypes() const | 143 | \fn QStringList AppLnk::mimeTypes() const |
144 | 144 | ||
145 | Returns the MimeTypes property. This is the list of MIME types | 145 | Returns the MimeTypes property. This is the list of MIME types |
146 | that the application can view or edit. | 146 | that the application can view or edit. |
147 | */ | 147 | */ |
148 | /*! | 148 | /*! |
149 | \fn const QArray<int>& AppLnk::categories() const | 149 | \fn const QArray<int>& AppLnk::categories() const |
150 | 150 | ||
151 | Returns the Categories property. | 151 | Returns the Categories property. |
152 | */ | 152 | */ |
153 | 153 | ||
154 | const QArray<int>& AppLnk::categories() const | 154 | const QArray<int>& AppLnk::categories() const |
155 | { | 155 | { |
156 | return d->mCat; | 156 | return d->mCat; |
157 | } | 157 | } |
158 | 158 | ||
159 | /*! | 159 | /*! |
160 | \fn int AppLnk::id() const | 160 | \fn int AppLnk::id() const |
161 | 161 | ||
162 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, | 162 | Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, |
163 | this value is 0, otherwise it is a value that is unique for the | 163 | this value is 0, otherwise it is a value that is unique for the |
164 | duration of the current process. | 164 | duration of the current process. |
165 | */ | 165 | */ |
166 | 166 | ||
167 | /*! | 167 | /*! |
168 | \fn bool AppLnk::isValid() const | 168 | \fn bool AppLnk::isValid() const |
169 | 169 | ||
170 | Returns whether this AppLnk is valid. | 170 | Returns whether this AppLnk is valid. |
171 | */ | 171 | */ |
172 | 172 | ||
173 | /*! | 173 | /*! |
174 | Creates an invalid AppLnk. | 174 | Creates an invalid AppLnk. |
175 | 175 | ||
176 | \sa isValid() | 176 | \sa isValid() |
177 | */ | 177 | */ |
178 | AppLnk::AppLnk() | 178 | AppLnk::AppLnk() |
179 | { | 179 | { |
180 | mId = 0; | 180 | mId = 0; |
181 | d = new AppLnkPrivate(); | 181 | d = new AppLnkPrivate(); |
182 | } | 182 | } |
183 | 183 | ||
184 | /*! | 184 | /*! |
185 | Loads \a file as an AppLnk. | 185 | Loads \a file as an AppLnk. |
186 | */ | 186 | */ |
187 | AppLnk::AppLnk( const QString &file ) | 187 | AppLnk::AppLnk( const QString &file ) |
188 | { | 188 | { |
189 | QStringList sl; | 189 | QStringList sl; |
190 | d = new AppLnkPrivate(); | 190 | d = new AppLnkPrivate(); |
191 | if ( !file.isNull() ) { | 191 | if ( !file.isNull() ) { |
192 | Config config( file, Config::File ); | 192 | Config config( file, Config::File ); |
193 | 193 | ||
194 | if ( config.isValid() ) { | 194 | if ( config.isValid() ) { |
195 | config.setGroup( "Desktop Entry" ); | 195 | config.setGroup( "Desktop Entry" ); |
196 | 196 | ||
197 | mName = config.readEntry( "Name", file ); | 197 | mName = config.readEntry( "Name", file ); |
198 | mExec = config.readEntry( "Exec" ); | 198 | mExec = config.readEntry( "Exec" ); |
199 | mType = config.readEntry( "Type", QString::null ); | 199 | mType = config.readEntry( "Type", QString::null ); |
200 | mIconFile = config.readEntry( "Icon", QString::null ); | 200 | mIconFile = config.readEntry( "Icon", QString::null ); |
201 | mRotation = config.readEntry( "Rotation", "" ); | 201 | mRotation = config.readEntry( "Rotation", "" ); |
202 | mComment = config.readEntry( "Comment", QString::null ); | 202 | mComment = config.readEntry( "Comment", QString::null ); |
203 | mMimeTypes = config.readListEntry( "MimeType", ';' ); | 203 | mMimeTypes = config.readListEntry( "MimeType", ';' ); |
204 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); | 204 | mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); |
205 | mLinkFile = file; | 205 | mLinkFile = file; |
206 | mFile = config.readEntry("File", QString::null); | 206 | mFile = config.readEntry("File", QString::null); |
207 | sl = config.readListEntry("Categories", ';'); | 207 | sl = config.readListEntry("Categories", ';'); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | // let's try our darndest to create categories... | 210 | // let's try our darndest to create categories... |
211 | Categories cat( 0 ); | 211 | Categories cat( 0 ); |
212 | cat.load( categoryFileName() ); | 212 | cat.load( categoryFileName() ); |
213 | d->mCat.resize( sl.count() ); | 213 | d->mCat.resize( sl.count() ); |
214 | int i; | 214 | int i; |
215 | QStringList::Iterator it; | 215 | QStringList::Iterator it; |
216 | for ( i = 0, it = sl.begin(); it != sl.end(); | 216 | for ( i = 0, it = sl.begin(); it != sl.end(); |
217 | ++it, i++ ) { | 217 | ++it, i++ ) { |
218 | 218 | ||
219 | bool number; | 219 | bool number; |
220 | int id = (*it).toInt( &number ); | 220 | int id = (*it).toInt( &number ); |
221 | if ( !number ) { | 221 | if ( !number ) { |
222 | // convert from old school... | 222 | // convert from old school... |
223 | id = cat.id( "Document Viewer", *it ); | 223 | id = cat.id( "Document Viewer", *it ); |
224 | if ( id == 0 ) | 224 | if ( id == 0 ) |
225 | id = cat.addCategory( "Document Viewer", *it ); | 225 | id = cat.addCategory( "Document Viewer", *it ); |
226 | } | 226 | } |
227 | d->mCat[i] = id; | 227 | d->mCat[i] = id; |
228 | } | 228 | } |
229 | mId = 0; | 229 | mId = 0; |
230 | } | 230 | } |
231 | 231 | ||
232 | /*! | 232 | /*! |
233 | Returns a small pixmap associated with the application. | 233 | Returns a small pixmap associated with the application. |
234 | */ | 234 | */ |
235 | const QPixmap& AppLnk::pixmap() const | 235 | const QPixmap& AppLnk::pixmap() const |
236 | { | 236 | { |
237 | if ( mPixmap.isNull() ) { | 237 | if ( mPixmap.isNull() ) { |
238 | AppLnk* that = (AppLnk*)this; | 238 | AppLnk* that = (AppLnk*)this; |
239 | if ( mIconFile.isEmpty() ) { | 239 | if ( mIconFile.isEmpty() ) { |
240 | MimeType mt(type()); | 240 | MimeType mt(type()); |
241 | that->mPixmap = mt.pixmap(); | 241 | that->mPixmap = mt.pixmap(); |
242 | if ( that->mPixmap.isNull() ) | 242 | if ( that->mPixmap.isNull() ) |
243 | that->mPixmap = Resource::loadPixmap("UnknownDocument-14"); | 243 | that->mPixmap = Resource::loadPixmap("UnknownDocument-14"); |
244 | return that->mPixmap; | 244 | return that->mPixmap; |
245 | } | 245 | } |
246 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 246 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
247 | that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 247 | that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
248 | that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 248 | that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
249 | return that->mPixmap; | 249 | return that->mPixmap; |
250 | } | 250 | } |
251 | return mPixmap; | 251 | return mPixmap; |
252 | } | 252 | } |
253 | 253 | ||
254 | /*! | 254 | /*! |
255 | Returns a large pixmap associated with the application. | 255 | Returns a large pixmap associated with the application. |
256 | */ | 256 | */ |
257 | const QPixmap& AppLnk::bigPixmap() const | 257 | const QPixmap& AppLnk::bigPixmap() const |
258 | { | 258 | { |
259 | if ( mBigPixmap.isNull() ) { | 259 | if ( mBigPixmap.isNull() ) { |
260 | AppLnk* that = (AppLnk*)this; | 260 | AppLnk* that = (AppLnk*)this; |
261 | if ( mIconFile.isEmpty() ) { | 261 | if ( mIconFile.isEmpty() ) { |
262 | MimeType mt(type()); | 262 | MimeType mt(type()); |
263 | that->mBigPixmap = mt.bigPixmap(); | 263 | that->mBigPixmap = mt.bigPixmap(); |
264 | if ( that->mBigPixmap.isNull() ) | 264 | if ( that->mBigPixmap.isNull() ) |
265 | that->mBigPixmap = Resource::loadPixmap("UnknownDocument"); | 265 | that->mBigPixmap = Resource::loadPixmap("UnknownDocument"); |
266 | return that->mBigPixmap; | 266 | return that->mBigPixmap; |
267 | } | 267 | } |
268 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); | 268 | QImage unscaledIcon = Resource::loadImage( that->mIconFile ); |
269 | that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 269 | that->mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
270 | that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 270 | that->mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
271 | return that->mBigPixmap; | 271 | return that->mBigPixmap; |
272 | } | 272 | } |
273 | return mBigPixmap; | 273 | return mBigPixmap; |
274 | } | 274 | } |
275 | 275 | ||
276 | /*! | 276 | /*! |
277 | Returns the type of the application. | 277 | Returns the type of the application. |
278 | */ | 278 | */ |
279 | QString AppLnk::type() const | 279 | QString AppLnk::type() const |
280 | { | 280 | { |
281 | if ( mType.isNull() ) { | 281 | if ( mType.isNull() ) { |
282 | AppLnk* that = (AppLnk*)this; | 282 | AppLnk* that = (AppLnk*)this; |
283 | MimeType mt(file()); | 283 | MimeType mt(file()); |
284 | that->mType = mt.id(); | 284 | that->mType = mt.id(); |
285 | return that->mType; | 285 | return that->mType; |
286 | } | 286 | } |
287 | return mType; | 287 | return mType; |
288 | } | 288 | } |
289 | 289 | ||
290 | /*! | 290 | /*! |
291 | Returns the file associated with the AppLnk. | 291 | Returns the file associated with the AppLnk. |
292 | 292 | ||
293 | \sa exec() | 293 | \sa exec() |
294 | */ | 294 | */ |
295 | QString AppLnk::file() const | 295 | QString AppLnk::file() const |
296 | { | 296 | { |
297 | if ( mFile.isNull() ) { | 297 | if ( mFile.isNull() ) { |
298 | AppLnk* that = (AppLnk*)this; // copy? | 298 | AppLnk* that = (AppLnk*)this; // copy? |
299 | QString ext = MimeType(mType).extension(); | 299 | QString ext = MimeType(mType).extension(); |
300 | if ( !ext.isEmpty() ) | 300 | if ( !ext.isEmpty() ) |
301 | ext = "." + ext; | 301 | ext = "." + ext; |
302 | if ( !mLinkFile.isEmpty() ) { | 302 | if ( !mLinkFile.isEmpty() ) { |
303 | that->mFile = | 303 | that->mFile = |
304 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") | 304 | mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") |
305 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; | 305 | ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; |
306 | } else if ( mType.contains('/') ) { | 306 | } else if ( mType.contains('/') ) { |
307 | that->mFile = | 307 | that->mFile = |
308 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); | 308 | QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); |
309 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists | 309 | if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists |
310 | int n=1; | 310 | int n=1; |
311 | qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() ); | 311 | qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() ); |
312 | QString nn; | 312 | QString nn; |
313 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) | 313 | while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) |
314 | || QFile::exists(nn+".desktop")) | 314 | || QFile::exists(nn+".desktop")) |
315 | n++; | 315 | n++; |
316 | that->mFile = nn; | 316 | that->mFile = nn; |
317 | qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() ); | 317 | qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() ); |
318 | } | 318 | } |
319 | that->mLinkFile = that->mFile+".desktop"; | 319 | that->mLinkFile = that->mFile+".desktop"; |
320 | that->mFile += ext; | 320 | that->mFile += ext; |
321 | } | 321 | } |
322 | prepareDirectories(that->mFile); | 322 | prepareDirectories(that->mFile); |
323 | QFile f(that->mFile); | 323 | QFile f(that->mFile); |
324 | if ( !f.open(IO_WriteOnly) ) | 324 | if ( !f.open(IO_WriteOnly) ) |
325 | that->mFile = QString::null; | 325 | that->mFile = QString::null; |
326 | return that->mFile; | 326 | return that->mFile; |
327 | } | 327 | } |
328 | return mFile; | 328 | return mFile; |
329 | } | 329 | } |
330 | 330 | ||
331 | /*! | 331 | /*! |
332 | Returns the desktop file coresponding to this AppLnk. | 332 | Returns the desktop file coresponding to this AppLnk. |
333 | 333 | ||
334 | \sa file(), exec() | 334 | \sa file(), exec() |
335 | */ | 335 | */ |
336 | QString AppLnk::linkFile() const | 336 | QString AppLnk::linkFile() const |
337 | { | 337 | { |
338 | if ( mLinkFile.isNull() ) { | 338 | if ( mLinkFile.isNull() ) { |
339 | AppLnk* that = (AppLnk*)this; | 339 | AppLnk* that = (AppLnk*)this; |
340 | if ( type().contains('/') ) { | 340 | if ( type().contains('/') ) { |
341 | StorageInfo storage; | 341 | StorageInfo storage; |
342 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); | 342 | const FileSystem *fs = storage.fileSystemOf( that->mFile ); |
343 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs" ) ) { | 343 | if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs" ) ) { |
344 | that->mLinkFile = fs->path(); | 344 | that->mLinkFile = fs->path(); |
345 | } else | 345 | } else |
346 | that->mLinkFile = getenv( "HOME" ); | 346 | that->mLinkFile = getenv( "HOME" ); |
347 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); | 347 | that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); |
348 | if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file | 348 | if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file |
349 | int n=1; | 349 | int n=1; |
350 | QString nn; | 350 | QString nn; |
351 | AppLnk lnk( that->mLinkFile+".desktop" ); | 351 | AppLnk lnk( that->mLinkFile+".desktop" ); |
352 | if(that->file() != lnk.file() ){ | 352 | if(that->file() != lnk.file() ){ |
353 | qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() ); | 353 | qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() ); |
354 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){ | 354 | while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){ |
355 | n++; | 355 | n++; |
356 | AppLnk lnk(nn ); // just to be sure | 356 | AppLnk lnk(nn ); // just to be sure |
357 | if(lnk.file() ==that->file() ){ | 357 | if(lnk.file() ==that->file() ){ |
358 | break; | 358 | break; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | that->mLinkFile = nn; | 361 | that->mLinkFile = nn; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | that->mLinkFile += ".desktop"; | 364 | that->mLinkFile += ".desktop"; |
365 | qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() ); | 365 | qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() ); |
366 | storeLink(); | 366 | storeLink(); |
367 | } | 367 | } |
368 | return that->mLinkFile; | 368 | return that->mLinkFile; |
369 | } | 369 | } |
370 | return mLinkFile; | 370 | return mLinkFile; |
371 | } | 371 | } |
372 | 372 | ||
373 | /*! | 373 | /*! |
374 | Copies \a copy. | 374 | Copies \a copy. |
375 | */ | 375 | */ |
376 | AppLnk::AppLnk( const AppLnk © ) | 376 | AppLnk::AppLnk( const AppLnk © ) |
377 | { | 377 | { |
378 | mName = copy.mName; | 378 | mName = copy.mName; |
379 | mPixmap = copy.mPixmap; | 379 | mPixmap = copy.mPixmap; |
380 | mBigPixmap = copy.mBigPixmap; | 380 | mBigPixmap = copy.mBigPixmap; |
381 | mExec = copy.mExec; | 381 | mExec = copy.mExec; |
382 | mType = copy.mType; | 382 | mType = copy.mType; |
383 | mRotation = copy.mRotation; | 383 | mRotation = copy.mRotation; |
384 | mComment = copy.mComment; | 384 | mComment = copy.mComment; |
385 | mFile = copy.mFile; | 385 | mFile = copy.mFile; |
386 | mLinkFile = copy.mLinkFile; | 386 | mLinkFile = copy.mLinkFile; |
387 | mIconFile = copy.mIconFile; | 387 | mIconFile = copy.mIconFile; |
388 | mMimeTypes = copy.mMimeTypes; | 388 | mMimeTypes = copy.mMimeTypes; |
389 | mMimeTypeIcons = copy.mMimeTypeIcons; | 389 | mMimeTypeIcons = copy.mMimeTypeIcons; |
390 | mId = 0; | 390 | mId = 0; |
391 | d = new AppLnkPrivate(); | 391 | d = new AppLnkPrivate(); |
392 | d->mCat = copy.d->mCat; | 392 | d->mCat = copy.d->mCat; |
393 | } | 393 | } |
394 | 394 | ||
395 | /*! | 395 | /*! |
396 | Destroys the AppLnk. Note that if the AppLnk is current a member of | 396 | Destroys the AppLnk. Note that if the AppLnk is current a member of |
397 | an AppLnkSet, this will produce a run-time warning. | 397 | an AppLnkSet, this will produce a run-time warning. |
398 | 398 | ||
399 | \sa AppLnkSet::add(), AppLnkSet::remove() | 399 | \sa AppLnkSet::add(), AppLnkSet::remove() |
400 | */ | 400 | */ |
401 | AppLnk::~AppLnk() | 401 | AppLnk::~AppLnk() |
402 | { | 402 | { |
403 | if ( mId ) | 403 | if ( mId ) |
404 | qWarning("Deleting AppLnk that is in an AppLnkSet"); | 404 | qWarning("Deleting AppLnk that is in an AppLnkSet"); |
405 | if ( d ) | 405 | if ( d ) |
406 | delete d; | 406 | delete d; |
407 | } | 407 | } |
408 | 408 | ||
409 | /*! | 409 | /*! |
410 | Executes the application associated with this AppLnk. | 410 | Executes the application associated with this AppLnk. |
411 | */ | 411 | */ |
412 | void AppLnk::execute() const | 412 | void AppLnk::execute() const |
413 | { | 413 | { |
414 | execute(QStringList()); | 414 | execute(QStringList()); |
415 | } | 415 | } |
416 | 416 | ||
417 | /*! | 417 | /*! |
418 | Executes the application associated with this AppLnk, with | 418 | Executes the application associated with this AppLnk, with |
419 | \a args as arguments. | 419 | \a args as arguments. |
420 | */ | 420 | */ |
421 | void AppLnk::execute(const QStringList& args) const | 421 | void AppLnk::execute(const QStringList& args) const |
422 | { | 422 | { |
423 | #ifdef Q_WS_QWS | 423 | #ifdef Q_WS_QWS |
424 | if ( !mRotation.isEmpty() ) { | 424 | if ( !mRotation.isEmpty() ) { |
425 | // ######## this will only work in the server | 425 | // ######## this will only work in the server |
426 | int rot = QPEApplication::defaultRotation(); | 426 | int rot = QPEApplication::defaultRotation(); |
427 | rot = (rot+mRotation.toInt())%360; | 427 | rot = (rot+mRotation.toInt())%360; |
428 | QCString old = getenv("QWS_DISPLAY"); | 428 | QCString old = getenv("QWS_DISPLAY"); |
429 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 429 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
430 | invoke(args); | 430 | invoke(args); |
431 | setenv("QWS_DISPLAY", old.data(), 1); | 431 | setenv("QWS_DISPLAY", old.data(), 1); |
432 | } else | 432 | } else |
433 | #endif | 433 | #endif |
434 | invoke(args); | 434 | invoke(args); |
435 | } | 435 | } |
436 | 436 | ||
437 | /*! | 437 | /*! |
438 | Invokes the application associated with this AppLnk, with | 438 | Invokes the application associated with this AppLnk, with |
439 | \a args as arguments. Rotation is not taken into account by | 439 | \a args as arguments. Rotation is not taken into account by |
440 | this function, you should not call it directly. | 440 | this function, you should not call it directly. |
441 | 441 | ||
442 | \sa execute() | 442 | \sa execute() |
443 | */ | 443 | */ |
444 | void AppLnk::invoke(const QStringList& args) const | 444 | void AppLnk::invoke(const QStringList& args) const |
445 | { | 445 | { |
446 | Global::execute( exec(), args[0] ); | 446 | Global::execute( exec(), args[0] ); |
447 | } | 447 | } |
448 | 448 | ||
449 | /*! | 449 | /*! |
450 | Sets the Exec property to \a exec. | 450 | Sets the Exec property to \a exec. |
451 | 451 | ||
452 | \sa exec() | 452 | \sa exec() |
453 | */ | 453 | */ |
454 | void AppLnk::setExec( const QString& exec ) | 454 | void AppLnk::setExec( const QString& exec ) |
455 | { | 455 | { |
456 | mExec = exec; | 456 | mExec = exec; |
457 | } | 457 | } |
458 | 458 | ||
459 | /*! | 459 | /*! |
460 | Sets the Name property to \a docname. | 460 | Sets the Name property to \a docname. |
461 | 461 | ||
462 | \sa name() | 462 | \sa name() |
463 | */ | 463 | */ |
464 | void AppLnk::setName( const QString& docname ) | 464 | void AppLnk::setName( const QString& docname ) |
465 | { | 465 | { |
466 | mName = docname; | 466 | mName = docname; |
467 | } | 467 | } |
468 | 468 | ||
469 | /*! | 469 | /*! |
470 | Sets the File property to \a filename. | 470 | Sets the File property to \a filename. |
471 | 471 | ||
472 | \sa file() | 472 | \sa file() |
473 | */ | 473 | */ |
474 | void AppLnk::setFile( const QString& filename ) | 474 | void AppLnk::setFile( const QString& filename ) |
475 | { | 475 | { |
476 | mFile = filename; | 476 | mFile = filename; |
477 | } | 477 | } |
478 | 478 | ||
479 | /*! | 479 | /*! |
480 | Sets the LinkFile property to \a filename. | 480 | Sets the LinkFile property to \a filename. |
481 | 481 | ||
482 | \sa linkFile() | 482 | \sa linkFile() |
483 | */ | 483 | */ |
484 | void AppLnk::setLinkFile( const QString& filename ) | 484 | void AppLnk::setLinkFile( const QString& filename ) |
485 | { | 485 | { |
486 | mLinkFile = filename; | 486 | mLinkFile = filename; |
487 | } | 487 | } |
488 | 488 | ||
489 | /*! | 489 | /*! |
490 | Sets the Comment property to \a comment. | 490 | Sets the Comment property to \a comment. |
491 | 491 | ||
492 | \sa comment() | 492 | \sa comment() |
493 | */ | 493 | */ |
494 | void AppLnk::setComment( const QString& comment ) | 494 | void AppLnk::setComment( const QString& comment ) |
495 | { | 495 | { |
496 | mComment = comment; | 496 | mComment = comment; |
497 | } | 497 | } |
498 | 498 | ||
499 | /*! | 499 | /*! |
500 | Sets the Type property to \a type. | 500 | Sets the Type property to \a type. |
501 | 501 | ||
502 | \sa type() | 502 | \sa type() |
503 | */ | 503 | */ |
504 | void AppLnk::setType( const QString& type ) | 504 | void AppLnk::setType( const QString& type ) |
505 | { | 505 | { |
506 | mType = type; | 506 | mType = type; |
507 | } | 507 | } |
508 | 508 | ||
509 | /*! | 509 | /*! |
510 | Sets the Icon property to \a iconname. | 510 | Sets the Icon property to \a iconname. |
511 | 511 | ||
512 | \sa pixmap(), bigPixmap() | 512 | \sa pixmap(), bigPixmap() |
513 | */ | 513 | */ |
514 | void AppLnk::setIcon( const QString& iconname ) | 514 | void AppLnk::setIcon( const QString& iconname ) |
515 | { | 515 | { |
516 | mIconFile = iconname; | 516 | mIconFile = iconname; |
517 | QImage unscaledIcon = Resource::loadImage( mIconFile ); | 517 | QImage unscaledIcon = Resource::loadImage( mIconFile ); |
518 | mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 518 | mPixmap.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
519 | mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 519 | mBigPixmap.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
520 | } | 520 | } |
521 | 521 | ||
522 | /*! | 522 | /*! |
523 | Sets the Categories property to \a c. | 523 | Sets the Categories property to \a c. |
524 | 524 | ||
525 | \sa categories() | 525 | \sa categories() |
526 | */ | 526 | */ |
527 | void AppLnk::setCategories( const QArray<int>& c ) | 527 | void AppLnk::setCategories( const QArray<int>& c ) |
528 | { | 528 | { |
529 | d->mCat = c; | 529 | d->mCat = c; |
530 | } | 530 | } |
531 | 531 | ||
532 | /*! | 532 | /*! |
533 | \fn QStringList AppLnk::mimeTypeIcons() const | 533 | \fn QStringList AppLnk::mimeTypeIcons() const |
534 | 534 | ||
535 | Returns the MimeTypeIcons property of the AppLnk. | 535 | Returns the MimeTypeIcons property of the AppLnk. |
536 | */ | 536 | */ |
537 | 537 | ||
538 | /*! | 538 | /*! |
539 | Attempts to ensure that the link file for this AppLnk exists, including | 539 | Attempts to ensure that the link file for this AppLnk exists, including |
540 | creating any required directories. Returns TRUE if successful. | 540 | creating any required directories. Returns TRUE if successful. |
541 | */ | 541 | */ |
542 | bool AppLnk::ensureLinkExists() const | 542 | bool AppLnk::ensureLinkExists() const |
543 | { | 543 | { |
544 | QString lf = linkFile(); | 544 | QString lf = linkFile(); |
545 | return prepareDirectories(lf); | 545 | return prepareDirectories(lf); |
546 | } | 546 | } |
547 | 547 | ||
548 | /*! | 548 | /*! |
549 | Commits the AppLnk to disk. Returns whether the operation succeeded. | 549 | Commits the AppLnk to disk. Returns whether the operation succeeded. |
550 | 550 | ||
551 | The "linkChanged(QString)" message is sent to the | 551 | The "linkChanged(QString)" message is sent to the |
552 | "QPE/System" QCop channel as a result. | 552 | "QPE/System" QCop channel as a result. |
553 | */ | 553 | */ |
554 | bool AppLnk::writeLink() const | 554 | bool AppLnk::writeLink() const |
555 | { | 555 | { |
556 | // Only re-writes settable parts | 556 | // Only re-writes settable parts |
557 | QString lf = linkFile(); | 557 | QString lf = linkFile(); |
558 | if ( !ensureLinkExists() ) | 558 | if ( !ensureLinkExists() ) |
559 | return FALSE; | 559 | return FALSE; |
560 | storeLink(); | 560 | storeLink(); |
561 | return TRUE; | 561 | return TRUE; |
562 | } | 562 | } |
563 | 563 | ||
564 | void AppLnk::storeLink() const | 564 | void AppLnk::storeLink() const |
565 | { | 565 | { |
566 | Config config( mLinkFile, Config::File ); | 566 | Config config( mLinkFile, Config::File ); |
567 | config.setGroup("Desktop Entry"); | 567 | config.setGroup("Desktop Entry"); |
568 | config.writeEntry("Name",mName); | 568 | config.writeEntry("Name",mName); |
569 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); | 569 | if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); |
570 | config.writeEntry("Type",type()); | 570 | config.writeEntry("Type",type()); |
571 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); | 571 | if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); |
572 | config.writeEntry("File",file()); | 572 | config.writeEntry("File",file()); |
573 | // write out the id... | 573 | // write out the id... |
574 | int i; | 574 | int i; |
575 | QStringList sl; | 575 | QStringList sl; |
576 | for ( i = 0; i < int(d->mCat.count()); i++ ) { | 576 | for ( i = 0; i < int(d->mCat.count()); i++ ) { |
577 | sl.append( QString::number( d->mCat[i] ) ); | 577 | sl.append( QString::number( d->mCat[i] ) ); |
578 | } | 578 | } |
579 | config.writeEntry( "Categories", sl, ';' ); | 579 | config.writeEntry( "Categories", sl, ';' ); |
580 | 580 | ||
581 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 581 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
582 | e << mLinkFile; | 582 | e << mLinkFile; |
583 | } | 583 | } |
584 | 584 | ||
585 | /*! | 585 | /*! |
586 | Sets the property named \a key to \a value. | 586 | Sets the property named \a key to \a value. |
587 | */ | 587 | */ |
588 | void AppLnk::setProperty(const QString& key, const QString& value) | 588 | void AppLnk::setProperty(const QString& key, const QString& value) |
589 | { | 589 | { |
590 | if ( ensureLinkExists() ) { | 590 | if ( ensureLinkExists() ) { |
591 | Config cfg(linkFile(), Config::File); | 591 | Config cfg(linkFile(), Config::File); |
592 | cfg.writeEntry(key,value); | 592 | cfg.writeEntry(key,value); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | 595 | ||
596 | /*! | 596 | /*! |
597 | Returns the property named \a key. | 597 | Returns the property named \a key. |
598 | */ | 598 | */ |
599 | QString AppLnk::property(const QString& key) const | 599 | QString AppLnk::property(const QString& key) const |
600 | { | 600 | { |
601 | QString lf = linkFile(); | 601 | QString lf = linkFile(); |
602 | if ( !QFile::exists(lf) ) | 602 | if ( !QFile::exists(lf) ) |
603 | return QString::null; | 603 | return QString::null; |
604 | Config cfg(lf, Config::File); | 604 | Config cfg(lf, Config::File); |
605 | return cfg.readEntry(key); | 605 | return cfg.readEntry(key); |
606 | } | 606 | } |
607 | 607 | ||
608 | 608 | ||
609 | bool AppLnk::isPreloaded() const { | ||
610 | // Preload information is stored in the Launcher config in v1.5. | ||
611 | Config cfg("Launcher"); | ||
612 | cfg.setGroup("Preload"); | ||
613 | QStringList apps = cfg.readListEntry("Apps",','); | ||
614 | if (apps.contains(exec())) | ||
615 | return true; | ||
616 | return false; | ||
617 | } | ||
618 | |||
619 | void AppLnk::setPreloaded(bool yesNo) { | ||
620 | // Preload information is stored in the Launcher config in v1.5. | ||
621 | Config cfg("Launcher"); | ||
622 | cfg.setGroup("Preload"); | ||
623 | QStringList apps = cfg.readListEntry("Apps", ','); | ||
624 | if (apps.contains(exec()) && !yesNo) | ||
625 | apps.remove(exec()); | ||
626 | else if (yesNo && !apps.contains(exec())) | ||
627 | apps.append(exec()); | ||
628 | cfg.writeEntry("Apps", apps, ','); | ||
629 | } | ||
630 | |||
631 | |||
609 | /*! | 632 | /*! |
610 | Deletes both the linkFile() and file() associated with this AppLnk. | 633 | Deletes both the linkFile() and file() associated with this AppLnk. |
611 | */ | 634 | */ |
612 | void AppLnk::removeFiles() | 635 | void AppLnk::removeFiles() |
613 | { | 636 | { |
614 | bool valid = isValid(); | 637 | bool valid = isValid(); |
615 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { | 638 | if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { |
616 | if ( QFile::remove(file()) ) { | 639 | if ( QFile::remove(file()) ) { |
617 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 640 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
618 | if ( linkFileKnown() ) | 641 | if ( linkFileKnown() ) |
619 | e << linkFile(); | 642 | e << linkFile(); |
620 | else | 643 | else |
621 | e << file(); | 644 | e << file(); |
622 | } else if ( valid ) { | 645 | } else if ( valid ) { |
623 | // restore link | 646 | // restore link |
624 | writeLink(); | 647 | writeLink(); |
625 | } | 648 | } |
626 | } | 649 | } |
627 | } | 650 | } |
628 | 651 | ||
629 | /*! | 652 | /*! |
630 | Delete the linkFile(), leaving any file() untouched. | 653 | Delete the linkFile(), leaving any file() untouched. |
631 | */ | 654 | */ |
632 | void AppLnk::removeLinkFile() | 655 | void AppLnk::removeLinkFile() |
633 | { | 656 | { |
634 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { | 657 | if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { |
635 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 658 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
636 | e << linkFile(); | 659 | e << linkFile(); |
637 | } | 660 | } |
638 | } | 661 | } |
639 | 662 | ||
640 | class AppLnkSetPrivate { | 663 | class AppLnkSetPrivate { |
641 | public: | 664 | public: |
642 | AppLnkSetPrivate() | 665 | AppLnkSetPrivate() |
643 | { | 666 | { |
644 | typPix.setAutoDelete(TRUE); | 667 | typPix.setAutoDelete(TRUE); |
645 | typPixBig.setAutoDelete(TRUE); | 668 | typPixBig.setAutoDelete(TRUE); |
646 | typName.setAutoDelete(TRUE); | 669 | typName.setAutoDelete(TRUE); |
647 | } | 670 | } |
648 | 671 | ||
649 | QDict<QPixmap> typPix; | 672 | QDict<QPixmap> typPix; |
650 | QDict<QPixmap> typPixBig; | 673 | QDict<QPixmap> typPixBig; |
651 | QDict<QString> typName; | 674 | QDict<QString> typName; |
652 | }; | 675 | }; |
653 | 676 | ||
654 | /*! | 677 | /*! |
655 | \class AppLnkSet applnk.h | 678 | \class AppLnkSet applnk.h |
656 | \brief The AppLnkSet class is a set of AppLnk objects. | 679 | \brief The AppLnkSet class is a set of AppLnk objects. |
657 | */ | 680 | */ |
658 | 681 | ||
659 | /*! | 682 | /*! |
660 | \fn QStringList AppLnkSet::types() const | 683 | \fn QStringList AppLnkSet::types() const |
661 | 684 | ||
662 | Returns the list of types in the set. | 685 | Returns the list of types in the set. |
663 | 686 | ||
664 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() | 687 | \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() |
665 | */ | 688 | */ |
666 | 689 | ||
667 | /*! | 690 | /*! |
668 | \fn const QList<AppLnk>& AppLnkSet::children() const | 691 | \fn const QList<AppLnk>& AppLnkSet::children() const |
669 | 692 | ||
670 | Returns the members of the set. | 693 | Returns the members of the set. |
671 | */ | 694 | */ |
672 | 695 | ||
673 | /*! | 696 | /*! |
674 | Constructs an empty AppLnkSet. | 697 | Constructs an empty AppLnkSet. |
675 | */ | 698 | */ |
676 | AppLnkSet::AppLnkSet() : | 699 | AppLnkSet::AppLnkSet() : |
677 | d(new AppLnkSetPrivate) | 700 | d(new AppLnkSetPrivate) |
678 | { | 701 | { |
679 | } | 702 | } |
680 | 703 | ||
681 | /*! | 704 | /*! |
682 | Constructs an AppLnkSet that contains AppLnk objects representing | 705 | Constructs an AppLnkSet that contains AppLnk objects representing |
683 | all the files in a \a directory (recursively). | 706 | all the files in a \a directory (recursively). |
684 | 707 | ||
685 | The directories may contain ".directory" files which overrides | 708 | The directories may contain ".directory" files which overrides |
686 | any AppLnk::type() value of AppLnk objects found in the directory. | 709 | any AppLnk::type() value of AppLnk objects found in the directory. |
687 | This allows simple localization of application types. | 710 | This allows simple localization of application types. |
688 | */ | 711 | */ |
689 | AppLnkSet::AppLnkSet( const QString &directory ) : | 712 | AppLnkSet::AppLnkSet( const QString &directory ) : |
690 | d(new AppLnkSetPrivate) | 713 | d(new AppLnkSetPrivate) |
691 | { | 714 | { |
692 | QDir dir( directory ); | 715 | QDir dir( directory ); |
693 | mFile = directory; | 716 | mFile = directory; |
694 | findChildren(directory,QString::null,QString::null); | 717 | findChildren(directory,QString::null,QString::null); |
695 | } | 718 | } |
696 | 719 | ||
697 | /*! | 720 | /*! |
698 | Detaches all AppLnk objects from the set. The set become empty | 721 | Detaches all AppLnk objects from the set. The set become empty |
699 | and the call becomes responsible for deleting the AppLnk objects. | 722 | and the call becomes responsible for deleting the AppLnk objects. |
700 | */ | 723 | */ |
701 | void AppLnkSet::detachChildren() | 724 | void AppLnkSet::detachChildren() |
702 | { | 725 | { |
703 | QListIterator<AppLnk> it( mApps ); | 726 | QListIterator<AppLnk> it( mApps ); |
704 | for ( ; it.current(); ) { | 727 | for ( ; it.current(); ) { |
705 | AppLnk* a = *it; | 728 | AppLnk* a = *it; |
706 | ++it; | 729 | ++it; |
707 | a->mId = 0; | 730 | a->mId = 0; |
708 | } | 731 | } |
709 | mApps.clear(); | 732 | mApps.clear(); |
710 | } | 733 | } |
711 | 734 | ||
712 | /*! | 735 | /*! |
713 | Destroys the set, deleting all AppLnk objects it contains. | 736 | Destroys the set, deleting all AppLnk objects it contains. |
714 | 737 | ||
715 | \sa detachChildren() | 738 | \sa detachChildren() |
716 | */ | 739 | */ |
717 | AppLnkSet::~AppLnkSet() | 740 | AppLnkSet::~AppLnkSet() |
718 | { | 741 | { |
719 | QListIterator<AppLnk> it( mApps ); | 742 | QListIterator<AppLnk> it( mApps ); |
720 | for ( ; it.current(); ) { | 743 | for ( ; it.current(); ) { |
721 | AppLnk* a = *it; | 744 | AppLnk* a = *it; |
722 | ++it; | 745 | ++it; |
723 | a->mId = 0; | 746 | a->mId = 0; |
724 | delete a; | 747 | delete a; |
725 | } | 748 | } |
726 | delete d; | 749 | delete d; |
727 | } | 750 | } |
728 | 751 | ||
729 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) | 752 | void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) |
730 | { | 753 | { |
731 | depth++; | 754 | depth++; |
732 | if ( depth > 10 ) | 755 | if ( depth > 10 ) |
733 | return; | 756 | return; |
734 | 757 | ||
735 | QDir dir( dr ); | 758 | QDir dir( dr ); |
736 | QString typNameLocal = typName; | 759 | QString typNameLocal = typName; |
737 | 760 | ||
738 | if ( dir.exists( ".directory" ) ) { | 761 | if ( dir.exists( ".directory" ) ) { |
739 | Config config( dr + "/.directory", Config::File ); | 762 | Config config( dr + "/.directory", Config::File ); |
740 | config.setGroup( "Desktop Entry" ); | 763 | config.setGroup( "Desktop Entry" ); |
741 | typNameLocal = config.readEntry( "Name", typNameLocal ); | 764 | typNameLocal = config.readEntry( "Name", typNameLocal ); |
742 | if ( !typ.isEmpty() ) { | 765 | if ( !typ.isEmpty() ) { |
743 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); | 766 | QString iconFile = config.readEntry( "Icon", "AppsIcon" ); |
744 | QImage unscaledIcon = Resource::loadImage( iconFile ); | 767 | QImage unscaledIcon = Resource::loadImage( iconFile ); |
745 | QPixmap pm, bpm; | 768 | QPixmap pm, bpm; |
746 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); | 769 | pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); |
747 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); | 770 | bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); |
748 | d->typPix.insert(typ, new QPixmap(pm)); | 771 | d->typPix.insert(typ, new QPixmap(pm)); |
749 | d->typPixBig.insert(typ, new QPixmap(bpm)); | 772 | d->typPixBig.insert(typ, new QPixmap(bpm)); |
750 | d->typName.insert(typ, new QString(typNameLocal)); | 773 | d->typName.insert(typ, new QString(typNameLocal)); |
751 | } | 774 | } |
752 | } | 775 | } |
753 | 776 | ||
754 | const QFileInfoList *list = dir.entryInfoList(); | 777 | const QFileInfoList *list = dir.entryInfoList(); |
755 | if ( list ) { | 778 | if ( list ) { |
756 | QFileInfo* fi; | 779 | QFileInfo* fi; |
757 | bool cadded=FALSE; | 780 | bool cadded=FALSE; |
758 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { | 781 | for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { |
759 | QString bn = fi->fileName(); | 782 | QString bn = fi->fileName(); |
760 | if ( bn[0] != '.' && bn != "CVS" ) { | 783 | if ( bn[0] != '.' && bn != "CVS" ) { |
761 | if ( fi->isDir() ) { | 784 | if ( fi->isDir() ) { |
762 | QString c = typ.isNull() ? bn : typ+"/"+bn; | 785 | QString c = typ.isNull() ? bn : typ+"/"+bn; |
763 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; | 786 | QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; |
764 | findChildren(fi->filePath(), c, d, depth ); | 787 | findChildren(fi->filePath(), c, d, depth ); |
765 | } else { | 788 | } else { |
766 | if ( fi->extension(FALSE) == "desktop" ) { | 789 | if ( fi->extension(FALSE) == "desktop" ) { |
767 | AppLnk* app = new AppLnk( fi->filePath() ); | 790 | AppLnk* app = new AppLnk( fi->filePath() ); |
768 | #ifdef QT_NO_QWS_MULTIPROCESS | 791 | #ifdef QT_NO_QWS_MULTIPROCESS |
769 | if ( !Global::isBuiltinCommand( app->exec() ) ) | 792 | if ( !Global::isBuiltinCommand( app->exec() ) ) |
770 | delete app; | 793 | delete app; |
771 | else | 794 | else |
772 | #endif | 795 | #endif |
773 | { | 796 | { |
774 | if ( !typ.isEmpty() ) { | 797 | if ( !typ.isEmpty() ) { |
775 | if ( !cadded ) { | 798 | if ( !cadded ) { |
776 | typs.append(typ); | 799 | typs.append(typ); |
777 | cadded = TRUE; | 800 | cadded = TRUE; |
778 | } | 801 | } |
779 | app->setType(typ); | 802 | app->setType(typ); |
780 | } | 803 | } |
781 | add(app); | 804 | add(app); |
782 | } | 805 | } |
783 | } | 806 | } |
784 | } | 807 | } |
785 | } | 808 | } |
786 | } | 809 | } |
787 | } | 810 | } |
788 | } | 811 | } |
789 | 812 | ||
790 | /*! | 813 | /*! |
791 | Adds \a f to the set. The set takes over responsibility for deleting \a f. | 814 | Adds \a f to the set. The set takes over responsibility for deleting \a f. |
792 | 815 | ||
793 | \sa remove() | 816 | \sa remove() |
794 | */ | 817 | */ |
795 | void AppLnkSet::add( AppLnk *f ) | 818 | void AppLnkSet::add( AppLnk *f ) |
796 | { | 819 | { |
797 | if ( f->mId == 0 ) { | 820 | if ( f->mId == 0 ) { |
798 | AppLnk::lastId++; | 821 | AppLnk::lastId++; |
799 | f->mId = AppLnk::lastId; | 822 | f->mId = AppLnk::lastId; |
800 | mApps.append( f ); | 823 | mApps.append( f ); |
801 | } else { | 824 | } else { |
802 | qWarning("Attempt to add an AppLnk twice"); | 825 | qWarning("Attempt to add an AppLnk twice"); |
803 | } | 826 | } |
804 | } | 827 | } |
805 | 828 | ||
806 | /*! | 829 | /*! |
807 | Removes \a f to the set, returning whether \a f was in the set. | 830 | Removes \a f to the set, returning whether \a f was in the set. |
808 | The caller becomes responsible for deleting \a f. | 831 | The caller becomes responsible for deleting \a f. |
809 | 832 | ||
810 | \sa add() | 833 | \sa add() |
811 | */ | 834 | */ |
812 | bool AppLnkSet::remove( AppLnk *f ) | 835 | bool AppLnkSet::remove( AppLnk *f ) |
813 | { | 836 | { |
814 | if ( mApps.remove( f ) ) { | 837 | if ( mApps.remove( f ) ) { |
815 | f->mId = 0; | 838 | f->mId = 0; |
816 | return TRUE; | 839 | return TRUE; |
817 | } | 840 | } |
818 | return FALSE; | 841 | return FALSE; |
819 | } | 842 | } |
820 | 843 | ||
821 | /*! | 844 | /*! |
822 | Returns the localized name for type \a t. | 845 | Returns the localized name for type \a t. |
823 | */ | 846 | */ |
824 | QString AppLnkSet::typeName( const QString& t ) const | 847 | QString AppLnkSet::typeName( const QString& t ) const |
825 | { | 848 | { |
826 | QString *st = d->typName.find(t); | 849 | QString *st = d->typName.find(t); |
827 | return st ? *st : QString::null; | 850 | return st ? *st : QString::null; |
828 | } | 851 | } |
829 | 852 | ||
830 | /*! | 853 | /*! |
831 | Returns the small pixmap associated with type \a t. | 854 | Returns the small pixmap associated with type \a t. |
832 | */ | 855 | */ |
833 | QPixmap AppLnkSet::typePixmap( const QString& t ) const | 856 | QPixmap AppLnkSet::typePixmap( const QString& t ) const |
834 | { | 857 | { |
835 | QPixmap *pm = d->typPix.find(t); | 858 | QPixmap *pm = d->typPix.find(t); |
836 | return pm ? *pm : QPixmap(); | 859 | return pm ? *pm : QPixmap(); |
837 | } | 860 | } |
838 | 861 | ||
839 | /*! | 862 | /*! |
840 | Returns the large pixmap associated with type \a t. | 863 | Returns the large pixmap associated with type \a t. |
841 | */ | 864 | */ |
842 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const | 865 | QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const |
843 | { | 866 | { |
844 | QPixmap *pm = d->typPixBig.find(t); | 867 | QPixmap *pm = d->typPixBig.find(t); |
845 | return pm ? *pm : QPixmap(); | 868 | return pm ? *pm : QPixmap(); |
846 | } | 869 | } |
847 | 870 | ||
848 | /*! | 871 | /*! |
849 | Returns the AppLnk with the given \a id. | 872 | Returns the AppLnk with the given \a id. |
850 | */ | 873 | */ |
851 | const AppLnk *AppLnkSet::find( int id ) const | 874 | const AppLnk *AppLnkSet::find( int id ) const |
852 | { | 875 | { |
853 | QListIterator<AppLnk> it( children() ); | 876 | QListIterator<AppLnk> it( children() ); |
854 | 877 | ||
855 | for ( ; it.current(); ++it ) { | 878 | for ( ; it.current(); ++it ) { |
856 | const AppLnk *app = it.current(); | 879 | const AppLnk *app = it.current(); |
857 | if ( app->id() == id ) | 880 | if ( app->id() == id ) |
858 | return app; | 881 | return app; |
859 | } | 882 | } |
860 | 883 | ||
861 | return 0; | 884 | return 0; |
862 | } | 885 | } |
863 | 886 | ||
864 | /*! | 887 | /*! |
diff --git a/library/applnk.h b/library/applnk.h index 18e20b6..9b5523e 100644 --- a/library/applnk.h +++ b/library/applnk.h | |||
@@ -1,172 +1,177 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef __APPLNK_H__ | 20 | #ifndef __APPLNK_H__ |
21 | #define __APPLNK_H__ | 21 | #define __APPLNK_H__ |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #include <qiconset.h> | 24 | #include <qiconset.h> |
25 | #include <qlist.h> | 25 | #include <qlist.h> |
26 | #include <qdict.h> | 26 | #include <qdict.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | 28 | ||
29 | class AppLnkSetPrivate; | 29 | class AppLnkSetPrivate; |
30 | class AppLnkPrivate; | 30 | class AppLnkPrivate; |
31 | 31 | ||
32 | class AppLnk | 32 | class AppLnk |
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | AppLnk(); | 35 | AppLnk(); |
36 | AppLnk( const QString &file ); | 36 | AppLnk( const QString &file ); |
37 | AppLnk( const AppLnk © ); // copy constructor | 37 | AppLnk( const AppLnk © ); // copy constructor |
38 | virtual ~AppLnk(); | 38 | virtual ~AppLnk(); |
39 | 39 | ||
40 | bool isValid() const { return !mLinkFile.isNull(); } | 40 | bool isValid() const { return !mLinkFile.isNull(); } |
41 | 41 | ||
42 | static void setSmallIconSize(int); | 42 | static void setSmallIconSize(int); |
43 | static void setBigIconSize(int); | 43 | static void setBigIconSize(int); |
44 | static int smallIconSize(); | 44 | static int smallIconSize(); |
45 | static int bigIconSize(); | 45 | static int bigIconSize(); |
46 | 46 | ||
47 | QString name() const { return mName; } | 47 | QString name() const { return mName; } |
48 | const QPixmap& pixmap() const; | 48 | const QPixmap& pixmap() const; |
49 | const QPixmap& bigPixmap() const; | 49 | const QPixmap& bigPixmap() const; |
50 | virtual QString exec() const { return mExec; } | 50 | virtual QString exec() const { return mExec; } |
51 | QString type() const; | 51 | QString type() const; |
52 | QString rotation() const { return mRotation; } | 52 | QString rotation() const { return mRotation; } |
53 | QString comment() const { return mComment; } | 53 | QString comment() const { return mComment; } |
54 | QString file() const; | 54 | QString file() const; |
55 | QString linkFile() const; | 55 | QString linkFile() const; |
56 | QStringList mimeTypes() const { return mMimeTypes; } | 56 | QStringList mimeTypes() const { return mMimeTypes; } |
57 | QStringList mimeTypeIcons() const { return mMimeTypeIcons; } | 57 | QStringList mimeTypeIcons() const { return mMimeTypeIcons; } |
58 | const QArray<int> &categories() const; | 58 | const QArray<int> &categories() const; |
59 | int id() const { return mId; } | 59 | int id() const { return mId; } |
60 | 60 | ||
61 | bool linkFileKnown() const { return !mLinkFile.isNull(); } | 61 | bool linkFileKnown() const { return !mLinkFile.isNull(); } |
62 | 62 | ||
63 | void execute() const; | 63 | void execute() const; |
64 | void execute(const QStringList& args) const; | 64 | void execute(const QStringList& args) const; |
65 | void removeFiles(); | 65 | void removeFiles(); |
66 | void removeLinkFile(); | 66 | void removeLinkFile(); |
67 | 67 | ||
68 | void setName( const QString& docname ); | 68 | void setName( const QString& docname ); |
69 | void setExec( const QString& exec ); | 69 | void setExec( const QString& exec ); |
70 | void setFile( const QString& filename ); | 70 | void setFile( const QString& filename ); |
71 | void setLinkFile( const QString& filename ); | 71 | void setLinkFile( const QString& filename ); |
72 | void setComment( const QString& comment ); | 72 | void setComment( const QString& comment ); |
73 | void setType( const QString& mimetype ); | 73 | void setType( const QString& mimetype ); |
74 | void setIcon( const QString& iconname ); | 74 | void setIcon( const QString& iconname ); |
75 | void setCategories( const QArray<int> &v ); | 75 | void setCategories( const QArray<int> &v ); |
76 | bool writeLink() const; | 76 | bool writeLink() const; |
77 | 77 | ||
78 | void setProperty(const QString& key, const QString& value); | 78 | void setProperty(const QString& key, const QString& value); |
79 | QString property(const QString& key) const; | 79 | QString property(const QString& key) const; |
80 | 80 | ||
81 | //#ifdef QTOPIA_INTERNAL_PRELOADACCESS | ||
82 | bool isPreloaded() const; | ||
83 | void setPreloaded(bool yesNo); | ||
84 | //#endif | ||
85 | |||
81 | protected: | 86 | protected: |
82 | QString mName; | 87 | QString mName; |
83 | QPixmap mPixmap; | 88 | QPixmap mPixmap; |
84 | QPixmap mBigPixmap; | 89 | QPixmap mBigPixmap; |
85 | QString mExec; | 90 | QString mExec; |
86 | QString mType; | 91 | QString mType; |
87 | QString mRotation; | 92 | QString mRotation; |
88 | QString mComment; | 93 | QString mComment; |
89 | QString mFile; | 94 | QString mFile; |
90 | QString mLinkFile; | 95 | QString mLinkFile; |
91 | QString mIconFile; | 96 | QString mIconFile; |
92 | QStringList mMimeTypes; | 97 | QStringList mMimeTypes; |
93 | QStringList mMimeTypeIcons; | 98 | QStringList mMimeTypeIcons; |
94 | int mId; | 99 | int mId; |
95 | static int lastId; | 100 | static int lastId; |
96 | AppLnkPrivate *d; | 101 | AppLnkPrivate *d; |
97 | friend class AppLnkSet; | 102 | friend class AppLnkSet; |
98 | 103 | ||
99 | virtual void invoke(const QStringList& args) const; | 104 | virtual void invoke(const QStringList& args) const; |
100 | bool ensureLinkExists() const; | 105 | bool ensureLinkExists() const; |
101 | void storeLink() const; | 106 | void storeLink() const; |
102 | }; | 107 | }; |
103 | 108 | ||
104 | class DocLnk : public AppLnk | 109 | class DocLnk : public AppLnk |
105 | { | 110 | { |
106 | public: | 111 | public: |
107 | DocLnk(); | 112 | DocLnk(); |
108 | DocLnk( const DocLnk &o ) : AppLnk(o) { } | 113 | DocLnk( const DocLnk &o ) : AppLnk(o) { } |
109 | DocLnk( const QString &file ); | 114 | DocLnk( const QString &file ); |
110 | DocLnk( const QString &file, bool may_be_desktopfile ); | 115 | DocLnk( const QString &file, bool may_be_desktopfile ); |
111 | virtual ~DocLnk(); | 116 | virtual ~DocLnk(); |
112 | 117 | ||
113 | QString exec() const; | 118 | QString exec() const; |
114 | 119 | ||
115 | protected: | 120 | protected: |
116 | void invoke(const QStringList& args) const; | 121 | void invoke(const QStringList& args) const; |
117 | 122 | ||
118 | private: | 123 | private: |
119 | void init(const QString &file); | 124 | void init(const QString &file); |
120 | }; | 125 | }; |
121 | 126 | ||
122 | class AppLnkSet | 127 | class AppLnkSet |
123 | { | 128 | { |
124 | public: | 129 | public: |
125 | AppLnkSet(); | 130 | AppLnkSet(); |
126 | AppLnkSet( const QString &dir ); | 131 | AppLnkSet( const QString &dir ); |
127 | ~AppLnkSet(); | 132 | ~AppLnkSet(); |
128 | 133 | ||
129 | const AppLnk *find( int id ) const; | 134 | const AppLnk *find( int id ) const; |
130 | const AppLnk *findExec( const QString& execname ) const; | 135 | const AppLnk *findExec( const QString& execname ) const; |
131 | 136 | ||
132 | QStringList types() const { return typs; } | 137 | QStringList types() const { return typs; } |
133 | QString typeName( const QString& ) const; | 138 | QString typeName( const QString& ) const; |
134 | QPixmap typePixmap( const QString& ) const; | 139 | QPixmap typePixmap( const QString& ) const; |
135 | QPixmap typeBigPixmap( const QString& ) const; | 140 | QPixmap typeBigPixmap( const QString& ) const; |
136 | 141 | ||
137 | void add(AppLnk*); | 142 | void add(AppLnk*); |
138 | bool remove(AppLnk*); | 143 | bool remove(AppLnk*); |
139 | 144 | ||
140 | const QList<AppLnk> &children() const { return mApps; } | 145 | const QList<AppLnk> &children() const { return mApps; } |
141 | void detachChildren(); | 146 | void detachChildren(); |
142 | 147 | ||
143 | protected: | 148 | protected: |
144 | friend class AppLnk; | 149 | friend class AppLnk; |
145 | QList<AppLnk> mApps; | 150 | QList<AppLnk> mApps; |
146 | QString mFile; | 151 | QString mFile; |
147 | QStringList typs; | 152 | QStringList typs; |
148 | AppLnkSetPrivate *d; | 153 | AppLnkSetPrivate *d; |
149 | 154 | ||
150 | private: | 155 | private: |
151 | AppLnkSet( const AppLnkSet & ); // no copying! | 156 | AppLnkSet( const AppLnkSet & ); // no copying! |
152 | void findChildren(const QString &, const QString& t, const QString& lt, int depth = 0); | 157 | void findChildren(const QString &, const QString& t, const QString& lt, int depth = 0); |
153 | }; | 158 | }; |
154 | 159 | ||
155 | class DocLnkSet : public AppLnkSet | 160 | class DocLnkSet : public AppLnkSet |
156 | { | 161 | { |
157 | public: | 162 | public: |
158 | DocLnkSet(); | 163 | DocLnkSet(); |
159 | DocLnkSet( const QString &dir, const QString &mimefilter=QString::null ); | 164 | DocLnkSet( const QString &dir, const QString &mimefilter=QString::null ); |
160 | 165 | ||
161 | const QList<DocLnk> &children() const { return (const QList<DocLnk> &)mApps; } | 166 | const QList<DocLnk> &children() const { return (const QList<DocLnk> &)mApps; } |
162 | 167 | ||
163 | void appendFrom( DocLnkSet& other ); | 168 | void appendFrom( DocLnkSet& other ); |
164 | 169 | ||
165 | private: | 170 | private: |
166 | DocLnkSet( const DocLnkSet & ); // no copying! | 171 | DocLnkSet( const DocLnkSet & ); // no copying! |
167 | void findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth=0); | 172 | void findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth=0); |
168 | }; | 173 | }; |
169 | 174 | ||
170 | 175 | ||
171 | #endif // __APPLNK_H__ | 176 | #endif // __APPLNK_H__ |
172 | 177 | ||