[ekiga] Made creating an XMPP/Jabber account nicer



commit 2891e44120d46d7e476887174482f5c8f693d156
Author: Snark <jpuydt gnome org>
Date:   Thu Feb 17 20:21:35 2011 +0100

    Made creating an XMPP/Jabber account nicer
    
    Previously, the account was created with a name that said "configure me"...
    
    Now the user get prompted a nice form ; just like for SIP accounts

 plugins/loudmouth/loudmouth-account.cpp |   61 ++++++++++++++++++++++--------
 plugins/loudmouth/loudmouth-account.h   |    8 ++++
 plugins/loudmouth/loudmouth-bank.cpp    |   63 ++++++++++++++++++++++++------
 plugins/loudmouth/loudmouth-bank.h      |    7 +++-
 4 files changed, 109 insertions(+), 30 deletions(-)
---
diff --git a/plugins/loudmouth/loudmouth-account.cpp b/plugins/loudmouth/loudmouth-account.cpp
index 47f88f4..badea4c 100644
--- a/plugins/loudmouth/loudmouth-account.cpp
+++ b/plugins/loudmouth/loudmouth-account.cpp
@@ -33,6 +33,8 @@
  *
  */
 
+#include <sstream>
+
 #include <glib/gi18n.h>
 
 #include "form-request-simple.h"
@@ -72,25 +74,12 @@ LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
 		      xmlNodePtr node_):
   details(details_), dialect(dialect_), cluster(cluster_), node(node_)
 {
-  xmlChar* xml_str = NULL;
-  bool enable_on_startup = false;
+  if (node == NULL) throw std::logic_error ("NULL node pointer received");
 
   status = _("inactive");
 
-  if (node == NULL) {
-
-    node = xmlNewNode (NULL, BAD_CAST "entry");
-    /* FIXME: make translatable */
-    xmlSetProp (node, BAD_CAST "name", BAD_CAST "Jabber/XMPP account to configure");
-    xmlSetProp (node, BAD_CAST "user", BAD_CAST "username");
-    xmlSetProp (node, BAD_CAST "password", BAD_CAST "");
-    xmlSetProp (node, BAD_CAST "resource", BAD_CAST "ekiga");
-    xmlSetProp (node, BAD_CAST "server", BAD_CAST "localhost");
-    xmlSetProp (node, BAD_CAST "port", BAD_CAST "5222");
-    xmlSetProp (node, BAD_CAST "startup", BAD_CAST "false");
-  }
-
-  xml_str = xmlGetProp (node, BAD_CAST "startup");
+  xmlChar* xml_str = xmlGetProp (node, BAD_CAST "startup");
+  bool enable_on_startup = false;
   if (xml_str != NULL) {
 
     if (xmlStrEqual (xml_str, BAD_CAST "true")) {
@@ -112,6 +101,46 @@ LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
   }
 }
 
+LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
+		      boost::shared_ptr<Dialect> dialect_,
+		      boost::shared_ptr<Cluster> cluster_,
+		      const std::string name, const std::string user,
+		      const std::string server, int port,
+		      const std::string resource, const std::string password,
+		      bool enable_on_startup):
+  details(details_), dialect(dialect_), cluster(cluster_)
+{
+  status = _("inactive");
+
+  node = xmlNewNode (NULL, BAD_CAST "entry");
+  xmlSetProp (node, BAD_CAST "name", BAD_CAST name.c_str ());
+  xmlSetProp (node, BAD_CAST "user", BAD_CAST user.c_str ());
+  xmlSetProp (node, BAD_CAST "server", BAD_CAST server.c_str ());
+  {
+    std::stringstream sstream;
+    sstream << port;
+    xmlSetProp (node, BAD_CAST "port", BAD_CAST sstream.str ().c_str ());
+  }
+  xmlSetProp (node, BAD_CAST "resource", BAD_CAST resource.c_str ());
+  xmlSetProp (node, BAD_CAST "password", BAD_CAST password.c_str ());
+
+  if (enable_on_startup) {
+
+    xmlSetProp (node, BAD_CAST "startup", BAD_CAST "true");
+  } else {
+
+    xmlSetProp (node, BAD_CAST "startup", BAD_CAST "false");
+  }
+
+  connection = lm_connection_new (NULL);
+  lm_connection_set_disconnect_function (connection, (LmDisconnectFunction)on_disconnected_c,
+					 this, NULL);
+  if (enable_on_startup) {
+
+    enable ();
+  }
+}
+
 void
 LM::Account::enable ()
 {
diff --git a/plugins/loudmouth/loudmouth-account.h b/plugins/loudmouth/loudmouth-account.h
index 0d681b7..eaa0732 100644
--- a/plugins/loudmouth/loudmouth-account.h
+++ b/plugins/loudmouth/loudmouth-account.h
@@ -53,6 +53,14 @@ namespace LM
 	     boost::shared_ptr<Cluster> cluster_,
 	     xmlNodePtr node_);
 
+    Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
+	     boost::shared_ptr<Dialect> dialect_,
+	     boost::shared_ptr<Cluster> cluster_,
+	     const std::string name, const std::string user,
+	     const std::string server, int port,
+	     const std::string resource, const std::string password,
+	     bool enable_on_startup);
+
     ~Account ();
 
     void enable ();
diff --git a/plugins/loudmouth/loudmouth-bank.cpp b/plugins/loudmouth/loudmouth-bank.cpp
index 6d4b480..fa56829 100644
--- a/plugins/loudmouth/loudmouth-bank.cpp
+++ b/plugins/loudmouth/loudmouth-bank.cpp
@@ -41,6 +41,8 @@
 
 #include "loudmouth-bank.h"
 
+#include "form-request-simple.h"
+
 #define KEY "/apps/" PACKAGE_NAME "/contacts/jabber"
 
 LM::Bank::Bank (boost::shared_ptr<Ekiga::PersonalDetails> details_,
@@ -65,7 +67,8 @@ LM::Bank::Bank (boost::shared_ptr<Ekiga::PersonalDetails> details_,
 
       if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("entry"), child->name)) {
 
-	add (child);
+	boost::shared_ptr<Account> account (new Account (details, dialect, cluster, child));
+	add (account);
       }
     }
     g_free (c_raw);
@@ -79,18 +82,8 @@ LM::Bank::Bank (boost::shared_ptr<Ekiga::PersonalDetails> details_,
 }
 
 void
-LM::Bank::add (xmlNodePtr node)
+LM::Bank::add (boost::shared_ptr<Account> account)
 {
-  boost::shared_ptr<Account> account (new Account (details, dialect, cluster, node));
-
-  if (node == NULL) { // that was a new one
-
-    xmlNodePtr root = xmlDocGetRootElement (doc);
-    xmlAddChild (root, account->get_node ());
-
-    save ();
-  }
-
   account->trigger_saving.connect (boost::bind (&LM::Bank::save, this));
   add_account (account);
 }
@@ -116,6 +109,50 @@ bool
 LM::Bank::populate_menu (Ekiga::MenuBuilder& builder)
 {
   builder.add_action ("add", _("_Add a jabber/XMPP account"),
-		      boost::bind (&LM::Bank::add, this, (xmlNodePtr)NULL));
+		      boost::bind (&LM::Bank::new_account, this));
   return true;
 }
+
+void
+LM::Bank::new_account ()
+{
+  boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&LM::Bank::on_new_account_form_submitted, this, _1, _2)));
+
+  request->title (_("Edit account"));
+
+  request->instructions (_("Please fill in the following fields:"));
+
+  request->text ("name", _("Name:"), "", "");
+  request->text ("user", _("User:"), "", "");
+  request->text ("server", _("Server:"), "", "");
+  request->text ("resource", _("Resource:"), "", "");
+  request->private_text ("password", _("Password:"), "", "");
+  request->boolean ("enabled", _("Enable Account"), true);
+
+  questions (request);
+}
+
+void
+LM::Bank::on_new_account_form_submitted (bool submitted,
+					 Ekiga::Form &result)
+{
+  if (!submitted)
+    return;
+
+  std::string name = result.text ("name");
+  std::string user = result.text ("user");
+  std::string server = result.text ("server");
+  std::string resource = result.text ("resource");
+  std::string password = result.private_text ("password");
+  bool enable_on_startup = result.boolean ("enabled");
+
+  boost::shared_ptr<Account> account (new Account (details, dialect, cluster,
+						   name, user, server, 5222,
+						   resource, password,
+						   enable_on_startup));
+  xmlNodePtr root = xmlDocGetRootElement (doc);
+  xmlAddChild (root, account->get_node ());
+
+  save ();
+  add (account);
+}
diff --git a/plugins/loudmouth/loudmouth-bank.h b/plugins/loudmouth/loudmouth-bank.h
index 91e0411..4e91630 100644
--- a/plugins/loudmouth/loudmouth-bank.h
+++ b/plugins/loudmouth/loudmouth-bank.h
@@ -77,9 +77,14 @@ namespace LM
 
     xmlDocPtr doc;
 
-    void add (xmlNodePtr node);
+    void add (boost::shared_ptr<Account> account);
 
     void save () const;
+
+    void new_account ();
+
+    void on_new_account_form_submitted (bool submitted,
+					Ekiga::Form& result);
   };
 
   typedef boost::shared_ptr<Bank> BankPtr;



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