Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
f33d34c3
Commit
f33d34c3
authored
Oct 12, 2022
by
Tijmen de Mes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added preference for changing interface language
parent
97e33b18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
168 additions
and
11 deletions
+168
-11
preferences.py
blink/preferences.py
+66
-1
preferences.ui
resources/preferences.ui
+102
-10
No files found.
blink/preferences.py
View file @
f33d34c3
import
os
import
re
import
urllib.parse
from
PyQt5
import
uic
from
PyQt5.QtCore
import
Qt
,
QEvent
,
QRegExp
from
PyQt5.QtGui
import
QFont
,
QRegExpValidator
,
QValidator
from
PyQt5.QtWidgets
import
QActionGroup
,
QButtonGroup
,
QFileDialog
,
QListView
,
QListWidgetItem
,
QMessageBox
,
QSpinBox
,
QStyle
,
QStyleOptionComboBox
,
QStyledItemDelegate
from
PyQt5.QtWidgets
import
QActionGroup
,
Q
Application
,
Q
ButtonGroup
,
QFileDialog
,
QListView
,
QListWidgetItem
,
QMessageBox
,
QSpinBox
,
QStyle
,
QStyleOptionComboBox
,
QStyledItemDelegate
from
application
import
log
from
application.notification
import
IObserver
,
NotificationCenter
...
...
@@ -33,6 +34,35 @@ from blink.util import QSingleton, call_in_gui_thread, run_in_gui_thread
__all__
=
[
'PreferencesWindow'
,
'AccountListView'
,
'SIPPortEditor'
]
class
LanguageError
(
Exception
):
pass
class
Language
(
object
):
filename_regex
=
re
.
compile
(
r'(\w+)_(\w+).*\.(\w+$)'
)
mapping
=
{
"default"
:
"System default"
,
"en"
:
"English"
,
"nl"
:
"Nederlands"
,
"ro"
:
"Română"
}
def
__init__
(
self
,
file
):
print
(
file
)
if
file
in
[
'default'
,
'en'
]:
self
.
name
=
self
.
mapping
[
file
]
self
.
language_code
=
file
return
match
=
self
.
filename_regex
.
match
(
file
)
if
match
[
3
]
!=
'qm'
:
raise
LanguageError
(
'Unsupported file'
)
try
:
self
.
name
=
self
.
mapping
[
match
[
2
]]
except
KeyError
:
raise
LanguageError
(
'Unsupported file'
)
self
.
language_code
=
match
[
2
]
# LineEdit and ComboBox validators
#
class
IDDPrefixValidator
(
QRegExpValidator
):
...
...
@@ -354,6 +384,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
# Interface
self
.
history_name_and_uri_button
.
clicked
.
connect
(
self
.
_SH_HistoryNameAndUriButtonClicked
)
self
.
language_button
.
activated
[
int
]
.
connect
(
self
.
_SH_LanguageButtonActivated
)
# Setup initial state (show the accounts page right after start)
self
.
accounts_action
.
trigger
()
...
...
@@ -439,6 +470,19 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self
.
idd_prefix_button
.
setValidator
(
IDDPrefixValidator
(
self
))
self
.
prefix_button
.
setValidator
(
PrefixValidator
(
self
))
# Languages
self
.
language_button
.
clear
()
languages_path
=
Resources
.
get
(
'i18n'
)
self
.
language_button
.
addItem
(
'System Default'
,
Language
(
'default'
))
self
.
language_button
.
addItem
(
'English'
,
Language
(
'en'
))
for
language_file
in
os
.
listdir
(
languages_path
):
try
:
language
=
Language
(
language_file
)
except
LanguageError
:
pass
else
:
self
.
language_button
.
addItem
(
language
.
name
,
language
)
# Adding the button group in designer has issues on Ubuntu 10.04
self
.
sip_transports_button_group
=
QButtonGroup
(
self
)
self
.
sip_transports_button_group
.
setObjectName
(
"sip_transports_button_group"
)
...
...
@@ -781,6 +825,13 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self
.
history_name_and_uri_button
.
setChecked
(
blink_settings
.
interface
.
show_history_name_and_uri
)
language_index
=
self
.
language_button
.
findText
(
Language
.
mapping
[
blink_settings
.
interface
.
language
])
if
language_index
==
-
1
:
language_index
=
0
blink_settings
.
interface
.
language
=
self
.
language_button
.
itemData
(
language_index
)
.
language_code
blink_settings
.
save
()
self
.
language_button
.
setCurrentIndex
(
language_index
)
def
load_account_settings
(
self
,
account
):
"""Load the account settings from configuration into the UI controls"""
settings
=
SIPSimpleSettings
()
...
...
@@ -1871,6 +1922,20 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
settings
.
interface
.
show_history_name_and_uri
=
checked
settings
.
save
()
def
_SH_LanguageButtonActivated
(
self
,
index
):
data
=
self
.
language_button
.
itemData
(
index
)
settings
=
BlinkSettings
()
if
data
.
language_code
!=
settings
.
interface
.
language
:
settings
.
interface
.
language
=
data
.
language_code
settings
.
save
()
title
=
"Restart required"
question
=
"The application language was changed. A restart is required to apply the change. Would you like to restart now?"
if
QMessageBox
.
question
(
self
,
title
,
question
)
==
QMessageBox
.
No
:
return
blink
=
QApplication
.
instance
()
blink
.
restart
()
@
run_in_gui_thread
def
handle_notification
(
self
,
notification
):
handler
=
getattr
(
self
,
'_NH_
%
s'
%
notification
.
name
,
Null
)
...
...
resources/preferences.ui
View file @
f33d34c3
...
...
@@ -3724,6 +3724,19 @@
<property
name=
"spacing"
>
<number>
5
</number>
</property>
<item
row=
"1"
column=
"0"
>
<widget
class=
"Line"
name=
"line_14"
>
<property
name=
"baseSize"
>
<size>
<width>
0
</width>
<height>
10
</height>
</size>
</property>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_6"
>
<property
name=
"font"
>
...
...
@@ -3737,7 +3750,86 @@
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
>
<item
row=
"6"
column=
"0"
>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout"
>
<item>
<widget
class=
"QLabel"
name=
"label_8"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Preferred"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"font"
>
<font>
<weight>
50
</weight>
<bold>
false
</bold>
</font>
</property>
<property
name=
"text"
>
<string>
Interface Language:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item>
<widget
class=
"QComboBox"
name=
"language_button"
>
<property
name=
"currentText"
>
<string>
System Default
</string>
</property>
<property
name=
"currentIndex"
>
<number>
0
</number>
</property>
<property
name=
"sizeAdjustPolicy"
>
<enum>
QComboBox::AdjustToContents
</enum>
</property>
<item>
<property
name=
"text"
>
<string>
System Default
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string
notr=
"true"
>
English
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string
notr=
"true"
comment=
"nl"
>
Nederlands
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string
notr=
"true"
comment=
"ro"
>
Română
</string>
</property>
</item>
</widget>
</item>
<item>
<spacer
name=
"horizontalSpacer_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item
row=
"5"
column=
"0"
>
<widget
class=
"Line"
name=
"line_15"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"8"
column=
"0"
>
<spacer
name=
"verticalSpacer_5"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
...
...
@@ -3757,16 +3849,16 @@
</property>
</widget>
</item>
<item
row=
"
1
"
column=
"0"
>
<widget
class=
"
Line"
name=
"line_14
"
>
<property
name=
"
baseSize
"
>
<
size
>
<w
idth>
0
</width
>
<
height>
10
</height
>
</
size
>
<item
row=
"
4
"
column=
"0"
>
<widget
class=
"
QLabel"
name=
"label_7
"
>
<property
name=
"
font
"
>
<
font
>
<w
eight>
75
</weight
>
<
bold>
true
</bold
>
</
font
>
</property>
<property
name=
"
orientation
"
>
<
enum>
Qt::Horizontal
</enum
>
<property
name=
"
text
"
>
<
string>
Localization
</string
>
</property>
</widget>
</item>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment