diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index ceffc749b..c64d890da 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -56,7 +56,7 @@ if(NOT WIN32) endif() endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG") # ------------------------------------------------------------------------------ # Define packages, libs, sources, headers, resources and languages. diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index a5601d7ad..36a541581 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -99,9 +99,6 @@ void App::initContentApp () { CoreManager::init(this, m_parser.value("config")); qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors(); - // Avoid double free. - m_engine.setObjectOwnership(this, QQmlEngine::CppOwnership); - // Provide `+custom` folders for custom components. { QQmlFileSelector *file_selector = new QQmlFileSelector(&m_engine); @@ -243,8 +240,9 @@ QQuickWindow *App::getCallsWindow () { } QQuickWindow *App::getMainWindow () const { - QQmlApplicationEngine &engine = const_cast(m_engine); - return qobject_cast(engine.rootObjects().at(0)); + return qobject_cast( + const_cast(&m_engine)->rootObjects().at(0) + ); } QQuickWindow *App::getSettingsWindow () { @@ -273,9 +271,36 @@ bool App::hasFocus () const { // ----------------------------------------------------------------------------- +#define REGISTER_EXISTING_SINGLETON(TYPE, NAME, METHOD) qmlRegisterSingletonType( \ + "Linphone", 1, 0, NAME, \ + [](QQmlEngine *, QJSEngine *) -> QObject *{ \ + QObject *object = METHOD(); \ + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); \ + return object; \ + } \ +) + +template +void registerSingletonType (const char *name) { + qmlRegisterSingletonType( + "Linphone", 1, 0, name, + [](QQmlEngine *, QJSEngine *) -> QObject *{ + return new T(); + } + ); +} + void App::registerTypes () { qInfo() << "Registering types..."; + qmlRegisterType("Linphone", 1, 0, "Camera"); + qmlRegisterType("Linphone", 1, 0, "ContactsListProxyModel"); + qmlRegisterType("Linphone", 1, 0, "ChatModel"); + qmlRegisterType("Linphone", 1, 0, "ChatProxyModel"); + qmlRegisterType("Linphone", 1, 0, "SmartSearchBarModel"); + + qRegisterMetaType("ChatModel::EntryType"); + qmlRegisterUncreatableType( "Linphone", 1, 0, "CallModel", "CallModel is uncreatable." ); @@ -289,85 +314,21 @@ void App::registerTypes () { "Linphone", 1, 0, "VcardModel", "VcardModel is uncreatable." ); - qmlRegisterSingletonType( - "Linphone", 1, 0, "App", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return App::getInstance(); - } - ); + registerSingletonType("AccountSettingsModel"); + registerSingletonType("Presence"); + registerSingletonType("PresenceStatusModel"); + registerSingletonType("TimelineModel"); - qmlRegisterSingletonType( - "Linphone", 1, 0, "CoreManager", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return CoreManager::getInstance(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "AccountSettingsModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return new AccountSettingsModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "CallsListModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return CoreManager::getInstance()->getCallsListModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "ContactsListModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return CoreManager::getInstance()->getContactsListModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "Presence", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return new Presence(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "PresenceStatusModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return new PresenceStatusModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "SettingsModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return CoreManager::getInstance()->getSettingsModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "SipAddressesModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return CoreManager::getInstance()->getSipAddressesModel(); - } - ); - - qmlRegisterSingletonType( - "Linphone", 1, 0, "TimelineModel", - [](QQmlEngine *, QJSEngine *) -> QObject *{ - return new TimelineModel(); - } - ); - - qmlRegisterType("Linphone", 1, 0, "Camera"); - qmlRegisterType("Linphone", 1, 0, "ContactsListProxyModel"); - qmlRegisterType("Linphone", 1, 0, "ChatModel"); - qmlRegisterType("Linphone", 1, 0, "ChatProxyModel"); - qmlRegisterType("Linphone", 1, 0, "SmartSearchBarModel"); - - qRegisterMetaType("ChatModel::EntryType"); + REGISTER_EXISTING_SINGLETON(App, "App", App::getInstance); + REGISTER_EXISTING_SINGLETON(CoreManager, "CoreManager", CoreManager::getInstance); + REGISTER_EXISTING_SINGLETON(SettingsModel, "SettingsModel", CoreManager::getInstance()->getSettingsModel); + REGISTER_EXISTING_SINGLETON(SipAddressesModel, "SipAddressesModel", CoreManager::getInstance()->getSipAddressesModel); + REGISTER_EXISTING_SINGLETON(CallsListModel, "CallsListModel", CoreManager::getInstance()->getCallsListModel); + REGISTER_EXISTING_SINGLETON(ContactsListModel, "ContactsListModel", CoreManager::getInstance()->getContactsListModel); } +#undef REGISTER_EXISTING_SINGLETON + // ----------------------------------------------------------------------------- void App::setTrayIcon () { diff --git a/linphone-desktop/src/app/App.hpp b/linphone-desktop/src/app/App.hpp index 9c95c41da..40d3505f2 100644 --- a/linphone-desktop/src/app/App.hpp +++ b/linphone-desktop/src/app/App.hpp @@ -89,15 +89,15 @@ private: } QCommandLineParser m_parser; - QQmlApplicationEngine m_engine; - - DefaultTranslator *m_translator = nullptr; - - Notifier *m_notifier = nullptr; QVariantList m_available_locales; QString m_locale; + QQmlApplicationEngine m_engine; + + DefaultTranslator *m_translator = nullptr; + Notifier *m_notifier = nullptr; + QQuickWindow *m_calls_window = nullptr; QQuickWindow *m_settings_window = nullptr; }; diff --git a/linphone-desktop/src/main.cpp b/linphone-desktop/src/main.cpp index 25f0fb828..b4ec23dcc 100644 --- a/linphone-desktop/src/main.cpp +++ b/linphone-desktop/src/main.cpp @@ -35,11 +35,11 @@ int main (int argc, char *argv[]) { // --------------------------------------------------------------------------- // Options to get a nice video render. -#ifdef _WIN32 - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); -#else - QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true); -#endif + #ifdef _WIN32 + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); + #else + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true); + #endif // ifdef _WIN32 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); {