further progress on translation without restart

This commit is contained in:
itsmattkc
2019-02-17 03:36:23 -08:00
parent eb55a89cfd
commit 5cf5321c0f
3 changed files with 61 additions and 48 deletions
+6 -3
View File
@@ -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)) {
+53 -45
View File
@@ -28,66 +28,74 @@ const int kThrobberSize = 50;
std::unique_ptr<MediaIconService> 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<throbber_items_.size();i++) {
olive::project_model.set_icon(throbber_items_.at(i), throbber_ico);
}
// throbber_lock_.lock();
throbber_animation_frame_++;
for (int i=0;i<throbber_items_.size();i++) {
olive::project_model.set_icon(throbber_items_.at(i), throbber_ico);
}
// throbber_lock_.unlock();
throbber_animation_frame_++;
}
+2
View File
@@ -23,6 +23,7 @@
#include <QObject>
#include <QTimer>
#include <QMutex>
#include "project/media.h"
@@ -49,6 +50,7 @@ private:
QVector<Media*> throbber_items_;
QTimer throbber_animator_;
QPixmap throbber_pixmap_;
QMutex throbber_lock_;
};
namespace olive {