[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Querying the capabilities of KHTML
From:       Jeroen Wijnhout <Jeroen.Wijnhout () kdemail ! net>
Date:       2004-03-31 11:57:47
Message-ID: 200403311357.47176.Jeroen.Wijnhout () kdemail ! net
[Download RAW message or body]

On Wednesday 31 March 2004 13:50, Kevin Krammer wrote:
> > Is there another way to test for the capabilities of KHTML?
>
> KHTML defines it is of ServiceType KPart/ReadOnlyPart and Browser/View.
>
> Perhaps you should just use the MIME type and KPart/ReadOnlyPart of you are
> looking for a viewer for the MIME type.
>
> If you need KHTML for special reasons, like casting to its interface, you
> could direclty instantiate it instead of loading it.

Well, actually I want to test if KHTML supports (i.e. is capable of viewing) a 
file with specified mimetype. If I test for KPart/ReadOnlyPart and 
Browser/View, it is not guaranteed that KHTML is the only service (for 
example, KGhostView would also satisfy the query). This is precisely what I 
want to circumvent. Pressing on a link to a PS file in a KHTML part causes 
the file to be loaded in KHTML, as plain text! So I want to test if KHTML is 
capable of viewing, for example, a PS file. If it can't do that, I use 
KTrader to find an application to view this file.

This is the code I use in a from KHTMLPart derived class:

void docpart::urlSelected(const QString &url, int button, int state,const 
QString & target, KParts::URLArgs args)
{
        KURL cURL = completeURL( url );

        KMimeMagicResult *mm = KMimeMagic::self()->findFileType(cURL.path());

        KTrader::OfferList offers = KTrader::self()->
	query(mm->mimeType(), "Library == 'libkhtml' || Library == 'libkhtmlpart' ");

        //load this URL in the embedded viewer if KHTML can handle it, or when 
	//mimetype detection failed
        if ( !mm->isValid() || offers.count() > 0 )
        {
                KHTMLPart::urlSelected(url, button, state, target, args);
                openURL(cURL) ;
                addToHistory(cURL.url());
        }
        //KHTML can't handle it, look for an appropriate application
        else
        {
                KTrader::OfferList offers =
	 KTrader::self()->query(mm->mimeType(), "Type == 'Application'");

                KService::Ptr ptr = offers.first();
                KURL::List lst;
                lst.append(cURL);
                KRun::run(*ptr, lst);
        }
}


best,
Jeroen
-- 
Kile - an Integrated LaTeX Environment
http://kile.sourceforge.net
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic