Skip to content

Commit

Permalink
Fixed all the issues brought up by @vktr
Browse files Browse the repository at this point in the history
  • Loading branch information
make-42 committed May 13, 2023
1 parent c6a943d commit 28017d9
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 177 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ add_executable(

# Win32 specific stuff
src/picotorrent/ui/win32/openfiledialog

# Theming
src/picotorrent/ui/theming/theming
)

target_compile_definitions(
Expand Down
5 changes: 2 additions & 3 deletions lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
"torrent_file_s": "Torrent file(s)",
"exported_magnet_link_s": "Exported magnet link(s)",
"theme": "Theme",
"light_mode": "Light",
"dark_mode": "Dark",
"system_sets_theme_mode":"System"
"light_theme": "Light",
"follow_system_theme": "System"
}
2 changes: 1 addition & 1 deletion res/dbmigrations/20220508103321_insert_theme_id.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO setting (key, value, default_value)
VALUES ('theme_id', NULL, NULL);
VALUES ('theme_id', NULL, '"system"');
7 changes: 1 addition & 6 deletions src/picotorrent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "ui/mainframe.hpp"
#include "ui/translator.hpp"

#include "ui/theming/theming.hpp"

using json = nlohmann::json;
using pt::Application;

Expand Down Expand Up @@ -112,10 +110,7 @@ bool Application::OnInit()
.value_or(env->GetCurrentLocale()));

// Load theme
pt::UI::Theming &theming = pt::UI::Theming::GetInstance();
theming.LoadThemes();
theming.SetCurrentTheme(cfg->Get<std::string>("theme_id").value_or("system")); // Sets default to 'System'.
if (theming.GetMSWDarkMode())
if (cfg->IsDarkMode())
{
wxApp::MSWEnableDarkMode();
}
Expand Down
29 changes: 29 additions & 0 deletions src/picotorrent/core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "database.hpp"
#include "environment.hpp"

#include <Windows.h>

namespace fs = std::filesystem;

using pt::Core::Configuration;
Expand Down Expand Up @@ -214,3 +216,30 @@ void Configuration::UpsertListenInterface(Configuration::ListenInterface const&
stmt->Execute();
}
}

bool Configuration::IsSystemDarkMode()
{
bool systemUsesDarkTheme = false;
HKEY hKey = 0;
DWORD dwValue = 1;
DWORD dwBufSize = sizeof(dwValue);
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
RegQueryValueEx(hKey, TEXT("AppsUseLightTheme"), NULL, NULL, (LPBYTE)&dwValue, &dwBufSize);
}
if (dwValue == 0)
{
systemUsesDarkTheme = true;
}
return systemUsesDarkTheme;
}

bool Configuration::IsDarkMode()
{
auto val = Configuration::Get<std::string>("theme_id").value_or("system");

if (val == "light"){
return false;
}
return Configuration::IsSystemDarkMode();
}
4 changes: 4 additions & 0 deletions src/picotorrent/core/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ namespace Core

std::vector<DhtBootstrapNode> GetDhtBootstrapNodes();

// Dark mode
bool IsDarkMode();
bool IsSystemDarkMode();

std::vector<Filter> GetFilters();
std::optional<Filter> GetFilterById(int id);

Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ICO_TERMINAL_DARK_THEME ICON "..\\..\\res\\terminal-dark-theme.ico"
20201107234213_setup_filters DBMIGRATION "..\\..\\res\\dbmigrations\\20201107234213_setup_filters.sql"
20201219222232_insert_connections_limit DBMIGRATION "..\\..\\res\\dbmigrations\\20201219222232_insert_connections_limit.sql"
20201227195100_insert_ipfilter_settings DBMIGRATION "..\\..\\res\\dbmigrations\\20201227195100_insert_ipfilter_settings.sql"
20220508103321_insert_theme_id.sql DBMIGRATION "..\\..\\res\\dbmigrations\\20220508103321_insert_theme_id.sql"
20220508103321_insert_theme_id DBMIGRATION "..\\..\\res\\dbmigrations\\20220508103321_insert_theme_id.sql"

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILE_VERSION
Expand Down
8 changes: 4 additions & 4 deletions src/picotorrent/ui/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#include "ids.hpp"
#include "models/torrentlistmodel.hpp"
#include "torrentlistview.hpp"
#include "theming/theming.hpp"
#include "../core/configuration.hpp"

using pt::UI::Console;

wxDEFINE_EVENT(ptEVT_FILTER_CHANGED, wxCommandEvent);

Console::Console(wxWindow* parent, wxWindowID id, pt::UI::Models::TorrentListModel* model)
Console::Console(wxWindow* parent, wxWindowID id, pt::UI::Models::TorrentListModel* model, std::shared_ptr<pt::Core::Configuration> cfg)
: wxPanel(parent, id),
m_input(new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_LEFT | wxTE_PROCESS_ENTER)),
m_model(model)
{
m_input->SetFont(
wxFont(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Consolas")));

wxIcon funnel(pt::UI::Theming::GetInstance().GetMSWDarkMode() ? L"ICO_TERMINAL_DARK_THEME" : L"ICO_TERMINAL", wxBITMAP_TYPE_ICO_RESOURCE, FromDIP(16), FromDIP(16));
wxIcon funnel((cfg -> IsDarkMode()) ? L"ICO_TERMINAL_DARK_THEME" : L"ICO_TERMINAL", wxBITMAP_TYPE_ICO_RESOURCE, FromDIP(16), FromDIP(16));

int i = FromDIP(16);
printf("%d", i);
Expand All @@ -27,7 +27,7 @@ Console::Console(wxWindow* parent, wxWindowID id, pt::UI::Models::TorrentListMod
sizer->Add(new wxStaticBitmap(this, wxID_ANY, funnel), 0, wxALIGN_CENTER | wxLEFT, FromDIP(4));
sizer->Add(m_input, 1, wxEXPAND | wxALL, FromDIP(4));

this->SetBackgroundColour(getBGCol());
this->SetBackgroundColour((cfg -> IsDarkMode()) ? wxColour(32,32,32) : wxColour(255,255,255));
this->SetSizerAndFit(sizer);

this->Bind(
Expand Down
4 changes: 3 additions & 1 deletion src/picotorrent/ui/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <memory>

#include "../core/configuration.hpp"

wxDECLARE_EVENT(ptEVT_FILTER_CHANGED, wxCommandEvent);

namespace pt::UI::Models { class TorrentListModel; }
Expand All @@ -16,7 +18,7 @@ namespace pt::UI
class Console : public wxPanel
{
public:
Console(wxWindow* parent, wxWindowID id, Models::TorrentListModel* model);
Console(wxWindow* parent, wxWindowID id, Models::TorrentListModel* model, std::shared_ptr<pt::Core::Configuration> cfg);
void SetText(std::string const& text);

private:
Expand Down
17 changes: 7 additions & 10 deletions src/picotorrent/ui/dialogs/preferencesgeneralpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "../../core/utils.hpp"
#include "../translator.hpp"

#include "../theming/theming.hpp"

struct AutoRunKey
{
AutoRunKey()
Expand Down Expand Up @@ -149,15 +147,14 @@ PreferencesGeneralPage::PreferencesGeneralPage(wxWindow* parent, std::shared_ptr
m_language->SetSelection(pos);
}
}

for (auto &theme : pt::UI::Theming::GetInstance().GetThemes())

m_theme->Append(i18n("follow_system_theme"), new ClientData<std::string>("system"));
m_theme->Append(i18n("light_theme"), new ClientData<std::string>("light"));
if (m_cfg->Get<std::string>("theme_id").value_or("system") == "light")
{
int pos = m_theme->Append(i18n(theme.i18n_name), new ClientData<std::string>(theme.id));

if (theme.id == Theming::GetInstance().GetCurrentTheme())
{
m_theme->SetSelection(pos);
}
m_theme->SetSelection(1);
} else {
m_theme->SetSelection(0);
}

m_labelColor->SetValue(m_cfg->Get<bool>("use_label_as_list_bgcolor").value());
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 @@ -67,7 +67,7 @@ MainFrame::MainFrame(std::shared_ptr<pt::Core::Environment> env, std::shared_ptr
m_menuItemFilters(nullptr),
m_ipc(std::make_unique<IPC::Server>(this))
{
m_console = new Console(this, wxID_ANY, m_torrentListModel);
m_console = new Console(this, wxID_ANY, m_torrentListModel,m_cfg);

m_splitter->SetWindowStyleFlag(
m_splitter->GetWindowStyleFlag() | wxSP_LIVE_UPDATE);
Expand Down
91 changes: 0 additions & 91 deletions src/picotorrent/ui/theming/theming.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions src/picotorrent/ui/theming/theming.hpp

This file was deleted.

9 changes: 5 additions & 4 deletions src/picotorrent/ui/torrentdetailsoverviewpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../bittorrent/torrenthandle.hpp"
#include "../bittorrent/torrentstatus.hpp"
#include "../core/utils.hpp"
#include "../core/configuration.hpp"
#include "translator.hpp"
#include "widgets/pieceprogressbar.hpp"

Expand Down Expand Up @@ -84,7 +85,7 @@ class CopyableStaticText : public wxStaticText
}
};

TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, int cols, bool showPieceProgress)
TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, std::shared_ptr<pt::Core::Configuration> cfg, int cols, bool showPieceProgress)
: wxScrolledWindow(parent, id),
m_pieceProgress(nullptr),
m_name(new CopyableStaticText(this)),
Expand Down Expand Up @@ -141,7 +142,7 @@ TorrentDetailsOverviewPanel::TorrentDetailsOverviewPanel(wxWindow* parent, wxWin

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

Expand Down Expand Up @@ -243,11 +244,11 @@ void TorrentDetailsOverviewPanel::Reset()
m_totalUpload->SetLabel("-");
}

void TorrentDetailsOverviewPanel::UpdateView(int cols, bool showPieceProgress)
void TorrentDetailsOverviewPanel::UpdateView(int cols, bool showPieceProgress, std::shared_ptr<pt::Core::Configuration> cfg)
{
if (showPieceProgress && m_pieceProgress == nullptr)
{
m_pieceProgress = new Widgets::PieceProgressBar(this, wxID_ANY);
m_pieceProgress = new Widgets::PieceProgressBar(this, wxID_ANY, cfg);
m_mainSizer->Insert(0, m_pieceProgress, 0, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, FromDIP(5));
}
else if (!showPieceProgress && m_pieceProgress != nullptr)
Expand Down
6 changes: 4 additions & 2 deletions 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

#include "../core/configuration.hpp"

class wxFlexGridSizer;

namespace pt::UI::Widgets { class PieceProgressBar; }
Expand All @@ -20,11 +22,11 @@ namespace UI
class TorrentDetailsOverviewPanel : public wxScrolledWindow
{
public:
TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, int cols = 2, bool showPieceProgress = true);
TorrentDetailsOverviewPanel(wxWindow* parent, wxWindowID id, std::shared_ptr<pt::Core::Configuration> cfg,int cols = 2, bool showPieceProgress = true);

void Refresh(BitTorrent::TorrentHandle* torrent);
void Reset();
void UpdateView(int cols, bool showPieceProgress);
void UpdateView(int cols, bool showPieceProgress, std::shared_ptr<pt::Core::Configuration> cfg);

private:
wxFlexGridSizer* m_sizer;
Expand Down
Loading

0 comments on commit 28017d9

Please sign in to comment.