<commit_before>#include <mu_coin_qt/qt.hpp>

#include <cryptopp/sha.h>

#include <sstream>

mu_coin_qt::gui::gui (QApplication & application_a, mu_coin::client & client_a) :
client (client_a),
application (application_a),
main_stack (new QStackedWidget),
settings_window (new QWidget),
settings_layout (new QVBoxLayout),
settings_port_label (new QLabel ((std::string ("Port: ") + std::to_string (client_a.network.socket.local_endpoint ().port ())).c_str ())),
settings_connect_label (new QLabel ("Connect to IP:Port")),
settings_connect_line (new QLineEdit),
settings_connect_button (new QPushButton ("Connect")),
settings_bootstrap_button (new QPushButton ("Bootstrap")),
settings_password_label (new QLabel ("Password:")),
settings_password (new QLineEdit),
settings_back (new QPushButton ("Back")),
balance_main_window (new QWidget),
balance_main_window_layout (new QVBoxLayout),
balance_label (new QLabel),
entry_window (new QWidget),
entry_window_layout (new QVBoxLayout),
send_coins (new QPushButton ("Send")),
show_wallet (new QPushButton ("Wallet")),
settings (new QPushButton ("Settings")),
show_ledger (new QPushButton ("Ledger")),
send_coins_window (new QWidget),
send_coins_layout (new QVBoxLayout),
send_address_label (new QLabel ("Address:")),
send_address (new QLineEdit),
send_count_label (new QLabel ("Coins:")),
send_count (new QLineEdit),
send_coins_send (new QPushButton ("Send")),
send_coins_back (new QPushButton ("Back")),
wallet_window (new QWidget),
wallet_layout (new QVBoxLayout),
wallet_model (new QStringListModel),
wallet_view (new QListView),
wallet_refresh (new QPushButton ("Refresh")),
wallet_add_account (new QPushButton ("Add account")),
wallet_key_line (new QLineEdit),
wallet_add_key_button (new QPushButton ("Add key")),
wallet_back (new QPushButton ("Back")),
ledger_window (new QWidget),
ledger_layout (new QVBoxLayout),
ledger_model (new QStringListModel),
ledger_view (new QListView),
ledger_refresh (new QPushButton ("Refresh")),
ledger_back (new QPushButton ("Back")),
wallet_account_menu (new QMenu),
wallet_account_copy (new QAction ("Copy", wallet_account_menu)),
wallet_account_cancel (new QAction ("Cancel", wallet_account_menu))
{    
    send_coins_layout->addWidget (send_address_label);
    send_coins_layout->addWidget (send_address);
    send_coins_layout->addWidget (send_count_label);
    send_coins_layout->addWidget (send_count);
    send_coins_layout->addWidget (send_coins_send);
    send_coins_layout->addWidget (send_coins_back);
    send_coins_layout->setContentsMargins (0, 0, 0, 0);
    send_coins_window->setLayout (send_coins_layout);
    
    wallet_view->setModel (wallet_model);
    wallet_view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu);
    wallet_layout->addWidget (wallet_view);
    wallet_layout->addWidget (wallet_refresh);
    wallet_layout->addWidget (wallet_add_account);
    wallet_layout->addWidget (wallet_key_line);
    wallet_layout->addWidget (wallet_add_key_button);
    wallet_layout->addWidget (wallet_back);
    wallet_layout->setContentsMargins (0, 0, 0, 0);
    wallet_window->setLayout (wallet_layout);
    
    wallet_account_menu->addAction (wallet_account_copy);
    wallet_account_menu->addAction (wallet_account_cancel);
    
    ledger_view->setModel (ledger_model);
    ledger_layout->addWidget (ledger_view);
    ledger_layout->addWidget (ledger_refresh);
    ledger_layout->addWidget (ledger_back);
    ledger_window->setLayout (ledger_layout);
    
    entry_window_layout->addWidget (send_coins);
    entry_window_layout->addWidget (show_wallet);
    entry_window_layout->addWidget (settings);
    entry_window_layout->addWidget (show_ledger);
    entry_window_layout->setContentsMargins (0, 0, 0, 0);
    entry_window->setLayout (entry_window_layout);
    
    main_stack->addWidget (entry_window);
    
    balance_main_window_layout->addWidget (balance_label);
    balance_main_window_layout->addWidget (main_stack);
    balance_main_window_layout->setSpacing (0);
    balance_main_window->setLayout (balance_main_window_layout);
    
    settings_layout->addWidget (settings_port_label);
    settings_layout->addWidget (settings_connect_label);
    settings_layout->addWidget (settings_connect_line);
    settings_layout->addWidget (settings_connect_button);
    settings_layout->addWidget (settings_bootstrap_button);
    settings_layout->addWidget (settings_password_label);
    settings_password->setEchoMode (QLineEdit::EchoMode::Password);
    settings_layout->addWidget (settings_password);
    settings_layout->addWidget (settings_back);
    settings_window->setLayout (settings_layout);
    
    QObject::connect (wallet_add_key_button, &QPushButton::released, [this] ()
    {
        QString key_text_wide (wallet_key_line->text ());
        std::string key_text (key_text_wide.toLocal8Bit ());
        mu_coin::private_key key;
        if (!key.decode_hex (key_text))
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::black);
            wallet_key_line->setPalette (palette);
            wallet_key_line->clear ();
            client.wallet.insert (key, client.wallet.password);
            refresh_wallet ();
        }
        else
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::red);
            wallet_key_line->setPalette (palette);
        }
    });
    QObject::connect (settings_bootstrap_button, &QPushButton::released, [this] ()
    {
        QString address_text_wide (settings_connect_line->text ());
        std::string address_text (address_text_wide.toLocal8Bit ());
        mu_coin::tcp_endpoint endpoint;
        if (!mu_coin::parse_tcp_endpoint (address_text, endpoint))
        {
          QPalette palette;
          palette.setColor (QPalette::Text, Qt::black);
          settings_connect_line->setPalette (palette);
          client.processor.bootstrap (endpoint);
          settings_connect_line->clear ();
        }
        else
        {
          QPalette palette;
          palette.setColor (QPalette::Text, Qt::red);
          settings_connect_line->setPalette (palette);
        }
    });
    
    QObject::connect (settings_connect_button, &QPushButton::released, [this] ()
    {
        QString address_text_wide (settings_connect_line->text ());
        std::string address_text (address_text_wide.toLocal8Bit ());
        mu_coin::endpoint endpoint;
        if (!mu_coin::parse_endpoint (address_text, endpoint))
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::black);
            settings_connect_line->setPalette (palette);
            client.network.send_keepalive (endpoint);
            settings_connect_line->clear ();
        }
        else
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::red);<commit_msg>Disabling bootstrap button while it's in process.<commit_after>#include <mu_coin_qt/qt.hpp>

#include <cryptopp/sha.h>

#include <sstream>

mu_coin_qt::gui::gui (QApplication & application_a, mu_coin::client & client_a) :
client (client_a),
application (application_a),
main_stack (new QStackedWidget),
settings_window (new QWidget),
settings_layout (new QVBoxLayout),
settings_port_label (new QLabel ((std::string ("Port: ") + std::to_string (client_a.network.socket.local_endpoint ().port ())).c_str ())),
settings_connect_label (new QLabel ("Connect to IP:Port")),
settings_connect_line (new QLineEdit),
settings_connect_button (new QPushButton ("Connect")),
settings_bootstrap_button (new QPushButton ("Bootstrap")),
settings_password_label (new QLabel ("Password:")),
settings_password (new QLineEdit),
settings_back (new QPushButton ("Back")),
balance_main_window (new QWidget),
balance_main_window_layout (new QVBoxLayout),
balance_label (new QLabel),
entry_window (new QWidget),
entry_window_layout (new QVBoxLayout),
send_coins (new QPushButton ("Send")),
show_wallet (new QPushButton ("Wallet")),
settings (new QPushButton ("Settings")),
show_ledger (new QPushButton ("Ledger")),
send_coins_window (new QWidget),
send_coins_layout (new QVBoxLayout),
send_address_label (new QLabel ("Address:")),
send_address (new QLineEdit),
send_count_label (new QLabel ("Coins:")),
send_count (new QLineEdit),
send_coins_send (new QPushButton ("Send")),
send_coins_back (new QPushButton ("Back")),
wallet_window (new QWidget),
wallet_layout (new QVBoxLayout),
wallet_model (new QStringListModel),
wallet_view (new QListView),
wallet_refresh (new QPushButton ("Refresh")),
wallet_add_account (new QPushButton ("Add account")),
wallet_key_line (new QLineEdit),
wallet_add_key_button (new QPushButton ("Add key")),
wallet_back (new QPushButton ("Back")),
ledger_window (new QWidget),
ledger_layout (new QVBoxLayout),
ledger_model (new QStringListModel),
ledger_view (new QListView),
ledger_refresh (new QPushButton ("Refresh")),
ledger_back (new QPushButton ("Back")),
wallet_account_menu (new QMenu),
wallet_account_copy (new QAction ("Copy", wallet_account_menu)),
wallet_account_cancel (new QAction ("Cancel", wallet_account_menu))
{    
    send_coins_layout->addWidget (send_address_label);
    send_coins_layout->addWidget (send_address);
    send_coins_layout->addWidget (send_count_label);
    send_coins_layout->addWidget (send_count);
    send_coins_layout->addWidget (send_coins_send);
    send_coins_layout->addWidget (send_coins_back);
    send_coins_layout->setContentsMargins (0, 0, 0, 0);
    send_coins_window->setLayout (send_coins_layout);
    
    wallet_view->setModel (wallet_model);
    wallet_view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu);
    wallet_layout->addWidget (wallet_view);
    wallet_layout->addWidget (wallet_refresh);
    wallet_layout->addWidget (wallet_add_account);
    wallet_layout->addWidget (wallet_key_line);
    wallet_layout->addWidget (wallet_add_key_button);
    wallet_layout->addWidget (wallet_back);
    wallet_layout->setContentsMargins (0, 0, 0, 0);
    wallet_window->setLayout (wallet_layout);
    
    wallet_account_menu->addAction (wallet_account_copy);
    wallet_account_menu->addAction (wallet_account_cancel);
    
    ledger_view->setModel (ledger_model);
    ledger_layout->addWidget (ledger_view);
    ledger_layout->addWidget (ledger_refresh);
    ledger_layout->addWidget (ledger_back);
    ledger_window->setLayout (ledger_layout);
    
    entry_window_layout->addWidget (send_coins);
    entry_window_layout->addWidget (show_wallet);
    entry_window_layout->addWidget (settings);
    entry_window_layout->addWidget (show_ledger);
    entry_window_layout->setContentsMargins (0, 0, 0, 0);
    entry_window->setLayout (entry_window_layout);
    
    main_stack->addWidget (entry_window);
    
    balance_main_window_layout->addWidget (balance_label);
    balance_main_window_layout->addWidget (main_stack);
    balance_main_window_layout->setSpacing (0);
    balance_main_window->setLayout (balance_main_window_layout);
    
    settings_layout->addWidget (settings_port_label);
    settings_layout->addWidget (settings_connect_label);
    settings_layout->addWidget (settings_connect_line);
    settings_layout->addWidget (settings_connect_button);
    settings_layout->addWidget (settings_bootstrap_button);
    settings_layout->addWidget (settings_password_label);
    settings_password->setEchoMode (QLineEdit::EchoMode::Password);
    settings_layout->addWidget (settings_password);
    settings_layout->addWidget (settings_back);
    settings_window->setLayout (settings_layout);
    
    QObject::connect (wallet_add_key_button, &QPushButton::released, [this] ()
    {
        QString key_text_wide (wallet_key_line->text ());
        std::string key_text (key_text_wide.toLocal8Bit ());
        mu_coin::private_key key;
        if (!key.decode_hex (key_text))
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::black);
            wallet_key_line->setPalette (palette);
            wallet_key_line->clear ();
            client.wallet.insert (key, client.wallet.password);
            refresh_wallet ();
        }
        else
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::red);
            wallet_key_line->setPalette (palette);
        }
    });
    QObject::connect (settings_bootstrap_button, &QPushButton::released, [this] ()
    {
        QString address_text_wide (settings_connect_line->text ());
        std::string address_text (address_text_wide.toLocal8Bit ());
        mu_coin::tcp_endpoint endpoint;
        if (!mu_coin::parse_tcp_endpoint (address_text, endpoint))
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::black);
            settings_connect_line->setPalette (palette);
            settings_bootstrap_button->setEnabled (false);
            settings_bootstrap_button->setText ("Bootstrapping...");
            client.processor.bootstrap (endpoint, [this] () {settings_bootstrap_button->setText ("Bootstrap"); settings_bootstrap_button->setEnabled (true);});
            settings_connect_line->clear ();
        }
        else
        {
          QPalette palette;
          palette.setColor (QPalette::Text, Qt::red);
          settings_connect_line->setPalette (palette);
        }
    });
    
    QObject::connect (settings_connect_button, &QPushButton::released, [this] ()
    {
        QString address_text_wide (settings_connect_line->text ());
        std::string address_text (address_text_wide.toLocal8Bit ());
        mu_coin::endpoint endpoint;
        if (!mu_coin::parse_endpoint (address_text, endpoint))
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::black);
            settings_connect_line->setPalette (palette);
            client.network.send_keepalive (endpoint);
            settings_connect_line->clear ();
        }
        else
        {
            QPalette palette;
            palette.setColor (QPalette::Text, Qt::red);
{'fraction_non_alphanumeric': 0.11535987420484597, 'fraction_numerical': 0.0022871846186834394, 'mean_word_length': 4.446477228493578, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1729586', 'n_tokens_mistral': 4321, 'n_tokens_neox': 4322, 'n_words': 790}