From 77fb65377b739ead68ec5be29d63a67ed6e38229 Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Sun, 7 Nov 2021 08:41:04 +0530 Subject: [PATCH] Add command line option to reset app data, new Paths header, more code refactoring. --- .dir-locals.el | 15 ++-- meson.build | 57 ++++++++++-- src/App.cpp | 60 ++++++++++++- src/GUI/Dialogs/Settings.cpp | 39 ++++---- src/GUI/Dialogs/Settings.hpp | 6 +- src/GUI/Dialogs/TagEditor.cpp | 23 +++-- src/GUI/Dialogs/TagEditor.hpp | 10 ++- src/GUI/MainFrame.cpp | 164 +++++++++++++++++----------------- src/GUI/MainFrame.hpp | 5 +- src/GUI/WaveformViewer.cpp | 9 +- src/GUI/WaveformViewer.hpp | 7 +- src/Utility/Paths.hpp | 29 ++++++ src/Utility/SH_Event.cpp | 16 ++-- src/Utility/SH_Event.hpp | 34 +++---- src/Utility/Serialize.cpp | 54 +++++------ src/Utility/Serialize.hpp | 5 +- 16 files changed, 323 insertions(+), 210 deletions(-) create mode 100644 src/Utility/Paths.hpp diff --git a/.dir-locals.el b/.dir-locals.el index ca29a68..71e329e 100755 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,11 +1,6 @@ ((nil . ((cmake-ide-project-dir . "~/repos/sample-hive") - -(cmake-ide-build-dir . "~/repos/sample-hive/build") - -(cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPORTABLE=1 -DCMAKE_CXX_COMPILER='/usr/bin/g++'") - -(projectile-project-name . "SampleHive") - -(projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive") - -(projectile-project-test-cmd . "./test.sh")))) + (cmake-ide-build-dir . "~/repos/sample-hive/build") + (cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPORTABLE=1 -DCMAKE_CXX_COMPILER='/usr/bin/g++'") + (projectile-project-name . "SampleHive") + (projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive") + (projectile-project-test-cmd . "./test.sh")))) diff --git a/meson.build b/meson.build index 800d740..05687ac 100755 --- a/meson.build +++ b/meson.build @@ -22,23 +22,47 @@ project('SampleHive', version : 'v0.9.0_alpha.1', license : 'GPL v3', meson_version: '>= 0.58.0', - default_options : ['warning_level=1', - 'cpp_std=c++14']) - -meson_src_root = meson.current_source_dir() -meson_build_root = meson.current_build_dir() + default_options : ['warning_level=2', + 'buildtype=debugoptimized', + 'b_lto=true', + 'b_lto_threads=2', + 'cpp_std=gnu++14']) # Create configuration data config_data = configuration_data() # Save project information +meson_src_root = meson.current_source_dir() +meson_build_root = meson.current_build_dir() + project_name = meson.project_name() project_license = meson.project_license() project_version = meson.project_version() +project_author = 'Apoorv' +project_copyright_years = '2020-2021' +project_description = 'A simple, modern audio sample browser/manager for GNU/Linux.' +project_website = 'http://samplehive.gitlab.io/website' -config_data.set_quoted('NAME', project_name) -config_data.set_quoted('LICENSE', project_license) -config_data.set_quoted('VERSION', project_version) +build_type = get_option('buildtype') + +host_sys = host_machine.system() + +cpp_compiler_id = meson.get_compiler('cpp').get_id() +cpp_compiler_version = meson.get_compiler('cpp').version() + +config_data.set_quoted('PROJECT_NAME', project_name) +config_data.set_quoted('PROJECT_LICENSE', project_license) +config_data.set_quoted('PROJECT_VERSION', project_version) +config_data.set_quoted('PROJECT_AUTHOR', project_author) +config_data.set_quoted('PROJECT_COPYRIGHT_YEARS', project_copyright_years) +config_data.set_quoted('PROJECT_DESCRIPTION', project_description) +config_data.set_quoted('PROJECT_WEBSITE', project_website) +config_data.set_quoted('BUILD_TYPE', build_type) +config_data.set_quoted('HOST_MACHINE', host_sys) +config_data.set_quoted('MESON_SRC_ROOT', meson_src_root) +config_data.set_quoted('MESON_BUILD_ROOT', meson_build_root) +config_data.set_quoted('CPP_COMPILER', cpp_compiler_id) +config_data.set_quoted('CPP_COMPILER_VERSION', cpp_compiler_version) # Save important directories prefix = get_option('prefix') @@ -230,8 +254,11 @@ endif summary( { - 'Debug': get_option('debug'), + 'Build type': build_type, 'Optimization': get_option('optimization'), + 'Link time optimization': get_option('b_lto'), + 'Warning level': get_option('warning_level'), + 'Host system': host_sys, }, section: 'General') @@ -244,3 +271,15 @@ summary( 'samplehive_datadir': samplehive_datadir, }, section: 'Directories') + +summary( + { + 'Project name': project_name, + 'Project license': project_license, + 'Project version': project_version, + 'Project author': project_author, + 'Project copyright years': project_copyright_years, + 'Project description': project_description, + 'Project website': project_website, + }, + section: 'Project') diff --git a/src/App.cpp b/src/App.cpp index d8f5cdd..e138687 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -20,21 +20,22 @@ #include "App.hpp" #include "SampleHiveConfig.hpp" +#include "Utility/Paths.hpp" #include "Utility/Log.hpp" #include #include +#include #include #include #include -#define SPLASH_LOGO SAMPLEHIVE_DATADIR "/logo/logo-samplehive_768x432.png" - wxIMPLEMENT_APP(App); App::App() { - + // Initialize the logger + SampleHive::Log::InitLogger("SampleHive"); } App::~App() @@ -74,6 +75,7 @@ void App::OnInitCmdLine(wxCmdLineParser& parser) wxApp::OnInitCmdLine(parser); parser.AddSwitch("v", "version", "Shows the application version", 0); + parser.AddSwitch("r", "reset", "Reset app data", 0); parser.Parse(true); } @@ -84,9 +86,59 @@ bool App::OnCmdLineParsed(wxCmdLineParser& parser) if (parser.Found("version")) { - std::cout << NAME << ' ' << VERSION << std::endl; + std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << std::endl; return false; } + else if (parser.Found("reset")) + { + char ans; + + std::cout << "Are you sure you want reset app data? [y/N] "; + std::cin >> ans; + + if (ans == 'y' || ans == 'Y') + { + if (!wxFileExists(CONFIG_FILEPATH)) + { + SH_LOG_ERROR("Error! File {} doesn't exist.", CONFIG_FILEPATH); + return false; + } + + bool config_is_deleted = wxRemoveFile(CONFIG_FILEPATH); + + if (config_is_deleted) + SH_LOG_INFO("Deleted {}", CONFIG_FILEPATH); + else + SH_LOG_ERROR("Could not delete {}", CONFIG_FILEPATH); + + if (!wxFileExists(DATABASE_FILEPATH)) + { + SH_LOG_ERROR("Error! File {} doesn't exist.", DATABASE_FILEPATH); + return false; + } + + bool db_is_deleted = wxRemoveFile(DATABASE_FILEPATH); + + if (db_is_deleted) + SH_LOG_INFO("Deleted {}", DATABASE_FILEPATH); + else + SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH); + + if (config_is_deleted && db_is_deleted) + SH_LOG_INFO("Successfully cleared app data"); + else + SH_LOG_ERROR("Error! Could not clear app data"); + + return false; + } + else if (ans == 'n' || ans == 'N') + return false; + else + { + SH_LOG_ERROR("Unknown option '{}' please select a correct option", ans); + return false; + } + } return true; } diff --git a/src/GUI/Dialogs/Settings.cpp b/src/GUI/Dialogs/Settings.cpp index cc93c47..87b83f2 100644 --- a/src/GUI/Dialogs/Settings.cpp +++ b/src/GUI/Dialogs/Settings.cpp @@ -22,21 +22,16 @@ #include "Utility/ControlID_Enums.hpp" #include "Utility/Serialize.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" #include #include #include -Settings::Settings(const std::string& configFilepath, const std::string& databaseFilepath) - : m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath) -{ - -} - -Settings::Settings(wxWindow* window, const std::string& configFilepath, const std::string& databaseFilepath) +Settings::Settings(wxWindow *window) : wxDialog(window, wxID_ANY, "Settings", wxDefaultPosition, wxSize(720, 270), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), - m_Window(window), m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath) + m_Window(window) { m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); @@ -52,7 +47,7 @@ Settings::Settings(wxWindow* window, const std::string& configFilepath, const st m_DisplayFontSizer = new wxBoxSizer(wxHORIZONTAL); m_WaveformColourSizer = new wxBoxSizer(wxHORIZONTAL); - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxString fontChoices[] = { "System default" }; @@ -106,13 +101,13 @@ Settings::Settings(wxWindow* window, const std::string& configFilepath, const st m_ConfigLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default configuration file location", wxDefaultPosition, wxDefaultSize); - m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, configFilepath, + m_ConfigText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, CONFIG_FILEPATH, wxDefaultPosition, wxDefaultSize); m_ConfigBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseConfigDir, "Browse", wxDefaultPosition, wxDefaultSize, 0); m_DatabaseLabel = new wxStaticText(m_ConfigurationSettingPanel, wxID_ANY, "Default database location", wxDefaultPosition, wxDefaultSize); - m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, databaseFilepath, + m_DatabaseText = new wxTextCtrl(m_ConfigurationSettingPanel, wxID_ANY, DATABASE_FILEPATH, wxDefaultPosition, wxDefaultSize); m_DatabaseBrowse = new wxButton(m_ConfigurationSettingPanel, SD_BrowseDatabaseDir, "Browse", wxDefaultPosition, wxDefaultSize, 0); @@ -247,7 +242,7 @@ void Settings::OnClickDatabaseBrowse(wxCommandEvent& event) void Settings::OnCheckAutoImport(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (!m_AutoImportCheck->GetValue()) { @@ -271,21 +266,21 @@ void Settings::OnCheckAutoImport(wxCommandEvent& event) void Settings::OnCheckFollowSymLinks(wxCommandEvent& event) { - Serializer serialize(m_ConfigFilepath); + Serializer serializer; - serialize.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue()); + serializer.SerializeFollowSymLink(m_FollowSymLinksCheck->GetValue()); } void Settings::OnCheckShowFileExtension(wxCommandEvent& event) { - Serializer serialize(m_ConfigFilepath); + Serializer serializer; - serialize.SerializeShowFileExtensionSetting(m_ShowFileExtensionCheck->GetValue()); + serializer.SerializeShowFileExtensionSetting(m_ShowFileExtensionCheck->GetValue()); } void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxString initial_dir = wxGetHomeDir(); @@ -344,7 +339,7 @@ void Settings::OnSelectFont(wxCommandEvent& event) void Settings::OnChangeFontSize(wxSpinEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; int font_size = m_FontSize->GetValue(); @@ -364,7 +359,7 @@ void Settings::OnChangeFontSize(wxSpinEvent& event) void Settings::LoadDefaultConfig() { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); wxString system_font = sys_font.GetFaceName(); @@ -414,7 +409,7 @@ void Settings::LoadDefaultConfig() void Settings::SetShowExtension(bool value) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; m_ShowFileExtensionCheck->SetValue(value); serializer.SerializeShowFileExtensionSetting(value); @@ -431,7 +426,7 @@ void Settings::PrintFont() void Settings::SetCustomFont() { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxFont sys_font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); std::string system_font = sys_font.GetFaceName().ToStdString(); @@ -468,7 +463,7 @@ wxString Settings::GetImportDirPath() void Settings::OnChangeWaveformColour(wxColourPickerEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxColour colour = m_WaveformColourPickerCtrl->GetColour(); wxColour wave_colour = serializer.DeserializeWaveformColour(); diff --git a/src/GUI/Dialogs/Settings.hpp b/src/GUI/Dialogs/Settings.hpp index 2e34dc7..4ce7bcb 100644 --- a/src/GUI/Dialogs/Settings.hpp +++ b/src/GUI/Dialogs/Settings.hpp @@ -43,17 +43,13 @@ class Settings : public wxDialog { public: - Settings(const std::string& configFilepath, const std::string& databaseFilepath); - Settings(wxWindow* window, const std::string& configFilepath, const std::string& databaseFilepath); + Settings(wxWindow* window); ~Settings(); private: // ------------------------------------------------------------------- wxWindow* m_Window; - const std::string& m_ConfigFilepath; - const std::string& m_DatabaseFilepath; - private: // ------------------------------------------------------------------- // Top panel for wxDialog diff --git a/src/GUI/Dialogs/TagEditor.cpp b/src/GUI/Dialogs/TagEditor.cpp index 9eb1888..3f5907e 100644 --- a/src/GUI/Dialogs/TagEditor.cpp +++ b/src/GUI/Dialogs/TagEditor.cpp @@ -19,7 +19,9 @@ */ #include "Utility/ControlID_Enums.hpp" +#include "Utility/SH_Event.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" #include "Database/Database.hpp" #include "GUI/Dialogs/TagEditor.hpp" @@ -29,10 +31,10 @@ #include #include -TagEditor::TagEditor(wxWindow* window, const std::string& dbPath, const std::string& filename, wxInfoBar& info_bar) +TagEditor::TagEditor(wxWindow* window, const std::string& filename) : wxDialog(window, wxID_ANY, "Edit tags", wxDefaultPosition, wxSize(640, 360), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP), - m_Window(window), m_DatabaseFilepath(dbPath), m_Filename(filename), m_InfoBar(info_bar), tags(filename) + m_Window(window), m_Filename(filename), tags(filename) { m_Panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); @@ -226,8 +228,7 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event) void TagEditor::OnClickApply(wxCommandEvent& event) { - // Database db(m_InfoBar, m_DatabaseFilepath); - Database db(m_DatabaseFilepath); + Database db(static_cast(DATABASE_FILEPATH)); wxString title = m_TitleText->GetValue(); wxString artist = m_ArtistText->GetValue(); @@ -311,7 +312,19 @@ void TagEditor::OnClickApply(wxCommandEvent& event) info_msg = "Error, cannot change tag!"; } - m_InfoBar.ShowMessage(info_msg, wxICON_INFORMATION); + SendInfoBarMessage(info_msg, wxICON_INFORMATION); +} + +void TagEditor::SendInfoBarMessage(const wxString& msg, int mode) +{ + SH_LOG_INFO("{} called..", __FUNCTION__); + + SampleHive::SH_InfoBarMessageEvent event(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, this->GetId()); + event.SetEventObject(this); + + event.SetInfoBarMessage({ msg, mode }); + + GetParent()->GetEventHandler()->ProcessEvent(event); } TagEditor::~TagEditor() diff --git a/src/GUI/Dialogs/TagEditor.hpp b/src/GUI/Dialogs/TagEditor.hpp index 28c8542..32a8d3d 100644 --- a/src/GUI/Dialogs/TagEditor.hpp +++ b/src/GUI/Dialogs/TagEditor.hpp @@ -39,16 +39,15 @@ class TagEditor : public wxDialog { public: - TagEditor(wxWindow* window, const std::string& dbPath, const std::string& filename, wxInfoBar& info_bar); + TagEditor(wxWindow* window, const std::string& filename); ~TagEditor(); private: // ------------------------------------------------------------------- wxWindow* m_Window; - const std::string m_DatabaseFilepath; - const std::string m_Filename; - wxInfoBar& m_InfoBar; + // ------------------------------------------------------------------- + const std::string m_Filename; private: // ------------------------------------------------------------------- @@ -105,4 +104,7 @@ class TagEditor : public wxDialog // ------------------------------------------------------------------- void OnClickApply(wxCommandEvent& event); + + // ------------------------------------------------------------------- + void SendInfoBarMessage(const wxString& msg, int mode); }; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 3d70e63..65f25a3 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -23,6 +23,7 @@ #include "GUI/Dialogs/TagEditor.hpp" #include "Database/Database.hpp" #include "Utility/ControlID_Enums.hpp" +#include "Utility/Paths.hpp" #include "Utility/Tags.hpp" #include "Utility/Sample.hpp" #include "Utility/Log.hpp" @@ -68,34 +69,8 @@ #include #include -// Path to all the assets -#define ICON_HIVE_16px SAMPLEHIVE_DATADIR "/icons/icon-hive_16x16.png" -#define ICON_HIVE_24px SAMPLEHIVE_DATADIR "/icons/icon-hive_24x24.png" -#define ICON_HIVE_32px SAMPLEHIVE_DATADIR "/icons/icon-hive_32x32.png" -#define ICON_HIVE_64px SAMPLEHIVE_DATADIR "/icons/icon-hive_64x64.png" -#define ICON_HIVE_128px SAMPLEHIVE_DATADIR "/icons/icon-hive_128x128.png" -#define ICON_HIVE_256px SAMPLEHIVE_DATADIR "/icons/icon-hive_256x256.png" -#define ICON_STAR_FILLED_16px SAMPLEHIVE_DATADIR "/icons/icon-star_filled_16x16.png" -#define ICON_STAR_EMPTY_16px SAMPLEHIVE_DATADIR "/icons/icon-star_empty_16x16.png" -#define ICON_PLAY_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-play-dark_16x16.png" -#define ICON_STOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-dark_16x16.png" -#define ICON_AB_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-dark_16x16.png" -#define ICON_LOOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-dark_16x16.png" -#define ICON_MUTE_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-dark_16x16.png" -#define ICON_PLAY_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-play-light_16x16.png" -#define ICON_STOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-light_16x16.png" -#define ICON_AB_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-light_16x16.png" -#define ICON_LOOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-light_16x16.png" -#define ICON_MUTE_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-light_16x16.png" -#define USER_HOME_DIR wxGetUserHome() -#define APP_CONFIG_DIR USER_HOME_DIR + "/.config/SampleHive" -#define APP_DATA_DIR USER_HOME_DIR + "/.local/share/SampleHive" -#define CONFIG_FILEPATH APP_CONFIG_DIR + "/config.yaml" -#define DATABASE_FILEPATH APP_DATA_DIR "/sample.hive" - MainFrame::MainFrame() - : wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition), - m_ConfigFilepath(CONFIG_FILEPATH), m_DatabaseFilepath(DATABASE_FILEPATH) + : wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition) { // Initialize statusbar with 4 sections m_StatusBar = CreateStatusBar(4); @@ -156,9 +131,6 @@ MainFrame::MainFrame() // Set the menu bar to use SetMenuBar(m_MenuBar); - // Initialize the logger - SampleHive::Log::InitLogger("SampleHive"); - // Load default yaml config file. LoadConfigFile(); @@ -430,13 +402,11 @@ MainFrame::MainFrame() m_Timer = new wxTimer(this); // Initialize the database - // m_Database = std::make_unique(*m_InfoBar, m_DatabaseFilepath); - m_Database = std::make_unique(m_DatabaseFilepath); + m_Database = std::make_unique(static_cast(DATABASE_FILEPATH)); m_Database->CreateTableSamples(); m_Database->CreateTableHives(); - m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database, - m_ConfigFilepath, m_DatabaseFilepath); + m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database); // Binding events. Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile); @@ -490,6 +460,7 @@ MainFrame::MainFrame() Bind(SampleHive::SH_EVT_LOOP_POINTS_UPDATED, &MainFrame::OnRecieveLoopPoints, this); Bind(SampleHive::SH_EVT_STATUSBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveStatusBarStatus, this); + Bind(SampleHive::SH_EVT_INFOBAR_MESSAGE_UPDATED, &MainFrame::OnRecieveInfoBarStatus, this); // Adding widgets to their sizers m_MainSizer->Add(m_MainPanel, 1, wxALL | wxEXPAND, 0); @@ -591,7 +562,7 @@ MainFrame::MainFrame() void MainFrame::OnClickSettings(wxCommandEvent& event) { - Settings* settings = new Settings(this, m_ConfigFilepath, m_DatabaseFilepath); + Settings* settings = new Settings(this); switch (settings->ShowModal()) { @@ -615,7 +586,7 @@ void MainFrame::OnClickSettings(wxCommandEvent& event) void MainFrame::AddSamples(wxArrayString& files) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxBusyCursor busy_cursor; wxWindowDisabler window_disabler; @@ -786,7 +757,7 @@ void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event) void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (event.GetNumberOfFiles() > 0) { @@ -1220,7 +1191,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxDataViewItem selected_hive = event.GetItem(); @@ -1617,7 +1588,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) { TagEditor* tagEditor; - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxString msg; @@ -1953,8 +1924,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) break; case MN_EditTagSample: { - tagEditor = new TagEditor(this, static_cast(DATABASE_FILEPATH), - static_cast(sample_path), *m_InfoBar); + tagEditor = new TagEditor(this, static_cast(sample_path)); switch (tagEditor->ShowModal()) { @@ -2056,7 +2026,7 @@ void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event) void MainFrame::LoadDatabase() { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; try { @@ -2083,7 +2053,7 @@ void MainFrame::LoadDatabase() void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxTreeItemId selected_trashed_item = event.GetItem(); @@ -2171,7 +2141,7 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (event.GetNumberOfFiles() > 0) { @@ -2319,7 +2289,7 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event) void MainFrame::OnClickRemoveHive(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxDataViewItem selected_item = m_Hives->GetSelection(); wxString hive_name = m_Hives->GetItemText(selected_item); @@ -2442,7 +2412,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxArrayTreeItemIds selected_item_ids; m_Trash->GetSelections(selected_item_ids); @@ -2507,7 +2477,7 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) void MainFrame::OnDoSearch(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; const auto search = m_SearchBox->GetValue().ToStdString(); @@ -2579,36 +2549,36 @@ void MainFrame::LoadConfigFile() } } - Serializer serialize(m_ConfigFilepath); + Serializer serializer; SH_LOG_INFO("Reading configuration file.."); int height = 600, width = 800; - bAutoplay = serialize.DeserializeBrowserControls("autoplay"); - bLoop = serialize.DeserializeBrowserControls("loop"); - bMuted = serialize.DeserializeBrowserControls("muted"); + bAutoplay = serializer.DeserializeBrowserControls("autoplay"); + bLoop = serializer.DeserializeBrowserControls("loop"); + bMuted = serializer.DeserializeBrowserControls("muted"); - width = serialize.DeserializeWinSize().first; - height = serialize.DeserializeWinSize().second; + width = serializer.DeserializeWinSize().first; + height = serializer.DeserializeWinSize().second; - bShowMenuBar = serialize.DeserializeShowMenuAndStatusBar("menubar"); - bShowStatusBar = serialize.DeserializeShowMenuAndStatusBar("statusbar"); + bShowMenuBar = serializer.DeserializeShowMenuAndStatusBar("menubar"); + bShowStatusBar = serializer.DeserializeShowMenuAndStatusBar("statusbar"); m_ToggleMenuBar->Check(bShowMenuBar); m_MenuBar->Show(bShowMenuBar); m_ToggleStatusBar->Check(bShowStatusBar); m_StatusBar->Show(bShowStatusBar); - m_ToggleExtension->Check(serialize.DeserializeShowFileExtensionSetting()); + m_ToggleExtension->Check(serializer.DeserializeShowFileExtensionSetting()); - this->SetFont(serialize.DeserializeDisplaySettings()); + this->SetFont(serializer.DeserializeDisplaySettings()); this->SetSize(width, height); this->SetMinSize(wxSize(width, height)); this->CenterOnScreen(wxBOTH); this->SetIcon(wxIcon(ICON_HIVE_256px, wxICON_DEFAULT_TYPE, -1, -1)); - this->SetTitle(NAME); - this->SetStatusText(wxString::Format("%s %s", NAME, VERSION), 3); + this->SetTitle(PROJECT_NAME); + this->SetStatusText(wxString::Format("%s %s", PROJECT_NAME, PROJECT_VERSION), 3); this->SetStatusText(_("Stopped"), 1); } @@ -2640,7 +2610,7 @@ bool MainFrame::CreateWatcherIfNecessary() void MainFrame::CreateWatcher() { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxCHECK_RET(!m_FsWatcher, _("Watcher already initialized")); @@ -2658,7 +2628,7 @@ void MainFrame::CreateWatcher() void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (path.empty()) { @@ -2674,6 +2644,12 @@ void MainFrame::AddWatchEntry(wxFSWPathType type, std::string path) wxFileName filename = wxFileName::DirName(path); + if (!filename.IsOk() || !filename.IsDir() || !filename.IsDirReadable()) + { + SH_LOG_ERROR("Error! Something wrong with {} path", filename.GetFullPath()); + return; + } + if (!serializer.DeserializeFollowSymLink()) { filename.DontFollowLink(); @@ -2746,7 +2722,7 @@ void MainFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) FileInfo MainFrame::GetFilenamePathAndExtension(const wxString& selected, bool checkExtension, bool doGetFilename) const { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; wxString path; std::string extension, filename; @@ -2820,7 +2796,7 @@ void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (m_ToggleExtension->IsChecked()) { @@ -2838,7 +2814,7 @@ void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (m_ToggleMenuBar->IsChecked()) { @@ -2862,7 +2838,7 @@ void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; if (m_ToggleStatusBar->IsChecked()) { @@ -2891,7 +2867,7 @@ void MainFrame::OnSelectExit(wxCommandEvent& event) void MainFrame::OnSelectPreferences(wxCommandEvent& event) { - Settings* settings = new Settings(this, m_ConfigFilepath, m_DatabaseFilepath); + Settings* settings = new Settings(this); switch (settings->ShowModal()) { @@ -2918,7 +2894,7 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) wxMessageDialog clearDataDialog(this, wxString::Format(_("Warning! This will delete configuration file " "\"%s\" and database file \"%s\" permanently, " "are you sure you want to delete these files?"), - m_ConfigFilepath, m_DatabaseFilepath), + CONFIG_FILEPATH, DATABASE_FILEPATH), _("Clear app data?"), wxYES_NO | wxNO_DEFAULT | wxCENTRE, wxDefaultPosition); @@ -2931,19 +2907,31 @@ void MainFrame::OnSelectResetAppData(wxCommandEvent& event) if (remove) { - bool config_is_deleted = wxRemoveFile(m_ConfigFilepath); + if (!wxFileExists(CONFIG_FILEPATH)) + { + SH_LOG_ERROR("Error! File {} doesn't exist.", CONFIG_FILEPATH); + return; + } + + bool config_is_deleted = wxRemoveFile(CONFIG_FILEPATH); if (config_is_deleted) - SH_LOG_INFO("Deleted {}", m_ConfigFilepath); + SH_LOG_INFO("Deleted {}", CONFIG_FILEPATH); else - SH_LOG_ERROR("Could not delete {}", m_ConfigFilepath); + SH_LOG_ERROR("Could not delete {}", CONFIG_FILEPATH); - bool db_is_deleted = wxRemoveFile(m_DatabaseFilepath); + if (!wxFileExists(DATABASE_FILEPATH)) + { + SH_LOG_ERROR("Error! File {} doesn't exist.", DATABASE_FILEPATH); + return; + } + + bool db_is_deleted = wxRemoveFile(DATABASE_FILEPATH); if (db_is_deleted) - SH_LOG_INFO("Deleted {}", m_DatabaseFilepath); + SH_LOG_INFO("Deleted {}", DATABASE_FILEPATH); else - SH_LOG_ERROR("Could not delete {}", m_DatabaseFilepath); + SH_LOG_ERROR("Could not delete {}", DATABASE_FILEPATH); if (config_is_deleted && db_is_deleted) m_InfoBar->ShowMessage(_("Successfully cleared app data"), wxICON_INFORMATION); @@ -2963,17 +2951,17 @@ void MainFrame::OnSelectAbout(wxCommandEvent& event) { wxAboutDialogInfo aboutInfo; - aboutInfo.SetName(NAME); + aboutInfo.SetName(PROJECT_NAME); aboutInfo.SetIcon(wxIcon(ICON_HIVE_64px)); - aboutInfo.AddArtist("Apoorv"); - aboutInfo.SetVersion(VERSION, _("Version 0.9.0_alpha.1")); - aboutInfo.SetDescription(_("A simple, modern audio sample browser/manager for GNU/Linux.")); - aboutInfo.SetCopyright("(C) 2020-2021"); - aboutInfo.SetWebSite("http://samplehive.gitlab.io"); - aboutInfo.AddDeveloper("Apoorv"); + aboutInfo.AddArtist(PROJECT_AUTHOR); + aboutInfo.SetVersion(PROJECT_VERSION, _("Version 0.9.0_alpha.1")); + aboutInfo.SetDescription(_(PROJECT_DESCRIPTION)); + aboutInfo.SetCopyright("(C)" PROJECT_COPYRIGHT_YEARS); + aboutInfo.SetWebSite(PROJECT_WEBSITE); + aboutInfo.AddDeveloper(PROJECT_AUTHOR); aboutInfo.SetLicence(wxString::Format(wxString::FromAscii( "%s %s\n" - "Copyright (C) 2021 Apoorv Singh\n" + "Copyright (C) %s Apoorv Singh\n" "\n" "%s is free software: you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" @@ -2987,7 +2975,8 @@ void MainFrame::OnSelectAbout(wxCommandEvent& event) "\n" "You should have received a copy of the GNU General Public License\n" "along with this program. If not, see .\n" - ), NAME, VERSION, NAME, NAME)); + ), PROJECT_NAME, PROJECT_VERSION, PROJECT_COPYRIGHT_YEARS, + PROJECT_NAME, PROJECT_NAME)); wxAboutBox(aboutInfo); } @@ -3038,6 +3027,17 @@ void MainFrame::OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& e m_StatusBar->PushStatusText(status.first, status.second); } +void MainFrame::OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event) +{ + SH_LOG_INFO("{} called..", __FUNCTION__); + + std::pair info = event.GetInfoBarMessage(); + + m_InfoBar->ShowMessage(info.first, info.second); + + SH_LOG_INFO("{} event processed", __FUNCTION__); +} + void MainFrame::ClearLoopPoints() { m_LoopA = 0; diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index 9797d13..c7311c5 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -197,10 +197,6 @@ class MainFrame : public wxFrame bool bShowStatusBar = false; bool bLoopPointsSet = false; - // ------------------------------------------------------------------- - const std::string m_ConfigFilepath; - const std::string m_DatabaseFilepath; - private: // ------------------------------------------------------------------- // Top panel control handlers @@ -278,6 +274,7 @@ class MainFrame : public wxFrame // ------------------------------------------------------------------- void OnRecieveLoopPoints(SampleHive::SH_LoopPointsEvent& event); void OnRecieveStatusBarStatus(SampleHive::SH_StatusBarMessageEvent& event); + void OnRecieveInfoBarStatus(SampleHive::SH_InfoBarMessageEvent& event); // ------------------------------------------------------------------- void LoadDatabase(); diff --git a/src/GUI/WaveformViewer.cpp b/src/GUI/WaveformViewer.cpp index 41199e8..17ae61f 100644 --- a/src/GUI/WaveformViewer.cpp +++ b/src/GUI/WaveformViewer.cpp @@ -23,6 +23,7 @@ #include "Utility/Tags.hpp" #include "Utility/SH_Event.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" #include @@ -37,12 +38,10 @@ #include WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database, - const std::string& configFilepath, const std::string& databaseFilepath) + wxMediaCtrl& mediaCtrl, Database& database) : wxPanel(window, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE), - m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl), - m_ConfigFilepath(configFilepath), m_DatabaseFilepath(databaseFilepath) + m_Window(window), m_Database(database), m_Library(library), m_MediaCtrl(mediaCtrl) { this->SetDoubleBuffered(true); @@ -148,7 +147,7 @@ void WaveformViewer::RenderPlayhead(wxDC& dc) void WaveformViewer::UpdateWaveformBitmap() { - Serializer serializer(m_ConfigFilepath); + Serializer serializer; int selected_row = m_Library.GetSelectedRow(); diff --git a/src/GUI/WaveformViewer.hpp b/src/GUI/WaveformViewer.hpp index 382e9b5..dd3e5bf 100644 --- a/src/GUI/WaveformViewer.hpp +++ b/src/GUI/WaveformViewer.hpp @@ -39,21 +39,18 @@ class WaveformViewer : public wxPanel { public: WaveformViewer(wxWindow* window, wxDataViewListCtrl& library, - wxMediaCtrl& mediaCtrl, Database& database, - const std::string& configFilepath, const std::string& databaseFilepath); + wxMediaCtrl& mediaCtrl, Database& database); ~WaveformViewer(); private: // ------------------------------------------------------------------- wxWindow* m_Window; + // ------------------------------------------------------------------- Database& m_Database; wxDataViewListCtrl& m_Library; wxMediaCtrl& m_MediaCtrl; - const std::string& m_ConfigFilepath; - const std::string& m_DatabaseFilepath; - private: // ------------------------------------------------------------------- wxBitmap m_WaveformBitmap; diff --git a/src/Utility/Paths.hpp b/src/Utility/Paths.hpp new file mode 100644 index 0000000..2b72df7 --- /dev/null +++ b/src/Utility/Paths.hpp @@ -0,0 +1,29 @@ +#pragma once + +// Path to all the assets +#define ICON_HIVE_16px SAMPLEHIVE_DATADIR "/icons/icon-hive_16x16.png" +#define ICON_HIVE_24px SAMPLEHIVE_DATADIR "/icons/icon-hive_24x24.png" +#define ICON_HIVE_32px SAMPLEHIVE_DATADIR "/icons/icon-hive_32x32.png" +#define ICON_HIVE_64px SAMPLEHIVE_DATADIR "/icons/icon-hive_64x64.png" +#define ICON_HIVE_128px SAMPLEHIVE_DATADIR "/icons/icon-hive_128x128.png" +#define ICON_HIVE_256px SAMPLEHIVE_DATADIR "/icons/icon-hive_256x256.png" +#define ICON_STAR_FILLED_16px SAMPLEHIVE_DATADIR "/icons/icon-star_filled_16x16.png" +#define ICON_STAR_EMPTY_16px SAMPLEHIVE_DATADIR "/icons/icon-star_empty_16x16.png" +#define ICON_PLAY_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-play-dark_16x16.png" +#define ICON_STOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-dark_16x16.png" +#define ICON_AB_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-dark_16x16.png" +#define ICON_LOOP_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-dark_16x16.png" +#define ICON_MUTE_DARK_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-dark_16x16.png" +#define ICON_PLAY_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-play-light_16x16.png" +#define ICON_STOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-stop-light_16x16.png" +#define ICON_AB_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-ab-light_16x16.png" +#define ICON_LOOP_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-loop-light_16x16.png" +#define ICON_MUTE_LIGHT_16px SAMPLEHIVE_DATADIR "/icons/icon-mute-light_16x16.png" +#define SPLASH_LOGO SAMPLEHIVE_DATADIR "/logo/logo-samplehive_768x432.png" + +// Path to useful directories and files +#define USER_HOME_DIR wxGetUserHome() +#define APP_CONFIG_DIR USER_HOME_DIR + "/.config/SampleHive" +#define APP_DATA_DIR USER_HOME_DIR + "/.local/share/SampleHive" +#define CONFIG_FILEPATH APP_CONFIG_DIR + "/config.yaml" +#define DATABASE_FILEPATH APP_DATA_DIR "/sample.hive" diff --git a/src/Utility/SH_Event.cpp b/src/Utility/SH_Event.cpp index 0513ab4..463e19b 100644 --- a/src/Utility/SH_Event.cpp +++ b/src/Utility/SH_Event.cpp @@ -74,18 +74,18 @@ namespace SampleHive wxDEFINE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); - // SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) - // : wxCommandEvent(eventType, winId) - // { + SH_InfoBarMessageEvent::SH_InfoBarMessageEvent(wxEventType eventType, int winId) + : wxCommandEvent(eventType, winId) + { - // } + } - // SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent() - // { + SH_InfoBarMessageEvent::~SH_InfoBarMessageEvent() + { - // } + } - // wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); + wxDEFINE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); // SH_TimerEvent::SH_TimerEvent(wxEventType eventType, int winId) // : wxCommandEvent(eventType, winId) diff --git a/src/Utility/SH_Event.hpp b/src/Utility/SH_Event.hpp index 3061a63..d8eb27e 100644 --- a/src/Utility/SH_Event.hpp +++ b/src/Utility/SH_Event.hpp @@ -95,7 +95,8 @@ namespace SampleHive public: std::pair GetMessageAndSection() const { return { m_Msg, m_Section }; } - void SetMessageAndSection(std::pair status) { m_Msg = status.first; m_Section = status.second; } + void SetMessageAndSection(std::pair status) + { m_Msg = status.first; m_Section = status.second; } private: wxString m_Msg; @@ -104,25 +105,26 @@ namespace SampleHive wxDECLARE_EVENT(SH_EVT_STATUSBAR_MESSAGE_UPDATED, SH_StatusBarMessageEvent); - // class SH_InfoBarMessageEvent : public wxCommandEvent - // { - // public: - // SH_InfoBarMessageEvent(wxEventType eventType, int winId); - // ~SH_InfoBarMessageEvent(); + class SH_InfoBarMessageEvent : public wxCommandEvent + { + public: + SH_InfoBarMessageEvent(wxEventType eventType, int winId); + ~SH_InfoBarMessageEvent(); - // public: - // virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); } + public: + virtual wxEvent* Clone() const { return new SH_InfoBarMessageEvent(*this); } - // public: - // std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } - // void SetInfoBarMessage(std::pair infoBarMessageEvent) { m_Msg = infoBarMessageEvent.first; m_Mode = infoBarMessageEvent.second; } + public: + std::pair GetInfoBarMessage() const { return { m_Msg, m_Mode }; } + void SetInfoBarMessage(std::pair info) + { m_Msg = info.first; m_Mode = info.second; } - // private: - // wxString m_Msg; - // int m_Mode; - // }; + private: + wxString m_Msg; + int m_Mode; + }; - // wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); + wxDECLARE_EVENT(SH_EVT_INFOBAR_MESSAGE_UPDATED, SH_InfoBarMessageEvent); // class SH_TimerEvent : public wxCommandEvent // { diff --git a/src/Utility/Serialize.cpp b/src/Utility/Serialize.cpp index 0c49e6e..fc5eaf4 100644 --- a/src/Utility/Serialize.cpp +++ b/src/Utility/Serialize.cpp @@ -20,6 +20,7 @@ #include "Utility/Serialize.hpp" #include "Utility/Log.hpp" +#include "Utility/Paths.hpp" #include #include @@ -30,10 +31,9 @@ #include #include -Serializer::Serializer(const std::string& filepath) - : m_Filepath(filepath) +Serializer::Serializer() { - std::ifstream ifstrm(m_Filepath); + std::ifstream ifstrm(static_cast(CONFIG_FILEPATH)); wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT); std::string system_font_face = font.GetFaceName().ToStdString(); @@ -94,10 +94,10 @@ Serializer::Serializer(const std::string& filepath) m_Emitter << YAML::EndMap; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(CONFIG_FILEPATH); ofstrm << m_Emitter.c_str(); - SH_LOG_INFO("Generated {} successfully!", m_Filepath); + SH_LOG_INFO("Generated {} successfully!", CONFIG_FILEPATH); } } @@ -112,7 +112,7 @@ WindowSize Serializer::DeserializeWinSize() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (!config["Window"]) { @@ -141,7 +141,7 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto bar = config["Window"]) { @@ -153,7 +153,7 @@ void Serializer::SerializeShowMenuAndStatusBar(std::string key, bool value) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -171,7 +171,7 @@ bool Serializer::DeserializeShowMenuAndStatusBar(std::string key) const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto bar = config["Window"]) { @@ -200,7 +200,7 @@ void Serializer::SerializeBrowserControls(std::string key, bool value) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto media = config["Media"]) { @@ -215,7 +215,7 @@ void Serializer::SerializeBrowserControls(std::string key, bool value) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -233,7 +233,7 @@ bool Serializer::DeserializeBrowserControls(std::string key) const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto media = config["Media"]) { @@ -268,7 +268,7 @@ void Serializer::SerializeDisplaySettings(wxFont& font) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); auto display = config["Display"]; @@ -279,7 +279,7 @@ void Serializer::SerializeDisplaySettings(wxFont& font) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -302,7 +302,7 @@ wxFont Serializer::DeserializeDisplaySettings() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); auto display = config["Display"]; @@ -335,7 +335,7 @@ void Serializer::SerializeWaveformColour(wxColour& colour) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); auto display = config["Display"]; @@ -345,7 +345,7 @@ void Serializer::SerializeWaveformColour(wxColour& colour) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -365,7 +365,7 @@ wxColour Serializer::DeserializeWaveformColour() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); auto display = config["Display"]; @@ -392,7 +392,7 @@ void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string& try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto autoImportInfo = config["Collection"]) { @@ -401,7 +401,7 @@ void Serializer::SerializeAutoImportSettings(bool autoImport, const std::string& out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -422,7 +422,7 @@ ImportDirInfo Serializer::DeserializeAutoImportSettings() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto autoImportInfo = config["Collection"]) { @@ -448,7 +448,7 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto followSymLinks = config["Collection"]) { @@ -456,7 +456,7 @@ void Serializer::SerializeFollowSymLink(bool followSymLinks) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -476,7 +476,7 @@ bool Serializer::DeserializeFollowSymLink() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto followSymLinks = config["Collection"]) { @@ -501,7 +501,7 @@ void Serializer::SerializeShowFileExtensionSetting(bool showExtension) try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto fileExtensionInfo = config["Collection"]) { @@ -509,7 +509,7 @@ void Serializer::SerializeShowFileExtensionSetting(bool showExtension) out << config; - std::ofstream ofstrm(m_Filepath); + std::ofstream ofstrm(static_cast(CONFIG_FILEPATH)); ofstrm << out.c_str(); } else @@ -529,7 +529,7 @@ bool Serializer::DeserializeShowFileExtensionSetting() const try { - YAML::Node config = YAML::LoadFile(m_Filepath); + YAML::Node config = YAML::LoadFile(static_cast(CONFIG_FILEPATH)); if (auto fileExtensionInfo = config["Collection"]) { diff --git a/src/Utility/Serialize.hpp b/src/Utility/Serialize.hpp index f0459fc..8a9f701 100644 --- a/src/Utility/Serialize.hpp +++ b/src/Utility/Serialize.hpp @@ -45,13 +45,10 @@ typedef std::pair ImportDirInfo; class Serializer { public: - Serializer(const std::string& filepath); + Serializer(); ~Serializer(); private: - // ------------------------------------------------------------------- - const std::string& m_Filepath; - // ------------------------------------------------------------------- YAML::Emitter m_Emitter;