| ... |
... |
@@ -12,7 +12,12 @@ |
|
12
|
12
|
# You should have received a copy of the GNU General Public License
|
|
13
|
13
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
14
|
14
|
|
|
|
15
|
+from __future__ import annotations
|
|
|
16
|
+
|
|
|
17
|
+from typing import cast
|
|
|
18
|
+
|
|
15
|
19
|
import os
|
|
|
20
|
+from enum import IntEnum
|
|
16
|
21
|
|
|
17
|
22
|
from gi.repository import Gdk
|
|
18
|
23
|
from gi.repository import Gtk
|
| ... |
... |
@@ -26,6 +31,24 @@ |
|
26
|
31
|
from .builder import get_builder
|
|
27
|
32
|
|
|
28
|
33
|
|
|
|
34
|
+SOUNDS = {
|
|
|
35
|
+ 'attention_received': _('Attention Message Received'),
|
|
|
36
|
+ 'first_message_received': _('Message Received'),
|
|
|
37
|
+ 'contact_connected': _('Contact Connected'),
|
|
|
38
|
+ 'contact_disconnected': _('Contact Disconnected'),
|
|
|
39
|
+ 'message_sent': _('Message Sent'),
|
|
|
40
|
+ 'muc_message_highlight': _('Group Chat Message Highlight'),
|
|
|
41
|
+ 'muc_message_received': _('Group Chat Message Received'),
|
|
|
42
|
+}
|
|
|
43
|
+
|
|
|
44
|
+
|
|
|
45
|
+class Column(IntEnum):
|
|
|
46
|
+ ENABLED = 0
|
|
|
47
|
+ NAME = 1
|
|
|
48
|
+ PATH = 2
|
|
|
49
|
+ CONFIG = 3
|
|
|
50
|
+
|
|
|
51
|
+
|
|
29
|
52
|
class ManageSounds(Gtk.ApplicationWindow):
|
|
30
|
53
|
def __init__(self, transient_for: Gtk.Window) -> None:
|
|
31
|
54
|
Gtk.ApplicationWindow.__init__(self)
|
| ... |
... |
@@ -65,47 +88,44 @@ def _on_row_changed(model: Gtk.TreeModel, |
|
65
|
88
|
path: Gtk.TreePath,
|
|
66
|
89
|
iter_: Gtk.TreeIter
|
|
67
|
90
|
) -> None:
|
|
68
|
|
- sound_event = model[iter_][3]
|
|
|
91
|
+
|
|
|
92
|
+ sound_event = model[iter_][Column.CONFIG]
|
|
69
|
93
|
app.settings.set_soundevent_setting(sound_event,
|
|
70
|
94
|
'enabled',
|
|
71
|
|
- bool(model[path][0]))
|
|
|
95
|
+ model[path][Column.ENABLED])
|
|
72
|
96
|
app.settings.set_soundevent_setting(sound_event,
|
|
73
|
97
|
'path',
|
|
74
|
|
- model[iter_][2])
|
|
|
98
|
+ model[iter_][Column.PATH])
|
|
75
|
99
|
|
|
76
|
100
|
def _on_toggle(self,
|
|
77
|
101
|
_cell: Gtk.CellRendererToggle,
|
|
78
|
102
|
path: Gtk.TreePath
|
|
79
|
103
|
) -> None:
|
|
|
104
|
+
|
|
80
|
105
|
if self._ui.filechooser.get_filename() is None:
|
|
81
|
106
|
return
|
|
|
107
|
+
|
|
82
|
108
|
model = self._ui.sounds_treeview.get_model()
|
|
83
|
|
- model[path][0] = not model[path][0]
|
|
|
109
|
+ assert model is not None
|
|
|
110
|
+
|
|
|
111
|
+ model[path][Column.ENABLED] = not model[path][Column.ENABLED]
|
|
84
|
112
|
|
|
85
|
113
|
def _fill_sound_treeview(self) -> None:
|
|
86
|
|
- model = self._ui.sounds_treeview.get_model()
|
|
|
114
|
+ model = cast(Gtk.ListStore, self._ui.sounds_treeview.get_model())
|
|
87
|
115
|
model.clear()
|
|
88
|
116
|
|
|
89
|
|
- sounds_dict = {
|
|
90
|
|
- 'attention_received': _('Attention Message Received'),
|
|
91
|
|
- 'first_message_received': _('Message Received'),
|
|
92
|
|
- 'contact_connected': _('Contact Connected'),
|
|
93
|
|
- 'contact_disconnected': _('Contact Disconnected'),
|
|
94
|
|
- 'message_sent': _('Message Sent'),
|
|
95
|
|
- 'muc_message_highlight': _('Group Chat Message Highlight'),
|
|
96
|
|
- 'muc_message_received': _('Group Chat Message Received'),
|
|
97
|
|
- }
|
|
98
|
|
-
|
|
99
|
|
- for sound_event, sound_name in sounds_dict.items():
|
|
|
117
|
+ for sound_event, sound_name in SOUNDS.items():
|
|
100
|
118
|
settings = app.settings.get_soundevent_settings(sound_event)
|
|
101
|
|
- model.append((settings['enabled'],
|
|
|
119
|
+ model.append([settings['enabled'],
|
|
102
|
120
|
sound_name,
|
|
103
|
121
|
settings['path'],
|
|
104
|
|
- sound_event))
|
|
|
122
|
+ sound_event])
|
|
105
|
123
|
|
|
106
|
124
|
def _on_cursor_changed(self, treeview: Gtk.TreeView) -> None:
|
|
107
|
125
|
model, iter_ = treeview.get_selection().get_selected()
|
|
108
|
|
- path_to_snd_file = check_soundfile_path(model[iter_][2])
|
|
|
126
|
+ assert iter_ is not None
|
|
|
127
|
+
|
|
|
128
|
+ path_to_snd_file = check_soundfile_path(model[iter_][Column.PATH])
|
|
109
|
129
|
if path_to_snd_file is None:
|
|
110
|
130
|
self._ui.filechooser.unselect_all()
|
|
111
|
131
|
else:
|
| ... |
... |
@@ -113,26 +133,31 @@ def _on_cursor_changed(self, treeview: Gtk.TreeView) -> None: |
|
113
|
133
|
|
|
114
|
134
|
def _on_file_set(self, button: Gtk.FileChooserButton) -> None:
|
|
115
|
135
|
model, iter_ = self._ui.sounds_treeview.get_selection().get_selected()
|
|
|
136
|
+ assert iter_ is not None
|
|
116
|
137
|
|
|
117
|
138
|
filename = button.get_filename()
|
|
|
139
|
+ assert filename is not None
|
|
|
140
|
+
|
|
118
|
141
|
directory = os.path.dirname(filename)
|
|
119
|
142
|
app.settings.set('last_sounds_dir', directory)
|
|
120
|
143
|
path_to_snd_file = strip_soundfile_path(filename)
|
|
121
|
144
|
|
|
122
|
|
- # set new path to sounds_model
|
|
123
|
|
- model[iter_][2] = str(path_to_snd_file)
|
|
124
|
|
- # set the sound to enabled
|
|
125
|
|
- model[iter_][0] = True
|
|
|
145
|
+ model[iter_][Column.PATH] = str(path_to_snd_file)
|
|
|
146
|
+ model[iter_][Column.ENABLED] = True
|
|
126
|
147
|
|
|
127
|
148
|
def _on_clear(self, _button: Gtk.Button) -> None:
|
|
128
|
149
|
self._ui.filechooser.unselect_all()
|
|
129
|
150
|
model, iter_ = self._ui.sounds_treeview.get_selection().get_selected()
|
|
130
|
|
- model[iter_][2] = ''
|
|
131
|
|
- model[iter_][0] = False
|
|
|
151
|
+ assert iter_ is not None
|
|
|
152
|
+
|
|
|
153
|
+ model[iter_][Column.PATH] = ''
|
|
|
154
|
+ model[iter_][Column.ENABLED] = False
|
|
132
|
155
|
|
|
133
|
156
|
def _on_play(self, _button: Gtk.Button) -> None:
|
|
134
|
157
|
model, iter_ = self._ui.sounds_treeview.get_selection().get_selected()
|
|
135
|
|
- snd_event_config_name = model[iter_][3]
|
|
|
158
|
+ assert iter_ is not None
|
|
|
159
|
+
|
|
|
160
|
+ snd_event_config_name = model[iter_][Column.CONFIG]
|
|
136
|
161
|
play_sound(snd_event_config_name, None, force=True)
|
|
137
|
162
|
|
|
138
|
163
|
def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
|