diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-06-02 04:25:05 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-06-02 04:25:05 +0800 |
commit | 9223336edde583afe690a3757d71188ed6ebf16d (patch) | |
tree | 1554ddeff64a9fcdb14978076ce6cb63a29d0aeb | |
parent | 7a99a96e5b81b8d573104d1809364d5969b6b83d (diff) | |
download | gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar.gz gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar.bz2 gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar.lz gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar.xz gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.tar.zst gsoc2013-empathy-9223336edde583afe690a3757d71188ed6ebf16d.zip |
Monitor changes on chatrooms.xml file and relead it when it's modified.
2007-06-01 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/gossip-chatrooms-window.c:
* libempathy-gtk/gossip-chat-window.c:
* libempathy/gossip-chatroom.c:
* libempathy/gossip-chatroom-manager.c:
* configure.ac: Monitor changes on chatrooms.xml file and relead it
when it's modified. connect chatroom-added/removed in some places where
needed.
svn path=/trunk/; revision=111
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | libempathy-gtk/gossip-chat-window.c | 94 | ||||
-rw-r--r-- | libempathy-gtk/gossip-chatrooms-window.c | 45 | ||||
-rw-r--r-- | libempathy/gossip-chatroom-manager.c | 66 | ||||
-rw-r--r-- | libempathy/gossip-chatroom.c | 6 |
6 files changed, 170 insertions, 52 deletions
@@ -1,5 +1,15 @@ 2007-06-01 Xavier Claessens <xclaesse@gmail.com> + * libempathy-gtk/gossip-chatrooms-window.c: + * libempathy-gtk/gossip-chat-window.c: + * libempathy/gossip-chatroom.c: + * libempathy/gossip-chatroom-manager.c: + * configure.ac: Monitor changes on chatrooms.xml file and relead it + when it's modified. connect chatroom-added/removed in some places where + needed. + +2007-06-01 Xavier Claessens <xclaesse@gmail.com> + * configure.ac: Bump version to 0.7 2007-05-31 Xavier Claessens <xclaesse@gmail.com> diff --git a/configure.ac b/configure.ac index c19662f89..b166120a7 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,7 @@ PKG_CHECK_MODULES(LIBEMPATHY, gobject-2.0 gconf-2.0 >= $GCONF_REQUIRED libxml-2.0 + gnome-vfs-2.0 libtelepathy >= $TELEPATHY_REQUIRED libmissioncontrol >= $MISSION_CONTROL_REQUIRED ]) diff --git a/libempathy-gtk/gossip-chat-window.c b/libempathy-gtk/gossip-chat-window.c index 6979e450e..aef972cff 100644 --- a/libempathy-gtk/gossip-chat-window.c +++ b/libempathy-gtk/gossip-chat-window.c @@ -63,49 +63,50 @@ #define URGENCY_TIMEOUT 60*1000 struct _GossipChatWindowPriv { - GList *chats; - GList *chats_new_msg; - GList *chats_composing; + GossipChatroomManager *chatroom_manager; + GList *chats; + GList *chats_new_msg; + GList *chats_composing; - GossipChat *current_chat; + GossipChat *current_chat; - gboolean page_added; - gboolean dnd_same_window; + gboolean page_added; + gboolean dnd_same_window; - guint urgency_timeout_id; + guint urgency_timeout_id; - GtkWidget *dialog; - GtkWidget *notebook; + GtkWidget *dialog; + GtkWidget *notebook; - GtkTooltips *tooltips; + GtkTooltips *tooltips; /* Menu items. */ - GtkWidget *menu_conv_clear; - GtkWidget *menu_conv_insert_smiley; - GtkWidget *menu_conv_log; - GtkWidget *menu_conv_separator; - GtkWidget *menu_conv_add_contact; - GtkWidget *menu_conv_info; - GtkWidget *menu_conv_close; - - GtkWidget *menu_room; - GtkWidget *menu_room_set_topic; - GtkWidget *menu_room_join_new; - GtkWidget *menu_room_invite; - GtkWidget *menu_room_add; - GtkWidget *menu_room_show_contacts; - - GtkWidget *menu_edit_cut; - GtkWidget *menu_edit_copy; - GtkWidget *menu_edit_paste; - - GtkWidget *menu_tabs_next; - GtkWidget *menu_tabs_prev; - GtkWidget *menu_tabs_left; - GtkWidget *menu_tabs_right; - GtkWidget *menu_tabs_detach; - - guint save_geometry_id; + GtkWidget *menu_conv_clear; + GtkWidget *menu_conv_insert_smiley; + GtkWidget *menu_conv_log; + GtkWidget *menu_conv_separator; + GtkWidget *menu_conv_add_contact; + GtkWidget *menu_conv_info; + GtkWidget *menu_conv_close; + + GtkWidget *menu_room; + GtkWidget *menu_room_set_topic; + GtkWidget *menu_room_join_new; + GtkWidget *menu_room_invite; + GtkWidget *menu_room_add; + GtkWidget *menu_room_show_contacts; + + GtkWidget *menu_edit_cut; + GtkWidget *menu_edit_copy; + GtkWidget *menu_edit_paste; + + GtkWidget *menu_tabs_next; + GtkWidget *menu_tabs_prev; + GtkWidget *menu_tabs_left; + GtkWidget *menu_tabs_right; + GtkWidget *menu_tabs_detach; + + guint save_geometry_id; }; static void gossip_chat_window_class_init (GossipChatWindowClass *klass); @@ -331,6 +332,15 @@ gossip_chat_window_init (GossipChatWindow *window) g_object_unref (glade); + /* Set up chatroom manager */ + priv->chatroom_manager = gossip_chatroom_manager_new (); + g_signal_connect_swapped (priv->chatroom_manager, "chatroom-added", + G_CALLBACK (chat_window_update_menu), + window); + g_signal_connect_swapped (priv->chatroom_manager, "chatroom-removed", + G_CALLBACK (chat_window_update_menu), + window); + priv->notebook = gtk_notebook_new (); gtk_notebook_set_group_id (GTK_NOTEBOOK (priv->notebook), 1); gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0); @@ -500,6 +510,7 @@ gossip_chat_window_finalize (GObject *object) chat_windows = g_list_remove (chat_windows, window); gtk_widget_destroy (priv->dialog); + g_object_unref (priv->chatroom_manager); g_object_unref (priv->tooltips); G_OBJECT_CLASS (gossip_chat_window_parent_class)->finalize (object); @@ -763,10 +774,9 @@ chat_window_update_menu (GossipChatWindow *window) is_connected = gossip_chat_is_connected (priv->current_chat); if (gossip_chat_is_group_chat (priv->current_chat)) { - GossipGroupChat *group_chat; - GossipChatroom *chatroom; - GossipChatroomManager *manager; - gboolean show_contacts; + GossipGroupChat *group_chat; + GossipChatroom *chatroom; + gboolean show_contacts; group_chat = GOSSIP_GROUP_CHAT (priv->current_chat); @@ -780,11 +790,9 @@ chat_window_update_menu (GossipChatWindow *window) /* Can we add this room to our favourites and are we * connected to the room? */ - manager = gossip_chatroom_manager_new (); - chatroom = gossip_chatroom_manager_find (manager, + chatroom = gossip_chatroom_manager_find (priv->chatroom_manager, priv->current_chat->account, gossip_chat_get_id (priv->current_chat)); - g_object_unref (manager); gtk_widget_set_sensitive (priv->menu_room_add, chatroom == NULL); gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected); diff --git a/libempathy-gtk/gossip-chatrooms-window.c b/libempathy-gtk/gossip-chatrooms-window.c index 5ff5d8812..4d4333e8d 100644 --- a/libempathy-gtk/gossip-chatrooms-window.c +++ b/libempathy-gtk/gossip-chatrooms-window.c @@ -84,6 +84,13 @@ static void chatrooms_window_button_close_clicked_cb (GtkWid static void chatrooms_window_chatroom_added_cb (GossipChatroomManager *manager, GossipChatroom *chatroom, GossipChatroomsWindow *window); +static void chatrooms_window_chatroom_removed_cb (GossipChatroomManager *manager, + GossipChatroom *chatroom, + GossipChatroomsWindow *window); +static gboolean chatrooms_window_remove_chatroom_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + GossipChatroom *chatroom); static void chatrooms_window_account_changed_cb (GtkWidget *combo_box, GossipChatroomsWindow *window); @@ -139,6 +146,9 @@ gossip_chatrooms_window_show (GtkWindow *parent) g_signal_connect (window->manager, "chatroom-added", G_CALLBACK (chatrooms_window_chatroom_added_cb), window); + g_signal_connect (window->manager, "chatroom-removed", + G_CALLBACK (chatrooms_window_chatroom_removed_cb), + window); /* Account chooser for chat rooms */ window->account_chooser = gossip_account_chooser_new (); @@ -522,6 +532,41 @@ chatrooms_window_chatroom_added_cb (GossipChatroomManager *manager, } static void +chatrooms_window_chatroom_removed_cb (GossipChatroomManager *manager, + GossipChatroom *chatroom, + GossipChatroomsWindow *window) +{ + GtkTreeModel *model; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->treeview)); + + gtk_tree_model_foreach (model, + (GtkTreeModelForeachFunc) chatrooms_window_remove_chatroom_foreach, + chatroom); +} + +static gboolean +chatrooms_window_remove_chatroom_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + GossipChatroom *chatroom) +{ + GossipChatroom *this_chatroom; + + gtk_tree_model_get (model, iter, COL_POINTER, &this_chatroom, -1); + + if (gossip_chatroom_equal (chatroom, this_chatroom)) { + gtk_list_store_remove (GTK_LIST_STORE (model), iter); + g_object_unref (this_chatroom); + return TRUE; + } + + g_object_unref (this_chatroom); + + return FALSE; +} + +static void chatrooms_window_account_changed_cb (GtkWidget *combo_box, GossipChatroomsWindow *window) { diff --git a/libempathy/gossip-chatroom-manager.c b/libempathy/gossip-chatroom-manager.c index ade0b0ba0..45b787df5 100644 --- a/libempathy/gossip-chatroom-manager.c +++ b/libempathy/gossip-chatroom-manager.c @@ -31,6 +31,8 @@ #include <libxml/parser.h> #include <libxml/tree.h> +#include <libgnomevfs/gnome-vfs.h> + #include "gossip-debug.h" #include "gossip-chatroom-manager.h" #include "gossip-utils.h" @@ -43,13 +45,19 @@ #define CHATROOMS_DTD_FILENAME "gossip-chatroom-manager.dtd" struct _GossipChatroomManagerPriv { - GList *chatrooms; + GList *chatrooms; + GHashTable *monitors; }; static void gossip_chatroom_manager_class_init (GossipChatroomManagerClass *klass); static void gossip_chatroom_manager_init (GossipChatroomManager *manager); static void chatroom_manager_finalize (GObject *object); static gboolean chatroom_manager_get_all (GossipChatroomManager *manager); +static void chatroom_manager_file_changed_cb (GnomeVFSMonitorHandle *handle, + const gchar *monitor_uri, + const gchar *info_uri, + GnomeVFSMonitorEventType event_type, + GossipChatroomManager *manager); static gboolean chatroom_manager_file_parse (GossipChatroomManager *manager, const gchar *filename); static void chatroom_manager_parse_chatroom (GossipChatroomManager *manager, @@ -99,6 +107,14 @@ gossip_chatroom_manager_class_init (GossipChatroomManagerClass *klass) static void gossip_chatroom_manager_init (GossipChatroomManager *manager) { + GossipChatroomManagerPriv *priv; + + priv = GET_PRIV (manager); + + priv->monitors = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) gnome_vfs_monitor_cancel); } static void @@ -110,6 +126,7 @@ chatroom_manager_finalize (GObject *object) g_list_foreach (priv->chatrooms, (GFunc) g_object_unref, NULL); g_list_free (priv->chatrooms); + g_hash_table_destroy (priv->monitors); (G_OBJECT_CLASS (gossip_chatroom_manager_parent_class)->finalize) (object); } @@ -149,7 +166,7 @@ gossip_chatroom_manager_add (GossipChatroomManager *manager, if (!gossip_chatroom_manager_find (manager, gossip_chatroom_get_account (chatroom), gossip_chatroom_get_room (chatroom))) { - priv->chatrooms = g_list_append (priv->chatrooms, g_object_ref (chatroom)); + priv->chatrooms = g_list_prepend (priv->chatrooms, g_object_ref (chatroom)); chatroom_manager_file_save (manager); g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); @@ -322,6 +339,31 @@ chatroom_manager_get_all (GossipChatroomManager *manager) return TRUE; } +static void +chatroom_manager_file_changed_cb (GnomeVFSMonitorHandle *handle, + const gchar *monitor_uri, + const gchar *info_uri, + GnomeVFSMonitorEventType event_type, + GossipChatroomManager *manager) +{ + GossipChatroomManagerPriv *priv; + GList *l; + + priv = GET_PRIV (manager); + + gossip_debug (DEBUG_DOMAIN, "Reload file: %s", monitor_uri); + + /* FIXME: This is not optimised */ + for (l = priv->chatrooms; l; l = l->next) { + g_signal_emit (manager, signals[CHATROOM_REMOVED], 0, l->data); + g_object_unref (l->data); + } + g_list_free (priv->chatrooms); + priv->chatrooms = NULL; + + chatroom_manager_get_all (manager); +} + static gboolean chatroom_manager_file_parse (GossipChatroomManager *manager, const gchar *filename) @@ -334,6 +376,19 @@ chatroom_manager_file_parse (GossipChatroomManager *manager, priv = GET_PRIV (manager); + /* Do not monitor this file twice if it's already monitored */ + if (!g_hash_table_lookup (priv->monitors, filename)) { + GnomeVFSMonitorHandle *handle; + + gnome_vfs_monitor_add (&handle, + filename, + GNOME_VFS_MONITOR_FILE, + (GnomeVFSMonitorCallback) chatroom_manager_file_changed_cb, + manager); + + g_hash_table_insert (priv->monitors, g_strdup (filename), handle); + } + gossip_debug (DEBUG_DOMAIN, "Attempting to parse file:'%s'...", filename); ctxt = xmlNewParserCtxt (); @@ -432,12 +487,9 @@ chatroom_manager_parse_chatroom (GossipChatroomManager *manager, return; } - chatroom = gossip_chatroom_new_full (account, - room, - name, - auto_connect); - + chatroom = gossip_chatroom_new_full (account, room, name, auto_connect); priv->chatrooms = g_list_prepend (priv->chatrooms, chatroom); + g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); g_object_unref (account); g_free (name); diff --git a/libempathy/gossip-chatroom.c b/libempathy/gossip-chatroom.c index eccd2824c..5b1760fdd 100644 --- a/libempathy/gossip-chatroom.c +++ b/libempathy/gossip-chatroom.c @@ -300,12 +300,14 @@ gossip_chatroom_set_name (GossipChatroom *chatroom, GossipChatroomPriv *priv; g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); - g_return_if_fail (name != NULL); priv = GET_PRIV (chatroom); g_free (priv->name); - priv->name = g_strdup (name); + priv->name = NULL; + if (name) { + priv->name = g_strdup (name); + } g_object_notify (G_OBJECT (chatroom), "name"); } |