]> git.0d.be Git - empathy.git/commitdiff
Reset network list button
authorChandni Verma <chandniverma2112@gmail.com>
Mon, 14 Feb 2011 02:11:30 +0000 (07:41 +0530)
committerChandni Verma <chandniverma2112@gmail.com>
Mon, 14 Feb 2011 17:08:46 +0000 (22:38 +0530)
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=642264
libempathy-gtk/empathy-irc-network-chooser-dialog.c
libempathy/empathy-irc-network-manager.c
libempathy/empathy-irc-network-manager.h
libempathy/empathy-irc-network.c
libempathy/empathy-irc-network.h

index f81ba80bbdee503355d7502265c41f12194e6f89..9d29aff4a3b770d3a468ab2cdf4c12ad87402e5f 100644 (file)
@@ -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,
index 5e0530938272b6239773a9c169ca284d67f9dc5b..691c05df52e3abb1c43ef83173a2940751ee98fa 100644 (file)
@@ -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);
 }
 
 /*
index 11c84836f2a9a0f5cbff6ef30b66d1662eedfa34..19df2f7e19b9d8cdf4abb1111b42a7f3cb8842f6 100644 (file)
@@ -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);
 
index d5b0bdcb99e5de3cd574b3b97b41989ca482857f..68e071be840f6091f59c3f8631ee24572a9f5093 100644 (file)
@@ -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
index 9d78f3c3fa854f54a266f08c069c68513b4dd088..a298ced9a3a8c5f02865098f7b05c1518b01cee5 100644 (file)
@@ -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);