VoiceAssistant  main
Resource-efficient, customizable voice assistant
Loading...
Searching...
No Matches
bridge.h
Go to the documentation of this file.
1#ifndef PLUGINBRIDGE_H
2#define PLUGINBRIDGE_H
3
4#include <QCoreApplication>
5#include <QMutex>
6#include <QObject>
7
8#if QT_WIDGETS_LIB
9#include <QWidget>
10#else
11class QWidget;
12#endif
13
20class PluginBridge final : public QObject
21{
22 Q_OBJECT
23
24 friend class MainWindow;
25
26public:
31 inline explicit PluginBridge(QObject *parent = nullptr)
32 : QObject(parent){};
33
39 inline ~PluginBridge() final
40 {
41 if (mutex.tryLock())
42 mutex.unlock();
43 }
44
53 inline QString ask(const QString &text)
54 {
55 mutex.lock();
56 pause = true;
57
58 Q_EMIT _ask(text, QPrivateSignal());
59
60 while (pause)
61 QCoreApplication::processEvents();
62
63 mutex.unlock();
64 return answer;
65 };
66
74 inline void sayAndWait(const QString &text)
75 {
76 if (text.isEmpty())
77 return;
78
79 mutex.lock();
80 pause = true;
81
82 Q_EMIT _sayAndWait(text, QPrivateSignal());
83
84 while (pause)
85 QCoreApplication::processEvents();
86
87 mutex.unlock();
88 }
89
90public Q_SLOTS:
98 inline void say(const QString &text) { Q_EMIT _say(text, QPrivateSignal()); };
99
100Q_SIGNALS:
107 void _say(const QString &text, QPrivateSignal);
108
115 void _sayAndWait(const QString &text, QPrivateSignal);
116
124 void _ask(const QString &text, QPrivateSignal);
125
133 void useWidget(QWidget *widget);
134
135private:
136 QString answer;
137 bool pause = false;
138
139 QMutex mutex;
140};
141
142#endif
The PluginBridge class provides a bridge for communication between plugins and the host application.
Definition: bridge.h:21
QString ask(const QString &text)
ask sends a request to the host application with a question and waits for an answer.
Definition: bridge.h:53
void _ask(const QString &text, QPrivateSignal)
_ask signal emitted to send a question to the host application and wait for an answer.
~PluginBridge() final
PluginBridge destructor.
Definition: bridge.h:39
PluginBridge(QObject *parent=nullptr)
PluginBridge constructor.
Definition: bridge.h:31
void sayAndWait(const QString &text)
sayAndWait sends a speech request to the host application and waits until it completes.
Definition: bridge.h:74
void _sayAndWait(const QString &text, QPrivateSignal)
_sayAndWait signal emitted to send a speech request to the host application and wait until it complet...
void useWidget(QWidget *widget)
useWidget signal emitted to send a widget to the host application for usage.
void _say(const QString &text, QPrivateSignal)
_say signal emitted to send a speech request to the host application.
friend class MainWindow
Definition: bridge.h:24
void say(const QString &text)
say sends a speech request to the host application.
Definition: bridge.h:98