GList *
empathy_chatroom_manager_get_chatrooms (EmpathyChatroomManager *manager,
    TpAccount *account)
{
  EmpathyChatroomManagerPriv *priv;
  GList *chatrooms, *l;

  g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), NULL);

  priv = GET_PRIV (manager);

  if (!account)
    return g_list_copy (priv->chatrooms);

  chatrooms = NULL;
  for (l = priv->chatrooms; l; l = l->next)
    {
      EmpathyChatroom *chatroom;

      chatroom = l->data;

      if (account == empathy_chatroom_get_account (chatroom))
        chatrooms = g_list_append (chatrooms, chatroom);
    }

  return chatrooms;
}
EmpathyChatroom *
empathy_chatroom_manager_find (EmpathyChatroomManager *manager,
    TpAccount *account,
    const gchar *room)
{
  EmpathyChatroomManagerPriv *priv;
  GList *l;

  g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), NULL);
  g_return_val_if_fail (room != NULL, NULL);

  priv = GET_PRIV (manager);

  for (l = priv->chatrooms; l; l = l->next)
    {
      EmpathyChatroom *chatroom;
      TpAccount *this_account;
      const gchar    *this_room;

      chatroom = l->data;
      this_account = empathy_chatroom_get_account (chatroom);
      this_room = empathy_chatroom_get_room (chatroom);

      if (this_account && this_room && account == this_account
          && strcmp (this_room, room) == 0)
        return chatroom;
    }

  return NULL;
}
예제 #3
0
guint
empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager,
				   EmpathyAccount *account)
{
	EmpathyChatroomManagerPriv *priv;
	GList                     *l;
	guint                      count = 0;

	g_return_val_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager), 0);

	priv = GET_PRIV (manager);

	if (!account) {
		return g_list_length (priv->chatrooms);
	}

	for (l = priv->chatrooms; l; l = l->next) {
		EmpathyChatroom *chatroom;

		chatroom = l->data;

		if (account == empathy_chatroom_get_account (chatroom)) {
			count++;
		}
	}

	return count;
}
예제 #4
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 gboolean
chatroom_manager_file_save (EmpathyChatroomManager *manager)
{
  EmpathyChatroomManagerPriv *priv;
  xmlDocPtr doc;
  xmlNodePtr root;
  GList *l;

  priv = GET_PRIV (manager);

  priv->writing = TRUE;

  doc = xmlNewDoc ((const xmlChar *) "1.0");
  root = xmlNewNode (NULL, (const xmlChar *) "chatrooms");
  xmlDocSetRootElement (doc, root);

  for (l = priv->chatrooms; l; l = l->next)
    {
      EmpathyChatroom *chatroom;
      xmlNodePtr       node;
      const gchar     *account_id;

      chatroom = l->data;

      if (!empathy_chatroom_is_favorite (chatroom))
        continue;

      account_id = tp_proxy_get_object_path (empathy_chatroom_get_account (
            chatroom));

      node = xmlNewChild (root, NULL, (const xmlChar *) "chatroom", NULL);
      xmlNewTextChild (node, NULL, (const xmlChar *) "name",
        (const xmlChar *) empathy_chatroom_get_name (chatroom));
      xmlNewTextChild (node, NULL, (const xmlChar *) "room",
        (const xmlChar *) empathy_chatroom_get_room (chatroom));
      xmlNewTextChild (node, NULL, (const xmlChar *) "account",
        (const xmlChar *) account_id);
      xmlNewTextChild (node, NULL, (const xmlChar *) "auto_connect",
        empathy_chatroom_get_auto_connect (chatroom) ?
        (const xmlChar *) "yes" : (const xmlChar *) "no");
      xmlNewTextChild (node, NULL, (const xmlChar *) "always_urgent",
        empathy_chatroom_is_always_urgent (chatroom) ?
        (const xmlChar *) "yes" : (const xmlChar *) "no");
    }

  /* Make sure the XML is indented properly */
  xmlIndentTreeOutput = 1;

  DEBUG ("Saving file:'%s'", priv->file);
  xmlSaveFormatFileEnc (priv->file, doc, "utf-8", 1);
  xmlFreeDoc (doc);

  xmlMemoryDump ();

  priv->writing = FALSE;
  return TRUE;
}
예제 #6
0
gboolean
empathy_chatroom_equal (gconstpointer v1,
		       gconstpointer v2)
{
	EmpathyAccount *account_a;
	EmpathyAccount *account_b;
	const gchar *room_a;
	const gchar *room_b;

	g_return_val_if_fail (EMPATHY_IS_CHATROOM (v1), FALSE);
	g_return_val_if_fail (EMPATHY_IS_CHATROOM (v2), FALSE);

	account_a = empathy_chatroom_get_account (EMPATHY_CHATROOM (v1));
	account_b = empathy_chatroom_get_account (EMPATHY_CHATROOM (v2));

	room_a = empathy_chatroom_get_room (EMPATHY_CHATROOM (v1));
	room_b = empathy_chatroom_get_room (EMPATHY_CHATROOM (v2));

	return account_a == account_b && !tp_strdiff (room_a, room_b);
}
예제 #7
0
static void
main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
{
	TpAccount      *account;
	TpConnection   *connection;
	const gchar    *room;

	account = empathy_chatroom_get_account (chatroom);
	connection = tp_account_get_connection (account);
	room = empathy_chatroom_get_room (chatroom);

	if (connection != NULL) {
		DEBUG ("Requesting channel for '%s'", room);
		empathy_dispatcher_join_muc (connection, room, NULL, NULL);
	}
}
예제 #8
0
static void
chatrooms_window_chatroom_added_cb (EmpathyChatroomManager *manager,
                                    EmpathyChatroom        *chatroom,
                                    EmpathyChatroomsWindow *window)
{
    EmpathyAccountChooser *account_chooser;
    TpAccount             *account;

    account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser);
    account = empathy_account_chooser_dup_account (account_chooser);

    if (!account) {
        chatrooms_window_model_add (window, chatroom, FALSE);
    } else {
        if (account == empathy_chatroom_get_account (chatroom)) {
            chatrooms_window_model_add (window, chatroom, FALSE);
        }

        g_object_unref (account);
    }
}