You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
5.6 KiB
159 lines
5.6 KiB
From d8de33cb9552d390494405e6922041122ae2e968 Mon Sep 17 00:00:00 2001
|
|
From: David Faure <faure@kde.org>
|
|
Date: Sun, 28 Feb 2016 14:23:13 +0100
|
|
Subject: [PATCH 06/10] ktraderclient: add --properties flag, so the default
|
|
output is much shorter.
|
|
|
|
More useful for debugging the list of services (especially remotely).
|
|
---
|
|
ktraderclient/ktraderclient.cpp | 125 +++++++++++++++++++++-------------------
|
|
1 file changed, 66 insertions(+), 59 deletions(-)
|
|
|
|
diff --git a/ktraderclient/ktraderclient.cpp b/ktraderclient/ktraderclient.cpp
|
|
index 5a14cfe..31330c1 100644
|
|
--- a/ktraderclient/ktraderclient.cpp
|
|
+++ b/ktraderclient/ktraderclient.cpp
|
|
@@ -46,73 +46,80 @@ int main( int argc, char **argv )
|
|
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("servicetype"), i18n("A servicetype, like KParts/ReadOnlyPart or KMyApp/Plugin"), QLatin1String("servicetype")));
|
|
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("constraint"), i18n("A constraint expressed in the trader query language"), QLatin1String("constraint")));
|
|
|
|
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("properties"), i18n("Output all properties")));
|
|
+
|
|
parser.process(app);
|
|
aboutData.processCommandLine(&parser);
|
|
|
|
const QString mimetype = parser.value("mimetype");
|
|
QString servicetype = parser.value("servicetype");
|
|
const QString constraint = parser.value("constraint");
|
|
+ const bool outputProperties = parser.isSet("properties");
|
|
+
|
|
+ if ( mimetype.isEmpty() && servicetype.isEmpty() )
|
|
+ parser.showHelp();
|
|
+
|
|
+ if ( !mimetype.isEmpty() )
|
|
+ printf( "mimetype is : %s\n", qPrintable( mimetype ) );
|
|
+ if ( !servicetype.isEmpty() )
|
|
+ printf( "servicetype is : %s\n", qPrintable( servicetype ) );
|
|
+ if ( !constraint.isEmpty() )
|
|
+ printf( "constraint is : %s\n", qPrintable( constraint ) );
|
|
+
|
|
+ KService::List offers;
|
|
+ if ( !mimetype.isEmpty() ) {
|
|
+ if ( servicetype.isEmpty() )
|
|
+ servicetype = "Application";
|
|
+ offers = KMimeTypeTrader::self()->query( mimetype, servicetype, constraint );
|
|
+ }
|
|
+ else
|
|
+ offers = KServiceTypeTrader::self()->query( servicetype, constraint );
|
|
+
|
|
+ printf("got %d offers.\n", offers.count());
|
|
|
|
- if ( mimetype.isEmpty() && servicetype.isEmpty() )
|
|
- parser.showHelp();
|
|
-
|
|
- if ( !mimetype.isEmpty() )
|
|
- printf( "mimetype is : %s\n", qPrintable( mimetype ) );
|
|
- if ( !servicetype.isEmpty() )
|
|
- printf( "servicetype is : %s\n", qPrintable( servicetype ) );
|
|
- if ( !constraint.isEmpty() )
|
|
- printf( "constraint is : %s\n", qPrintable( constraint ) );
|
|
-
|
|
- KService::List offers;
|
|
- if ( !mimetype.isEmpty() ) {
|
|
- if ( servicetype.isEmpty() )
|
|
- servicetype = "Application";
|
|
- offers = KMimeTypeTrader::self()->query( mimetype, servicetype, constraint );
|
|
- }
|
|
- else
|
|
- offers = KServiceTypeTrader::self()->query( servicetype, constraint );
|
|
-
|
|
- printf("got %d offers.\n", offers.count());
|
|
-
|
|
- int i = 0;
|
|
- KService::List::ConstIterator it = offers.constBegin();
|
|
- const KService::List::ConstIterator end = offers.constEnd();
|
|
- for (; it != end; ++it, ++i )
|
|
- {
|
|
- printf("---- Offer %d ----\n", i);
|
|
- QStringList props = (*it)->propertyNames();
|
|
- QStringList::ConstIterator propIt = props.constBegin();
|
|
- QStringList::ConstIterator propEnd = props.constEnd();
|
|
- for (; propIt != propEnd; ++propIt )
|
|
+ int i = 0;
|
|
+ KService::List::ConstIterator it = offers.constBegin();
|
|
+ const KService::List::ConstIterator end = offers.constEnd();
|
|
+ for (; it != end; ++it, ++i )
|
|
{
|
|
- QVariant prop = (*it)->property( *propIt );
|
|
-
|
|
- if ( !prop.isValid() )
|
|
- {
|
|
- printf("Invalid property %s\n", (*propIt).toLocal8Bit().data());
|
|
- continue;
|
|
- }
|
|
-
|
|
- QString outp = *propIt;
|
|
- outp += " : '";
|
|
-
|
|
- switch ( prop.type() )
|
|
- {
|
|
- case QVariant::StringList:
|
|
- outp += prop.toStringList().join(" - ");
|
|
- break;
|
|
- case QVariant::Bool:
|
|
- outp += prop.toBool() ? "TRUE" : "FALSE";
|
|
- break;
|
|
- default:
|
|
- outp += prop.toString();
|
|
- break;
|
|
- }
|
|
-
|
|
- if ( !outp.isEmpty() )
|
|
- printf("%s'\n", outp.toLocal8Bit().data());
|
|
+ if (outputProperties) {
|
|
+ printf("---- Offer %d ----\n", i);
|
|
+ QStringList props = (*it)->propertyNames();
|
|
+ QStringList::ConstIterator propIt = props.constBegin();
|
|
+ QStringList::ConstIterator propEnd = props.constEnd();
|
|
+ for (; propIt != propEnd; ++propIt )
|
|
+ {
|
|
+ QVariant prop = (*it)->property( *propIt );
|
|
+
|
|
+ if ( !prop.isValid() )
|
|
+ {
|
|
+ printf("Invalid property %s\n", (*propIt).toLocal8Bit().data());
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ QString outp = *propIt;
|
|
+ outp += " : '";
|
|
+
|
|
+ switch ( prop.type() )
|
|
+ {
|
|
+ case QVariant::StringList:
|
|
+ outp += prop.toStringList().join(" - ");
|
|
+ break;
|
|
+ case QVariant::Bool:
|
|
+ outp += prop.toBool() ? "TRUE" : "FALSE";
|
|
+ break;
|
|
+ default:
|
|
+ outp += prop.toString();
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ if ( !outp.isEmpty() )
|
|
+ printf("%s'\n", outp.toLocal8Bit().constData());
|
|
+ }
|
|
+ } else {
|
|
+ printf("%s\n", (*it)->entryPath().toLocal8Bit().constData());
|
|
+ }
|
|
}
|
|
- }
|
|
- return 0;
|
|
+ return 0;
|
|
}
|
|
|
|
--
|
|
2.5.0
|
|
|