[ekiga] Modified the way the local roster interacts with Ekiga::ServiceCore
- From: Julien Puydt <jpuydt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Modified the way the local roster interacts with Ekiga::ServiceCore
- Date: Wed, 23 Jan 2013 08:54:25 +0000 (UTC)
commit b7c1947718d8fda21932823ad03b4e55247544ae
Author: Julien Puydt <jpuydt free fr>
Date: Wed Jan 23 09:47:29 2013 +0100
Modified the way the local roster interacts with Ekiga::ServiceCore
Made it interact at startup only
.../components/local-roster/local-cluster.cpp | 31 ++++++++++-----
lib/engine/components/local-roster/local-cluster.h | 9 +++-
lib/engine/components/local-roster/local-heap.cpp | 32 +++++++++++-----
lib/engine/components/local-roster/local-heap.h | 7 ++-
.../components/local-roster/local-presentity.cpp | 40 +++++++++++++-------
.../components/local-roster/local-presentity.h | 13 ++++--
.../components/local-roster/local-roster-main.cpp | 6 ++-
7 files changed, 91 insertions(+), 47 deletions(-)
---
diff --git a/lib/engine/components/local-roster/local-cluster.cpp b/lib/engine/components/local-roster/local-cluster.cpp
index 6201494..6d8f5c3 100644
--- a/lib/engine/components/local-roster/local-cluster.cpp
+++ b/lib/engine/components/local-roster/local-cluster.cpp
@@ -40,16 +40,9 @@
#include "local-cluster.h"
-Local::Cluster::Cluster (Ekiga::ServiceCore &_core): core(_core)
+Local::Cluster::Cluster (boost::shared_ptr<Ekiga::PresenceCore> pcore):
+ presence_core (pcore)
{
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-
- heap = HeapPtr (new Heap (core));
-
- presence_core->presence_received.connect (boost::bind (&Local::Cluster::on_presence_received, this, _1, _2));
- presence_core->status_received.connect (boost::bind (&Local::Cluster::on_status_received, this, _1, _2));
-
- add_heap (heap);
}
Local::Cluster::~Cluster ()
@@ -59,9 +52,12 @@ Local::Cluster::~Cluster ()
bool
Local::Cluster::is_supported_uri (const std::string uri) const
{
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
- return presence_core->is_supported_uri (uri);
+ if (pcore)
+ return pcore->is_supported_uri (uri);
+ else
+ return false;
}
void
@@ -86,6 +82,19 @@ Local::Cluster::populate_menu (Ekiga::MenuBuilder& builder)
}
void
+Local::Cluster::set_heap (HeapPtr _heap)
+{
+ heap = _heap;
+ add_heap (heap);
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+ if (pcore) {
+
+ pcore->presence_received.connect (boost::bind (&Local::Cluster::on_presence_received, this, _1, _2));
+ pcore->status_received.connect (boost::bind (&Local::Cluster::on_status_received, this, _1, _2));
+ }
+}
+
+void
Local::Cluster::on_new_presentity ()
{
heap->new_presentity ("", "");
diff --git a/lib/engine/components/local-roster/local-cluster.h b/lib/engine/components/local-roster/local-cluster.h
index dc8fa46..5d9f01f 100644
--- a/lib/engine/components/local-roster/local-cluster.h
+++ b/lib/engine/components/local-roster/local-cluster.h
@@ -55,7 +55,7 @@ namespace Local
{
public:
- Cluster (Ekiga::ServiceCore &_core);
+ Cluster (boost::shared_ptr<Ekiga::PresenceCore> _presence_core);
~Cluster ();
@@ -73,12 +73,15 @@ namespace Local
const std::set<std::string> existing_groups () const;
- HeapPtr get_heap ()
+ HeapPtr get_heap () const
{ return heap; }
+ // used by the local roster main code
+ void set_heap (HeapPtr _heap);
+
private:
- Ekiga::ServiceCore &core;
+ boost::weak_ptr<Ekiga::PresenceCore> presence_core;
HeapPtr heap;
void on_new_presentity ();
diff --git a/lib/engine/components/local-roster/local-heap.cpp b/lib/engine/components/local-roster/local-heap.cpp
index 3295986..5639fa7 100644
--- a/lib/engine/components/local-roster/local-heap.cpp
+++ b/lib/engine/components/local-roster/local-heap.cpp
@@ -42,13 +42,16 @@
#include "gmconf.h"
#include "form-request-simple.h"
+#include "local-cluster.h"
#include "local-heap.h"
#include "local-presentity.h"
/*
* Public API
*/
-Local::Heap::Heap (Ekiga::ServiceCore &_core): core (_core), doc ()
+Local::Heap::Heap (boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+ boost::shared_ptr<Local::Cluster> _local_cluster):
+ presence_core(_presence_core), local_cluster(_local_cluster), doc ()
{
xmlNodePtr root;
gchar *c_raw = gm_conf_get_string (ROSTER_KEY);
@@ -223,7 +226,10 @@ Local::Heap::new_presentity (const std::string name,
{
if (!has_presentity_with_uri (uri)) {
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+ if (!pcore)
+ return;
+
boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&Local::Heap::new_presentity_form_submitted, this, _1, _2)));
std::set<std::string> groups = existing_groups ();
@@ -231,7 +237,7 @@ Local::Heap::new_presentity (const std::string name,
request->instructions (_("Please fill in this form to add a new contact "
"to ekiga's internal roster"));
request->text ("name", _("Name:"), name, _("Name of the contact, as shown in your roster"));
- if (presence_core->is_supported_uri (uri)) {
+ if (pcore->is_supported_uri (uri)) {
request->hidden ("good-uri", "yes");
request->hidden ("uri", uri);
@@ -322,7 +328,8 @@ Local::Heap::push_status (const std::string uri,
void
Local::Heap::add (xmlNodePtr node)
{
- PresentityPtr presentity (new Presentity (core, doc, node));
+ PresentityPtr presentity (new Presentity (local_cluster, presence_core,
+ doc, node));
common_add (presentity);
}
@@ -336,7 +343,8 @@ Local::Heap::add (const std::string name,
xmlNodePtr root = NULL;
root = xmlDocGetRootElement (doc.get ());
- PresentityPtr presentity (new Presentity (core, doc, name, uri, groups));
+ PresentityPtr presentity (new Presentity (local_cluster, presence_core,
+ doc, name, uri, groups));
xmlAddChild (root, presentity->get_node ());
@@ -348,13 +356,14 @@ Local::Heap::add (const std::string name,
void
Local::Heap::common_add (PresentityPtr presentity)
{
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
// Add the presentity to this Heap
add_presentity (presentity);
// Fetch presence
- presence_core->fetch_presence (presentity->get_uri ());
+ if (pcore)
+ pcore->fetch_presence (presentity->get_uri ());
// Connect the Local::Presentity signals.
add_connection (presentity, presentity->trigger_saving.connect (boost::bind (&Local::Heap::save, this)));
@@ -382,7 +391,10 @@ Local::Heap::new_presentity_form_submitted (bool submitted,
if (!submitted)
return;
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+ if (!pcore)
+ return;
+
const std::string name = result.text ("name");
const std::string good_uri = result.hidden ("good-uri");
std::string uri;
@@ -395,7 +407,7 @@ Local::Heap::new_presentity_form_submitted (bool submitted,
uri = canonize_uri (uri);
- if (presence_core->is_supported_uri (uri)
+ if (pcore->is_supported_uri (uri)
&& !has_presentity_with_uri (uri)) {
add (name, uri, groups);
@@ -405,7 +417,7 @@ Local::Heap::new_presentity_form_submitted (bool submitted,
boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple>(new Ekiga::FormRequestSimple (boost::bind (&Local::Heap::new_presentity_form_submitted, this, _1, _2)));
result.visit (*request);
- if (!presence_core->is_supported_uri (uri))
+ if (!pcore->is_supported_uri (uri))
request->error (_("You supplied an unsupported address"));
else
request->error (_("You already have a contact with this address!"));
diff --git a/lib/engine/components/local-roster/local-heap.h b/lib/engine/components/local-roster/local-heap.h
index e571c2d..820e846 100644
--- a/lib/engine/components/local-roster/local-heap.h
+++ b/lib/engine/components/local-roster/local-heap.h
@@ -41,7 +41,6 @@
#include "friend-or-foe.h"
#include "local-presentity.h"
-
namespace Local
{
/**
@@ -73,7 +72,8 @@ namespace Local
* @param: The Ekiga::ServiceCore to use to trigger operations on other
* components.
*/
- Heap (Ekiga::ServiceCore &_core);
+ Heap (boost::shared_ptr<Ekiga::PresenceCore> presence_core,
+ boost::shared_ptr<Local::Cluster> local_cluster);
/** The destructor.
@@ -205,7 +205,8 @@ namespace Local
bool submitted,
Ekiga::Form& result);
- Ekiga::ServiceCore &core;
+ boost::weak_ptr<Ekiga::PresenceCore> presence_core;
+ boost::weak_ptr<Local::Cluster> local_cluster;
boost::shared_ptr<xmlDoc> doc;
};
diff --git a/lib/engine/components/local-roster/local-presentity.cpp b/lib/engine/components/local-roster/local-presentity.cpp
index 9f427f8..2627f3e 100644
--- a/lib/engine/components/local-roster/local-presentity.cpp
+++ b/lib/engine/components/local-roster/local-presentity.cpp
@@ -76,20 +76,22 @@ struct null_deleter
/*
* Public API
*/
-Local::Presentity::Presentity (Ekiga::ServiceCore &_core,
+Local::Presentity::Presentity (boost::weak_ptr<Local::Cluster> _local_cluster,
+ boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
boost::shared_ptr<xmlDoc> _doc,
- xmlNodePtr _node) :
- core(_core), doc(_doc), node(_node), presence("unknown")
+ xmlNodePtr _node):
+ local_cluster(_local_cluster), presence_core(_presence_core), doc(_doc), node(_node), presence("unknown")
{
}
-Local::Presentity::Presentity (Ekiga::ServiceCore &_core,
+Local::Presentity::Presentity (boost::weak_ptr<Local::Cluster> _local_cluster,
+ boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
boost::shared_ptr<xmlDoc> _doc,
const std::string name,
const std::string uri,
const std::set<std::string> groups) :
- core(_core), doc(_doc), presence("unknown")
+ local_cluster(_local_cluster), presence_core(_presence_core), doc(_doc), presence("unknown")
{
node = xmlNewNode (NULL, BAD_CAST "entry");
xmlSetProp (node, BAD_CAST "uri", BAD_CAST uri.c_str ());
@@ -228,11 +230,14 @@ bool
Local::Presentity::populate_menu (Ekiga::MenuBuilder &builder)
{
bool populated = false;
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+
+ if (!pcore)
+ return false;
populated
- = presence_core->populate_presentity_menu (PresentityPtr(this, null_deleter ()),
- get_uri (), builder);
+ = pcore->populate_presentity_menu (PresentityPtr(this, null_deleter ()),
+ get_uri (), builder);
if (populated)
builder.add_separator ();
@@ -256,7 +261,11 @@ Local::Presentity::get_node () const
void
Local::Presentity::edit_presentity ()
{
- ClusterPtr cluster = core.get<Local::Cluster> ("local-cluster");
+ ClusterPtr cluster = local_cluster.lock ();
+
+ if (!cluster)
+ return;
+
boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&Local::Presentity::edit_presentity_form_submitted, this, _1, _2)));
std::string name = get_name ();
@@ -311,10 +320,12 @@ Local::Presentity::edit_presentity_form_submitted (bool submitted,
if (uri != new_uri) {
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
- presence_core->unfetch_presence (uri);
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+ if (pcore) {
+ pcore->unfetch_presence (uri);
+ pcore->fetch_presence (new_uri);
+ }
presence = "unknown";
- presence_core->fetch_presence (new_uri);
xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ());
}
@@ -441,8 +452,9 @@ Local::Presentity::rename_group (const std::string old_name,
void
Local::Presentity::remove ()
{
- boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
- presence_core->unfetch_presence (get_uri ());
+ boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+ if (pcore)
+ pcore->unfetch_presence (get_uri ());
xmlUnlinkNode (node);
xmlFreeNode (node);
diff --git a/lib/engine/components/local-roster/local-presentity.h b/lib/engine/components/local-roster/local-presentity.h
index 9b315b3..f83ff09 100644
--- a/lib/engine/components/local-roster/local-presentity.h
+++ b/lib/engine/components/local-roster/local-presentity.h
@@ -54,6 +54,8 @@ std::string canonize_uri (std::string uri);
namespace Local
{
+ class Cluster;
+
/**
* @addtogroup presence
* @internal
@@ -76,11 +78,13 @@ namespace Local
/**
* Constructors (and destructor)
*/
- Presentity (Ekiga::ServiceCore &_core,
+ Presentity (boost::weak_ptr<Local::Cluster> _local_cluster,
+ boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
boost::shared_ptr<xmlDoc> _doc,
xmlNodePtr _node);
- Presentity (Ekiga::ServiceCore &_core,
+ Presentity (boost::weak_ptr<Local::Cluster> _local_cluster,
+ boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
boost::shared_ptr<xmlDoc> _doc,
const std::string _name,
const std::string _uri,
@@ -186,8 +190,9 @@ namespace Local
Ekiga::Form &result);
- Ekiga::ServiceCore &core;
-
+ boost::weak_ptr<Local::Cluster> local_cluster;
+ boost::weak_ptr<Ekiga::PresenceCore> presence_core;
+
boost::shared_ptr<xmlDoc> doc;
xmlNodePtr node;
diff --git a/lib/engine/components/local-roster/local-roster-main.cpp b/lib/engine/components/local-roster/local-roster-main.cpp
index 8b2174a..7e6ff96 100644
--- a/lib/engine/components/local-roster/local-roster-main.cpp
+++ b/lib/engine/components/local-roster/local-roster-main.cpp
@@ -54,10 +54,12 @@ struct LOCALROSTERSpark: public Ekiga::Spark
if (presence_core && iff) {
- boost::shared_ptr<Local::Cluster> cluster (new Local::Cluster (core));
+ boost::shared_ptr<Local::Cluster> cluster (new Local::Cluster (presence_core));
+ boost::shared_ptr<Local::Heap> heap(new Local::Heap (presence_core, cluster));
if (core.add (cluster)) {
- iff->add_helper (cluster->get_heap ());
+ iff->add_helper (heap);
+ cluster->set_heap (heap);
presence_core->add_cluster (cluster);
result = true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]