]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-irc-network-manager.c
Merge remote-tracking branch 'origin/gnome-3-8'
[empathy.git] / libempathy / empathy-irc-network-manager.c
index 5e0530938272b6239773a9c169ca284d67f9dc5b..3f53a49ad2ab17ee00acc0e547e80935a86eda2a 100644 (file)
  * Authors: Guillaume Desmottes <gdesmott@gnome.org>
  */
 
-#include <config.h>
-#include <string.h>
-#include <sys/types.h>
+#include "config.h"
+#include "empathy-irc-network-manager.h"
+
 #include <sys/stat.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
 
 #include "empathy-utils.h"
-#include "empathy-irc-network-manager.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_IRC
 #include "empathy-debug.h"
 
-#define IRC_NETWORKS_DTD_FILENAME "empathy-irc-networks.dtd"
+#define IRC_NETWORKS_DTD_RESOURCENAME "/org/gnome/Empathy/empathy-irc-networks.dtd"
 #define IRC_NETWORKS_FILENAME "irc-networks.xml"
 #define SAVE_TIMER 4
 
@@ -155,7 +152,7 @@ empathy_irc_network_manager_finalize (GObject *object)
   g_free (priv->global_file);
   g_free (priv->user_file);
 
-  g_hash_table_destroy (priv->networks);
+  g_hash_table_unref (priv->networks);
 
   G_OBJECT_CLASS (empathy_irc_network_manager_parent_class)->finalize (object);
 }
@@ -366,7 +363,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 +373,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 +421,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);
 }
 
 /*
@@ -576,14 +614,11 @@ irc_network_manager_file_parse (EmpathyIrcNetworkManager *self,
                                 const gchar *filename,
                                 gboolean user_defined)
 {
-  EmpathyIrcNetworkManagerPriv *priv;
   xmlParserCtxtPtr ctxt;
   xmlDocPtr doc;
   xmlNodePtr networks;
   xmlNodePtr node;
 
-  priv = GET_PRIV (self);
-
   DEBUG ("Attempting to parse file:'%s'...", filename);
 
   ctxt = xmlNewParserCtxt ();
@@ -597,7 +632,7 @@ irc_network_manager_file_parse (EmpathyIrcNetworkManager *self,
       return FALSE;
     }
 
-  if (!empathy_xml_validate (doc, IRC_NETWORKS_DTD_FILENAME)) {
+  if (!empathy_xml_validate_from_resource (doc, IRC_NETWORKS_DTD_RESOURCENAME)) {
     g_warning ("Failed to validate file:'%s'", filename);
     xmlFreeDoc (doc);
     xmlFreeParserCtxt (ctxt);