Cleaned up ui/root.

This commit is contained in:
rakshasa
2025-03-11 14:06:57 +01:00
committed by Jari Sundell
parent c6ebdf876a
commit 47af28aecd
3 changed files with 38 additions and 121 deletions
+4
View File
@@ -13,6 +13,10 @@
#include "display/canvas.h"
#include "display/window.h"
#include "display/window_http_queue.h"
#include "display/window_input.h"
#include "display/window_statusbar.h"
#include "display/window_title.h"
#include "display/manager.h"
#include "input/manager.h"
#include "input/input_event.h"
+16 -69
View File
@@ -1,39 +1,3 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2011, Jari Sundell
//
// 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
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <fstream>
@@ -63,17 +27,7 @@
namespace ui {
Root::Root() :
m_control(NULL),
m_downloadList(NULL),
m_windowTitle(NULL),
m_windowHttpQueue(NULL),
m_windowInput(NULL),
m_windowStatusbar(NULL),
m_input_history_length(99),
m_input_history_last_input(""),
m_input_history_pointer_get(0) {
Root::Root() {
// Initialise prefilled m_input_history and m_input_history_pointers objects.
for (int type = ui::DownloadList::INPUT_LOAD_DEFAULT; type != ui::DownloadList::INPUT_EOI; type++) {
m_input_history.insert( std::make_pair(type, InputHistoryCategory(m_input_history_length)) );
@@ -84,25 +38,25 @@ Root::Root() :
void
Root::init(Control* c) {
if (m_control != NULL)
if (m_control != nullptr)
throw std::logic_error("Root::init() called twice on the same object");
m_control = c;
m_windowTitle = new WTitle();
m_windowHttpQueue = new WHttpQueue(control->core()->http_queue());
m_windowInput = new WInput();
m_windowStatusbar = new WStatusbar();
m_windowTitle = std::make_unique<display::WindowTitle>();
m_windowHttpQueue = std::make_unique<WHttpQueue>(control->core()->http_queue());
m_windowInput = std::make_unique<WInput>();
m_windowStatusbar = std::make_unique<WStatusbar>();
m_downloadList = new DownloadList();
m_downloadList = std::make_unique<DownloadList>();
display::Frame* rootFrame = m_control->display()->root_frame();
rootFrame->initialize_row(5);
rootFrame->frame(0)->initialize_window(m_windowTitle);
rootFrame->frame(2)->initialize_window(m_windowHttpQueue);
rootFrame->frame(3)->initialize_window(m_windowInput);
rootFrame->frame(4)->initialize_window(m_windowStatusbar);
rootFrame->frame(0)->initialize_window(m_windowTitle.get());
rootFrame->frame(2)->initialize_window(m_windowHttpQueue.get());
rootFrame->frame(3)->initialize_window(m_windowInput.get());
rootFrame->frame(4)->initialize_window(m_windowStatusbar.get());
m_windowTitle->set_active(true);
m_windowStatusbar->set_active(true);
@@ -122,15 +76,8 @@ Root::cleanup() {
m_downloadList->disable();
m_control->display()->root_frame()->clear();
delete m_downloadList;
delete m_windowTitle;
delete m_windowHttpQueue;
delete m_windowInput;
delete m_windowStatusbar;
m_control->input()->erase(&m_bindings);
m_control = NULL;
}
@@ -248,7 +195,7 @@ Root::enable_input(const std::string& title, input::TextInput* input, ui::Downlo
if (m_windowInput->input() != NULL)
throw torrent::internal_error("Root::enable_input(...) m_windowInput->input() != NULL.");
input->slot_dirty(std::bind(&WInput::mark_dirty, m_windowInput));
input->slot_dirty(std::bind(&WInput::mark_dirty, m_windowInput.get()));
m_windowStatusbar->set_active(false);
@@ -392,7 +339,7 @@ Root::set_input_history_size(int size) {
void
Root::load_input_history() {
if (m_control == NULL || !m_control->core()->download_store()->is_enabled()) {
if (m_control == nullptr || !m_control->core()->download_store()->is_enabled()) {
lt_log_print(torrent::LOG_DEBUG, "ignoring input history file");
return;
}
@@ -411,7 +358,7 @@ Root::load_input_history() {
while (std::getline(history_file, line)) {
if (!line.empty()) {
int delim_pos = line.find("|");
auto delim_pos = line.find("|");
if (delim_pos != std::string::npos) {
int type = std::atoi(line.substr(0, delim_pos).c_str());
@@ -460,7 +407,7 @@ Root::load_input_history() {
void
Root::save_input_history() {
if (m_control == NULL || !m_control->core()->download_store()->is_enabled())
if (m_control == nullptr || !m_control->core()->download_store()->is_enabled())
return;
std::string history_filename = m_control->core()->download_store()->path() + "rtorrent.input_history";
+18 -52
View File
@@ -1,43 +1,9 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2011, Jari Sundell
//
// 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
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_UI_ROOT_H
#define RTORRENT_UI_ROOT_H
#include <cstdint>
#include <memory>
#include "input/bindings.h"
#include "download_list.h"
@@ -77,11 +43,11 @@ public:
void init(Control* c);
void cleanup();
WTitle* window_title() { return m_windowTitle; }
WStatusbar* window_statusbar() { return m_windowStatusbar; }
WInput* window_input() { return m_windowInput; }
WTitle* window_title() { return m_windowTitle.get(); }
WStatusbar* window_statusbar() { return m_windowStatusbar.get(); }
WInput* window_input() { return m_windowInput.get(); }
DownloadList* download_list() { return m_downloadList; }
DownloadList* download_list() { return m_downloadList.get(); }
void set_down_throttle(unsigned int throttle);
void set_up_throttle(unsigned int throttle);
@@ -117,21 +83,21 @@ public:
private:
void setup_keys();
Control* m_control;
DownloadList* m_downloadList;
Control* m_control{nullptr};
std::unique_ptr<DownloadList> m_downloadList;
WTitle* m_windowTitle;
WHttpQueue* m_windowHttpQueue;
WInput* m_windowInput;
WStatusbar* m_windowStatusbar;
std::unique_ptr<WTitle> m_windowTitle;
std::unique_ptr<WHttpQueue> m_windowHttpQueue;
std::unique_ptr<WInput> m_windowInput;
std::unique_ptr<WStatusbar> m_windowStatusbar;
input::Bindings m_bindings;
input::Bindings m_bindings;
int m_input_history_length;
std::string m_input_history_last_input;
int m_input_history_pointer_get;
InputHistory m_input_history;
InputHistoryPointers m_input_history_pointers;
int m_input_history_length{99};
std::string m_input_history_last_input{""};
int m_input_history_pointer_get{0};
InputHistory m_input_history;
InputHistoryPointers m_input_history_pointers;
void prev_in_input_history(ui::DownloadList::Input type);
void next_in_input_history(ui::DownloadList::Input type);