]> git.0d.be Git - empathy.git/commitdiff
Show a notification when a contact goes offline or online
authorFrédéric Péters <fpeters@0d.be>
Mon, 15 Jun 2009 14:53:48 +0000 (16:53 +0200)
committerFrédéric Péters <fpeters@0d.be>
Tue, 23 Jun 2009 10:08:50 +0000 (12:08 +0200)
data/empathy.schemas.in
libempathy-gtk/empathy-conf.h
src/empathy-event-manager.c
src/empathy-preferences.c
src/empathy-preferences.ui

index 8820da1bf2ae3690589fe62a0e787d10add70ec5..fb068e5bd4299ee261709c02ba66abb786f0e102 100644 (file)
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/empathy/notifications/notifications_contact_signin</key>
+      <applyto>/apps/empathy/notifications/notifications_contact_signin</applyto>
+      <owner>empathy</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+         <short>Popup notifications when a contact sign in</short>
+         <long>
+         Whether or not to show a popup notification when a contact goes
+         online.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/empathy/notifications/notifications_contact_signout</key>
+      <applyto>/apps/empathy/notifications/notifications_contact_signout</applyto>
+      <owner>empathy</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+         <short>Popup notifications when a contact sign out</short>
+         <long>
+         Whether or not to show a popup notification when a contact goes
+         offline.
+         </long>
+      </locale>
+    </schema>
+
     <schema>
        <key>/schemas/apps/empathy/ui/separate_chat_windows</key>
        <applyto>/apps/empathy/ui/separate_chat_windows</applyto>
index e40c2283d834048cc33480afc7196b73ace1d09a..937a4bf9cb83ebd7091775b6fff3dc5b248d1e35 100644 (file)
@@ -48,6 +48,8 @@ struct _EmpathyConfClass {
 #define EMPATHY_PREFS_NOTIFICATIONS_ENABLED        EMPATHY_PREFS_PATH "/notifications/notifications_enabled"
 #define EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY  EMPATHY_PREFS_PATH "/notifications/notifications_disabled_away"
 #define EMPATHY_PREFS_NOTIFICATIONS_FOCUS          EMPATHY_PREFS_PATH "/notifications/notifications_focus"
+#define EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN EMPATHY_PREFS_PATH "/notifications/notifications_contact_signin"
+#define EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT EMPATHY_PREFS_PATH "/notifications/notifications_contact_signout"
 #define EMPATHY_PREFS_SOUNDS_ENABLED               EMPATHY_PREFS_PATH "/sounds/sounds_enabled"
 #define EMPATHY_PREFS_SOUNDS_DISABLED_AWAY         EMPATHY_PREFS_PATH "/sounds/sounds_disabled_away"
 #define EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE      EMPATHY_PREFS_PATH "/sounds/sounds_incoming_message"
index 1ee619e5827021bf69175cc6fa299166dc7ae5c2..1a4ce0d65ce439dd94ee441561cd1ef95e3525d3 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <telepathy-glib/util.h>
 
+#include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-contact-manager.h>
@@ -37,6 +38,7 @@
 
 #include <extensions/extensions.h>
 
+#include <libempathy-gtk/empathy-conf.h>
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-contact-dialogs.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
@@ -956,6 +958,66 @@ event_manager_pendings_changed_cb (EmpathyContactList  *list,
   g_free (header);
 }
 
+static void
+event_manager_presence_changed_cb (EmpathyContactMonitor *monitor,
+                                   EmpathyContact *contact,
+                                   TpConnectionPresenceType current,
+                                   TpConnectionPresenceType previous,
+                                   EmpathyEventManager *manager)
+{
+  McAccount *account;
+  gboolean just_connected;
+  EmpathyAccountManager *account_manager;
+  gchar *header = NULL;
+  gboolean preference = FALSE;
+
+  account = empathy_contact_get_account (contact);
+  account_manager = empathy_account_manager_dup_singleton ();
+  just_connected = empathy_account_manager_is_account_just_connected (
+                  account_manager, account);
+
+  g_object_unref (account_manager);
+  if (just_connected) {
+    return;
+  }
+
+  if (tp_connection_presence_type_cmp_availability (previous,
+     TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
+    {
+      /* contact was online */
+      empathy_conf_get_bool (empathy_conf_get (),
+                      EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT, &preference);
+      if (preference && tp_connection_presence_type_cmp_availability (current,
+          TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
+        {
+          /* someone is logging off */
+          header = g_strdup_printf (_("%s signed out."),
+            empathy_contact_get_name (contact));
+
+          event_manager_add (manager, contact, GTK_STOCK_DIALOG_INFO, header,
+                             NULL, NULL, NULL, NULL);
+        }
+    }
+  else
+    {
+      /* contact was offline */
+      empathy_conf_get_bool (empathy_conf_get (),
+                      EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN, &preference);
+      if (preference && tp_connection_presence_type_cmp_availability (current,
+          TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
+        {
+          /* someone is logging in */
+          header = g_strdup_printf (_("%s signed in."),
+            empathy_contact_get_name (contact));
+
+          event_manager_add (manager, contact, GTK_STOCK_DIALOG_INFO, header,
+                             NULL, NULL, NULL, NULL);
+        }
+    }
+  g_free (header);
+}
+
+
 static GObject *
 event_manager_constructor (GType type,
                           guint n_props,
@@ -1034,6 +1096,12 @@ empathy_event_manager_init (EmpathyEventManager *manager)
 {
   EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
     EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
+  EmpathyContactMonitor   *monitor;
+  EmpathyContactList      *list_iface;
+
+  list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
+  monitor = empathy_contact_list_get_monitor (list_iface);
+  g_object_unref (list_iface);
 
   manager->priv = priv;
 
@@ -1043,6 +1111,8 @@ empathy_event_manager_init (EmpathyEventManager *manager)
     G_CALLBACK (event_manager_approve_channel_cb), manager);
   g_signal_connect (priv->contact_manager, "pendings-changed",
     G_CALLBACK (event_manager_pendings_changed_cb), manager);
+  g_signal_connect (monitor, "contact-presence-changed",
+    G_CALLBACK (event_manager_presence_changed_cb), manager);
 }
 
 EmpathyEventManager *
index cb087cb30c9110e93e6b62ced7c95d5430628253..d91dc9817c0b7babe36e7c6863fcb9c01febc260 100644 (file)
@@ -69,6 +69,8 @@ typedef struct {
        GtkWidget *checkbutton_notifications_enabled;
        GtkWidget *checkbutton_notifications_disabled_away;
        GtkWidget *checkbutton_notifications_focus;
+       GtkWidget *checkbutton_notifications_contact_signin;
+       GtkWidget *checkbutton_notifications_contact_signout;
 
        GtkWidget *treeview_spell_checker;
 
@@ -200,6 +202,12 @@ preferences_setup_widgets (EmpathyPreferences *preferences)
        preferences_hookup_toggle_button (preferences,
                                          EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
                                          preferences->checkbutton_notifications_focus);
+       preferences_hookup_toggle_button (preferences,
+                                         EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
+                                         preferences->checkbutton_notifications_contact_signin);
+       preferences_hookup_toggle_button (preferences,
+                                         EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
+                                         preferences->checkbutton_notifications_contact_signout);
 
        preferences_hookup_sensitivity (preferences,
                                        EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
@@ -207,6 +215,12 @@ preferences_setup_widgets (EmpathyPreferences *preferences)
        preferences_hookup_sensitivity (preferences,
                                        EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
                                        preferences->checkbutton_notifications_focus);
+       preferences_hookup_sensitivity (preferences,
+                                       EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
+                                       preferences->checkbutton_notifications_contact_signin);
+       preferences_hookup_sensitivity (preferences,
+                                       EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
+                                       preferences->checkbutton_notifications_contact_signout);
 
        preferences_hookup_toggle_button (preferences,
                                          EMPATHY_PREFS_SOUNDS_ENABLED,
@@ -1207,6 +1221,8 @@ empathy_preferences_show (GtkWindow *parent)
                "checkbutton_notifications_enabled", &preferences->checkbutton_notifications_enabled,
                "checkbutton_notifications_disabled_away", &preferences->checkbutton_notifications_disabled_away,
                "checkbutton_notifications_focus", &preferences->checkbutton_notifications_focus,
+               "checkbutton_notifications_contact_signin", &preferences->checkbutton_notifications_contact_signin,
+               "checkbutton_notifications_contact_signout", &preferences->checkbutton_notifications_contact_signout,
                "checkbutton_sounds_enabled", &preferences->checkbutton_sounds_enabled,
                "checkbutton_sounds_disabled_away", &preferences->checkbutton_sounds_disabled_away,
                "treeview_sounds", &preferences->treeview_sounds,
index ed0cb54eb1bf1cd7054b793901302e412f260889..3b577ed9d443dbe8f170d8e7a8209f5c72d6dbdc 100644 (file)
                             <property name="position">1</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkCheckButton" id="checkbutton_notifications_contact_signin">
+                            <property name="label" translatable="yes">Enable notifications when a contact signs in</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="checkbutton_notifications_contact_signout">
+                            <property name="label" translatable="yes">Enable notifications when a contact signs out</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">3</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>