📄 ui_handler.cpp
字号:
t_int max_uploads = limitBase::LIMIT_DISABLED; t_int max_connections = limitBase::LIMIT_DISABLED; { GET_HANDLER_INST; handler->reqGlobalLimitStatus(); if (handler->lastCommandSuccess()) { handler->getLastGlobalLimitStatus(upload, download, max_uploads, max_connections); if (upload != limitBase::LIMIT_DISABLED) { upload /= limitBase::KiB_to_B; } if (download != limitBase::LIMIT_DISABLED) { download /= limitBase::KiB_to_B; } } } windowSize limitdimensions; mainwindow_.getSize(limitdimensions); limitWindow limitwindow(keymap_, limitdimensions, upload, limitBase::LIMIT_DISABLED, /* min */ 65536, /* max */ "Global upload (KiB/sec)", /* label */ download, limitBase::LIMIT_DISABLED, 65536, "Global download (KiB/sec)", max_uploads, limitBase::LIMIT_DISABLED, 65536, "Global max uploads", max_connections, limitBase::LIMIT_DISABLED, 65536, "Global max connections"); if (limitwindow.run() == dialog::R_RESIZE) { // the window was resized. handleResizeMainWindow(); statuswindow_.setStatus("Setting global limits aborted."); // abort setting of limits, if the window was resized. return; } if (limitwindow.getLimits(upload, download, max_uploads, max_connections)) { { GET_HANDLER_INST; if (upload != limitBase::LIMIT_DISABLED) { upload *= limitBase::KiB_to_B; } if (download != limitBase::LIMIT_DISABLED) { download *= limitBase::KiB_to_B; } handler->reqGlobalLimit(upload, download, max_uploads, max_connections); if (handler->lastCommandSuccess()) { statuswindow_.setStatus("Global limits set."); } else { statuswindow_.setError("Unable to set global limits."); } } } else { statuswindow_.setStatus("Setting global limits aborted."); } } bool UI::handleQuit() { bool status = true; if (!neverAskQuestions_) { statuswindow_.setStatus("Quit?"); std::vector<menuEntry> contents; enum { QUIT_YES = 1, QUIT_NO = 2 }; contents.push_back(menuEntry(QUIT_NO, "No", "Quit")); contents.push_back(menuEntry(QUIT_YES, "Yes", "Do not quit")); windowSize menudimensions; mainwindow_.getSize(menudimensions); baseMenu bm(keymap_, menudimensions, "Quit?", contents); switch(bm.run()) { case dialog::R_RESIZE: { // the window was resized. handleResizeMainWindow(); statuswindow_.setStatus("Quit aborted."); // abort showing menu. return status; break; } case dialog::R_NCREAT: { return status; break; } default: { break; } } if (bm.getResult() == baseMenu::BM_cancel) { statuswindow_.setStatus("Quit aborted."); return status; } switch (bm.getResult()) { case QUIT_YES: status = false; break; case QUIT_NO: status = true; break; } } else { // No questions are asked, so just quit. status = false; } if (status) { return status; } // Quit confirmed. { GET_HANDLER_INST; handler->reqQuit(); } return status; } void UI::handleResizeMainWindow() { windowSize ws; baseWindow::getScreenSize(ws.width, ws.height); // Main window. windowSize mainwndSize = mainwindow_.calculateDimenstions(ws); mainwindow_.resize(mainwndSize); // Top window. windowSize topwndSize = topwindow_.calculateDimenstions(ws); topwindow_.resize(topwndSize); // Status window. windowSize statuswndSize = statuswindow_.calculateDimenstions(ws); statuswindow_.resize(statuswndSize); refresh(); } void UI::handleShowFiles(std::vector<btg::core::fileInformation> const& _fi) { std::string helpText; genHelpText(helpText); statuswindow_.setStatus("Showing file(s). " + helpText); windowSize fldimensions; mainwindow_.getSize(fldimensions); // Show a window with file information about a torrent. fileView fv(keymap_, fldimensions, _fi); // Use the same dimenstions as the main window. if (fv.run() == dialog::R_RESIZE) { // the window was resized. handleResizeMainWindow(); statuswindow_.setStatus("Showing file(s) aborted."); return; } setDefaultStatusText(); refresh(); } void UI::handleShowPeers(t_peerList & _peerlist) { std::string helpText; genHelpText(helpText); statuswindow_.setStatus("Showing peer(s). " + helpText); windowSize fldimensions; mainwindow_.getSize(fldimensions); // Show a window with file information about a torrent. peerList pl(keymap_, fldimensions, _peerlist); // Use the same dimenstions as the main window. if (pl.run() == dialog::R_RESIZE) { // the window was resized. handleResizeMainWindow(); statuswindow_.setStatus("Showing peer(s) aborted."); return; } setDefaultStatusText(); refresh(); } UI::selectState UI::handleSelectFiles(t_int const _context_id, btg::core::selectedFileEntryList const& _files) { std::string helpText; genHelpText(helpText); statuswindow_.setStatus("Selecting files. " + helpText); windowSize fldimensions; mainwindow_.getSize(fldimensions); // Show a window with file information about a torrent. fileSelect fs(keymap_, fldimensions, _files); // Use the same dimenstions as the main window. if (fs.run() == dialog::R_RESIZE) { // the window was resized. handleResizeMainWindow(); return UI::sS_SELECT_RESIZE; } // User selected the list. if (fs.pressed_select() && fs.changed()) { { // Got mutex already - in the calling function, // the menu handling. Handler* handler = dynamic_cast<Handler*>(handlerthread_->handler()); btg::core::selectedFileEntryList filesToSet; fs.getFiles(filesToSet); handler->reqSetFiles(_context_id, filesToSet); if (handler->lastCommandSuccess()) { return UI::sS_SELECT_SUCCESS; } else { return UI::sS_SELECT_FAILURE; } } } else if ((fs.pressed_select()) && (!fs.changed())) { // No change to the list of selected files. // No reason to tell the daemon to set the list. return UI::sS_SELECT_SUCCESS; } setDefaultStatusText(); refresh(); return UI::sS_SELECT_ABORT; } } // namespace cli } // namespace UI} // namespace btg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -