[ekiga] Moved and hooked some code around to treat any received presence information



commit bfd5b7231b9e7d587134bf48ee1e0447e7fcdd77
Author: Snark <jpuydt gnome org>
Date:   Wed Mar 30 12:17:49 2011 +0200

    Moved and hooked some code around to treat any received presence information

 lib/engine/components/opal/opal-account.cpp |  110 ++++++++++++++++++++++++++-
 lib/engine/components/opal/opal-account.h   |   15 ++++
 lib/engine/components/opal/opal-bank.cpp    |  105 -------------------------
 lib/engine/components/opal/opal-bank.h      |   15 ----
 4 files changed, 123 insertions(+), 122 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index f3bee3a..8d09273 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -298,8 +298,8 @@ void Opal::Account::enable ()
 
     std::cout << "opening presentity for " << get_aor () << std::endl;
     presentity->Open ();
-    presentity->SubscribeToPresence ("sip:julien puydt ekiga net");
-    presentity->SubscribeToPresence ("sip:eugen dedu ekiga net");
+    //presentity->SubscribeToPresence ("sip:julien puydt ekiga net");
+    //presentity->SubscribeToPresence ("sip:eugen dedu ekiga net");
   }
 
   updated ();
@@ -629,6 +629,7 @@ Opal::Account::setup_presentity ()
 
   if (presentity) {
 
+    presentity->SetPresenceChangeNotifier (PCREATE_PresenceChangeNotifier (OnPresenceChange));
     presentity->GetAttributes().Set(SIP_Presentity::AuthNameKey, username);
     presentity->GetAttributes().Set(SIP_Presentity::AuthPasswordKey, password);
     presentity->GetAttributes().Set(SIP_Presentity::SubProtocolKey, "Agent");
@@ -637,3 +638,108 @@ Opal::Account::setup_presentity ()
   } else
     std::cout << "NULL presentity for " << url << std::endl;
 }
+
+void
+Opal::Account::OnPresenceChange (OpalPresentity& /*presentity*/,
+				 const OpalPresenceInfo& info)
+{
+  std::string presence = "unknown";
+  std::string status;
+
+  /* we could do something precise */
+  switch (info.m_state) {
+
+  case OpalPresenceInfo::InternalError:
+  case OpalPresenceInfo::Forbidden:
+  case OpalPresenceInfo::NoPresence:
+  case OpalPresenceInfo::Unchanged:
+  case OpalPresenceInfo::Unavailable:
+    presence = "offline";
+    break;
+
+  case OpalPresenceInfo::Available:
+  case OpalPresenceInfo::UnknownExtended:
+  case OpalPresenceInfo::Appointment:
+  case OpalPresenceInfo::Away:
+  case OpalPresenceInfo::Breakfast:
+  case OpalPresenceInfo::Busy:
+  case OpalPresenceInfo::Dinner:
+  case OpalPresenceInfo::Holiday:
+  case OpalPresenceInfo::InTransit:
+  case OpalPresenceInfo::LookingForWork:
+  case OpalPresenceInfo::Lunch:
+  case OpalPresenceInfo::Meal:
+  case OpalPresenceInfo::Meeting:
+  case OpalPresenceInfo::OnThePhone:
+  case OpalPresenceInfo::Other:
+  case OpalPresenceInfo::Performance:
+  case OpalPresenceInfo::PermanentAbsence:
+  case OpalPresenceInfo::Playing:
+  case OpalPresenceInfo::Presentation:
+  case OpalPresenceInfo:: Shopping:
+  case OpalPresenceInfo::Sleeping:
+  case OpalPresenceInfo::Spectator:
+  case OpalPresenceInfo::Steering:
+  case OpalPresenceInfo::Travel:
+  case OpalPresenceInfo::TV:
+  case OpalPresenceInfo::Vacation:
+  case OpalPresenceInfo::Working:
+  case OpalPresenceInfo:: Worship:
+    presence = "online";
+    break;
+  default:
+    presence = "offline";
+    break;
+  }
+
+  if (!info.m_note.IsEmpty ()) {
+
+    PINDEX j;
+    PCaselessString note = info.m_note;
+    if (note.Find ("Away") != P_MAX_INDEX)
+      presence = "away";
+    else if (note.Find ("On the phone") != P_MAX_INDEX)
+      presence = "inacall";
+    else if (note.Find ("Ringing") != P_MAX_INDEX)
+      presence = "ringing";
+    else if (note.Find ("dnd") != P_MAX_INDEX
+             || note.Find ("Do Not Disturb") != P_MAX_INDEX)
+      presence = "dnd";
+
+    else if (note.Find ("Free For Chat") != P_MAX_INDEX)
+      presence = "freeforchat";
+
+    if ((j = note.Find (" - ")) != P_MAX_INDEX)
+      status = (const char *) info.m_note.Mid (j + 3);
+  }
+
+  SIPURL sip_uri = SIPURL (info.m_entity);
+  sip_uri.Sanitise (SIPURL::ExternalURI);
+  std::string uri = sip_uri.AsString ();
+  std::string old_presence = presence_infos[uri].presence;
+  std::string old_status = presence_infos[uri].status;
+
+  // If first notification, and no information, then we are offline
+  if (presence == "unknown" && old_presence.empty ())
+    presence = "offline";
+
+  // If presence change, then signal it to the various components
+  // If presence is unknown (notification with empty body), and it is not the
+  // first notification, and we can conclude it is a ping back from the server
+  // to indicate the presence status did not change, hence we do nothing.
+  if (presence != "unknown" && (old_presence != presence || old_status != status)) {
+    presence_infos[uri].presence = presence;
+    presence_infos[uri].status = status;
+    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, this, uri, presence_infos[uri].presence, presence_infos[uri].status));
+  }
+}
+
+
+void
+Opal::Account::presence_status_in_main (std::string uri,
+					std::string presence,
+					std::string status)
+{
+  presence_received (uri, presence);
+  status_received (uri, status);
+}
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index 2fa8ac8..2cf215f 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -195,6 +195,21 @@ private:
     PSafePtr<OpalPresentity> presentity;
     void setup_presentity ();
 
+    typedef struct {
+
+      std::string presence;
+      std::string status;
+      bool requested;
+    } uri_info;
+    
+    std::map<std::string, uri_info> presence_infos;
+
+    PDECLARE_PresenceChangeNotifier (Account, OnPresenceChange);
+
+    void presence_status_in_main (std::string uri,
+				  std::string presence,
+				  std::string status);
+
     Ekiga::ServiceCore & core;
   };
 
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index fca8712..8aa3816 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -289,108 +289,3 @@ Opal::Bank::unfetch (const std::string uri)
        iter++)
     (*iter)->unfetch (uri);
 }
-
-void
-Opal::Bank::OnPresenceChange (OpalPresentity& /*presentity*/,
-			      const OpalPresenceInfo& info)
-{
-  std::string presence = "unknown";
-  std::string status;
-
-  /* we could do something precise */
-  switch (info.m_state) {
-
-  case OpalPresenceInfo::InternalError:
-  case OpalPresenceInfo::Forbidden:
-  case OpalPresenceInfo::NoPresence:
-  case OpalPresenceInfo::Unchanged:
-  case OpalPresenceInfo::Unavailable:
-    presence = "offline";
-    break;
-
-  case OpalPresenceInfo::Available:
-  case OpalPresenceInfo::UnknownExtended:
-  case OpalPresenceInfo::Appointment:
-  case OpalPresenceInfo::Away:
-  case OpalPresenceInfo::Breakfast:
-  case OpalPresenceInfo::Busy:
-  case OpalPresenceInfo::Dinner:
-  case OpalPresenceInfo::Holiday:
-  case OpalPresenceInfo::InTransit:
-  case OpalPresenceInfo::LookingForWork:
-  case OpalPresenceInfo::Lunch:
-  case OpalPresenceInfo::Meal:
-  case OpalPresenceInfo::Meeting:
-  case OpalPresenceInfo::OnThePhone:
-  case OpalPresenceInfo::Other:
-  case OpalPresenceInfo::Performance:
-  case OpalPresenceInfo::PermanentAbsence:
-  case OpalPresenceInfo::Playing:
-  case OpalPresenceInfo::Presentation:
-  case OpalPresenceInfo:: Shopping:
-  case OpalPresenceInfo::Sleeping:
-  case OpalPresenceInfo::Spectator:
-  case OpalPresenceInfo::Steering:
-  case OpalPresenceInfo::Travel:
-  case OpalPresenceInfo::TV:
-  case OpalPresenceInfo::Vacation:
-  case OpalPresenceInfo::Working:
-  case OpalPresenceInfo:: Worship:
-    presence = "online";
-    break;
-  default:
-    presence = "offline";
-    break;
-  }
-
-  if (!info.m_note.IsEmpty ()) {
-
-    PINDEX j;
-    PCaselessString note = info.m_note;
-    if (note.Find ("Away") != P_MAX_INDEX)
-      presence = "away";
-    else if (note.Find ("On the phone") != P_MAX_INDEX)
-      presence = "inacall";
-    else if (note.Find ("Ringing") != P_MAX_INDEX)
-      presence = "ringing";
-    else if (note.Find ("dnd") != P_MAX_INDEX
-             || note.Find ("Do Not Disturb") != P_MAX_INDEX)
-      presence = "dnd";
-
-    else if (note.Find ("Free For Chat") != P_MAX_INDEX)
-      presence = "freeforchat";
-
-    if ((j = note.Find (" - ")) != P_MAX_INDEX)
-      status = (const char *) info.m_note.Mid (j + 3);
-  }
-
-  SIPURL sip_uri = SIPURL (info.m_entity);
-  sip_uri.Sanitise (SIPURL::ExternalURI);
-  std::string uri = sip_uri.AsString ();
-  std::string old_presence = presence_infos[uri].presence;
-  std::string old_status = presence_infos[uri].status;
-
-  // If first notification, and no information, then we are offline
-  if (presence == "unknown" && old_presence.empty ())
-    presence = "offline";
-
-  // If presence change, then signal it to the various components
-  // If presence is unknown (notification with empty body), and it is not the
-  // first notification, and we can conclude it is a ping back from the server
-  // to indicate the presence status did not change, hence we do nothing.
-  if (presence != "unknown" && (old_presence != presence || old_status != status)) {
-    presence_infos[uri].presence = presence;
-    presence_infos[uri].status = status;
-    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Bank::presence_status_in_main, this, uri, presence_infos[uri].presence, presence_infos[uri].status));
-  }
-}
-
-
-void
-Opal::Bank::presence_status_in_main (std::string uri,
-				     std::string presence,
-				     std::string status)
-{
-  presence_received (uri, presence);
-  status_received (uri, status);
-}
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index f6bf9b6..15e08d8 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -98,12 +98,6 @@ public:
 private:
     Ekiga::ServiceCore &core;
 
-    PDECLARE_PresenceChangeNotifier (Bank, OnPresenceChange);
-
-    void presence_status_in_main (std::string uri,
-				  std::string presence,
-				  std::string status);
-
     void on_new_account_form_submitted (bool submitted,
 					Ekiga::Form& form,
 					Account::Type acc_type);
@@ -119,15 +113,6 @@ private:
 
     void save () const;
 
-    typedef struct {
-
-      std::string presence;
-      std::string status;
-      bool requested;
-    } uri_info;
-    
-    std::map<std::string, uri_info> presence_infos;
-
   };
 
   /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]