diff --git a/Linphone/CMakeLists.txt b/Linphone/CMakeLists.txt index 5b3e60ebb..4674ff1f7 100644 --- a/Linphone/CMakeLists.txt +++ b/Linphone/CMakeLists.txt @@ -22,7 +22,7 @@ set(APP_TARGETS ${LinphoneCxx_TARGET} ${LibLinphone_TARGET})#MediastreamerUtils set(QT_DEFAULT_MAJOR_VERSION 6) -set(QT_PACKAGES Core Quick Qml Widgets Svg Multimedia Test NetworkAuth)# Search Core at first for initialize Qt scripts for next find_packages. +set(QT_PACKAGES Core Quick Qml Widgets Svg Multimedia Test NetworkAuth Concurrent)# Search Core at first for initialize Qt scripts for next find_packages. if (UNIX AND NOT APPLE) list(APPEND QT_PACKAGES DBus) endif() diff --git a/Linphone/core/logger/QtLogger.cpp b/Linphone/core/logger/QtLogger.cpp index d3b1e1367..d4295d8c8 100644 --- a/Linphone/core/logger/QtLogger.cpp +++ b/Linphone/core/logger/QtLogger.cpp @@ -88,7 +88,7 @@ QString QtLogger::formatLog(QString contextFile, int contextLine, QString msg) { void QtLogger::onQtLog(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString out; QString message = QtLogger::formatLog(context.file, context.line, msg); - if (gLogger.mVerboseEnabled) { + if (gLogger.mVerboseEnabled || !gLogger.isSignalConnected(QMetaMethod::fromSignal(&QtLogger::qtLogReceived))) { gLogger.printLog(&out, Constants::AppDomain, LinphoneEnums::toLinphone(type), Utils::appStringToCoreString(message)); } diff --git a/Linphone/core/timezone/TimeZoneList.cpp b/Linphone/core/timezone/TimeZoneList.cpp index 504665352..e98ef41a3 100644 --- a/Linphone/core/timezone/TimeZoneList.cpp +++ b/Linphone/core/timezone/TimeZoneList.cpp @@ -21,7 +21,10 @@ #include "TimeZoneList.hpp" #include "core/App.hpp" +#include #include +#include +#include // ============================================================================= @@ -37,7 +40,8 @@ QSharedPointer TimeZoneList::create() { TimeZoneList::TimeZoneList(QObject *parent) : ListProxy(parent) { App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership); - initTimeZones(); + // There is too much items (more than 400) to be sort in main thread. Dispatch the process. + QFuture future = QtConcurrent::run([this]() { initTimeZones(); }); } TimeZoneList::~TimeZoneList() { @@ -47,6 +51,8 @@ TimeZoneList::~TimeZoneList() { void TimeZoneList::initTimeZones() { QList> models; + QElapsedTimer benchmark; + benchmark.start(); for (auto id : QTimeZone::availableTimeZoneIds()) { auto model = QSharedPointer::create(QTimeZone(id)); if (std::find_if(mList.begin(), mList.end(), [id](const QSharedPointer &a) { @@ -57,7 +63,16 @@ void TimeZoneList::initTimeZones() { } } } - resetData(models); + std::sort(models.begin(), models.end(), [](QSharedPointer a, QSharedPointer b) { + auto tA = a.objectCast(); + auto tB = b.objectCast(); + auto timeA = tA->getStandardTimeOffset() / 3600; + auto timeB = tB->getStandardTimeOffset() / 3600; + return timeA < timeB || (timeA == timeB && tA->getCountryName() < tB->getCountryName()); + }); + lDebug() << log().arg("Sorting %1 TZ : %2ms").arg(models.size()).arg(benchmark.elapsed()); + // Reset models inside main thread. + QMetaObject::invokeMethod(this, [this, models]() { resetData(models); }); } QHash TimeZoneList::roleNames() const { @@ -73,11 +88,11 @@ QVariant TimeZoneList::data(const QModelIndex &index, int role) const { if (!index.isValid() || row < 0 || row >= mList.count()) return QVariant(); auto timeZoneModel = getAt(row); if (!timeZoneModel) return QVariant(); - int offset = timeZoneModel->getStandardTimeOffset() / 3600; - int absOffset = std::abs(offset); if (role == Qt::DisplayRole + 1) { - return QVariant::fromValue(new TimeZoneModel(timeZoneModel->getTimeZone())); + return QVariant::fromValue(timeZoneModel.get()); } else { + int offset = timeZoneModel->getStandardTimeOffset() / 3600; + int absOffset = std::abs(offset); return QStringLiteral("(GMT%1%2%3:00) %4 %5") .arg(offset >= 0 ? "+" : "-") .arg(absOffset < 10 ? "0" : "") diff --git a/Linphone/core/timezone/TimeZoneProxy.cpp b/Linphone/core/timezone/TimeZoneProxy.cpp index d8d8ef3d7..13b8e0662 100644 --- a/Linphone/core/timezone/TimeZoneProxy.cpp +++ b/Linphone/core/timezone/TimeZoneProxy.cpp @@ -26,7 +26,8 @@ TimeZoneProxy::TimeZoneProxy(QObject *parent) : LimitProxy(parent) { mList = TimeZoneList::create(); - setSourceModels(new SortFilterList(mList.get(), Qt::AscendingOrder)); + auto a = new SortFilterList(mList.get()); // Avoid using sort because it is too slow + setSourceModels(a); } // ----------------------------------------------------------------------------- diff --git a/Linphone/main.cpp b/Linphone/main.cpp index 347add5d5..85c70da7c 100644 --- a/Linphone/main.cpp +++ b/Linphone/main.cpp @@ -37,12 +37,8 @@ void cleanStream() { } #endif } -void fallbackLog(QtMsgType type, const QMessageLogContext &context, const QString &msg) { - QString message = QtLogger::formatLog(context.file, context.line, msg); - std::cout << message.toStdString() << std::endl; -} + int main(int argc, char *argv[]) { - qInstallMessageHandler(fallbackLog); // Use for messages prior QCoreApplication generation. /* #if defined _WIN32 // log in console only if launched from console diff --git a/Linphone/view/Control/Button/ComboBox.qml b/Linphone/view/Control/Button/ComboBox.qml index 51a589c04..2ebb1e015 100644 --- a/Linphone/view/Control/Button/ComboBox.qml +++ b/Linphone/view/Control/Button/ComboBox.qml @@ -23,6 +23,7 @@ Control.ComboBox { onCurrentIndexChanged: { var item = model[currentIndex] if (!item) item = model.getAt(currentIndex) + if (!item) return selectedItemText.text = item.text ? item.text : item @@ -142,7 +143,7 @@ Control.ComboBox { clip: true implicitHeight: contentHeight height: contentHeight - model: mainItem.model + model: visible? mainItem.model : [] currentIndex: mainItem.highlightedIndex >= 0 ? mainItem.highlightedIndex : 0 highlightFollowsCurrentItem: true highlightMoveDuration: -1 diff --git a/Linphone/view/Page/Form/Meeting/MeetingForm.qml b/Linphone/view/Page/Form/Meeting/MeetingForm.qml index f44a7edc6..31ebe74a9 100644 --- a/Linphone/view/Page/Form/Meeting/MeetingForm.qml +++ b/Linphone/view/Page/Form/Meeting/MeetingForm.qml @@ -204,7 +204,7 @@ FocusScope { constantImageSource: AppIcons.globe weight: 700 * DefaultStyle.dp leftMargin: 0 - currentIndex: mainItem.conferenceInfoGui ? model.getIndex(mainItem.conferenceInfoGui.core.timeZoneModel) : -1 + currentIndex: mainItem.conferenceInfoGui && model.count > 0 ? model.getIndex(mainItem.conferenceInfoGui.core.timeZoneModel) : -1 background: Rectangle { visible: parent.hovered || parent.down anchors.fill: parent @@ -212,6 +212,7 @@ FocusScope { } model: TimeZoneProxy{ } + visible: model.count > 0 onCurrentIndexChanged: { var modelIndex = timeZoneCbox.model.index(currentIndex, 0) mainItem.conferenceInfoGui.core.timeZoneModel = timeZoneCbox.model.data(modelIndex, Qt.DisplayRole + 1)