From c7e246e02d143268e0e8fc310c2078d312e4b91a Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Mon, 14 Feb 2011 07:41:30 +0530 Subject: Reset network list button Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=642264 --- .../empathy-irc-network-chooser-dialog.c | 33 ++++++++++++ libempathy/empathy-irc-network-manager.c | 63 ++++++++++++++++++---- libempathy/empathy-irc-network-manager.h | 3 ++ libempathy/empathy-irc-network.c | 21 +++++++- libempathy/empathy-irc-network.h | 2 + 5 files changed, 110 insertions(+), 12 deletions(-) diff --git a/libempathy-gtk/empathy-irc-network-chooser-dialog.c b/libempathy-gtk/empathy-irc-network-chooser-dialog.c index f81ba80bb..9d29aff4a 100644 --- a/libempathy-gtk/empathy-irc-network-chooser-dialog.c +++ b/libempathy-gtk/empathy-irc-network-chooser-dialog.c @@ -47,6 +47,10 @@ enum { PROP_NETWORK }; +enum { + RESPONSE_RESET = 0 +}; + typedef struct { EmpathyAccountSettings *settings; EmpathyIrcNetwork *network; @@ -389,6 +393,32 @@ remove_network (EmpathyIrcNetworkChooserDialog *self) g_object_unref (network); } +static void +reset_networks (EmpathyIrcNetworkChooserDialog *self) +{ + EmpathyIrcNetworkChooserDialogPriv *priv = GET_PRIV (self); + GSList *networks, *l; + + networks = empathy_irc_network_manager_get_dropped_networks ( + priv->network_manager); + + for (l = networks; l != NULL; l = g_slist_next (l)) + { + EmpathyIrcNetwork *network; + GtkTreeIter iter; + + network = EMPATHY_IRC_NETWORK (l->data); + empathy_irc_network_activate (network); + + gtk_list_store_insert_with_values (priv->store, &iter, -1, + COL_NETWORK_OBJ, network, + COL_NETWORK_NAME, empathy_irc_network_get_name (network), + -1); + } + + g_slist_foreach (networks, (GFunc) g_object_unref, NULL); +} + static void dialog_response_cb (GtkDialog *dialog, gint response, @@ -400,6 +430,8 @@ dialog_response_cb (GtkDialog *dialog, edit_network (self); else if (response == GTK_RESPONSE_REJECT) remove_network (self); + else if (response == RESPONSE_RESET) + reset_networks (self); } static gboolean @@ -549,6 +581,7 @@ empathy_irc_network_chooser_dialog_constructed (GObject *object) GTK_STOCK_ADD, GTK_RESPONSE_OK, GTK_STOCK_EDIT, GTK_RESPONSE_APPLY, GTK_STOCK_REMOVE, GTK_RESPONSE_REJECT, + _("Reset _Networks List"), RESPONSE_RESET, NULL); priv->select_button = gtk_dialog_add_button (dialog, diff --git a/libempathy/empathy-irc-network-manager.c b/libempathy/empathy-irc-network-manager.c index 5e0530938..691c05df5 100644 --- a/libempathy/empathy-irc-network-manager.c +++ b/libempathy/empathy-irc-network-manager.c @@ -366,7 +366,7 @@ empathy_irc_network_manager_remove (EmpathyIrcNetworkManager *self, } static void -append_network_to_list (const gchar *id, +append_active_networks_to_list (const gchar *id, EmpathyIrcNetwork *network, GSList **list) { @@ -376,6 +376,42 @@ append_network_to_list (const gchar *id, *list = g_slist_prepend (*list, g_object_ref (network)); } +static void +append_dropped_networks_to_list (const gchar *id, + EmpathyIrcNetwork *network, + GSList **list) +{ + if (!network->dropped) + return; + + *list = g_slist_prepend (*list, g_object_ref (network)); +} + +static GSList * +get_network_list (EmpathyIrcNetworkManager *self, + gboolean get_active) +{ + EmpathyIrcNetworkManagerPriv *priv; + GSList *irc_networks = NULL; + + g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), NULL); + + priv = GET_PRIV (self); + + if (get_active) + { + g_hash_table_foreach (priv->networks, + (GHFunc) append_active_networks_to_list, &irc_networks); + } + else + { + g_hash_table_foreach (priv->networks, + (GHFunc) append_dropped_networks_to_list, &irc_networks); + } + + return irc_networks; +} + /** * empathy_irc_network_manager_get_networks: * @manager: an #EmpathyIrcNetworkManager @@ -388,17 +424,22 @@ append_network_to_list (const gchar *id, GSList * empathy_irc_network_manager_get_networks (EmpathyIrcNetworkManager *self) { - EmpathyIrcNetworkManagerPriv *priv; - GSList *irc_networks = NULL; - - g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), NULL); - - priv = GET_PRIV (self); - - g_hash_table_foreach (priv->networks, (GHFunc) append_network_to_list, - &irc_networks); + return get_network_list (self, TRUE); +} - return irc_networks; +/** + * empathy_irc_network_manager_get_dropped_networks: + * @manager: an #EmpathyIrcNetworkManager + * + * Get the list of dropped #EmpathyIrcNetworks associated with the given + * manager. + * + * Returns: a new #GSList of refed dropped #EmpathyIrcNetworks + */ +GSList * +empathy_irc_network_manager_get_dropped_networks (EmpathyIrcNetworkManager *self) +{ + return get_network_list (self, FALSE); } /* diff --git a/libempathy/empathy-irc-network-manager.h b/libempathy/empathy-irc-network-manager.h index 11c84836f..19df2f7e1 100644 --- a/libempathy/empathy-irc-network-manager.h +++ b/libempathy/empathy-irc-network-manager.h @@ -74,6 +74,9 @@ void empathy_irc_network_manager_remove (EmpathyIrcNetworkManager *manager, GSList * empathy_irc_network_manager_get_networks ( EmpathyIrcNetworkManager *manager); +GSList * empathy_irc_network_manager_get_dropped_networks ( + EmpathyIrcNetworkManager *manager); + EmpathyIrcNetwork * empathy_irc_network_manager_find_network_by_address ( EmpathyIrcNetworkManager *manager, const gchar *address); diff --git a/libempathy/empathy-irc-network.c b/libempathy/empathy-irc-network.c index d5b0bdcb9..68e071be8 100644 --- a/libempathy/empathy-irc-network.c +++ b/libempathy/empathy-irc-network.c @@ -206,7 +206,8 @@ empathy_irc_network_class_init (EmpathyIrcNetworkClass *klass) * EmpathyIrcNetwork::modified: * @network: the object that received the signal * - * Emitted when either a property or a server of the network is modified. + * Emitted when either a property or a server of the network is modified or + * when a network is activated. * */ signals[MODIFIED] = g_signal_new ( @@ -219,6 +220,24 @@ empathy_irc_network_class_init (EmpathyIrcNetworkClass *klass) G_TYPE_NONE, 0); } +/** + * empathy_irc_network_activate: + * @self: the name of the network + * + * Activates a #EmpathyIrcNetwork. + * + */ +void +empathy_irc_network_activate (EmpathyIrcNetwork *self) +{ + g_return_if_fail (EMPATHY_IS_IRC_NETWORK (self)); + g_return_if_fail (self->dropped); + + self->dropped = FALSE; + + g_signal_emit (self, signals[MODIFIED], 0); +} + /** * empathy_irc_network_new: * @name: the name of the network diff --git a/libempathy/empathy-irc-network.h b/libempathy/empathy-irc-network.h index 9d78f3c3f..a298ced9a 100644 --- a/libempathy/empathy-irc-network.h +++ b/libempathy/empathy-irc-network.h @@ -62,6 +62,8 @@ GType empathy_irc_network_get_type (void); (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK, \ EmpathyIrcNetworkClass)) +void empathy_irc_network_activate (EmpathyIrcNetwork *self); + EmpathyIrcNetwork * empathy_irc_network_new (const gchar *name); GSList * empathy_irc_network_get_servers (EmpathyIrcNetwork *network); -- cgit v1.2.3