From 7c496001356b7f650be327e5ea6a456ef11aba5a Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 14 Feb 2008 19:18:07 +0000 Subject: [PATCH] use timeout_add_seconds instead of timeout_add (when it's available), more efficient. fixes #3734, #3736 --- src/chat_control.py | 4 ++-- src/common/zeroconf/connection_zeroconf.py | 2 +- src/dialogs.py | 4 ++-- src/disco.py | 6 +++--- src/gajim.py | 16 ++++++++++------ src/music_track_listener.py | 4 ++-- src/profile_window.py | 4 ++-- src/roster_window.py | 4 ++-- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 55f1a53a8..20b3c33c0 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1134,9 +1134,9 @@ class ChatControl(ChatControlBase): self.mouse_over_in_last_30_secs = True def _schedule_activity_timers(self): - self.possible_paused_timeout_id = gobject.timeout_add(5000, + self.possible_paused_timeout_id = gobject.timeout_add_seconds(5, self.check_for_possible_paused_chatstate, None) - self.possible_inactive_timeout_id = gobject.timeout_add(30000, + self.possible_inactive_timeout_id = gobject.timeout_add_seconds(30, self.check_for_possible_inactive_chatstate, None) def update_ui(self): diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 04294118c..717478ad5 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -277,7 +277,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): # refresh all contacts data every five seconds self.call_resolve_timeout = True - gobject.timeout_add(5000, self._on_resolve_timeout) + gobject.timeout_add_seconds(5, self._on_resolve_timeout) return True def disconnect(self, on_purpose = False): diff --git a/src/dialogs.py b/src/dialogs.py index 7cdcb39cf..15baf1112 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1942,8 +1942,8 @@ class PopupNotificationWindow: xml.signal_autoconnect(self) self.window.show_all() - timeout = gajim.config.get('notification_timeout') * 1000 # make it ms - gobject.timeout_add(timeout, self.on_timeout) + timeout = gajim.config.get('notification_timeout') + gobject.timeout_add_seconds(timeout, self.on_timeout) def on_close_button_clicked(self, widget): self.adjust_height_and_move_popup_notification_windows() diff --git a/src/disco.py b/src/disco.py index cc4368b47..faa320e5c 100644 --- a/src/disco.py +++ b/src/disco.py @@ -152,7 +152,7 @@ class CacheDictionary: if item.source: gobject.source_remove(item.source) if self.lifetime: - source = gobject.timeout_add(self.lifetime, self._expire_timeout, key) + source = gobject.timeout_add_seconds(self.lifetime/1000, self._expire_timeout, key) item.source = source def __getitem__(self, key): @@ -1364,12 +1364,12 @@ class ToplevelAgentBrowser(AgentBrowser): fraction = float(self._progress) / float(self._total_items) if self._progress >= self._total_items: # We show the progressbar for just a bit before hiding it. - id = gobject.timeout_add(1500, self._hide_progressbar_cb) + id = gobject.timeout_add_seconds(2, self._hide_progressbar_cb) self._progressbar_sourceid = id else: self.window.progressbar.show() # Hide the progressbar if we're timing out anyways. (20 secs) - id = gobject.timeout_add(20000, self._hide_progressbar_cb) + id = gobject.timeout_add_seconds(20, self._hide_progressbar_cb) self._progressbar_sourceid = id self.window.progressbar.set_fraction(fraction) diff --git a/src/gajim.py b/src/gajim.py index 7da613341..7258df5f1 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -218,6 +218,10 @@ if '.svn' in os.listdir(path) or '_svn' in os.listdir(path): del path import gobject +if not hasattr(gobject, 'timeout_add_seconds'): + def timeout_add_seconds_fake(time_sec, *args): + return gobject.timeout_add(time_sec * 1000, *args) + gobject.timeout_add_seconds = timeout_add_seconds_fake import re import signal @@ -533,7 +537,7 @@ class Interface: # we stop blocking notifications of any kind # this prevents from getting the roster items as 'just signed in' # contacts. 30 seconds should be enough time - gobject.timeout_add(30000, self.unblock_signed_in_notifications, account) + gobject.timeout_add_seconds(30, self.unblock_signed_in_notifications, account) # sensitivity for this menuitem model[self.roster.status_message_menuitem_iter][3] = True @@ -648,7 +652,7 @@ class Interface: gajim.newly_added[account].append(contact1.jid) if contact1.jid in gajim.to_be_removed[account]: gajim.to_be_removed[account].remove(contact1.jid) - gobject.timeout_add(5000, self.roster.remove_newly_added, + gobject.timeout_add_seconds(5, self.roster.remove_newly_added, contact1.jid, account) elif old_show > 1 and new_show == 0 and gajim.connections[account].\ connected > 1: @@ -657,7 +661,7 @@ class Interface: if contact1.jid in gajim.newly_added[account]: gajim.newly_added[account].remove(contact1.jid) self.roster.draw_contact(contact1.jid, account) - gobject.timeout_add(5000, self.roster.really_remove_contact, + gobject.timeout_add_seconds(5, self.roster.really_remove_contact, contact1, account) contact1.show = array[1] contact1.status = status_message @@ -684,7 +688,7 @@ class Interface: # for 30s account_ji = account + '/' + ji gajim.block_signed_in_notifications[account_ji] = True - gobject.timeout_add(30000, self.unblock_signed_in_notifications, + gobject.timeout_add_seconds(30, self.unblock_signed_in_notifications, account_ji) locations = (self.instances, self.instances[account]) for location in locations: @@ -2948,8 +2952,8 @@ class Interface: if os.name == 'nt': gobject.timeout_add(200, self.process_connections) else: - gobject.timeout_add(2000, self.process_connections) - gobject.timeout_add(10000, self.read_sleepy) + gobject.timeout_add_seconds(2, self.process_connections) + gobject.timeout_add_seconds(10, self.read_sleepy) if __name__ == '__main__': def sigint_cb(num, stack): diff --git a/src/music_track_listener.py b/src/music_track_listener.py index 1867db981..deb7b7bc1 100644 --- a/src/music_track_listener.py +++ b/src/music_track_listener.py @@ -87,13 +87,13 @@ class MusicTrackListener(gobject.GObject): self.current_banshee_title = '' self.banshee_paused_before = False self.banshee_is_here = False - gobject.timeout_add(10000, self._check_if_banshee_bus) + gobject.timeout_add_seconds(10, self._check_if_banshee_bus) if self.dubus_methods.NameHasOwner('org.gnome.Banshee'): self._get_banshee_bus() self.banshee_is_here = True # Otherwise, it opens Banshee! self.banshee_props ={} - gobject.timeout_add(1000, self._banshee_check_track_status) + gobject.timeout_add_seconds(1, self._banshee_check_track_status) def _check_if_banshee_bus(self): if self.dubus_methods.NameHasOwner('org.gnome.Banshee'): diff --git a/src/profile_window.py b/src/profile_window.py index 8fa581d49..61ffcc19d 100644 --- a/src/profile_window.py +++ b/src/profile_window.py @@ -248,7 +248,7 @@ class ProfileWindow: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _('Information received')) - self.remove_statusbar_timeout_id = gobject.timeout_add(3000, + self.remove_statusbar_timeout_id = gobject.timeout_add_seconds(3, self.remove_statusbar, self.message_id) gobject.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() @@ -344,7 +344,7 @@ class ProfileWindow: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _('Information NOT published')) - self.remove_statusbar_timeout_id = gobject.timeout_add(3000, + self.remove_statusbar_timeout_id = gobject.timeout_add_seconds(3, self.remove_statusbar, self.message_id) if self.update_progressbar_timeout_id is not None: gobject.source_remove(self.update_progressbar_timeout_id) diff --git a/src/roster_window.py b/src/roster_window.py index c58373b11..cb56308a7 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -5620,10 +5620,10 @@ class RosterWindow: ## accounts has no effect until they are connected. st = gajim.config.get('set_status_msg_from_current_music_track') if st: - gobject.timeout_add(1000, + gobject.timeout_add_seconds(1, self.enable_syncing_status_msg_from_current_music_track, st) else: - gobject.timeout_add(1000, + gobject.timeout_add_seconds(1, self.enable_syncing_status_msg_from_lastfm, gajim.config.get('set_status_msg_from_lastfm'))