1 /**********************
5 ***********************/
11 #include <qtextstream.h>
15 #include <kaboutdata.h>
16 #include <kapplication.h>
17 #include <kcmdlineargs.h>
20 #include <kparts/componentfactory.h>
22 #include "filterproc.h"
23 #include "talkercode.h"
25 static const KCmdLineOptions options
[] =
27 { "+pluginName", I18N_NOOP("Name of a KTTSD filter plugin (required)"), 0 },
29 { "talker <talker>", I18N_NOOP("Talker code passed to filter"), "en" },
31 { "appid <appID>", I18N_NOOP("DCOP application ID passed to filter"), "testfilter" },
34 I18N_NOOP("Config file group name passed to filter"), "testfilter" },
35 { "list", I18N_NOOP("Display list of available Filter PlugIns and exit"), 0 },
37 { "break", I18N_NOOP("Display tabs as \\t, otherwise they are removed"), 0 },
38 { "list", I18N_NOOP("Display list of available filter plugins and exit"), 0 }
41 int main(int argc
, char *argv
[])
44 "testfilter", I18N_NOOP("testfilter"),
45 "0.1.0", I18N_NOOP("A utility for testing KTTSD filter plugins."),
46 KAboutData::License_GPL
, "(C) 2005, Gary Cramblitt <garycramblitt@comcast.net>");
47 aboutdata
.addAuthor("Gary Cramblitt", I18N_NOOP("Maintainer"),"garycramblitt@comcast.net");
49 KCmdLineArgs::init( argc
, argv
, &aboutdata
);
50 // Tell which options are supported
51 KCmdLineArgs::addCmdLineOptions( options
);
53 KApplication
app( false, false );
55 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
57 KTrader::OfferList offers
= KTrader::self()->query("KTTSD/FilterPlugin");
59 if (args
->isSet("list"))
61 // Iterate thru the offers to list the plugins.
62 const int offersCount
= offers
.count();
63 for(int ndx
=0; ndx
< offersCount
; ++ndx
)
65 QString name
= offers
[ndx
]->name();
66 cout
<< name
.latin1() << endl
;
72 if (args
->count() > 0) filterName
= args
->arg(0);
73 QString talker
= args
->getOption("talker");
74 QCString appId
= args
->getOption("appid");
75 QString groupName
= args
->getOption("group");
77 if (filterName
.isEmpty()) kdError(1) << "No filter name given." << endl
;
79 const int offersCount
= offers
.count();
80 for(int ndx
=0; ndx
< offersCount
; ++ndx
)
82 if(offers
[ndx
]->name() == filterName
)
84 // When the entry is found, load the plug in
85 // First create a factory for the library
86 KLibFactory
*factory
= KLibLoader::self()->factory(offers
[ndx
]->library().latin1());
89 // If the factory is created successfully, instantiate the KttsFilterConf class for the
90 // specific plug in to get the plug in configuration object.
92 KttsFilterProc
*plugIn
=
93 KLibLoader::createInstance
<KttsFilterProc
>(
94 offers
[ndx
]->library().latin1(), NULL
, offers
[ndx
]->library().latin1(),
95 QStringList(), &errorNo
);
98 KConfig
* config
= new KConfig("kttsdrc");
99 config
->setGroup( "General" );
100 plugIn
->init( config
, groupName
);
101 QTextStream
inp ( stdin
, QIODevice::ReadOnly
);
104 TalkerCode
* talkerCode
= new TalkerCode( talker
);
105 text
= plugIn
->convert( text
, talkerCode
, appId
);
106 if ( args
->isSet("break") )
107 text
.replace( "\t", "\\t" );
109 text
.replace( "\t", "" );
110 cout
<< text
.latin1() << endl
;
115 kdError(2) << "Unable to create instance from library." << endl
;
117 kdError(3) << "Unable to create factory." << endl
;
120 kdError(4) << "Unable to find a plugin named " << filterName
<< endl
;