Fix database initializing before loading configuration file.
This commit is contained in:
parent
c9b79a6935
commit
e1d89d0b24
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "Database/Database.hpp"
|
#include "Database/Database.hpp"
|
||||||
#include "Utility/Log.hpp"
|
#include "Utility/Log.hpp"
|
||||||
|
#include "Utility/Paths.hpp"
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
@ -77,9 +78,9 @@ class Sqlite3Statement
|
||||||
sqlite3_stmt* stmt = nullptr;
|
sqlite3_stmt* stmt = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
Database::Database(const std::string &dbPath)
|
Database::Database()
|
||||||
{
|
{
|
||||||
OpenDatabase(dbPath);
|
OpenDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
Database::~Database()
|
Database::~Database()
|
||||||
|
|
@ -1072,9 +1073,9 @@ Database::RestoreFromTrashByFilename(const std::string &filename,
|
||||||
return vecSet;
|
return vecSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::OpenDatabase(const std::string &dbPath)
|
void Database::OpenDatabase()
|
||||||
{
|
{
|
||||||
throw_on_sqlite3_error(sqlite3_open(dbPath.c_str(), &m_Database));
|
throw_on_sqlite3_error(sqlite3_open(static_cast<std::string>(DATABASE_FILEPATH).c_str(), &m_Database));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::CloseDatabase()
|
void Database::CloseDatabase()
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Database(const std::string& dbPath);
|
Database();
|
||||||
~Database();
|
~Database();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -48,7 +48,7 @@ class Database
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
void OpenDatabase(const std::string& dbPath);
|
void OpenDatabase();
|
||||||
void CloseDatabase();
|
void CloseDatabase();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ void TagEditor::OnClickCustomTagButton(wxCommandEvent& event)
|
||||||
|
|
||||||
void TagEditor::OnClickApply(wxCommandEvent& event)
|
void TagEditor::OnClickApply(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
Database db(static_cast<std::string>(DATABASE_FILEPATH));
|
Database db;
|
||||||
|
|
||||||
wxString title = m_TitleText->GetValue();
|
wxString title = m_TitleText->GetValue();
|
||||||
wxString artist = m_ArtistText->GetValue();
|
wxString artist = m_ArtistText->GetValue();
|
||||||
|
|
|
||||||
|
|
@ -398,11 +398,6 @@ MainFrame::MainFrame()
|
||||||
// Intializing wxTimer
|
// Intializing wxTimer
|
||||||
m_Timer = new wxTimer(this);
|
m_Timer = new wxTimer(this);
|
||||||
|
|
||||||
// Initialize the database
|
|
||||||
m_Database = std::make_unique<Database>(static_cast<std::string>(DATABASE_FILEPATH));
|
|
||||||
m_Database->CreateTableSamples();
|
|
||||||
m_Database->CreateTableHives();
|
|
||||||
|
|
||||||
m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database);
|
m_TopWaveformPanel = new WaveformViewer(m_TopPanel, *m_Library, *m_MediaCtrl, *m_Database);
|
||||||
|
|
||||||
// Binding events.
|
// Binding events.
|
||||||
|
|
@ -557,6 +552,18 @@ MainFrame::MainFrame()
|
||||||
// Load default yaml config file.
|
// Load default yaml config file.
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
|
||||||
|
// Initialize the database
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_Database = std::make_unique<Database>();
|
||||||
|
m_Database->CreateTableSamples();
|
||||||
|
m_Database->CreateTableHives();
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
SH_LOG_ERROR("Error! Cannot initialize database {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
// Restore the data previously added to Library
|
// Restore the data previously added to Library
|
||||||
LoadDatabase();
|
LoadDatabase();
|
||||||
|
|
||||||
|
|
@ -712,7 +719,7 @@ void MainFrame::OnClickDirCtrl(wxCommandEvent& event)
|
||||||
void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event)
|
void MainFrame::OnDragAndDropToLibrary(wxDropFilesEvent& event)
|
||||||
{
|
{
|
||||||
SH_LOG_DEBUG("Start Inserting Samples");
|
SH_LOG_DEBUG("Start Inserting Samples");
|
||||||
|
|
||||||
if (event.GetNumberOfFiles() > 0)
|
if (event.GetNumberOfFiles() > 0)
|
||||||
{
|
{
|
||||||
wxString* dropped = event.GetFiles();
|
wxString* dropped = event.GetFiles();
|
||||||
|
|
@ -1631,13 +1638,13 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
std::string extension = GetFilenamePathAndExtension(selection).Extension;
|
std::string extension = GetFilenamePathAndExtension(selection).Extension;
|
||||||
|
|
||||||
wxMenu menu;
|
wxMenu menu;
|
||||||
|
|
||||||
//true = add false = remove
|
//true = add false = remove
|
||||||
bool favorite_add = false;
|
bool favorite_add = false;
|
||||||
|
|
||||||
if (m_Database->GetFavoriteColumnValueByFilename(filename) == 1)
|
if (m_Database->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
|
||||||
{
|
{
|
||||||
menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive"));
|
menu.Append(MN_FavoriteSample, _("Add to hive"), _("Add selected sample(s) to hive"));
|
||||||
favorite_add = true;
|
favorite_add = true;
|
||||||
|
|
@ -1645,7 +1652,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database"));
|
menu.Append(MN_DeleteSample, _("Delete"), _("Delete the selected sample(s) from database"));
|
||||||
menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash"));
|
menu.Append(MN_TrashSample, _("Trash"), _("Send the selected sample(s) to trash"));
|
||||||
|
|
||||||
if (m_Library->GetSelectedItemsCount() <= 1)
|
if (m_Library->GetSelectedItemsCount() <= 1)
|
||||||
{
|
{
|
||||||
menu.Append(MN_EditTagSample, _("Edit tags"),
|
menu.Append(MN_EditTagSample, _("Edit tags"),
|
||||||
|
|
@ -1710,7 +1717,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
|
|
||||||
m_Database->UpdateFavoriteColumn(filename, 1);
|
m_Database->UpdateFavoriteColumn(filename, 1);
|
||||||
m_Database->UpdateHiveName(filename, hive_name);
|
m_Database->UpdateHiveName(filename, hive_name);
|
||||||
|
|
||||||
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
for (int i = 0; i < m_Hives->GetChildCount(root); i++)
|
||||||
{
|
{
|
||||||
container = m_Hives->GetNthChild(root, i);
|
container = m_Hives->GetNthChild(root, i);
|
||||||
|
|
@ -1724,7 +1731,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//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);
|
||||||
|
|
@ -1732,7 +1739,7 @@ void MainFrame::OnShowLibraryContextMenu(wxDataViewEvent& event)
|
||||||
m_Database->UpdateFavoriteColumn(filename, 0);
|
m_Database->UpdateFavoriteColumn(filename, 0);
|
||||||
m_Database->UpdateHiveName(filename,
|
m_Database->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++)
|
||||||
{
|
{
|
||||||
container = m_Hives->GetNthChild(root, i);
|
container = m_Hives->GetNthChild(root, i);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue