[ekiga] Store the accounts in gmconf
- From: Julien Puydt <jpuydt src gnome org>
- To: svn-commits-list gnome org
- Subject: [ekiga] Store the accounts in gmconf
- Date: Thu, 11 Jun 2009 11:42:52 -0400 (EDT)
commit 6ba3575292a1b30dc9fb5d5cfb7679bc91f2bc62
Author: Julien Puydt <jpuydt noether localdomain>
Date: Fri Dec 5 03:36:36 2008 +0100
Store the accounts in gmconf
lib/engine/components/loudmouth/Makefile.am | 5 +-
.../components/loudmouth/loudmouth-account.cpp | 92 ++++++++++++++++++--
.../components/loudmouth/loudmouth-account.h | 15 ++-
lib/engine/components/loudmouth/loudmouth-bank.cpp | 69 ++++++++++++++-
lib/engine/components/loudmouth/loudmouth-bank.h | 8 ++-
5 files changed, 172 insertions(+), 17 deletions(-)
---
diff --git a/lib/engine/components/loudmouth/Makefile.am b/lib/engine/components/loudmouth/Makefile.am
index 993884a..06cda8c 100644
--- a/lib/engine/components/loudmouth/Makefile.am
+++ b/lib/engine/components/loudmouth/Makefile.am
@@ -2,9 +2,10 @@ noinst_LTLIBRARIES = libgmloudmouth.la
loudmouth_dir = $(top_srcdir)/lib/engine/components/loudmouth
-AM_CXXFLAGS = $(SIGC_CFLAGS) $(LOUDMOUTH_CFLAGS)
+AM_CXXFLAGS = $(SIGC_CFLAGS) $(XML_CFLAGS) $(LOUDMOUTH_CFLAGS)
INCLUDES = \
+ -I$(top_srcdir)/lib/gmconf \
-I$(top_srcdir)/lib/engine/framework \
-I$(top_srcdir)/lib/engine/account/skel \
-I$(top_srcdir)/lib/engine/presence/skel \
@@ -28,4 +29,4 @@ libgmloudmouth_la_SOURCES = \
$(loudmouth_dir)/loudmouth-dialect.h \
$(loudmouth_dir)/loudmouth-dialect.cpp
-libgmloudmouth_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(LOUDMOUTH_LIBS)
\ No newline at end of file
+libgmloudmouth_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(XML_LIBS) $(LOUDMOUTH_LIBS)
\ No newline at end of file
diff --git a/lib/engine/components/loudmouth/loudmouth-account.cpp b/lib/engine/components/loudmouth/loudmouth-account.cpp
index ff30417..bc9c99f 100644
--- a/lib/engine/components/loudmouth/loudmouth-account.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-account.cpp
@@ -67,17 +67,89 @@ on_authenticate_c (LmConnection* /*unused*/,
LM::Account::Account (gmref_ptr<Ekiga::PersonalDetails> details_,
gmref_ptr<Dialect> dialect_,
gmref_ptr<Cluster> cluster_,
- const std::string user_,
- const std::string password_,
- const std::string resource_,
- const std::string server_,
- unsigned port_):
- details(details_), dialect(dialect_), cluster(cluster_), user(user_), password(password_), resource(resource_), server(server_), port(port_), connection(0)
+ xmlNodePtr node_):
+ details(details_), dialect(dialect_), cluster(cluster_), node(node_)
{
+ xmlChar* xml_str = NULL;
+
+ if (node == NULL) {
+
+ // FIXME: change to saner defaults
+ node = xmlNewNode (NULL, BAD_CAST "entry");
+ xmlSetProp (node, BAD_CAST "name", BAD_CAST "Premier");
+ xmlSetProp (node, BAD_CAST "user", BAD_CAST "premier");
+ xmlSetProp (node, BAD_CAST "password", BAD_CAST "premier");
+ 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 "true");
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "name");
+ if (xml_str != NULL) {
+
+ name = (const char*)xml_str;
+ xmlFree (xml_str);
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "user");
+ if (xml_str != NULL) {
+
+ user = (const char*)xml_str;
+ xmlFree (xml_str);
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "password");
+ if (xml_str != NULL) {
+
+ password = (const char*)xml_str;
+ xmlFree (xml_str);
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "resource");
+ if (xml_str != NULL) {
+
+ resource = (const char*)xml_str;
+ xmlFree (xml_str);
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "server");
+ if (xml_str != NULL) {
+
+ server = (const char*)xml_str;
+ xmlFree (xml_str);
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "port");
+ if (xml_str != NULL) {
+
+ port = atoi ((const char*)xml_str);
+ xmlFree (xml_str);
+ } else {
+
+ port = 5222;
+ }
+
+ xml_str = xmlGetProp (node, BAD_CAST "startup");
+ if (xml_str != NULL) {
+
+ if (xmlStrEqual (xml_str, BAD_CAST "true")) {
+
+ enable_on_startup = true;
+ } else {
+
+ enable_on_startup = false;
+ }
+ xmlFree (xml_str);
+ }
+
connection = lm_connection_new (NULL);
lm_connection_set_disconnect_function (connection, (LmDisconnectFunction)on_disconnected_c,
this, NULL);
- connect ();
+ if (enable_on_startup) {
+
+ connect ();
+ }
}
void
@@ -155,3 +227,9 @@ LM::Account::on_authenticate (bool result)
std::cout << "Error authenticating loudmouth account" << std::endl;
}
}
+
+xmlNodePtr
+LM::Account::get_node () const
+{
+ return node;
+}
diff --git a/lib/engine/components/loudmouth/loudmouth-account.h b/lib/engine/components/loudmouth/loudmouth-account.h
index 753b633..bbfea1a 100644
--- a/lib/engine/components/loudmouth/loudmouth-account.h
+++ b/lib/engine/components/loudmouth/loudmouth-account.h
@@ -36,6 +36,8 @@
#ifndef __LOUDMOUTH_ACCOUNT_H__
#define __LOUDMOUTH_ACCOUNT_H__
+#include <libxml/tree.h>
+
#include "gmref.h"
#include "loudmouth-cluster.h"
@@ -50,16 +52,16 @@ namespace LM
Account (gmref_ptr<Ekiga::PersonalDetails> details_,
gmref_ptr<Dialect> dialect_,
gmref_ptr<Cluster> cluster_,
- const std::string user_,
- const std::string password_,
- const std::string resource_,
- const std::string server_,
- unsigned port_ = 5222);
+ xmlNodePtr node_);
~Account ();
void connect ();
+ xmlNodePtr get_node () const;
+
+ sigc::signal0<void> trigger_saving;
+
/* public only to be called by C callbacks */
void on_connection_opened (bool result);
@@ -72,12 +74,15 @@ namespace LM
gmref_ptr<Ekiga::PersonalDetails> details;
gmref_ptr<Dialect> dialect;
gmref_ptr<Cluster> cluster;
+ xmlNodePtr node;
+ std::string name;
std::string user;
std::string password;
std::string resource;
std::string server;
unsigned port;
+ bool enable_on_startup;
LmConnection* connection;
diff --git a/lib/engine/components/loudmouth/loudmouth-bank.cpp b/lib/engine/components/loudmouth/loudmouth-bank.cpp
index 29a96bf..f4830c2 100644
--- a/lib/engine/components/loudmouth/loudmouth-bank.cpp
+++ b/lib/engine/components/loudmouth/loudmouth-bank.cpp
@@ -35,14 +35,79 @@
#include <iostream>
+#include "gmconf.h"
+
+#include "config.h"
+
#include "loudmouth-bank.h"
+#define KEY "/apps/" PACKAGE_NAME "/contacts/jabber"
+
LM::Bank::Bank (gmref_ptr<Ekiga::PersonalDetails> details_,
gmref_ptr<Dialect> dialect_,
gmref_ptr<Cluster> cluster_):
- details(details_), cluster(cluster_), dialect(dialect_)
+ details(details_), cluster(cluster_), dialect(dialect_), doc (NULL)
+{
+ gchar* c_raw = gm_conf_get_string (KEY);
+
+ if (c_raw != NULL) { // we already have it in store
+
+ const std::string raw = c_raw;
+ doc = xmlRecoverMemory (raw.c_str (), raw.length ());
+ xmlNodePtr root = xmlDocGetRootElement (doc);
+ if (root == NULL) {
+
+ root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL);
+ xmlDocSetRootElement (doc, root);
+ }
+
+ for (xmlNodePtr child = root->children; child != NULL; child = child->next) {
+
+ if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("entry"), child->name)) {
+
+ add (child);
+ }
+ }
+ g_free (c_raw);
+
+ } else { // create a new XML document
+
+ doc = xmlNewDoc (BAD_CAST "1.0");
+ xmlNodePtr root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL);
+ xmlDocSetRootElement (doc, root);
+ add (NULL);
+ }
+}
+
+void
+LM::Bank::add (xmlNodePtr node)
+{
+ gmref_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 ();
+ }
+
+ // 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);
+}
+
+void
+LM::Bank::save () const
{
- account = gmref_ptr<Account>(new Account (details, dialect, cluster, "premier", "premier", "ekiga", "localhost"));
+ xmlChar* buffer = NULL;
+ int size = 0;
+
+ xmlDocDumpMemory (doc, &buffer, &size);
+
+ gm_conf_set_string (KEY, (const char *)buffer);
+
+ xmlFree (buffer);
}
LM::Bank::~Bank ()
diff --git a/lib/engine/components/loudmouth/loudmouth-bank.h b/lib/engine/components/loudmouth/loudmouth-bank.h
index 2b4ee2e..52c370f 100644
--- a/lib/engine/components/loudmouth/loudmouth-bank.h
+++ b/lib/engine/components/loudmouth/loudmouth-bank.h
@@ -65,7 +65,13 @@ namespace LM
gmref_ptr<Ekiga::PersonalDetails> details;
gmref_ptr<Cluster> cluster;
gmref_ptr<Dialect> dialect;
- gmref_ptr<Account> account;
+ std::list<gmref_ptr<Account> > accounts;
+
+ xmlDocPtr doc;
+
+ void add (xmlNodePtr node);
+
+ void save () const;
};
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]