[ekiga/ds-gtk-application] Opal Accounts: Enable/disable actions when accounts are added/removed.



commit ac59681b5a329b3a9adf2f124801e52ddca40ed7
Author: Damien Sandras <dsandras seconix com>
Date:   Thu Dec 25 12:13:00 2014 +0100

    Opal Accounts: Enable/disable actions when accounts are added/removed.
    
    Ekiga Call Out and Ekiga.net account related actions are now added and
    removed following such an account exist or not.

 lib/engine/components/opal/opal-account.cpp |   44 ++++++++++++++--
 lib/engine/components/opal/opal-account.h   |    8 ++-
 lib/engine/components/opal/opal-bank.cpp    |   76 ++++++++++-----------------
 lib/engine/components/opal/opal-bank.h      |    2 -
 4 files changed, 73 insertions(+), 57 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 1104491..aaa1a98 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -112,6 +112,9 @@ Opal::Account::build_node(Opal::Account::Type typus,
     xmlSetProp (node, BAD_CAST "timeout", BAD_CAST sstream.str ().c_str ());
   }
 
+  // FIXME: One improvement could be to use inheritance here and have
+  //        specific objects for specific accounts types.
+  //        Would it be considered cleaner or overkill?
   switch (typus) {
 
   case Ekiga:
@@ -138,7 +141,8 @@ Opal::Account::build_node(Opal::Account::Type typus,
 }
 
 
-Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+Opal::Account::Account (Opal::Bank & _bank,
+                        boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
                        boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
                        boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
                        boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
@@ -148,6 +152,7 @@ Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
                        xmlNodePtr _node):
   existing_groups(_existing_groups),
   node(_node),
+  bank(_bank),
   sip_endpoint(_sip_endpoint),
   presence_core(_presence_core),
   notification_core(_notification_core),
@@ -216,20 +221,37 @@ Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
 
     url.str ("");
     url << str.str () << "&act=rch";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("recharge-account", _("Recharge the account"),
+    bank.add_action (Ekiga::ActionPtr (new Ekiga::Action ("recharge-account", _("Recharge the Ekiga Call Out 
account"),
+                                                          boost::bind (&Opal::Account::on_consult, this, 
url.str ()))));
+    add_action (Ekiga::ActionPtr (new Ekiga::Action ("recharge-account", _("Recharge the Ekiga Call Out 
account"),
                                                      boost::bind (&Opal::Account::on_consult, this, url.str 
()))));
     url.str ("");
     url << str.str () << "&act=bh";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("balance-account", _("Consult the balance history"),
+    bank.add_action (Ekiga::ActionPtr (new Ekiga::Action ("balance-account", _("Consult the Ekiga Call Out 
balance history"),
+                                                          boost::bind (&Opal::Account::on_consult, this, 
url.str ()))));
+    add_action (Ekiga::ActionPtr (new Ekiga::Action ("balance-account", _("Consult the Ekiga Call Out 
balance history"),
                                                      boost::bind (&Opal::Account::on_consult, this, url.str 
()))));
     url.str ("");
     url << str.str () << "&act=ch";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("history-account", _("Consult the call history"),
+    bank.add_action (Ekiga::ActionPtr (new Ekiga::Action ("history-account", _("Consult the Ekiga Call Out 
call history"),
+                                                          boost::bind (&Opal::Account::on_consult, this, 
url.str ()))));
+    add_action (Ekiga::ActionPtr (new Ekiga::Action ("history-account", _("Consult the Ekiga Call Out call 
history"),
                                                      boost::bind (&Opal::Account::on_consult, this, url.str 
()))));
+
+    bank.disable_action ("add-account-diamondcard");
+  }
+  else if (type == Ekiga) {
+
+    bank.disable_action ("add-account-ekiga");
   }
 }
 
 
+Opal::Account::~Account ()
+{
+}
+
+
 std::list<std::string>
 Opal::Account::get_groups () const
 {
@@ -567,11 +589,23 @@ Opal::Account::remove ()
     return;
   }
 
+  if (type == DiamondCard) {
+
+    bank.remove_action ("recharge-account");
+    bank.remove_action ("balance-account");
+    bank.remove_action ("history-account");
+    bank.enable_action ("add-account-diamondcard");
+  }
+  else if (type == Ekiga) {
+    bank.enable_action ("add-account-ekiga");
+  }
+
   xmlUnlinkNode (node);
   xmlFreeNode (node);
 
   trigger_saving ();
-  removed ();
+  Ekiga::Heap::removed ();
+  Ekiga::Account::removed ();
 }
 
 
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index 0966903..7309012 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -55,6 +55,7 @@
 namespace Opal
 {
   // forward declarations:
+  class Bank;
   class CallManager;
   class Presentity;
   namespace Sip { class EndPoint; };
@@ -84,7 +85,8 @@ public:
                                  bool enabled,
                                  unsigned timeout);
 
-    Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+    Account (Opal::Bank & bank,
+             boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
             boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
             boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
             boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
@@ -93,7 +95,7 @@ public:
             boost::function0<std::list<std::string> > _existing_groups,
             xmlNodePtr node_);
 
-    ~Account () {}
+    ~Account ();
 
     const std::string get_name () const;
 
@@ -243,6 +245,8 @@ private:
     void when_presentity_removed (boost::shared_ptr<Opal::Presentity> pres);
     void when_presentity_updated (boost::shared_ptr<Opal::Presentity> pres);
 
+    Opal::Bank & bank;
+
     boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     boost::weak_ptr<Ekiga::NotificationCore> notification_core;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 916d695..2ddc7d8 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -42,7 +42,6 @@
 
 #include <glib/gi18n.h>
 
-#include "platform.h"
 #include "menu-builder.h"
 #include "form-request-simple.h"
 
@@ -64,6 +63,10 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
 
   const std::string raw = protocols_settings->get_string ("accounts");
 
+  /* Actor stuff */
+  add_actions ();
+
+  /* Populate Accounts */
   doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
   if (!doc)
     doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
@@ -81,9 +84,15 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
         && child->name != NULL
         && xmlStrEqual(BAD_CAST "account", child->name)) {
 
-      boost::shared_ptr<Account> account(new Account (sip_endpoint, presence_core, notification_core,
-                                                      personal_details, audiooutput_core, opal_component,
-                                                      boost::bind(&Opal::Bank::existing_groups, this), 
child));
+      boost::shared_ptr<Account> account(new Account (*this,
+                                                      sip_endpoint,
+                                                      presence_core,
+                                                      notification_core,
+                                                      personal_details,
+                                                      audiooutput_core,
+                                                      opal_component,
+                                                      boost::bind(&Opal::Bank::existing_groups, this),
+                                                      child));
 
       add_account (account);
       Ekiga::BankImpl<Account>::add_connection (account, account->presentity_added.connect (boost::bind 
(boost::ref(presentity_added), account, _1)));
@@ -108,9 +117,6 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
   account_updated.connect (boost::bind (&Opal::Bank::update_sip_endpoint_aor_map, this));
   account_removed.connect (boost::bind (&Opal::Bank::update_sip_endpoint_aor_map, this));
   update_sip_endpoint_aor_map ();
-
-  /* Actor stuff */
-  add_actions ();
 }
 
 
@@ -251,7 +257,8 @@ Opal::Bank::add (Account::Type acc_type,
   save ();
 
   AccountPtr account
-    = AccountPtr(new Opal::Account (sip_endpoint,
+    = AccountPtr(new Opal::Account (*this,
+                                    sip_endpoint,
                                    presence_core,
                                    notification_core,
                                    personal_details,
@@ -507,48 +514,21 @@ Opal::Bank::migrate_from_gconf (const std::list<std::string> old)
 
 
 void
-Opal::Bank::on_consult (const std::string url)
-{
-  gm_platform_open_uri (url.c_str ());
-}
-
-
-void
 Opal::Bank::add_actions ()
 {
-  Opal::AccountPtr account = find_account ("ekiga.net");
-  if (!account)
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-account-ekiga",
-                                                     _("_Add an Ekiga.net Account"),
-                                                     boost::bind (&Opal::Bank::new_account, this,
-                                                                  Opal::Account::Ekiga, "", ""))));
-  account = find_account ("sip.diamondcard.us");
-  if (account) {
-    std::stringstream str;
-    std::stringstream url;
-    str << "https://www.diamondcard.us/exec/voip-login?accId="; << account->get_username () << "&pinCode=" << 
account->get_password () << "&spo=ekiga";
-
-    url.str ("");
-    url << str.str () << "&act=rch";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("recharge-account-diamondcard",
-                                                     _("Recharge the Ekiga Call Out account"),
-                                                     boost::bind (&Opal::Bank::on_consult, this, url.str 
()))));
-    url.str ("");
-    url << str.str () << "&act=bh";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("balance-account-diamondcard",
-                                                     _("Consult the Ekiga Call Out balance history"),
-                                                     boost::bind (&Opal::Bank::on_consult, this, url.str 
()))));
-    url.str ("");
-    url << str.str () << "&act=ch";
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("history-account-diamondcard",
-                                                     _("Consult the Ekiga Call Out call history"),
-                                                     boost::bind (&Opal::Bank::on_consult, this, url.str 
()))));
-  }
-  else
-    add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-account-diamondcard",
-                                                     _("_Add an Ekiga Call Out Account"),
-                                                     boost::bind (&Opal::Bank::new_account, this,
-                                                                  Opal::Account::DiamondCard, "", ""))));
+  // Will be disabled when an Ekiga.net account is added
+  // and enabled back when an Ekiga.net account is removed
+  add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-account-ekiga",
+                                                   _("_Add an Ekiga.net Account"),
+                                                   boost::bind (&Opal::Bank::new_account, this,
+                                                                Opal::Account::Ekiga, "", ""))));
+
+  // Will be disabled when a DiamondCard account is added
+  // and enabled back when an DiamondCard account is removed
+  add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-account-diamondcard",
+                                                 _("_Add an Ekiga Call Out Account"),
+                                                 boost::bind (&Opal::Bank::new_account, this,
+                                                              Opal::Account::DiamondCard, "", ""))));
   add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-account-sip", _("_Add a SIP Account"),
                                                    boost::bind (&Opal::Bank::new_account, this,
                                                                 Opal::Account::SIP, "", ""))));
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 0df22c4..520d0ab 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -147,8 +147,6 @@ private:
 
     void update_sip_endpoint_aor_map ();
 
-    void on_consult (const std::string url);
-
     void add_actions ();
 
     Ekiga::Settings *protocols_settings;


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