summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-30 01:12:49 (UTC)
committer zecke <zecke>2002-03-30 01:12:49 (UTC)
commit06063167a17f44b51295cf13d5c453b61b2c2a66 (patch) (side-by-side diff)
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
@@ -20,2 +20,4 @@
+#define QTOPIA_INTERNAL_MIMEEXT
+
#include "applnk.h"
@@ -50,3 +52,3 @@ static QString safeFileName(const QString& n)
QString safename=n;
- safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
+ safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); // Njaard says this is broken
safename.replace(QRegExp("^[^A-Za-z]*"),"");
@@ -57,2 +59,12 @@ static QString safeFileName(const QString& n)
+static bool prepareDirectories(const QString& lf)
+{
+ if ( !QFile::exists(lf) ) {
+ // May need to create directories
+ QFileInfo fi(lf);
+ if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
+ return FALSE;
+ }
+ return TRUE;
+}
@@ -285,3 +297,6 @@ QString AppLnk::file() const
if ( mFile.isNull() ) {
- AppLnk* that = (AppLnk*)this;
+ AppLnk* that = (AppLnk*)this; // copy?
+ QString ext = MimeType(mType).extension();
+ if ( !ext.isEmpty() )
+ ext = "." + ext;
if ( !mLinkFile.isEmpty() ) {
@@ -293,6 +308,7 @@ QString AppLnk::file() const
QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
- if ( QFile::exists(that->mFile) || QFile::exists(that->mFile+".desktop") ) {
+ if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { // a .desktop with the same name exists
int n=1;
+ qWarning("AppLnk::file() n=1 %s", that->mFile.latin1() );
QString nn;
- while (QFile::exists((nn=(that->mFile+"_"+QString::number(n))))
+ while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
|| QFile::exists(nn+".desktop"))
@@ -300,5 +316,11 @@ QString AppLnk::file() const
that->mFile = nn;
+ qWarning("AppLnl::file() now mFile is %s", that->mFile.latin1() );
}
that->mLinkFile = that->mFile+".desktop";
+ that->mFile += ext;
}
+ prepareDirectories(that->mFile);
+ QFile f(that->mFile);
+ if ( !f.open(IO_WriteOnly) )
+ that->mFile = QString::null;
return that->mFile;
@@ -320,7 +342,3 @@ QString AppLnk::linkFile() const
const FileSystem *fs = storage.fileSystemOf( that->mFile );
-// qDebug("creating lnkFile for %s", mFile.latin1() );
-// if ( fs )
-// qDebug("fs is %s", fs->path().latin1() );
if ( fs && fs->isRemovable() ) {
-// qDebug("isRemovable");
that->mLinkFile = fs->path();
@@ -329,11 +347,21 @@ QString AppLnk::linkFile() const
that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
- if ( QFile::exists(that->mLinkFile+".desktop") ) {
+ if ( QFile::exists(that->mLinkFile+".desktop") ) { // ok the file exists lets check if we point to the same file
int n=1;
QString nn;
- while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop"))
+ AppLnk lnk( that->mLinkFile+".desktop" );
+ if(that->file() != lnk.file() ){
+ qWarning("AppLnk::linkFile exists %s", that->mLinkFile.latin1() );
+ while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")){
n++;
- that->mLinkFile = nn;
+ AppLnk lnk(nn ); // just to be sure
+ if(lnk.file() ==that->file() ){
+ break;
+ }
+ }
+ that->mLinkFile = nn;
+ }
}
that->mLinkFile += ".desktop";
-// qDebug("file is %s", mLinkFile.latin1() );
+ qWarning("AppLnk::linkFile is %s", that->mLinkFile.latin1() );
+ storeLink();
}
@@ -516,9 +544,3 @@ bool AppLnk::ensureLinkExists() const
QString lf = linkFile();
- if ( !QFile::exists(lf) ) {
- // May need to create directories
- QFileInfo fi(lf);
- if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
- return FALSE;
- }
- return TRUE;
+ return prepareDirectories(lf);
}
@@ -537,3 +559,9 @@ bool AppLnk::writeLink() const
return FALSE;
- Config config( lf, Config::File );
+ storeLink();
+ return TRUE;
+}
+
+void AppLnk::storeLink() const
+{
+ Config config( mLinkFile, Config::File );
config.setGroup("Desktop Entry");
@@ -553,5 +581,3 @@ bool AppLnk::writeLink() const
QCopEnvelope e("QPE/System", "linkChanged(QString)");
- e << lf;
-
- return TRUE;
+ e << mLinkFile;
}
@@ -588,6 +614,9 @@ void AppLnk::removeFiles()
bool valid = isValid();
- if ( !valid || QFile::remove(linkFile()) ) {
+ if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
if ( QFile::remove(file()) ) {
QCopEnvelope e("QPE/System", "linkChanged(QString)");
- e << linkFile();
+ if ( linkFileKnown() )
+ e << linkFile();
+ else
+ e << file();
} else if ( valid ) {
@@ -604,3 +633,3 @@ void AppLnk::removeLinkFile()
{
- if ( isValid() && QFile::remove(linkFile()) ) {
+ if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
QCopEnvelope e("QPE/System", "linkChanged(QString)");
@@ -1085,3 +1114,3 @@ void DocLnk::invoke(const QStringList& args) const
QStringList a = args;
- if ( QFile::exists( linkFile() ) )
+ if ( linkFileKnown() && QFile::exists( linkFile() ) )
a.append(linkFile());