7#include "speechtotextengineloader.h"
10#include "speechtotextclient.h"
11#include "textspeechtotext_debug.h"
12#include <QCoreApplication>
14#include <QPluginLoader>
15using namespace TextSpeechToText;
16class TextSpeechToText::SpeechToTextEngineLoaderPrivate
29SpeechToTextEngineLoader::SpeechToTextEngineLoader(
QObject *parent)
31 , d(new TextSpeechToText::SpeechToTextEngineLoaderPrivate)
36SpeechToTextEngineLoader::~SpeechToTextEngineLoader() =
default;
38void SpeechToTextEngineLoader::loadPlugins()
41 const QString pathSuffix(QStringLiteral(
"/kf6/speechtotext/"));
42 for (
const QString &libPath : libPaths) {
43 const QDir dir(libPath + pathSuffix);
48 loadPlugin(
dir.absoluteFilePath(fileName));
51 if (d->loadedPlugins.isEmpty()) {
52 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"No speechtotext plugins available!";
57void SpeechToTextEngineLoader::loadPlugin(
const QString &pluginPath)
60 const QString pluginIID = plugin.metaData()[
"IID"_L1].toString();
62 if (d->loadedPlugins.contains(pluginIID)) {
63 qCDebug(TEXTSPEECHTOTEXT_LOG) <<
"Skipping already loaded" << pluginPath;
66 d->loadedPlugins.insert(pluginIID);
70 qCDebug(TEXTSPEECHTOTEXT_LOG) <<
"Unable to load plugin" << pluginPath <<
"Error:" << plugin.errorString();
71 d->loadedPlugins.remove(pluginIID);
76 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"Invalid plugin loaded" << pluginPath;
80 d->speechToTextClients.insert(client->
name(), client);
85 auto clientsItr = d->speechToTextClients.constFind(clientName);
86 if (clientsItr == d->speechToTextClients.constEnd()) {
87 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"Client name not found: " << clientName;
88 Q_EMIT loadingSpeechToTextFailed();
94bool SpeechToTextEngineLoader::hasConfigurationDialog(
const QString &clientName)
const
96 auto clientsItr = d->speechToTextClients.constFind(clientName);
97 if (clientsItr == d->speechToTextClients.constEnd()) {
98 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"Client name not found: " << clientName;
101 return (*clientsItr)->hasConfigurationDialog();
104bool SpeechToTextEngineLoader::showConfigureDialog(
const QString &clientName,
QWidget *parentWidget)
106 auto clientsItr = d->speechToTextClients.constFind(clientName);
107 if (clientsItr == d->speechToTextClients.constEnd()) {
108 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"Client name not found: " << clientName;
111 return (*clientsItr)->showConfigureDialog(parentWidget);
118 while (i.hasNext()) {
120 map.insert(i.key(), i.value()->translatedName());
125QString SpeechToTextEngineLoader::fallbackFirstEngine()
const
127 if (!d->speechToTextClients.isEmpty()) {
128 return *d->speechToTextClients.keyBegin();
130 qCWarning(TEXTSPEECHTOTEXT_LOG) <<
"No plugin found ! ";
134bool SpeechToTextEngineLoader::hasEngine()
const
136 return !d->speechToTextClients.isEmpty();
139#include "moc_speechtotextengineloader.cpp"
The SpeechToTextClient class.
virtual QString name() const =0
The SpeechToTextEngineLoader class.
KIOCORE_EXPORT QString dir(const QString &fileClass)
QStringList libraryPaths()
T qobject_cast(QObject *object)
bool isEmpty() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)