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 /library/applnk.cpp | |
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 |
1 files changed, 26 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 | |||
@@ -293,132 +293,132 @@ QString AppLnk::type() const | |||
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() ) { |
@@ -545,128 +545,151 @@ bool AppLnk::ensureLinkExists() const | |||
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 | ||