From 7b629ff02edde3e838ccba54e32b3ef5be59732a Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Wed, 13 Nov 2024 19:16:12 -0500 Subject: [PATCH] Disable TTS If No Such QT Module Some systems or QT versions might not have or the module is not available. --- kiwix-desktop.pro | 11 +++++++---- src/mainmenu.cpp | 2 ++ src/webview.cpp | 2 ++ src/zimview.cpp | 21 +++++++++++++++------ src/zimview.h | 8 ++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/kiwix-desktop.pro b/kiwix-desktop.pro index d54c8edf..934f09d8 100644 --- a/kiwix-desktop.pro +++ b/kiwix-desktop.pro @@ -7,7 +7,7 @@ QT += core gui network QT += webenginewidgets webchannel QT += printsupport -QT += texttospeech +qtHaveModule(texttospeech): QT += texttospeech # Avoid stripping incompatible files, due to false identification as executables, on WSL DETECT_WSL = $$system(test -f /proc/sys/fs/binfmt_misc/WSLInterop && echo true || echo false) @@ -94,7 +94,8 @@ SOURCES += \ src/fullscreennotification.cpp \ src/zimview.cpp \ src/multizimbutton.cpp \ - src/texttospeechbar.cpp \ + +qtHaveModule(texttospeech): SOURCES += src/texttospeechbar.cpp \ HEADERS += \ src/choiceitem.h \ @@ -150,7 +151,8 @@ HEADERS += \ src/css_constants.h \ src/multizimbutton.h \ src/kiwixwebchannelobject.h \ - src/texttospeechbar.h \ + +qtHaveModule(texttospeech): HEADERS += src/texttospeechbar.h \ FORMS += \ src/choiceitem.ui \ @@ -165,7 +167,8 @@ FORMS += \ ui/localkiwixserver.ui \ ui/settings.ui \ src/tableofcontentbar.ui \ - src/texttospeechbar.ui \ + +qtHaveModule(texttospeech): FORMS += src/texttospeechbar.ui \ include(subprojects/QtSingleApplication/src/qtsingleapplication.pri) CODECFORSRC = UTF-8 diff --git a/src/mainmenu.cpp b/src/mainmenu.cpp index 0b20b1b5..9910ea37 100644 --- a/src/mainmenu.cpp +++ b/src/mainmenu.cpp @@ -36,8 +36,10 @@ MainMenu::MainMenu(QWidget *parent) : m_editMenu.ADD_ACTION(FindInPageAction); m_editMenu.ADD_ACTION(ToggleAddBookmarkAction); m_editMenu.ADD_ACTION(OpenMultiZimAction); +#if defined(QT_TEXTTOSPEECH_LIB) m_editMenu.ADD_ACTION(ReadArticleAction); m_editMenu.ADD_ACTION(ReadTextAction); +#endif addMenu(&m_editMenu); m_viewMenu.setTitle(gt("view")); diff --git a/src/webview.cpp b/src/webview.cpp index f03d5abe..c90ec943 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -308,10 +308,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu = createLinkContextMenu(); } +#if defined(QT_TEXTTOSPEECH_LIB) const auto app = KiwixApp::instance(); menu->addAction(app->getAction(KiwixApp::ReadArticleAction)); if (page()->hasSelection()) menu->addAction(app->getAction(KiwixApp::ReadTextAction)); +#endif menu->exec(event->globalPos()); } diff --git a/src/zimview.cpp b/src/zimview.cpp index abce0d93..d1dd74c7 100644 --- a/src/zimview.cpp +++ b/src/zimview.cpp @@ -1,29 +1,37 @@ #include "zimview.h" #include "kiwixapp.h" -#include "texttospeechbar.h" #include #include #include +#if defined(QT_TEXTTOSPEECH_LIB) +#include "texttospeechbar.h" +#endif + ZimView::ZimView(TabBar *tabBar, QWidget *parent) : QWidget(parent), mp_tabBar(tabBar), - mp_findInPageBar(new FindInPageBar(this)), - mp_ttsBar(new TextToSpeechBar(this)) + mp_findInPageBar(new FindInPageBar(this)) { mp_webView = new WebView(); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(mp_webView); layout->addWidget(mp_findInPageBar); - layout->addWidget(mp_ttsBar); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); setLayout(layout); // now 'mp_webView' has 'this' as the parent QObject mp_findInPageBar->hide(); - mp_ttsBar->hide(); auto app = KiwixApp::instance(); + +#if defined(QT_TEXTTOSPEECH_LIB) + mp_ttsBar = new TextToSpeechBar(this); + layout->addWidget(mp_ttsBar); + mp_ttsBar->hide(); + connect(mp_webView, &WebView::zimIdChanged, this, &ZimView::setSpeechLocaleByZimId); connect(app->getAction(KiwixApp::ReadArticleAction), &QAction::triggered, this, &ZimView::readArticle); connect(app->getAction(KiwixApp::ReadTextAction), &QAction::triggered, this, &ZimView::readSelectedText); +#endif + connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered, this, [=]() { if (mp_tabBar->currentZimView() != this) @@ -101,7 +109,6 @@ ZimView::ZimView(TabBar *tabBar, QWidget *parent) QToolTip::showText(pos, link); } }); - connect(mp_webView, &WebView::zimIdChanged, this, &ZimView::setSpeechLocaleByZimId); } void ZimView::openFindInPageBar() @@ -110,6 +117,7 @@ void ZimView::openFindInPageBar() mp_findInPageBar->getFindLineEdit()->setFocus(); } +#if defined(QT_TEXTTOSPEECH_LIB) void ZimView::readArticle() { if (mp_tabBar->currentZimView() != this) @@ -144,3 +152,4 @@ void ZimView::setSpeechLocaleByZimId(const QString& zimId) mp_ttsBar->setLocale(isValidISO2 ? iso2Locale : QLocale(iso3)); } catch (...) { /* Blank */ } } +#endif diff --git a/src/zimview.h b/src/zimview.h index e8accde5..70fc15b7 100644 --- a/src/zimview.h +++ b/src/zimview.h @@ -7,7 +7,10 @@ class FindInPageBar; class TabBar; class WebView; + +#if defined(QT_TEXTTOSPEECH_LIB) class TextToSpeechBar; +#endif class ZimView : public QWidget { @@ -20,9 +23,11 @@ class ZimView : public QWidget void openFindInPageBar(); public slots: +#if defined(QT_TEXTTOSPEECH_LIB) void readArticle(); void readSelectedText(); void setSpeechLocaleByZimId(const QString& zimId); +#endif signals: void webActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled); @@ -31,7 +36,10 @@ public slots: WebView *mp_webView; TabBar *mp_tabBar; FindInPageBar *mp_findInPageBar; + +#if defined(QT_TEXTTOSPEECH_LIB) TextToSpeechBar *mp_ttsBar; +#endif }; #endif // ZIMVIEW_H