Example #1
0
gboolean
empathy_chatroom_manager_add (EmpathyChatroomManager *manager,
			     EmpathyChatroom        *chatroom)
{
  EmpathyChatroomManagerPriv *priv;

  g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), FALSE);
  g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), FALSE);

  priv = GET_PRIV (manager);

  /* don't add more than once */
  if (!empathy_chatroom_manager_find (manager,
      empathy_chatroom_get_account (chatroom),
      empathy_chatroom_get_room (chatroom)))
    {
      add_chatroom (manager, chatroom);

      if (empathy_chatroom_is_favorite (chatroom))
        reset_save_timeout (manager);

      g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);
      return TRUE;
    }

  return FALSE;
}
static void
chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
    xmlNodePtr node)
{
  EmpathyChatroom *chatroom = NULL;
  TpAccount *account;
  xmlNodePtr child;
  gchar *str;
  gchar *name;
  gchar *room;
  gchar *account_id;
  gboolean auto_connect;
  gboolean always_urgent;
  EmpathyClientFactory *factory;
  GError *error = NULL;

  /* default values. */
  name = NULL;
  room = NULL;
  auto_connect = TRUE;
  always_urgent = FALSE;
  account_id = NULL;

  for (child = node->children; child; child = child->next)
    {
      gchar *tag;

      if (xmlNodeIsText (child))
        continue;

      tag = (gchar *) child->name;
      str = (gchar *) xmlNodeGetContent (child);

      if (strcmp (tag, "name") == 0)
        {
          name = g_strdup (str);
        }
      else if (strcmp (tag, "room") == 0)
        {
          room = g_strdup (str);
        }
      else if (strcmp (tag, "auto_connect") == 0)
        {
          if (strcmp (str, "yes") == 0)
            auto_connect = TRUE;
          else
            auto_connect = FALSE;
        }
      else if (!tp_strdiff (tag, "always_urgent"))
        {
          if (strcmp (str, "yes") == 0)
            always_urgent = TRUE;
          else
            always_urgent = FALSE;
        }
      else if (strcmp (tag, "account") == 0)
        {
          account_id = g_strdup (str);
        }

      xmlFree (str);
    }

  /* account has to be a valid Account object path */
  if (!tp_dbus_check_valid_object_path (account_id, NULL) ||
      !g_str_has_prefix (account_id, TP_ACCOUNT_OBJECT_PATH_BASE))
    goto out;

  factory = empathy_client_factory_dup ();

  account = tp_simple_client_factory_ensure_account (
          TP_SIMPLE_CLIENT_FACTORY (factory), account_id, NULL, &error);
  g_object_unref (factory);

  if (account == NULL)
    {
      DEBUG ("Failed to create account: %s", error->message);
      g_error_free (error);

      g_free (name);
      g_free (room);
      g_free (account_id);
      return;
    }

  chatroom = empathy_chatroom_new_full (account, room, name, auto_connect);
  empathy_chatroom_set_favorite (chatroom, TRUE);
  empathy_chatroom_set_always_urgent (chatroom, always_urgent);
  add_chatroom (manager, chatroom);
  g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);

out:
  g_free (name);
  g_free (room);
  g_free (account_id);
  tp_clear_object (&chatroom);
}
Example #3
0
static void
chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
				 xmlNodePtr             node)
{
	EmpathyChatroomManagerPriv *priv;
	EmpathyChatroom            *chatroom;
	EmpathyAccount             *account;
	xmlNodePtr                 child;
	gchar                     *str;
	gchar                     *name;
	gchar                     *room;
	gchar                     *account_id;
	gboolean                   auto_connect;

	priv = GET_PRIV (manager);

	/* default values. */
	name = NULL;
	room = NULL;
	auto_connect = TRUE;
	account_id = NULL;

	for (child = node->children; child; child = child->next) {
		gchar *tag;

		if (xmlNodeIsText (child)) {
			continue;
		}

		tag = (gchar *) child->name;
		str = (gchar *) xmlNodeGetContent (child);

		if (strcmp (tag, "name") == 0) {
			name = g_strdup (str);
		}
		else if (strcmp (tag, "room") == 0) {
			room = g_strdup (str);
		}
		else if (strcmp (tag, "auto_connect") == 0) {
			if (strcmp (str, "yes") == 0) {
				auto_connect = TRUE;
			} else {
				auto_connect = FALSE;
			}
		}
		else if (strcmp (tag, "account") == 0) {
			account_id = g_strdup (str);
		}

		xmlFree (str);
	}

	account = empathy_account_manager_get_account (priv->account_manager,
		account_id);
	if (!account) {
		g_free (name);
		g_free (room);
		g_free (account_id);
		return;
	}

	chatroom = empathy_chatroom_new_full (account, room, name, auto_connect);
	empathy_chatroom_set_favorite (chatroom, TRUE);
	add_chatroom (manager, chatroom);
	g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);

	g_free (name);
	g_free (room);
	g_free (account_id);
}