Exemplo n.º 1
0
void
Local::Heap::new_presentity_form_submitted (bool submitted,
					    Ekiga::Form &result)
{
  if (!submitted)
    return;

  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;
  const std::set<std::string> groups = result.editable_set ("groups");

  if (good_uri == "yes")
    uri = result.hidden ("uri");
  else
    uri = result.text ("uri");

  uri = canonize_uri (uri);

  if (pcore->is_supported_uri (uri)
      && !has_presentity_with_uri (uri)) {

    add (name, uri, groups);
    save ();
  } else {

    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 (!pcore->is_supported_uri (uri))
      request->error (_("You supplied an unsupported address"));
    else
      request->error (_("You already have a contact with this address!"));

    questions (request);
  }
}
Exemplo n.º 2
0
void
Local::Presentity::edit_presentity_form_submitted (bool submitted,
						   Ekiga::Form &result)
{
  if (!submitted)
    return;

  const std::string new_name = result.text ("name");
  const std::set<std::string> groups = get_groups ();
  const std::set<std::string> new_groups = result.editable_set ("groups");
  std::string new_uri = result.text ("uri");
  const std::string uri = get_uri ();
  bool preferred = result.boolean ("preferred");
  std::set<xmlNodePtr> nodes_to_remove;

  new_uri = canonize_uri (new_uri);

  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL) {

      if (xmlStrEqual (BAD_CAST ("name"), child->name)) {

	robust_xmlNodeSetContent (node, &child, "name", new_name);
      }
    }
  }

  if (uri != new_uri) {

    boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
    if (pcore) {
      pcore->unfetch_presence (uri);
      pcore->fetch_presence (new_uri);
    }
    presence = "unknown";
    xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ());
  }

  // the first loop looks at groups we were in : are we still in ?
  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL) {

      if (xmlStrEqual (BAD_CAST ("group"), child->name)) {

	xmlChar* xml_str = xmlNodeGetContent (child);

	if (xml_str != NULL) {

	  if (new_groups.find ((const char*) xml_str) == new_groups.end ()) {

	    nodes_to_remove.insert (child); // don't free what we loop on!
	  }
	  xmlFree (xml_str);
	}
      }
    }
  }

  // ok, now we can clean up!
  for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin ();
       iter != nodes_to_remove.end ();
       ++iter) {

    xmlUnlinkNode (*iter);
    xmlFreeNode (*iter);
  }

  // the second loop looking for groups we weren't in but are now
  for (std::set<std::string>::const_iterator iter = new_groups.begin ();
       iter != new_groups.end ();
       iter++) {

    if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) {
      xmlNewChild (node, NULL,
		   BAD_CAST "group",
		   BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ());
    }
  }

  if (preferred) {

    xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "true");
  } else {

    xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "false");
  }

  updated ();
  trigger_saving ();
}
Exemplo n.º 3
0
bool
Opal::Presentity::edit_presentity_form_submitted (bool submitted,
                                                  Ekiga::Form &result,
                                                  std::string &error)
{
  if (!submitted)
    return false;

  const std::string new_name = result.text ("name");
  const std::list<std::string> groups = get_groups ();
  const std::list<std::string> new_groups = result.editable_list ("groups");
  std::string new_uri = result.text ("uri");
  const std::string uri = get_uri ();
  std::set<xmlNodePtr> nodes_to_remove;

  if (new_name.empty ()) {
    error = _("You did not provide a valid name");
    return false;
  }
  else if (new_uri.empty ()) {
    error = _("You did not provide a valid address");
    return false;
  }

  new_uri = canonize_uri (new_uri);

  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL)
      if (xmlStrEqual (BAD_CAST ("name"), child->name))
        robust_xmlNodeSetContent (node, &child, "name", new_name);
  }

  if (uri != new_uri) {
    xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ());
    account.unfetch (uri);
    account.fetch (new_uri);
    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, &account, new_uri, "unknown", ""));
  }

  // the first loop looks at groups we were in: are we still in?
  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL) {

      if (xmlStrEqual (BAD_CAST ("group"), child->name)) {

        xmlChar* xml_str = xmlNodeGetContent (child);

        if (xml_str != NULL) {
          if (std::find (new_groups.begin (), new_groups.end (), (const char*) xml_str) == new_groups.end ())
            nodes_to_remove.insert (child); // don't free what we loop on!
          xmlFree (xml_str);
        }
      }
    }
  }

  // ok, now we can clean up!
  for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin ();
       iter != nodes_to_remove.end ();
       ++iter) {

    xmlUnlinkNode (*iter);
    xmlFreeNode (*iter);
  }

  // the second loop looks for groups we weren't in but are now
  for (std::list<std::string>::const_iterator iter = new_groups.begin ();
       iter != new_groups.end ();
       iter++) {

    if (std::find (groups.begin (), groups.end (), *iter) == groups.end ())
      xmlNewChild (node, NULL,
                   BAD_CAST "group",
                   BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ());
  }

  updated (this->shared_from_this ());
  trigger_saving ();

  return true;
}