\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=72pt]{classKTrader__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
typedef {\bf QValue\-List}$<$ {\bf KService::Ptr} $>$ {\bf Offer\-List}
\begin{CompactList}\small\item\em A list of services. \item\end{CompactList}\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} ()
\begin{CompactList}\small\item\em Standard destructor. \item\end{CompactList}\item 
virtual {\bf Offer\-List} {\bf query} (const  {\bf QString} \&servicetype, const  {\bf QString} \&constraint=QString::null, const  {\bf QString} \&preferences=QString::null) const 
\begin{CompactList}\small\item\em The main function in the KTrader class. \item\end{CompactList}\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 
\begin{CompactList}\small\item\em A variant of query, that takes two service types as an input. \item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KTrader} $\ast$ {\bf self} ()
\begin{CompactList}\small\item\em This is a static pointer to a KTrader instance. \item\end{CompactList}\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.

{\bf  Examples}

{\bf  A few examples will make this a lot more clear.}

{\bf  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.}

{\bf  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: \small\begin{alltt}
 {\bf KTrader::OfferList}{\rm (p.\,\pageref{classKTrader_w0})} offers = {\bf KTrader::self()}{\rm (p.\,\pageref{classKTrader_e0})}-$>$query("text/html", "Type == 'Application'");
 {\bf KService::Ptr} ptr = offers.first();
 {\bf KURL::List} lst;
 lst.append("http://www.kde.org/index.html");
 KRun::run(*ptr, lst);
 \end{alltt}\normalsize 
}

{\bf  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`\"{}}

{\bf  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: \small\begin{alltt}
 {\bf KTrader::OfferList}{\rm (p.\,\pageref{classKTrader_w0})} offers = {\bf KTrader::self()}{\rm (p.\,\pageref{classKTrader_e0})}-$>$query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes");
 {\bf KService::Ptr} ptr = offers.first();
 {\bf KLibFactory} *factory = {\bf KLibLoader::self()}-$>$factory( ptr-$>$library() );
 if (factory)
   part = static\_cast<KParts::ReadOnlyPart *>(factory-$>$create(this, ptr-$>${\bf name()}, "KParts::ReadOnlyPart"));
 \end{alltt}\normalsize 
}

{\bf  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.}

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

{\bf }

{\bf  }

{\bf \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.

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

\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 101 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} = QString::null, const {\bf QString} \& {\em preferences} = 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 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: \small\begin{alltt}
 (Type == 'Service') and (('KParts/ReadOnlyPart' in ServiceTypes) or (exist Exec))
 \end{alltt}\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. \item[{\em preferences}]Indicates a particular preference to return.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A list of services that satisfy the query. \end{Desc}


Definition at line 105 of file ktrader.cpp.

References Offer\-List.

Referenced by KIO::Preview\-Job::available\-Plugins(), KIO::Meta\-Info\-Job::available\-Plugins(), KFilter\-Base::find\-Filter\-By\-Mime\-Type(), KScan\-Dialog::get\-Scan\-Dialog(), KURIFilter::load\-Plugins(), KData\-Tool\-Info::query(), 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 query, 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`\"{}. 

Definition at line 111 of file ktrader.cpp.

References QValue\-List::append(), QValue\-List::begin(), QValue\-List::count(), QValue\-List::end(), QString::is\-Empty(), KIO::match\-Constraint(), KIO::match\-Preferences(), Offer\-List, KService\-Type\-Profile::offers(), QValue\-List::prepend(), 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 89 of file ktrader.cpp.

Referenced by KIO::Preview\-Job::available\-Plugins(), KIO::Meta\-Info\-Job::available\-Plugins(), KFilter\-Base::find\-Filter\-By\-Mime\-Type(), KScan\-Dialog::get\-Scan\-Dialog(), KURIFilter::load\-Plugins(), KData\-Tool\-Info::query(), 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}
