From 47af28aecda80f2df5f5ec439b830780b888b646 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 11 Mar 2025 14:06:57 +0100 Subject: [PATCH] Cleaned up ui/root. --- src/control.cc | 4 +++ src/ui/root.cc | 85 ++++++++++---------------------------------------- src/ui/root.h | 70 +++++++++++------------------------------ 3 files changed, 38 insertions(+), 121 deletions(-) diff --git a/src/control.cc b/src/control.cc index 1edfccec..907fc12b 100644 --- a/src/control.cc +++ b/src/control.cc @@ -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" diff --git a/src/ui/root.cc b/src/ui/root.cc index db7bab8d..3a3d675e 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #include "config.h" #include @@ -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(); + m_windowHttpQueue = std::make_unique(control->core()->http_queue()); + m_windowInput = std::make_unique(); + m_windowStatusbar = std::make_unique(); - m_downloadList = new DownloadList(); + m_downloadList = std::make_unique(); 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"; diff --git a/src/ui/root.h b/src/ui/root.h index e6950322..023de98e 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #ifndef RTORRENT_UI_ROOT_H #define RTORRENT_UI_ROOT_H #include +#include + #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 m_downloadList; - WTitle* m_windowTitle; - WHttpQueue* m_windowHttpQueue; - WInput* m_windowInput; - WStatusbar* m_windowStatusbar; + std::unique_ptr m_windowTitle; + std::unique_ptr m_windowHttpQueue; + std::unique_ptr m_windowInput; + std::unique_ptr 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);