On Monday 15 July 2002 04:01 am, David Faure wrote: > On Sunday 14 July 2002 18:22, Doug Hanley wrote: > > KMimeType::Ptr mimeType =3D KMimeType::findByURL( url ); > > Ouch. That's not good at all. > This function doesn't give reliable results, in particular over HTTP. > You work around that by assuming HTML, but there is more than HTML that > one can get over HTTP. Think images, for instance. =46rom what I've seen that function always returns application/octet-stream= over=20 http, even for images, but I'd imagine that there are still times when it c= an=20 mess up, so I guess its not a good idea to use it. Also, in the case of=20 images, the htmlpart is only there in the beginning, it is replaced by an=20 image viewing part when KonqRun is called. > Hmm, ok, I see you use a KonqRun if the mimetype was unknown, but.... > the danger of the code that was posted here is more precisely in case > findByURL does a wrong assumption (as it does on some protocols). > > Why does addTab need to know the mimetype? Can't it create an empty > tab, and let openView (directly via openURL, or via KonqRun), take care > of creating the right part into it? Well, as it is right now, add tab needs to have a mimetype so it can create= a=20 part for the view. Just looking at the KonqView constrution code, it doesn= 't=20 seem to be possible to create a KonqView without a part. And all these=20 functions: openURL, openView, and KonqRun::KonqRun, require that a view=20 already exists for them to work on. All I can say is that I've been using this for 2 days or so, and it has wor= ked=20 flawlessly for me. Also, looking at this snippet of code from=20 KMimeType::findByURL, it seems as though almost all non-local files would b= e=20 shown as application/octet-stream. if ( !_is_local_file || _fast_mode ) { if ( path.endsWith( slash ) || path.isEmpty() ) { // We have no filename at all. Maybe the protocol has a setting for // which mimetype this means. For HTTP we set unknown now, because // of redirections (e.g. freshmeat downloads). // Assume inode/directory otherwise. QString def =3D KProtocolInfo::defaultMimetype( _url ); return mimeType( def.isEmpty() ? QString::fromLatin1("inode/directory= ")=20 : def ); } } // No more chances for non local URLs if ( !_is_local_file || _fast_mode ) return mimeType( defaultMimeType() ); <---------application/octet-stre= am Better yet, perhaps we could simply do something like: bool unknown =3D false; if (!url.isLocalFile()) unknown =3D true; QString mimeName, mimeComment; if (unknown) { mimeName =3D "text/html"; mimeComment =3D "Unknown"; } else { KMimeType::Ptr mimeType =3D KMimeType::findByURL( url ); =20 mimeName =3D mimeType->name(); mimeComment =3D mimeType->comment(); } KonqView* newView =3D 0L; newView =3D m_pViewManager->addTab( mimeName, mimeComment ); if (newView =3D=3D 0L) return; if (unknown) new KonqRun( this, newView, url ); else openURL( newView, url, args ); static_cast(m_pViewManager->docContainer())->showPage= (=20 newView->frame() ); Basically, we use KMimeType::findByURL for all local files, and KonqRun for= =20 all remote files. =2D- Doug