From 5cf5321c0f4ba38f0f9a05b691234e9b2d930196 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 17 Feb 2019 03:36:23 -0800 Subject: [PATCH] further progress on translation without restart --- oliveglobal.cpp | 9 ++-- ui/mediaiconservice.cpp | 98 ++++++++++++++++++++++------------------- ui/mediaiconservice.h | 2 + 3 files changed, 61 insertions(+), 48 deletions(-) diff --git a/oliveglobal.cpp b/oliveglobal.cpp index 174df5b9f..7cd63139e 100644 --- a/oliveglobal.cpp +++ b/oliveglobal.cpp @@ -119,14 +119,17 @@ void OliveGlobal::load_translation_from_config() { olive::CurrentConfig.language_file : olive::CurrentRuntimeConfig.external_translation_file; + // clear runtime language file so if the user sets a different language, we won't load it next time + olive::CurrentRuntimeConfig.external_translation_file.clear(); + + // remove current translation if there is one + QApplication::removeTranslator(translator.get()); + if (!language_file.isEmpty()) { // translation files are stored relative to app path (see GitHub issue #454) QString full_language_path = QDir(get_app_path()).filePath(language_file); - // remove translation - QApplication::removeTranslator(translator.get()); - // load translation file if (QFileInfo::exists(full_language_path) && translator->load(full_language_path)) { diff --git a/ui/mediaiconservice.cpp b/ui/mediaiconservice.cpp index 6a2578d17..97e11aa6e 100644 --- a/ui/mediaiconservice.cpp +++ b/ui/mediaiconservice.cpp @@ -28,66 +28,74 @@ const int kThrobberSize = 50; std::unique_ptr olive::media_icon_service; MediaIconService::MediaIconService() { - // set up animation timer - throbber_animator_.setInterval(20); - connect(&throbber_animator_, SIGNAL(timeout()), this, SLOT(AnimationUpdate())); + // set up animation timer + throbber_animator_.setInterval(20); + connect(&throbber_animator_, SIGNAL(timeout()), this, SLOT(AnimationUpdate())); - // set up pixmap - throbber_pixmap_ = QPixmap(":/icons/throbber.png"); + // set up pixmap + throbber_pixmap_ = QPixmap(":/icons/throbber.png"); } void MediaIconService::SetMediaIcon(Media *media, int icon_type) { - // if this icon is already part of the throbber animation loop, remove it - if (throbber_items_.contains(media)) { - throbber_items_.removeAll(media); + // if this icon is already part of the throbber animation loop, remove it + if (throbber_items_.contains(media)) { +// throbber_lock_.lock(); - // if we aren't animating anything, no need to run the timer for now - if (throbber_items_.empty()) { - // ensure timer function is called in its own thread - QMetaObject::invokeMethod(&throbber_animator_, "stop", Qt::QueuedConnection); - } + throbber_items_.removeAll(media); + +// throbber_lock_.unlock(); + + // if we aren't animating anything, no need to run the timer for now + if (throbber_items_.empty()) { + // ensure timer function is called in its own thread + QMetaObject::invokeMethod(&throbber_animator_, "stop", Qt::QueuedConnection); } + } - switch (icon_type) { - case ICON_TYPE_VIDEO: - olive::project_model.set_icon(media, QIcon(":/icons/videosource.png")); - break; - case ICON_TYPE_AUDIO: - olive::project_model.set_icon(media, QIcon(":/icons/audiosource.png")); - break; - case ICON_TYPE_IMAGE: - olive::project_model.set_icon(media, QIcon(":/icons/imagesource.png")); - break; - case ICON_TYPE_LOADING: - throbber_items_.append(media); + switch (icon_type) { + case ICON_TYPE_VIDEO: + olive::project_model.set_icon(media, QIcon(":/icons/videosource.png")); + break; + case ICON_TYPE_AUDIO: + olive::project_model.set_icon(media, QIcon(":/icons/audiosource.png")); + break; + case ICON_TYPE_IMAGE: + olive::project_model.set_icon(media, QIcon(":/icons/imagesource.png")); + break; + case ICON_TYPE_LOADING: + throbber_items_.append(media); - // if the animation timer isn't running, start it - if (!throbber_animator_.isActive()) { - // set starting frame to 0 - throbber_animation_frame_ = 0; + // if the animation timer isn't running, start it + if (!throbber_animator_.isActive()) { + // set starting frame to 0 + throbber_animation_frame_ = 0; - // ensure timer function is called in its own thread - QMetaObject::invokeMethod(&throbber_animator_, "start", Qt::QueuedConnection); - } - break; - case ICON_TYPE_ERROR: - olive::project_model.set_icon(media, QIcon(":/icons/error.png")); - break; + // ensure timer function is called in its own thread + QMetaObject::invokeMethod(&throbber_animator_, "start", Qt::QueuedConnection); } + break; + case ICON_TYPE_ERROR: + olive::project_model.set_icon(media, QIcon(":/icons/error.png")); + break; + } - emit IconChanged(); + emit IconChanged(); } void MediaIconService::AnimationUpdate() { - if (throbber_animation_frame_ == kThrobberLimit) { - throbber_animation_frame_ = 0; - } + if (throbber_animation_frame_ == kThrobberLimit) { + throbber_animation_frame_ = 0; + } - QIcon throbber_ico = QIcon(throbber_pixmap_.copy(kThrobberSize*throbber_animation_frame_, 0, kThrobberSize, kThrobberSize)); + QIcon throbber_ico = QIcon(throbber_pixmap_.copy(kThrobberSize*throbber_animation_frame_, 0, kThrobberSize, kThrobberSize)); - for (int i=0;i #include +#include #include "project/media.h" @@ -49,6 +50,7 @@ private: QVector throbber_items_; QTimer throbber_animator_; QPixmap throbber_pixmap_; + QMutex throbber_lock_; }; namespace olive {