Refactor database
This commit is contained in:
parent
f808a8281f
commit
63173df9ad
918
src/Database.cpp
918
src/Database.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -33,10 +33,12 @@
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
class Database
|
#include "IDatabase.hpp"
|
||||||
|
|
||||||
|
class Database : public IDatabase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Database(wxInfoBar& infoBar);
|
Database(wxInfoBar& infoBar, const std::string& dbPath);
|
||||||
~Database();
|
~Database();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -44,69 +46,71 @@ class Database
|
||||||
sqlite3* m_Database;
|
sqlite3* m_Database;
|
||||||
int rc;
|
int rc;
|
||||||
char* m_ErrMsg;
|
char* m_ErrMsg;
|
||||||
sqlite3_stmt* m_Stmt;
|
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
wxInfoBar& m_InfoBar;
|
wxInfoBar& m_InfoBar;
|
||||||
|
|
||||||
|
void open(const std::string& dbPath);
|
||||||
|
void close();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Create the table
|
// Create the table
|
||||||
void CreateTableSamples(const std::string& dbPath);
|
void CreateTableSamples() override;
|
||||||
void CreateTableHives(const std::string& dbPath);
|
void CreateTableHives() override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Insert into database
|
// Insert into database
|
||||||
void InsertIntoSamples(const std::string& dbPath, std::vector<Sample>);
|
void InsertIntoSamples(std::vector<Sample>) override;
|
||||||
void InsertIntoHives(const std::string& dbPath, const std::string& hiveName);
|
void InsertIntoHives(const std::string& hiveName) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Update database
|
// Update database
|
||||||
void UpdateFavoriteColumn(const std::string& dbPath, const std::string& filename, int value);
|
void UpdateFavoriteColumn(const std::string& filename, int value) override;
|
||||||
void UpdateHive(const std::string& dbPath, const std::string& hiveOldName, const std::string& hiveNewName);
|
void UpdateHive(const std::string& hiveOldName, const std::string& hiveNewName) override;
|
||||||
void UpdateHiveName(const std::string& dbPath, const std::string& filename, const std::string& hiveName);
|
void UpdateHiveName(const std::string& filename, const std::string& hiveName) override;
|
||||||
void UpdateTrashColumn(const std::string& dbPath, const std::string& filename, int value);
|
void UpdateTrashColumn(const std::string& filename, int value) override;
|
||||||
void UpdateSamplePack(const std::string& dbPath, const std::string& filename, const std::string& samplePack);
|
void UpdateSamplePack(const std::string& filename, const std::string& samplePack) override;
|
||||||
void UpdateSampleType(const std::string& dbPath, const std::string& filename, const std::string& type);
|
void UpdateSampleType(const std::string& filename, const std::string& type) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Get from database
|
// Get from database
|
||||||
int GetFavoriteColumnValueByFilename(const std::string& dbPath, const std::string& filename);
|
int GetFavoriteColumnValueByFilename(const std::string& filename) override;
|
||||||
std::string GetHiveByFilename(const std::string& dbPath, const std::string& filename);
|
std::string GetHiveByFilename(const std::string& filename) override;
|
||||||
std::string GetSamplePathByFilename(const std::string& dbPath, const std::string& filename);
|
std::string GetSamplePathByFilename(const std::string& filename) override;
|
||||||
std::string GetSampleFileExtension(const std::string& dbPath, const std::string& filename);
|
std::string GetSampleFileExtension(const std::string& filename) override;
|
||||||
std::string GetSampleType(const std::string& dbPath, const std::string& filename);
|
std::string GetSampleType(const std::string& filename) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Check database
|
// Check database
|
||||||
bool IsTrashed(const std::string& dbPath, const std::string& filename);
|
bool IsTrashed(const std::string& filename) override;
|
||||||
wxArrayString CheckDuplicates(const std::string& dbPath, const wxArrayString& files);
|
wxArrayString CheckDuplicates(const wxArrayString& files) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Remove from database
|
// Remove from database
|
||||||
void RemoveSampleFromDatabase(const std::string& dbPath, const std::string& filename);
|
void RemoveSampleFromDatabase(const std::string& filename) override;
|
||||||
void RemoveHiveFromDatabase(const std::string& dbPath, const std::string& hiveName);
|
void RemoveHiveFromDatabase(const std::string& hiveName) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
// LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
// LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
||||||
// wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
// wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||||
// wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension);
|
// wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension) override;
|
||||||
LoadSamplesDatabase(const std::string& dbPath, wxVector<wxVector<wxVariant>>& vecSet,
|
LoadSamplesDatabase(wxVector<wxVector<wxVariant>>& vecSet,
|
||||||
wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item,
|
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);
|
const std::string& icon_star_filled, const std::string& icon_star_emtpy) override;
|
||||||
void LoadHivesDatabase(const std::string& dbPath, wxDataViewTreeCtrl& favorite_tree);
|
void LoadHivesDatabase(wxDataViewTreeCtrl& favorite_tree) override;
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
RestoreFromTrashByFilename(const std::string& dbPath, const std::string& filename,
|
RestoreFromTrashByFilename(const std::string& filename,
|
||||||
wxVector<wxVector<wxVariant>>& vecSet, bool show_extension,
|
wxVector<wxVector<wxVariant>>& vecSet, bool show_extension,
|
||||||
const std::string& icon_star_filled, const std::string& icon_star_empty);
|
const std::string& icon_star_filled, const std::string& icon_star_empty) override;
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
FilterDatabaseBySampleName(const std::string& dbPath, wxVector<wxVector<wxVariant>>& sampleVec,
|
FilterDatabaseBySampleName(wxVector<wxVector<wxVariant>>& 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);
|
const std::string& icon_star_filled, const std::string& icon_star_empty) override;
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
FilterDatabaseByHiveName(const std::string& dbPath, wxVector<wxVector<wxVariant>>& sampleVec,
|
FilterDatabaseByHiveName(wxVector<wxVector<wxVariant>>& 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);
|
const std::string& icon_star_filled, const std::string& icon_star_empty) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
/* SampleHive
|
||||||
|
* Copyright (C) 2021 Apoorv Singh
|
||||||
|
* A simple, modern audio sample browser/manager for GNU/Linux.
|
||||||
|
*
|
||||||
|
* This file is a part of SampleHive
|
||||||
|
*
|
||||||
|
* SampleHive is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* SampleHive is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include "Sample.hpp"
|
||||||
|
#include <wx/vector.h>
|
||||||
|
|
||||||
|
class IDatabase
|
||||||
|
{ public:
|
||||||
|
virtual ~IDatabase() = default;
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Create the table
|
||||||
|
virtual void CreateTableSamples() = 0;
|
||||||
|
virtual void CreateTableHives() = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Insert into database
|
||||||
|
virtual void InsertIntoSamples(std::vector<Sample>) = 0;
|
||||||
|
virtual void InsertIntoHives(const std::string& hiveName) = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Update database
|
||||||
|
virtual void UpdateFavoriteColumn(const std::string& filename, int value) = 0;
|
||||||
|
virtual void UpdateHive(const std::string& hiveOldName, const std::string& hiveNewName) = 0;
|
||||||
|
virtual void UpdateHiveName(const std::string& filename, const std::string& hiveName) = 0;
|
||||||
|
virtual void UpdateTrashColumn(const std::string& filename, int value) = 0;
|
||||||
|
virtual void UpdateSamplePack(const std::string& filename, const std::string& samplePack) = 0;
|
||||||
|
virtual void UpdateSampleType(const std::string& filename, const std::string& type) = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Get from database
|
||||||
|
virtual int GetFavoriteColumnValueByFilename(const std::string& filename) = 0;
|
||||||
|
virtual std::string GetHiveByFilename(const std::string& filename) = 0;
|
||||||
|
virtual std::string GetSamplePathByFilename(const std::string& filename) = 0;
|
||||||
|
virtual std::string GetSampleFileExtension(const std::string& filename) = 0;
|
||||||
|
virtual std::string GetSampleType(const std::string& filename) = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Check database
|
||||||
|
virtual bool IsTrashed(const std::string& filename) = 0;
|
||||||
|
virtual wxArrayString CheckDuplicates(const wxArrayString& files) = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// Remove from database
|
||||||
|
virtual void RemoveSampleFromDatabase(const std::string& filename) = 0;
|
||||||
|
virtual void RemoveHiveFromDatabase(const std::string& hiveName) = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
virtual wxVector<wxVector<wxVariant>>
|
||||||
|
// LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
||||||
|
// wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||||
|
// wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension) = 0;
|
||||||
|
LoadSamplesDatabase(wxVector<wxVector<wxVariant>>& vecSet,
|
||||||
|
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_emtpy) = 0;
|
||||||
|
virtual void LoadHivesDatabase(wxDataViewTreeCtrl& favorite_tree) = 0;
|
||||||
|
virtual wxVector<wxVector<wxVariant>>
|
||||||
|
RestoreFromTrashByFilename(const std::string& filename,
|
||||||
|
wxVector<wxVector<wxVariant>>& vecSet, bool show_extension,
|
||||||
|
const std::string& icon_star_filled, const std::string& icon_star_empty) = 0;
|
||||||
|
virtual wxVector<wxVector<wxVariant>>
|
||||||
|
FilterDatabaseBySampleName(wxVector<wxVector<wxVariant>>& sampleVec,
|
||||||
|
const std::string& sampleName, bool show_extension,
|
||||||
|
const std::string& icon_star_filled, const std::string& icon_star_empty) = 0;
|
||||||
|
virtual wxVector<wxVector<wxVariant>>
|
||||||
|
FilterDatabaseByHiveName(wxVector<wxVector<wxVariant>>& sampleVec,
|
||||||
|
const std::string& hiveName, bool show_extension,
|
||||||
|
const std::string& icon_star_filled, const std::string& icon_star_empty) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class DatabaseType {
|
||||||
|
SqlLite
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<IDatabase> createSqlDatabase(DatabaseType type, wxInfoBar& infoBar, const std::string& dbPath);
|
||||||
|
|
@ -544,9 +544,9 @@ MainFrame::MainFrame()
|
||||||
m_BottomRightPanelMainSizer->Layout();
|
m_BottomRightPanelMainSizer->Layout();
|
||||||
|
|
||||||
// Initialize the database
|
// Initialize the database
|
||||||
Database db(*m_InfoBar);
|
m_pDatabase = createSqlDatabase(DatabaseType::SqlLite, *m_InfoBar, m_DatabaseFilepath);
|
||||||
db.CreateTableSamples(static_cast<std::string>(DATABASE_FILEPATH));
|
m_pDatabase->CreateTableSamples();
|
||||||
db.CreateTableHives(static_cast<std::string>(DATABASE_FILEPATH));
|
m_pDatabase->CreateTableHives();
|
||||||
|
|
||||||
// Restore the data previously added to Library
|
// Restore the data previously added to Library
|
||||||
LoadDatabase();
|
LoadDatabase();
|
||||||
|
|
@ -582,7 +582,6 @@ void MainFrame::OnClickSettings(wxCommandEvent& event)
|
||||||
void MainFrame::AddSamples(wxArrayString& files)
|
void MainFrame::AddSamples(wxArrayString& files)
|
||||||
{
|
{
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
|
||||||
|
|
||||||
wxBusyCursor busy_cursor;
|
wxBusyCursor busy_cursor;
|
||||||
wxWindowDisabler window_disabler;
|
wxWindowDisabler window_disabler;
|
||||||
|
|
@ -605,7 +604,7 @@ void MainFrame::AddSamples(wxArrayString& files)
|
||||||
//Check All Files At Once
|
//Check All Files At Once
|
||||||
wxArrayString sorted_files;
|
wxArrayString sorted_files;
|
||||||
|
|
||||||
sorted_files = db.CheckDuplicates(static_cast<std::string>(DATABASE_FILEPATH), files);
|
sorted_files = m_pDatabase->CheckDuplicates(files);
|
||||||
files = sorted_files;
|
files = sorted_files;
|
||||||
|
|
||||||
if(files.size() < 1)
|
if(files.size() < 1)
|
||||||
|
|
@ -686,7 +685,7 @@ void MainFrame::AddSamples(wxArrayString& files)
|
||||||
|
|
||||||
progressDialog->Pulse(_("Updating Database.."), NULL);
|
progressDialog->Pulse(_("Updating Database.."), NULL);
|
||||||
|
|
||||||
db.InsertIntoSamples(static_cast<std::string>(DATABASE_FILEPATH), sample_array);
|
m_pDatabase->InsertIntoSamples(sample_array);
|
||||||
|
|
||||||
progressDialog->Destroy();
|
progressDialog->Destroy();
|
||||||
}
|
}
|
||||||
|
|
@ -750,7 +749,6 @@ void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event)
|
void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event)
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
|
|
||||||
if (event.GetNumberOfFiles() > 0)
|
if (event.GetNumberOfFiles() > 0)
|
||||||
|
|
@ -787,27 +785,23 @@ void MainFrame::OnDragAndDropToHives(wxDropFilesEvent& event)
|
||||||
rows - i, files[i], m_Hives->GetItemText(drop_target));
|
rows - i, files[i], m_Hives->GetItemText(drop_target));
|
||||||
|
|
||||||
if (drop_target.IsOk() && m_Hives->IsContainer(drop_target) &&
|
if (drop_target.IsOk() && m_Hives->IsContainer(drop_target) &&
|
||||||
db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->GetFavoriteColumnValueByFilename( file_name.ToStdString()) == 0)
|
||||||
file_name.ToStdString()) == 0)
|
|
||||||
{
|
{
|
||||||
m_Hives->AppendItem(drop_target, files[i]);
|
m_Hives->AppendItem(drop_target, files[i]);
|
||||||
|
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), file_name.ToStdString(), 1);
|
m_pDatabase->UpdateFavoriteColumn(file_name.ToStdString(), 1);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->UpdateHiveName( file_name.ToStdString(), hive_name.ToStdString());
|
||||||
file_name.ToStdString(), hive_name.ToStdString());
|
|
||||||
|
|
||||||
msg = wxString::Format(_("%s added to %s."), files[i], hive_name);
|
msg = wxString::Format(_("%s added to %s."), files[i], hive_name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH),
|
if (m_pDatabase->GetFavoriteColumnValueByFilename( file_name.ToStdString()) == 1)
|
||||||
file_name.ToStdString()) == 1)
|
|
||||||
{
|
{
|
||||||
wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i],
|
wxMessageBox(wxString::Format(_("%s is already added to %s hive"), files[i],
|
||||||
db.GetHiveByFilename(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->GetHiveByFilename( file_name.ToStdString())),
|
||||||
file_name.ToStdString())),
|
|
||||||
_("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this);
|
_("Error!"), wxOK | wxICON_ERROR | wxCENTRE, this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -901,20 +895,19 @@ void MainFrame::OnDragFromDirCtrl(wxTreeEvent& event)
|
||||||
void MainFrame::OnDragFromLibrary(wxDataViewEvent& event)
|
void MainFrame::OnDragFromLibrary(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
// Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
// Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
// Database db(*m_InfoBar);
|
//
|
||||||
|
|
||||||
int selected_row = m_Library->ItemToRow(event.GetItem());
|
int selected_row = m_Library->ItemToRow(event.GetItem());
|
||||||
|
|
||||||
if (selected_row < 0) return;
|
if (selected_row < 0) return;
|
||||||
|
|
||||||
wxString selection = m_Library->GetTextValue(selected_row, 1);
|
wxString selection = m_Library->GetTextValue(selected_row, 1);
|
||||||
|
|
||||||
// wxString sample_with_extension = db.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
// wxString sample_with_extension = m_pDatabase->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
||||||
// wxString sample_without_extension = db.GetSamplePathByFilename(selection.ToStdString());
|
// wxString sample_without_extension = m_pDatabase->GetSamplePathByFilename(selection.ToStdString());
|
||||||
|
|
||||||
// std::string extension = settings.ShouldShowFileExtension() ?
|
// std::string extension = settings.ShouldShowFileExtension() ?
|
||||||
// db.GetSampleFileExtension(selection.ToStdString()) :
|
// m_pDatabase->GetSampleFileExtension(selection.ToStdString()) :
|
||||||
// db.GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
// m_pDatabase->GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
||||||
|
|
||||||
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
||||||
// sample_with_extension : sample_without_extension;
|
// sample_with_extension : sample_without_extension;
|
||||||
|
|
@ -934,8 +927,7 @@ void MainFrame::OnClickPlay(wxCommandEvent& event)
|
||||||
bStopped = false;
|
bStopped = false;
|
||||||
|
|
||||||
// Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
// Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
// Database db(*m_InfoBar);
|
//
|
||||||
|
|
||||||
int selected_row = m_Library->GetSelectedRow();
|
int selected_row = m_Library->GetSelectedRow();
|
||||||
|
|
||||||
if (selected_row < 0)
|
if (selected_row < 0)
|
||||||
|
|
@ -943,12 +935,12 @@ void MainFrame::OnClickPlay(wxCommandEvent& event)
|
||||||
|
|
||||||
wxString selection = m_Library->GetTextValue(selected_row, 1);
|
wxString selection = m_Library->GetTextValue(selected_row, 1);
|
||||||
|
|
||||||
// wxString sample_with_extension = db.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
// wxString sample_with_extension = m_pDatabase->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
||||||
// wxString sample_without_extension = db.GetSamplePathByFilename(selection.ToStdString());
|
// wxString sample_without_extension = m_pDatabase->GetSamplePathByFilename(selection.ToStdString());
|
||||||
|
|
||||||
// std::string extension = settings.ShouldShowFileExtension() ?
|
// std::string extension = settings.ShouldShowFileExtension() ?
|
||||||
// db.GetSampleFileExtension(selection.ToStdString()) :
|
// m_pDatabase->GetSampleFileExtension(selection.ToStdString()) :
|
||||||
// db.GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
// m_pDatabase->GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
||||||
|
|
||||||
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
||||||
// sample_with_extension : sample_without_extension;
|
// sample_with_extension : sample_without_extension;
|
||||||
|
|
@ -1091,9 +1083,7 @@ void MainFrame::OnReleaseVolumeSlider(wxScrollEvent& event)
|
||||||
void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
int selected_row = m_Library->ItemToRow(event.GetItem());
|
||||||
|
|
||||||
int selected_row = m_Library->ItemToRow(event.GetItem());
|
|
||||||
|
|
||||||
int current_row = m_Library->ItemToRow(m_Library->GetCurrentItem());
|
int current_row = m_Library->ItemToRow(m_Library->GetCurrentItem());
|
||||||
|
|
||||||
|
|
@ -1139,12 +1129,12 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
||||||
// else
|
// else
|
||||||
// selection = m_Library->GetTextValue(selected_row, 1);
|
// selection = m_Library->GetTextValue(selected_row, 1);
|
||||||
|
|
||||||
// wxString sample_with_extension = db.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
// wxString sample_with_extension = m_pDatabase->GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
||||||
// wxString sample_without_extension = db.GetSamplePathByFilename(selection.ToStdString());
|
// wxString sample_without_extension = m_pDatabase->GetSamplePathByFilename(selection.ToStdString());
|
||||||
|
|
||||||
// std::string extension = settings.ShouldShowFileExtension() ?
|
// std::string extension = settings.ShouldShowFileExtension() ?
|
||||||
// db.GetSampleFileExtension(selection.ToStdString()) :
|
// m_pDatabase->GetSampleFileExtension(selection.ToStdString()) :
|
||||||
// db.GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
// m_pDatabase->GetSampleFileExtension(selection.BeforeLast('.').ToStdString());
|
||||||
|
|
||||||
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
// wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
||||||
// sample_with_extension : sample_without_extension;
|
// sample_with_extension : sample_without_extension;
|
||||||
|
|
@ -1187,12 +1177,12 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
||||||
wxDataViewItem container;
|
wxDataViewItem container;
|
||||||
wxDataViewItem child;
|
wxDataViewItem child;
|
||||||
|
|
||||||
if (db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH), filename) == 0)
|
if (m_pDatabase->GetFavoriteColumnValueByFilename(filename) == 0)
|
||||||
{
|
{
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), filename, 1);
|
m_pDatabase->UpdateFavoriteColumn(filename, 1);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), filename, hive_name);
|
m_pDatabase->UpdateHiveName(filename, hive_name);
|
||||||
|
|
||||||
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -1211,9 +1201,8 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), filename, 0);
|
m_pDatabase->UpdateFavoriteColumn(filename, 0);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->UpdateHiveName( filename, m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
filename, m_Hives->GetItemText(favorites_hive).ToStdString());
|
|
||||||
|
|
||||||
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -1242,9 +1231,7 @@ void MainFrame::OnClickLibrary(wxDataViewEvent& event)
|
||||||
void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
wxDataViewItem selected_hive = event.GetItem();
|
||||||
|
|
||||||
wxDataViewItem selected_hive = event.GetItem();
|
|
||||||
|
|
||||||
wxString hive_name = m_Hives->GetItemText(selected_hive);
|
wxString hive_name = m_Hives->GetItemText(selected_hive);
|
||||||
|
|
||||||
|
|
@ -1342,8 +1329,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
wxLogDebug("Sample count: %d", sample_count);
|
wxLogDebug("Sample count: %d", sample_count);
|
||||||
|
|
||||||
m_Hives->SetItemText(selected_hive, hive_name);
|
m_Hives->SetItemText(selected_hive, hive_name);
|
||||||
db.UpdateHive(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->UpdateHive( selected_hive_name.ToStdString(), hive_name.ToStdString());
|
||||||
selected_hive_name.ToStdString(), hive_name.ToStdString());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1357,10 +1343,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
wxLogDebug("Sample count: %d :: Sample name: %s", sample_count, sample_name);
|
wxLogDebug("Sample count: %d :: Sample name: %s", sample_count, sample_name);
|
||||||
|
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->UpdateHiveName( sample_name.ToStdString(), hive_name.ToStdString());
|
||||||
sample_name.ToStdString(), hive_name.ToStdString());
|
m_pDatabase->UpdateHive( selected_hive_name.ToStdString(), hive_name.ToStdString());
|
||||||
db.UpdateHive(static_cast<std::string>(DATABASE_FILEPATH),
|
|
||||||
selected_hive_name.ToStdString(), hive_name.ToStdString());
|
|
||||||
|
|
||||||
m_Hives->SetItemText(selected_hive, hive_name);
|
m_Hives->SetItemText(selected_hive, hive_name);
|
||||||
}
|
}
|
||||||
|
|
@ -1429,8 +1413,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
m_Hives->DeleteItem(selected_hive);
|
m_Hives->DeleteItem(selected_hive);
|
||||||
|
|
||||||
db.RemoveHiveFromDatabase(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->RemoveHiveFromDatabase( hive_name.ToStdString());
|
||||||
hive_name.ToStdString());
|
|
||||||
|
|
||||||
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
|
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
|
||||||
}
|
}
|
||||||
|
|
@ -1471,10 +1454,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->UpdateFavoriteColumn( matched_sample.ToStdString(), 0);
|
||||||
matched_sample.ToStdString(), 0);
|
m_pDatabase->UpdateHiveName( matched_sample.ToStdString(),
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH),
|
|
||||||
matched_sample.ToStdString(),
|
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -1487,8 +1468,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
m_Hives->DeleteChildren(selected_hive);
|
m_Hives->DeleteChildren(selected_hive);
|
||||||
m_Hives->DeleteItem(selected_hive);
|
m_Hives->DeleteItem(selected_hive);
|
||||||
|
|
||||||
db.RemoveHiveFromDatabase(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->RemoveHiveFromDatabase( hive_name.ToStdString());
|
||||||
hive_name.ToStdString());
|
|
||||||
|
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("%s and all samples inside %s have been deleted from hives successfully."),
|
_("%s and all samples inside %s have been deleted from hives successfully."),
|
||||||
|
|
@ -1514,8 +1494,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.FilterDatabaseByHiveName(static_cast<std::string>(DATABASE_FILEPATH),
|
if (m_pDatabase->FilterDatabaseByHiveName( dataset, hive_name.ToStdString(),
|
||||||
dataset, hive_name.ToStdString(),
|
|
||||||
settings.ShouldShowFileExtension(),
|
settings.ShouldShowFileExtension(),
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
|
|
@ -1549,8 +1528,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.FilterDatabaseBySampleName(static_cast<std::string>(DATABASE_FILEPATH),
|
if (m_pDatabase->FilterDatabaseBySampleName( dataset, "", settings.ShouldShowFileExtension(),
|
||||||
dataset, "", settings.ShouldShowFileExtension(),
|
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
wxMessageBox(_("Error! Database is empty."), _("Error!"),
|
wxMessageBox(_("Error! Database is empty."), _("Error!"),
|
||||||
|
|
@ -1601,8 +1579,8 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), matched_sample.ToStdString(), 0);
|
m_pDatabase->UpdateFavoriteColumn(matched_sample.ToStdString(), 0);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), matched_sample.ToStdString(),
|
m_pDatabase->UpdateHiveName(matched_sample.ToStdString(),
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
m_Hives->DeleteItem(selected_hive);
|
m_Hives->DeleteItem(selected_hive);
|
||||||
|
|
@ -1612,8 +1590,7 @@ void MainFrame::OnShowHivesContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"),
|
m_InfoBar->ShowMessage(wxString::Format(_("Removed %s from %s"),
|
||||||
m_Hives->GetItemText(event.GetItem()),
|
m_Hives->GetItemText(event.GetItem()),
|
||||||
db.GetHiveByFilename(static_cast<std::string>(DATABASE_FILEPATH),
|
m_pDatabase->GetHiveByFilename(matched_sample.ToStdString())),
|
||||||
matched_sample.ToStdString())),
|
|
||||||
wxICON_INFORMATION);
|
wxICON_INFORMATION);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -1652,9 +1629,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
TagEditor* tagEditor;
|
TagEditor* tagEditor;
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
wxString msg;
|
||||||
|
|
||||||
wxString msg;
|
|
||||||
|
|
||||||
wxDataViewItem item = event.GetItem();
|
wxDataViewItem item = event.GetItem();
|
||||||
int selected_row;
|
int selected_row;
|
||||||
|
|
@ -1675,7 +1650,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
//true = add false = remove
|
//true = add false = remove
|
||||||
bool favorite_add = false;
|
bool favorite_add = false;
|
||||||
|
|
||||||
if (db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH), filename) == 1)
|
if (m_pDatabase->GetFavoriteColumnValueByFilename(filename) == 1)
|
||||||
menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive"));
|
menu.Append(MN_FavoriteSample, _("Remove from hive"), _("Remove the selected sample(s) from hive"));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1729,7 +1704,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
filename = settings.ShouldShowFileExtension() ?
|
filename = settings.ShouldShowFileExtension() ?
|
||||||
name.BeforeLast('.').ToStdString() : name.ToStdString();
|
name.BeforeLast('.').ToStdString() : name.ToStdString();
|
||||||
|
|
||||||
db_status = db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH), filename);
|
db_status = m_pDatabase->GetFavoriteColumnValueByFilename(filename);
|
||||||
|
|
||||||
// Aleady Added, Do Nothing
|
// Aleady Added, Do Nothing
|
||||||
if (favorite_add && db_status == 1)
|
if (favorite_add && db_status == 1)
|
||||||
|
|
@ -1744,8 +1719,8 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_FILLED_16px)), selected_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), filename, 1);
|
m_pDatabase->UpdateFavoriteColumn(filename, 1);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), filename, hive_name);
|
m_pDatabase->UpdateHiveName(filename, hive_name);
|
||||||
|
|
||||||
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -1765,8 +1740,8 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
//Remove From Favorites
|
//Remove From Favorites
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), selected_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), filename, 0);
|
m_pDatabase->UpdateFavoriteColumn(filename, 0);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), filename,
|
m_pDatabase->UpdateHiveName(filename,
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
||||||
|
|
@ -1829,7 +1804,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
wxLogDebug("Selected row: %d :: Sample: %s", selected_row, filename);
|
wxLogDebug("Selected row: %d :: Sample: %s", selected_row, filename);
|
||||||
|
|
||||||
db.RemoveSampleFromDatabase(static_cast<std::string>(DATABASE_FILEPATH), filename);
|
m_pDatabase->RemoveSampleFromDatabase(filename);
|
||||||
m_Library->DeleteItem(selected_row);
|
m_Library->DeleteItem(selected_row);
|
||||||
|
|
||||||
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
||||||
|
|
@ -1879,7 +1854,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
std::string multi_selection = settings.ShouldShowFileExtension() ?
|
std::string multi_selection = settings.ShouldShowFileExtension() ?
|
||||||
text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ;
|
text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ;
|
||||||
|
|
||||||
db.RemoveSampleFromDatabase(static_cast<std::string>(DATABASE_FILEPATH), multi_selection);
|
m_pDatabase->RemoveSampleFromDatabase(multi_selection);
|
||||||
m_Library->DeleteItem(row);
|
m_Library->DeleteItem(row);
|
||||||
|
|
||||||
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
||||||
|
|
@ -1921,7 +1896,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
wxDataViewItem root = wxDataViewItem(wxNullPtr);
|
wxDataViewItem root = wxDataViewItem(wxNullPtr);
|
||||||
wxDataViewItem container, child;
|
wxDataViewItem container, child;
|
||||||
|
|
||||||
if (db.IsTrashed(static_cast<std::string>(DATABASE_FILEPATH), filename))
|
if (m_pDatabase->IsTrashed(filename))
|
||||||
wxLogDebug(_("Already trashed.."));
|
wxLogDebug(_("Already trashed.."));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1946,11 +1921,11 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
files = file_data.GetFilenames();
|
files = file_data.GetFilenames();
|
||||||
|
|
||||||
if (db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString()))
|
if (m_pDatabase->GetFavoriteColumnValueByFilename(files[i].ToStdString()))
|
||||||
{
|
{
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 0);
|
m_pDatabase->UpdateFavoriteColumn(files[i].ToStdString(), 0);
|
||||||
|
|
||||||
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
||||||
{
|
{
|
||||||
|
|
@ -1973,8 +1948,8 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.UpdateTrashColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 1);
|
m_pDatabase->UpdateTrashColumn(files[i].ToStdString(), 1);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(),
|
m_pDatabase->UpdateHiveName(files[i].ToStdString(),
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
m_Trash->AppendItem(trash_root, text_value);
|
m_Trash->AppendItem(trash_root, text_value);
|
||||||
|
|
@ -2081,15 +2056,13 @@ void MainFrame::OnShowLibraryColumnHeaderContextMenu(wxDataViewEvent& event)
|
||||||
void MainFrame::LoadDatabase()
|
void MainFrame::LoadDatabase()
|
||||||
{
|
{
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
try
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
db.LoadHivesDatabase(static_cast<std::string>(DATABASE_FILEPATH), *m_Hives);
|
m_pDatabase->LoadHivesDatabase(*m_Hives);
|
||||||
|
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.LoadSamplesDatabase(static_cast<std::string>(DATABASE_FILEPATH), dataset, *m_Hives, favorites_hive,
|
if (m_pDatabase->LoadSamplesDatabase(dataset, *m_Hives, favorites_hive,
|
||||||
*m_Trash, trash_root, settings.ShouldShowFileExtension(),
|
*m_Trash, trash_root, settings.ShouldShowFileExtension(),
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
|
|
@ -2112,9 +2085,7 @@ void MainFrame::LoadDatabase()
|
||||||
void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
||||||
{
|
{
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
wxTreeItemId selected_trashed_item = event.GetItem();
|
||||||
|
|
||||||
wxTreeItemId selected_trashed_item = event.GetItem();
|
|
||||||
|
|
||||||
wxMenu menu;
|
wxMenu menu;
|
||||||
|
|
||||||
|
|
@ -2133,7 +2104,7 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
||||||
m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') :
|
m_Trash->GetItemText(selected_trashed_item).BeforeLast('.') :
|
||||||
m_Trash->GetItemText(selected_trashed_item);
|
m_Trash->GetItemText(selected_trashed_item);
|
||||||
|
|
||||||
db.RemoveSampleFromDatabase(static_cast<std::string>(DATABASE_FILEPATH), trashed_item_name.ToStdString());
|
m_pDatabase->RemoveSampleFromDatabase(trashed_item_name.ToStdString());
|
||||||
|
|
||||||
m_Trash->Delete(selected_trashed_item);
|
m_Trash->Delete(selected_trashed_item);
|
||||||
}
|
}
|
||||||
|
|
@ -2142,9 +2113,7 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
||||||
{
|
{
|
||||||
wxLogDebug(_("Restore sample"));
|
wxLogDebug(_("Restore sample"));
|
||||||
|
|
||||||
Database db(*m_InfoBar);
|
wxArrayTreeItemIds selected_item_ids;
|
||||||
|
|
||||||
wxArrayTreeItemIds selected_item_ids;
|
|
||||||
m_Trash->GetSelections(selected_item_ids);
|
m_Trash->GetSelections(selected_item_ids);
|
||||||
|
|
||||||
wxFileDataObject file_data;
|
wxFileDataObject file_data;
|
||||||
|
|
@ -2166,13 +2135,13 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
||||||
|
|
||||||
files = file_data.GetFilenames();
|
files = file_data.GetFilenames();
|
||||||
|
|
||||||
db.UpdateTrashColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 0);
|
m_pDatabase->UpdateTrashColumn(files[i].ToStdString(), 0);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.RestoreFromTrashByFilename(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(),
|
if (m_pDatabase->RestoreFromTrashByFilename(files[i].ToStdString(),
|
||||||
dataset, settings.ShouldShowFileExtension(),
|
dataset, settings.ShouldShowFileExtension(),
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
|
|
@ -2203,7 +2172,6 @@ void MainFrame::OnShowTrashContextMenu(wxTreeEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
|
void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
|
|
||||||
if (event.GetNumberOfFiles() > 0)
|
if (event.GetNumberOfFiles() > 0)
|
||||||
|
|
@ -2233,11 +2201,11 @@ void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
|
||||||
|
|
||||||
files = file_data.GetFilenames();
|
files = file_data.GetFilenames();
|
||||||
|
|
||||||
if (db.GetFavoriteColumnValueByFilename(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString()))
|
if (m_pDatabase->GetFavoriteColumnValueByFilename(files[i].ToStdString()))
|
||||||
{
|
{
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), item_row, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 0);
|
m_pDatabase->UpdateFavoriteColumn(files[i].ToStdString(), 0);
|
||||||
|
|
||||||
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
for (int j = 0; j < m_Hives->GetChildCount(root); j++)
|
||||||
{
|
{
|
||||||
|
|
@ -2260,8 +2228,8 @@ void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.UpdateTrashColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 1);
|
m_pDatabase->UpdateTrashColumn(files[i].ToStdString(), 1);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(),
|
m_pDatabase->UpdateHiveName(files[i].ToStdString(),
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
m_Trash->AppendItem(trash_root, text_value);
|
m_Trash->AppendItem(trash_root, text_value);
|
||||||
|
|
@ -2278,9 +2246,7 @@ void MainFrame::OnDragAndDropToTrash(wxDropFilesEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnClickAddHive(wxCommandEvent& event)
|
void MainFrame::OnClickAddHive(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
std::deque<wxDataViewItem> nodes;
|
||||||
|
|
||||||
std::deque<wxDataViewItem> nodes;
|
|
||||||
nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0));
|
nodes.push_back(m_Hives->GetNthChild(wxDataViewItem(wxNullPtr), 0));
|
||||||
|
|
||||||
wxDataViewItem current_item, found_item;
|
wxDataViewItem current_item, found_item;
|
||||||
|
|
@ -2341,7 +2307,7 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name);
|
m_Hives->AppendContainer(wxDataViewItem(wxNullPtr), hive_name);
|
||||||
db.InsertIntoHives(static_cast<std::string>(DATABASE_FILEPATH), hive_name.ToStdString());
|
m_pDatabase->InsertIntoHives(hive_name.ToStdString());
|
||||||
|
|
||||||
msg = wxString::Format(_("%s added to Hives."), hive_name);
|
msg = wxString::Format(_("%s added to Hives."), hive_name);
|
||||||
}
|
}
|
||||||
|
|
@ -2360,9 +2326,7 @@ void MainFrame::OnClickAddHive(wxCommandEvent& event)
|
||||||
void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
Database db(*m_InfoBar);
|
wxDataViewItem selected_item = m_Hives->GetSelection();
|
||||||
|
|
||||||
wxDataViewItem selected_item = m_Hives->GetSelection();
|
|
||||||
wxString hive_name = m_Hives->GetItemText(selected_item);
|
wxString hive_name = m_Hives->GetItemText(selected_item);
|
||||||
|
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
|
@ -2411,7 +2375,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
m_Hives->DeleteItem(selected_item);
|
m_Hives->DeleteItem(selected_item);
|
||||||
|
|
||||||
db.RemoveHiveFromDatabase(static_cast<std::string>(DATABASE_FILEPATH), hive_name.ToStdString());
|
m_pDatabase->RemoveHiveFromDatabase(hive_name.ToStdString());
|
||||||
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
|
msg = wxString::Format(_("%s deleted from hives successfully."), hive_name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -2451,8 +2415,8 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
||||||
|
|
||||||
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
m_Library->SetValue(wxVariant(wxBitmap(ICON_STAR_EMPTY_16px)), i, 0);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(static_cast<std::string>(DATABASE_FILEPATH), matched_sample.ToStdString(), 0);
|
m_pDatabase->UpdateFavoriteColumn(matched_sample.ToStdString(), 0);
|
||||||
db.UpdateHiveName(static_cast<std::string>(DATABASE_FILEPATH), matched_sample.ToStdString(),
|
m_pDatabase->UpdateHiveName(matched_sample.ToStdString(),
|
||||||
m_Hives->GetItemText(favorites_hive).ToStdString());
|
m_Hives->GetItemText(favorites_hive).ToStdString());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -2465,7 +2429,7 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
||||||
m_Hives->DeleteChildren(selected_item);
|
m_Hives->DeleteChildren(selected_item);
|
||||||
m_Hives->DeleteItem(selected_item);
|
m_Hives->DeleteItem(selected_item);
|
||||||
|
|
||||||
db.RemoveHiveFromDatabase(static_cast<std::string>(DATABASE_FILEPATH), hive_name.ToStdString());
|
m_pDatabase->RemoveHiveFromDatabase(hive_name.ToStdString());
|
||||||
|
|
||||||
msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."),
|
msg = wxString::Format(_("%s and all samples inside %s have been deleted from hives successfully."),
|
||||||
hive_name, hive_name);
|
hive_name, hive_name);
|
||||||
|
|
@ -2484,7 +2448,6 @@ void MainFrame::OnClickRemoveHive(wxCommandEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
|
|
||||||
wxArrayTreeItemIds selected_item_ids;
|
wxArrayTreeItemIds selected_item_ids;
|
||||||
|
|
@ -2521,13 +2484,13 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
||||||
|
|
||||||
files = file_data.GetFilenames();
|
files = file_data.GetFilenames();
|
||||||
|
|
||||||
db.UpdateTrashColumn(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), 0);
|
m_pDatabase->UpdateTrashColumn(files[i].ToStdString(), 0);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.RestoreFromTrashByFilename(static_cast<std::string>(DATABASE_FILEPATH), files[i].ToStdString(), dataset,
|
if (m_pDatabase->RestoreFromTrashByFilename(files[i].ToStdString(), dataset,
|
||||||
settings.ShouldShowFileExtension(),
|
settings.ShouldShowFileExtension(),
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
|
|
@ -2552,16 +2515,15 @@ void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnDoSearch(wxCommandEvent& event)
|
void MainFrame::OnDoSearch(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
|
||||||
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
|
|
||||||
std::string search = m_SearchBox->GetValue().ToStdString();
|
const auto search = m_SearchBox->GetValue().ToStdString();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.FilterDatabaseBySampleName(static_cast<std::string>(DATABASE_FILEPATH), dataset, search, settings.ShouldShowFileExtension(),
|
if (m_pDatabase->FilterDatabaseBySampleName(dataset, search, settings.ShouldShowFileExtension(),
|
||||||
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
ICON_STAR_FILLED_16px, ICON_STAR_EMPTY_16px).empty())
|
||||||
{
|
{
|
||||||
wxLogDebug(_("Error! Database is empty."));
|
wxLogDebug(_("Error! Database is empty."));
|
||||||
|
|
@ -2685,21 +2647,19 @@ void MainFrame::RefreshDatabase()
|
||||||
FileInfo
|
FileInfo
|
||||||
MainFrame::GetFilenamePathAndExtension(const wxString& selected, bool checkExtension, bool doGetFilename) const
|
MainFrame::GetFilenamePathAndExtension(const wxString& selected, bool checkExtension, bool doGetFilename) const
|
||||||
{
|
{
|
||||||
Database db(*m_InfoBar);
|
|
||||||
Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
|
||||||
|
|
||||||
wxString path;
|
wxString path;
|
||||||
std::string extension, filename;
|
std::string extension, filename;
|
||||||
|
|
||||||
wxString filename_with_extension = db.GetSamplePathByFilename(static_cast<std::string>(DATABASE_FILEPATH),
|
wxString filename_with_extension = m_pDatabase->GetSamplePathByFilename(selected.BeforeLast('.').ToStdString());
|
||||||
selected.BeforeLast('.').ToStdString());
|
wxString filename_without_extension = m_pDatabase->GetSamplePathByFilename(selected.ToStdString());
|
||||||
wxString filename_without_extension = db.GetSamplePathByFilename(static_cast<std::string>(DATABASE_FILEPATH), selected.ToStdString());
|
|
||||||
|
|
||||||
if (checkExtension)
|
if (checkExtension)
|
||||||
{
|
{
|
||||||
extension = settings.ShouldShowFileExtension() ?
|
extension = settings.ShouldShowFileExtension() ?
|
||||||
db.GetSampleFileExtension(static_cast<std::string>(DATABASE_FILEPATH), selected.ToStdString()) :
|
m_pDatabase->GetSampleFileExtension(selected.ToStdString()) :
|
||||||
db.GetSampleFileExtension(static_cast<std::string>(DATABASE_FILEPATH), selected.BeforeLast('.').ToStdString());
|
m_pDatabase->GetSampleFileExtension(selected.BeforeLast('.').ToStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
path = selected.Contains(wxString::Format(".%s", extension)) ?
|
path = selected.Contains(wxString::Format(".%s", extension)) ?
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@
|
||||||
#include <taglib/tstring.h>
|
#include <taglib/tstring.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "IDatabase.hpp"
|
||||||
|
|
||||||
struct FileInfo
|
struct FileInfo
|
||||||
{
|
{
|
||||||
wxString Path;
|
wxString Path;
|
||||||
|
|
@ -180,6 +182,7 @@ class MainFrame : public wxFrame
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance();
|
wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance();
|
||||||
|
|
||||||
|
std::unique_ptr<IDatabase> m_pDatabase;
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
bool bAutoplay = false;
|
bool bAutoplay = false;
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
|
||||||
|
|
||||||
void TagEditor::OnClickApply(wxCommandEvent& event)
|
void TagEditor::OnClickApply(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Database db(m_InfoBar);
|
Database db(m_InfoBar, m_DatabaseFilepath);
|
||||||
|
|
||||||
wxString title = m_TitleText->GetValue();
|
wxString title = m_TitleText->GetValue();
|
||||||
wxString artist = m_ArtistText->GetValue();
|
wxString artist = m_ArtistText->GetValue();
|
||||||
|
|
@ -235,7 +235,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
||||||
wxString comment = m_CommentText->GetValue();
|
wxString comment = m_CommentText->GetValue();
|
||||||
wxString type = m_SampleTypeChoice->GetStringSelection();
|
wxString type = m_SampleTypeChoice->GetStringSelection();
|
||||||
|
|
||||||
std::string sampleType = db.GetSampleType(m_DatabaseFilepath, m_Filename);
|
std::string sampleType = db.GetSampleType(m_Filename);
|
||||||
|
|
||||||
std::string filename = wxString(m_Filename).AfterLast('/').BeforeLast('.').ToStdString();
|
std::string filename = wxString(m_Filename).AfterLast('/').BeforeLast('.').ToStdString();
|
||||||
|
|
||||||
|
|
@ -265,7 +265,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
||||||
wxLogDebug("Changing artist tag..");
|
wxLogDebug("Changing artist tag..");
|
||||||
tags.SetArtist(artist.ToStdString());
|
tags.SetArtist(artist.ToStdString());
|
||||||
|
|
||||||
db.UpdateSamplePack(m_DatabaseFilepath, m_Filename, artist.ToStdString());
|
db.UpdateSamplePack(m_Filename, artist.ToStdString());
|
||||||
|
|
||||||
wxLogDebug("SAMPLE FILENAME HERE: %s", m_Filename);
|
wxLogDebug("SAMPLE FILENAME HERE: %s", m_Filename);
|
||||||
|
|
||||||
|
|
@ -299,7 +299,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
||||||
if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType)
|
if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType)
|
||||||
{
|
{
|
||||||
wxLogDebug("Changing type tag..");
|
wxLogDebug("Changing type tag..");
|
||||||
db.UpdateSampleType(m_DatabaseFilepath, filename, type.ToStdString());
|
db.UpdateSampleType(filename, type.ToStdString());
|
||||||
|
|
||||||
info_msg = wxString::Format("Successfully changed type tag to %s", type);
|
info_msg = wxString::Format("Successfully changed type tag to %s", type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue