delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / ktraderclient / ktraderclient.cpp
bloba73b624d72325a39034baafc1552db84565a4de6
1 /*
2 * Copyright (C) 2002, 2003 David Faure <faure@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
19 #include <kcmdlineargs.h>
20 #include <kmimetypetrader.h>
21 #include <kmimetype.h>
22 #include <kapplication.h>
23 #include <klocale.h>
24 #include <kservicetypetrader.h>
26 #include <stdio.h>
28 int main( int argc, char **argv )
30 KCmdLineArgs::init( argc, argv, "ktraderclient", 0, ki18n("KTraderClient"), "0.0" , ki18n("A command-line tool for querying the KDE trader system"));
33 KCmdLineOptions options;
35 options.add("mimetype <mimetype>", ki18n("A mimetype"));
37 options.add("servicetype <servicetype>", ki18n("A servicetype, like KParts/ReadOnlyPart or KMyApp/Plugin"));
39 options.add("constraint <constraint>", ki18n("A constraint expressed in the trader query language"));
41 KCmdLineArgs::addCmdLineOptions( options );
43 KApplication app( false ); // no GUI
45 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
47 const QString mimetype = args->getOption( "mimetype" );
48 QString servicetype = args->getOption( "servicetype" );
49 const QString constraint = args->getOption( "constraint" );
51 if ( mimetype.isEmpty() && servicetype.isEmpty() )
52 KCmdLineArgs::usage();
54 if ( !mimetype.isEmpty() )
55 printf( "mimetype is : %s\n", qPrintable( mimetype ) );
56 if ( !servicetype.isEmpty() )
57 printf( "servicetype is : %s\n", qPrintable( servicetype ) );
58 if ( !constraint.isEmpty() )
59 printf( "constraint is : %s\n", qPrintable( constraint ) );
61 KService::List offers;
62 if ( !mimetype.isEmpty() ) {
63 if ( servicetype.isEmpty() )
64 servicetype = "Application";
65 offers = KMimeTypeTrader::self()->query( mimetype, servicetype, constraint );
67 else
68 offers = KServiceTypeTrader::self()->query( servicetype, constraint );
70 printf("got %d offers.\n", offers.count());
72 int i = 0;
73 KService::List::ConstIterator it = offers.constBegin();
74 const KService::List::ConstIterator end = offers.constEnd();
75 for (; it != end; ++it, ++i )
77 printf("---- Offer %d ----\n", i);
78 QStringList props = (*it)->propertyNames();
79 QStringList::ConstIterator propIt = props.constBegin();
80 QStringList::ConstIterator propEnd = props.constEnd();
81 for (; propIt != propEnd; ++propIt )
83 QVariant prop = (*it)->property( *propIt );
85 if ( !prop.isValid() )
87 printf("Invalid property %s\n", (*propIt).toLocal8Bit().data());
88 continue;
91 QString outp = *propIt;
92 outp += " : '";
94 switch ( prop.type() )
96 case QVariant::StringList:
97 outp += prop.toStringList().join(" - ");
98 break;
99 case QVariant::Bool:
100 outp += prop.toBool() ? "TRUE" : "FALSE";
101 break;
102 default:
103 outp += prop.toString();
104 break;
107 if ( !outp.isEmpty() )
108 printf("%s'\n", outp.toLocal8Bit().data());