* Moved handling of events from DownloadList into ElementDownloadList

and WindowLog.

* Added bindings to input::TextInput and disabled other bindings while
it is active.

* ^K now sets ignore_commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@750 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-07-31 00:26:58 +00:00
parent fa5ff92e24
commit 62beb9d9ed
24 changed files with 272 additions and 261 deletions
+17 -190
View File
@@ -77,13 +77,6 @@ DownloadList::DownloadList() :
m_windowLog = new WLog(&control->core()->get_log_important());
receive_change_view("main");
if (m_view == NULL)
throw torrent::client_error("View \"main\" must be present to initialize the main display.");
m_taskUpdate.set_slot(rak::mem_fn(this, &DownloadList::task_update)),
setup_keys();
}
@@ -101,11 +94,9 @@ DownloadList::activate(display::Frame* frame) {
if (is_active())
throw torrent::client_error("ui::DownloadList::activate() called on an already activated object");
priority_queue_insert(&taskScheduler, &m_taskUpdate, cachedTime);
m_frame = frame;
control->input()->push_front(&m_bindings);
control->input()->push_back(&m_bindings);
control->core()->download_list()->slot_map_erase()["0_download_list"] = sigc::mem_fun(this, &DownloadList::receive_download_erased);
activate_display(DISPLAY_DOWNLOAD_LIST);
@@ -121,10 +112,14 @@ DownloadList::disable() {
m_frame = NULL;
priority_queue_erase(&taskScheduler, &m_taskUpdate);
control->input()->erase(&m_bindings);
}
core::View*
DownloadList::current_view() {
return dynamic_cast<ElementDownloadList*>(m_uiArray[DISPLAY_DOWNLOAD_LIST])->view();
}
void
DownloadList::activate_display(Display displayType) {
if (!is_active())
@@ -144,7 +139,6 @@ DownloadList::activate_display(Display displayType) {
delete m_uiArray[m_state];
m_uiArray[m_state] = NULL;
control->input()->push_front(&m_bindings);
break;
case DISPLAY_DOWNLOAD_LIST:
@@ -171,16 +165,14 @@ DownloadList::activate_display(Display displayType) {
switch (displayType) {
case DISPLAY_DOWNLOAD:
// If no download has the focus, just return to the download list.
if (m_view->focus() == m_view->end_visible()) {
if (current_view()->focus() == current_view()->end_visible()) {
m_state = DISPLAY_MAX_SIZE;
activate_display(DISPLAY_DOWNLOAD_LIST);
return;
} else {
control->input()->erase(&m_bindings);
Download* download = new Download(*m_view->focus());
Download* download = new Download(*current_view()->focus());
download->activate(m_frame);
download->bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST);
@@ -196,6 +188,7 @@ DownloadList::activate_display(Display displayType) {
m_frame->frame(1)->initialize_window(m_windowLog);
m_windowLog->set_active(true);
m_windowLog->receive_update();
break;
case DISPLAY_LOG:
@@ -217,108 +210,6 @@ DownloadList::activate_display(Display displayType) {
control->display()->adjust_layout();
}
void
DownloadList::receive_next() {
m_view->next_focus();
m_view->set_last_changed();
}
void
DownloadList::receive_prev() {
m_view->prev_focus();
m_view->set_last_changed();
}
void
DownloadList::receive_start_download() {
if (m_view->focus() == m_view->end_visible())
return;
control->core()->download_list()->start_normal(*m_view->focus());
m_view->set_last_changed();
}
void
DownloadList::receive_stop_download() {
if (m_view->focus() == m_view->end_visible())
return;
if ((*m_view->focus())->variable()->get_value("state") == 1)
control->core()->download_list()->stop_normal(*m_view->focus());
else
control->core()->download_list()->erase(*m_view->focus());
m_view->set_last_changed();
}
void
DownloadList::receive_close_download() {
if (m_view->focus() == m_view->end_visible())
return;
core::Download* download = *m_view->focus();
control->core()->download_list()->stop_normal(download);
control->core()->download_list()->close(download);
m_view->set_last_changed();
}
void
DownloadList::receive_next_priority() {
if (m_view->focus() == m_view->end_visible())
return;
(*m_view->focus())->set_priority(((*m_view->focus())->priority() + 1) % 4);
// (*m_window)->mark_dirty();
}
void
DownloadList::receive_prev_priority() {
if (m_view->focus() == m_view->end_visible())
return;
(*m_view->focus())->set_priority(((*m_view->focus())->priority() - 1) % 4);
// (*m_window)->mark_dirty();
}
void
DownloadList::receive_check_hash() {
if (m_view->focus() == m_view->end_visible())
return;
// Catch here?
control->core()->download_list()->check_hash(*m_view->focus());
}
void
DownloadList::receive_ignore_ratio() {
if (m_view->focus() == m_view->end_visible())
return;
if ((*m_view->focus())->variable()->get_value("ignore_commands") != 0) {
(*m_view->focus())->variable()->set("ignore_commands", (int64_t)0);
control->core()->push_log("Torrent set to heed commands.");
} else {
(*m_view->focus())->variable()->set("ignore_commands", (int64_t)1);
control->core()->push_log("Torrent set to ignore commands.");
}
}
void
DownloadList::receive_clear_tied() {
if (m_view->focus() == m_view->end_visible())
return;
const std::string& tiedFile = (*m_view->focus())->variable()->get_string("tied_to_file");
if (!tiedFile.empty()) {
// Move this into core?
control->core()->delete_tied(*m_view->focus());
control->core()->push_log("Cleared tied to file association for download.");
}
}
void
DownloadList::receive_view_input(Input type) {
if (control->ui()->current_input() != NULL)
@@ -365,7 +256,6 @@ DownloadList::receive_view_input(Input type) {
input->bindings()[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type);
input->bindings()['\x07'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), INPUT_NONE);
m_bindings.disable();
control->ui()->enable_input(title, input);
}
@@ -378,7 +268,6 @@ DownloadList::receive_exit_input(Input type) {
return;
control->ui()->disable_input();
m_bindings.enable();
try {
@@ -392,11 +281,11 @@ DownloadList::receive_exit_input(Input type) {
break;
case INPUT_CHANGE_DIRECTORY:
if (m_view->focus() == m_view->end_visible())
if (current_view()->focus() == current_view()->end_visible())
throw torrent::input_error("No download in focus to change root directory.");
(*m_view->focus())->variable()->set("directory", rak::trim(input->str()));
control->core()->push_log("New root directory \"" + (*m_view->focus())->variable()->get_string("directory") + "\" for torrent.");
(*current_view()->focus())->variable()->set("directory", rak::trim(input->str()));
control->core()->push_log("New root directory \"" + (*current_view()->focus())->variable()->get_string("directory") + "\" for torrent.");
break;
case INPUT_COMMAND:
@@ -418,51 +307,14 @@ DownloadList::receive_exit_input(Input type) {
void
DownloadList::receive_download_erased(core::Download* d) {
if (m_view->focus() == m_view->end_visible() || *m_view->focus() != d)
if (m_state != DISPLAY_DOWNLOAD || current_view()->focus() == current_view()->end_visible() || *current_view()->focus() != d)
return;
activate_display(DISPLAY_DOWNLOAD_LIST);
receive_next();
}
void
DownloadList::receive_change_view(const std::string& name) {
core::ViewManager::iterator itr = control->view_manager()->find(name);
if (itr == control->view_manager()->end()) {
control->core()->push_log("Could not find view \"" + name + "\".");
return;
}
m_view = *itr;
m_view->sort();
ElementDownloadList* ui = dynamic_cast<ElementDownloadList*>(m_uiArray[DISPLAY_DOWNLOAD_LIST]);
if (ui == NULL)
throw torrent::client_error("DownloadList::receive_change_view(...) could not cast ui.");
ui->set_view(m_view);
}
void
DownloadList::task_update() {
m_windowLog->receive_update();
priority_queue_insert(&taskScheduler, &m_taskUpdate, (cachedTime + rak::timer::from_seconds(1)).round_seconds());
}
void
DownloadList::setup_keys() {
m_bindings['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download);
m_bindings['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download);
m_bindings['\x0B'] = sigc::mem_fun(*this, &DownloadList::receive_close_download);
m_bindings['\x12'] = sigc::mem_fun(*this, &DownloadList::receive_check_hash);
m_bindings['+'] = sigc::mem_fun(*this, &DownloadList::receive_next_priority);
m_bindings['-'] = sigc::mem_fun(*this, &DownloadList::receive_prev_priority);
m_bindings['I'] = sigc::mem_fun(*this, &DownloadList::receive_ignore_ratio);
m_bindings['U'] = sigc::mem_fun(*this, &DownloadList::receive_clear_tied);
m_bindings['\x7f'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_DEFAULT);
m_bindings[KEY_BACKSPACE] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_DEFAULT);
m_bindings['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED);
@@ -470,36 +322,11 @@ DownloadList::setup_keys() {
m_bindings['\x0F'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_CHANGE_DIRECTORY);
m_bindings['\x10'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_COMMAND);
m_bindings[KEY_UP] = sigc::mem_fun(*this, &DownloadList::receive_prev);
m_bindings[KEY_DOWN] = sigc::mem_fun(*this, &DownloadList::receive_next);
m_bindings[KEY_RIGHT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD);
m_bindings['l'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_LOG);
m_uiArray[DISPLAY_LOG]->bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST);
m_uiArray[DISPLAY_LOG]->bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST);
m_bindings['1'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "main");
m_bindings['2'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "name");
m_bindings['3'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "started");
m_bindings['4'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "stopped");
m_bindings['5'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "complete");
m_bindings['6'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "incomplete");
m_bindings['7'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "hashing");
m_uiArray[DISPLAY_LOG]->bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST);
m_uiArray[DISPLAY_LOG]->bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST);
m_uiArray[DISPLAY_DOWNLOAD_LIST]->bindings()[KEY_RIGHT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD);
m_uiArray[DISPLAY_DOWNLOAD_LIST]->bindings()['l'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_LOG);
}
// void
// DownloadList::setup_input() {
// input::PathInput* p = new input::PathInput;
// m_windowTextInput = new WInput(p);
// p->slot_dirty(sigc::mem_fun(*m_windowTextInput, &WInput::mark_dirty));
// p->signal_show_next().connect(sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_STRING_LIST));
// p->signal_show_next().connect(sigc::mem_fun(*esl, &ElementStringList::next_screen));
// p->signal_show_range().connect(sigc::hide(sigc::hide(sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_STRING_LIST))));
// p->signal_show_range().connect(sigc::mem_fun(*esl, &ElementStringList::set_range<utils::Directory::iterator>));
// }
}