MMB opens in new tab
Doug Hanley
hanleyman at adelphia.net
Mon Jul 15 17:43:57 BST 2002
On Monday 15 July 2002 04:01 am, David Faure wrote:
> On Sunday 14 July 2002 18:22, Doug Hanley wrote:
> > KMimeType::Ptr mimeType = 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.
From what I've seen that function always returns application/octet-stream over
http, even for images, but I'd imagine that there are still times when it can
mess up, so I guess its not a good idea to use it. Also, in the case of
images, the htmlpart is only there in the beginning, it is replaced by an
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
part for the view. Just looking at the KonqView constrution code, it doesn't
seem to be possible to create a KonqView without a part. And all these
functions: openURL, openView, and KonqRun::KonqRun, require that a view
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 worked
flawlessly for me. Also, looking at this snippet of code from
KMimeType::findByURL, it seems as though almost all non-local files would be
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 = KProtocolInfo::defaultMimetype( _url );
return mimeType( def.isEmpty() ? QString::fromLatin1("inode/directory")
: def );
}
}
// No more chances for non local URLs
if ( !_is_local_file || _fast_mode )
return mimeType( defaultMimeType() ); <---------application/octet-stream
Better yet, perhaps we could simply do something like:
bool unknown = false;
if (!url.isLocalFile()) unknown = true;
QString mimeName, mimeComment;
if (unknown) {
mimeName = "text/html";
mimeComment = "Unknown";
} else {
KMimeType::Ptr mimeType = KMimeType::findByURL( url );
mimeName = mimeType->name();
mimeComment = mimeType->comment();
}
KonqView* newView = 0L;
newView = m_pViewManager->addTab( mimeName, mimeComment );
if (newView == 0L) return;
if (unknown) new KonqRun( this, newView, url );
else openURL( newView, url, args );
static_cast<KonqFrameTabs*>(m_pViewManager->docContainer())->showPage(
newView->frame() );
Basically, we use KMimeType::findByURL for all local files, and KonqRun for
all remote files.
-- Doug
More information about the kfm-devel
mailing list