summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-30 01:12:49 (UTC)
committer zecke <zecke>2002-03-30 01:12:49 (UTC)
commit06063167a17f44b51295cf13d5c453b61b2c2a66 (patch) (unidiff)
tree19696543f70aec5f54a89bb5b31980c733eed6aa
parentbe017d10da4ccd54b2b3ce030d2ccdc3d0825d62 (diff)
downloadopie-06063167a17f44b51295cf13d5c453b61b2c2a66.zip
opie-06063167a17f44b51295cf13d5c453b61b2c2a66.tar.gz
opie-06063167a17f44b51295cf13d5c453b61b2c2a66.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp83
1 files changed, 56 insertions, 27 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 2af6cf4..5185b5f 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -18,6 +18,8 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_MIMEEXT
22
21#include "applnk.h" 23#include "applnk.h"
22 24
23#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
@@ -48,13 +50,23 @@ static int bigSize = 32;
48static QString safeFileName(const QString& n) 50static QString safeFileName(const QString& n)
49{ 51{
50 QString safename=n; 52 QString safename=n;
51 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 53 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); // Njaard says this is broken
52 safename.replace(QRegExp("^[^A-Za-z]*"),""); 54 safename.replace(QRegExp("^[^A-Za-z]*"),"");
53 if ( safename.isEmpty() ) 55 if ( safename.isEmpty() )
54 safename = "_"; 56 safename = "_";
55 return safename; 57 return safename;
56} 58}
57 59
60static bool prepareDirectories(const QString& lf)
61{
62 if ( !QFile::exists(lf) ) {
63 // May need to create directories
64 QFileInfo fi(lf);
65 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
66 return FALSE;
67 }
68 return TRUE;
69}
58 70
59class AppLnkPrivate 71class AppLnkPrivate
60{ 72{
@@ -283,7 +295,10 @@ QString AppLnk::type() const
283QString AppLnk::file() const 295QString AppLnk::file() const
284{ 296{
285 if ( mFile.isNull() ) { 297 if ( mFile.isNull() ) {
286 AppLnk* that = (AppLnk*)this; 298 AppLnk* that = (AppLnk*)this; // copy?
299 QString ext = MimeType(mType).extension();
300 if ( !ext.isEmpty() )
301 ext = "." + ext;
287 if ( !mLinkFile.isEmpty() ) { 302 if ( !mLinkFile.isEmpty() ) {
288 that->mFile = 303 that->mFile =
289 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 304 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
@@ -291,16 +306,23 @@ QString AppLnk::file() const
291 } else if ( mType.contains('/') ) { 306 } else if ( mType.contains('/') ) {
292 that->mFile = 307 that->mFile =
293 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 308 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
294 if ( QFile::exists(that->mFile) || QFile::exists(that->mFile+".desktop") ) { 309 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists
295 int n=1; 310 int n=1;
311 qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() );
296 QString nn; 312 QString nn;
297 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))) 313 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
298 || QFile::exists(nn+".desktop")) 314 || QFile::exists(nn+".desktop"))
299 n++; 315 n++;
300 that->mFile = nn; 316 that->mFile = nn;
317 qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() );
301 } 318 }
302 that->mLinkFile = that->mFile+".desktop"; 319 that->mLinkFile = that->mFile+".desktop";
320 that->mFile += ext;
303 } 321 }
322 prepareDirectories(that->mFile);
323 QFile f(that->mFile);
324 if ( !f.open(IO_WriteOnly) )
325 that->mFile = QString::null;
304 return that->mFile; 326 return that->mFile;
305 } 327 }
306 return mFile; 328 return mFile;
@@ -318,24 +340,30 @@ QString AppLnk::linkFile() const
318 if ( type().contains('/') ) { 340 if ( type().contains('/') ) {
319 StorageInfo storage; 341 StorageInfo storage;
320 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 342 const FileSystem *fs = storage.fileSystemOf( that->mFile );
321 // qDebug("creating lnkFile for %s", mFile.latin1() );
322 // if ( fs )
323 // qDebug("fs is %s", fs->path().latin1() );
324 if ( fs && fs->isRemovable() ) { 343 if ( fs && fs->isRemovable() ) {
325 // qDebug("isRemovable");
326 that->mLinkFile = fs->path(); 344 that->mLinkFile = fs->path();
327 } else 345 } else
328 that->mLinkFile = getenv( "HOME" ); 346 that->mLinkFile = getenv( "HOME" );
329 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 347 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
330 if ( QFile::exists(that->mLinkFile+".desktop") ) { 348 if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file
331 int n=1; 349 int n=1;
332 QString nn; 350 QString nn;
333 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) 351 AppLnk lnk( that->mLinkFile+".desktop" );
352 if(that->file() != lnk.file() ){
353 qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() );
354 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){
334 n++; 355 n++;
335 that->mLinkFile = nn; 356 AppLnk lnk(nn ); // just to be sure
357 if(lnk.file() ==that->file() ){
358 break;
359 }
360 }
361 that->mLinkFile = nn;
362 }
336 } 363 }
337 that->mLinkFile += ".desktop"; 364 that->mLinkFile += ".desktop";
338 // qDebug("file is %s", mLinkFile.latin1() ); 365 qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() );
366 storeLink();
339 } 367 }
340 return that->mLinkFile; 368 return that->mLinkFile;
341 } 369 }
@@ -514,13 +542,7 @@ void AppLnk::setCategories( const QArray<int>& c )
514bool AppLnk::ensureLinkExists() const 542bool AppLnk::ensureLinkExists() const
515{ 543{
516 QString lf = linkFile(); 544 QString lf = linkFile();
517 if ( !QFile::exists(lf) ) { 545 return prepareDirectories(lf);
518 // May need to create directories
519 QFileInfo fi(lf);
520 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
521 return FALSE;
522 }
523 return TRUE;
524} 546}
525 547
526/*! 548/*!
@@ -535,7 +557,13 @@ bool AppLnk::writeLink() const
535 QString lf = linkFile(); 557 QString lf = linkFile();
536 if ( !ensureLinkExists() ) 558 if ( !ensureLinkExists() )
537 return FALSE; 559 return FALSE;
538 Config config( lf, Config::File ); 560 storeLink();
561 return TRUE;
562}
563
564void AppLnk::storeLink() const
565{
566 Config config( mLinkFile, Config::File );
539 config.setGroup("Desktop Entry"); 567 config.setGroup("Desktop Entry");
540 config.writeEntry("Name",mName); 568 config.writeEntry("Name",mName);
541 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 569 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
@@ -551,9 +579,7 @@ bool AppLnk::writeLink() const
551 config.writeEntry( "Categories", sl, ';' ); 579 config.writeEntry( "Categories", sl, ';' );
552 580
553 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 581 QCopEnvelope e("QPE/System", "linkChanged(QString)");
554 e << lf; 582 e << mLinkFile;
555
556 return TRUE;
557} 583}
558 584
559/*! 585/*!
@@ -586,10 +612,13 @@ QString AppLnk::property(const QString& key) const
586void AppLnk::removeFiles() 612void AppLnk::removeFiles()
587{ 613{
588 bool valid = isValid(); 614 bool valid = isValid();
589 if ( !valid || QFile::remove(linkFile()) ) { 615 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
590 if ( QFile::remove(file()) ) { 616 if ( QFile::remove(file()) ) {
591 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 617 QCopEnvelope e("QPE/System", "linkChanged(QString)");
592 e << linkFile(); 618 if ( linkFileKnown() )
619 e << linkFile();
620 else
621 e << file();
593 } else if ( valid ) { 622 } else if ( valid ) {
594 // restore link 623 // restore link
595 writeLink(); 624 writeLink();
@@ -602,7 +631,7 @@ void AppLnk::removeFiles()
602*/ 631*/
603void AppLnk::removeLinkFile() 632void AppLnk::removeLinkFile()
604{ 633{
605 if ( isValid() && QFile::remove(linkFile()) ) { 634 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
606 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 635 QCopEnvelope e("QPE/System", "linkChanged(QString)");
607 e << linkFile(); 636 e << linkFile();
608 } 637 }
@@ -1083,7 +1112,7 @@ void DocLnk::invoke(const QStringList& args) const
1083 const AppLnk* app = mt.application(); 1112 const AppLnk* app = mt.application();
1084 if ( app ) { 1113 if ( app ) {
1085 QStringList a = args; 1114 QStringList a = args;
1086 if ( QFile::exists( linkFile() ) ) 1115 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1087 a.append(linkFile()); 1116 a.append(linkFile());
1088 else 1117 else
1089 a.append(file()); 1118 a.append(file());