1 /**********************
5 ***********************/
7 #include <QtCore/QTextStream>
9 #include <kapplication.h>
12 #include <kaboutdata.h>
13 #include <kcmdlineargs.h>
15 #include <kconfiggroup.h>
16 #include <kparts/componentfactory.h>
18 #include "filterproc.h"
19 #include "talkercode.h"
21 int main(int argc
, char *argv
[])
24 "testfilter", 0, ki18n("testfilter"),
25 "0.1.0", ki18n("A utility for testing KTTSD filter plugins."),
26 KAboutData::License_GPL
, ki18n("Copyright 2005, Gary Cramblitt <garycramblitt@comcast.net>"));
27 aboutdata
.addAuthor(ki18n("Gary Cramblitt"), ki18n("Maintainer"),"garycramblitt@comcast.net");
29 KCmdLineArgs::init( argc
, argv
, &aboutdata
);
30 // Tell which options are supported
32 KCmdLineOptions options
;
33 options
.add("+pluginName", ki18n("Name of a KTTSD filter plugin (required)"));
35 options
.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
37 options
.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
39 options
.add("group <filterID>", ki18n("Config file group name passed to filter"), "testfilter");
40 options
.add("list", ki18n("Display list of available Filter PlugIns and exit"));
42 options
.add("break", ki18n("Display tabs as \\t, otherwise they are removed"));
43 options
.add("list", ki18n("Display list of available filter plugins and exit"));
44 KCmdLineArgs::addCmdLineOptions( options
);
48 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
50 KService::List offers
= KServiceTypeTrader::self()->query("KTTSD/FilterPlugin");
52 if (args
->isSet("list"))
54 // Iterate thru the offers to list the plugins.
55 foreach (const KService::Ptr service
, offers
)
57 kDebug() << service
->name();
63 if (args
->count() > 0) filterName
= args
->arg(0);
64 QString talker
= args
->getOption("talker");
65 QString appId
= args
->getOption("appid");
66 QString groupName
= args
->getOption("group");
68 if (filterName
.isEmpty()) kError(1) << "No filter name given." << endl
;
71 foreach (const KService::Ptr service
, offers
)
73 if (service
->name() == filterName
)
75 // When the entry is found, load the plug in
76 // First create a factory for the library
77 KPluginLoader
loader(service
->library());
78 KPluginFactory
*factory
= loader
.factory();
81 // If the factory is created successfully, instantiate the KttsFilterConf class for the
82 // specific plug in to get the plug in configuration object.
83 KttsFilterProc
*plugIn
= factory
->create
<KttsFilterProc
>(NULL
, list
);
84 //KLibLoader::createInstance<KttsFilterProc>(
85 //service->library(), NULL, QStringList(service->library()),
89 KConfig
* config
= new KConfig("kttsdrc");
90 plugIn
->init( config
, groupName
);
91 QTextStream
inp ( stdin
, QIODevice::ReadOnly
);
93 text
= inp
.readLine();
94 TalkerCode
* talkerCode
= new TalkerCode( talker
);
95 text
= plugIn
->convert( text
, talkerCode
, appId
);
96 if ( args
->isSet("break") )
97 text
.replace( '\t', "\\t" );
107 kError(2) << "Unable to create instance from library." << endl
;
112 kError(3) << "Unable to create factory." << endl
;
116 kError(4) << "Unable to find a plugin named " << filterName
<< endl
;