summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
authorllornkcor <llornkcor>2003-05-04 13:12:11 (UTC)
committer llornkcor <llornkcor>2003-05-04 13:12:11 (UTC)
commit8409a251d52b59585889e1bcaa278a6b847db2fc (patch) (unidiff)
tree50f085a116cdb739705aa3c40ceececc99833465 /library/applnk.cpp
parent8489a583d5b762c5530076271ee3c3be7011b9ef (diff)
downloadopie-8409a251d52b59585889e1bcaa278a6b847db2fc.zip
opie-8409a251d52b59585889e1bcaa278a6b847db2fc.tar.gz
opie-8409a251d52b59585889e1bcaa278a6b847db2fc.tar.bz2
remove debug message - Cannot find icon
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp712
1 files changed, 356 insertions, 356 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 00030e8..4adf1bd 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -49,21 +49,21 @@ static int bigSize = 32;
49 49
50static QString safeFileName(const QString& n) 50static QString safeFileName(const QString& n)
51{ 51{
52 QString safename=n; 52 QString safename=n;
53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
54 safename.replace(QRegExp("^[^A-Za-z]*"),""); 54 safename.replace(QRegExp("^[^A-Za-z]*"),"");
55 if ( safename.isEmpty() ) 55 if ( safename.isEmpty() )
56 safename = "_"; 56 safename = "_";
57 return safename; 57 return safename;
58} 58}
59 59
60static bool prepareDirectories(const QString& lf) 60static bool prepareDirectories(const QString& lf)
61{ 61{
62 if ( !QFile::exists(lf) ) { 62 if ( !QFile::exists(lf) ) {
63 // May need to create directories 63 // May need to create directories
64 QFileInfo fi(lf); 64 QFileInfo fi(lf);
65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
66 return FALSE; 66 return FALSE;
67 } 67 }
68 return TRUE; 68 return TRUE;
69} 69}
@@ -87,9 +87,9 @@ public:
87 87
88 void updateCatListFromArray() 88 void updateCatListFromArray()
89 { 89 {
90 Categories cat( 0 ); 90 Categories cat( 0 );
91 cat.load( categoryFileName() ); 91 cat.load( categoryFileName() );
92 // we need to update the names for the mCat... to mCatList 92 // we need to update the names for the mCat... to mCatList
93 mCatList.clear(); 93 mCatList.clear();
94 for (uint i = 0; i < mCat.count(); i++ ) 94 for (uint i = 0; i < mCat.count(); i++ )
95 mCatList << cat.label("Document View", mCat[i] ); 95 mCatList << cat.label("Document View", mCat[i] );
@@ -98,31 +98,31 @@ public:
98 98
99 void setCatArrayDirty() 99 void setCatArrayDirty()
100 { 100 {
101 mCat.resize(0); 101 mCat.resize(0);
102 } 102 }
103 103
104 void ensureCatArray() 104 void ensureCatArray()
105 { 105 {
106 if ( mCat.count() > 0 || mCatList.count()==0 ) 106 if ( mCat.count() > 0 || mCatList.count()==0 )
107 return; 107 return;
108 108
109 Categories cat( 0 ); 109 Categories cat( 0 );
110 cat.load( categoryFileName() ); 110 cat.load( categoryFileName() );
111 mCat.resize( mCatList.count() ); 111 mCat.resize( mCatList.count() );
112 int i; 112 int i;
113 QStringList::ConstIterator it; 113 QStringList::ConstIterator it;
114 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 114 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
115 ++it, i++ ) { 115 ++it, i++ ) {
116 116
117 bool number; 117 bool number;
118 int id = (*it).toInt( &number ); 118 int id = (*it).toInt( &number );
119 if ( !number ) { 119 if ( !number ) {
120 id = cat.id( "Document View", *it ); 120 id = cat.id( "Document View", *it );
121 if ( id == 0 ) 121 if ( id == 0 )
122 id = cat.addCategory( "Document View", *it ); 122 id = cat.addCategory( "Document View", *it );
123 } 123 }
124 mCat[i] = id; 124 mCat[i] = id;
125 } 125 }
126 } 126 }
127}; 127};
128 128
@@ -186,23 +186,23 @@ public:
186 about the application: 186 about the application:
187 \table 187 \table
188 \header \i Get Function \i Set Function \i Short Description 188 \header \i Get Function \i Set Function \i Short Description
189 \row \i \l name() \i \l setName() \i application's name 189 \row \i \l name() \i \l setName() \i application's name
190 \row \i \l pixmap() \i \e none \i application's icon 190 \row \i \l pixmap() \i \e none \i application's icon
191 \row \i \l bigPixmap() \i \e none \i application's large icon 191 \row \i \l bigPixmap() \i \e none \i application's large icon
192 \row \i \e none \i setIcon() \i sets the icon's filename 192 \row \i \e none \i setIcon() \i sets the icon's filename
193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 193 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 194 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
195 \row \i \l comment() \i \l setComment() \i text for the Details dialog 195 \row \i \l comment() \i \l setComment() \i text for the Details dialog
196 \row \i \l exec() \i \l setExec() \i executable's filename 196 \row \i \l exec() \i \l setExec() \i executable's filename
197 \row \i \l file() \i \e none \i document's filename 197 \row \i \l file() \i \e none \i document's filename
198 \row \i \l linkFile() \i \l setLinkFile()\i \e .desktop filename 198 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename
199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 199 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
200 \row \i \l categories() \i \l setCategories()\i \e{see the function descriptions} 200 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions}
201 \row \i \l fileKnown() \i \e none \i see \link 201 \row \i \l fileKnown() \i \e none \i see \link
202#files-and-links Files and Links\endlink above 202#files-and-links Files and Links\endlink above
203 \row \i \l linkFileKnown() \i \e none \i see \link 203 \row \i \l linkFileKnown() \i \e none \i see \link
204#files-and-links Files and Links\endlink above 204#files-and-links Files and Links\endlink above
205 \row \i \l property() \i \l setProperty()\i any AppLnk property 205 \row \i \l property() \i \l setProperty() \i any AppLnk property
206 can be retrieved or set (if writeable) using these 206 can be retrieved or set (if writeable) using these
207 \endtable 207 \endtable
208 208
@@ -370,56 +370,56 @@ AppLnk::AppLnk( const QString &file )
370 QStringList sl; 370 QStringList sl;
371 d = new AppLnkPrivate(); 371 d = new AppLnkPrivate();
372 if ( !file.isNull() ) { 372 if ( !file.isNull() ) {
373 Config config( file, Config::File ); 373 Config config( file, Config::File );
374 374
375 if ( config.isValid() ) { 375 if ( config.isValid() ) {
376 config.setGroup( "Desktop Entry" ); 376 config.setGroup( "Desktop Entry" );
377 377
378 mName = config.readEntry( "Name", file ); 378 mName = config.readEntry( "Name", file );
379 mExec = config.readEntry( "Exec" ); 379 mExec = config.readEntry( "Exec" );
380 mType = config.readEntry( "Type", QString::null ); 380 mType = config.readEntry( "Type", QString::null );
381 mIconFile = config.readEntry( "Icon", QString::null ); 381 mIconFile = config.readEntry( "Icon", QString::null );
382 mRotation = config.readEntry( "Rotation", "" ); 382 mRotation = config.readEntry( "Rotation", "" );
383 mComment = config.readEntry( "Comment", QString::null ); 383 mComment = config.readEntry( "Comment", QString::null );
384 // MIME types are case-insensitive. 384 // MIME types are case-insensitive.
385 mMimeTypes = config.readListEntry( "MimeType", ';' ); 385 mMimeTypes = config.readListEntry( "MimeType", ';' );
386 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 386 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
387 *it = (*it).lower(); 387 *it = (*it).lower();
388 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 388 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
389 mLinkFile = file; 389 mLinkFile = file;
390 mFile = config.readEntry("File", QString::null); 390 mFile = config.readEntry("File", QString::null);
391 if ( !mExec. isEmpty ( )) { 391 if ( !mExec. isEmpty ( )) {
392 mFile = QString::null; 392 mFile = QString::null;
393 } 393 }
394 else if ( mFile[0] != '/' ) { 394 else if ( mFile[0] != '/' ) {
395 int slash = file.findRev('/'); 395 int slash = file.findRev('/');
396 if ( slash >= 0 ) { 396 if ( slash >= 0 ) {
397 mFile = file.left(slash) + '/' + mFile; 397 mFile = file.left(slash) + '/' + mFile;
398 } 398 }
399 } 399 }
400 d->mCatList = config.readListEntry("Categories", ';'); 400 d->mCatList = config.readListEntry("Categories", ';');
401 if ( d->mCatList[0].toInt() < -1 ) { 401 if ( d->mCatList[0].toInt() < -1 ) {
402 // numeric cats in file! convert to text 402 // numeric cats in file! convert to text
403 Categories cat( 0 ); 403 Categories cat( 0 );
404 cat.load( categoryFileName() ); 404 cat.load( categoryFileName() );
405 d->mCat.resize( d->mCatList.count() ); 405 d->mCat.resize( d->mCatList.count() );
406 int i; 406 int i;
407 QStringList::ConstIterator it; 407 QStringList::ConstIterator it;
408 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 408 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
409 ++it, i++ ) { 409 ++it, i++ ) {
410 bool number; 410 bool number;
411 int id = (*it).toInt( &number ); 411 int id = (*it).toInt( &number );
412 if ( !number ) { 412 if ( !number ) {
413 // convert from text 413 // convert from text
414 id = cat.id( "Document View", *it ); 414 id = cat.id( "Document View", *it );
415 if ( id == 0 ) 415 if ( id == 0 )
416 id = cat.addCategory( "Document View", *it ); 416 id = cat.addCategory( "Document View", *it );
417 } 417 }
418 d->mCat[i] = id; 418 d->mCat[i] = id;
419 } 419 }
420 d->updateCatListFromArray(); 420 d->updateCatListFromArray();
421 } 421 }
422 } 422 }
423 } 423 }
424 mId = 0; 424 mId = 0;
425} 425}
@@ -428,9 +428,9 @@ AppLnk& AppLnk::operator=(const AppLnk &copy)
428{ 428{
429 if ( this == &copy ) return *this; 429 if ( this == &copy ) return *this;
430 if ( mId ) 430 if ( mId )
431 qWarning("Deleting AppLnk that is in an AppLnkSet"); 431 qWarning("Deleting AppLnk that is in an AppLnkSet");
432 if ( d ) 432 if ( d )
433 delete d; 433 delete d;
434 434
435 435
436 mName = copy.mName; 436 mName = copy.mName;
@@ -463,27 +463,27 @@ AppLnk& AppLnk::operator=(const AppLnk &copy)
463*/ 463*/
464const QPixmap& AppLnk::pixmap( int pos, int size ) const { 464const QPixmap& AppLnk::pixmap( int pos, int size ) const {
465 if ( d->mPixmaps[pos].isNull() ) { 465 if ( d->mPixmaps[pos].isNull() ) {
466 AppLnk* that = (AppLnk*)this; 466 AppLnk* that = (AppLnk*)this;
467 if ( mIconFile.isEmpty() ) { 467 if ( mIconFile.isEmpty() ) {
468 MimeType mt(type()); 468 MimeType mt(type());
469 that->d->mPixmaps[pos] = mt.pixmap(); 469 that->d->mPixmaps[pos] = mt.pixmap();
470 if ( that->d->mPixmaps[pos].isNull() ) 470 if ( that->d->mPixmaps[pos].isNull() )
471 that->d->mPixmaps[pos].convertFromImage( 471 that->d->mPixmaps[pos].convertFromImage(
472 Resource::loadImage("UnknownDocument") 472 Resource::loadImage("UnknownDocument")
473 .smoothScale( size, size ) ); 473 .smoothScale( size, size ) );
474 return that->d->mPixmaps[pos]; 474 return that->d->mPixmaps[pos];
475 } 475 }
476 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 476 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
477 if ( unscaledIcon.isNull() ) { 477 if ( unscaledIcon.isNull() ) {
478 qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 478 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
479 that->d->mPixmaps[pos].convertFromImage( 479 that->d->mPixmaps[pos].convertFromImage(
480 Resource::loadImage("UnknownDocument") 480 Resource::loadImage("UnknownDocument")
481 .smoothScale( size, size ) ); 481 .smoothScale( size, size ) );
482 } else { 482 } else {
483 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 483 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
484 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 484 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
485 } 485 }
486 return that->d->mPixmaps[pos]; 486 return that->d->mPixmaps[pos];
487 } 487 }
488 return d->mPixmaps[pos]; 488 return d->mPixmaps[pos];
489} 489}
@@ -522,13 +522,13 @@ const QPixmap& AppLnk::bigPixmap() const
522QString AppLnk::type() const 522QString AppLnk::type() const
523{ 523{
524 if ( mType.isNull() ) { 524 if ( mType.isNull() ) {
525 AppLnk* that = (AppLnk*)this; 525 AppLnk* that = (AppLnk*)this;
526 QString f = file(); 526 QString f = file();
527 if ( !f.isNull() ) { 527 if ( !f.isNull() ) {
528 MimeType mt(f); 528 MimeType mt(f);
529 that->mType = mt.id(); 529 that->mType = mt.id();
530 return that->mType; 530 return that->mType;
531 } 531 }
532 } 532 }
533 return mType; 533 return mType;
534} 534}
@@ -541,39 +541,39 @@ QString AppLnk::type() const
541QString AppLnk::file() const 541QString AppLnk::file() const
542{ 542{
543 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 543 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
544 AppLnk* that = (AppLnk*)this; 544 AppLnk* that = (AppLnk*)this;
545 QString ext = MimeType(mType).extension(); 545 QString ext = MimeType(mType).extension();
546 if ( !ext.isEmpty() ) 546 if ( !ext.isEmpty() )
547 ext = "." + ext; 547 ext = "." + ext;
548 if ( !mLinkFile.isEmpty() ) { 548 if ( !mLinkFile.isEmpty() ) {
549 that->mFile = 549 that->mFile =
550 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 550 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
551 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 551 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
552 qDebug("mFile now == %s", mFile.latin1()); 552 qDebug("mFile now == %s", mFile.latin1());
553 } else if ( mType.contains('/') ) { 553 } else if ( mType.contains('/') ) {
554 that->mFile = 554 that->mFile =
555 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 555 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
556 /* 556 /*
557 * A file with the same name or a .desktop file already exists 557 * A file with the same name or a .desktop file already exists
558 */ 558 */
559 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 559 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
560 int n=1; 560 int n=1;
561 QString nn; 561 QString nn;
562 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 562 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
563 || QFile::exists(nn+".desktop")) 563 || QFile::exists(nn+".desktop"))
564 n++; 564 n++;
565 that->mFile = nn; 565 that->mFile = nn;
566 } 566 }
567 that->mLinkFile = that->mFile+".desktop"; 567 that->mLinkFile = that->mFile+".desktop";
568 that->mFile += ext; 568 that->mFile += ext;
569 } 569 }
570 prepareDirectories(that->mFile); 570 prepareDirectories(that->mFile);
571 if ( !that->mFile.isEmpty() ) { 571 if ( !that->mFile.isEmpty() ) {
572 QFile f(that->mFile); 572 QFile f(that->mFile);
573 if ( !f.open(IO_WriteOnly) ) 573 if ( !f.open(IO_WriteOnly) )
574 that->mFile = QString::null; 574 that->mFile = QString::null;
575 return that->mFile; 575 return that->mFile;
576 } 576 }
577 } 577 }
578 return mFile; 578 return mFile;
579} 579}
@@ -586,21 +586,21 @@ QString AppLnk::file() const
586QString AppLnk::linkFile() const 586QString AppLnk::linkFile() const
587{ 587{
588 if ( mLinkFile.isNull() ) { 588 if ( mLinkFile.isNull() ) {
589 AppLnk* that = (AppLnk*)this; 589 AppLnk* that = (AppLnk*)this;
590 if ( type().contains('/') ) { 590 if ( type().contains('/') ) {
591 StorageInfo storage; 591 StorageInfo storage;
592 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 592 const FileSystem *fs = storage.fileSystemOf( that->mFile );
593 /* tmpfs + and ramfs are available too but not removable 593 /* tmpfs + and ramfs are available too but not removable
594 * either we fix storage or add this 594 * either we fix storage or add this
595 */ 595 */
596 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 596 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
597 that->mLinkFile = fs->path(); 597 that->mLinkFile = fs->path();
598 } else 598 } else
599 that->mLinkFile = getenv( "HOME" ); 599 that->mLinkFile = getenv( "HOME" );
600 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 600 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
601 601
602 /* the desktop file exists make sure we don't point to the same file */ 602 /* the desktop file exists make sure we don't point to the same file */
603 if ( QFile::exists(that->mLinkFile+".desktop") ) { 603 if ( QFile::exists(that->mLinkFile+".desktop") ) {
604 AppLnk lnk( that->mLinkFile + ".desktop" ); 604 AppLnk lnk( that->mLinkFile + ".desktop" );
605 605
606 /* the linked is different */ 606 /* the linked is different */
@@ -616,11 +616,11 @@ QString AppLnk::linkFile() const
616 } 616 }
617 that->mLinkFile = nn; 617 that->mLinkFile = nn;
618 } 618 }
619 } 619 }
620 that->mLinkFile += ".desktop"; 620 that->mLinkFile += ".desktop";
621 storeLink(); 621 storeLink();
622 } 622 }
623 return that->mLinkFile; 623 return that->mLinkFile;
624 } 624 }
625 return mLinkFile; 625 return mLinkFile;
626} 626}
@@ -658,9 +658,9 @@ AppLnk::AppLnk( const AppLnk &copy )
658AppLnk::~AppLnk() 658AppLnk::~AppLnk()
659{ 659{
660 if ( mId ) 660 if ( mId )
661 qWarning("Deleting AppLnk that is in an AppLnkSet"); 661 qWarning("Deleting AppLnk that is in an AppLnkSet");
662 if ( d ) 662 if ( d )
663 delete d; 663 delete d;
664} 664}
665 665
666/*! 666/*!
@@ -684,16 +684,16 @@ void AppLnk::execute(const QStringList& args) const
684{ 684{
685#ifdef Q_WS_QWS 685#ifdef Q_WS_QWS
686 if ( !mRotation.isEmpty() ) { 686 if ( !mRotation.isEmpty() ) {
687 // ######## this will only work in the server 687 // ######## this will only work in the server
688 int rot = QPEApplication::defaultRotation(); 688 int rot = QPEApplication::defaultRotation();
689 rot = (rot+mRotation.toInt())%360; 689 rot = (rot+mRotation.toInt())%360;
690 QCString old = getenv("QWS_DISPLAY"); 690 QCString old = getenv("QWS_DISPLAY");
691 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 691 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
692 invoke(args); 692 invoke(args);
693 setenv("QWS_DISPLAY", old.data(), 1); 693 setenv("QWS_DISPLAY", old.data(), 1);
694 } else 694 } else
695#endif 695#endif
696 invoke(args); 696 invoke(args);
697} 697}
698 698
699/*! 699/*!
@@ -726,7 +726,7 @@ void AppLnk::setExec( const QString& exec )
726*/ 726*/
727void AppLnk::setRotation ( const QString &rot ) 727void AppLnk::setRotation ( const QString &rot )
728{ 728{
729 mRotation = rot; 729 mRotation = rot;
730} 730}
731#endif 731#endif
732 732
@@ -853,7 +853,7 @@ bool AppLnk::writeLink() const
853 // Only re-writes settable parts 853 // Only re-writes settable parts
854 QString lf = linkFile(); 854 QString lf = linkFile();
855 if ( !ensureLinkExists() ) 855 if ( !ensureLinkExists() )
856 return FALSE; 856 return FALSE;
857 storeLink(); 857 storeLink();
858 return TRUE; 858 return TRUE;
859} 859}
@@ -869,19 +869,19 @@ void AppLnk::storeLink() const
869 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 869 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
870 config.writeEntry("Type",type()); 870 config.writeEntry("Type",type());
871 if(!rotation().isEmpty()) 871 if(!rotation().isEmpty())
872 config.writeEntry("Rotation",rotation()); 872 config.writeEntry("Rotation",rotation());
873 else 873 else
874 config.removeEntry("Rotation"); 874 config.removeEntry("Rotation");
875 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 875 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
876 QString f = file(); 876 QString f = file();
877 int i = 0; 877 int i = 0;
878 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 878 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
879 i++; 879 i++;
880 while ( i && f[i] != '/' ) 880 while ( i && f[i] != '/' )
881 i--; 881 i--;
882 // simple case where in the same directory 882 // simple case where in the same directory
883 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 883 if ( mLinkFile.find( '/', i + 1 ) < 0 )
884 f = f.mid(i+1); 884 f = f.mid(i+1);
885 // ### could do relative ie ../../otherDocs/file.doc 885 // ### could do relative ie ../../otherDocs/file.doc
886 config.writeEntry("File",f); 886 config.writeEntry("File",f);
887 config.writeEntry( "Categories", d->mCatList, ';' ); 887 config.writeEntry( "Categories", d->mCatList, ';' );
@@ -900,8 +900,8 @@ void AppLnk::storeLink() const
900void AppLnk::setProperty(const QString& key, const QString& value) 900void AppLnk::setProperty(const QString& key, const QString& value)
901{ 901{
902 if ( ensureLinkExists() ) { 902 if ( ensureLinkExists() ) {
903 Config cfg(linkFile(), Config::File); 903 Config cfg(linkFile(), Config::File);
904 cfg.writeEntry(key,value); 904 cfg.writeEntry(key,value);
905 } 905 }
906} 906}
907 907
@@ -914,7 +914,7 @@ QString AppLnk::property(const QString& key) const
914{ 914{
915 QString lf = linkFile(); 915 QString lf = linkFile();
916 if ( !QFile::exists(lf) ) 916 if ( !QFile::exists(lf) )
917 return QString::null; 917 return QString::null;
918 Config cfg(lf, Config::File); 918 Config cfg(lf, Config::File);
919 return cfg.readEntry(key); 919 return cfg.readEntry(key);
920} 920}
@@ -951,18 +951,18 @@ void AppLnk::removeFiles()
951{ 951{
952 bool valid = isValid(); 952 bool valid = isValid();
953 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 953 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
954 if ( QFile::remove(file()) ) { 954 if ( QFile::remove(file()) ) {
955#ifndef QT_NO_COP 955#ifndef QT_NO_COP
956 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 956 QCopEnvelope e("QPE/System", "linkChanged(QString)");
957 if ( linkFileKnown() ) 957 if ( linkFileKnown() )
958 e << linkFile(); 958 e << linkFile();
959 else 959 else
960 e << file(); 960 e << file();
961#endif 961#endif
962 } else if ( valid ) { 962 } else if ( valid ) {
963 // restore link 963 // restore link
964 writeLink(); 964 writeLink();
965 } 965 }
966 } 966 }
967} 967}
968 968
@@ -975,8 +975,8 @@ void AppLnk::removeLinkFile()
975{ 975{
976 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 976 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
977#ifndef QT_NO_COP 977#ifndef QT_NO_COP
978 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 978 QCopEnvelope e("QPE/System", "linkChanged(QString)");
979 e << linkFile(); 979 e << linkFile();
980#endif 980#endif
981 } 981 }
982} 982}
@@ -985,9 +985,9 @@ class AppLnkSetPrivate {
985public: 985public:
986 AppLnkSetPrivate() 986 AppLnkSetPrivate()
987 { 987 {
988 typPix.setAutoDelete(TRUE); 988 typPix.setAutoDelete(TRUE);
989 typPixBig.setAutoDelete(TRUE); 989 typPixBig.setAutoDelete(TRUE);
990 typName.setAutoDelete(TRUE); 990 typName.setAutoDelete(TRUE);
991 } 991 }
992 992
993 QDict<QPixmap> typPix; 993 QDict<QPixmap> typPix;
@@ -1052,9 +1052,9 @@ void AppLnkSet::detachChildren()
1052{ 1052{
1053 QListIterator<AppLnk> it( mApps ); 1053 QListIterator<AppLnk> it( mApps );
1054 for ( ; it.current(); ) { 1054 for ( ; it.current(); ) {
1055 AppLnk* a = *it; 1055 AppLnk* a = *it;
1056 ++it; 1056 ++it;
1057 a->mId = 0; 1057 a->mId = 0;
1058 } 1058 }
1059 mApps.clear(); 1059 mApps.clear();
1060} 1060}
@@ -1068,10 +1068,10 @@ AppLnkSet::~AppLnkSet()
1068{ 1068{
1069 QListIterator<AppLnk> it( mApps ); 1069 QListIterator<AppLnk> it( mApps );
1070 for ( ; it.current(); ) { 1070 for ( ; it.current(); ) {
1071 AppLnk* a = *it; 1071 AppLnk* a = *it;
1072 ++it; 1072 ++it;
1073 a->mId = 0; 1073 a->mId = 0;
1074 delete a; 1074 delete a;
1075 } 1075 }
1076 delete d; 1076 delete d;
1077} 1077}
@@ -1080,60 +1080,61 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin
1080{ 1080{
1081 depth++; 1081 depth++;
1082 if ( depth > 10 ) 1082 if ( depth > 10 )
1083 return; 1083 return;
1084 1084
1085 QDir dir( dr ); 1085 QDir dir( dr );
1086 QString typNameLocal = typName; 1086 QString typNameLocal = typName;
1087 1087
1088 if ( dir.exists( ".directory" ) ) { 1088 if ( dir.exists( ".directory" ) ) {
1089 Config config( dr + "/.directory", Config::File ); 1089 Config config( dr + "/.directory", Config::File );
1090 config.setGroup( "Desktop Entry" ); 1090 config.setGroup( "Desktop Entry" );
1091 typNameLocal = config.readEntry( "Name", typNameLocal ); 1091 typNameLocal = config.readEntry( "Name", typNameLocal );
1092 if ( !typ.isEmpty() ) { 1092 if ( !typ.isEmpty() ) {
1093 QString iconFile = config.readEntry( "Icon", "AppsIcon" ); 1093 QString iconFile = config.readEntry( "Icon", "AppsIcon" );
1094 QImage unscaledIcon = Resource::loadImage( iconFile ); 1094 QImage unscaledIcon = Resource::loadImage( iconFile );
1095 QPixmap pm, bpm; 1095 QPixmap pm, bpm;
1096 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 1096 pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
1097 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 1097 bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
1098 d->typPix.insert(typ, new QPixmap(pm)); 1098 d->typPix.insert(typ, new QPixmap(pm));
1099 d->typPixBig.insert(typ, new QPixmap(bpm)); 1099 d->typPixBig.insert(typ, new QPixmap(bpm));
1100 d->typName.insert(typ, new QString(typNameLocal)); 1100 d->typName.insert(typ, new QString(typNameLocal));
1101 } 1101 }
1102 } 1102 }
1103 1103
1104 const QFileInfoList *list = dir.entryInfoList(); 1104 const QFileInfoList *list = dir.entryInfoList();
1105 if ( list ) { 1105 if ( list ) {
1106 QFileInfo* fi; 1106 QFileInfo* fi;
1107 bool cadded=FALSE; 1107 bool cadded=FALSE;
1108 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1108 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1109 QString bn = fi->fileName(); 1109 QString bn = fi->fileName();
1110 if ( bn[0] != '.' && bn != "CVS" ) { 1110// qDebug("findChildren "+bn);
1111 if ( fi->isDir() ) { 1111 if ( bn[0] != '.' && bn != "CVS" ) {
1112 QString c = typ.isNull() ? bn : typ+"/"+bn; 1112 if ( fi->isDir() ) {
1113 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; 1113 QString c = typ.isNull() ? bn : typ+"/"+bn;
1114 findChildren(fi->filePath(), c, d, depth ); 1114 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
1115 } else { 1115 findChildren(fi->filePath(), c, d, depth );
1116 if ( fi->extension(FALSE) == "desktop" ) { 1116 } else {
1117 AppLnk* app = new AppLnk( fi->filePath() ); 1117 if ( fi->extension(FALSE) == "desktop" ) {
1118 AppLnk* app = new AppLnk( fi->filePath() );
1118#ifdef QT_NO_QWS_MULTIPROCESS 1119#ifdef QT_NO_QWS_MULTIPROCESS
1119 if ( !Global::isBuiltinCommand( app->exec() ) ) 1120 if ( !Global::isBuiltinCommand( app->exec() ) )
1120 delete app; 1121 delete app;
1121 else 1122 else
1122#endif 1123#endif
1123 { 1124 {
1124 if ( !typ.isEmpty() ) { 1125 if ( !typ.isEmpty() ) {
1125 if ( !cadded ) { 1126 if ( !cadded ) {
1126 typs.append(typ); 1127 typs.append(typ);
1127 cadded = TRUE; 1128 cadded = TRUE;
1128 } 1129 }
1129 app->setType(typ); 1130 app->setType(typ);
1130 } 1131 }
1131 add(app); 1132 add(app);
1132 } 1133 }
1133 } 1134 }
1134 } 1135 }
1135 } 1136 }
1136 } 1137 }
1137 } 1138 }
1138} 1139}
1139 1140
@@ -1146,11 +1147,11 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin
1146void AppLnkSet::add( AppLnk *f ) 1147void AppLnkSet::add( AppLnk *f )
1147{ 1148{
1148 if ( f->mId == 0 ) { 1149 if ( f->mId == 0 ) {
1149 AppLnk::lastId++; 1150 AppLnk::lastId++;
1150 f->mId = AppLnk::lastId; 1151 f->mId = AppLnk::lastId;
1151 mApps.append( f ); 1152 mApps.append( f );
1152 } else { 1153 } else {
1153 qWarning("Attempt to add an AppLnk twice"); 1154 qWarning("Attempt to add an AppLnk twice");
1154 } 1155 }
1155} 1156}
1156 1157
@@ -1164,8 +1165,8 @@ void AppLnkSet::add( AppLnk *f )
1164bool AppLnkSet::remove( AppLnk *f ) 1165bool AppLnkSet::remove( AppLnk *f )
1165{ 1166{
1166 if ( mApps.remove( f ) ) { 1167 if ( mApps.remove( f ) ) {
1167 f->mId = 0; 1168 f->mId = 0;
1168 return TRUE; 1169 return TRUE;
1169 } 1170 }
1170 return FALSE; 1171 return FALSE;
1171} 1172}
@@ -1215,9 +1216,9 @@ const AppLnk *AppLnkSet::find( int id ) const
1215 QListIterator<AppLnk> it( children() ); 1216 QListIterator<AppLnk> it( children() );
1216 1217
1217 for ( ; it.current(); ++it ) { 1218 for ( ; it.current(); ++it ) {
1218 const AppLnk *app = it.current(); 1219 const AppLnk *app = it.current();
1219 if ( app->id() == id ) 1220 if ( app->id() == id )
1220 return app; 1221 return app;
1221 } 1222 }
1222 1223
1223 return 0; 1224 return 0;
@@ -1231,9 +1232,9 @@ const AppLnk *AppLnkSet::findExec( const QString& exec ) const
1231 QListIterator<AppLnk> it( children() ); 1232 QListIterator<AppLnk> it( children() );
1232 1233
1233 for ( ; it.current(); ++it ) { 1234 for ( ; it.current(); ++it ) {
1234 const AppLnk *app = it.current(); 1235 const AppLnk *app = it.current();
1235 if ( app->exec() == exec ) 1236 if ( app->exec() == exec )
1236 return app; 1237 return app;
1237 } 1238 }
1238 1239
1239 return 0; 1240 return 0;
@@ -1281,35 +1282,34 @@ DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
1281 QStringList subFilter = QStringList::split(";", mimefilter); 1282 QStringList subFilter = QStringList::split(";", mimefilter);
1282 QValueList<QRegExp> mimeFilters; 1283 QValueList<QRegExp> mimeFilters;
1283 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) 1284 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
1284 mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 1285 mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
1285 1286
1286 findChildren(directory, mimeFilters, reference); 1287 findChildren(directory, mimeFilters, reference);
1287 1288
1288 const QList<DocLnk> &list = children(); 1289 const QList<DocLnk> &list = children();
1289 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 1290 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
1290 reference.remove( (*it)->file() ); 1291 reference.remove( (*it)->file() );
1291 } 1292 }
1292
1293 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { 1293 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
1294 if ( dit.current() == (void*)2 ) { 1294 if ( dit.current() == (void*)2 ) {
1295 // Unreferenced, make an unwritten link 1295 // Unreferenced, make an unwritten link
1296 DocLnk* dl = new DocLnk; 1296 DocLnk* dl = new DocLnk;
1297 QFileInfo fi( dit.currentKey() ); 1297 QFileInfo fi( dit.currentKey() );
1298 dl->setFile(fi.filePath()); 1298 dl->setFile(fi.filePath());
1299 dl->setName(fi.baseName()); 1299 dl->setName(fi.baseName());
1300 // #### default to current path? 1300 // #### default to current path?
1301 // dl->setCategories( ... ); 1301 // dl->setCategories( ... );
1302 bool match = mimefilter.isNull(); 1302 bool match = mimefilter.isNull();
1303 if ( !match ) 1303 if ( !match )
1304 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) 1304 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
1305 if ( (*it).match(dl->type()) >= 0 ) 1305 if ( (*it).match(dl->type()) >= 0 )
1306 match = TRUE; 1306 match = TRUE;
1307 if ( match /* && dl->type() != "application/octet-stream" */ 1307 if ( match /* && dl->type() != "application/octet-stream" */
1308 && !!dl->exec() ) 1308 && !!dl->exec() )
1309 add(dl); 1309 add(dl);
1310 else 1310 else
1311 delete dl; 1311 delete dl;
1312 } 1312 }
1313 } 1313 }
1314} 1314}
1315 1315
@@ -1321,11 +1321,11 @@ DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
1321void DocLnkSet::appendFrom( DocLnkSet& other ) 1321void DocLnkSet::appendFrom( DocLnkSet& other )
1322{ 1322{
1323 if ( &other == this ) 1323 if ( &other == this )
1324 return; 1324 return;
1325 QListIterator<AppLnk> it( other.mApps ); 1325 QListIterator<AppLnk> it( other.mApps );
1326 for ( ; it.current(); ) { 1326 for ( ; it.current(); ) {
1327 mApps.append(*it); 1327 mApps.append(*it);
1328 ++it; 1328 ++it;
1329 } 1329 }
1330 other.mApps.clear(); 1330 other.mApps.clear();
1331} 1331}
@@ -1334,7 +1334,7 @@ void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeF
1334{ 1334{
1335 depth++; 1335 depth++;
1336 if ( depth > 10 ) 1336 if ( depth > 10 )
1337 return; 1337 return;
1338 1338
1339 QDir dir( dr ); 1339 QDir dir( dr );
1340 1340
@@ -1343,45 +1343,45 @@ void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeF
1343 * in this case to be discussed 1343 * in this case to be discussed
1344 */ 1344 */
1345 if ( dir.exists( ".Qtopia-ignore" ) ) 1345 if ( dir.exists( ".Qtopia-ignore" ) )
1346 return; 1346 return;
1347 1347
1348 const QFileInfoList *list = dir.entryInfoList(); 1348 const QFileInfoList *list = dir.entryInfoList();
1349 if ( list ) { 1349 if ( list ) {
1350 QFileInfo* fi; 1350 QFileInfo* fi;
1351 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1351 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1352 QString bn = fi->fileName(); 1352 QString bn = fi->fileName();
1353 if ( bn[0] != '.' ) { 1353 if ( bn[0] != '.' ) {
1354 if ( fi->isDir() ) { 1354 if ( fi->isDir() ) {
1355 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) 1355 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
1356 findChildren(fi->filePath(), mimeFilters, reference, depth); 1356 findChildren(fi->filePath(), mimeFilters, reference, depth);
1357 } else { 1357 } else {
1358 if ( fi->extension(FALSE) == "desktop" ) { 1358 if ( fi->extension(FALSE) == "desktop" ) {
1359 DocLnk* dl = new DocLnk( fi->filePath() ); 1359 DocLnk* dl = new DocLnk( fi->filePath() );
1360 QFileInfo fi2(dl->file()); 1360 QFileInfo fi2(dl->file());
1361 bool match = FALSE; 1361 bool match = FALSE;
1362 if ( !fi2.exists() ) { 1362 if ( !fi2.exists() ) {
1363 dir.remove( dl->file() ); 1363 dir.remove( dl->file() );
1364 } 1364 }
1365 if ( mimeFilters.count() == 0 ) { 1365 if ( mimeFilters.count() == 0 ) {
1366 add( dl ); 1366 add( dl );
1367 match = TRUE; 1367 match = TRUE;
1368 } else { 1368 } else {
1369 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { 1369 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
1370 if ( (*it).match(dl->type()) >= 0 ) { 1370 if ( (*it).match(dl->type()) >= 0 ) {
1371 add(dl); 1371 add(dl);
1372 match = TRUE; 1372 match = TRUE;
1373 } 1373 }
1374 } 1374 }
1375 } 1375 }
1376 if ( !match ) 1376 if ( !match )
1377 delete dl; 1377 delete dl;
1378 } else { 1378 } else {
1379 if ( !reference.find(fi->fileName()) ) 1379 if ( !reference.find(fi->fileName()) )
1380 reference.insert(fi->filePath(), (void*)2); 1380 reference.insert(fi->filePath(), (void*)2);
1381 } 1381 }
1382 } 1382 }
1383 } 1383 }
1384 } 1384 }
1385 } 1385 }
1386} 1386}
1387 1387
@@ -1422,31 +1422,31 @@ void DocLnk::init(const QString &file)
1422{ 1422{
1423 if ( isValid() ) { 1423 if ( isValid() ) {
1424#ifndef FORCED_DIR_STRUCTURE_WAY 1424#ifndef FORCED_DIR_STRUCTURE_WAY
1425 if ( mType.isNull() ) 1425 if ( mType.isNull() )
1426 // try to infer it 1426 // try to infer it
1427#endif 1427#endif
1428 { 1428 {
1429 int s0 = file.findRev('/'); 1429 int s0 = file.findRev('/');
1430 if ( s0 > 0 ) { 1430 if ( s0 > 0 ) {
1431 int s1 = file.findRev('/',s0-1); 1431 int s1 = file.findRev('/',s0-1);
1432 if ( s1 > 0 ) { 1432 if ( s1 > 0 ) {
1433 int s2 = file.findRev('/',s1-1); 1433 int s2 = file.findRev('/',s1-1);
1434 if ( s2 > 0 ) { 1434 if ( s2 > 0 ) {
1435 mType = file.mid(s2+1,s0-s2-1); 1435 mType = file.mid(s2+1,s0-s2-1);
1436 } 1436 }
1437 } 1437 }
1438 } 1438 }
1439 } 1439 }
1440 } else if ( QFile::exists(file) ) { 1440 } else if ( QFile::exists(file) ) {
1441 QString n = file; 1441 QString n = file;
1442 n.replace(QRegExp(".*/"),""); 1442 n.replace(QRegExp(".*/"),"");
1443 n.replace(QRegExp("\\..*"),""); 1443 n.replace(QRegExp("\\..*"),"");
1444 setName( n ); 1444 setName( n );
1445 setFile( file ); 1445 setFile( file );
1446 } 1446 }
1447 MimeType mt(mType); 1447 MimeType mt(mType);
1448 if( mt.application() ) 1448 if( mt.application() )
1449 mExec = mt.application()->exec(); 1449 mExec = mt.application()->exec();
1450} 1450}
1451 1451
1452/*! 1452/*!
@@ -1472,9 +1472,9 @@ QString DocLnk::exec() const
1472 MimeType mt(type()); 1472 MimeType mt(type());
1473 const AppLnk* app = mt.application(); 1473 const AppLnk* app = mt.application();
1474 if ( app ) 1474 if ( app )
1475 return app->exec(); 1475 return app->exec();
1476 else 1476 else
1477 return QString::null; 1477 return QString::null;
1478} 1478}
1479 1479
1480/*! 1480/*!
@@ -1485,12 +1485,12 @@ void DocLnk::invoke(const QStringList& args) const
1485 MimeType mt(type()); 1485 MimeType mt(type());
1486 const AppLnk* app = mt.application(); 1486 const AppLnk* app = mt.application();
1487 if ( app ) { 1487 if ( app ) {
1488 QStringList a = args; 1488 QStringList a = args;
1489 if ( linkFileKnown() && QFile::exists( linkFile() ) ) 1489 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1490 a.append(linkFile()); 1490 a.append(linkFile());
1491 else 1491 else
1492 a.append(file()); 1492 a.append(file());
1493 app->execute(a); 1493 app->execute(a);
1494 } 1494 }
1495} 1495}
1496 1496