📄 ui_handler.cpp
字号:
/* * btg Copyright (C) 2005 Michael Wojciechowski. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* * $Id: ui_handler.cpp,v 1.1.4.1 2007/09/17 15:34:50 wojci Exp $ */#include "ui.h"#include <bcore/logmacro.h>#include "detailwindow.h"#include "helpwindow.h"#include "filelist.h"#include "fileview.h"#include "fileselect.h"#include "peerlist.h"#include "basemenu.h"#include "limitwindow.h"#include <bcore/client/handlerthr.h>#include "handler.h"#include <bcore/command/limit_base.h>#include <bcore/hrr.h>#define GET_HANDLER_INST \ boost::shared_ptr<boost::mutex> ptr = handlerthread_->mutex(); \ boost::mutex::scoped_lock interface_lock(*ptr); \ Handler* handler = dynamic_cast<Handler*>(handlerthread_->handler());namespace btg{ namespace UI { namespace cli { using namespace btg::core; bool UI::handleKeyboard() { bool status = true; // Continue reading. keyMapping::KEYLABEL label = mainwindow_.handleKeyboard(); switch (label) { case keyMapping::K_UNDEF: { // Handle status updates, used to fill the list // of torrents. { GET_HANDLER_INST; bool statusUpdated = handler->statusListUpdated(); if (statusUpdated) { t_statusList statusList; handler->getStatusList(statusList); update(statusList); updateBandwidth(statusList); } // Make sure that if (handler->statusSize() == 0) { clear(); } refresh(); } break; } case keyMapping::K_QUIT: { status = handleQuit(); switch (status) { case true: statuswindow_.setStatus("Quit aborted."); break; case false: statuswindow_.setStatus("Quitting."); break; } refresh(); break; } case keyMapping::K_DETACH: { { GET_HANDLER_INST; handler->reqDetach(); } status = false; break; } case keyMapping::K_DOWN: { mainwindow_.moveDown(); refresh(); break; } case keyMapping::K_UP: { mainwindow_.moveUp(); refresh(); break; } case keyMapping::K_LIST_START: { mainwindow_.toStart(); refresh(); break; } case keyMapping::K_LIST_END: { mainwindow_.toEnd(); refresh(); break; } case keyMapping::K_SELECT: { handleShowDetails(); refresh(); break; } case keyMapping::K_MARK: { handleMark(); break; } case keyMapping::K_MARK_ALL: { handleMarkAll(); break; } case keyMapping::K_MENU: { handleMenu(); refresh(); break; } case keyMapping::K_LOAD: { handleLoad(); refresh(); break; } case keyMapping::K_GLIMIT: { handleGlobalLimit(); refresh(); break; } case keyMapping::K_HELP: { switch (handleHelp()) { case dialog::R_RESIZE: { handleResizeMainWindow(); break; } case dialog::R_NCREAT: { statuswindow_.setError("Unable to show help - resize window."); break; } default: { setDefaultStatusText(); break; } } refresh(); break; } case keyMapping::K_RESIZE: { handleResizeMainWindow(); break; } default: { break; } } return status; } dialog::RESULT UI::handleShowDetailsHelp() { // Show a help window on the middle of the screen. std::vector<std::string> helpText; helpText.push_back("Help"); helpText.push_back(" "); std::string keyDescr; if (helpWindow::generateHelpForKey(keymap_, keyMapping::K_QUIT, "to go back", keyDescr)) { helpText.push_back(keyDescr); } helpText.push_back(" "); helpWindow hw(keymap_, helpText); return hw.run(); } void UI::handleShowDetails() { btg::core::Status teststatus; if (!mainwindow_.getSelection(teststatus)) { // Nothing to display. return; } bool details_resized = false; windowSize detailsdimension; mainwindow_.getSize(detailsdimension); { setDefaultStatusText(); mainwindow_.clear(); detailWindow dw(keymap_, mainwindow_); dw.init(detailsdimension); dw.refresh(); keyMapping::KEYLABEL label; bool cont = true; while (cont) { label = dw.handleKeyboard(); switch (label) { case keyMapping::K_UNDEF: { { GET_HANDLER_INST; bool statusUpdated = handler->statusListUpdated(); if (statusUpdated) { t_statusList statusList; handler->getStatusList(statusList); update(statusList); // Redraw the contents. dw.refresh(); } } break; } case keyMapping::K_QUIT: { cont = false; dw.clear(); break; } case keyMapping::K_HELP: { switch (handleShowDetailsHelp()) { case dialog::R_RESIZE: { // window was resized. cont = false; details_resized = true; dw.clear(); break; } default: { break; } } break; } case keyMapping::K_RESIZE: { cont = false; details_resized = true; dw.clear(); break; } default: { // Do nothing. break; } } } // dw.destroy(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -