⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cpp

📁 LINUX下
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            // Find the max length of the contained file names;            t_uint max_filename_size = 0;            std::vector<statusEntry>::const_iterator iter;            for (iter = iterBeg;                 iter != iterEnd;                 iter++)               {                  btg::core::Status const& s = iter->status;                  t_uint size = s.filename().size();                  if (size > max_filename_size)                     {                        max_filename_size = size;                     }               }            if (max_filename_size > 40)               {                  max_filename_size = 40;               }            // Display the window.            t_int counter = 0;            for (iter = iterBeg;                 iter != iterEnd;                 iter++)               {                  btg::core::Status const& s = iter->status;                  std::string filename = s.filename();                  if (filename.size() > max_filename_size)                     {                        filename = filename.substr(0, max_filename_size);                     }                  else                     {                        t_int diff = max_filename_size - filename.size();                        if (diff > 0)                           {                              for (t_int counter = 0;                                   counter < diff;                                   counter++)                                 {                                    filename += " ";                                 }                           }                     }                  // Indicates that progress should be shown,                  // which is not always the case.                  bool show_progress = false;                  std::string st_status(" ");                  switch (s.status())                     {                     case btg::core::Status::ts_undefined:                        {                           st_status += "undf";                           break;                        }                     case btg::core::Status::ts_queued:                        {                           st_status += "wait";                           break;                        }                     case btg::core::Status::ts_checking:                        {                           st_status += "Chec";                           break;                        }                     case btg::core::Status::ts_connecting:                        {                           st_status += "conn";                           break;                        }                     case btg::core::Status::ts_downloading:                        {                           st_status    += "down";                           show_progress = true;                           break;                        }                     case btg::core::Status::ts_seeding:                        {                           st_status += "seed";                           break;                        }                     case btg::core::Status::ts_finished:                        {                           st_status += "fini";                           break;                        }                     case btg::core::Status::ts_stopped:                        {                           st_status += "stop";                           break;                        }                     }                  // Add percent:                  t_int done = s.done();                  std::string st_done(" ");                  if (done < 10)                     {                        st_done += " ";                     }                  if (done < 100)                     {                        st_done += " ";                     }                  st_done += btg::core::convertToString<t_int>(done);                  st_done += "%";                  // Add progress:                  std::string st_progress(" ");                  if (show_progress)                     {                        if (s.time_left_d() != 0)                           {                              // Only show days.                              st_progress += btg::core::convertToString<t_ulong>(s.time_left_d());                              st_progress += " days";                           }                        else                           {                              if ((s.time_left_h() != 0) ||                                  (s.time_left_m() != 0) ||                                  (s.time_left_s() != 0)                                  )                                 {                                    if (s.time_left_h() < 10)                                       {                                          st_progress += "0";                                       }                                    st_progress += btg::core::convertToString<t_ulong>(s.time_left_h()) + ":";                                    if (s.time_left_m() < 10)                                       {                                          st_progress += "0";                                       }                                    st_progress += btg::core::convertToString<t_int>(s.time_left_m()) + ":";			                                          if (s.time_left_s() < 10)                                       {                                          st_progress += "0";                                       }                                    st_progress += btg::core::convertToString<t_int>(s.time_left_s());                                 }                           }                     }                  else                     {                        st_progress += " ";                     }                  // Display marked torrents with different color.                  if (iter->marked)                     {                        setColor(Colors::C_MARK);                     }                  if (counter == currentPosition_)                     {                        // Highlight.                        std::string spacestr;                        t_int spaces = width_ - filename.size() -                            st_status.size() - st_done.size() -                            st_progress.size() - 1;                        /* extra space is inserted at                         * the beginning of the line.                         */                        if (spaces > 0)                           {                              for (t_int spacecounter = 0;                                   spacecounter < spaces;                                   spacecounter++)                                 {                                    spacestr += " ";                                 }                           }                        ::wattron(window_, A_REVERSE);                        mvwprintw(window_, counter, 0, " %s%s%s%s%s",                                   filename.c_str(),                                   st_status.c_str(),                                  st_done.c_str(),                                  st_progress.c_str(),                                  spacestr.c_str());                        ::wattroff(window_, A_REVERSE);                     }                  else                     {                        mvwprintw(window_, counter, 0, " %s%s%s%s",                                   filename.c_str(),                                  st_status.c_str(),                                  st_done.c_str(),                                  st_progress.c_str());                     }                  // Display marked torrents with different color.                  if (iter->marked)                     {                        unSetColor(Colors::C_MARK);                     }                  counter++;               }            unSetColor(Colors::C_NORMAL);         }         void mainWindow::update(std::vector<btg::core::Status> const& _list)         {            list_.update(_list);            if (list_.changed())               {                  list_.resetChanged();                  // Fix the position window.                  if (positionWindowEnd_ < static_cast<t_int>(list_.size()))                     {                        positionWindowEnd_ = list_.size();                        if (positionWindowEnd_ > numberOfLines_)                           {                              positionWindowEnd_ = numberOfLines_;                           }                     }                  drawList();                  refresh();               }         }         void mainWindow::remove(std::vector<t_int> const& _id_list)         {            list_.remove(_id_list);            if (list_.changed())               {                  list_.resetChanged();                  // Adjust:                  const t_int list_size = list_.size();                  if (positionWindowStart_ > list_size)                     {                        positionWindowStart_ = list_.size();                     }                  if (positionWindowEnd_ > list_size)                     {                        positionWindowEnd_ = list_.size();                     }                  if (currentPosition_ > list_size)                     {                        currentPosition_ = list_.size();                     }                  clear();                  drawList();                  refresh();               }         }         void mainWindow::clearContents()         {            list_.clear();         }         void mainWindow::moveDown()         {            const t_int list_max = list_.size();            if (currentPosition_ < (numberOfLines_-1))               {                  currentPosition_++;                  if (list_.size() > 0)                     {                        if (currentPosition_ > (list_max - 1))                           {                              currentPosition_--;                           }                     }               }            else               {                  if (positionWindowEnd_ < list_max)                     {                        positionWindowStart_++;                        positionWindowEnd_++;                     }               }         }         void mainWindow::moveUp()         {            if (currentPosition_ > 0)               {                  currentPosition_--;               }            else               {                  if ((positionWindowStart_-1) >= 0)                     {                        positionWindowStart_--;                        positionWindowEnd_--;                     }               }         }         void mainWindow::toStart()         {            currentPosition_     = 0;         }         void mainWindow::toEnd()         {            currentPosition_ = (numberOfLines_-1);            t_int max_position = list_.size();            if (max_position > 0)               {                  max_position--;               }            if (currentPosition_ > max_position)               {                  currentPosition_ = max_position;               }         }         bool mainWindow::get(t_int const _context_id, btg::core::Status & _status) const         {            return list_.get(_context_id, _status);         }         bool mainWindow::getSelection(btg::core::Status & _status) const         {            bool status = false;            if (list_.size() == 0)               {                  return status;               }            t_uint current = positionWindowStart_ + currentPosition_;            if (list_.getAtPosition(current, _status))               {                  status = true;               }            return status;         }         void mainWindow::mark()         {            if (list_.size() == 0)               {                  return;               }            t_uint current = positionWindowStart_ + currentPosition_;            list_.mark(current);         }         void mainWindow::markAll()         {            list_.markAll();         }         void mainWindow::getMarked(std::vector<t_int> & _id_list) const         {            list_.getMarked(_id_list);         }         void mainWindow::clearMark()         {            list_.clearMark();         }         windowSize mainWindow::calculateDimenstions(windowSize const& _ws) const         {            windowSize ws;            ws.topX   = 0;            ws.topY   = 2;            ws.width  = _ws.width;            ws.height = _ws.height-3;            return ws;         }         mainWindow::~mainWindow()         {            destroy();         }      } // namespace cli   } // namespace UI} // namespace btg

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -