TDE core libraries
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.

tdetradertest.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2002, 2003 David Faure <faure@kde.org>
  3. *
  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;
  7. *
  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.
  12. *
  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.
  17. */
  18. #include <tdecmdlineargs.h>
  19. #include <ktrader.h>
  20. #include <kmimetype.h>
  21. #include <tdeapplication.h>
  22. #include <stdio.h>
  23. static TDECmdLineOptions options[] =
  24. {
  25. { "+query", "the query", 0 },
  26. { "+[genericServiceType]", "Application (default), or KParts/ReadOnlyPart", 0 },
  27. { "+[constraint]", "constraint", 0 },
  28. { "+[preference]", "preference", 0 },
  29. TDECmdLineLastOption
  30. };
  31. int main( int argc, char **argv )
  32. {
  33. TDECmdLineArgs::init( argc, argv, "tdetradertest", "TDETradertest", "A TDETrader testing tool", "0.0" );
  34. TDECmdLineArgs::addCmdLineOptions( options );
  35. TDEApplication app( false, false ); // no GUI
  36. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  37. if ( args->count() < 1 )
  38. TDECmdLineArgs::usage();
  39. TQString query = TQString::fromLocal8Bit( args->arg( 0 ) );
  40. TQString genericServiceType, constraint, preference;
  41. if ( args->count() >= 2 )
  42. genericServiceType = TQString::fromLocal8Bit( args->arg( 1 ) );
  43. if ( args->count() >= 3 )
  44. constraint = TQString::fromLocal8Bit( args->arg( 2 ) );
  45. if ( args->count() == 4 )
  46. preference = TQString::fromLocal8Bit( args->arg( 3 ) );
  47. printf( "query is : %s\n", query.local8Bit().data() );
  48. printf( "genericServiceType is : %s\n", genericServiceType.local8Bit().data() );
  49. printf( "constraint is : %s\n", constraint.local8Bit().data() );
  50. printf( "preference is : %s\n", preference.local8Bit().data() );
  51. TDETrader::OfferList offers = TDETrader::self()->query( query, genericServiceType, constraint, preference );
  52. printf("got %d offers.\n", offers.count());
  53. int i = 0;
  54. TDETrader::OfferList::ConstIterator it = offers.begin();
  55. TDETrader::OfferList::ConstIterator end = offers.end();
  56. for (; it != end; ++it, ++i )
  57. {
  58. printf("---- Offer %d ----\n", i);
  59. TQStringList props = (*it)->propertyNames();
  60. TQStringList::ConstIterator propIt = props.begin();
  61. TQStringList::ConstIterator propEnd = props.end();
  62. for (; propIt != propEnd; ++propIt )
  63. {
  64. TQVariant prop = (*it)->property( *propIt );
  65. if ( !prop.isValid() )
  66. {
  67. printf("Invalid property %s\n", (*propIt).local8Bit().data());
  68. continue;
  69. }
  70. TQString outp = *propIt;
  71. outp += " : '";
  72. switch ( prop.type() )
  73. {
  74. case TQVariant::StringList:
  75. outp += prop.toStringList().join(" - ");
  76. break;
  77. case TQVariant::Bool:
  78. outp += prop.toBool() ? "TRUE" : "FALSE";
  79. break;
  80. default:
  81. outp += prop.toString();
  82. break;
  83. }
  84. if ( !outp.isEmpty() )
  85. printf("%s'\n", outp.local8Bit().data());
  86. }
  87. }
  88. }