Skip to content

Commit

Permalink
Merge pull request #1000 from vktr/feature/better-overview
Browse files Browse the repository at this point in the history
Torrent overview: add user-defined column count, optional piece progress
  • Loading branch information
vktr committed Oct 27, 2020
2 parents 5ab11f5 + eee744c commit d340b73
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 57 deletions.
4 changes: 4 additions & 0 deletions res/dbmigrations/20201027213145_insert_overview_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO setting (key, value, default_value)
VALUES
('ui.torrent_overview.columns', NULL, 2),
('ui.torrent_overview.show_piece_progress', NULL, 'true');
1 change: 1 addition & 0 deletions src/picotorrent/resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AppIcon ICON "..\\..\\res\\app.ico"
20200916213321_insert_locale_name_setting DBMIGRATION "..\\..\\res\\dbmigrations\\20200916213321_insert_locale_name_setting.sql"
20200919221011_create_label_table DBMIGRATION "..\\..\\res\\dbmigrations\\20200919221011_create_label_table.sql"
20200925235912_save_resume_data_interval DBMIGRATION "..\\..\\res\\dbmigrations\\20200925235912_save_resume_data_interval.sql"
20201027213145_insert_overview_columns DBMIGRATION "..\\..\\res\\dbmigrations\\20201027213145_insert_overview_columns.sql"

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILE_VERSION
Expand Down
4 changes: 3 additions & 1 deletion src/picotorrent/ui/dialogs/preferencesadvancedpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ static std::map<std::string, std::map<std::string, Property>> properties =
{
"PicoTorrent",
{
MAKE_PROP(Int, Integer, int, "save_resume_data_interval", "save_resume_data_interval", "The interval (in seconds) between checks to save resume data for torrents. Saving resume data will help keep a current state if (for example) the application exits unexpectedly.")
MAKE_PROP(Int, Integer, int, "save_resume_data_interval", "save_resume_data_interval", "The interval (in seconds) between checks to save resume data for torrents. Saving resume data will help keep a current state if (for example) the application exits unexpectedly."),
MAKE_PROP(Int, Integer, int, "ui.torrent_overview.columns", "torrent_overview_columns", "The number of columns to show in the torrent overview panel."),
MAKE_PROP(Bool, Bool, bool, "ui.torrent_overview.show_piece_progress", "torrent_overview_show_piece_progress", "When set to true, show the piece progress bar in the torrent overview panel.")
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/picotorrent/ui/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ MainFrame::MainFrame(std::shared_ptr<Core::Environment> env, std::shared_ptr<Cor
m_splitter(new wxSplitterWindow(this, ptID_MAIN_SPLITTER)),
m_statusBar(new StatusBar(this)),
m_taskBarIcon(new TaskBarIcon(this)),
m_torrentDetails(new TorrentDetailsView(m_splitter, ptID_MAIN_TORRENT_DETAILS)),
m_torrentDetails(new TorrentDetailsView(m_splitter, ptID_MAIN_TORRENT_DETAILS, cfg)),
m_torrentListModel(new Models::TorrentListModel()),
m_torrentList(new TorrentListView(m_splitter, ptID_MAIN_TORRENT_LIST, m_torrentListModel)),
m_torrentsCount(0),
Expand Down Expand Up @@ -751,6 +751,7 @@ void MainFrame::OnViewPreferences(wxCommandEvent&)
m_taskBarIcon->Hide();
}

m_torrentDetails->ReloadConfiguration();
m_torrentListModel->SetBackgroundColorEnabled(
m_cfg->Get<bool>("use_label_as_list_bgcolor").value());

Expand Down
138 changes: 94 additions & 44 deletions src/picotorrent/ui/torrentdetailsoverviewpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CopyableStaticText : public wxStaticText
{
public:
CopyableStaticText(wxWindow* parent)
: wxStaticText(parent, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END)
: wxStaticText(parent, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END | wxST_NO_AUTORESIZE)
{
this->Bind(wxEVT_RIGHT_DOWN,
[this](wxMouseEvent const&)
Expand All @@ -83,9 +83,9 @@ class CopyableStaticText : public wxStaticText
}
};

TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id)
TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, int cols, bool showPieceProgress)
: wxScrolledWindow(parent, id),
m_pieceProgress(new Widgets::PieceProgressBar(this, wxID_ANY)),
m_pieceProgress(nullptr),
m_name(new CopyableStaticText(this)),
m_infoHash(new CopyableStaticText(this)),
m_savePath(new CopyableStaticText(this)),
Expand All @@ -99,45 +99,54 @@ TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWin
m_totalDownload(new CopyableStaticText(this)),
m_totalUpload(new CopyableStaticText(this))
{
auto sizer = new wxFlexGridSizer(4, FromDIP(10), FromDIP(10));
sizer->AddGrowableCol(1, 1);
sizer->AddGrowableCol(3, 1);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("name")));
sizer->Add(m_name, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("info_hash")));
sizer->Add(m_infoHash, 1, wxEXPAND);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("save_path")));
sizer->Add(m_savePath, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("pieces")));
sizer->Add(m_pieces, 1, wxEXPAND);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("comment")));
sizer->Add(m_comment, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("size")));
sizer->Add(m_size, 1, wxEXPAND);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("private")));
sizer->Add(m_priv, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("ratio")));
sizer->Add(m_ratio, 1, wxEXPAND);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("last_download")));
sizer->Add(m_lastDownload, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("last_upload")));
sizer->Add(m_lastUpload, 1, wxEXPAND);

sizer->Add(BoldLabel(this, wxID_ANY, i18n("total_download")));
sizer->Add(m_totalDownload, 1, wxEXPAND);
sizer->Add(BoldLabel(this, wxID_ANY, i18n("total_upload")));
sizer->Add(m_totalUpload, 1, wxEXPAND);

auto mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(m_pieceProgress, 0, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, FromDIP(5));
mainSizer->Add(sizer, 1, wxALL | wxEXPAND, FromDIP(5));

this->SetSizer(mainSizer);
m_sizer = new wxFlexGridSizer(cols * 2, FromDIP(10), FromDIP(10));

for (int i = 0; i < cols; i++)
{
m_sizer->AddGrowableCol(i * 2 + 1, 1);
}

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("name")));
m_sizer->Add(m_name, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("info_hash")));
m_sizer->Add(m_infoHash, 0, wxEXPAND);

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("save_path")));
m_sizer->Add(m_savePath, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("pieces")));
m_sizer->Add(m_pieces, 0, wxEXPAND);

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("comment")));
m_sizer->Add(m_comment, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("size")));
m_sizer->Add(m_size, 0, wxEXPAND);

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("private")));
m_sizer->Add(m_priv, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("ratio")));
m_sizer->Add(m_ratio, 0, wxEXPAND);

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("last_download")));
m_sizer->Add(m_lastDownload, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("last_upload")));
m_sizer->Add(m_lastUpload, 0, wxEXPAND);

m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("total_download")));
m_sizer->Add(m_totalDownload, 0, wxEXPAND);
m_sizer->Add(BoldLabel(this, wxID_ANY, i18n("total_upload")));
m_sizer->Add(m_totalUpload, 0, wxEXPAND);

m_mainSizer = new wxBoxSizer(wxVERTICAL);

if (showPieceProgress)
{
m_pieceProgress = new Widgets::PieceProgressBar(this, wxID_ANY);
m_mainSizer->Add(m_pieceProgress, 0, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, FromDIP(5));
}

m_mainSizer->Add(m_sizer, 1, wxALL | wxEXPAND, FromDIP(5));

this->SetSizer(m_mainSizer);
this->FitInside();
this->SetScrollRate(5, 5);
}
Expand All @@ -146,7 +155,10 @@ void TorrentDetailsOverviewPanel::Refresh(BitTorrent::TorrentHandle* torrent)
{
auto status = torrent->Status();

m_pieceProgress->UpdateBitfield(status.pieces);
if (m_pieceProgress != nullptr)
{
m_pieceProgress->UpdateBitfield(status.pieces);
}

m_name->SetLabel(Utils::toStdWString(status.name));
m_savePath->SetLabel(Utils::toStdWString(status.savePath));
Expand Down Expand Up @@ -211,7 +223,11 @@ void TorrentDetailsOverviewPanel::Refresh(BitTorrent::TorrentHandle* torrent)

void TorrentDetailsOverviewPanel::Reset()
{
m_pieceProgress->UpdateBitfield({});
if (m_pieceProgress != nullptr)
{
m_pieceProgress->UpdateBitfield({});
}

m_name->SetLabel("-");
m_infoHash->SetLabel("-");
m_savePath->SetLabel("-");
Expand All @@ -225,3 +241,37 @@ void TorrentDetailsOverviewPanel::Reset()
m_totalDownload->SetLabel("-");
m_totalUpload->SetLabel("-");
}

void TorrentDetailsOverviewPanel::UpdateView(int cols, bool showPieceProgress)
{
if (showPieceProgress && m_pieceProgress == nullptr)
{
m_pieceProgress = new Widgets::PieceProgressBar(this, wxID_ANY);
m_mainSizer->Insert(0, m_pieceProgress, 0, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, FromDIP(5));
}
else if (!showPieceProgress && m_pieceProgress != nullptr)
{
m_mainSizer->Remove(0);

delete m_pieceProgress;
m_pieceProgress = nullptr;
}

for (int i = 0; i < m_sizer->GetCols(); i++)
{
if (m_sizer->IsColGrowable(i))
{
m_sizer->RemoveGrowableCol(i);
}
}

m_sizer->SetCols(cols * 2);

for (int i = 0; i < cols; i++)
{
m_sizer->AddGrowableCol(i * 2 + 1, 1);
}

this->Layout();
this->FitInside();
}
7 changes: 6 additions & 1 deletion src/picotorrent/ui/torrentdetailsoverviewpanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <wx/wx.h>
#endif

class wxFlexGridSizer;

namespace pt::UI::Widgets { class PieceProgressBar; }

namespace pt
Expand All @@ -18,12 +20,15 @@ namespace UI
class TorrentDetailsOverviewPanel : public wxScrolledWindow
{
public:
TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id);
TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, int cols = 2, bool showPieceProgress = true);

void Refresh(BitTorrent::TorrentHandle* torrent);
void Reset();
void UpdateView(int cols, bool showPieceProgress);

private:
wxFlexGridSizer* m_sizer;
wxBoxSizer* m_mainSizer;
Widgets::PieceProgressBar* m_pieceProgress;
wxStaticText* m_name;
wxStaticText* m_infoHash;
Expand Down
15 changes: 14 additions & 1 deletion src/picotorrent/ui/torrentdetailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <wx/notebook.h>
#include <wx/sizer.h>

#include "../core/configuration.hpp"
#include "torrentdetailsfilespanel.hpp"
#include "torrentdetailsoverviewpanel.hpp"
#include "torrentdetailspeerspanel.hpp"
Expand All @@ -11,8 +12,9 @@

using pt::UI::TorrentDetailsView;

TorrentDetailsView::TorrentDetailsView(wxWindow* parent, wxWindowID id)
TorrentDetailsView::TorrentDetailsView(wxWindow* parent, wxWindowID id, std::shared_ptr<Core::Configuration> cfg)
: wxNotebook(parent, id),
m_cfg(cfg),
m_overview(new TorrentDetailsOverviewPanel(this, wxID_ANY)),
m_files(new TorrentDetailsFilesPanel(this, wxID_ANY)),
m_peers(new TorrentDetailsPeersPanel(this, wxID_ANY)),
Expand All @@ -22,6 +24,7 @@ TorrentDetailsView::TorrentDetailsView(wxWindow* parent, wxWindowID id)
this->AddPage(m_files, i18n("files"));
this->AddPage(m_peers, i18n("peers"));
this->AddPage(m_trackers, i18n("trackers"));
this->ReloadConfiguration();
}

TorrentDetailsView::~TorrentDetailsView()
Expand All @@ -42,6 +45,16 @@ void TorrentDetailsView::Refresh(std::map<lt::info_hash_t, BitTorrent::TorrentHa
m_trackers->Refresh(torrents.begin()->second);
}

void TorrentDetailsView::ReloadConfiguration()
{
auto showPieceProgress = m_cfg->Get<bool>("ui.torrent_overview.show_piece_progress");
auto cols = m_cfg->Get<int>("ui.torrent_overview.columns");

m_overview->UpdateView(
cols.value_or(2),
showPieceProgress.value_or(true));
}

void TorrentDetailsView::Reset()
{
m_overview->Reset();
Expand Down
18 changes: 9 additions & 9 deletions src/picotorrent/ui/torrentdetailsview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
#endif

#include <map>
#include <memory>

#include <libtorrent/info_hash.hpp>
#include <wx/notebook.h>

namespace pt
{
namespace BitTorrent
{
class TorrentHandle;
}
namespace UI
namespace pt::BitTorrent { class TorrentHandle; }
namespace pt::Core { class Configuration; }

namespace pt::UI
{
class TorrentDetailsFilesPanel;
class TorrentDetailsOverviewPanel;
Expand All @@ -26,17 +24,19 @@ namespace UI
class TorrentDetailsView : public wxNotebook
{
public:
TorrentDetailsView(wxWindow* parent, wxWindowID id);
TorrentDetailsView(wxWindow* parent, wxWindowID id, std::shared_ptr<Core::Configuration> cfg);
virtual ~TorrentDetailsView();

void Refresh(std::map<libtorrent::info_hash_t, BitTorrent::TorrentHandle*> const& torrents);
void ReloadConfiguration();
void Reset();

private:
std::shared_ptr<Core::Configuration> m_cfg;

TorrentDetailsOverviewPanel* m_overview;
TorrentDetailsFilesPanel* m_files;
TorrentDetailsPeersPanel* m_peers;
TorrentDetailsTrackersPanel* m_trackers;
};
}
}

0 comments on commit d340b73

Please sign in to comment.