1 /*************************************************** vim:set ts=4 sw=4 sts=4:
2 This class holds KTTS data from config file.
5 (C) 2006 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 ******************************************************************************/
25 #include <QDomDocument>
30 #include <kstandarddirs.h>
33 #include "talkercode.h"
36 // ConfigData includes.
37 #include "configdata.h"
39 ConfigData::ConfigData(KConfig
* config
) : m_config(config
)
44 ConfigData::~ConfigData() { delete m_config
; }
46 KConfig
* ConfigData::config() { return m_config
; }
48 bool ConfigData::readConfig()
52 // Set the group general for the configuration of KTTSD itself (no plug ins)
53 m_config
->setGroup("General");
55 // Load the configuration of the text interruption messages and sound
56 textPreMsgEnabled
= m_config
->readEntry("TextPreMsgEnabled", QVariant(false)).toBool();
57 textPreMsg
= m_config
->readEntry("TextPreMsg");
59 textPreSndEnabled
= m_config
->readEntry("TextPreSndEnabled", QVariant(false)).toBool();
60 textPreSnd
= m_config
->readEntry("TextPreSnd");
62 textPostMsgEnabled
= m_config
->readEntry("TextPostMsgEnabled", QVariant(false)).toBool();
63 textPostMsg
= m_config
->readEntry("TextPostMsg");
65 textPostSndEnabled
= m_config
->readEntry("TextPostSndEnabled", QVariant(false)).toBool();
66 textPostSnd
= m_config
->readEntry("TextPostSnd");
67 keepAudio
= m_config
->readEntry("KeepAudio", QVariant(false)).toBool();
68 keepAudioPath
= m_config
->readEntry("KeepAudioPath",
69 KStandardDirs::locateLocal("data", "kttsd/audio/"));
71 // Notification (KNotify).
72 notify
= m_config
->readEntry("Notify", QVariant(false)).toBool();
73 notifyExcludeEventsWithSound
= m_config
->readEntry("ExcludeEventsWithSound", QVariant(true)).toBool();
74 loadNotifyEventsFromFile(KStandardDirs::locateLocal("config", "kttsd_notifyevents.xml"), true );
76 // KTTSMgr auto start and auto exit.
77 autoStartManager
= m_config
->readEntry("AutoStartManager", QVariant(false)).toBool();
78 autoExitManager
= m_config
->readEntry("AutoExitManager", QVariant(false)).toBool();
80 // Default to Phonon (0).
81 playerOption
= m_config
->readEntry("AudioOutputMethod", 0);
83 // Map 50% to 100% onto 2.0 to 0.5.
84 audioStretchFactor
= 1.0/(float(m_config
->readEntry("AudioStretchFactor", 100))/100.0);
90 m_config
->setGroup("ALSAPlayer");
91 sinkName
= m_config
->readEntry("PcmName", "default");
92 if ("custom" == sinkName
)
93 sinkName
= m_config
->readEntry("CustomPcmName", "default");
94 periodSize
= m_config
->readEntry("PeriodSize", 128);
95 periods
= m_config
->readEntry("Periods", 8);
96 playerDebugLevel
= m_config
->readEntry("DebugLevel", 1);
103 void ConfigData::loadNotifyEventsFromFile( const QString
& filename
, bool clear
)
105 // Open existing event list.
106 QFile
file( filename
);
107 if ( !file
.open( QIODevice::ReadOnly
) ) {
108 kDebug() << "SpeechData::loadNotifyEventsFromFile: Unable to open file " << filename
<< endl
;
111 // QDomDocument doc( "http://www.kde.org/share/apps/kttsd/stringreplacer/wordlist.dtd []" );
112 QDomDocument
doc( "" );
113 if ( !doc
.setContent( &file
) ) {
115 kDebug() << "SpeechData::loadNotifyEventsFromFile: File not in proper XML format. " << filename
<< endl
;
117 // kDebug() << "StringReplacerConf::load: document successfully parsed." << endl;
121 notifyDefaultPresent
= NotifyPresent::Passive
;
122 notifyDefaultOptions
.action
= NotifyAction::SpeakMsg
;
123 notifyDefaultOptions
.talker
.clear();
124 notifyDefaultOptions
.customMsg
.clear();
125 notifyAppMap
.clear();
129 QDomNodeList eventList
= doc
.elementsByTagName("notifyEvent");
130 const int eventListCount
= eventList
.count();
131 for (int eventIndex
= 0; eventIndex
< eventListCount
; ++eventIndex
)
133 QDomNode eventNode
= eventList
.item(eventIndex
);
134 QDomNodeList propList
= eventNode
.childNodes();
139 TalkerCode talkerCode
;
140 const int propListCount
= propList
.count();
141 for (int propIndex
= 0; propIndex
< propListCount
; ++propIndex
) {
142 QDomNode propNode
= propList
.item(propIndex
);
143 QDomElement prop
= propNode
.toElement();
144 if (prop
.tagName() == "eventSrc") eventSrc
= prop
.text();
145 if (prop
.tagName() == "event") event
= prop
.text();
146 if (prop
.tagName() == "action") actionName
= prop
.text();
147 if (prop
.tagName() == "message") message
= prop
.text();
148 if (prop
.tagName() == "talker") talkerCode
= TalkerCode(prop
.text(), false);
150 NotifyOptions notifyOptions
;
151 notifyOptions
.action
= NotifyAction::action( actionName
);
152 notifyOptions
.talker
= talkerCode
.getTalkerCode();
153 notifyOptions
.customMsg
= message
;
154 if ( eventSrc
!= "default" ){
155 notifyOptions
.eventName
= NotifyEvent::getEventName( eventSrc
, event
);
156 NotifyEventMap notifyEventMap
= notifyAppMap
[ eventSrc
];
157 notifyEventMap
[ event
] = notifyOptions
;
158 notifyAppMap
[ eventSrc
] = notifyEventMap
;
160 notifyOptions
.eventName
.clear();
161 notifyDefaultPresent
= NotifyPresent::present( event
);
162 notifyDefaultOptions
= notifyOptions
;