Skip to content

Commit

Permalink
Toggle details panel (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
vktr committed May 16, 2018
1 parent 35e3ce3 commit d7d3c8e
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"dht_i64d_nodes": "DHT: %I64d node(s)",
"i64d_torrents": "%I64d torrent(s)",
"dl_s_ul_s": "DL: %s/s, UL: %s/s",
"encrypt_config_file": "Encrypt configuration file"
"encrypt_config_file": "Encrypt configuration file",
"amp_details_panel": "&Details panel"
}
}
60 changes: 56 additions & 4 deletions src/picotorrent/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ MainFrame::MainFrame(std::shared_ptr<pt::Configuration> config,
m_torrentDetailsView = new TorrentDetailsView(m_splitter, m_trans, m_state);

// Splitter
m_splitter->SetMinimumPaneSize(10);
m_splitter->SetMinimumPaneSize(50);
m_splitter->SetSashGravity(0.5);
m_splitter->SplitHorizontally(m_torrentListView, m_torrentDetailsView);

Expand Down Expand Up @@ -112,13 +112,38 @@ MainFrame::MainFrame(std::shared_ptr<pt::Configuration> config,

this->DragAcceptFiles(true);
this->SetIcon(wxICON(AppIcon));
this->SetMenuBar(new MainMenu(m_state, m_config, m_env, m_updater, m_taskBar, m_trans));
this->SetMenuBar(new MainMenu(this, m_state, m_config, m_env, m_updater, m_taskBar, m_trans));
this->SetName("MainFrame");
this->SetSizerAndFit(mainSizer);
this->SetStatusBar(m_status);

wxPersistenceManager::Get().RegisterAndRestore(this);
wxPersistenceManager::Get().RegisterAndRestore(m_torrentListView);
wxPersistenceManager& persistenceManager = wxPersistenceManager::Get();

if (auto persistentObject = persistenceManager.Register(this))
{
persistenceManager.Restore(this);

int sashPosition = -1;
bool detailsVisible = false;

if (persistenceManager.RestoreValue(*persistentObject, "SashPosition", &sashPosition))
{
m_splitter->SetSashPosition(sashPosition);
}

if (persistenceManager.RestoreValue(*persistentObject, "DetailsVisible", &detailsVisible))
{
if (!detailsVisible)
{
m_splitter->Unsplit(m_torrentDetailsView);

MainMenu* mainMenu = reinterpret_cast<MainMenu*>(GetMenuBar());
mainMenu->SetDetailsToggle(false);
}
}
}

persistenceManager.RegisterAndRestore(m_torrentListView);

// Check for update
m_updater->Check(false);
Expand All @@ -129,6 +154,14 @@ MainFrame::MainFrame(std::shared_ptr<pt::Configuration> config,

MainFrame::~MainFrame()
{
wxPersistenceManager& persistenceManager = wxPersistenceManager::Get();

if (auto persistentObject = persistenceManager.Find(this))
{
persistenceManager.SaveValue(*persistentObject, "DetailsVisible", IsDetailsPanelVisible());
persistenceManager.SaveValue(*persistentObject, "SashPosition", m_splitter->GetSashPosition());
}

m_timer->Stop();

m_state->session->set_alert_notify([] {});
Expand All @@ -149,6 +182,25 @@ void MainFrame::HandleOptions(std::shared_ptr<pt::ApplicationOptions> options)
}
}

bool MainFrame::IsDetailsPanelVisible() const
{
return m_splitter->IsSplit();
}

void MainFrame::ToggleDetailsPanel()
{
if (m_splitter->IsSplit())
{
m_splitter->Unsplit(m_torrentDetailsView);
}
else
{
m_splitter->SplitHorizontally(
m_torrentListView,
m_torrentDetailsView);
}
}

void MainFrame::OnClose(wxCloseEvent& ev)
{
if (ev.CanVeto()
Expand Down
2 changes: 2 additions & 0 deletions src/picotorrent/mainframe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace pt
virtual ~MainFrame();

void HandleOptions(std::shared_ptr<ApplicationOptions> options);
bool IsDetailsPanelVisible() const;
void ToggleDetailsPanel();

private:
enum
Expand Down
22 changes: 21 additions & 1 deletion src/picotorrent/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "buildinfo.hpp"
#include "config.hpp"
#include "environment.hpp"
#include "mainframe.hpp"
#include "preferencesdlg.hpp"
#include "sessionstate.hpp"
#include "taskbaricon.hpp"
Expand All @@ -24,12 +25,14 @@ wxBEGIN_EVENT_TABLE(MainMenu, wxMenuBar)
EVT_MENU(wxID_ABOUT, MainMenu::OnAbout)
EVT_MENU(ptID_ADD_TORRENTS, MainMenu::OnAddTorrents)
EVT_MENU(ptID_ADD_MAGNET_LINK, MainMenu::OnAddMagnetLink)
EVT_MENU(ptID_VIEW_DETAILS_PANEL, MainMenu::OnViewDetailsPanel)
EVT_MENU(ptID_VIEW_PREFERENCES, MainMenu::OnViewPreferences)
EVT_MENU(ptID_CHECK_FOR_UPDATES, MainMenu::OnCheckForUpdates)
EVT_MENU(wxID_EXIT, MainMenu::OnExit)
wxEND_EVENT_TABLE()

MainMenu::MainMenu(std::shared_ptr<pt::SessionState> state,
MainMenu::MainMenu(pt::MainFrame const* mainFrame,
std::shared_ptr<pt::SessionState> state,
std::shared_ptr<pt::Configuration> cfg,
std::shared_ptr<pt::Environment> env,
std::shared_ptr<pt::ApplicationUpdater> updater,
Expand All @@ -52,6 +55,11 @@ MainMenu::MainMenu(std::shared_ptr<pt::SessionState> state,
menuFile->Append(wxID_EXIT, i18n(m_trans, "amp_exit"));

wxMenu* menuView = new wxMenu();

m_detailsToggle = menuView->AppendCheckItem(ptID_VIEW_DETAILS_PANEL, i18n(m_trans, "amp_details_panel"));
m_detailsToggle->Check(mainFrame->IsDetailsPanelVisible());

menuView->AppendSeparator();
menuView->Append(ptID_VIEW_PREFERENCES, i18n(m_trans, "amp_preferences"));

wxMenu* menuHelp = new wxMenu();
Expand All @@ -64,6 +72,11 @@ MainMenu::MainMenu(std::shared_ptr<pt::SessionState> state,
Append(menuHelp, i18n(m_trans, "amp_help"));
}

void MainMenu::SetDetailsToggle(bool value)
{
m_detailsToggle->Check(value);
}

void MainMenu::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxAboutDialogInfo aboutInfo;
Expand Down Expand Up @@ -99,6 +112,13 @@ void MainMenu::OnExit(wxCommandEvent& WXUNUSED(event))
this->GetFrame()->Close(true);
}

void MainMenu::OnViewDetailsPanel(wxCommandEvent& WXUNUSED(event))
{
MainFrame* mf = reinterpret_cast<MainFrame*>(this->GetFrame());
mf->ToggleDetailsPanel();
m_detailsToggle->Check(mf->IsDetailsPanelVisible());
}

void MainMenu::OnViewPreferences(wxCommandEvent& WXUNUSED(event))
{
PreferencesDialog dlg(
Expand Down
10 changes: 9 additions & 1 deletion src/picotorrent/mainmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ namespace pt
struct SessionState;
class TaskBarIcon;
class Translator;
class MainFrame;

class MainMenu : public wxMenuBar
{
public:
MainMenu(std::shared_ptr<SessionState> state,
MainMenu(MainFrame const* mainFrame,
std::shared_ptr<SessionState> state,
std::shared_ptr<Configuration> cfg,
std::shared_ptr<Environment> env,
std::shared_ptr<ApplicationUpdater> updater,
std::shared_ptr<TaskBarIcon> taskBarIcon,
std::shared_ptr<Translator> translator);

void SetDetailsToggle(bool value);

private:
enum
{
ptID_ADD_TORRENTS = wxID_HIGHEST + 1,
ptID_ADD_MAGNET_LINK,
ptID_VIEW_DETAILS_PANEL,
ptID_VIEW_PREFERENCES,
ptID_CHECK_FOR_UPDATES
};
Expand All @@ -42,6 +47,7 @@ namespace pt
void OnAddTorrents(wxCommandEvent&);
void OnCheckForUpdates(wxCommandEvent&);
void OnExit(wxCommandEvent&);
void OnViewDetailsPanel(wxCommandEvent&);
void OnViewPreferences(wxCommandEvent&);

std::shared_ptr<ApplicationUpdater> m_updater;
Expand All @@ -50,5 +56,7 @@ namespace pt
std::shared_ptr<Environment> m_env;
std::shared_ptr<TaskBarIcon> m_taskBarIcon;
std::shared_ptr<Translator> m_trans;

wxMenuItem* m_detailsToggle;
};
}
5 changes: 0 additions & 5 deletions src/picotorrent/torrentdetailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ void TorrentDetailsView::Clear()
m_trackers->Clear();
}

wxSize TorrentDetailsView::GetMinSize() const
{
return wxSize(450, 150);
}

void TorrentDetailsView::Update()
{
if (m_state->selected_torrents.size() != 1)
Expand Down
1 change: 0 additions & 1 deletion src/picotorrent/torrentdetailsview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace pt
TorrentDetailsView(wxWindow* parent,
std::shared_ptr<Translator> translator,
std::shared_ptr<SessionState> state);
virtual wxSize GetMinSize() const;

void Clear();
void Update();
Expand Down
5 changes: 0 additions & 5 deletions src/picotorrent/torrentlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ TorrentListView::TorrentListView(wxWindow* parent, wxWindowID id, std::shared_pt
statusCol->GetRenderer()->EnableEllipsize(wxELLIPSIZE_END);
}

wxSize TorrentListView::GetMinSize() const
{
return wxSize(SX(500), SY(150));
}

void TorrentListView::Sort()
{
if (GetSortingColumn())
Expand Down
1 change: 0 additions & 1 deletion src/picotorrent/torrentlistview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace pt
{
public:
TorrentListView(wxWindow* parent, wxWindowID id, std::shared_ptr<Translator> translator);
virtual wxSize GetMinSize() const wxOVERRIDE;
void Sort();
};
}

0 comments on commit d7d3c8e

Please sign in to comment.