qt3support--
[kdeaccessibility.git] / kttsd / filters / main.cpp
blobec61b4d11be1e28f4344e9d55e2415905a6f367f
1 /**********************
2 #FILENAME: #FILEDESC
3 #COPYRIGHTNOTICE
4 #LICENSE
5 ***********************/
7 #include <qstring.h>
8 #include <iostream>
9 using namespace std;
11 #include <qtextstream.h>
13 #include <kdebug.h>
14 #include <klocale.h>
15 #include <kaboutdata.h>
16 #include <kapplication.h>
17 #include <kcmdlineargs.h>
18 #include <kconfig.h>
19 #include <ktrader.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 },
28 { "t", 0, 0 },
29 { "talker <talker>", I18N_NOOP("Talker code passed to filter"), "en" },
30 { "a", 0, 0 },
31 { "appid <appID>", I18N_NOOP("DCOP application ID passed to filter"), "testfilter" },
32 { "g", 0, 0 },
33 { "group <filterID>",
34 I18N_NOOP("Config file group name passed to filter"), "testfilter" },
35 { "list", I18N_NOOP("Display list of available Filter PlugIns and exit"), 0 },
36 { "b", 0, 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[])
43 KAboutData aboutdata(
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;
68 return 0;
71 QString filterName;
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());
87 if(factory)
89 // If the factory is created successfully, instantiate the KttsFilterConf class for the
90 // specific plug in to get the plug in configuration object.
91 int errorNo;
92 KttsFilterProc *plugIn =
93 KLibLoader::createInstance<KttsFilterProc>(
94 offers[ndx]->library().latin1(), NULL, offers[ndx]->library().latin1(),
95 QStringList(), &errorNo);
96 if(plugIn)
98 KConfig* config = new KConfig("kttsdrc");
99 config->setGroup( "General" );
100 plugIn->init( config, groupName );
101 QTextStream inp ( stdin, QIODevice::ReadOnly );
102 QString text;
103 text = inp.read();
104 TalkerCode* talkerCode = new TalkerCode( talker );
105 text = plugIn->convert( text, talkerCode, appId );
106 if ( args->isSet("break") )
107 text.replace( "\t", "\\t" );
108 else
109 text.replace( "\t", "" );
110 cout << text.latin1() << endl;
111 delete config;
112 delete plugIn;
113 return 0;
114 } else
115 kdError(2) << "Unable to create instance from library." << endl;
116 } else
117 kdError(3) << "Unable to create factory." << endl;
120 kdError(4) << "Unable to find a plugin named " << filterName << endl;