[ekiga] Hooked the loudmouth account code into the ekiga account stack



commit a7988abd4dd7e51df3ac41d38bd253e12320d4a5
Author: Julien Puydt <jpuydt gnome org>
Date:   Wed Jun 10 14:48:26 2009 +0200

    Hooked the loudmouth account code into the ekiga account stack

 .../components/loudmouth/loudmouth-account.cpp     |   64 ++++++++++++++++++--
 .../components/loudmouth/loudmouth-account.h       |   18 ++++-
 lib/engine/components/loudmouth/loudmouth-bank.cpp |    9 ++-
 lib/engine/components/loudmouth/loudmouth-bank.h   |   14 ++++-
 lib/engine/components/loudmouth/loudmouth-main.cpp |    7 ++-
 5 files changed, 96 insertions(+), 16 deletions(-)
---
diff --git a/lib/engine/components/loudmouth/loudmouth-account.cpp b/lib/engine/components/loudmouth/loudmouth-account.cpp
index bc9c99f..df37e7d 100644
--- a/lib/engine/components/loudmouth/loudmouth-account.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-account.cpp
@@ -35,6 +35,8 @@
 
 #include <iostream>
 
+#include <glib/gi18n.h>
+
 #include "loudmouth-account.h"
 
 /* here come the C callbacks, which just push to C++ code */
@@ -72,6 +74,8 @@ LM::Account::Account (gmref_ptr<Ekiga::PersonalDetails> details_,
 {
   xmlChar* xml_str = NULL;
 
+  status = _("inactive");
+
   if (node == NULL) {
 
     // FIXME: change to saner defaults
@@ -83,6 +87,7 @@ LM::Account::Account (gmref_ptr<Ekiga::PersonalDetails> details_,
     xmlSetProp (node, BAD_CAST "server", BAD_CAST "localhost");
     xmlSetProp (node, BAD_CAST "port", BAD_CAST "5222");
     xmlSetProp (node, BAD_CAST "startup", BAD_CAST "true");
+    status = _("needs configuration");
   }
 
   xml_str = xmlGetProp (node, BAD_CAST "name");
@@ -148,12 +153,12 @@ LM::Account::Account (gmref_ptr<Ekiga::PersonalDetails> details_,
 					 this, NULL);
   if (enable_on_startup) {
 
-    connect ();
+    enable ();
   }
 }
 
 void
-LM::Account::connect ()
+LM::Account::enable ()
 {
   GError *error = NULL;
   {
@@ -167,10 +172,31 @@ LM::Account::connect ()
 			    (LmResultFunction)on_connection_opened_c,
 			    this, NULL, &error)) {
 
-    // FIXME: do better
-    std::cout << error->message << std::endl;
+    gchar* message = NULL;
+
+    message = g_strdup_printf (_("error connecting (%s)"), error->message);
+    status = message;
+    g_free (message);
     g_error_free (error);
+  } else {
+
+    status = _("connecting");
   }
+
+  enable_on_startup = true;
+  trigger_saving.emit ();
+
+  updated.emit ();
+}
+
+void
+LM::Account::disable ()
+{
+
+  enable_on_startup = false;
+  trigger_saving.emit ();
+
+  lm_connection_close (connection, NULL);
 }
 
 LM::Account::~Account ()
@@ -196,11 +222,15 @@ LM::Account::on_connection_opened (bool result)
 {
   if (result) {
 
+    status = _("authenticating");
     lm_connection_authenticate (connection, user.c_str (), password.c_str (), resource.c_str (),
 				(LmResultFunction)on_authenticate_c, this, NULL, NULL);
+    updated.emit ();
   } else {
 
-    std::cout << "Error opening loudmouth connection" << std::endl; // FIXME: do better
+    /* FIXME: can't we report better? */
+    status = _("error connecting");
+    updated.emit ();
   }
 }
 
@@ -211,6 +241,8 @@ LM::Account::on_disconnected (LmDisconnectReason /*reason*/)
 
     heap->disconnected ();
     heap.reset ();
+    status = _("disconnected");
+    updated.emit ();
   }
 }
 
@@ -221,10 +253,14 @@ LM::Account::on_authenticate (bool result)
 
     heap = gmref_ptr<Heap> (new Heap (details, dialect, connection));
     cluster->add_heap (heap);
+    status = _("connected");
+    updated.emit ();
   } else {
 
     lm_connection_close (connection, NULL);
-    std::cout << "Error authenticating loudmouth account" << std::endl;
+    // FIXME: can't we report something better?
+    status = _("error authenticating loudmouth account");
+    updated.emit ();
   }
 }
 
@@ -233,3 +269,19 @@ LM::Account::get_node () const
 {
   return node;
 }
+
+bool
+LM::Account::populate_menu (Ekiga::MenuBuilder& builder)
+{
+  if (lm_connection_is_open (connection)) {
+
+    builder.add_action ("disable", _("_Disable"),
+			sigc::mem_fun (this, &LM::Account::disable));
+  } else {
+
+    builder.add_action ("enable", _("_Enable"),
+			sigc::mem_fun (this, &LM::Account::enable));
+  }
+
+  return true;
+}
diff --git a/lib/engine/components/loudmouth/loudmouth-account.h b/lib/engine/components/loudmouth/loudmouth-account.h
index bbfea1a..fa11dd0 100644
--- a/lib/engine/components/loudmouth/loudmouth-account.h
+++ b/lib/engine/components/loudmouth/loudmouth-account.h
@@ -38,15 +38,14 @@
 
 #include <libxml/tree.h>
 
-#include "gmref.h"
+#include "account.h"
 
 #include "loudmouth-cluster.h"
 
 namespace LM
 {
 
-  class Account:
-    public virtual GmRefCounted
+  class Account: public Ekiga::Account
   {
   public:
     Account (gmref_ptr<Ekiga::PersonalDetails> details_,
@@ -56,12 +55,22 @@ namespace LM
 
     ~Account ();
 
-    void connect ();
+    void enable ();
+
+    void disable ();
 
     xmlNodePtr get_node () const;
 
     sigc::signal0<void> trigger_saving;
 
+    const std::string get_name () const
+    { return name; }
+
+    const std::string get_status () const
+    { return status; }
+
+    bool populate_menu (Ekiga::MenuBuilder& builder);
+
     /* public only to be called by C callbacks */
     void on_connection_opened (bool result);
 
@@ -83,6 +92,7 @@ namespace LM
     std::string server;
     unsigned port;
     bool enable_on_startup;
+    std::string status;
 
     LmConnection* connection;
 
diff --git a/lib/engine/components/loudmouth/loudmouth-bank.cpp b/lib/engine/components/loudmouth/loudmouth-bank.cpp
index f4830c2..863a92f 100644
--- a/lib/engine/components/loudmouth/loudmouth-bank.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-bank.cpp
@@ -92,9 +92,8 @@ LM::Bank::add (xmlNodePtr node)
     save ();
   }
 
-  // FIXME : we should disconnect those when we die (RefLister-like or sigc::trackable)
   account->trigger_saving.connect (sigc::mem_fun (this, &LM::Bank::save));
-  accounts.push_back (account);
+  add_account (account);
 }
 
 void
@@ -114,3 +113,9 @@ LM::Bank::~Bank ()
 {
   std::cout << __PRETTY_FUNCTION__ << std::endl;
 }
+
+bool
+LM::Bank::populate_menu (Ekiga::MenuBuilder& builder)
+{
+  return false; // FIXME
+}
diff --git a/lib/engine/components/loudmouth/loudmouth-bank.h b/lib/engine/components/loudmouth/loudmouth-bank.h
index 52c370f..df6f5ec 100644
--- a/lib/engine/components/loudmouth/loudmouth-bank.h
+++ b/lib/engine/components/loudmouth/loudmouth-bank.h
@@ -38,6 +38,8 @@
 
 #include "services.h"
 
+#include "bank-impl.h"
+
 #include "loudmouth-account.h"
 #include "loudmouth-dialect.h"
 
@@ -45,7 +47,8 @@ namespace LM
 {
 
   class Bank:
-    public Ekiga::Service
+    public Ekiga::Service,
+    public Ekiga::BankImpl<Account>
   {
   public:
     Bank (gmref_ptr<Ekiga::PersonalDetails> details_,
@@ -54,18 +57,23 @@ namespace LM
 
     ~Bank ();
 
+    /* Service */
+
     const std::string get_name () const
     { return "loudmouth-bank"; }
 
     const std::string get_description () const
     { return "\tManager of the XMPP/Jabber accounts"; }
 
+    /* BankImpl */
+
+    bool populate_menu (Ekiga::MenuBuilder& builder);
+
   private:
 
     gmref_ptr<Ekiga::PersonalDetails> details;
     gmref_ptr<Cluster> cluster;
     gmref_ptr<Dialect> dialect;
-    std::list<gmref_ptr<Account> > accounts;
 
     xmlDocPtr doc;
 
@@ -73,6 +81,8 @@ namespace LM
 
     void save () const;
   };
+
+  typedef gmref_ptr<Bank> BankPtr;
 };
 
 #endif
diff --git a/lib/engine/components/loudmouth/loudmouth-main.cpp b/lib/engine/components/loudmouth/loudmouth-main.cpp
index a835869..ac64860 100644
--- a/lib/engine/components/loudmouth/loudmouth-main.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-main.cpp
@@ -38,6 +38,7 @@
 #include "loudmouth-main.h"
 
 #include "presence-core.h"
+#include "account-core.h"
 #include "chat-core.h"
 #include "personal-details.h"
 
@@ -55,16 +56,18 @@ struct LOUDMOUTHSpark: public Ekiga::Spark
   {
     gmref_ptr<Ekiga::Service> service(core.get ("loudmouth-bank"));
     gmref_ptr<Ekiga::PresenceCore> presence (core.get ("presence-core"));
+    gmref_ptr<Ekiga::AccountCore> account (core.get ("account-core"));
     gmref_ptr<Ekiga::ChatCore> chat (core.get ("chat-core"));
     gmref_ptr<Ekiga::PersonalDetails> details (core.get ("personal-details"));
 
-    if ( !service && presence && chat && details) {
+    if ( !service && presence && account && chat && details) {
 
       LM::DialectPtr dialect(new LM::Dialect);
       LM::ClusterPtr cluster(new LM::Cluster);
-      gmref_ptr<LM::Bank> bank (new LM::Bank (details, dialect, cluster));
+      LM::BankPtr bank (new LM::Bank (details, dialect, cluster));
       core.add (bank);
       chat->add_dialect (dialect);
+      account->add_bank (bank);
       presence->add_cluster (cluster);
       result = true;
     }



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