void QFileInfo::doStat() const { QFileInfo *that = ((QFileInfo*)this); // mutable function if ( !that->fic ) that->fic = new QFileInfoCache; STATBUF *b = &that->fic->st; that->fic->isSymLink = FALSE; #if defined(__CYGWIN32_) int r; r = STAT( QFile::encodeName(fn), b ); if ( r != 0 ) { delete that->fic; that->fic = 0; } #else QString file = fn; reslashify(file); #ifdef QT_LARGEFILE_SUPPORT if ( _wstati64( (wchar_t*) file.ucs2(), b ) == -1 ) { #else if ( _wstat( (wchar_t*) file.ucs2(), b ) == -1 ) { #endif delete that->fic; that->fic = 0; } #endif } /*! Returns the directory path of the file. If \e absPath is TRUE an absolute path is always returned. \sa dir(), filePath(), fileName(), isRelative() */ #ifndef QT_NO_DIR QString QFileInfo::dirPath( bool absPath ) const { QString s; if ( absPath ) s = absFilePath(); else s = fn; int pos = s.findRev( '/' ); if ( pos == -1 ) { return QString::fromLatin1("."); } else { if ( pos == 0 ) return QString::fromLatin1( "/" ); return s.left( pos ); } }
void FileDef::parseSource() { static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); DevNullCodeDocInterface devNullIntf; ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension()); pIntf->resetCodeParserState(); pIntf->parseCode( devNullIntf,0, fileToString(absFilePath(),filterSourceFiles,TRUE), FALSE,0,this ); }
void MainWindow::loadLanguage(const QString& filename) { QString absFilePath(mLangPath.absoluteFilePath(filename)); if ( !QFile::exists(absFilePath) || !mTranslator.load(filename, mLangPath.canonicalPath()) ) { #if DEBUG std::cerr << "Could not load translation file '" << filename.toStdString() << "' !"; #endif } mLangFile = filename; retranslateUi(); }
QString QFileInfo::dirPath( bool absPath ) const { QString s; if ( absPath ) s = absFilePath(); else s = fn; int pos = s.findRev( '/' ); if ( pos == -1 ) { return QString::fromLatin1("."); } else { if ( pos == 0 ) return QString::fromLatin1( "/" ); return s.left( pos ); } }
bool FileDef::includes(FileDef *incFile,QDict<FileDef> *includedFiles) const { if (incFile==this) return TRUE; //printf("%s::includes(%s)\n",name().data(),incFile->name().data()); includedFiles->insert(absFilePath(),this); if (includeList) { QListIterator<IncludeInfo> ili(*includeList); IncludeInfo *ii; for (;(ii=ili.current());++ili) { if (ii->fileDef && includedFiles->find(ii->fileDef->absFilePath())==0 && ii->fileDef->includes(incFile,includedFiles)) return TRUE; } } return FALSE; }
void K3bDataUrlAddingDialog::slotAddUrls() { if( m_bCanceled ) return; // add next url KURL url = m_urlQueue.first().first; K3bDirItem* dir = m_urlQueue.first().second; m_urlQueue.remove( m_urlQueue.begin() ); // // HINT: // we only use QFileInfo::absFilePath() and QFileInfo::isHidden() // both do not cause QFileInfo to stat, thus no speed improvement // can come from removing QFileInfo usage here. // QFileInfo info(url.path()); QString absFilePath( info.absFilePath() ); QString resolved( absFilePath ); bool valid = true; k3b_struct_stat statBuf, resolvedStatBuf; bool isSymLink = false; bool isDir = false; bool isFile = false; ++m_filesHandled; #if 0 m_infoLabel->setText( url.path() ); if( m_totalFiles == 0 ) m_counterLabel->setText( QString("(%1)").arg(m_filesHandled) ); else m_counterLabel->setText( QString("(%1/%2)").arg(m_filesHandled).arg(m_totalFiles) ); #endif // // 1. Check if we want and can add the url // if( !url.isLocalFile() ) { valid = false; m_nonLocalFiles.append( url.path() ); } else if( k3b_lstat( QFile::encodeName(absFilePath), &statBuf ) != 0 ) { valid = false; m_notFoundFiles.append( url.path() ); } else if( !m_encodingConverter->encodedLocally( QFile::encodeName( url.path() ) ) ) { valid = false; m_invalidFilenameEncodingFiles.append( url.path() ); } else { isSymLink = S_ISLNK(statBuf.st_mode); isFile = S_ISREG(statBuf.st_mode); isDir = S_ISDIR(statBuf.st_mode); // symlinks are always readable and can always be added to a project // but we need to know if the symlink points to a directory if( isSymLink ) { resolved = K3b::resolveLink( absFilePath ); k3b_stat( QFile::encodeName(resolved), &resolvedStatBuf ); isDir = S_ISDIR(resolvedStatBuf.st_mode); } else { if( ::access( QFile::encodeName( absFilePath ), R_OK ) != 0 ) { valid = false; m_unreadableFiles.append( url.path() ); } else if( isFile && (unsigned long long)statBuf.st_size >= 0xFFFFFFFFULL ) { if ( !k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "no-4gb-limit" ) ) { valid = false; m_tooBigFiles.append( url.path() ); } } } // FIXME: if we do not add hidden dirs the progress gets messed up! // // check for hidden and system files // if( valid ) { if( info.isHidden() && !addHiddenFiles() ) valid = false; if( S_ISCHR(statBuf.st_mode) || S_ISBLK(statBuf.st_mode) || S_ISFIFO(statBuf.st_mode) || S_ISSOCK(statBuf.st_mode) ) if( !addSystemFiles() ) valid = false; if( isSymLink ) if( S_ISCHR(resolvedStatBuf.st_mode) || S_ISBLK(resolvedStatBuf.st_mode) || S_ISFIFO(resolvedStatBuf.st_mode) || S_ISSOCK(resolvedStatBuf.st_mode) ) if( !addSystemFiles() ) valid = false; } } // // 2. Handle the url // QString newName = url.fileName(); // filenames cannot end in backslashes (mkisofs problem. See comments in k3bisoimager.cpp (escapeGraftPoint())) bool bsAtEnd = false; while( newName[newName.length()-1] == '\\' ) { newName.truncate( newName.length()-1 ); bsAtEnd = true; } if( bsAtEnd ) m_mkisofsLimitationRenamedFiles.append( url.path() + " -> " + newName ); // backup dummy name if( newName.isEmpty() ) newName = "1"; K3bDirItem* newDirItem = 0; // // The source is valid. Now check if the project already contains a file with that name // and if so handle it properly // if( valid ) { if( K3bDataItem* oldItem = dir->find( newName ) ) { // // reuse an existing dir // if( oldItem->isDir() && isDir ) newDirItem = dynamic_cast<K3bDirItem*>(oldItem); // // we cannot replace files in the old session with dirs and vice versa (I think) // files are handled in K3bFileItem constructor and dirs handled above // else if( oldItem->isFromOldSession() && isDir != oldItem->isDir() ) { if( !getNewName( newName, dir, newName ) ) valid = false; } else if( m_bExistingItemsIgnoreAll ) valid = false; else if( oldItem->localPath() == resolved ) { // // Just ignore if the same file is added again // valid = false; } else if( m_bExistingItemsReplaceAll ) { // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; } // // Let the user choose // else { switch( K3bMultiChoiceDialog::choose( i18n("File already exists"), i18n("<p>File <em>%1</em> already exists in " "project folder <em>%2</em>.") .arg(newName) .arg('/' + dir->k3bPath()), QMessageBox::Warning, this, 0, 6, KGuiItem( i18n("Replace"), QString::null, i18n("Replace the existing file") ), KGuiItem( i18n("Replace All"), QString::null, i18n("Always replace existing files") ), KGuiItem( i18n("Ignore"), QString::null, i18n("Keep the existing file") ), KGuiItem( i18n("Ignore All"), QString::null, i18n("Always keep the existing file") ), KGuiItem( i18n("Rename"), QString::null, i18n("Rename the new file") ), KStdGuiItem::cancel() ) ) { case 2: // replace all m_bExistingItemsReplaceAll = true; // fallthrough case 1: // replace // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; break; case 4: // ignore all m_bExistingItemsIgnoreAll = true; // fallthrough case 3: // ignore valid = false; break; case 5: // rename if( !getNewName( newName, dir, newName ) ) valid = false; break; case 6: // cancel slotCancel(); return; } } } } // // One more thing to warn the user about: We cannot follow links to folders since that // would change the doc. So we simply ask the user what to do with a link to a folder // if( valid ) { // let's see if this link starts a loop // that means if it points to some folder above this one // if so we cannot follow it anyway if( isDir && isSymLink && !absFilePath.startsWith( resolved ) ) { bool followLink = dir->doc()->isoOptions().followSymbolicLinks() || m_bFolderLinksFollowAll; if( !followLink && !m_bFolderLinksAddAll ) { switch( K3bMultiChoiceDialog::choose( i18n("Adding link to folder"), i18n("<p>'%1' is a symbolic link to folder '%2'." "<p>If you intend to make K3b follow symbolic links you should consider letting K3b do this now " "since K3b will not be able to do so afterwards because symbolic links to folders inside a " "K3b project cannot be resolved." "<p><b>If you do not intend to enable the option <em>follow symbolic links</em> you may safely " "ignore this warning and choose to add the link to the project.</b>") .arg(absFilePath) .arg(resolved ), QMessageBox::Warning, this, 0, 5, i18n("Follow link now"), i18n("Always follow links"), i18n("Add link to project"), i18n("Always add links"), KStdGuiItem::cancel() ) ) { case 2: m_bFolderLinksFollowAll = true; case 1: followLink = true; break; case 4: m_bFolderLinksAddAll = true; case 3: followLink = false; break; case 5: slotCancel(); return; } } if( followLink ) { absFilePath = resolved; isSymLink = false; // count the files in the followed dir if( m_dirSizeJob->active() ) m_dirSizeQueue.append( KURL::fromPathOrURL(absFilePath) ); else { m_progressWidget->setTotalSteps( 0 ); m_dirSizeJob->setUrls( KURL::fromPathOrURL(absFilePath) ); m_dirSizeJob->start(); } } } } // // Project valid also (we overwrite or renamed) // now create the new item // if( valid ) { // // Set the volume id from the first added url // only if the doc was not changed yet // if( m_urls.count() == 1 && !dir->doc()->isModified() && !dir->doc()->isSaved() ) { dir->doc()->setVolumeID( K3b::removeFilenameExtension( newName ) ); } if( isDir && !isSymLink ) { if( !newDirItem ) { // maybe we reuse an already existing dir newDirItem = new K3bDirItem( newName , dir->doc(), dir ); newDirItem->setLocalPath( url.path() ); // HACK: see k3bdiritem.h } QDir newDir( absFilePath ); int dirFilter = QDir::All|QDir::Hidden|QDir::System; QStringList dlist = newDir.entryList( dirFilter ); const QString& dot = KGlobal::staticQString( "." ); const QString& dotdot = KGlobal::staticQString( ".." ); dlist.remove( dot ); dlist.remove( dotdot ); for( QStringList::Iterator it = dlist.begin(); it != dlist.end(); ++it ) { m_urlQueue.append( qMakePair( KURL::fromPathOrURL(absFilePath + '/' + *it), newDirItem ) ); } } else { (void)new K3bFileItem( &statBuf, &resolvedStatBuf, url.path(), dir->doc(), dir, newName ); } } if( m_urlQueue.isEmpty() ) { m_dirSizeJob->cancel(); m_progressWidget->setProgress( 100 ); accept(); } else { updateProgress(); QTimer::singleShot( 0, this, SLOT(slotAddUrls()) ); } }
/*! Write a source listing of this file to the output */ void FileDef::writeSource(OutputList &ol) { static bool generateTreeView = Config_getBool("GENERATE_TREEVIEW"); static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); static bool latexSourceCode = Config_getBool("LATEX_SOURCE_CODE"); QCString title = docname; if (!fileVersion.isEmpty()) { title+=(" ("+fileVersion+")"); } QCString pageTitle = theTranslator->trSourceFile(title); ol.disable(OutputGenerator::Man); ol.disable(OutputGenerator::RTF); if (!latexSourceCode) ol.disable(OutputGenerator::Latex); if (Config_getBool("SHOW_DIRECTORIES") && getDirDef()) { startFile(ol,getSourceFileBase(),0,pageTitle,HLI_FileVisible, !generateTreeView,getOutputFileBase()); if (!generateTreeView) { getDirDef()->writeNavigationPath(ol); ol.endQuickIndices(); } startTitle(ol,getOutputFileBase()); ol.parseText(name()); endTitle(ol,getOutputFileBase(),title); } else { startFile(ol,getSourceFileBase(),0,pageTitle,HLI_FileVisible, !generateTreeView,getOutputFileBase()); startTitle(ol,getSourceFileBase()); ol.parseText(title); endTitle(ol,getSourceFileBase(),0); } ol.startContents(); if (isLinkable()) { if (latexSourceCode) ol.disable(OutputGenerator::Latex); ol.startTextLink(getOutputFileBase(),0); ol.parseText(theTranslator->trGotoDocumentation()); ol.endTextLink(); if (latexSourceCode) ol.enable(OutputGenerator::Latex); } ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension()); pIntf->resetCodeParserState(); ol.startCodeFragment(); pIntf->parseCode(ol,0, fileToString(absFilePath(),filterSourceFiles,TRUE), FALSE,0,this ); ol.endCodeFragment(); ol.endContents(); if (generateTreeView) { writeNavigationPath(ol); endFile(ol,TRUE); } else { endFile(ol); } ol.enableAll(); }
bool QFileInfo::convertToAbs() { if ( isRelative() ) fn = absFilePath(); return QDir::isRelativePath( fn ); }