diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index c784d818e..0b83023ed 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -36,7 +36,7 @@ include(CheckCXXCompilerFlag) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -if(NOT WIN32) +if (NOT WIN32) check_cxx_compiler_flag("-Wsuggest-override" SUGGEST_OVERRIDE) set(CUSTOM_FLAGS "\ -Wall \ @@ -53,19 +53,19 @@ if(NOT WIN32) -Wuninitialized \ -Wunused \ ") - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CUSTOM_FLAGS "${CUSTOM_FLAGS} -Wlogical-op") - endif() - if(SUGGEST_OVERRIDE) + endif () + if (SUGGEST_OVERRIDE) set(CUSTOM_FLAGS "${CUSTOM_FLAGS} -Wsuggest-override -Werror=suggest-override") - endif() -endif() + endif () +endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}") # See: http://stackoverflow.com/a/1372836 -if(WIN32) +if (WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WINSOCKAPI_") -endif() +endif () set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DQT_NO_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG") @@ -74,19 +74,20 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -DQT_QML_DEBUG -DQT_ # Define packages, libs, sources, headers, resources and languages. # ------------------------------------------------------------------------------ -set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 Svg LinguistTools Concurrent Network TextToSpeech) +set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 Svg LinguistTools Concurrent Network) +set(QT5_PACKAGES_OPTIONAL TextToSpeech) -if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) +if (LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake") include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake") include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake") include("${EP_belcard_CONFIG_DIR}/BelcardConfig.cmake") -else() +else () find_package(Linphone REQUIRED) find_package(LinphoneCxx REQUIRED) find_package(BcToolbox REQUIRED) find_package(Belcard REQUIRED) -endif() +endif () set(SOURCES src/app/App.cpp @@ -127,6 +128,7 @@ set(SOURCES src/components/sip-addresses/SipAddressesProxyModel.cpp src/components/sip-addresses/SipAddressObserver.cpp src/components/sound-player/SoundPlayer.cpp + src/components/text-to-speech/TextToSpeech.cpp src/components/timeline/TimelineModel.cpp src/externals/single-application/SingleApplication.cpp src/main.cpp @@ -173,6 +175,7 @@ set(HEADERS src/components/sip-addresses/SipAddressesProxyModel.hpp src/components/sip-addresses/SipAddressObserver.hpp src/components/sound-player/SoundPlayer.hpp + src/components/text-to-speech/TextToSpeech.hpp src/components/timeline/TimelineModel.hpp src/externals/single-application/SingleApplication.hpp src/externals/single-application/SingleApplicationPrivate.hpp @@ -221,16 +224,16 @@ foreach (line ${QRC_RESOURCES_CONTENT}) endif () endforeach () -if(NOT WIN32) +# ------------------------------------------------------------------------------ +# Init git hooks. +# ------------------------------------------------------------------------------ + +if (NOT WIN32) add_custom_target( check_qml DEPENDS ${QML_SOURCES} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check_qml_syntax" ) -endif() - -# ------------------------------------------------------------------------------ -# Init git hooks. -# ------------------------------------------------------------------------------ +endif () execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/tools/private/pre-commit" @@ -249,13 +252,14 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN # ------------------------------------------------------------------------------ find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED) +find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET) -if(CMAKE_INSTALL_RPATH) +if (CMAKE_INSTALL_RPATH) get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION) get_filename_component(LUPDATE_PATH "${LUPDATE_PATH}" DIRECTORY) get_filename_component(QT_PATH "${LUPDATE_PATH}/../lib" ABSOLUTE) list(APPEND CMAKE_INSTALL_RPATH "${QT_PATH}") -endif() +endif () # Add languages support. add_subdirectory(${LANGUAGES_DIRECTORY}) @@ -266,26 +270,40 @@ qt5_add_resources(RESOURCES ${QRC_RESOURCES}) # Build. # Note: `update_translations` is provided by `languages/CMakeLists.txt`. -if(WIN32) +if (WIN32) add_executable(${TARGET_NAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} linphone.rc) -else() +else () add_executable(${TARGET_NAME} ${SOURCES} ${HEADERS} ${RESOURCES}) -endif() +endif () bc_git_version(${TARGET_NAME} ${PROJECT_VERSION}) add_dependencies(${TARGET_NAME} ${TARGET_NAME}-git-version) add_dependencies(${TARGET_NAME} update_translations) -if(NOT WIN32) +if (NOT WIN32) add_dependencies(update_translations check_qml) -endif() +endif () set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}") target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${LINPHONECXX_INCLUDE_DIRS}" "${LINPHONE_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}") + foreach (package ${QT5_PACKAGES}) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}") # `qt5_create_translation` is provided from `LinguistTools` package. # But the `Qt5::LinguistTools` lib does not exist. Remove it. if (NOT (${package} STREQUAL LinguistTools)) target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES}) - endif() + endif () +endforeach () + +foreach (package ${QT5_PACKAGES_OPTIONAL}) + if ("${Qt5${package}_FOUND}") + message("Optional package ${package} found.") + target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}") + target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES}) + + string(TOUPPER "${package}" INCLUDE_NAME) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_${INCLUDE_NAME}_ENABLED") + else () + message("Optional package ${package} not found.") + endif () endforeach () target_link_libraries(${TARGET_NAME} ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES}) diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index c9cb0c74e..807b40d7d 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -151,9 +151,8 @@ void App::initContentApp () { ); } - // Init core and clipboard. + // Init core. CoreManager::init(this, mParser.value("config")); - Clipboard::init(this); // Init engine content. mEngine = new QQmlApplicationEngine(); @@ -171,9 +170,6 @@ void App::initContentApp () { mEngine->addImageProvider(AvatarProvider::PROVIDER_ID, new AvatarProvider()); mEngine->addImageProvider(ThumbnailProvider::PROVIDER_ID, new ThumbnailProvider()); - mTextToSpeech = new QTextToSpeech(this); - QQmlEngine::setObjectOwnership(mTextToSpeech, QQmlEngine::CppOwnership); - registerTypes(); registerSharedTypes(); @@ -359,8 +355,10 @@ void App::registerTypes () { registerType("SoundPlayer"); registerSingletonType("AudioCodecsModel"); + registerSingletonType("Clipboard"); registerSingletonType("OwnPresenceModel"); registerSingletonType("Presence"); + registerSingletonType("TextToSpeech"); registerSingletonType("TimelineModel"); registerSingletonType("VideoCodecsModel"); @@ -377,7 +375,6 @@ void App::registerSharedTypes () { qInfo() << QStringLiteral("Registering shared types..."); registerSharedSingletonType(App, "App", App::getInstance); - registerSharedSingletonType(Clipboard, "Clipboard", Clipboard::getInstance); registerSharedSingletonType(CoreManager, "CoreManager", CoreManager::getInstance); registerSharedSingletonType(SettingsModel, "SettingsModel", CoreManager::getInstance()->getSettingsModel); registerSharedSingletonType(AccountSettingsModel, "AccountSettingsModel", CoreManager::getInstance()->getAccountSettingsModel); diff --git a/linphone-desktop/src/app/App.hpp b/linphone-desktop/src/app/App.hpp index 881a29793..f712e6faf 100644 --- a/linphone-desktop/src/app/App.hpp +++ b/linphone-desktop/src/app/App.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include "../components/notifier/Notifier.hpp" #include "../externals/single-application/SingleApplication.hpp" @@ -45,8 +44,6 @@ class App : public SingleApplication { Q_PROPERTY(QVariantList availableLocales READ getAvailableLocales CONSTANT); Q_PROPERTY(QString qtVersion READ getQtVersion CONSTANT); - Q_PROPERTY(QTextToSpeech * textToSpeech READ getTextToSpeech CONSTANT); - public: App (int &argc, char *argv[]); ~App (); @@ -89,10 +86,6 @@ signals: void configLocaleChanged (const QString &locale); private: - QTextToSpeech *getTextToSpeech () const { - return mTextToSpeech; - } - void registerTypes (); void registerSharedTypes (); void setTrayIcon (); @@ -118,8 +111,6 @@ private: QVariantList mAvailableLocales; QString mLocale; - QTextToSpeech *mTextToSpeech = nullptr; - QQmlApplicationEngine *mEngine = nullptr; DefaultTranslator *mTranslator = nullptr; @@ -129,6 +120,4 @@ private: QQuickWindow *mSettingsWindow = nullptr; }; -Q_DECLARE_METATYPE(QTextToSpeech *); - #endif // APP_H_ diff --git a/linphone-desktop/src/components/Components.hpp b/linphone-desktop/src/components/Components.hpp index 5d5c3438c..fce91a10d 100644 --- a/linphone-desktop/src/components/Components.hpp +++ b/linphone-desktop/src/components/Components.hpp @@ -40,6 +40,7 @@ #include "settings/AccountSettingsModel.hpp" #include "sip-addresses/SipAddressesProxyModel.hpp" #include "sound-player/SoundPlayer.hpp" +#include "text-to-speech/TextToSpeech.hpp" #include "timeline/TimelineModel.hpp" #endif // COMPONENTS_H_ diff --git a/linphone-desktop/src/components/clipboard/Clipboard.cpp b/linphone-desktop/src/components/clipboard/Clipboard.cpp index 928aa0339..99d707d9a 100644 --- a/linphone-desktop/src/components/clipboard/Clipboard.cpp +++ b/linphone-desktop/src/components/clipboard/Clipboard.cpp @@ -27,19 +27,10 @@ // ============================================================================= -Clipboard *Clipboard::mInstance = nullptr; - Clipboard::Clipboard (QObject *parent) : QObject(parent) { connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &Clipboard::textChanged); } -// ----------------------------------------------------------------------------- - -void Clipboard::init (QObject *parent) { - if (!mInstance) - mInstance = new Clipboard(parent); -} - QString Clipboard::getText () const { return QGuiApplication::clipboard()->text(QClipboard::Clipboard); } diff --git a/linphone-desktop/src/components/clipboard/Clipboard.hpp b/linphone-desktop/src/components/clipboard/Clipboard.hpp index bc9fdf699..f10d0ca20 100644 --- a/linphone-desktop/src/components/clipboard/Clipboard.hpp +++ b/linphone-desktop/src/components/clipboard/Clipboard.hpp @@ -33,25 +33,16 @@ class Clipboard : public QObject { Q_PROPERTY(QString text READ getText WRITE setText NOTIFY textChanged); public: + Clipboard (QObject *parent = Q_NULLPTR); ~Clipboard () = default; - static void init (QObject *parent); - - static Clipboard *getInstance () { - Q_ASSERT(mInstance != nullptr); - return mInstance; - } - signals: void textChanged (); private: - Clipboard (QObject *parent); QString getText () const; void setText (const QString &text); - - static Clipboard *mInstance; }; #endif // ifndef CLIPBOARD_H_ diff --git a/linphone-desktop/src/components/text-to-speech/TextToSpeech.cpp b/linphone-desktop/src/components/text-to-speech/TextToSpeech.cpp new file mode 100644 index 000000000..11eabaf91 --- /dev/null +++ b/linphone-desktop/src/components/text-to-speech/TextToSpeech.cpp @@ -0,0 +1,45 @@ +/* + * TextToSpeech.cpp + * Copyright (C) 2017 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: May 31, 2017 + * Author: Ronan Abhamon + */ + +#ifdef TEXTTOSPEECH_ENABLED + #include +#endif // ifdef TEXTTOSPEECH_ENABLED + +#include "TextToSpeech.hpp" + +// ============================================================================= + +#ifdef TEXTTOSPEECH_ENABLED + TextToSpeech::TextToSpeech (QObject *parent) : QObject(parent) { + mQtTextToSpeech = new QTTextToSpeech(this); + } + + void TextToSpeech::say (const QString &text) { + mQtTextToSpeech->say(text); + } + +#else + TextToSpeech::TextToSpeech (QObject *parent) : QObject(parent) {} + + void TextToSpeech::say (const QString &) {} + +#endif // ifdef TEXTTOSPEECH_ENABLED diff --git a/linphone-desktop/src/components/text-to-speech/TextToSpeech.hpp b/linphone-desktop/src/components/text-to-speech/TextToSpeech.hpp new file mode 100644 index 000000000..287af1aa7 --- /dev/null +++ b/linphone-desktop/src/components/text-to-speech/TextToSpeech.hpp @@ -0,0 +1,45 @@ +/* + * TextToSpeech.hpp + * Copyright (C) 2017 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: May 31, 2017 + * Author: Ronan Abhamon + */ + +#ifndef TEXT_TO_SPEECH_H_ +#define TEXT_TO_SPEECH_H_ + +#include + +// ============================================================================= + +class QTextToSpeech; + +class TextToSpeech : public QObject { + Q_OBJECT; + +public: + TextToSpeech (QObject *parent = Q_NULLPTR); + ~TextToSpeech () = default; + + Q_INVOKABLE void say (const QString &text); + +private: + QTextToSpeech *mQtTextToSpeech = nullptr; +}; + +#endif // ifndef TEXT_TO_SPEECH_H_ diff --git a/linphone-desktop/ui/modules/Linphone/Chat/Message.qml b/linphone-desktop/ui/modules/Linphone/Chat/Message.qml index b69a06e09..4c02b347f 100644 --- a/linphone-desktop/ui/modules/Linphone/Chat/Message.qml +++ b/linphone-desktop/ui/modules/Linphone/Chat/Message.qml @@ -77,7 +77,7 @@ Item { MenuItem { text: qsTr('menuPlayMe') - onTriggered: App.textToSpeech.say($chatEntry.content) + onTriggered: TextToSpeech.say($chatEntry.content) } }