diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2008-10-13 15:55:08 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-10-13 15:55:08 +0800 |
commit | 91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb (patch) | |
tree | a3d5ffb8a70bf11670bd6f75739013bb4a65b13e /libempathy | |
parent | 8ed3271c0c6387dba8a163f0405ac83828898f93 (diff) | |
download | gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar.gz gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar.bz2 gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar.lz gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar.xz gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.tar.zst gsoc2013-empathy-91ecb23e1dbfdff66bf480d856f0f6b918ca0dbb.zip |
chatroom-mgr: use a save timer instead of saving the file directly
svn path=/trunk/; revision=1567
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-chatroom-manager.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index a0dd00049..fa12cd277 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -39,11 +39,14 @@ #define CHATROOMS_XML_FILENAME "chatrooms.xml" #define CHATROOMS_DTD_FILENAME "empathy-chatroom-manager.dtd" +#define SAVE_TIMER 4 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatroomManager) typedef struct { GList *chatrooms; gchar *file; + /* source id of the autosave timer */ + gint save_timer_id; } EmpathyChatroomManagerPriv; static void chatroom_manager_finalize (GObject *object); @@ -203,10 +206,19 @@ empathy_chatroom_manager_init (EmpathyChatroomManager *manager) static void chatroom_manager_finalize (GObject *object) { + EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object); EmpathyChatroomManagerPriv *priv; priv = GET_PRIV (object); + if (priv->save_timer_id > 0) + { + /* have to save before destroy the object */ + g_source_remove (priv->save_timer_id); + priv->save_timer_id = 0; + chatroom_manager_file_save (self); + } + g_list_foreach (priv->chatrooms, (GFunc) g_object_unref, NULL); g_list_free (priv->chatrooms); g_free (priv->file); @@ -232,12 +244,37 @@ empathy_chatroom_manager_new (const gchar *file) return manager; } +static gboolean +save_timeout (EmpathyChatroomManager *self) +{ + EmpathyChatroomManagerPriv *priv = GET_PRIV (self); + + priv->save_timer_id = 0; + chatroom_manager_file_save (self); + + return FALSE; +} + +static void +reset_save_timeout (EmpathyChatroomManager *self) +{ + EmpathyChatroomManagerPriv *priv = GET_PRIV (self); + + if (priv->save_timer_id > 0) + { + g_source_remove (priv->save_timer_id); + } + + priv->save_timer_id = g_timeout_add_seconds (SAVE_TIMER, + (GSourceFunc) save_timeout, self); +} + static void chatroom_favorite_changed_cb (EmpathyChatroom *chatroom, GParamSpec *spec, EmpathyChatroomManager *self) { - chatroom_manager_file_save (self); + reset_save_timeout (self); } static void @@ -275,7 +312,7 @@ empathy_chatroom_manager_add (EmpathyChatroomManager *manager, if (favorite) { - chatroom_manager_file_save (manager); + reset_save_timeout (manager); } g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); @@ -311,7 +348,7 @@ empathy_chatroom_manager_remove (EmpathyChatroomManager *manager, if (favorite) { - chatroom_manager_file_save (manager); + reset_save_timeout (manager); } g_signal_emit (manager, signals[CHATROOM_REMOVED], 0, this_chatroom); |