Skip to content

Commit

Permalink
Merge pull request #965 from vktr/feature/label-save-path
Browse files Browse the repository at this point in the history
Fix setting save path, Unicode issues
  • Loading branch information
vktr committed Oct 8, 2020
2 parents 8ca3826 + 4d3caac commit bead438
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
33 changes: 26 additions & 7 deletions src/picotorrent/ui/dialogs/addtorrentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../../core/configuration.hpp"
#include "../../core/database.hpp"
#include "../../core/utils.hpp"
#include "../clientdata.hpp"
#include "../models/filestoragemodel.hpp"
#include "../translator.hpp"

Expand Down Expand Up @@ -132,7 +133,12 @@ AddTorrentDialog::AddTorrentDialog(wxWindow* parent, wxWindowID id, std::vector<
this->SetMinSize(FromDIP(wxSize(400, 450)));

// Load labels
m_torrentLabel->Append(i18n("none"), wxNullBitmap, reinterpret_cast<void*>(-1));
Core::Configuration::Label lbl;
lbl.id = -1;
lbl.savePath = m_cfg->Get<std::string>("default_save_path").value();
lbl.savePathEnabled = true;

m_torrentLabel->Append(i18n("none"), wxNullBitmap, new ClientData<Core::Configuration::Label>(lbl));

for (auto const& label : cfg->GetLabels())
{
Expand All @@ -150,7 +156,10 @@ AddTorrentDialog::AddTorrentDialog(wxWindow* parent, wxWindowID id, std::vector<
}
}

m_torrentLabel->Append(label.name, bmp, reinterpret_cast<void*>(label.id));
m_torrentLabel->Append(
Utils::toStdWString(label.name),
bmp,
new ClientData<Core::Configuration::Label>(label));
}

// Load save path history
Expand Down Expand Up @@ -181,8 +190,17 @@ AddTorrentDialog::AddTorrentDialog(wxWindow* parent, wxWindowID id, std::vector<
{
int idx = m_torrents->GetSelection();
lt::add_torrent_params& params = m_params.at(idx);
int labelId = reinterpret_cast<int>(m_torrentLabel->GetClientData(m_torrentLabel->GetSelection()));
params.userdata.get<BitTorrent::AddParams>()->labelId = labelId;
auto label = reinterpret_cast<ClientData<Core::Configuration::Label>*>(m_torrentLabel->GetClientObject(m_torrentLabel->GetSelection()));

if (m_manualSavePath.find(params.info_hashes) == m_manualSavePath.end()
&& label->GetValue().savePathEnabled
&& !label->GetValue().savePath.empty())
{
params.save_path = label->GetValue().savePath;
m_torrentSavePath->ChangeValue(Utils::toStdWString(params.save_path));
}

params.userdata.get<BitTorrent::AddParams>()->labelId = label->GetValue().id;
},
ptID_LABEL_COMBO);

Expand Down Expand Up @@ -212,6 +230,7 @@ AddTorrentDialog::AddTorrentDialog(wxWindow* parent, wxWindowID id, std::vector<
int idx = m_torrents->GetSelection();
lt::add_torrent_params& params = m_params.at(idx);
params.save_path = Utils::toStdString(m_torrentSavePath->GetValue().wc_str());
m_manualSavePath.insert(params.info_hashes);
},
ptID_SAVE_PATH_INPUT);

Expand Down Expand Up @@ -372,7 +391,7 @@ void AddTorrentDialog::Load(size_t index)
m_torrentComment->SetLabel(this->GetTorrentDisplayComment(params));

// Save path
m_torrentSavePath->SetValue(wxString::FromUTF8(params.save_path));
m_torrentSavePath->ChangeValue(wxString::FromUTF8(params.save_path));

m_sequentialDownload->SetValue(
(params.flags & lt::torrent_flags::sequential_download) == lt::torrent_flags::sequential_download);
Expand Down Expand Up @@ -401,9 +420,9 @@ void AddTorrentDialog::Load(size_t index)
m_torrentLabel->SetSelection(0);
for (uint32_t i = 0; i < m_torrentLabel->GetCount(); i++)
{
int labelId = reinterpret_cast<int>(m_torrentLabel->GetClientData(i));
auto label = reinterpret_cast<ClientData<Core::Configuration::Label>*>(m_torrentLabel->GetClientObject(i));

if (labelId == params.userdata.get<BitTorrent::AddParams>()->labelId)
if (label->GetValue().id == params.userdata.get<BitTorrent::AddParams>()->labelId)
{
// yup
m_torrentLabel->SetSelection(i);
Expand Down
2 changes: 2 additions & 0 deletions src/picotorrent/ui/dialogs/addtorrentdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <libtorrent/fwd.hpp>
#include <libtorrent/info_hash.hpp>
#include <memory>
#include <set>
#include <vector>

class wxBitmapComboBox;
Expand Down Expand Up @@ -85,6 +86,7 @@ namespace Dialogs
std::shared_ptr<Core::Configuration> m_cfg;
std::shared_ptr<Core::Database> m_db;
std::vector<libtorrent::add_torrent_params> m_params;
std::set<libtorrent::info_hash_t> m_manualSavePath;
};
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/picotorrent/ui/dialogs/preferenceslabelspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../clientdata.hpp"
#include "../../core/configuration.hpp"
#include "../../core/utils.hpp"
#include "../translator.hpp"

using pt::Core::Configuration;
Expand Down Expand Up @@ -123,7 +124,7 @@ PreferencesLabelsPage::PreferencesLabelsPage(wxWindow* parent, std::shared_ptr<C
m_labelsList->GetItemData(
m_labelsList->GetFirstSelected()));

m_name->SetValue(label->name);
m_name->SetValue(Utils::toStdWString(label->name));

m_colorEnabled->SetValue(label->colorEnabled);

Expand All @@ -133,7 +134,7 @@ PreferencesLabelsPage::PreferencesLabelsPage(wxWindow* parent, std::shared_ptr<C
}

m_savePath->Enable(label->savePathEnabled);
m_savePath->SetPath(label->savePath);
m_savePath->SetPath(Utils::toStdWString(label->savePath));
m_savePathEnabled->SetValue(label->savePathEnabled);

m_applyFilter->Enable(label->applyFilterEnabled);
Expand All @@ -156,8 +157,8 @@ PreferencesLabelsPage::PreferencesLabelsPage(wxWindow* parent, std::shared_ptr<C
long sel = m_labelsList->GetFirstSelected();
if (sel < 0) { return; }
auto label = reinterpret_cast<Configuration::Label*>(m_labelsList->GetItemData(sel));
label->name = m_name->GetValue();
m_labelsList->SetItemText(sel, label->name);
label->name = Utils::toStdString(m_name->GetValue().wc_str());
m_labelsList->SetItemText(sel, Utils::toStdWString(label->name));
});

m_colorEnabled->Bind(
Expand Down Expand Up @@ -199,7 +200,7 @@ PreferencesLabelsPage::PreferencesLabelsPage(wxWindow* parent, std::shared_ptr<C
long sel = m_labelsList->GetFirstSelected();
if (sel < 0) { return; }
auto label = reinterpret_cast<Configuration::Label*>(m_labelsList->GetItemData(sel));
label->savePath = m_savePath->GetPath();
label->savePath = Utils::toStdString(m_savePath->GetPath().wc_str());
});

m_applyFilter->Bind(
Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/ui/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void MainFrame::CreateLabelMenuItems()

for (auto const& label : m_cfg->GetLabels())
{
m_labelsMenu->AppendRadioItem(ptID_EVT_LABELS_USER + label.id, label.name);
m_labelsMenu->AppendRadioItem(ptID_EVT_LABELS_USER + label.id, Utils::toStdWString(label.name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/ui/torrentcontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TorrentContextMenu::TorrentContextMenu(wxWindow* parent, std::shared_ptr<Core::C

for (auto const& label : labels)
{
labelsMenu->AppendRadioItem(ptID_LABELS_USER + label.id, label.name)
labelsMenu->AppendRadioItem(ptID_LABELS_USER + label.id, Utils::toStdWString(label.name))
->Check(
selectedTorrents.size() == 1
&& selectedTorrents.at(0)->Label() == label.id);
Expand Down

0 comments on commit bead438

Please sign in to comment.