Skip to content

Commit

Permalink
General improvements (#558)
Browse files Browse the repository at this point in the history
* Add padding and ellipsis fix when selecting torrent

* Add copyable elements for the overview page

* Fix an update bug in the peers list view

* Improve the torrent context menu

* Add a more immediate feel when pausing/resuming torrents

* Remove stalled status

* Fix UTF8 paths

Closes #547 
Closes #554
  • Loading branch information
vktr committed Apr 7, 2018
1 parent d38d98f commit 366be86
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 84 deletions.
3 changes: 2 additions & 1 deletion lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"comment": "Comment",
"skip_add_torrent_dialog": "Skip 'Add torrent' dialog",
"start_torrent": "Start torrent",
"auto_managed": "Auto managed"
"auto_managed": "Auto managed",
"copy": "Copy"
}
}
4 changes: 2 additions & 2 deletions src/picotorrent/addtorrentdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void AddTorrentDialog::LoadTorrentInfo(int index)
m_infoHash->SetLabel("-");

// Save path
m_savePath->SetPath(params.save_path);
m_savePath->SetPath(wxString::FromUTF8(params.save_path));
m_sequentialMode->SetValue(
(params.flags & lt::torrent_flags::sequential_download) == lt::torrent_flags::sequential_download);

Expand Down Expand Up @@ -217,7 +217,7 @@ void AddTorrentDialog::OnSavePathChanged(wxFileDirPickerEvent& event)
{
int idx = m_torrents->GetSelection();
lt::add_torrent_params& params = m_params.at(idx);
params.save_path = event.GetPath().ToStdString();
params.save_path = event.GetPath().ToUTF8();
}

void AddTorrentDialog::OnSetPriority(wxCommandEvent& event)
Expand Down
4 changes: 2 additions & 2 deletions src/picotorrent/downloadspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DownloadsPage::DownloadsPage(wxWindow* parent, std::shared_ptr<pt::Configuration
wxFlexGridSizer* transfersGrid = new wxFlexGridSizer(2, 10, 10);

m_savePathCtrl = new wxDirPickerCtrl(transfersSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE | wxDIRP_SMALL);
m_savePathCtrl->SetPath(m_cfg->DefaultSavePath().string());
m_savePathCtrl->SetPath(wxString::FromUTF8(m_cfg->DefaultSavePath().string()));

transfersGrid->AddGrowableCol(1, 1);
transfersGrid->Add(new wxStaticText(transfersSizer->GetStaticBox(), wxID_ANY, i18n(tran, "save_path")), 0, wxALIGN_CENTER_VERTICAL);
Expand Down Expand Up @@ -100,7 +100,7 @@ void DownloadsPage::ApplyConfiguration()
long ulLimit = 0;
m_uploadLimit->GetValue().ToLong(&ulLimit);

m_cfg->DefaultSavePath(m_savePathCtrl->GetPath().ToStdString());
m_cfg->DefaultSavePath(std::string(m_savePathCtrl->GetPath().ToUTF8()));
m_cfg->Session()->EnableDownloadRateLimit(m_enableDownloadLimit->GetValue());
m_cfg->Session()->DownloadRateLimit(static_cast<int>(dlLimit));
m_cfg->Session()->EnableUploadRateLimit(m_enableUploadLimit->GetValue());
Expand Down
14 changes: 14 additions & 0 deletions src/picotorrent/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ void MainFrame::OnSessionAlert()

break;
}
case lt::torrent_paused_alert::alert_type:
{
lt::torrent_paused_alert* tpa = lt::alert_cast<lt::torrent_paused_alert>(alert);
m_torrentListViewModel->Update(tpa->handle.status());

break;
}
case lt::torrent_removed_alert::alert_type:
{
lt::torrent_removed_alert* tra = lt::alert_cast<lt::torrent_removed_alert>(alert);
Expand All @@ -421,6 +428,13 @@ void MainFrame::OnSessionAlert()

break;
}
case lt::torrent_resumed_alert::alert_type:
{
lt::torrent_resumed_alert* tra = lt::alert_cast<lt::torrent_resumed_alert>(alert);
m_torrentListViewModel->Update(tra->handle.status());

break;
}
}
}
}
Expand Down
53 changes: 45 additions & 8 deletions src/picotorrent/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,48 @@

#include "translator.hpp"

#include <sstream>

#include <libtorrent/torrent_status.hpp>
#include <sstream>
#include <wx/clipbrd.h>

namespace lt = libtorrent;
using pt::OverviewPage;

class CopyableStaticText : public wxStaticText
{
public:
CopyableStaticText(wxWindow *parent, std::shared_ptr<pt::Translator> tr)
: wxStaticText(parent, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END, wxStaticTextNameStr)
{
this->Bind(wxEVT_RIGHT_DOWN, [this, tr](wxMouseEvent const& ev)
{
if (this->GetLabel() == "-")
{
return;
}

wxMenu menu;
menu.Append(9999, i18n(tr, "copy"));
menu.Bind(wxEVT_MENU, [this](wxCommandEvent const&)
{
if (wxTheClipboard->Open())
{
wxTheClipboard->SetData(new wxTextDataObject(this->GetLabel()));
wxTheClipboard->Close();
}
});

PopupMenu(&menu);
});
}
};

OverviewPage::OverviewPage(wxWindow* parent, wxWindowID id, std::shared_ptr<pt::Translator> tr)
: wxPanel(parent, id),
m_name(new wxStaticText(this, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END)),
m_infoHash(new wxStaticText(this, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END)),
m_savePath(new wxStaticText(this, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END)),
m_pieces(new wxStaticText(this, wxID_ANY, "-", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END))
m_name(new CopyableStaticText(this, tr)),
m_infoHash(new CopyableStaticText(this, tr)),
m_savePath(new CopyableStaticText(this, tr)),
m_pieces(new CopyableStaticText(this, tr))
{
wxFlexGridSizer* sz = new wxFlexGridSizer(4, 10, 10);
sz->AddGrowableCol(1);
Expand All @@ -30,7 +59,10 @@ OverviewPage::OverviewPage(wxWindow* parent, wxWindowID id, std::shared_ptr<pt::
sz->Add(GetBoldStatic(i18n(tr, "pieces")));
sz->Add(m_pieces, 1, wxEXPAND);

this->SetSizerAndFit(sz);
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(sz, 1, wxALL | wxEXPAND, 5);

this->SetSizerAndFit(mainSizer);
}

void OverviewPage::Clear()
Expand All @@ -46,10 +78,15 @@ void OverviewPage::Update(lt::torrent_status const& ts)
std::stringstream ih;
ih << ts.info_hash;

wxString savePath = wxString::FromUTF8(ts.save_path);
savePath.Replace("&", "&&");

m_name->SetLabel(ts.name);
m_infoHash->SetLabel(ih.str());
m_savePath->SetLabel(ts.save_path);
m_savePath->SetLabel(savePath);
m_pieces->SetLabel(wxString::Format("%d (of %d)", ts.pieces.count(), ts.pieces.size()));

this->SendSizeEvent();
}

wxStaticText* OverviewPage::GetBoldStatic(wxString const& label)
Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/peersviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void PeersViewModel::Update(lt::torrent_status const& ts)
else
{
auto distance = std::distance(m_data.begin(), f);
m_data.at(distance) = *f;
m_data.at(distance) = *it;
RowChanged(distance);
}
}
Expand Down
55 changes: 21 additions & 34 deletions src/picotorrent/torrentcontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using pt::TorrentContextMenu;
BEGIN_EVENT_TABLE(TorrentContextMenu, wxMenu)
EVT_MENU(ptID_PAUSE, TorrentContextMenu::Pause)
EVT_MENU(ptID_RESUME, TorrentContextMenu::Resume)
EVT_MENU(ptID_RESUME_FORCE, TorrentContextMenu::Resume)
EVT_MENU(ptID_QUEUE_UP, TorrentContextMenu::QueueUp)
EVT_MENU(ptID_QUEUE_DOWN, TorrentContextMenu::QueueDown)
EVT_MENU(ptID_QUEUE_TOP, TorrentContextMenu::QueueTop)
Expand All @@ -31,7 +32,6 @@ BEGIN_EVENT_TABLE(TorrentContextMenu, wxMenu)
EVT_MENU(ptID_FORCE_RECHECK, TorrentContextMenu::ForceRecheck)
EVT_MENU(ptID_FORCE_REANNOUNCE, TorrentContextMenu::ForceReannounce)
EVT_MENU(ptID_SEQUENTIAL_DOWNLOAD, TorrentContextMenu::SequentialDownload)
EVT_MENU(ptID_AUTO_MANAGED, TorrentContextMenu::AutoManaged)
END_EVENT_TABLE()

TorrentContextMenu::TorrentContextMenu(
Expand All @@ -55,7 +55,8 @@ TorrentContextMenu::TorrentContextMenu(
[this](lt::torrent_handle const& th)
{
lt::torrent_status ts = th.status();
return (ts.flags & lt::torrent_flags::paused) == lt::torrent_flags::paused;
return (ts.flags & lt::torrent_flags::paused) == lt::torrent_flags::paused
&& !((ts.flags & lt::torrent_flags::auto_managed) == lt::torrent_flags::auto_managed);
});

bool allNotPaused = std::all_of(
Expand All @@ -64,10 +65,12 @@ TorrentContextMenu::TorrentContextMenu(
[this](lt::torrent_handle const& th)
{
lt::torrent_status ts = th.status();
return !((ts.flags & lt::torrent_flags::paused) == lt::torrent_flags::paused);
return !((ts.flags & lt::torrent_flags::paused) == lt::torrent_flags::paused
&& !((ts.flags & lt::torrent_flags::auto_managed) == lt::torrent_flags::auto_managed));
});

wxMenuItem* resume = Append(ptID_RESUME, i18n(tr, "resume"));
wxMenuItem* resumeForced = Append(ptID_RESUME_FORCE, i18n(tr, "resume_force"));
wxMenuItem* pause = Append(ptID_PAUSE, i18n(tr, "pause"));

if (allPaused)
Expand All @@ -78,21 +81,10 @@ TorrentContextMenu::TorrentContextMenu(
if (allNotPaused)
{
Delete(resume);
Delete(resumeForced);
}

AppendSeparator();

if (m_state->selected_torrents.size() == 1)
{
wxMenuItem* autoManagedItem = Append(ptID_AUTO_MANAGED, i18n(tr, "auto_managed"));

if ((m_state->selected_torrents[0].flags() & lt::torrent_flags::auto_managed) == lt::torrent_flags::auto_managed)
{
autoManagedItem->SetCheckable(true);
autoManagedItem->Check();
}
}

Append(ptID_FORCE_REANNOUNCE, i18n(tr, "force_reannounce"));
Append(ptID_FORCE_RECHECK, i18n(tr, "force_recheck"));

Expand All @@ -116,23 +108,6 @@ TorrentContextMenu::TorrentContextMenu(
Append(ptID_OPEN_IN_EXPLORER, i18n(tr, "open_in_explorer"));
}

void TorrentContextMenu::AutoManaged(wxCommandEvent& WXUNUSED(event))
{
for (lt::torrent_handle& th : m_state->selected_torrents)
{
lt::torrent_flags_t flags = th.flags();

if ((flags & lt::torrent_flags::auto_managed) == lt::torrent_flags::auto_managed)
{
th.unset_flags(lt::torrent_flags::auto_managed);
}
else
{
th.set_flags(lt::torrent_flags::auto_managed);
}
}
}

void TorrentContextMenu::CopyInfoHash(wxCommandEvent& WXUNUSED(event))
{
std::stringstream ss;
Expand Down Expand Up @@ -200,7 +175,7 @@ void TorrentContextMenu::OpenInExplorer(wxCommandEvent& WXUNUSED(event))
lt::torrent_handle const& th = m_state->selected_torrents.front();
lt::torrent_status ts = th.status();

fs::path savePath = ts.save_path;
fs::path savePath = wxString::FromUTF8(ts.save_path).ToStdWstring();
fs::path path = savePath / ts.name;

Utils::OpenAndSelect(path);
Expand All @@ -210,6 +185,7 @@ void TorrentContextMenu::Pause(wxCommandEvent& WXUNUSED(event))
{
for (lt::torrent_handle& th : m_state->selected_torrents)
{
th.unset_flags(lt::torrent_flags::auto_managed);
th.pause(lt::torrent_handle::graceful_pause);
}
}
Expand All @@ -224,10 +200,21 @@ void TorrentContextMenu::Remove(wxCommandEvent& WXUNUSED(event))
m_state->selected_torrents.clear();
}

void TorrentContextMenu::Resume(wxCommandEvent& WXUNUSED(event))
void TorrentContextMenu::Resume(wxCommandEvent& event)
{
for (lt::torrent_handle& th : m_state->selected_torrents)
{
switch (event.GetId())
{
case ptID_RESUME:
th.set_flags(lt::torrent_flags::auto_managed);
break;
case ptID_RESUME_FORCE:
th.unset_flags(lt::torrent_flags::auto_managed);
break;
}

th.clear_error();
th.resume();
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/picotorrent/torrentcontextmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace pt
enum
{
ptID_RESUME = wxID_HIGHEST + 1,
ptID_RESUME_FORCE,
ptID_PAUSE,
ptID_MOVE,
ptID_REMOVE,
Expand All @@ -34,13 +35,11 @@ namespace pt
ptID_OPEN_IN_EXPLORER,
ptID_FORCE_RECHECK,
ptID_FORCE_REANNOUNCE,
ptID_SEQUENTIAL_DOWNLOAD,
ptID_AUTO_MANAGED
ptID_SEQUENTIAL_DOWNLOAD
};

wxDECLARE_EVENT_TABLE();

void AutoManaged(wxCommandEvent&);
void CopyInfoHash(wxCommandEvent&);
void ForceReannounce(wxCommandEvent&);
void ForceRecheck(wxCommandEvent&);
Expand Down

0 comments on commit 366be86

Please sign in to comment.