1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
|
/* Ekiga -- A VoIP and Video-Conferencing application
* Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* Ekiga is licensed under the GPL license and as a special exception,
* you have permission to link or otherwise combine this program with the
* programs OPAL, OpenH323 and PWLIB, and distribute the combination,
* without applying the requirements of the GNU GPL to the OPAL, OpenH323
* and PWLIB programs, as long as you do follow the requirements of the
* GNU GPL for all the rest of the software thus combined.
*/
/*
* rl-list.cpp - description
* ------------------------------------------
* begin : written in 2008 by Julien Puydt
* copyright : (c) 2008 by Julien Puydt
* description : resource-list list class
*
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "rl-list.h"
class RL::ListImpl
{
public: // no need to make anything private
ListImpl (Ekiga::ServiceCore& core_,
boost::shared_ptr<XCAP::Path> path_,
int pos,
const std::string group_,
xmlNodePtr node_);
~ListImpl ();
bool has_name (const std::string name) const;
void push_presence (const std::string uri_,
const std::string presence);
void push_status (const std::string uri_,
const std::string status);
std::string compute_path () const;
void flush ();
void refresh ();
void on_xcap_answer (bool error,
std::string value);
void parse ();
/* data for itself */
Ekiga::ServiceCore& core;
boost::shared_ptr<XCAP::Path> path;
int position;
std::string group;
boost::shared_ptr<xmlDoc> doc;
xmlNodePtr node;
xmlNodePtr name_node;
std::string position_name;
std::string display_name;
/* make the world know what we have */
bool visit_presentities (boost::function1<bool, Ekiga::Presentity&> visitor) const;
void publish () const;
boost::signal1<void, boost::shared_ptr<Entry> > entry_added;
boost::signal1<void, boost::shared_ptr<Entry> > entry_updated;
boost::signal1<void, boost::shared_ptr<Entry> > entry_removed;
/* data for its children */
typedef enum { LIST, ENTRY } ChildType;
std::list<ChildType> ordering;
std::list<boost::shared_ptr<List> > lists;
std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > > entries;
};
/* implementation of the List class */
RL::List::List (Ekiga::ServiceCore& core_,
boost::shared_ptr<XCAP::Path> path_,
int pos,
const std::string group_,
xmlNodePtr node_)
{
impl = new ListImpl (core_, path_, pos, group_, node_);
impl->entry_added.connect (entry_added);
impl->entry_updated.connect (entry_updated);
impl->entry_removed.connect (entry_removed);
}
RL::List::~List ()
{
delete impl;
}
void
RL::List::flush ()
{
return impl->flush ();
}
bool
RL::List::has_name (const std::string name) const
{
return impl->has_name (name);
}
void
RL::List::push_presence (const std::string uri_,
const std::string presence)
{
impl->push_presence (uri_, presence);
}
void
RL::List::push_status (const std::string uri_,
const std::string status)
{
impl->push_status (uri_, status);
}
bool
RL::List::visit_presentities (boost::function1<bool, Ekiga::Presentity&> visitor) const
{
return impl->visit_presentities (visitor);
}
void
RL::List::publish () const
{
impl->publish ();
}
/* implementation of the ListImpl class */
RL::ListImpl::ListImpl (Ekiga::ServiceCore& core_,
boost::shared_ptr<XCAP::Path> path_,
int pos,
const std::string group_,
xmlNodePtr node_):
core(core_), position(pos), group(group_), doc(), node(node_)
{
{
gchar* raw = NULL;
if ( !group_.empty ()) {
/* Translators: #%d - ordinal number */
raw = g_strdup_printf (_("%s / List #%d"),
group_.c_str (), position);
} else {
/* Translators: #%d - ordinal number */
raw = g_strdup_printf (_("List #%d"), position);
}
position_name = raw;
g_free (raw);
}
display_name = position_name; // will be set to better when we get the data
if (node != NULL) {
xmlChar* str = xmlGetProp (node, BAD_CAST "name");
if (str != NULL) {
path = path_->build_child_with_attribute ("list", "name",
(const char*)str);
xmlFree (str);
} else {
path = path_->build_child_with_position ("list", position);
}
parse ();
} else {
path = path_;
refresh ();
}
}
RL::ListImpl::~ListImpl ()
{
}
bool
RL::ListImpl::has_name (const std::string name) const
{
return (name == position_name) || (name == display_name);
}
void
RL::ListImpl::flush ()
{
ordering.clear ();
for (std::list<boost::shared_ptr<List> >::iterator iter = lists.begin ();
iter != lists.end ();
++iter)
(*iter)->flush ();
lists.clear ();
for (std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > >::iterator iter = entries.begin ();
iter != entries.end ();
++iter) {
iter->first->removed ();
for (std::list<boost::signals::connection>::iterator conn_iter
= iter->second.begin ();
conn_iter != iter->second.end ();
++conn_iter)
conn_iter->disconnect ();
}
entries.clear ();
doc.reset ();
node = NULL;
name_node = NULL;
}
void
RL::ListImpl::refresh ()
{
flush ();
boost::shared_ptr<XCAP::Core> xcap = core.get<XCAP::Core> ("xcap-core");
xcap->read (path, boost::bind (&RL::ListImpl::on_xcap_answer, this, _1, _2));
}
void
RL::ListImpl::on_xcap_answer (bool error,
std::string value)
{
if (error) {
// FIXME: how to properly tell the user?
} else {
doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (value.c_str (), value.length ()), xmlFreeDoc);
if ( !doc)
doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
node = xmlDocGetRootElement (doc.get ());
if (node == NULL
|| node->name == NULL
|| !xmlStrEqual (BAD_CAST "list", node->name)) {
// FIXME : how to properly tell the user?
} else {
parse ();
}
}
}
void
RL::ListImpl::parse ()
{
int list_pos = 1;
int entry_pos = 1;
for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
if (child->type == XML_ELEMENT_NODE
&& child->name != NULL
&& xmlStrEqual (BAD_CAST "display-name", child->name)) {
xmlChar* str = xmlNodeGetContent (child);
name_node = child;
if (str != NULL) {
if ( !group.empty ())
display_name = group + " / " + (const char*) str;
else
display_name = (const char*) str;
xmlFree (str);
}
break;
}
}
for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
if (child->type == XML_ELEMENT_NODE
&& child->name != NULL
&& xmlStrEqual (BAD_CAST "list", child->name)) {
boost::shared_ptr<List> list = boost::shared_ptr<List> (new List (core, path,
list_pos, display_name,
child));
list->entry_added.connect (entry_added);
list->entry_updated.connect (entry_updated);
list->entry_removed.connect (entry_removed);
lists.push_back (list);
ordering.push_back (LIST);
list_pos++;
list->publish ();
continue;
}
if (child->type == XML_ELEMENT_NODE
&& child->name != NULL
&& xmlStrEqual (BAD_CAST "entry", child->name)) {
boost::shared_ptr<Entry> entry = boost::shared_ptr<Entry> (new Entry (core, path,
entry_pos,
display_name,
doc, child));
std::list<boost::signals::connection> conns;
conns.push_back (entry->updated.connect (boost::bind (boost::ref (entry_updated), entry)));
conns.push_back (entry->removed.connect (boost::bind (boost::ref (entry_removed), entry)));
entries.push_back (std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > (entry, conns));
ordering.push_back (ENTRY);
entry_pos++;
entry_added (entry);
continue;
}
}
}
void
RL::ListImpl::push_presence (const std::string uri_,
const std::string presence)
{
for (std::list<boost::shared_ptr<List> >::const_iterator iter = lists.begin ();
iter != lists.end ();
++iter)
(*iter)->push_presence (uri_, presence);
for (std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > >::const_iterator iter = entries.begin ();
iter != entries.end ();
++iter) {
if (iter->first->get_uri () == uri_)
iter->first->set_presence (presence);
}
}
void
RL::ListImpl::push_status (const std::string uri_,
const std::string status)
{
for (std::list<boost::shared_ptr<List> >::const_iterator iter = lists.begin ();
iter != lists.end ();
++iter)
(*iter)->push_status (uri_, status);
for (std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > >::const_iterator iter = entries.begin ();
iter != entries.end ();
++iter) {
if (iter->first->get_uri () == uri_)
iter->first->set_status (status);
}
}
bool
RL::ListImpl::visit_presentities (boost::function1<bool, Ekiga::Presentity&> visitor) const
{
bool go_on = true;
for (std::list<boost::shared_ptr<List> >::const_iterator iter = lists.begin ();
go_on && iter != lists.end ();
++iter)
go_on = (*iter)->visit_presentities (visitor);
for (std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > >::const_iterator iter = entries.begin ();
go_on && iter != entries.end ();
++iter) {
go_on = visitor (*(iter->first));
}
return go_on;
}
void
RL::ListImpl::publish () const
{
for (std::list<boost::shared_ptr<List> >::const_iterator iter = lists.begin ();
iter != lists.end ();
++iter)
(*iter)->publish ();
for (std::list<std::pair<boost::shared_ptr<Entry>, std::list<boost::signals::connection> > >::const_iterator iter = entries.begin ();
iter != entries.end ();
++iter) {
entry_added (iter->first);
}
}
|