void tdeio_isoProtocol::stat( const KURL & url ) { TQString path; UDSEntry entry; kdDebug() << "tdeio_isoProtocol::stat " << url.url() << endl; if ( !checkNewFile( url.path(), path, url.hasRef() ? url.htmlRef().toInt() : -1 ) ) { // We may be looking at a real directory - this happens // when pressing up after being in the root of an archive TQCString _path( TQFile::encodeName(url.path())); kdDebug() << "tdeio_isoProtocol::stat (stat) on " << _path << endl; struct stat buff; if ( ::stat( _path.data(), &buff ) == -1 || !S_ISDIR( buff.st_mode ) ) { kdDebug() << "isdir=" << S_ISDIR( buff.st_mode ) << " errno=" << strerror(errno) << endl; error( TDEIO::ERR_DOES_NOT_EXIST, url.path() ); return; } // Real directory. Return just enough information for KRun to work UDSAtom atom; atom.m_uds = TDEIO::UDS_NAME; atom.m_str = url.fileName(); entry.append( atom ); kdDebug() << "tdeio_isoProtocol::stat returning name=" << url.fileName() << endl; atom.m_uds = TDEIO::UDS_FILE_TYPE; atom.m_long = buff.st_mode & S_IFMT; entry.append( atom ); statEntry( entry ); finished(); // And let go of the iso file - for people who want to unmount a cdrom after that delete m_isoFile; m_isoFile = 0L; return; } const KArchiveDirectory* root = m_isoFile->directory(); const KArchiveEntry* isoEntry; if ( path.isEmpty() ) { path = TQString::fromLatin1( "/" ); isoEntry = root; } else { isoEntry = root->entry( path ); } if ( !isoEntry ) { error( TDEIO::ERR_DOES_NOT_EXIST, path ); return; } createUDSEntry( isoEntry, entry ); statEntry( entry ); finished(); }
void tdeio_isoProtocol::listDir( const KURL & url ) { kdDebug() << "tdeio_isoProtocol::listDir " << url.url() << endl; TQString path; if ( !checkNewFile( url.path(), path, url.hasRef() ? url.htmlRef().toInt() : -1 ) ) { TQCString _path( TQFile::encodeName(url.path())); kdDebug() << "Checking (stat) on " << _path << endl; struct stat buff; if ( ::stat( _path.data(), &buff ) == -1 || !S_ISDIR( buff.st_mode ) ) { error( TDEIO::ERR_DOES_NOT_EXIST, url.path() ); return; } // It's a real dir -> redirect KURL redir; redir.setPath( url.path() ); if (url.hasRef()) redir.setRef(url.htmlRef()); kdDebug() << "Ok, redirection to " << redir.url() << endl; redirection( redir ); finished(); // And let go of the iso file - for people who want to unmount a cdrom after that delete m_isoFile; m_isoFile = 0L; return; } if ( path.isEmpty() ) { KURL redir( TQString::fromLatin1( "iso:/") ); kdDebug() << "url.path()==" << url.path() << endl; if (url.hasRef()) redir.setRef(url.htmlRef()); redir.setPath( url.path() + TQString::fromLatin1("/") ); kdDebug() << "tdeio_isoProtocol::listDir: redirection " << redir.url() << endl; redirection( redir ); finished(); return; } kdDebug() << "checkNewFile done" << endl; const KArchiveDirectory* root = m_isoFile->directory(); const KArchiveDirectory* dir; if (!path.isEmpty() && path != "/") { kdDebug() << TQString(TQString("Looking for entry %1").arg(path)) << endl; const KArchiveEntry* e = root->entry( path ); if ( !e ) { error( TDEIO::ERR_DOES_NOT_EXIST, path ); return; } if ( ! e->isDirectory() ) { error( TDEIO::ERR_IS_FILE, path ); return; } dir = (KArchiveDirectory*)e; } else { dir = root; } TQStringList l = dir->entries(); totalSize( l.count() ); UDSEntry entry; TQStringList::Iterator it = l.begin(); for( ; it != l.end(); ++it ) { kdDebug() << (*it) << endl; const KArchiveEntry* isoEntry = dir->entry( (*it) ); createUDSEntry( isoEntry, entry ); listEntry( entry, false ); } listEntry( entry, true ); // ready finished(); kdDebug() << "tdeio_isoProtocol::listDir done" << endl; }
void HelpProtocol::get(const KURL &url) { kdDebug(7119) << "get: path=" << url.path() << " query=" << url.query() << endl; bool redirect; QString doc; doc = url.path(); if(!mGhelp) { if(doc.at(0) != '/') doc = doc.prepend('/'); if(doc.at(doc.length() - 1) == '/') doc += "index.html"; } infoMessage(i18n("Looking up correct file")); if(!mGhelp) { doc = lookupFile(doc, url.query(), redirect); if(redirect) { finished(); return; } } if(doc.isEmpty()) { error(KIO::ERR_DOES_NOT_EXIST, url.url()); return; } mimeType("text/html"); KURL target; target.setPath(doc); if(url.hasHTMLRef()) target.setHTMLRef(url.htmlRef()); kdDebug(7119) << "target " << target.url() << endl; QString file = target.path(); if(mGhelp) { if(file.right(4) != ".xml") { get_file(target); return; } } else { QString docbook_file = file.left(file.findRev('/')) + "/index.docbook"; if(!KStandardDirs::exists(file)) { file = docbook_file; } else { QFileInfo fi(file); if(fi.isDir()) { file = file + "/index.docbook"; } else { if(file.right(5) != ".html" || !compareTimeStamps(file, docbook_file)) { get_file(target); return; } else file = docbook_file; } } } infoMessage(i18n("Preparing document")); if(mGhelp) { QString xsl = "customization/kde-nochunk.xsl"; mParsed = transform(file, locate("dtd", xsl)); kdDebug(7119) << "parsed " << mParsed.length() << endl; if(mParsed.isEmpty()) { unicodeError(i18n("The requested help file could not be parsed:<br>%1").arg(file)); } else { int pos1 = mParsed.find("charset="); if(pos1 > 0) { int pos2 = mParsed.find('"', pos1); if(pos2 > 0) { mParsed.replace(pos1, pos2 - pos1, "charset=UTF-8"); } } data(mParsed.utf8()); } } else { kdDebug(7119) << "look for cache for " << file << endl; mParsed = lookForCache(file); kdDebug(7119) << "cached parsed " << mParsed.length() << endl; if(mParsed.isEmpty()) { mParsed = transform(file, locate("dtd", "customization/kde-chunk.xsl")); if(!mParsed.isEmpty()) { infoMessage(i18n("Saving to cache")); QString cache = file.left(file.length() - 7); saveToCache(mParsed, locateLocal("cache", "kio_help" + cache + "cache.bz2")); } } else infoMessage(i18n("Using cached version")); kdDebug(7119) << "parsed " << mParsed.length() << endl; if(mParsed.isEmpty()) { unicodeError(i18n("The requested help file could not be parsed:<br>%1").arg(file)); } else { QString query = url.query(), anchor; // if we have a query, look if it contains an anchor if(!query.isEmpty()) if(query.left(8) == "?anchor=") { anchor = query.mid(8).lower(); KURL redirURL(url); redirURL.setQuery(QString::null); redirURL.setHTMLRef(anchor); redirection(redirURL); finished(); return; } if(anchor.isEmpty() && url.hasHTMLRef()) anchor = url.htmlRef(); kdDebug(7119) << "anchor: " << anchor << endl; if(!anchor.isEmpty()) { int index = 0; while(true) { index = mParsed.find(QRegExp("<a name="), index); if(index == -1) { kdDebug(7119) << "no anchor\n"; break; // use whatever is the target, most likely index.html } if(mParsed.mid(index, 11 + anchor.length()).lower() == QString("<a name=\"%1\">").arg(anchor)) { index = mParsed.findRev("<FILENAME filename=", index) + strlen("<FILENAME filename=\""); QString filename = mParsed.mid(index, 2000); filename = filename.left(filename.find('\"')); QString path = target.path(); path = path.left(path.findRev('/') + 1) + filename; kdDebug(7119) << "anchor found in " << path << endl; target.setPath(path); break; } index++; } } emitFile(target); } } finished(); }