fix icon
[kdeaccessibility.git] / kttsd / filters / main.cpp
blob7fa26deafeffe93a3e03a25d407c459506ca8801
1 /**********************
2 #FILENAME: #FILEDESC
3 #COPYRIGHTNOTICE
4 #LICENSE
5 ***********************/
7 #include <iostream>
8 using namespace std;
10 #include <QtCore/QTextStream>
12 #include <kdebug.h>
13 #include <klocale.h>
14 #include <kaboutdata.h>
15 #include <kcmdlineargs.h>
16 #include <kconfig.h>
17 #include <ktrader.h>
18 #include <kparts/componentfactory.h>
20 #include "filterproc.h"
21 #include "talkercode.h"
23 int main(int argc, char *argv[])
25 KAboutData aboutdata(
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)"));
36 options.add("t");
37 options.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
38 options.add("a");
39 options.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
40 options.add("g");
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"));
43 options.add("b");
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;
63 return 0;
66 QString filterName;
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());
82 if(factory)
84 // If the factory is created successfully, instantiate the KttsFilterConf class for the
85 // specific plug in to get the plug in configuration object.
86 int errorNo;
87 KttsFilterProc *plugIn =
88 KLibLoader::createInstance<KttsFilterProc>(
89 offers[ndx]->library().latin1(), NULL, offers[ndx]->library().latin1(),
90 QStringList(), &errorNo);
91 if(plugIn)
93 KConfig* config = new KConfig("kttsdrc");
94 config->setGroup( "General" );
95 plugIn->init( config, groupName );
96 QTextStream inp ( stdin, QIODevice::ReadOnly );
97 QString text;
98 text = inp.read();
99 TalkerCode* talkerCode = new TalkerCode( talker );
100 text = plugIn->convert( text, talkerCode, appId );
101 if ( args->isSet("break") )
102 text.replace( "\t", "\\t" );
103 else
104 text.replace( "\t", "" );
105 cout << text.latin1() << endl;
106 delete config;
107 delete plugIn;
108 return 0;
109 } else
110 kError(2) << "Unable to create instance from library." << endl;
111 } else
112 kError(3) << "Unable to create factory." << endl;
115 kError(4) << "Unable to find a plugin named " << filterName << endl;