예제 #1
0
static void
new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
				 EmpathyChatroom          *chatroom,
				 EmpathyNewChatroomDialog *dialog)
{
	GtkTreeView      *view;
	GtkTreeSelection *selection;
	GtkListStore     *store;
	GtkTreeIter       iter;

	DEBUG ("New chatroom listed: %s (%s)",
		empathy_chatroom_get_name (chatroom),
		empathy_chatroom_get_room (chatroom));

	/* Add to model */
	view = GTK_TREE_VIEW (dialog->treeview);
	selection = gtk_tree_view_get_selection (view);
	store = GTK_LIST_STORE (dialog->model);

	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
			    COL_NAME, empathy_chatroom_get_name (chatroom),
			    COL_ROOM, empathy_chatroom_get_room (chatroom),
			    -1);
}
static void
new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist        *room_list,
				 EmpathyChatroom          *chatroom,
				 EmpathyNewChatroomDialog *dialog)
{
	GtkTreeView      *view;
	GtkTreeSelection *selection;
	GtkListStore     *store;
	GtkTreeIter       iter;
	gchar            *members;
	gchar            *tooltip;
	const gchar      *need_password;
	const gchar      *invite_only;

	DEBUG ("New chatroom listed: %s (%s)",
		empathy_chatroom_get_name (chatroom),
		empathy_chatroom_get_room (chatroom));

	/* Add to model */
	view = GTK_TREE_VIEW (dialog->treeview);
	selection = gtk_tree_view_get_selection (view);
	store = GTK_LIST_STORE (dialog->model);
	members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
	/* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
	yes/no, yes/no and a number. */
	tooltip = g_strdup_printf (_("<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
		empathy_chatroom_get_name (chatroom),
		empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
		empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
		members);
	invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
		GTK_STOCK_INDEX : NULL);
	need_password = (empathy_chatroom_get_need_password (chatroom) ?
		GTK_STOCK_DIALOG_AUTHENTICATION : NULL);

	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
			    COL_NEED_PASSWORD, need_password,
			    COL_INVITE_ONLY, invite_only,
			    COL_NAME, empathy_chatroom_get_name (chatroom),
			    COL_ROOM, empathy_chatroom_get_room (chatroom),
			    COL_MEMBERS, members,
			    COL_MEMBERS_INT, empathy_chatroom_get_members_count (chatroom),
			    COL_TOOLTIP, tooltip,
			    -1);

	g_free (members);
	g_free (tooltip);
}
예제 #3
0
static void
chatrooms_window_model_add (EmpathyChatroomsWindow *window,
                            EmpathyChatroom        *chatroom,
                            gboolean               set_active)
{
    GtkTreeView      *view;
    GtkTreeModel     *model;
    GtkTreeSelection *selection;
    GtkListStore     *store;
    GtkTreeIter       iter;

    view = GTK_TREE_VIEW (window->treeview);
    selection = gtk_tree_view_get_selection (view);
    model = gtk_tree_view_get_model (view);
    store = GTK_LIST_STORE (model);

    gtk_list_store_append (store, &iter);
    gtk_list_store_set (store, &iter,
                        COL_NAME, empathy_chatroom_get_name (chatroom),
                        COL_ROOM, empathy_chatroom_get_room (chatroom),
                        COL_AUTO_CONNECT, empathy_chatroom_get_auto_connect (chatroom),
                        COL_POINTER, chatroom,
                        -1);

    if (set_active) {
        gtk_tree_selection_select_iter (selection, &iter);
    }
}
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;
}
예제 #5
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;
}
예제 #7
0
static void
account_manager_chatroom_ready_cb (GObject *source_object,
    GAsyncResult *result,
    gpointer user_data)
{
  TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
  EmpathyChatroomManager *chatroom_manager = user_data;
  GList *accounts, *l;
  GError *error = NULL;

  if (!tp_account_manager_prepare_finish (account_manager, result, &error))
    {
      DEBUG ("Failed to prepare account manager: %s", error->message);
      g_error_free (error);
      return;
    }

  accounts = tp_account_manager_get_valid_accounts (account_manager);

  for (l = accounts; l != NULL; l = g_list_next (l))
    {
      TpAccount *account = TP_ACCOUNT (l->data);
      TpConnection *conn;
      GList *chatrooms, *p;

      conn = tp_account_get_connection (account);

      chatrooms = empathy_chatroom_manager_get_chatrooms (
          chatroom_manager, account);

      for (p = chatrooms; p != NULL; p = p->next)
        {
          EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);

          if (!empathy_chatroom_get_auto_connect (room))
            continue;

          if (conn == NULL)
            {
              g_signal_connect (G_OBJECT (account), "status-changed",
                  G_CALLBACK (account_status_changed_cb), room);
            }
          else
            {
              empathy_dispatcher_join_muc (conn,
                  empathy_chatroom_get_room (room), NULL, NULL);
            }
        }

      g_list_free (chatrooms);
    }

  g_list_free (accounts);
}
예제 #8
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);
}
static void
check_chatrooms_list (EmpathyChatroomManager *mgr,
                      EmpathyAccount *account,
                      struct chatroom_t *_chatrooms,
                      guint nb_chatrooms)
{
  GList *chatrooms, *l;
  guint i;
  GHashTable *found;

  fail_if (empathy_chatroom_manager_get_count (mgr, account) != nb_chatrooms);

  found = g_hash_table_new (g_str_hash, g_str_equal);
  for (i = 0; i < nb_chatrooms; i++)
    {
      g_hash_table_insert (found, _chatrooms[i].room, &_chatrooms[i]);
    }

  chatrooms = empathy_chatroom_manager_get_chatrooms (mgr, account);
  fail_if (g_list_length (chatrooms) != nb_chatrooms);

  for (l = chatrooms; l != NULL; l = g_list_next (l))
    {
      EmpathyChatroom *chatroom = l->data;
      struct chatroom_t *tmp;

      tmp = g_hash_table_lookup (found, empathy_chatroom_get_room (chatroom));
      fail_if (tmp == NULL);

      check_chatroom (chatroom, tmp->name, tmp->room, tmp->auto_connect,
          tmp->favorite);

      g_hash_table_remove (found, empathy_chatroom_get_room (chatroom));
    }

  fail_if (g_hash_table_size (found) != 0);

  g_list_free (chatrooms);
  g_hash_table_destroy (found);
}
static void
check_chatroom (EmpathyChatroom *chatroom,
                const gchar *name,
                const gchar *room,
                gboolean auto_connect,
                gboolean favorite)
{
  gboolean _favorite;

  fail_if (tp_strdiff (empathy_chatroom_get_name (chatroom), name));
  fail_if (tp_strdiff (empathy_chatroom_get_room (chatroom), room));
  fail_if (empathy_chatroom_get_auto_connect (chatroom) != auto_connect);
  g_object_get (chatroom, "favorite", &_favorite, NULL);
  fail_if (favorite != _favorite);
}
예제 #11
0
static void
account_status_changed_cb (TpAccount *account,
    guint old_status,
    guint new_status,
    guint reason,
    gchar *dbus_error_name,
    GHashTable *details,
    EmpathyChatroom *room)
{
  TpConnection *conn;

  conn = tp_account_get_connection (account);

  empathy_dispatcher_join_muc (conn,
      empathy_chatroom_get_room (room), NULL, NULL);
}
예제 #12
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);
	}
}