Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2020-08-13 18:21:22 +0300
committerlovetox <philipp@hoerist.com>2020-08-14 23:30:43 +0300
commite504c5b3ebc742c2d5b9f93a617fb58e89d2c4ed (patch)
tree355e164407bfff6cdef34ebc3b27d3ce1ae9d82a
parent5d3feb2cdc6b094a6a52ad47d510428756109234 (diff)
Refactor TimeoutWindow
- Remove source when timeout is stopped - Adapt StatusChange dialog
-rw-r--r--gajim/data/gui/status_change_window.ui2
-rw-r--r--gajim/gtk/dialogs.py35
-rw-r--r--gajim/gtk/status_change.py24
3 files changed, 32 insertions, 29 deletions
diff --git a/gajim/data/gui/status_change_window.ui b/gajim/data/gui/status_change_window.ui
index 1a8dc7537..b27c8f832 100644
--- a/gajim/data/gui/status_change_window.ui
+++ b/gajim/data/gui/status_change_window.ui
@@ -48,7 +48,7 @@
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="popover">preset_popover</property>
- <signal name="toggled" handler="_stop_timeout" swapped="no"/>
+ <signal name="toggled" handler="stop_timeout" swapped="no"/>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
diff --git a/gajim/gtk/dialogs.py b/gajim/gtk/dialogs.py
index d01602354..4294de6d1 100644
--- a/gajim/gtk/dialogs.py
+++ b/gajim/gtk/dialogs.py
@@ -524,14 +524,21 @@ class TimeoutWindow:
Derived windows close automatically after reaching the timeout
"""
def __init__(self, timeout):
- self.countdown_left = timeout
- self.countdown_enabled = True
self.title_text = ''
+ self._countdown_left = timeout
+ self._timeout_source_id = None
- def run_timeout(self):
- if self.countdown_left > 0:
+ def start_timeout(self):
+ if self._countdown_left > 0:
self.countdown()
- GLib.timeout_add_seconds(1, self.countdown)
+ self._timeout_source_id = GLib.timeout_add_seconds(
+ 1, self.countdown)
+
+ def stop_timeout(self, *args, **kwargs):
+ if self._timeout_source_id is not None:
+ GLib.source_remove(self._timeout_source_id)
+ self._timeout_source_id = None
+ self.set_title(self.title_text)
def on_timeout(self):
"""
@@ -539,17 +546,15 @@ class TimeoutWindow:
"""
def countdown(self):
- if self.countdown_enabled:
- if self.countdown_left <= 0:
- self.on_timeout()
- return False
- self.set_title('%s [%s]' % (
- self.title_text, str(self.countdown_left)))
- self.countdown_left -= 1
- return True
+ if self._countdown_left <= 0:
+ self._timeout_source_id = None
+ self.on_timeout()
+ return False
- self.set_title(self.title_text)
- return False
+ self.set_title('%s [%s]' % (
+ self.title_text, str(self._countdown_left)))
+ self._countdown_left -= 1
+ return True
class ShortcutsWindow:
diff --git a/gajim/gtk/status_change.py b/gajim/gtk/status_change.py
index 927215418..b0b2bf612 100644
--- a/gajim/gtk/status_change.py
+++ b/gajim/gtk/status_change.py
@@ -100,21 +100,18 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
self._ui.pep_grid.set_no_show_all(True)
self._ui.pep_grid.hide()
- self._message_buffer.connect('changed', self._stop_timeout)
+ self._message_buffer.connect('changed', self.stop_timeout)
self.connect('key-press-event', self._on_key_press)
self._ui.connect_signals(self)
self.show_all()
- self.run_timeout()
+ self.start_timeout()
def on_timeout(self):
self._change_status()
- def _stop_timeout(self, *args):
- self.countdown_enabled = False
-
def _on_key_press(self, _widget, event):
- self.countdown_enabled = False
+ self.stop_timeout()
if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter):
if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
self._change_status()
@@ -374,7 +371,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
self._ui.mood_button_label.set_text(_('No mood'))
def _on_preset_select(self, widget):
- self.countdown_enabled = False
+ self.stop_timeout()
self._ui.preset_popover.popdown()
name = widget.get_name()
self._message_buffer.set_text(self._preset_messages_dict[name][0])
@@ -390,13 +387,13 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
self._ui.mood_page_button.set_sensitive(self._pep_dict['mood'])
def _on_preset_remove(self, widget):
- self.countdown_enabled = False
+ self.stop_timeout()
name = widget.get_name()
app.config.del_per('statusmsg', name)
self._get_presets()
def _on_save_as_preset_clicked(self, _widget):
- self.countdown_enabled = False
+ self.stop_timeout()
start_iter, finish_iter = self._message_buffer.get_bounds()
message_text = self._message_buffer.get_text(
start_iter, finish_iter, True)
@@ -452,7 +449,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
transient_for=self).show()
def _on_activity_page_clicked(self, _widget):
- self.countdown_enabled = False
+ self.stop_timeout()
self._ui.status_stack.set_visible_child_full(
'activity-page',
Gtk.StackTransitionType.SLIDE_LEFT)
@@ -467,7 +464,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
self._pep_dict['subactivity'] = ''
def _on_mood_page_clicked(self, _widget):
- self.countdown_enabled = False
+ self.stop_timeout()
self._ui.status_stack.set_visible_child_full(
'mood-page',
Gtk.StackTransitionType.SLIDE_LEFT)
@@ -487,11 +484,11 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
self._draw_mood()
def _on_activity_switch(self, switch, *args):
- self.countdown_enabled = False
+ self.stop_timeout()
self._ui.activity_page_button.set_sensitive(switch.get_active())
def _on_mood_switch(self, switch, *args):
- self.countdown_enabled = False
+ self.stop_timeout()
self._ui.mood_page_button.set_sensitive(switch.get_active())
def _send_user_mood(self):
@@ -512,6 +509,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
client.set_user_activity(activity)
def _change_status(self, *args):
+ self.stop_timeout()
beg, end = self._message_buffer.get_bounds()
message = self._message_buffer.get_text(beg, end, True).strip()
message = remove_invalid_xml_chars(message)