[ekiga] Remade the Opal::Bank an Ekiga::PresenceFetcher



commit e4ef1304e9fa96bbcddbd0a7a91bd6b337b32cbb
Author: Julien Puydt <jpuydt free fr>
Date:   Fri Jan 3 13:30:53 2014 +0100

    Remade the Opal::Bank an Ekiga::PresenceFetcher
    
    I thought it was useless, which was only half true:
    - it's useful because it provides presence for simple chats ;
    - it's useless because our ui for simple chats doesn't show
    the presence anyway!

 lib/engine/components/opal/opal-account.cpp |   40 ++++++++-------------------
 lib/engine/components/opal/opal-account.h   |    7 +++++
 lib/engine/components/opal/opal-bank.cpp    |    4 +++
 lib/engine/components/opal/opal-bank.h      |    9 ++++++
 lib/engine/components/opal/opal-main.cpp    |    1 +
 5 files changed, 33 insertions(+), 28 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 489e736..78a8178 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -76,32 +76,6 @@ canonize_uri (std::string uri)
   return uri;
 }
 
-struct presence_status_helper
-{
-  presence_status_helper (const std::string uri_,
-                         const std::string presence_,
-                         const std::string status_):
-    uri(uri_),
-    presence(presence_),
-    status(status_)
-  {}
-
-  const std::string uri;
-  const std::string presence;
-  const std::string status;
-
-  bool operator() (Ekiga::PresentityPtr pres)
-  {
-    Opal::PresentityPtr presentity = boost::dynamic_pointer_cast<Opal::Presentity> (pres);
-    if (presentity && presentity->has_uri(uri)) {
-
-      presentity->set_presence (presence);
-      presentity->set_status (status);
-    }
-    return true;
-}
-};
-
 
 xmlNodePtr
 Opal::Account::build_node(Opal::Account::Type typus,
@@ -1270,8 +1244,18 @@ Opal::Account::presence_status_in_main (std::string uri,
                                        std::string uri_presence,
                                        std::string uri_status) const
 {
-  presence_status_helper helper(uri, uri_presence, uri_status);
-  visit_presentities (helper);
+  for (const_iterator iter = begin ();
+       iter != end ();
+       ++iter) {
+
+    if ((*iter)->has_uri (uri)) {
+
+      (*iter)->set_presence (uri_presence);
+      (*iter)->set_status (uri_status);
+    }
+  }
+  presence_received (uri, uri_presence);
+  status_received (uri, uri_status);
 }
 
 void
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index 8da0691..c06ca12 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -190,6 +190,13 @@ public:
     bool populate_menu_for_group (const std::string name,
                                  Ekiga::MenuBuilder& builder);
 
+
+    /* This object is not an Ekiga::PresenceFetcher, but Opal::Bank is,
+     * this is where the information comes from
+     */
+    boost::signals2::signal<void(std::string, std::string)> presence_received;
+    boost::signals2::signal<void(std::string, std::string)> status_received;
+
 private:
     void fetch (const std::string uri) const;
     void unfetch (const std::string uri) const;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 7b9937e..bf2e193 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -88,6 +88,8 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
       Ekiga::BankImpl<Account>::add_connection (account, account->presentity_updated.connect (boost::bind 
(boost::ref(presentity_updated), account, _1)));
       Ekiga::BankImpl<Account>::add_connection (account, account->presentity_removed.connect (boost::bind 
(boost::ref(presentity_removed), account, _1)));
       Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
+      Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
+      Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
     }
   }
 
@@ -310,6 +312,8 @@ Opal::Bank::add (Account::Type acc_type,
                                    child));
   add_account (account);
   Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
+  Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref 
(presence_received)));
+  Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref 
(status_received)));
 }
 
 
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 79323a7..ce30015 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -56,6 +56,7 @@ namespace Opal
       public Ekiga::BankImpl<Account>,
       public Ekiga::Cluster,
       public Ekiga::PresencePublisher,
+      public Ekiga::PresenceFetcher,
       public Ekiga::ContactDecorator,
       public Ekiga::PresentityDecorator,
       public Ekiga::Service
@@ -84,6 +85,14 @@ public:
                       std::string password = "");
 
     /*
+     * this object is an Ekiga::PresenceFetcher
+     * (but it doesn't take orders : it just makes available to all of
+     * ekiga what it knows -- it is useful to have presence&status in chats)
+     */
+    void fetch (const std::string) {}
+    void unfetch (const std::string) {}
+
+    /*
      * this object is an Ekiga::ContactDecorator and an Ekiga::PresentityDecorator
      */
     bool populate_menu (Ekiga::ContactPtr contact,
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index 0fa18b4..e0b5e0d 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -126,6 +126,7 @@ struct OPALSpark: public Ekiga::Spark
       call_manager->ready.connect (boost::bind (&Opal::Bank::call_manager_ready, &*bank));
       call_manager->setup ();
       presence_core->add_presence_publisher (bank);
+      presence_core->add_presence_fetcher (bank);
 
       call_core->add_manager (call_manager);
 


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