]> 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 16a678dcd60a2bba125be55eeb2168d1038bb7c4..9e62a1e189e363bc4bb5b2ae88db428f1bc9133f 100644 (file)
@@ -2,20 +2,19 @@
 /*
  * Copyright (C) 2007 Collabora Ltd.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  * 
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 #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"
 #include "empathy-images.h"
+#include "empathy-new-message-dialog.h"
 
 
 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
@@ -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,21 +181,37 @@ 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.Chat",
-                                               "/org/freedesktop/Telepathy/Filter",
+       priv->text_filter = empathy_filter_new ("org.gnome.Empathy.ChatFilter",
+                                               "/org/gnome/Empathy/ChatFilter",
                                                TP_IFACE_CHANNEL_TYPE_TEXT,
                                                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);
 
@@ -248,7 +291,9 @@ empathy_status_icon_new (GtkWindow *window)
                              EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN,
                              &should_hide);
 
-       status_icon_set_visibility (icon, !should_hide);
+       if (gtk_window_is_active (priv->window) == should_hide) {
+               status_icon_set_visibility (icon, !should_hide, FALSE);
+       }
 
        return icon;
 }
@@ -390,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);
@@ -426,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
@@ -452,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;
 }
@@ -527,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
@@ -544,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