/*! Returns the desktop file corresponding to this AppLnk. \sa file() exec() name() */ QString AppLnk::linkFile() const { if ( mLinkFile.isNull() ) { AppLnk* that = (AppLnk*)this; if ( type().contains('/') ) { StorageInfo storage; const FileSystem *fs = storage.fileSystemOf( that->mFile ); /* tmpfs + and ramfs are available too but not removable * either we fix storage or add this */ if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { that->mLinkFile = fs->path(); } else that->mLinkFile = getenv( "HOME" ); that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); /* the desktop file exists make sure we don't point to the same file */ if ( QFile::exists(that->mLinkFile+".desktop") ) { AppLnk lnk( that->mLinkFile + ".desktop" ); /* the linked is different */ if(that->file() != lnk.file() ) { int n = 1; QString nn; while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { n++; /* just to be sure */ AppLnk lnk(nn ); if (lnk.file() == that->file() ) break; } that->mLinkFile = nn; } } that->mLinkFile += ".desktop"; storeLink(); } return that->mLinkFile; } return mLinkFile; }
/*! Returns the file associated with the AppLnk. \sa exec() name() */ QString AppLnk::file() const { if ( mExec.isEmpty ( ) && mFile.isNull() ) { AppLnk* that = (AppLnk*)this; QString ext = MimeType(mType).extension(); if ( !ext.isEmpty() ) ext = "." + ext; if ( !mLinkFile.isEmpty() ) { that->mFile = mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; qDebug("mFile now == %s", mFile.latin1()); } else if ( mType.contains('/') ) { that->mFile = QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); /* * A file with the same name or a .desktop file already exists */ if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { int n=1; QString nn; while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) || QFile::exists(nn+".desktop")) n++; that->mFile = nn; } that->mLinkFile = that->mFile+".desktop"; that->mFile += ext; } prepareDirectories(that->mFile); if ( !that->mFile.isEmpty() ) { QFile f(that->mFile); if ( !f.open(IO_WriteOnly) ) that->mFile = QString::null; return that->mFile; } } return mFile; }
/// removes previous state machine mapping to file and adds new one /// \param stateMachine - pointer to state machine to map /// \param fileName - current file name for state machine /// \param oldFileName - old mapping file name. This value may be NULL void CQHStateMachineManager::MapStateMachineToFileName( IObject *stateMachine, IHashString *fileName, IHashString *oldFileName ) { if( oldFileName != NULL && !oldFileName->IsEmpty() && oldFileName->GetString() != NULL ) { StdString oldFile = oldFileName->GetString(); oldFile.MakeSafeFileName(); CHashString safeOldFileName( oldFile ); m_StateMachineToFileName.erase( stateMachine->GetName()->GetUniqueID() ); m_FilenameToStateMachine.erase( safeOldFileName.GetUniqueID() ); } StdString file = fileName->GetString(); file.MakeSafeFileName(); CHashString safeFileName( file ); // Map file unique IDs to corresponding state machines and vice versa // TODO: There seems to be a problem calling GetUniqueID() from the hash string returned from CQHStateMachine::GetFileName m_StateMachineToFileName[stateMachine->GetName()->GetUniqueID()] = safeFileName.GetUniqueID(); m_FilenameToStateMachine[safeFileName.GetUniqueID()] = stateMachine; }