From fa476d57fd885a16711aa08979c408f27e372d05 Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Wed, 14 Jul 2021 03:22:37 +0530 Subject: [PATCH] Add menubar, statusbar and about dialog, also fixed layout of some widgets. --- src/ControlID_Enums.hpp | 8 + src/Database.cpp | 57 +++---- src/Database.hpp | 12 +- src/MainFrame.cpp | 333 +++++++++++++++++++++++++++++++++++----- src/MainFrame.hpp | 51 +++++- 5 files changed, 391 insertions(+), 70 deletions(-) diff --git a/src/ControlID_Enums.hpp b/src/ControlID_Enums.hpp index 348894e..433b838 100644 --- a/src/ControlID_Enums.hpp +++ b/src/ControlID_Enums.hpp @@ -40,6 +40,14 @@ enum ControlIDs SD_FontSize, SD_FontBrowseButton, + // ------------------------------------------------------------------- + // App Menu items + MN_AddFile, + MN_AddDirectory, + MN_ToggleExtension, + MN_ToggleMenuBar, + MN_ToggleStatusBar, + // ------------------------------------------------------------------- // Library Menu items MN_FavoriteSample, diff --git a/src/Database.cpp b/src/Database.cpp index ec61660..788a9bc 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -832,10 +832,10 @@ std::string Database::GetSampleFileExtension(const std::string& filename) wxVector> Database::LoadSamplesDatabase(wxVector>& vecSet, - // wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item, - wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item, - wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, - bool show_extension) + // wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item, + wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item, + wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_empty) { try { @@ -881,14 +881,14 @@ Database::LoadSamplesDatabase(wxVector>& vecSet, } else { - wxVariant icon_c, icon_gs; - icon_c = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16.png")); - icon_gs = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16-gs.png")); + wxVariant icon_filled, icon_empty; + icon_filled = wxVariant(wxBitmap(icon_star_filled)); + icon_empty = wxVariant(wxBitmap(icon_star_empty)); if (favorite == 1) { // vec.push_back(true); - vec.push_back(icon_c); + vec.push_back(icon_filled); wxLogDebug("Loading hives.."); @@ -943,7 +943,7 @@ Database::LoadSamplesDatabase(wxVector>& vecSet, } else // vec.push_back(false); - vec.push_back(icon_gs); + vec.push_back(icon_empty); if (show_extension) { @@ -990,7 +990,8 @@ Database::LoadSamplesDatabase(wxVector>& vecSet, wxVector> Database::FilterDatabaseBySampleName(wxVector>& sampleVec, - const std::string& sampleName, bool show_extension) + const std::string& sampleName, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_empty) { try { @@ -1027,14 +1028,14 @@ Database::FilterDatabaseBySampleName(wxVector>& sampleVec, wxVector vec; - wxVariant icon_c, icon_gs; - icon_c = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16.png")); - icon_gs = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16-gs.png")); + wxVariant icon_filled, icon_empty; + icon_filled = wxVariant(wxBitmap(icon_star_filled)); + icon_empty = wxVariant(wxBitmap(icon_star_empty)); if (favorite == 1) - vec.push_back(icon_c); + vec.push_back(icon_filled); else - vec.push_back(icon_gs); + vec.push_back(icon_empty); // if (favorite == 1) // vec.push_back(true); @@ -1087,7 +1088,8 @@ Database::FilterDatabaseBySampleName(wxVector>& sampleVec, wxVector> Database::FilterDatabaseByHiveName(wxVector>& sampleVec, - const std::string& hiveName, bool show_extension) + const std::string& hiveName, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_empty) { try { @@ -1124,14 +1126,14 @@ Database::FilterDatabaseByHiveName(wxVector>& sampleVec, wxVector vec; - wxVariant icon_c, icon_gs; - icon_c = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16.png")); - icon_gs = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16-gs.png")); + wxVariant icon_filled, icon_empty; + icon_filled = wxVariant(wxBitmap(icon_star_filled)); + icon_empty = wxVariant(wxBitmap(icon_star_empty)); if (favorite == 1) - vec.push_back(icon_c); + vec.push_back(icon_filled); else - vec.push_back(icon_gs); + vec.push_back(icon_empty); // if (favorite == 1) // vec.push_back(true); @@ -1352,7 +1354,8 @@ void Database::UpdateTrashColumn(const std::string& filename, int value) wxVector> Database::RestoreFromTrashByFilename(const std::string& filename, wxVector>& vecSet, - bool show_extension) + bool show_extension, const std::string& icon_star_filled, + const std::string& icon_star_empty) { try { @@ -1389,16 +1392,16 @@ Database::RestoreFromTrashByFilename(const std::string& filename, wxVector vec; - wxVariant icon_c, icon_gs; - icon_c = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16.png")); - icon_gs = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16-gs.png")); + wxVariant icon_filled, icon_empty; + icon_filled = wxVariant(wxBitmap(icon_star_filled)); + icon_empty = wxVariant(wxBitmap(icon_star_empty)); if (trashed == 0) { if (favorite == 1) - vec.push_back(icon_c); + vec.push_back(icon_filled); else - vec.push_back(icon_gs); + vec.push_back(icon_empty); if (show_extension) vec.push_back(path.AfterLast('/')); diff --git a/src/Database.hpp b/src/Database.hpp index 94c02be..ee8b6f3 100644 --- a/src/Database.hpp +++ b/src/Database.hpp @@ -74,15 +74,19 @@ class Database // wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension); LoadSamplesDatabase(wxVector>& vecSet, wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item, - wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension); + wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_emtpy); void LoadHivesDatabase(wxDataViewTreeCtrl& favorite_tree); wxVector> RestoreFromTrashByFilename(const std::string& filename, wxVector>& vecSet, - bool show_extension); + bool show_extension, const std::string& icon_star_filled, + const std::string& icon_star_empty); wxVector> FilterDatabaseBySampleName(wxVector>& sampleVec, - const std::string& sampleName, bool show_extension); + const std::string& sampleName, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_empty); wxVector> FilterDatabaseByHiveName(wxVector>& sampleVec, - const std::string& hiveName, bool show_extension); + const std::string& hiveName, bool show_extension, + const std::string& icon_star_filled, const std::string& icon_star_empty); }; diff --git a/src/MainFrame.cpp b/src/MainFrame.cpp index 486f416..fecbdc6 100644 --- a/src/MainFrame.cpp +++ b/src/MainFrame.cpp @@ -3,8 +3,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -12,7 +14,9 @@ #include #include #include +#include #include +// #include #include #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include "MainFrame.hpp" #include "ControlID_Enums.hpp" @@ -41,16 +46,73 @@ #include "Sample.hpp" #include "Serialize.hpp" -#include - -#define ICON_APP "../assets/icons/icon-hive_24x24.png" -#define ICON_COLOURED "../assets/icons/icon-hive_16x16.png" -#define ICON_GREYSCALE "../assets/icons/icon-hive_16x16-gs.png" +// Path to all the assets +#define ICON_HIVE_16px "../assets/icons/icon-hive_16x16.png" +#define ICON_HIVE_24px "../assets/icons/icon-hive_24x24.png" +#define ICON_HIVE_32px "../assets/icons/icon-hive_32x32.png" +#define ICON_HIVE_64px "../assets/icons/icon-hive_64x64.png" +#define ICON_HIVE_200px "../assets/icons/icon-hive_200x200.png" +#define ICON_STAR_FILLED_16px "../assets/icons/icon-star_filled_16x16.png" +#define ICON_STAR_EMPTY_16px "../assets/icons/icon-star_empty_16x16.png" MainFrame::MainFrame() : wxFrame(NULL, wxID_ANY, "Sample Hive", wxDefaultPosition), m_ConfigFilepath("config.yaml"), m_DatabaseFilepath("sample.hive") { + m_StatusBar = CreateStatusBar(4); + + int status_width[4] = { 300, -6, 30, -1 }; + m_StatusBar->SetStatusWidths(4, status_width); + + m_HiveBitmap = new wxStaticBitmap(m_StatusBar, wxID_ANY, wxBitmap(ICON_HIVE_24px)); + + // Initialize menubar and menus + m_MenuBar = new wxMenuBar(); + m_FileMenu = new wxMenu(); + m_EditMenu = new wxMenu(); + m_ViewMenu = new wxMenu(); + m_HelpMenu = new wxMenu(); + + // File menu items + m_AddFile = new wxMenuItem(m_FileMenu, MN_AddFile, _("Add a file\tCtrl+F"), "Add a file"); + m_AddFile->SetBitmap(wxArtProvider::GetBitmap(wxART_NORMAL_FILE)); + m_FileMenu->Append(m_AddFile); + + m_AddDirectory = new wxMenuItem(m_FileMenu, MN_AddDirectory, _("Add a directory\tCtrl+D"), "Add a directory"); + m_AddDirectory->SetBitmap(wxArtProvider::GetBitmap(wxART_FOLDER)); + m_FileMenu->Append(m_AddDirectory); + + m_FileMenu->AppendSeparator(); + + m_FileMenu->Append(wxID_EXIT, wxEmptyString, _("Exits the application")); + + // Edit menu items + m_EditMenu->Append(wxID_PREFERENCES, _("Preferences\tCtrl+P"), _("Open preferences dialog")); + + // View menu items + m_ToggleExtension = new wxMenuItem(m_ViewMenu, MN_ToggleExtension, + _("Toggle Extension\tCtrl+E"), _("Show/Hide Extension"), wxITEM_CHECK); + m_ToggleMenuBar = new wxMenuItem(m_ViewMenu, MN_ToggleMenuBar, + _("Toggle Menu Bar\tCtrl+M"), _("Show/Hide Menu Bar"), wxITEM_CHECK); + m_ToggleStatusBar = new wxMenuItem(m_ViewMenu, MN_ToggleStatusBar, + _("Toggle Status Bar\tCtrl+B"), _("Show/Hide Status Bar"), wxITEM_CHECK); + + m_ViewMenu->Append(m_ToggleExtension)->Check(true); + m_ViewMenu->Append(m_ToggleMenuBar)->Check(m_MenuBar->IsShown()); + m_ViewMenu->Append(m_ToggleStatusBar)->Check(m_StatusBar->IsShown()); + + // Help menu items + m_HelpMenu->Append(wxID_ABOUT, wxEmptyString, _("Show about the application")); + + // Append all menus to menubar + m_MenuBar->Append(m_FileMenu, _("&File")); + m_MenuBar->Append(m_EditMenu, _("&Edit")); + m_MenuBar->Append(m_ViewMenu, _("&View")); + m_MenuBar->Append(m_HelpMenu, _("&Help")); + + // Set the menu bar to use + SetMenuBar(m_MenuBar); + // Load default yaml config file. LoadConfigFile(); @@ -90,7 +152,7 @@ MainFrame::MainFrame() m_BottomSplitter = new wxSplitterWindow(m_TopSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_LIVE_UPDATE | wxSP_THIN_SASH); m_BottomSplitter->SetMinimumPaneSize(300); - m_BottomSplitter->SetSashGravity(0.2); + m_BottomSplitter->SetSashGravity(0); // Left half of the BottomSplitter window m_BottomLeftPanel = new wxPanel(m_BottomSplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); @@ -193,7 +255,7 @@ MainFrame::MainFrame() wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES | wxDV_ROW_LINES); // Adding columns to wxDataViewListCtrl. - m_Library->AppendBitmapColumn(wxBitmap(ICON_COLOURED), + m_Library->AppendBitmapColumn(wxBitmap(ICON_STAR_FILLED_16px), 0, wxDATAVIEW_CELL_ACTIVATABLE, 30, @@ -272,6 +334,17 @@ MainFrame::MainFrame() m_Timer = new wxTimer(this); // Binding events. + Bind(wxEVT_MENU, &MainFrame::OnSelectAddFile, this, MN_AddFile); + Bind(wxEVT_MENU, &MainFrame::OnSelectAddDirectory, this, MN_AddDirectory); + Bind(wxEVT_MENU, &MainFrame::OnSelectToggleExtension, this, MN_ToggleExtension); + Bind(wxEVT_MENU, &MainFrame::OnSelectToggleMenuBar, this, MN_ToggleMenuBar); + Bind(wxEVT_MENU, &MainFrame::OnSelectToggleStatusBar, this, MN_ToggleStatusBar); + Bind(wxEVT_MENU, &MainFrame::OnSelectExit, this, wxID_EXIT); + Bind(wxEVT_MENU, &MainFrame::OnSelectPreferences, this, wxID_PREFERENCES); + Bind(wxEVT_MENU, &MainFrame::OnSelectAbout, this, wxID_ABOUT); + + m_StatusBar->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeStatusBar), NULL, this); + Bind(wxEVT_DIRCTRL_FILEACTIVATED, &MainFrame::OnClickDirCtrl, this, BC_DirCtrl); Bind(wxEVT_TREE_BEGIN_DRAG, &MainFrame::OnDragFromDirCtrl, this, m_DirCtrl->GetTreeCtrl()->GetId()); @@ -283,6 +356,7 @@ MainFrame::MainFrame() Bind(wxEVT_BUTTON, &MainFrame::OnClickSettings, this, BC_Settings); Bind(wxEVT_CHECKBOX, &MainFrame::OnCheckAutoplay, this, BC_Autoplay); Bind(wxEVT_SCROLL_THUMBTRACK, &MainFrame::OnSlideVolume, this, BC_Volume); + Bind(wxEVT_SCROLL_THUMBRELEASE, &MainFrame::OnReleaseVolumeSlider, this, BC_Volume); Bind(wxEVT_TIMER, &MainFrame::UpdateElapsedTime, this); @@ -317,7 +391,7 @@ MainFrame::MainFrame() m_BrowserControlSizer->Add(m_SettingsButton, 0, wxALL | wxALIGN_LEFT, 2); m_BrowserControlSizer->Add(0,0,1, wxALL | wxEXPAND, 0); m_BrowserControlSizer->Add(m_SamplePosition, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2); - m_BrowserControlSizer->Add(20,0,0, wxALL | wxEXPAND, 0); + m_BrowserControlSizer->Add(30,0,0, wxALL | wxEXPAND, 0); m_BrowserControlSizer->Add(m_MuteButton, 0, wxALL | wxALIGN_RIGHT, 2); m_BrowserControlSizer->Add(m_VolumeSlider, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2); m_BrowserControlSizer->Add(m_AutoPlayCheck, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 2); @@ -395,6 +469,8 @@ MainFrame::MainFrame() // Restore the data previously added to Library LoadDatabase(); + + CallAfter(&MainFrame::SetAfterFrameCreate); } void MainFrame::OnClickSettings(wxCommandEvent& event) @@ -406,7 +482,7 @@ void MainFrame::OnClickSettings(wxCommandEvent& event) case wxID_OK: if (settings->IsAutoImport()) { - OnAutoImportDir(); + OnAutoImportDir(settings->GetImportDirPath()); RefreshDatabase(); } break; @@ -451,7 +527,7 @@ void MainFrame::AddSamples(wxArrayString& files) sorted_files = db.CheckDuplicates(files); files = sorted_files; - + if(files.size() < 1) { progressDialog->Destroy(); @@ -496,7 +572,7 @@ void MainFrame::AddSamples(wxArrayString& files) wxVector data; - wxVariant icon = wxVariant(wxBitmap(ICON_GREYSCALE)); + wxVariant icon = wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)); if (tags.IsFileValid()) { @@ -632,7 +708,7 @@ void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) { m_Hives->AppendItem(drop_target, files[i]); - m_Library->SetValue(wxVariant(wxBitmap(ICON_COLOURED)), row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0); db.UpdateFavoriteColumn(file_name.ToStdString(), 1); db.UpdateHiveName(file_name.ToStdString(), hive_name.ToStdString()); @@ -666,20 +742,17 @@ void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event) } } -void MainFrame::OnAutoImportDir() +void MainFrame::OnAutoImportDir(const wxString& pathToDirectory) { wxLogDebug("Start Importing Samples:"); - - Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath); wxBusyCursor busy_cursor; wxWindowDisabler window_disabler; - wxString dir_path = settings.GetImportDirPath(); wxString filepath; wxArrayString filepath_array; - size_t number_of_files = wxDir::GetAllFiles(dir_path, &filepath_array, wxEmptyString, wxDIR_DEFAULT); + size_t number_of_files = wxDir::GetAllFiles(pathToDirectory, &filepath_array, wxEmptyString, wxDIR_DEFAULT); wxProgressDialog* progressDialog = new wxProgressDialog("Adding files..", "Adding files, please wait...", (int)number_of_files, this, @@ -795,6 +868,9 @@ void MainFrame::OnClickPlay(wxCommandEvent& event) wxString sample_path = GetFilenamePathAndExtension(selection).Path; m_MediaCtrl->Load(sample_path); + + PushStatusText(wxString::Format("Now playing: %s", selection), 1); + m_MediaCtrl->Play(); m_Timer->Start(100, wxTIMER_CONTINUOUS); @@ -819,6 +895,8 @@ void MainFrame::OnClickStop(wxCommandEvent& event) m_Timer->Stop(); m_SamplePosition->SetLabel("--:--/--:--"); + + this->SetStatusText("Stopped", 1); } void MainFrame::OnClickMute(wxCommandEvent& event) @@ -854,6 +932,8 @@ void MainFrame::OnMediaFinished(wxMediaEvent& event) { m_Timer->Stop(); m_SamplePosition->SetLabel("--:--/--:--"); + PopStatusText(1); + this->SetStatusText("Stopped", 1); } } @@ -890,9 +970,28 @@ void MainFrame::OnCheckAutoplay(wxCommandEvent& event) void MainFrame::OnSlideVolume(wxScrollEvent& event) { - float get_volume = m_MediaCtrl->GetVolume() * 100.0; - m_MediaCtrl->SetVolume(float(m_VolumeSlider->GetValue()) / 100); + + PushStatusText(wxString::Format("Volume: %d", m_VolumeSlider->GetValue()), 1); +} + +void MainFrame::OnReleaseVolumeSlider(wxScrollEvent& event) +{ + int selected_row = m_Library->GetSelectedRow(); + + if (selected_row < 0) + return; + + wxString selection = m_Library->GetTextValue(selected_row, 1); + + // Wait a second then remove the status from statusbar + wxSleep(1); + PopStatusText(1); + + if (m_MediaCtrl->GetState() == wxMEDIASTATE_STOPPED) + this->SetStatusText("Stopped", 1); + else + PushStatusText(wxString::Format("Now playing: %s", selection), 1); } void MainFrame::OnClickLibrary(wxDataViewEvent& event) @@ -955,7 +1054,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) if (bAutoplay) { - wxLogDebug("Playing %s", filename); + PushStatusText(wxString::Format("Now playing: %s", selection), 1); m_MediaCtrl->Play(); m_Timer->Start(100, wxTIMER_CONTINUOUS); @@ -983,7 +1082,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) if (db.GetFavoriteColumnValueByFilename(filename) == 0) { - m_Library->SetValue(wxVariant(wxBitmap(ICON_COLOURED)), selected_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 1); db.UpdateHiveName(filename, hive_name); @@ -1003,7 +1102,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event) } else { - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), selected_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 0); db.UpdateHiveName(filename, m_Hives->GetItemText(favorites_hive).ToStdString()); @@ -1260,7 +1359,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { wxLogDebug("Found match"); - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), i, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); db.UpdateHiveName(matched_sample.ToStdString(), @@ -1303,7 +1402,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) wxVector> dataset; if (db.FilterDatabaseByHiveName(dataset, hive_name.ToStdString(), - settings.IsShowFileExtension()).empty()) + settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { wxMessageBox("Error! Database is empty.", "Error!", wxOK | wxICON_ERROR | wxCENTRE, this); @@ -1335,7 +1435,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { wxVector> dataset; - if (db.FilterDatabaseBySampleName(dataset, "", settings.IsShowFileExtension()).empty()) + if (db.FilterDatabaseBySampleName(dataset, "", settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { wxMessageBox("Error! Database is empty.", "Error!", wxOK | wxICON_ERROR | wxCENTRE, this); @@ -1385,7 +1486,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event) { wxLogDebug("Found match"); - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), i, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); db.UpdateHiveName(matched_sample.ToStdString(), @@ -1532,7 +1633,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) //Add To Favorites if (favorite_add && db_status == 0) { - m_Library->SetValue(wxVariant(wxBitmap(ICON_COLOURED)), selected_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 1); db.UpdateHiveName(filename, hive_name); @@ -1553,7 +1654,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) else { //Remove From Favorites - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), selected_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0); db.UpdateFavoriteColumn(filename, 0); db.UpdateHiveName(filename, m_Hives->GetItemText(favorites_hive).ToStdString()); @@ -1737,7 +1838,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event) if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) { - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), item_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); db.UpdateFavoriteColumn(files[i].ToStdString(), 0); @@ -1877,7 +1978,8 @@ void MainFrame::LoadDatabase() wxVector> dataset; if (db.LoadSamplesDatabase(dataset, *m_Hives, favorites_hive, - *m_Trash, trash_root, settings.IsShowFileExtension()).empty()) + *m_Trash, trash_root, settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { wxLogInfo("Error! Database is empty."); } @@ -1959,7 +2061,9 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event) wxVector> dataset; if (db.RestoreFromTrashByFilename(files[i].ToStdString(), dataset, - settings.IsShowFileExtension()).empty()) + settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, + ICON_STAR_EMPTY_16px).empty()) { wxLogDebug("Error! Database is empty."); } @@ -2020,7 +2124,7 @@ void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event) if (db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) { - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), item_row, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0); db.UpdateFavoriteColumn(files[i].ToStdString(), 0); @@ -2233,7 +2337,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event) { wxLogDebug("Found match"); - m_Library->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), i, 0); + m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0); db.UpdateFavoriteColumn(matched_sample.ToStdString(), 0); db.UpdateHiveName(matched_sample.ToStdString(), @@ -2306,7 +2410,8 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event) wxVector> dataset; if (db.RestoreFromTrashByFilename(files[i].ToStdString(), dataset, - settings.IsShowFileExtension()).empty()) + settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { wxLogDebug("Error! Database is empty."); } @@ -2338,7 +2443,8 @@ void MainFrame::OnDoSearch(wxCommandEvent& event) { wxVector> dataset; - if (db.FilterDatabaseBySampleName(dataset, search, settings.IsShowFileExtension()).empty()) + if (db.FilterDatabaseBySampleName(dataset, search, settings.IsShowFileExtension(), + ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty()) { wxLogDebug("Error! Database is empty."); } @@ -2387,8 +2493,12 @@ void MainFrame::LoadConfigFile() this->SetFont(settings.GetFontType()); this->SetSize(width, height); + this->SetMinSize(wxSize(width, height)); this->CenterOnScreen(wxBOTH); - this->SetIcon(wxIcon(ICON_APP, wxICON_DEFAULT_TYPE, -1, -1)); + this->SetIcon(wxIcon(ICON_HIVE_24px, wxICON_DEFAULT_TYPE, -1, -1)); + this->SetTitle("SampleHive"); + this->SetStatusText("SampleHive v0.1", 3); + this->SetStatusText("Stopped", 1); } void MainFrame::RefreshDatabase() @@ -2462,4 +2572,155 @@ void MainFrame::OnHiveStartEditing(wxDataViewEvent &event) event.Veto(); } +void MainFrame::OnSelectAddFile(wxCommandEvent& event) +{ + wxFileDialog file_dialog(this, wxFileSelectorPromptStr, wxStandardPaths::Get().GetDocumentsDir(), + wxEmptyString, wxFileSelectorDefaultWildcardStr, + wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_PREVIEW, + wxDefaultPosition, wxDefaultSize); + + switch (file_dialog.ShowModal()) + { + case wxID_OK: + { + wxArrayString paths; + file_dialog.GetPaths(paths); + + for (size_t i = 0; i < (size_t)paths.size(); i++) + AddSamples(paths); + } + break; + default: + break; + } +} + +void MainFrame::OnSelectAddDirectory(wxCommandEvent& event) +{ + wxDirDialog dir_dialog(this, wxDirSelectorPromptStr, wxStandardPaths::Get().GetDocumentsDir(), + wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST, wxDefaultPosition, wxDefaultSize); + + switch (dir_dialog.ShowModal()) + { + case wxID_OK: + { + wxString path = dir_dialog.GetPath(); + + OnAutoImportDir(path); + } + break; + default: + break; + } +} + +void MainFrame::OnSelectToggleExtension(wxCommandEvent& event) +{ + wxMessageBox("// TODO", "Toggle extension", wxOK | wxCENTRE, this); + + /* TODO: Toggle Show/Hide Extensions + * Perhaps need Refresh() + * that just updates all elements + * and sample info in all widgets. + */ +} + +void MainFrame::OnSelectToggleMenuBar(wxCommandEvent& event) +{ + if (m_ToggleMenuBar->IsChecked()) + { + m_MenuBar->Show(); + m_InfoBar->ShowMessage("MenuBar showing, press CTRL+M to toggle show/hide.", wxICON_INFORMATION); + } + else + { + m_MenuBar->Hide(); + m_InfoBar->ShowMessage("MenuBar hidden, press CTRL+M to toggle show/hide.", wxICON_INFORMATION); + } +} + +void MainFrame::OnSelectToggleStatusBar(wxCommandEvent& event) +{ + if (m_ToggleStatusBar->IsChecked()) + { + m_StatusBar->Show(); + m_InfoBar->ShowMessage("StatusBar showing, press CTRL+B to toggle show/hide.", wxICON_INFORMATION); + } + else + { + m_StatusBar->Hide(); + m_InfoBar->ShowMessage("StatusBar hidden, press CTRL+B to toggle show/hide.", wxICON_INFORMATION); + } +} + +void MainFrame::OnSelectExit(wxCommandEvent& event) +{ + Close(); +} + +void MainFrame::OnSelectPreferences(wxCommandEvent& event) +{ + Settings* settings = new Settings(this, m_ConfigFilepath, m_DatabaseFilepath); + + switch (settings->ShowModal()) + { + case wxID_OK: + break; + default: + break; + } +} + +void MainFrame::OnSelectAbout(wxCommandEvent& event) +{ + wxAboutDialogInfo aboutInfo; + + aboutInfo.SetName("SampleHive"); + aboutInfo.SetIcon(wxIcon(ICON_HIVE_64px)); + aboutInfo.AddArtist("Apoorv"); + aboutInfo.SetVersion("0.1", "Version 0.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.SetLicence(wxString::FromAscii( + "SampleHive\n" + "Copyright (C) 2021 Apoorv Singh\n" + "\n" + "This program 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" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see .\n" + )); + + wxAboutBox(aboutInfo); +} + +void MainFrame::OnResizeStatusBar(wxSizeEvent& event) +{ + wxRect rect; + m_StatusBar->GetFieldRect(2, rect); + + wxSize bitmap_size = m_HiveBitmap->GetSize(); + + m_HiveBitmap->Move(rect.x + (rect.width - bitmap_size.x), + rect.y + (rect.height - bitmap_size.y)); + + event.Skip(); +} + +void MainFrame::SetAfterFrameCreate() +{ + m_TopSplitter->SetSashPosition(200); + m_BottomSplitter->SetSashPosition(300); +} + MainFrame::~MainFrame(){} diff --git a/src/MainFrame.hpp b/src/MainFrame.hpp index 7735ee4..e72331c 100644 --- a/src/MainFrame.hpp +++ b/src/MainFrame.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +// #include #include #include #include @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -56,7 +58,30 @@ class MainFrame : public wxFrame wxPanel* m_MainPanel; wxBoxSizer* m_MainSizer; - private: + // ------------------------------------------------------------------- + // Hive bitmap icon for the statusbar + wxStaticBitmap* m_HiveBitmap; + + // ------------------------------------------------------------------- + // App statusbar + wxStatusBar* m_StatusBar; + + // ------------------------------------------------------------------- + // App menubar + wxMenuBar* m_MenuBar; + + // ------------------------------------------------------------------- + // Menu and menu items for the menubar + wxMenu* m_FileMenu; + wxMenu* m_EditMenu; + wxMenu* m_ViewMenu; + wxMenu* m_HelpMenu; + wxMenuItem* m_AddFile; + wxMenuItem* m_AddDirectory; + wxMenuItem* m_ToggleExtension; + wxMenuItem* m_ToggleMenuBar; + wxMenuItem* m_ToggleStatusBar; + // ------------------------------------------------------------------- // Splitter windows wxSplitterWindow* m_TopSplitter; @@ -143,6 +168,7 @@ class MainFrame : public wxFrame void OnMediaFinished(wxMediaEvent& event); void OnCheckAutoplay(wxCommandEvent& event); void OnSlideVolume(wxScrollEvent& event); + void OnReleaseVolumeSlider(wxScrollEvent& event); void OnClickSettings(wxCommandEvent& event); // ------------------------------------------------------------------- @@ -177,13 +203,28 @@ class MainFrame : public wxFrame void OnShowLibraryContextMenu(wxDataViewEvent& event); void OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event); + // ------------------------------------------------------------------- + // App menu items event handlers + void OnSelectAddFile(wxCommandEvent& event); + void OnSelectAddDirectory(wxCommandEvent& event); + void OnSelectToggleExtension(wxCommandEvent& event); + void OnSelectToggleMenuBar(wxCommandEvent& event); + void OnSelectToggleStatusBar(wxCommandEvent& event); + void OnSelectExit(wxCommandEvent& event); + void OnSelectPreferences(wxCommandEvent& event); + void OnSelectAbout(wxCommandEvent& event); + + // ------------------------------------------------------------------- + // Statusbar event handler + void OnResizeStatusBar(wxSizeEvent& event); + // ------------------------------------------------------------------- // Timer update event handler void UpdateElapsedTime(wxTimerEvent& event); // ------------------------------------------------------------------- void AddSamples(wxArrayString& files); - void OnAutoImportDir(); + void OnAutoImportDir(const wxString& pathToDirectory); // ------------------------------------------------------------------- void LoadDatabase(); @@ -202,6 +243,10 @@ class MainFrame : public wxFrame // wxString TagLibTowx(const TagLib::String& in); + // ------------------------------------------------------------------- + // Call after frame creation + void SetAfterFrameCreate(); + // ------------------------------------------------------------------- friend class App; };