]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-irc-network-manager.c
individual-menu: remove link-contacts-activated signal
[empathy.git] / libempathy / empathy-irc-network-manager.c
index d537d5574853bb7b733376e4feb24c74d5fc193b..a9d89dca95796667e1e5acb61affe721754f9452 100644 (file)
@@ -32,6 +32,7 @@
 #include "empathy-debug.h"
 
 #define IRC_NETWORKS_DTD_FILENAME "empathy-irc-networks.dtd"
+#define IRC_NETWORKS_FILENAME "irc-networks.xml"
 #define SAVE_TIMER 4
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcNetworkManager)
@@ -154,7 +155,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);
 }
@@ -323,7 +324,7 @@ empathy_irc_network_manager_add (EmpathyIrcNetworkManager *self,
 
   if (priv->last_id == G_MAXUINT)
     {
-      DEBUG ("Can't add network: too many networks using a similiar ID");
+      DEBUG ("Can't add network: too many networks using a similar ID");
       return;
     }
 
@@ -365,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)
 {
@@ -375,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
@@ -387,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);
 }
 
 /*
@@ -575,14 +617,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 ();
@@ -719,7 +758,6 @@ irc_network_manager_file_save (EmpathyIrcNetworkManager *self)
   xmlSaveFormatFileEnc (priv->user_file, doc, "utf-8", 1);
   xmlFreeDoc (doc);
 
-  xmlCleanupParser ();
   xmlMemoryDump ();
 
   priv->have_to_save = FALSE;
@@ -782,3 +820,36 @@ empathy_irc_network_manager_find_network_by_address (
 
   return network;
 }
+
+EmpathyIrcNetworkManager *
+empathy_irc_network_manager_dup_default (void)
+{
+  static EmpathyIrcNetworkManager *default_mgr = NULL;
+  gchar *dir, *user_file_with_path, *global_file_with_path;
+
+  if (default_mgr != NULL)
+    return g_object_ref (default_mgr);
+
+  dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
+  g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
+  user_file_with_path = g_build_filename (dir, IRC_NETWORKS_FILENAME, NULL);
+  g_free (dir);
+
+  global_file_with_path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"),
+      "libempathy", IRC_NETWORKS_FILENAME, NULL);
+  if (!g_file_test (global_file_with_path, G_FILE_TEST_EXISTS))
+    {
+      g_free (global_file_with_path);
+      global_file_with_path = g_build_filename (DATADIR, "empathy",
+          IRC_NETWORKS_FILENAME, NULL);
+    }
+
+  default_mgr = empathy_irc_network_manager_new (
+      global_file_with_path, user_file_with_path);
+
+  g_object_add_weak_pointer (G_OBJECT (default_mgr), (gpointer *) &default_mgr);
+
+  g_free (global_file_with_path);
+  g_free (user_file_with_path);
+  return default_mgr;
+}