\section{KTrader Class Reference}
\label{classKTrader}\index{KTrader@{KTrader}}
A Trader interface, similar to the CORBA Trader. Provides a way to query the {\bf KDE} infrastructure for specific applications or components.  


{\tt \#include $<$ktrader.h$>$}

Inheritance diagram for KTrader:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=44pt]{classKTrader__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KTrader:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=66pt]{classKTrader__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
typedef {\bf QValue\-List}$<$ {\bf KService::Ptr} $>$ {\bf Offer\-List}
\item 
typedef {\bf QValue\-List\-Iterator}$<$ {\bf KService::Ptr} $>$ {\bf Offer\-List\-Iterator}\label{classKTrader_w1}

\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
virtual {\bf $\sim$KTrader} ()
\item 
virtual {\bf Offer\-List} {\bf query} (const {\bf QString} \&servicetype, const {\bf QString} \&constraint=QString::null, const {\bf QString} \&preferences=QString::null) const 
\item 
{\bf Offer\-List} {\bf query} (const {\bf QString} \&servicetype, const {\bf QString} \&generic\-Service\-Type, const {\bf QString} \&constraint, const {\bf QString} \&preferences) const 
\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static {\bf KTrader} $\ast$ {\bf self} ()
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
virtual void {\bf virtual\_\-hook} (int id, void $\ast$data)\label{classKTrader_b1}

\end{CompactItemize}


\subsection{Detailed Description}
A Trader interface, similar to the CORBA Trader. Provides a way to query the {\bf KDE} infrastructure for specific applications or components. 

Basically, it provides a way for an application to query all {\bf KDE} services (that is, applications and components) that match a specific set of requirements. This allows you to find an application in real-time without you having to hard-code the name and/or path of the application. It is mostly used when you want to do complex queries that {\bf KService\-Type\-Profile}{\rm (p.\,\pageref{classKServiceTypeProfile})} can't handle.

A few examples will make this a lot more clear.

Say you have an application that will display HTML. In this example, you don't want to link to khtml... and furthermore, you really don't care if the HTML browser is ours or not, as long as it works. The way that you formulate your query as well as the way that you execute the browser depends on whether or not you want the browser to run stand-alone or embedded.

If you want the browser to run standalone, then you will limit the query to search for all services that handle 'text/html' {\em and\/}, furthermore, they must be applications (Type=Application). You then will use {\bf KRun::run()}{\rm (p.\,\pageref{classKRun_e0})} to invoke the application. In \char`\"{}trader-speak\char`\"{}, this looks like so: 

\footnotesize\begin{verbatim} KTrader::OfferList offers = KTrader::self()->query("text/html", "Type == 'Application'");
 KService::Ptr ptr = offers.first();
 KURL::List lst;
 lst.append("http://www.kde.org/index.html");
 KRun::run(*ptr, lst);
\end{verbatim}
\normalsize


It should be noted that in the above example, using {\bf KService\-Type\-Profile}{\rm (p.\,\pageref{classKServiceTypeProfile})} would be the better choice since you would probably want the preferred service and the trader doesn't take this into account. The trader does allow you to do more complex things, though. Say, for instance, you want to only choose Netscape. You can do it with the constraint: \char`\"{}(Type == 'Application') and (Name == 'Netscape')\char`\"{}

More the likely, though, you will only use the trader for such things as finding components. In our continuing example, we say that we want to load any KParts component that can handle HTML. We will need to use the {\bf KLib\-Factory} and {\bf KLib\-Loader} to actually do something with our query, then. Our code would look like so: 

\footnotesize\begin{verbatim} KTrader::OfferList offers = KTrader::self()->query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes");
 KService::Ptr ptr = offers.first();
 KLibFactory *factory = KLibLoader::self()->factory( ptr->library() );
 if (factory)
   part = static_cast<KParts::ReadOnlyPart *>(factory->create(this, ptr->name(), "KParts::ReadOnlyPart"));
\end{verbatim}
\normalsize


Please note that when including property names containing arithmetic operators like - or +, then you have to put brackets around the property name, in order to correctly separate arithmetic operations from the name. So for example a constraint expression like X-KDE-Blah $<$ 4 needs to be written as [X-KDE-Blah] $<$ 4 otherwise it could also be interpreted as Substract the numeric value of the property \char`\"{}KDE\char`\"{} and \char`\"{}Blah\char`\"{} from the property \char`\"{}X\char`\"{} and make sure it is less than 4. Instead of the other meaning, make sure that the numeric value of \char`\"{}X-KDE-Blah\char`\"{} is less than 4.

Please read {\tt http://developer.kde.org/documentation/library/kdeqt/tradersyntax.html} for a more complete description of the trader language syntax.

\begin{Desc}
\item[Author:]Torben Weis $<${\tt weis@kde.org}$>$ \end{Desc}




Definition at line 99 of file ktrader.h.

\subsection{Member Typedef Documentation}
\index{KTrader@{KTrader}!OfferList@{OfferList}}
\index{OfferList@{OfferList}!KTrader@{KTrader}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}typedef {\bf QValue\-List}$<${\bf KService::Ptr}$>$ {\bf KTrader::Offer\-List}}\label{classKTrader_w0}


A list of services. 



Definition at line 106 of file ktrader.h.

\subsection{Constructor \& Destructor Documentation}
\index{KTrader@{KTrader}!~KTrader@{$\sim$KTrader}}
\index{~KTrader@{$\sim$KTrader}!KTrader@{KTrader}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTrader::$\sim${\bf KTrader} ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKTrader_a0}


Standard destructor. 



Definition at line 102 of file ktrader.cpp.

\subsection{Member Function Documentation}
\index{KTrader@{KTrader}!query@{query}}
\index{query@{query}!KTrader@{KTrader}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KTrader::Offer\-List} KTrader::query (const {\bf QString} \& {\em servicetype}, const {\bf QString} \& {\em constraint} = {\tt QString::null}, const {\bf QString} \& {\em preferences} = {\tt QString::null}) const\hspace{0.3cm}{\tt  [virtual]}}\label{classKTrader_a1}


The main function in the KTrader class. 

It will return a list of services that match your specifications. The only required parameter is the service type. This is something like 'text/plain' or 'text/html'. The constraint parameter is used to limit the possible choices returned based on the constraints you give it.

The {\tt constraint} language is rather full. The most common keywords are AND, OR, NOT, IN, and EXIST, all used in an almost spoken-word form. An example is: 

\footnotesize\begin{verbatim} (Type == 'Service') and (('KParts/ReadOnlyPart' in ServiceTypes) or (exist Exec))
\end{verbatim}
\normalsize


The keys used in the query (Type, Service\-Type, Exec) are all fields found in the .desktop files.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em servicetype}]A service type like 'text/plain', 'text/html', or 'KOffice\-Plugin'. \item[{\em constraint}]A constraint to limit the choices returned, QString::null to get all services of the given {\tt servicetype} \item[{\em preferences}]Indicates a particular preference to return, QString::null to ignore. Uses an expression in the constraint language that must return a number\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A list of services that satisfy the query \end{Desc}
\begin{Desc}
\item[See also:]{\tt http://developer.kde.org/documentation/library/kdeqt/tradersyntax.html} \end{Desc}


Definition at line 106 of file ktrader.cpp.

Referenced by KIO::Preview\-Job::available\-Plugins(), KIO::Meta\-Info\-Job::available\-Plugins(), KFilter\-Base::find\-Filter\-By\-Mime\-Type(), KDCOPService\-Starter::find\-Service\-For(), KOCRDialog::get\-OCRDialog(), KScan\-Dialog::get\-Scan\-Dialog(), KURIFilter::load\-Plugins(), query(), KData\-Tool\-Info::query(), KDCOPService\-Starter::start\-Service\-For(), KIO::Preview\-Job::supported\-Mime\-Types(), and KIO::Meta\-Info\-Job::supported\-Mime\-Types().\index{KTrader@{KTrader}!query@{query}}
\index{query@{query}!KTrader@{KTrader}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KTrader::Offer\-List} KTrader::query (const {\bf QString} \& {\em servicetype}, const {\bf QString} \& {\em generic\-Service\-Type}, const {\bf QString} \& {\em constraint}, const {\bf QString} \& {\em preferences}) const}\label{classKTrader_a2}


A variant of {\bf query()}{\rm (p.\,\pageref{classKTrader_a1})}, that takes two service types as an input. 

It is not exactly the same as adding the second service type in the constraints of the other query call, because this one takes into account user preferences for this combination of service types.

Typically, this is used for getting the list of embeddable components that can handle a given mimetype. In that case, {\tt servicetype} is the mimetype and {\tt generic\-Service\-Type} is \char`\"{}KParts/Read\-Only\-Part\char`\"{}.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em servicetype}]A service type like 'text/plain', 'text/html', or 'KOffice\-Plugin'. \item[{\em generic\-Service\-Type}]a basic service type, like 'KParts/Read\-Only\-Part' \item[{\em constraint}]A constraint to limit the choices returned, QString::null to get all services of the given {\tt servicetype} \item[{\em preferences}]Indicates a particular preference to return, QString::null to ignore. Uses an expression in the constraint language that must return a number\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A list of services that satisfy the query \end{Desc}
\begin{Desc}
\item[See also:]{\tt http://developer.kde.org/documentation/library/kdeqt/tradersyntax.html} \end{Desc}


Definition at line 112 of file ktrader.cpp.

References QValue\-List::append(), QValue\-List::begin(), QValue\-List::count(), QValue\-List::end(), endl(), kd\-Debug(), KService\-Type\-Profile::offers(), QValue\-List::prepend(), query(), and QValue\-List::remove().\index{KTrader@{KTrader}!self@{self}}
\index{self@{self}!KTrader@{KTrader}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KTrader} $\ast$ KTrader::self ()\hspace{0.3cm}{\tt  [static]}}\label{classKTrader_e0}


This is a static pointer to a KTrader instance. 

You will need to use this to access the KTrader functionality since the constuctors are protected.

\begin{Desc}
\item[Returns:]Static KTrader instance \end{Desc}


Definition at line 90 of file ktrader.cpp.

Referenced by KIO::Preview\-Job::available\-Plugins(), KIO::Meta\-Info\-Job::available\-Plugins(), KFilter\-Base::find\-Filter\-By\-Mime\-Type(), KDCOPService\-Starter::find\-Service\-For(), KOCRDialog::get\-OCRDialog(), KScan\-Dialog::get\-Scan\-Dialog(), KURIFilter::load\-Plugins(), KData\-Tool\-Info::query(), KDCOPService\-Starter::start\-Service\-For(), KIO::Preview\-Job::supported\-Mime\-Types(), and KIO::Meta\-Info\-Job::supported\-Mime\-Types().

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
ktrader.h\item 
ktrader.cpp\end{CompactItemize}
