static void
main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
{
	GList *chatrooms, *l;
	GtkWidget *room;

	window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
	chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
	room = gtk_ui_manager_get_widget (window->ui_manager,
		"/menubar/room");
	window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
	window->room_separator = gtk_ui_manager_get_widget (window->ui_manager,
		"/menubar/room/room_separator");

	for (l = chatrooms; l; l = l->next) {
		main_window_favorite_chatroom_menu_add (window, l->data);
	}

	if (!chatrooms) {
		gtk_widget_hide (window->room_separator);
	}

	gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);

	g_signal_connect (window->chatroom_manager, "chatroom-added",
			  G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
			  window);
	g_signal_connect (window->chatroom_manager, "chatroom-removed",
			  G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
			  window);

	g_list_free (chatrooms);
}
Exemple #2
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);
}
Exemple #3
0
static void
chatrooms_window_model_refresh_data (EmpathyChatroomsWindow *window,
				     gboolean               first_time)
{
	GtkTreeView           *view;
	GtkTreeSelection      *selection;
	GtkTreeModel          *model;
	GtkListStore          *store;
	GtkTreeIter            iter;
	GtkTreeViewColumn     *column;
	EmpathyAccountChooser  *account_chooser;
	EmpathyAccount        *account;
	GList                 *chatrooms, *l;

	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);

	/* Look up chatrooms */
	account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser);
	account = empathy_account_chooser_dup_account (account_chooser);

	chatrooms = empathy_chatroom_manager_get_chatrooms (window->manager, account);

	/* Sort out columns, we only show the server column for
	 * selected protocol types, such as Jabber.
	 */
	if (account) {
		column = gtk_tree_view_get_column (view, window->room_column);
		gtk_tree_view_column_set_visible (column, TRUE);
	} else {
		column = gtk_tree_view_get_column (view, window->room_column);
		gtk_tree_view_column_set_visible (column, FALSE);
	}

	/* Clean out the store */
	gtk_list_store_clear (store);

	/* Populate with chatroom list. */
	for (l = chatrooms; l; l = l->next) {
		chatrooms_window_model_add (window, l->data,  FALSE);
	}

	if (gtk_tree_model_get_iter_first (model, &iter)) {
		gtk_tree_selection_select_iter (selection, &iter);
	}

	if (account) {
		g_object_unref (account);
	}

	g_list_free (chatrooms);
}
GtkWidget *
empathy_contact_invite_menu_item_new (EmpathyContact *contact)
{
	GtkWidget *item;
	GtkWidget *image;
	GtkWidget *room_item;
	EmpathyChatroomManager *mgr;
	GList *rooms, *l;
	GtkWidget *submenu = NULL;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
	image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
					      GTK_ICON_SIZE_MENU);
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);

	if (empathy_contact_is_user (contact)) {
		gtk_widget_set_sensitive (item, FALSE);
		gtk_widget_show (image);
		return item;
	}

	mgr = empathy_chatroom_manager_dup_singleton (NULL);
	rooms = empathy_chatroom_manager_get_chatrooms (mgr,
		empathy_contact_get_account (contact));

	for (l = rooms; l != NULL; l = g_list_next (l)) {
		EmpathyChatroom *chatroom = l->data;

		if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
			if (G_UNLIKELY (submenu == NULL))
				submenu = gtk_menu_new ();

			room_item = create_room_sub_menu (contact, chatroom);
			gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
			gtk_widget_show (room_item);
		}
	}

	if (submenu) {
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
	} else {
		gtk_widget_set_sensitive (item, FALSE);
	}

	gtk_widget_show (image);

	g_object_unref (mgr);
	g_list_free (rooms);

	return item;
}
static void
main_window_room_join_favorites_cb (GtkAction         *action,
				    EmpathyMainWindow *window)
{
	GList *chatrooms, *l;

	chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
	for (l = chatrooms; l; l = l->next) {
		main_window_favorite_chatroom_join (l->data);
	}
	g_list_free (chatrooms);
}
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
main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
					       EmpathyChatroom        *chatroom,
					       EmpathyMainWindow     *window)
{
	GtkWidget *menu_item;
	GList *chatrooms;

	menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
	g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
	gtk_widget_destroy (menu_item);

	chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
	if (chatrooms) {
		gtk_widget_show (window->room_separator);
	} else {
		gtk_widget_hide (window->room_separator);
	}

	gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
	g_list_free (chatrooms);
}