Made a start on amending the code to take advantage of

the sqlite view capability VIEW UserZookoIDs

Made add_name responsive, but add_name still
does not use the VIEW triggers.

Got distracted by sizing issues.  There is some issues
with resizing architecture - I know they put an ad hoc
workaround in on dialogs, need to read up on what they
did and why.
This commit is contained in:
Cheng 2023-11-10 12:00:15 +00:00
parent 84c6984e40
commit 35a3be9aa7
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
5 changed files with 112 additions and 95 deletions

View File

@ -12,10 +12,9 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
walletfile.GetFullPath().append(" does not exist.").ToUTF8(),
__LINE__, __func__, SrcFilename);
m_db.reset(Sqlite3_open(walletfile.GetFullPath().ToUTF8()));
m_insert_name.reset(new sql_insert_name(m_db));
m_read_from_misc.reset(new sql_read_from_misc(m_db));
m_read_names_and_keys.reset(new ro::sql(m_db,
R"|(SELECT "Names".name AS name, "Keys".pubkey AS pubkey FROM "Names" INNER JOIN "Keys" )|"
R"|(ON "Names"."ROWID"="Keys".id AND "Keys".use=1 ORDER BY LOWER(name), name COLLATE BINARY;)|"));
m_read_names_and_keys.reset(new ro::sql(m_db, R"|(SELECT * FROM "UserZookoIDs" )|"));
if (!(*m_read_from_misc)(1) || m_read_from_misc->value<int64_t>() != WALLET_FILE_IDENTIFIER)throw MyException(sz_unrecognizable_wallet_file_format);
if (!(*m_read_from_misc)(2) || m_read_from_misc->value<int64_t>() != WALLET_FILE_SCHEMA_VERSION_0_0 || !(*m_read_from_misc)(4))throw MyException(sz_unrecognized_wallet_schema);
m_MasterSecret= *(m_read_from_misc->value<ristretto255::scalar>());
@ -24,52 +23,12 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
auto sizer = new wxBoxSizer(wxHORIZONTAL);
m_lSizer = new wxBoxSizer(wxVERTICAL);
m_rSizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(m_lSizer, 0, wxGROW, 4);
sizer->Add(m_rSizer, 50, wxGROW, 4);
sizer->Add(m_lSizer, 0, 0, 4);
sizer->Add(m_rSizer, 50, 0, 4);
SetSizer(sizer);
try {
while (m_read_names_and_keys->step() == Icompiled_sql::ROW) {
std::string name = m_read_names_and_keys->column<const char*>(0);
auto pubkey = *(m_read_names_and_keys->column<ristretto255::point>(1));
if (m_MasterSecret(name).timesBase() != pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
m_lSizer->Add(
new wxStaticText(
this,
wxID_ANY,
name,
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_ELLIPSIZE_END
),
10,
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
m_rSizer->Add(
new wxStaticText(
this,
wxID_ANY,
"#" + base58(pubkey).operator std::string(),
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END
),
10,
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
}
}
catch (const MyException& e) {
throw MyException(e, __LINE__, __func__, SrcFilename);
// sql exceptions tend to be unintelligible and excessively generic
// because unclear what statement provoked them.
}
catch (const std::exception& e) {
throw MyException(e, __LINE__, __func__, SrcFilename);
}
catch (...) {
szError = sz_unknown_error;
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
}
Bind(wxEVT_CLOSE_WINDOW, &display_wallet::OnClose, this);
refresh_from_database();
this->SetSize(this->GetParent()->GetClientSize());
Bind(wxEVT_CLOSE_WINDOW, &display_wallet::OnClose, this);
singletonFrame->m_LastUsedWallet.Assign(walletfile);
m_DisplayWalletEditMenu.Menu->Append(
@ -93,8 +52,6 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
szError = sz_unknown_error;
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
}
}
display_wallet::~display_wallet() {
@ -114,12 +71,12 @@ and a public key defined by the name and the wallet master secret)",
if (dialog.ShowModal() == wxID_OK)
{
std::string zookoNickname(dialog.GetValue().ToUTF8());
sql_insert_name insert_name(m_db);
auto zookoNickname_psz = zookoNickname.c_str();
insert_name(
(*m_insert_name)(
zookoNickname_psz,
m_MasterSecret(zookoNickname_psz).timesBase()
);
refresh_from_database();
}
}
@ -134,3 +91,62 @@ void display_wallet::OnClose(wxCloseEvent& event) {
if (singletonFrame->m_panel ==this)singletonFrame->m_panel = nullptr;
}
void display_wallet::refresh_from_database() {
auto sizer = this->GetSizer();
auto m_lsizer = sizer->GetItem((size_t)0)->GetSizer();
assert(m_lsizer);
auto m_rsizer = sizer->GetItem(1)->GetSizer();
assert(m_rsizer);
m_lsizer->Clear();
m_rsizer->Clear();
try {
m_read_names_and_keys->reset();
while (m_read_names_and_keys->step() == Icompiled_sql::ROW) {
std::string name = m_read_names_and_keys->column<const char*>(0);
auto pubkey = *(m_read_names_and_keys->column<ristretto255::point>(1));
if (m_MasterSecret(name).timesBase() != pubkey)throw MyException(std::string(sz_public_key_of) + name + sz_fails_to_correspond);
m_lSizer->Add(
new wxStaticText(
this,
wxID_ANY,
name,
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_ELLIPSIZE_END
),
10,
wxALL, // and make border all around
2);
m_rSizer->Add(
new wxStaticText(
this,
wxID_ANY,
"#" + base58(pubkey).operator std::string(),
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END
),
10,
wxALL, // and make border all around
2);
}
}
catch (const MyException& e) {
throw MyException(e, __LINE__, __func__, SrcFilename);
// sql exceptions tend to be unintelligible and excessively generic
// because unclear what statement provoked them.
}
catch (const std::exception& e) {
throw MyException(e, __LINE__, __func__, SrcFilename);
}
catch (...) {
szError = sz_unknown_error;
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
}
auto desired_size = sizer->ComputeFittingClientSize(singletonFrame);
singletonFrame->SetMinClientSize(desired_size);
auto clientSize = singletonFrame->GetClientSize();
desired_size.IncTo(clientSize);
if (desired_size.GetHeight() > clientSize.GetHeight()
|| desired_size.GetWidth() > clientSize.GetWidth()
)singletonFrame->SetClientSize(desired_size);
}

View File

@ -9,6 +9,8 @@ private:
std::unique_ptr<ISqlite3> m_db;
std::unique_ptr <sql_read_from_misc> m_read_from_misc;
std::unique_ptr <ro::sql> m_read_names_and_keys;
std::unique_ptr <sql_insert_name> m_insert_name;
ristretto255::CMasterSecret m_MasterSecret;
wxBoxSizer* m_lSizer;
wxBoxSizer* m_rSizer;
@ -16,4 +18,5 @@ private:
void add_name_event_handler(wxCommandEvent&);
void OnClose(wxCloseEvent& event);
wxMenuTracker m_DisplayWalletEditMenu;
void refresh_from_database();
};

View File

@ -10,27 +10,50 @@ wxMenuTracker::wxMenuTracker(const int i) : Menu(new wxMenu), MenuPosition(i) {}
wxMenu* wxMenuTracker::InitialAndFinal[]{ nullptr, new wxMenu, nullptr };
void wxMenuTracker::Replace() {
singletonFrame->GetMenuBar()->Replace(
MenuPosition,
Menu,
menu_strings[MenuPosition].head
);
singletonFrame->GetMenuBar()->EnableTop(MenuPosition, true); //enable edit menu.
auto menuBar = singletonFrame->GetMenuBar();
if ((menuBar->GetMenu(MenuPosition) != Menu)) {
menuBar->Replace(
MenuPosition,
Menu,
menu_strings[MenuPosition].head
);
menuBar->EnableTop(MenuPosition, true); //enable edit menu.
}
};
wxMenuTracker::~wxMenuTracker() {
auto menu_bar = singletonFrame->GetMenuBar();
if (menu_bar->GetMenu(MenuPosition) == Menu) {
auto menuBar = singletonFrame->GetMenuBar();
if (menuBar->GetMenu(MenuPosition) == Menu) {
assert(InitialAndFinal[MenuPosition]);
menu_bar->Replace(
menuBar->Replace(
MenuPosition,
InitialAndFinal[MenuPosition],
menu_strings[MenuPosition].head
);
menu_bar->EnableTop(MenuPosition, false);
menuBar->EnableTop(MenuPosition, false);
delete Menu;
}
};
void wxMenuTracker::check_dynamic_menus_absent() {
if constexpr (debug_mode) {
// Check that the values of all replaceable menus
// are at their default values as if the window handling them
// had just been destroyed and not yet replaced.
auto menuBar = singletonFrame->GetMenuBar();
for (int i = 0; i < std::size(InitialAndFinal); i++) {
assert(
!InitialAndFinal[i]
||
(
InitialAndFinal[i] == menuBar->GetMenu(i)
&&
!menuBar->IsEnabledTop(i)
)
);
}
}
}
// ----------------------------------------------------------------------------
// frame
// ----------------------------------------------------------------------------
@ -199,21 +222,10 @@ Frame::Frame(const wxString& wxs)
SetMenuBar(menuBar);
menuBar->EnableTop(1, false); //disable edit menu.
if constexpr (debug_mode) {
// Check that the initial values of all replaceable menus
// are at their default values as if the window handling them
// had just been destroyed and not yet replaced.
for (int i = 0; i < std::size(wxMenuTracker::InitialAndFinal); i++) {
assert(
!wxMenuTracker::InitialAndFinal[i]
||
(
wxMenuTracker::InitialAndFinal[i] == menuBar->GetMenu(i)
&&
!menuBar->IsEnabledTop(i)
)
);
}
wxMenuTracker::check_dynamic_menus_absent();
// Because the initial values of the dynamic menus are not being deleted by the child windows
// that own the modified windows, they need to be the same as the final values,
// which is to say, the values in wxMenuTracker::InitialAndFinal[]
}
CreateStatusBar();
// child controls
@ -374,8 +386,7 @@ SELECT
"Keys".pubkey AS pubkey
FROM "Names" INNER JOIN "Keys"
ON "Names"."ROWID"="Keys"."id" AND "Keys"."use"=1
ORDER BY LOWER("name"), "name"
COLLATE BINARY;
ORDER BY LOWER("name"), "name" COLLATE BINARY;
COMMIT;
BEGIN IMMEDIATE TRANSACTION;
@ -555,7 +566,6 @@ void Frame::OnMenuOpen(wxMenuEvent& evt) {
Frame::~Frame() {
assert(singletonFrame == this);
singletonFrame = nullptr;
wxConfigBase& Config = singletonApp->m_Config;
StorePositionToConfig();
Config.SetPath(wxT("/TipOfTheDay"));
@ -567,21 +577,7 @@ Frame::~Frame() {
Config.SetPath(wxT("/"));
Config.Flush();
if constexpr (debug_mode) {
// Check that the final values of all replaceable menus
// are at what they should be because the window handling
// them should have been destroyed.
auto menuBar = this->GetMenuBar();
for (int i = 0; i < std::size(wxMenuTracker::InitialAndFinal); i++) {
assert(
!wxMenuTracker::InitialAndFinal[i]
||
(
wxMenuTracker::InitialAndFinal[i] == menuBar->GetMenu(i)
&&
!menuBar->IsEnabledTop(i)
)
);
}
wxMenuTracker::check_dynamic_menus_absent();
}
singletonFrame = nullptr;
}

View File

@ -21,6 +21,7 @@ struct wxMenuTracker {
// the frame initializer. In the debug build, congruence between the menu bar
// and InitialAndFinal should be checked with assert.
static wxMenu* InitialAndFinal[3];
static void check_dynamic_menus_absent();
wxMenuTracker(wxMenuTracker&&) = delete; // Move constructor
wxMenuTracker(const wxMenuTracker&) = delete; // Copy constructor
wxMenuTracker& operator=(wxMenuTracker&&) = delete; // Move assignment.

View File

@ -138,6 +138,7 @@ welcome_to_rhocoin::welcome_to_rhocoin(
Bind(wxEVT_CLOSE_WINDOW, &welcome_to_rhocoin::OnClose, this);
assert(singletonWelcome == nullptr);
singletonWelcome = this;
singletonFrame->SetMinClientSize(sizer->ComputeFittingClientSize(singletonFrame));
}
welcome_to_rhocoin::~welcome_to_rhocoin() {