]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-status-icon.c
Move empathy-conf to libempathy-gtk. libempathy do not depend directly on gconf anymore.
[empathy.git] / libempathy-gtk / empathy-status-icon.c
index 4421ddc85891fda8eeed1bb1ad4032cd017367a1..9e62a1e189e363bc4bb5b2ae88db428f1bc9133f 100644 (file)
 #include <libempathy/empathy-tp-chat.h>
 #include <libempathy/empathy-debug.h>
 #include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-conf.h>
 #include <libempathy/empathy-idle.h>
 #include <libempathy/empathy-filter.h>
 
 #include "empathy-status-icon.h"
 #include "empathy-contact-dialogs.h"
 #include "empathy-presence-chooser.h"
+#include "empathy-conf.h"
 #include "empathy-preferences.h"
 #include "empathy-ui-utils.h"
 #include "empathy-accounts-dialog.h"
@@ -101,7 +101,8 @@ static void       status_icon_idle_notify_cb      (EmpathyStatusIcon      *icon)
 static void       status_icon_update_tooltip      (EmpathyStatusIcon      *icon);
 static void       status_icon_set_from_state      (EmpathyStatusIcon      *icon);
 static void       status_icon_set_visibility      (EmpathyStatusIcon      *icon,
-                                                  gboolean                visible);
+                                                  gboolean                visible,
+                                                  gboolean                store);
 static void       status_icon_toggle_visibility   (EmpathyStatusIcon      *icon);
 static void       status_icon_activate_cb         (GtkStatusIcon          *status_icon,
                                                   EmpathyStatusIcon      *icon);
@@ -139,6 +140,32 @@ static void       status_icon_event_free          (StatusIconEvent        *event
 
 G_DEFINE_TYPE (EmpathyStatusIcon, empathy_status_icon, G_TYPE_OBJECT);
 
+static void
+status_icon_notify_use_nm_cb (EmpathyConf  *conf,
+                             const gchar *key,
+                             gpointer     user_data)
+{
+       EmpathyStatusIconPriv *priv = GET_PRIV (user_data);
+       gboolean               use_nm;
+
+       if (empathy_conf_get_bool (conf, key, &use_nm)) {
+               empathy_idle_set_use_nm (priv->idle, use_nm);
+       }
+}
+
+static void
+status_icon_notify_visibility_cb (EmpathyConf *conf,
+                                 const gchar *key,
+                                 gpointer     user_data)
+{
+       EmpathyStatusIcon *icon = user_data;
+       gboolean           hidden = FALSE;
+
+       if (empathy_conf_get_bool (conf, key, &hidden)) {
+               status_icon_set_visibility (icon, !hidden, FALSE);
+       }
+}
+
 static void
 empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
 {
@@ -154,13 +181,11 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
 {
        EmpathyStatusIconPriv *priv;
        GList                 *pendings, *l;
+       gboolean               use_nm;
 
        priv = GET_PRIV (icon);
 
        priv->icon = gtk_status_icon_new ();
-       priv->idle = empathy_idle_new ();
-       empathy_idle_set_auto_away (priv->idle, TRUE);
-       empathy_idle_set_auto_disconnect (priv->idle, TRUE);
        priv->manager = empathy_contact_manager_new ();
        priv->mc = empathy_mission_control_new ();
        priv->text_filter = empathy_filter_new ("org.gnome.Empathy.ChatFilter",
@@ -169,6 +194,24 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
                                                MC_FILTER_PRIORITY_DIALOG,
                                                MC_FILTER_FLAG_INCOMING);
 
+       /* Setup EmpathyIdle */
+       priv->idle = empathy_idle_new ();
+       empathy_conf_get_bool (empathy_conf_get (),
+                              EMPATHY_PREFS_USE_NM,
+                              &use_nm);
+       empathy_conf_notify_add (empathy_conf_get (),
+                                EMPATHY_PREFS_USE_NM,
+                                status_icon_notify_use_nm_cb,
+                                icon);
+       empathy_idle_set_auto_away (priv->idle, TRUE);
+       empathy_idle_set_use_nm (priv->idle, use_nm);
+
+       /* make icon listen and respond to MAIN_WINDOW_HIDDEN changes */
+       empathy_conf_notify_add (empathy_conf_get (),
+                                EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN,
+                                status_icon_notify_visibility_cb,
+                                icon);
+
        status_icon_create_menu (icon);
        status_icon_idle_notify_cb (icon);
 
@@ -249,7 +292,7 @@ empathy_status_icon_new (GtkWindow *window)
                              &should_hide);
 
        if (gtk_window_is_active (priv->window) == should_hide) {
-               status_icon_set_visibility (icon, !should_hide);
+               status_icon_set_visibility (icon, !should_hide, FALSE);
        }
 
        return icon;
@@ -392,22 +435,24 @@ status_icon_set_from_state (EmpathyStatusIcon *icon)
 
 static void
 status_icon_set_visibility (EmpathyStatusIcon *icon,
-                           gboolean           visible)
+                           gboolean           visible,
+                           gboolean           store)
 {
        EmpathyStatusIconPriv *priv;
 
        priv = GET_PRIV (icon);
 
+       if (store) {
+               empathy_conf_set_bool (empathy_conf_get (),
+                                      EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN, !visible);
+       }
+
        if (!visible) {
                empathy_window_iconify (priv->window, priv->icon);
-               empathy_conf_set_bool (empathy_conf_get (),
-                                     EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN, TRUE);
        } else {
                GList *accounts;
 
                empathy_window_present (GTK_WINDOW (priv->window), TRUE);
-               empathy_conf_set_bool (empathy_conf_get (),
-                                     EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN, FALSE);
        
                /* Show the accounts dialog if there is no enabled accounts */
                accounts = mc_accounts_list_by_enabled (TRUE);
@@ -428,7 +473,7 @@ status_icon_toggle_visibility (EmpathyStatusIcon *icon)
        gboolean               visible;
 
        visible = gtk_window_is_active (priv->window);
-       status_icon_set_visibility (icon, !visible);
+       status_icon_set_visibility (icon, !visible, TRUE);
 }
 
 static void
@@ -454,7 +499,7 @@ status_icon_delete_event_cb (GtkWidget         *widget,
                             GdkEvent          *event,
                             EmpathyStatusIcon *icon)
 {
-       status_icon_set_visibility (icon, FALSE);
+       status_icon_set_visibility (icon, FALSE, TRUE);
 
        return TRUE;
 }
@@ -529,7 +574,7 @@ status_icon_new_message_cb (GtkWidget         *widget,
 
        priv = GET_PRIV (icon);
 
-       empathy_new_message_dialog_show (GTK_WINDOW (priv->window));
+       empathy_new_message_dialog_show (NULL);
 }
 
 static void
@@ -546,7 +591,7 @@ status_icon_show_hide_window_cb (GtkWidget         *widget,
        gboolean visible;
 
        visible = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
-       status_icon_set_visibility (icon, visible);
+       status_icon_set_visibility (icon, visible, TRUE);
 }
 
 static void