SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / filters / main.cpp
blob1fad11b8e11bc338168176f2c41b1cd043222368
1 /**********************
2 #FILENAME: #FILEDESC
3 #COPYRIGHTNOTICE
4 #LICENSE
5 ***********************/
7 #include <QtCore/QTextStream>
9 #include <kapplication.h>
10 #include <kdebug.h>
11 #include <klocale.h>
12 #include <kaboutdata.h>
13 #include <kcmdlineargs.h>
14 #include <kconfig.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[])
23 KAboutData aboutdata(
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)"));
34 options.add("t");
35 options.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
36 options.add("a");
37 options.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
38 options.add("g");
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"));
41 options.add("b");
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 );
46 KApplication app;
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();
59 return 0;
62 QString filterName;
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;
70 QVariantList list;
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();
79 if (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()),
86 // &errorNo);
87 if (plugIn)
89 KConfig* config = new KConfig("kttsdrc");
90 plugIn->init( config, groupName);
91 QTextStream inp ( stdin, QIODevice::ReadOnly );
92 QString text;
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" );
98 else
99 text.remove( '\t');
100 kDebug() << text;
101 delete config;
102 delete plugIn;
103 return 0;
105 else
107 kError(2) << "Unable to create instance from library." << endl;
110 else
112 kError(3) << "Unable to create factory." << endl;
116 kError(4) << "Unable to find a plugin named " << filterName << endl;