Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Pass config argument to FreeseerApp to solve the duplicated code prob…
Browse files Browse the repository at this point in the history
…lem when doing the auto language changing.
  • Loading branch information
Cryspia committed Oct 12, 2014
1 parent 9a74a05 commit 9e09fbd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
7 changes: 1 addition & 6 deletions src/freeseer/frontend/configtool/configtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ class ConfigToolApp(FreeseerApp):
'''

def __init__(self, profile, config):
FreeseerApp.__init__(self)
FreeseerApp.__init__(self, config)

# Load Config Stuff
self.profile = profile
self.config = config

icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/freeseer/logo.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Expand Down Expand Up @@ -102,10 +101,6 @@ def __init__(self, profile, config):
language_display_text = translator.translate("Translation", "Language Display Text")
self.generalWidget.languageComboBox.addItem(language_display_text, language)

#There is not config file. Using the auto language changing.
if self.config.default_language == "tr_xx_XX.qm":
self.config.default_language = "tr_" + self.current_language + ".qm"

# Load default language.
actions = self.menuLanguage.actions()
for action in actions:
Expand Down
13 changes: 7 additions & 6 deletions src/freeseer/frontend/qtcommon/FreeseerApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@

class FreeseerApp(QMainWindow):

def __init__(self):
def __init__(self, config):
super(FreeseerApp, self).__init__()
self.config = config
self.icon = QIcon()
self.icon.addPixmap(QPixmap(_fromUtf8(":/freeseer/logo.png")), QIcon.Normal, QIcon.Off)
self.setWindowIcon(self.icon)
Expand Down Expand Up @@ -186,15 +187,15 @@ def setupLanguageMenu(self):

#Auto language changing.
#Ignore the location, only use the language to do the matching.
if self.current_language[:2] == str(language).strip("tr_").rstrip(".qm")[:2]:
if self.config.default_language[3:5] == str(language)[3:5]:
languageDetected = True
#Additional case for Simplified Chinese & Traditional Chinese.
#Traditional Chinese has higher priority
if (self.current_language[:2] != "zh" or
if (self.config.default_language[3:5] != "zh" or
str(language) == "tr_zh_HK.qm" and
self.current_language != "zh_CN"):
self.current_language = str(language).strip("tr_").rstrip(".qm")
self.config.default_language != "tr_zh_CN.qm"):
self.config.default_language = str(language)

#For the system language not included, using English for default.
if not languageDetected:
self.current_language = "en_US"
self.config.default_language = "tr_en_US.qm"
7 changes: 1 addition & 6 deletions src/freeseer/frontend/record/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ class RecordApp(FreeseerApp):
"""Freeseer's main GUI class."""

def __init__(self, profile, config):
FreeseerApp.__init__(self)
FreeseerApp.__init__(self, config)

self.db = profile.get_database()
self.config = config
self.controller = RecordingController(profile, self.db, self.config)

self.recently_recorded_video = None
Expand Down Expand Up @@ -177,10 +176,6 @@ def __init__(self, profile, config):
#
self.connect(self.reportWidget.reportButton, QtCore.SIGNAL("clicked()"), self.report)

#There is not config file. Using the auto language changing.
if self.config.default_language == "tr_xx_XX.qm":
self.config.default_language = "tr_" + self.current_language + ".qm"

self.load_settings()

# Setup spacebar key.
Expand Down
7 changes: 1 addition & 6 deletions src/freeseer/frontend/reporteditor/reporteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ class ReportEditorApp(FreeseerApp):
'''

def __init__(self, config, db):
FreeseerApp.__init__(self)
FreeseerApp.__init__(self,config)

self.config = config
self.db = db

icon = QIcon()
Expand Down Expand Up @@ -101,10 +100,6 @@ def __init__(self, config, db):
self.connect(self.actionExportCsv, SIGNAL('triggered()'), self.export_reports_to_csv)
self.connect(self.editorWidget.editor, SIGNAL('clicked (const QModelIndex&)'), self.editorSelectionChanged)

#There is not config file. Using the auto language changing.
if self.config.default_language == "tr_xx_XX.qm":
self.config.default_language = "tr_" + self.current_language + ".qm"

# Load default language
actions = self.menuLanguage.actions()
for action in actions:
Expand Down
7 changes: 1 addition & 6 deletions src/freeseer/frontend/talkeditor/talkeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
class TalkEditorApp(FreeseerApp):
'''Freeseer talk database editor main gui class'''
def __init__(self, config, db):
FreeseerApp.__init__(self)
FreeseerApp.__init__(self, config)

self.config = config
self.db = db

icon = QIcon()
Expand Down Expand Up @@ -157,10 +156,6 @@ def __init__(self, config, db):
self.newTalkWidget.connect(self.newTalkWidget.addButton, SIGNAL('clicked()'), self.add_talk)
self.newTalkWidget.connect(self.newTalkWidget.cancelButton, SIGNAL('clicked()'), self.newTalkWidget.reject)

#There is not config file. Using the auto language changing.
if self.config.default_language == "tr_xx_XX.qm":
self.config.default_language = "tr_" + self.current_language + ".qm"

# Load default language
actions = self.menuLanguage.actions()
for action in actions:
Expand Down
3 changes: 2 additions & 1 deletion src/freeseer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from freeseer.framework.config.core import Config
from freeseer.framework.config.profile import ProfileManager
from PyQt4.QtCore import QLocale
import freeseer.framework.config.options as options

# TODO: change to config_dir when all the pull requests from UCOSP Fall 2013 are merged in
Expand Down Expand Up @@ -64,4 +65,4 @@ class FreeseerConfig(Config):
record_to_stream_plugin = options.StringOption('RTMP Streaming')
audio_feedback = options.BooleanOption(False)
video_preview = options.BooleanOption(True)
default_language = options.StringOption('tr_xx_XX.qm')
default_language = options.StringOption('tr_'+str(QLocale.system().name())+'.qm')

0 comments on commit 9e09fbd

Please sign in to comment.