Skip to content

Commit f6991cb

Browse files
committed
qt, wallet: Add LoadWalletsActivity class
Also this commit moves wallets loading out from the main GUI thread.
1 parent 4a024fc commit f6991cb

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,8 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
659659
GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
660660
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
661661

662-
for (WalletModel* wallet_model : m_wallet_controller->getOpenWallets()) {
663-
addWallet(wallet_model);
664-
}
662+
auto activity = new LoadWalletsActivity(m_wallet_controller, this);
663+
activity->load();
665664
}
666665

667666
WalletController* BitcoinGUI::getWalletController()

src/qt/walletcontroller.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ WalletController::WalletController(ClientModel& client_model, const PlatformStyl
4141
getOrCreateWallet(std::move(wallet));
4242
});
4343

44-
for (std::unique_ptr<interfaces::Wallet>& wallet : m_node.walletClient().getWallets()) {
45-
getOrCreateWallet(std::move(wallet));
46-
}
47-
4844
m_activity_worker->moveToThread(m_activity_thread);
4945
m_activity_thread->start();
5046
QTimer::singleShot(0, m_activity_worker, []() {
@@ -342,3 +338,21 @@ void OpenWalletActivity::open(const std::string& path)
342338
QTimer::singleShot(0, this, &OpenWalletActivity::finish);
343339
});
344340
}
341+
342+
LoadWalletsActivity::LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget)
343+
: WalletControllerActivity(wallet_controller, parent_widget)
344+
{
345+
}
346+
347+
void LoadWalletsActivity::load()
348+
{
349+
showProgressDialog(tr("Loading wallets…"));
350+
351+
QTimer::singleShot(0, worker(), [this] {
352+
for (auto& wallet : node().walletClient().getWallets()) {
353+
m_wallet_controller->getOrCreateWallet(std::move(wallet));
354+
}
355+
356+
QTimer::singleShot(0, this, [this] { Q_EMIT finished(); });
357+
});
358+
}

src/qt/walletcontroller.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,14 @@ class OpenWalletActivity : public WalletControllerActivity
148148
void finish();
149149
};
150150

151+
class LoadWalletsActivity : public WalletControllerActivity
152+
{
153+
Q_OBJECT
154+
155+
public:
156+
LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
157+
158+
void load();
159+
};
160+
151161
#endif // BITCOIN_QT_WALLETCONTROLLER_H

0 commit comments

Comments
 (0)