1 /******************************************************************************
5 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
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>
29 #include <kaboutdata.h>
30 #include <kcmdlineargs.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
[])
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 <garycramblitt@comcast.net>"));
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)"));
52 options
.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
54 options
.add("appid <appID>", ki18n("DCOP application ID passed to filter"), "testfilter");
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"));
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
);
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();
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
;
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();
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()),
106 KConfig
* config
= new KConfig("kttsdrc");
107 plugIn
->init( config
, groupName
);
108 QTextStream
inp ( stdin
, QIODevice::ReadOnly
);
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" );
124 kError(2) << "Unable to create instance from library." << endl
;
129 kError(3) << "Unable to create factory." << endl
;
133 kError(4) << "Unable to find a plugin named " << filterName
<< endl
;