1 /**********************
5 ***********************/
10 #include <QtCore/QTextStream>
14 #include <kaboutdata.h>
15 #include <kcmdlineargs.h>
18 #include <kparts/componentfactory.h>
20 #include "filterproc.h"
21 #include "talkercode.h"
23 int main(int argc
, char *argv
[])
26 "testfilter", 0, ki18n("testfilter"),
27 "0.1.0", ki18n("A utility for testing KTTSD filter plugins."),
28 KAboutData::License_GPL
, ki18n("Copyright 2005, Gary Cramblitt <garycramblitt@comcast.net>"));
29 aboutdata
.addAuthor(ki18n("Gary Cramblitt"), ki18n("Maintainer"),"garycramblitt@comcast.net");
31 KCmdLineArgs::init( argc
, argv
, &aboutdata
);
32 // Tell which options are supported
34 KCmdLineOptions options
;
35 options
.add("+pluginName", ki18n("Name of a KTTSD filter plugin (required)"));
37 options
.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
39 options
.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
41 options
.add("group <filterID>", ki18n("Config file group name passed to filter"), "testfilter");
42 options
.add("list", ki18n("Display list of available Filter PlugIns and exit"));
44 options
.add("break", ki18n("Display tabs as \\t, otherwise they are removed"));
45 options
.add("list", ki18n("Display list of available filter plugins and exit"));
46 KCmdLineArgs::addCmdLineOptions( options
);
48 KApplication
app( false, false );
50 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
52 KTrader::OfferList offers
= KTrader::self()->query("KTTSD/FilterPlugin");
54 if (args
->isSet("list"))
56 // Iterate thru the offers to list the plugins.
57 const int offersCount
= offers
.count();
58 for(int ndx
=0; ndx
< offersCount
; ++ndx
)
60 QString name
= offers
[ndx
]->name();
61 cout
<< name
.latin1() << endl
;
67 if (args
->count() > 0) filterName
= args
->arg(0);
68 QString talker
= args
->getOption("talker");
69 QCString appId
= args
->getOption("appid");
70 QString groupName
= args
->getOption("group");
72 if (filterName
.isEmpty()) kError(1) << "No filter name given." << endl
;
74 const int offersCount
= offers
.count();
75 for(int ndx
=0; ndx
< offersCount
; ++ndx
)
77 if(offers
[ndx
]->name() == filterName
)
79 // When the entry is found, load the plug in
80 // First create a factory for the library
81 KLibFactory
*factory
= KLibLoader::self()->factory(offers
[ndx
]->library().latin1());
84 // If the factory is created successfully, instantiate the KttsFilterConf class for the
85 // specific plug in to get the plug in configuration object.
87 KttsFilterProc
*plugIn
=
88 KLibLoader::createInstance
<KttsFilterProc
>(
89 offers
[ndx
]->library().latin1(), NULL
, offers
[ndx
]->library().latin1(),
90 QStringList(), &errorNo
);
93 KConfig
* config
= new KConfig("kttsdrc");
94 config
->setGroup( "General" );
95 plugIn
->init( config
, groupName
);
96 QTextStream
inp ( stdin
, QIODevice::ReadOnly
);
99 TalkerCode
* talkerCode
= new TalkerCode( talker
);
100 text
= plugIn
->convert( text
, talkerCode
, appId
);
101 if ( args
->isSet("break") )
102 text
.replace( "\t", "\\t" );
104 text
.replace( "\t", "" );
105 cout
<< text
.latin1() << endl
;
110 kError(2) << "Unable to create instance from library." << endl
;
112 kError(3) << "Unable to create factory." << endl
;
115 kError(4) << "Unable to find a plugin named " << filterName
<< endl
;