author | zecke <zecke> | 2002-03-30 01:12:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-30 01:12:49 (UTC) |
commit | 06063167a17f44b51295cf13d5c453b61b2c2a66 (patch) (unidiff) | |
tree | 19696543f70aec5f54a89bb5b31980c733eed6aa | |
parent | be017d10da4ccd54b2b3ce030d2ccdc3d0825d62 (diff) | |
download | opie-06063167a17f44b51295cf13d5c453b61b2c2a66.zip opie-06063167a17f44b51295cf13d5c453b61b2c2a66.tar.gz opie-06063167a17f44b51295cf13d5c453b61b2c2a66.tar.bz2 |
*** empty log message ***
-rw-r--r-- | library/applnk.cpp | 83 |
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 | |||
@@ -19,4 +19,6 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | ||
22 | |||
21 | #include "applnk.h" | 23 | #include "applnk.h" |
22 | 24 | ||
@@ -49,5 +51,5 @@ static 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() ) |
@@ -56,4 +58,14 @@ static QString safeFileName(const QString& n) | |||
56 | } | 58 | } |
57 | 59 | ||
60 | static 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 | ||
59 | class AppLnkPrivate | 71 | class AppLnkPrivate |
@@ -284,5 +296,8 @@ QString 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 = |
@@ -292,14 +307,21 @@ QString AppLnk::file() const | |||
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 | } |
@@ -319,22 +341,28 @@ QString AppLnk::linkFile() const | |||
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; |
@@ -515,11 +543,5 @@ bool 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 | ||
@@ -536,5 +558,11 @@ bool AppLnk::writeLink() const | |||
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 | |||
564 | void 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); |
@@ -552,7 +580,5 @@ bool AppLnk::writeLink() const | |||
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 | ||
@@ -587,8 +613,11 @@ void 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 |
@@ -603,5 +632,5 @@ void AppLnk::removeFiles() | |||
603 | void AppLnk::removeLinkFile() | 632 | void 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(); |
@@ -1084,5 +1113,5 @@ void DocLnk::invoke(const QStringList& args) const | |||
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 |