• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • filters
filters/main.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  Copyright 2011 by Jeremy Whiting <jpwhiting@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) version 3.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***************************************************************************/
18 
19 #include <QtCore/QTextStream>
20 
21 #include <kapplication.h>
22 #include <kdebug.h>
23 #include <klocale.h>
24 #include <kaboutdata.h>
25 #include <kcmdlineargs.h>
26 #include <kconfig.h>
27 #include <kconfiggroup.h>
28 #include <kservicetypetrader.h>
29 
30 #include "filterproc.h"
31 #include "talkercode.h"
32 
33 int main(int argc, char *argv[])
34 {
35  KAboutData aboutdata(
36  "testfilter", 0, ki18n("testfilter"),
37  "0.1.0", ki18n("A utility for testing Jovie filter plugins."),
38  KAboutData::License_GPL, ki18n("Copyright 2005, Gary Cramblitt &lt;garycramblitt@comcast.net&gt;"));
39  aboutdata.addAuthor(ki18n("Gary Cramblitt"), ki18n("Maintainer"),"garycramblitt@comcast.net");
40 
41  KCmdLineArgs::init( argc, argv, &aboutdata );
42  // Tell which options are supported
43 
44  KCmdLineOptions options;
45  options.add("+pluginName", ki18n("Name of a Jovie filter plugin (required)"));
46  options.add("t");
47  options.add("talker <talker>", ki18n("Talker code passed to filter"), "en");
48  options.add("a");
49  options.add("appid <appID>", ki18n("D-Bus application ID passed to filter"), "testfilter");
50  options.add("g");
51  options.add("group <filterID>", ki18n("Config file group name passed to filter"), "testfilter");
52  options.add("list", ki18n("Display list of available Filter PlugIns and exit"));
53  options.add("b");
54  options.add("break", ki18n("Display tabs as \\t, otherwise they are removed"));
55  options.add("list", ki18n("Display list of available filter plugins and exit"));
56  KCmdLineArgs::addCmdLineOptions( options );
57 
58  KApplication app;
59 
60  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
61 
62  KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KTTSD/FilterPlugin"));
63 
64  if (args->isSet("list"))
65  {
66  // Iterate thru the offers to list the plugins.
67  foreach (const KService::Ptr service, offers)
68  {
69  kDebug() << service->name();
70  }
71  return 0;
72  }
73 
74  QString filterName;
75  if (args->count() > 0) filterName = args->arg(0);
76  QString talker = args->getOption("talker");
77  QString appId = args->getOption("appid");
78  QString groupName = args->getOption("group");
79 
80  if (filterName.isEmpty()) kError(1) << "No filter name given." << endl;
81 
82  QVariantList list;
83  foreach (const KService::Ptr service, offers)
84  {
85  if (service->name() == filterName)
86  {
87  // When the entry is found, load the plug in
88  // First create a factory for the library
89  KPluginLoader loader(service->library());
90  KPluginFactory *factory = loader.factory();
91  if (factory)
92  {
93  // If the factory is created successfully, instantiate the KttsFilterConf class for the
94  // specific plug in to get the plug in configuration object.
95  KttsFilterProc *plugIn = factory->create<KttsFilterProc>(NULL, list);
96  //KLibLoader::createInstance<KttsFilterProc>(
97  //service->library(), NULL, QStringList(service->library()),
98  // &errorNo);
99  if (plugIn)
100  {
101  KConfig* config = new KConfig(QLatin1String("kttsdrc"));
102  plugIn->init( config, groupName);
103  QTextStream inp ( stdin, QIODevice::ReadOnly );
104  QString text;
105  text = inp.readLine();
106  TalkerCode* talkerCode = new TalkerCode( talker );
107  text = plugIn->convert( text, talkerCode, appId );
108  if ( args->isSet("break") )
109  text.replace( QLatin1Char('\t'), QLatin1String("\\t") );
110  else
111  text.remove( QLatin1Char('\t'));
112  kDebug() << text;
113  delete config;
114  delete plugIn;
115  return 0;
116  }
117  else
118  {
119  kError(2) << "Unable to create instance from library." << endl;
120  }
121  }
122  else
123  {
124  kError(3) << "Unable to create factory." << endl;
125  }
126  }
127  }
128  kError(4) << "Unable to find a plugin named " << filterName << endl;
129 }
KttsFilterProc::init
virtual bool init(KConfig *config, const QString &configGroup)
Initialize the filter.
Definition: filterproc.cpp:57
KttsFilterProc::convert
virtual QString convert(const QString &inputText, TalkerCode *talkerCode, const QString &appId)
Convert input, returning output.
Definition: filterproc.cpp:90
filterproc.h
KttsFilterProc
Definition: filterproc.h:38
talkercode.h
TalkerCode
Definition: talkercode.h:38
main
int main(int argc, char *argv[])
Definition: filters/main.cpp:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal