SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / filters / main.cpp
blob0ff040c8783244673dca5dc625f69990a3a88b90
1 /******************************************************************************
2 /Filter main.
3 -------------------
4 Copyright:
5 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6 -------------------
7 Original author: Gary Cramblitt <garycramblitt@comcast.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ******************************************************************************/
24 #include <QtCore/QTextStream>
26 #include <kapplication.h>
27 #include <kdebug.h>
28 #include <klocale.h>
29 #include <kaboutdata.h>
30 #include <kcmdlineargs.h>
31 #include <kconfig.h>
32 #include <kconfiggroup.h>
33 #include <kparts/componentfactory.h>
35 #include "filterproc.h"
36 #include "talkercode.h"
38 int main(int argc, char *argv[])
40 KAboutData aboutdata(
41 "testfilter", 0, ki18n("testfilter"),
42 "0.1.0", ki18n("A utility for testing KTTSD filter plugins."),
43 KAboutData::License_GPL, ki18n("Copyright 2005, Gary Cramblitt &lt;garycramblitt@comcast.net&gt;"));
44 aboutdata.addAuthor(ki18n("Gary Cramblitt"), ki18n("Maintainer"),"garycramblitt@comcast.net");
46 KCmdLineArgs::init( argc, argv, &aboutdata );
47 // Tell which options are supported
49 KCmdLineOptions options;
50 options.add("+pluginName", ki18n("Name of a KTTSD filter plugin (required)"));
51 options.add("t");
52 options.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
53 options.add("a");
54 options.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
55 options.add("g");
56 options.add("group <filterID>", ki18n("Config file group name passed to filter"), "testfilter");
57 options.add("list", ki18n("Display list of available Filter PlugIns and exit"));
58 options.add("b");
59 options.add("break", ki18n("Display tabs as \\t, otherwise they are removed"));
60 options.add("list", ki18n("Display list of available filter plugins and exit"));
61 KCmdLineArgs::addCmdLineOptions( options );
63 KApplication app;
65 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
67 KService::List offers = KServiceTypeTrader::self()->query("KTTSD/FilterPlugin");
69 if (args->isSet("list"))
71 // Iterate thru the offers to list the plugins.
72 foreach (const KService::Ptr service, offers)
74 kDebug() << service->name();
76 return 0;
79 QString filterName;
80 if (args->count() > 0) filterName = args->arg(0);
81 QString talker = args->getOption("talker");
82 QString appId = args->getOption("appid");
83 QString groupName = args->getOption("group");
85 if (filterName.isEmpty()) kError(1) << "No filter name given." << endl;
87 QVariantList list;
88 foreach (const KService::Ptr service, offers)
90 if (service->name() == filterName)
92 // When the entry is found, load the plug in
93 // First create a factory for the library
94 KPluginLoader loader(service->library());
95 KPluginFactory *factory = loader.factory();
96 if (factory)
98 // If the factory is created successfully, instantiate the KttsFilterConf class for the
99 // specific plug in to get the plug in configuration object.
100 KttsFilterProc *plugIn = factory->create<KttsFilterProc>(NULL, list);
101 //KLibLoader::createInstance<KttsFilterProc>(
102 //service->library(), NULL, QStringList(service->library()),
103 // &errorNo);
104 if (plugIn)
106 KConfig* config = new KConfig("kttsdrc");
107 plugIn->init( config, groupName);
108 QTextStream inp ( stdin, QIODevice::ReadOnly );
109 QString text;
110 text = inp.readLine();
111 TalkerCode* talkerCode = new TalkerCode( talker );
112 text = plugIn->convert( text, talkerCode, appId );
113 if ( args->isSet("break") )
114 text.replace( '\t', "\\t" );
115 else
116 text.remove( '\t');
117 kDebug() << text;
118 delete config;
119 delete plugIn;
120 return 0;
122 else
124 kError(2) << "Unable to create instance from library." << endl;
127 else
129 kError(3) << "Unable to create factory." << endl;
133 kError(4) << "Unable to find a plugin named " << filterName << endl;