Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ void BitcoinGUI::createActions()
connect(action, &QAction::triggered, [this, path] {
auto activity = new OpenWalletActivity(m_wallet_controller, this);
connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
connect(activity, &OpenWalletActivity::opened, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
activity->open(path);
});
}
Expand Down Expand Up @@ -488,7 +487,6 @@ void BitcoinGUI::createActions()

auto activity = new RestoreWalletActivity(m_wallet_controller, this);
connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
connect(activity, &RestoreWalletActivity::restored, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);

auto backup_file_path = fs::PathFromString(backup_file.toStdString());
activity->restore(backup_file_path, wallet_name.toStdString());
Expand Down Expand Up @@ -853,6 +851,7 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
{
if (!walletFrame || !m_wallet_controller) return;
walletFrame->setCurrentWallet(wallet_model);
rpcConsole->setDisplayedWallet(wallet_model);
for (int index = 0; index < m_wallet_selector->count(); ++index) {
if (m_wallet_selector->itemData(index).value<WalletModel*>() == wallet_model) {
m_wallet_selector->setCurrentIndex(index);
Expand Down Expand Up @@ -1330,7 +1329,6 @@ void BitcoinGUI::createWallet()
#ifdef ENABLE_WALLET
auto activity = new CreateWalletActivity(getWalletController(), this);
connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet);
connect(activity, &CreateWalletActivity::created, rpcConsole, &RPCConsole::setCurrentWallet);
activity->create();
#endif // ENABLE_WALLET
}
Expand Down
41 changes: 32 additions & 9 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
const QSize FONT_RANGE(4, 40);
const char fontSizeSettingsKey[] = "consoleFontSize";

#ifdef ENABLE_WALLET
//! Index of the wallet selector entry that follows the wallet displayed in the main window.
//! Entry 0 is "(none)", from the form; wallets are appended after this one.
const int WALLET_SELECTOR_DISPLAYED = 1;
#endif // ENABLE_WALLET

const struct {
const char *url;
const char *source;
Expand Down Expand Up @@ -626,6 +632,11 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);

#ifdef ENABLE_WALLET
ui->WalletSelector->insertItem(WALLET_SELECTOR_DISPLAYED, QString());
setDisplayedWallet(nullptr);
#endif // ENABLE_WALLET

// disable the wallet selector by default
ui->WalletSelector->setVisible(false);
ui->WalletSelectorLabel->setVisible(false);
Expand Down Expand Up @@ -981,11 +992,11 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
{
// use name for text and wallet model for internal data object (to allow to move to a wallet id later)
ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
if (ui->WalletSelector->count() == 2) {
// First wallet added, set to default to match wallet RPC behavior
ui->WalletSelector->setCurrentIndex(1);
if (ui->WalletSelector->count() == 3) {
// First wallet added, follow the wallet displayed in the main window
ui->WalletSelector->setCurrentIndex(WALLET_SELECTOR_DISPLAYED);
}
if (ui->WalletSelector->count() > 2) {
if (ui->WalletSelector->count() > 3) {
ui->WalletSelector->setVisible(true);
ui->WalletSelectorLabel->setVisible(true);
}
Expand All @@ -994,16 +1005,28 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
void RPCConsole::removeWallet(WalletModel * const walletModel)
{
ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel)));
if (ui->WalletSelector->count() == 2) {
if (ui->WalletSelector->count() == 3) {
ui->WalletSelector->setVisible(false);
ui->WalletSelectorLabel->setVisible(false);
}
// The main window switches to another wallet before removing this one, so
// this only hits when the last wallet is unloaded
if (m_displayed_wallet_model == walletModel) setDisplayedWallet(nullptr);
}

void RPCConsole::setDisplayedWallet(WalletModel* const wallet_model)
{
m_displayed_wallet_model = wallet_model;
ui->WalletSelector->setItemText(WALLET_SELECTOR_DISPLAYED,
wallet_model ? tr("Use displayed wallet (%1)").arg(wallet_model->getDisplayName())
: tr("Use displayed wallet"));
}

void RPCConsole::setCurrentWallet(WalletModel* const wallet_model)
WalletModel* RPCConsole::currentWalletModel() const
{
QVariant data = QVariant::fromValue(wallet_model);
ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data));
const int index = ui->WalletSelector->currentIndex();
if (index == WALLET_SELECTOR_DISPLAYED) return m_displayed_wallet_model;
return ui->WalletSelector->itemData(index).value<WalletModel*>();
}
#endif

Expand Down Expand Up @@ -1259,7 +1282,7 @@ void RPCConsole::on_lineEdit_returnPressed()

WalletModel* wallet_model{nullptr};
#ifdef ENABLE_WALLET
wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
wallet_model = currentWalletModel();

if (m_last_wallet_model != wallet_model) {
if (wallet_model) {
Expand Down
9 changes: 7 additions & 2 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public Q_SLOTS:
/** set which tab has the focus (is visible) */
void setTabFocus(enum TabTypes tabType);
#ifdef ENABLE_WALLET
/** Set the current (ie - active) wallet */
void setCurrentWallet(WalletModel* const wallet_model);
/** Set the wallet displayed in the main window, followed when the selector is on "Use displayed wallet" */
void setDisplayedWallet(WalletModel* const wallet_model);
#endif // ENABLE_WALLET

private:
Expand Down Expand Up @@ -198,6 +198,11 @@ public Q_SLOTS:
QThread thread;
RPCExecutor* m_executor{nullptr};
WalletModel* m_last_wallet_model{nullptr};
#ifdef ENABLE_WALLET
/** Wallet the selector resolves to while "Use displayed wallet" is selected */
WalletModel* m_displayed_wallet_model{nullptr};
WalletModel* currentWalletModel() const;
#endif // ENABLE_WALLET
bool m_is_executing{false};
QByteArray m_peer_widget_header_state;
QByteArray m_banlist_widget_header_state;
Expand Down
Loading