KTextAddons

texttospeechutil.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "texttospeechutil.h"
8
9#include <KConfig>
10#include <KConfigGroup>
11#include <QIODevice>
12
13QString TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName()
14{
15 return QStringLiteral("texttospeechrc");
16}
17
18QString TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName()
19{
20 return QStringLiteral("Settings");
21}
22
23TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings TextEditTextToSpeech::TextToSpeechUtil::loadSettings()
24{
25 TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings settings;
26 KConfig config(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName());
27 const KConfigGroup grp = config.group(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName());
28 settings.engineName = grp.readEntry("engine");
29 settings.rate = grp.readEntry("rate", 50);
30 settings.volumeValue = grp.readEntry("volume", 0);
31 settings.localeName = grp.readEntry("localeName");
32 settings.pitch = grp.readEntry("pitch", 0);
33 QByteArray ba = grp.readEntry("voice", QByteArray());
35 s.setVersion(QDataStream::Qt_5_15);
36 s >> settings.voice;
37 return settings;
38}
39
40void TextEditTextToSpeech::TextToSpeechUtil::writeConfig(const TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings &settings)
41{
42 KConfig config(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName());
43 KConfigGroup grp = config.group(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName());
44 grp.writeEntry("volume", settings.volumeValue);
45 grp.writeEntry("rate", settings.rate);
46 grp.writeEntry("pitch", settings.pitch);
47 grp.writeEntry("localeName", settings.localeName);
48 // qDebug() << " engineName " << engineName;
49 grp.writeEntry("engine", settings.engineName);
50 QByteArray ba;
52 s.setVersion(QDataStream::Qt_5_15);
53 s << settings.voice;
54 grp.writeEntry("voice", ba);
55}
56
57QDebug operator<<(QDebug d, const TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings &t)
58{
59 d << "voice " << t.voice;
60 d << "engineName " << t.engineName;
61 d << "localeName " << t.localeName;
62 d << "rate " << t.rate;
63 d << "pitch " << t.pitch;
64 d << "volumeValue " << t.volumeValue;
65 return d;
66}
KConfigGroup group(const QString &group)
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.