Exemple #1
0
void torrent_view::render()
{
	print_tabs();
	print_headers();

	int lines_printed = header_size;

	int torrent_index = 0;

	for (std::vector<lt::torrent_status const*>::iterator i = m_filtered_handles.begin();
		i != m_filtered_handles.end(); ++torrent_index)
	{
		if (torrent_index < m_scroll_position)
		{
			++i;
			continue;
		}
		if (lines_printed >= m_height)
			break;

		lt::torrent_status const& s = **i;
		if (!s.handle.is_valid())
		{
			i = m_filtered_handles.erase(i);
			continue;
		}
		++i;

		set_cursor_pos(0, torrent_index + header_size - m_scroll_position);
		print_torrent(s, torrent_index == m_active_torrent);
		++lines_printed;
	}

	clear_rows(torrent_index + header_size, m_height);
}
Exemple #2
0
static void list_torrents()
{
    int64_t total_size = 0, total_up = 0, total_down = 0;
    char sizestr[20], upstr[20], downstr[20];
    torrent_array *tarray = NULL;

    get_torrent_list(&tarray);
    if (tarray == NULL)
        return;

    printf ("%-4s   %-4s  %8s  %-8s  %8s  %8s %9s  %-11s  %s\n", 
            "ID", "Done", "Have", "ETA", "Up", "Down", "Ratio", "Status", "Name");
    for (size_t i = 0; i < tarray->size; ++i) {
        print_torrent(tarray->torrents[i]);
        total_size += tarray->torrents[i]->done_bytes;
        total_up += tarray->torrents[i]->up_rate;
        total_down += tarray->torrents[i]->down_rate;
    }

    byte_to_string(sizestr, 20, total_size);
    byte_to_string(upstr, 20, total_up);
    byte_to_string(downstr, 20, total_down);
    printf ("Sum:        %9s            %8s  %8s\n",
            sizestr, upstr, downstr);

    torrent_array_free(tarray);
}
Exemple #3
0
void torrent_view::arrow_up()
{
	if (m_filtered_handles.empty()) return;
	if (m_active_torrent <= 0) return;

	if (m_active_torrent - 1 < m_scroll_position)
	{
		--m_active_torrent;
		m_scroll_position = m_active_torrent;
		TORRENT_ASSERT(m_scroll_position >= 0);
		render();
		return;
	}

	set_cursor_pos(0, header_size + m_active_torrent - m_scroll_position);
	print_torrent(*m_filtered_handles[m_active_torrent], false);
	--m_active_torrent;
	TORRENT_ASSERT(m_active_torrent >= 0);

	set_cursor_pos(0, header_size + m_active_torrent - m_scroll_position);
	print_torrent(*m_filtered_handles[m_active_torrent], true);
}
Exemple #4
0
void torrent_view::arrow_down()
{
	if (m_filtered_handles.empty()) return;
	if (m_active_torrent >= int(m_filtered_handles.size()) - 1) return;

	int bottom_pos = m_height - header_size - 1;
	if (m_active_torrent - m_scroll_position + 1 > bottom_pos)
	{
		++m_active_torrent;
		m_scroll_position = m_active_torrent - bottom_pos;
		TORRENT_ASSERT(m_scroll_position >= 0);
		render();
		return;
	}

	set_cursor_pos(0, header_size + m_active_torrent - m_scroll_position);
	print_torrent(*m_filtered_handles[m_active_torrent], false);

	TORRENT_ASSERT(m_active_torrent >= 0);
	++m_active_torrent;

	set_cursor_pos(0, header_size + m_active_torrent - m_scroll_position);
	print_torrent(*m_filtered_handles[m_active_torrent], true);
}
Exemple #5
0
void torrent_view::update_torrents(std::vector<lt::torrent_status> const& st)
{
	std::set<lt::torrent_handle> updates;
	bool need_filter_update = false;
	for (std::vector<lt::torrent_status>::const_iterator i = st.begin();
		i != st.end(); ++i)
	{
		boost::unordered_set<lt::torrent_status>::iterator j = m_all_handles.find(*i);
		// add new entries here
		if (j == m_all_handles.end())
		{
			j = m_all_handles.insert(*i).first;
			if (show_torrent(*j))
			{
				m_filtered_handles.push_back(&*j);
				need_filter_update = true;
			}
		}
		else
		{
			bool prev_show = show_torrent(*j);
			((lt::torrent_status&)*j) = *i;
			if (prev_show != show_torrent(*j))
				need_filter_update = true;
			else
				updates.insert(i->handle);
		}
	}
	if (need_filter_update)
	{
		update_filtered_torrents();
		render();
	}
	else
	{
		int torrent_index = 0;
		for (std::vector<lt::torrent_status const*>::iterator i
			= m_filtered_handles.begin();
			i != m_filtered_handles.end(); ++torrent_index)
		{
			if (torrent_index < m_scroll_position
				|| torrent_index >= m_scroll_position + m_height - header_size)
			{
				++i;
				continue;
			}

			lt::torrent_status const& s = **i;
			++i;

			if (!s.handle.is_valid())
				continue;

			if (updates.count(s.handle) == 0)
				continue;

			set_cursor_pos(0, header_size + torrent_index - m_scroll_position);
			print_torrent(s, torrent_index == m_active_torrent);
		}
	}
}