-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
1929 lines (1612 loc) · 72.6 KB
/
MainWindow.cpp
File metadata and controls
1929 lines (1612 loc) · 72.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: The Monero Project
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QCheckBox>
#include "constants.h"
#include "dialog/AddressCheckerIndexDialog.h"
#include "dialog/BalanceDialog.h"
#include "dialog/DebugInfoDialog.h"
#include "dialog/HistoryExportDialog.h"
#include "dialog/PasswordDialog.h"
#include "dialog/TxBroadcastDialog.h"
#include "dialog/TxConfAdvDialog.h"
#include "dialog/TxConfDialog.h"
#include "dialog/TxImportDialog.h"
#include "dialog/TxInfoDialog.h"
#include "dialog/TxPoolViewerDialog.h"
#include "dialog/ViewOnlyDialog.h"
#include "dialog/WalletInfoDialog.h"
#include "dialog/WalletCacheDebugDialog.h"
#include "libwalletqt/AddressBook.h"
#include "libwalletqt/rows/CoinsInfo.h"
#include "libwalletqt/rows/Output.h"
#include "libwalletqt/TransactionHistory.h"
#include "model/AddressBookModel.h"
#include "plugins/PluginRegistry.h"
#include "utils/AppData.h"
#include "utils/AsyncTask.h"
#include "utils/ColorScheme.h"
#include "utils/Icons.h"
#include "utils/TorManager.h"
#include "utils/WebsocketNotifier.h"
#include "wallet/wallet_errors.h"
#ifdef WITH_SCANNER
#include "wizard/offline_tx_signing/OfflineTxSigningWizard.h"
#include "qrcode/scanner/URDialog.h"
#endif
#ifdef CHECK_UPDATES
#include "utils/updater/UpdateDialog.h"
#endif
MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_windowManager(windowManager)
, m_wallet(wallet)
, m_nodes(new Nodes(this, wallet))
, m_rpc(new DaemonRpc(this, ""))
{
ui->setupUi(this);
// Ensure the destructor is called after closeEvent()
setAttribute(Qt::WA_DeleteOnClose);
m_splashDialog = new SplashDialog(this);
m_accountSwitcherDialog = new AccountSwitcherDialog(m_wallet, this);
#ifdef CHECK_UPDATES
m_updater = QSharedPointer<Updater>(new Updater(this));
#endif
this->restoreGeo();
this->initStatusBar();
this->initPlugins();
this->initWidgets();
this->initMenu();
this->initOffline();
this->initWalletContext();
emit uiSetup();
this->onOfflineMode(conf()->get(Config::offlineMode).toBool());
conf()->set(Config::restartRequired, false);
// Websocket notifier
#ifdef CHECK_UPDATES
connect(websocketNotifier(), &WebsocketNotifier::UpdatesReceived, m_updater.data(), &Updater::wsUpdatesReceived);
#endif
websocketNotifier()->emitCache(); // Get cached data
connect(m_windowManager, &WindowManager::websocketStatusChanged, this, &MainWindow::onWebsocketStatusChanged);
this->onWebsocketStatusChanged(!conf()->get(Config::disableWebsocket).toBool());
connect(m_windowManager, &WindowManager::proxySettingsChanged, this, &MainWindow::onProxySettingsChangedConnect);
connect(m_windowManager, &WindowManager::updateBalance, m_wallet, &Wallet::updateBalance);
connect(m_windowManager, &WindowManager::offlineMode, this, &MainWindow::onOfflineMode);
connect(m_windowManager, &WindowManager::manualFeeSelectionEnabled, this, &MainWindow::onManualFeeSelectionEnabled);
connect(m_windowManager, &WindowManager::subtractFeeFromAmountEnabled, this, &MainWindow::onSubtractFeeFromAmountEnabled);
connect(torManager(), &TorManager::connectionStateChanged, this, &MainWindow::onTorConnectionStateChanged);
this->onTorConnectionStateChanged(torManager()->torConnected);
#ifdef CHECK_UPDATES
connect(m_updater.data(), &Updater::updateAvailable, this, &MainWindow::showUpdateNotification);
#endif
ColorScheme::updateFromWidget(this);
QTimer::singleShot(1, [this]{this->updateWidgetIcons();});
// Timers
connect(&m_updateBytes, &QTimer::timeout, this, &MainWindow::updateNetStats);
connect(&m_txTimer, &QTimer::timeout, [this]{
m_statusLabelStatus->setText("Constructing transaction" + this->statusDots());
});
conf()->set(Config::firstRun, false);
this->onWalletOpened();
connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &MainWindow::updateBalance);
connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &MainWindow::updateBalance);
connect(m_windowManager->eventFilter, &EventFilter::userActivity, this, &MainWindow::userActivity);
connect(&m_checkUserActivity, &QTimer::timeout, this, &MainWindow::checkUserActivity);
m_checkUserActivity.setInterval(5000);
m_checkUserActivity.start();
}
void MainWindow::initStatusBar() {
#if defined(Q_OS_WIN)
// No separators between statusbar widgets
this->statusBar()->setStyleSheet("QStatusBar::item {border: None;}");
#endif
this->statusBar()->setFixedHeight(30);
m_statusLabelStatus = new QLabel("Idle", this);
m_statusLabelStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
this->statusBar()->addWidget(m_statusLabelStatus);
m_statusLabelNetStats = new QLabel("", this);
m_statusLabelNetStats->setTextInteractionFlags(Qt::TextSelectableByMouse);
this->statusBar()->addWidget(m_statusLabelNetStats);
m_statusUpdateAvailable = new QPushButton(this);
m_statusUpdateAvailable->setFlat(true);
m_statusUpdateAvailable->setCursor(Qt::PointingHandCursor);
m_statusUpdateAvailable->setIcon(icons()->icon("tab_party.png"));
m_statusUpdateAvailable->hide();
this->statusBar()->addPermanentWidget(m_statusUpdateAvailable);
m_statusLabelBalance = new ClickableLabel(this);
m_statusLabelBalance->setText("Balance: 0 XMR");
m_statusLabelBalance->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_statusLabelBalance->setCursor(Qt::PointingHandCursor);
this->statusBar()->addPermanentWidget(m_statusLabelBalance);
connect(m_statusLabelBalance, &ClickableLabel::clicked, this, &MainWindow::showBalanceDialog);
m_statusBtnConnectionStatusIndicator = new StatusBarButton(icons()->icon("status_disconnected.svg"), "Connection status", this);
connect(m_statusBtnConnectionStatusIndicator, &StatusBarButton::clicked, [this](){
this->onShowSettingsPage(Settings::Pages::NETWORK);
});
this->statusBar()->addPermanentWidget(m_statusBtnConnectionStatusIndicator);
this->onConnectionStatusChanged(Wallet::ConnectionStatus_Disconnected);
m_statusAccountSwitcher = new StatusBarButton(icons()->icon("change_account.png"), "Account switcher", this);
connect(m_statusAccountSwitcher, &StatusBarButton::clicked, this, &MainWindow::showAccountSwitcherDialog);
this->statusBar()->addPermanentWidget(m_statusAccountSwitcher);
m_statusBtnPassword = new StatusBarButton(icons()->icon("lock.svg"), "Password", this);
connect(m_statusBtnPassword, &StatusBarButton::clicked, this, &MainWindow::showPasswordDialog);
this->statusBar()->addPermanentWidget(m_statusBtnPassword);
m_statusBtnPreferences = new StatusBarButton(icons()->icon("preferences.svg"), "Settings", this);
connect(m_statusBtnPreferences, &StatusBarButton::clicked, this, &MainWindow::menuSettingsClicked);
this->statusBar()->addPermanentWidget(m_statusBtnPreferences);
m_statusBtnSeed = new StatusBarButton(icons()->icon("seed.png"), "Seed", this);
connect(m_statusBtnSeed, &StatusBarButton::clicked, this, &MainWindow::showSeedDialog);
this->statusBar()->addPermanentWidget(m_statusBtnSeed);
m_statusBtnProxySettings = new StatusBarButton(icons()->icon("tor_logo_disabled.png"), "Proxy settings", this);
connect(m_statusBtnProxySettings, &StatusBarButton::clicked, this, &MainWindow::menuProxySettingsClicked);
this->statusBar()->addPermanentWidget(m_statusBtnProxySettings);
this->onProxySettingsChanged();
m_statusBtnHwDevice = new StatusBarButton(this->hardwareDevicePairedIcon(), this->getHardwareDevice(), this);
connect(m_statusBtnHwDevice, &StatusBarButton::clicked, this, &MainWindow::menuHwDeviceClicked);
this->statusBar()->addPermanentWidget(m_statusBtnHwDevice);
m_statusBtnHwDevice->hide();
}
void MainWindow::initPlugins() {
const QStringList enabledPlugins = conf()->get(Config::enabledPlugins).toStringList();
for (const auto& plugin_creator : PluginRegistry::getPluginCreators()) {
Plugin* plugin = plugin_creator();
if (!PluginRegistry::getInstance().isPluginEnabled(plugin->id())) {
continue;
}
qDebug() << "Initializing plugin: " << plugin->id();
plugin->initialize(m_wallet, this);
connect(plugin, &Plugin::setStatusText, this, &MainWindow::setStatusText);
connect(plugin, &Plugin::fillSendTab, this, &MainWindow::fillSendTab);
connect(this, &MainWindow::updateIcons, plugin, &Plugin::skinChanged);
connect(this, &MainWindow::aboutToQuit, plugin, &Plugin::aboutToQuit);
connect(this, &MainWindow::uiSetup, plugin, &Plugin::uiSetup);
m_plugins.append(plugin);
}
std::sort(m_plugins.begin(), m_plugins.end(), [](Plugin *a, Plugin *b) {
return a->idx() < b->idx();
});
}
void MainWindow::initWidgets() {
// [History]
m_historyWidget = new HistoryWidget(m_wallet, this);
ui->historyWidgetLayout->addWidget(m_historyWidget);
connect(m_historyWidget, &HistoryWidget::viewOnBlockExplorer, this, &MainWindow::onViewOnBlockExplorer);
connect(m_historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction);
// [Send]
m_sendWidget = new SendWidget(m_wallet, this);
ui->sendWidgetLayout->addWidget(m_sendWidget);
// [Receive]
m_receiveWidget = new ReceiveWidget(m_wallet, this);
ui->receiveWidgetLayout->addWidget(m_receiveWidget);
connect(m_receiveWidget, &ReceiveWidget::showTransactions, [this](const QString &text) {
m_historyWidget->setSearchText(text);
ui->tabWidget->setCurrentIndex(this->findTab("History"));
});
// [Coins]
m_coinsWidget = new CoinsWidget(m_wallet, this);
ui->coinsWidgetLayout->addWidget(m_coinsWidget);
// [Contacts]
m_contactsWidget = new ContactsWidget(m_wallet, this);
ui->contactsWidgetLayout->addWidget(m_contactsWidget);
connect(m_contactsWidget, &ContactsWidget::fill, [this](const QString &address, const QString &description){
m_sendWidget->fill(address, description, 0, true);
ui->tabWidget->setCurrentIndex(this->findTab("Send"));
});
// [Notes]
ui->notes->setPlainText(m_wallet->getCacheAttribute("wallet.notes"));
connect(ui->notes, &QPlainTextEdit::textChanged, [this] {
m_wallet->setCacheAttribute("wallet.notes", ui->notes->toPlainText());
});
// [Plugins..]
for (auto* plugin : m_plugins) {
if (!plugin->hasParent()) {
qDebug() << "Adding tab: " << plugin->displayName();
if (plugin->insertFirst()) {
ui->tabWidget->insertTab(0, plugin->tab(), icons()->icon(plugin->icon()), plugin->displayName());
} else {
ui->tabWidget->addTab(plugin->tab(), icons()->icon(plugin->icon()), plugin->displayName());
}
for (auto* child : m_plugins) {
if (child->hasParent() && child->parent() == plugin->id()) {
plugin->addSubPlugin(child);
}
}
}
}
ui->frame_coinControl->setVisible(false);
connect(ui->btn_resetCoinControl, &QPushButton::clicked, [this]{
m_wallet->setSelectedInputs({});
});
m_walletUnlockWidget = new WalletUnlockWidget(this, m_wallet);
m_walletUnlockWidget->setWalletName(this->walletName());
ui->walletUnlockLayout->addWidget(m_walletUnlockWidget);
connect(m_walletUnlockWidget, &WalletUnlockWidget::closeWallet, this, &MainWindow::close);
connect(m_walletUnlockWidget, &WalletUnlockWidget::unlockWallet, this, &MainWindow::unlockWallet);
ui->tabWidget->setCurrentIndex(0);
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::initMenu() {
// TODO: Rename actions to follow style
// [File]
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::menuOpenClicked);
connect(ui->actionNew_Restore, &QAction::triggered, this, &MainWindow::menuNewRestoreClicked);
connect(ui->actionLock, &QAction::triggered, this, &MainWindow::lockWallet);
connect(ui->actionClose, &QAction::triggered, this, &MainWindow::menuWalletCloseClicked); // Close current wallet
connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::menuQuitClicked); // Quit application
connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::menuSettingsClicked);
// [File] -> [Recently open]
m_clearRecentlyOpenAction = new QAction("Clear history", ui->menuFile);
connect(m_clearRecentlyOpenAction, &QAction::triggered, this, &MainWindow::menuClearHistoryClicked);
// [Wallet]
connect(ui->actionInformation, &QAction::triggered, this, &MainWindow::showWalletInfoDialog);
connect(ui->actionAccount, &QAction::triggered, this, &MainWindow::showAccountSwitcherDialog);
connect(ui->actionPassword, &QAction::triggered, this, &MainWindow::showPasswordDialog);
connect(ui->actionSeed, &QAction::triggered, this, &MainWindow::showSeedDialog);
connect(ui->actionKeys, &QAction::triggered, this, &MainWindow::showKeysDialog);
connect(ui->actionViewOnly, &QAction::triggered, this, &MainWindow::showViewOnlyDialog);
// [Wallet] -> [Advanced]
connect(ui->actionStore_wallet, &QAction::triggered, this, &MainWindow::tryStoreWallet);
connect(ui->actionUpdate_balance, &QAction::triggered, [this]{m_wallet->updateBalance();});
connect(ui->actionRefresh_tabs, &QAction::triggered, [this]{m_wallet->refreshModels();});
connect(ui->actionRescan_spent, &QAction::triggered, this, &MainWindow::rescanSpent);
connect(ui->actionWallet_cache_debug, &QAction::triggered, this, &MainWindow::showWalletCacheDebugDialog);
connect(ui->actionTxPoolViewer, &QAction::triggered, this, &MainWindow::showTxPoolViewerDialog);
// [Wallet] -> [History]
connect(ui->actionExport_CSV, &QAction::triggered, this, &MainWindow::onExportHistoryCSV);
connect(ui->actionImportHistoryCSV, &QAction::triggered, this, &MainWindow::onImportHistoryDescriptionsCSV);
// [View]
m_tabShowHideSignalMapper = new QSignalMapper(this);
connect(ui->actionShow_Searchbar, &QAction::toggled, this, &MainWindow::toggleSearchbar);
ui->actionShow_Searchbar->setChecked(conf()->get(Config::showSearchbar).toBool());
// Show/Hide Coins
connect(ui->actionShow_Coins, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map));
m_tabShowHideMapper["Coins"] = new ToggleTab(ui->tabCoins, "Coins", "Coins", ui->actionShow_Coins, this);
m_tabShowHideSignalMapper->setMapping(ui->actionShow_Coins, "Coins");
// Show/Hide Contacts
connect(ui->actionShow_Contacts, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map));
m_tabShowHideMapper["Contacts"] = new ToggleTab(ui->tabContacts, "Contacts", "Contacts", ui->actionShow_Contacts, this);
m_tabShowHideSignalMapper->setMapping(ui->actionShow_Contacts, "Contacts");
// Show/Hide Notes
connect(ui->actionShow_Notes, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map));
m_tabShowHideMapper["Notes"] = new ToggleTab(ui->tabNotes, "Notes", "Notes", ui->actionShow_Notes, this);
m_tabShowHideSignalMapper->setMapping(ui->actionShow_Notes, "Notes");
// Show/Hide Plugins..
for (const auto &plugin : m_plugins) {
if (plugin->parent() != "") {
continue;
}
auto* pluginAction = new QAction(plugin->displayName(), this);
ui->menuView->insertAction(plugin->insertFirst() ? ui->actionPlaceholderBegin : ui->actionPlaceholderEnd, pluginAction);
connect(pluginAction, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map));
m_tabShowHideMapper[plugin->displayName()] = new ToggleTab(plugin->tab(), plugin->displayName(), plugin->displayName(), pluginAction, this);
m_tabShowHideSignalMapper->setMapping(pluginAction, plugin->displayName());
}
ui->actionPlaceholderBegin->setVisible(false);
ui->actionPlaceholderEnd->setVisible(false);
QStringList enabledTabs = conf()->get(Config::enabledTabs).toStringList();
for (const auto &key: m_tabShowHideMapper.keys()) {
const auto toggleTab = m_tabShowHideMapper.value(key);
bool show = enabledTabs.contains(key);
toggleTab->menuAction->setText(toggleTab->name);
toggleTab->menuAction->setCheckable(true);
toggleTab->menuAction->setChecked(show);
ui->tabWidget->setTabVisible(ui->tabWidget->indexOf(toggleTab->tab), show);
}
connect(m_tabShowHideSignalMapper, &QSignalMapper::mappedString, this, &MainWindow::menuToggleTabVisible);
// [Tools]
connect(ui->actionSignVerify, &QAction::triggered, this, &MainWindow::menuSignVerifyClicked);
connect(ui->actionVerifyTxProof, &QAction::triggered, this, &MainWindow::menuVerifyTxProof);
connect(ui->actionKeyImageSync, &QAction::triggered, this, &MainWindow::showKeyImageSyncWizard);
connect(ui->actionLoadSignedTxFromFile, &QAction::triggered, this, &MainWindow::loadSignedTx);
connect(ui->actionLoadSignedTxFromText, &QAction::triggered, this, &MainWindow::loadSignedTxFromText);
connect(ui->actionImport_transaction, &QAction::triggered, this, &MainWindow::importTransaction);
connect(ui->actionTransmitOverUR, &QAction::triggered, this, &MainWindow::showURDialog);
connect(ui->actionPay_to_many, &QAction::triggered, this, &MainWindow::payToMany);
connect(ui->actionAddress_checker, &QAction::triggered, this, &MainWindow::showAddressChecker);
connect(ui->actionCreateDesktopEntry, &QAction::triggered, this, &MainWindow::onCreateDesktopEntry);
if (m_wallet->viewOnly()) {
ui->actionKeyImageSync->setText("Key image sync");
}
// TODO: Allow creating desktop entry on Windows and Mac
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
ui->actionCreateDesktopEntry->setDisabled(true);
#endif
#ifndef SELF_CONTAINED
ui->actionCreateDesktopEntry->setVisible(false);
#endif
// [Help]
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::menuAboutClicked);
#if defined(CHECK_UPDATES)
connect(ui->actionCheckForUpdates, &QAction::triggered, this, &MainWindow::showUpdateDialog);
#else
ui->actionCheckForUpdates->setVisible(false);
#endif
connect(ui->actionOfficialWebsite, &QAction::triggered, [this](){Utils::externalLinkWarning(this, "https://featherwallet.org");});
connect(ui->actionDocumentation, &QAction::triggered, this, &MainWindow::onShowDocumentation);
connect(ui->actionReport_bug, &QAction::triggered, this, &MainWindow::onReportBug);
connect(ui->actionShow_debug_info, &QAction::triggered, this, &MainWindow::showDebugInfo);
// Setup shortcuts
ui->actionStore_wallet->setShortcut(QKeySequence("Ctrl+S"));
ui->actionRefresh_tabs->setShortcut(QKeySequence("Ctrl+R"));
ui->actionOpen->setShortcut(QKeySequence("Ctrl+O"));
ui->actionNew_Restore->setShortcut(QKeySequence("Ctrl+N"));
ui->actionLock->setShortcut(QKeySequence("Ctrl+L"));
ui->actionClose->setShortcut(QKeySequence("Ctrl+W"));
ui->actionShow_debug_info->setShortcut(QKeySequence("Ctrl+D"));
ui->actionSettings->setShortcut(QKeySequence("Ctrl+Alt+S"));
ui->actionUpdate_balance->setShortcut(QKeySequence("Ctrl+U"));
ui->actionShow_Searchbar->setShortcut(QKeySequence("Ctrl+F"));
ui->actionDocumentation->setShortcut(QKeySequence("F1"));
}
void MainWindow::initOffline() {
// TODO: check if we have any cameras available
ui->btn_help->setFocusPolicy(Qt::NoFocus);
ui->btn_viewOnlyDetails->setFocusPolicy(Qt::NoFocus);
ui->btn_checkAddress->setFocusPolicy(Qt::NoFocus);
ui->btn_signTransaction->setFocusPolicy(Qt::StrongFocus);
ui->btn_signTransaction->setFocus();
connect(ui->btn_help, &QPushButton::clicked, [this] {
windowManager()->showDocs(this, "offline_tx_signing");
});
connect(ui->btn_viewOnlyDetails, &QPushButton::clicked, [this] {
this->showViewOnlyDialog();
});
connect(ui->btn_checkAddress, &QPushButton::clicked, [this]{
AddressCheckerIndexDialog dialog{m_wallet, this};
dialog.exec();
});
connect(ui->btn_signTransaction, &QPushButton::clicked, [this] {
this->showKeyImageSyncWizard();
});
switch (conf()->get(Config::offlineTxSigningMethod).toInt()) {
case Config::OTSMethod::FileTransfer:
ui->radio_airgapFiles->setChecked(true);
break;
default:
ui->radio_airgapUR->setChecked(true);
}
// We can't use rich text for radio buttons
connect(ui->label_airgapUR, &ClickableLabel::clicked, [this] {
ui->radio_airgapUR->setChecked(true);
});
connect(ui->label_airgapFiles, &ClickableLabel::clicked, [this] {
ui->radio_airgapFiles->setChecked(true);
});
connect(ui->radio_airgapFiles, &QCheckBox::toggled, [this] (bool checked){
if (checked) {
conf()->set(Config::offlineTxSigningMethod, Config::OTSMethod::FileTransfer);
}
});
connect(ui->radio_airgapUR, &QCheckBox::toggled, [this](bool checked) {
if (checked) {
conf()->set(Config::offlineTxSigningMethod, Config::OTSMethod::UnifiedResources);
}
});
}
void MainWindow::initWalletContext() {
connect(m_wallet, &Wallet::balanceUpdated, this, &MainWindow::onBalanceUpdated);
connect(m_wallet, &Wallet::syncStatus, this, &MainWindow::onSyncStatus);
connect(m_wallet, &Wallet::transactionCreated, this, &MainWindow::onTransactionCreated);
connect(m_wallet, &Wallet::transactionCommitted, this, &MainWindow::onTransactionCommitted);
connect(m_wallet, &Wallet::initiateTransaction, this, &MainWindow::onInitiateTransaction);
connect(m_wallet, &Wallet::keysCorrupted, this, &MainWindow::onKeysCorrupted);
connect(m_wallet, &Wallet::selectedInputsChanged, this, &MainWindow::onSelectedInputsChanged);
connect(m_wallet, &Wallet::txPoolBacklog, this, &MainWindow::onTxPoolBacklog);
// Wallet
connect(m_wallet, &Wallet::connectionStatusChanged, [this](int status){
// Order is important, first inform UI about a potential disconnect, then reconnect
this->onConnectionStatusChanged(status);
m_nodes->autoConnect();
});
connect(m_wallet, &Wallet::currentSubaddressAccountChanged, this, &MainWindow::updateTitle);
connect(m_wallet, &Wallet::walletPassphraseNeeded, this, &MainWindow::onWalletPassphraseNeeded);
connect(m_wallet, &Wallet::unconfirmedMoneyReceived, this, [this](const QString &txId, uint64_t amount){
if (m_wallet->isSynchronized() && !m_locked) {
auto notify = QString("%1 XMR (pending)").arg(WalletManager::displayAmount(amount, false));
m_windowManager->notify("Payment received", notify, 5000);
}
});
connect(m_wallet, &Wallet::moneyReceived, this, [this](const QString &txId, uint64_t amount, bool coinbase){
if (m_wallet->isSynchronized() && !m_locked && coinbase) {
auto notify = QString("%1 XMR").arg(WalletManager::displayAmount(amount, false));
m_windowManager->notify("Mining payment received", notify, 5000);
}
});
// Device
connect(m_wallet, &Wallet::deviceButtonRequest, this, &MainWindow::onDeviceButtonRequest);
connect(m_wallet, &Wallet::deviceButtonPressed, this, &MainWindow::onDeviceButtonPressed);
connect(m_wallet, &Wallet::deviceError, this, &MainWindow::onDeviceError);
connect(m_wallet, &Wallet::multiBroadcast, this, &MainWindow::onMultiBroadcast);
}
void MainWindow::menuToggleTabVisible(const QString &key){
const auto toggleTab = m_tabShowHideMapper[key];
QStringList enabledTabs = conf()->get(Config::enabledTabs).toStringList();
bool show = enabledTabs.contains(key);
show = !show;
if (show) {
enabledTabs.append(key);
} else {
enabledTabs.removeAll(key);
}
conf()->set(Config::enabledTabs, enabledTabs);
ui->tabWidget->setTabVisible(ui->tabWidget->indexOf(toggleTab->tab), show);
toggleTab->menuAction->setText(toggleTab->name);
}
void MainWindow::menuClearHistoryClicked() {
conf()->remove(Config::recentlyOpenedWallets);
this->updateRecentlyOpenedMenu();
}
QString MainWindow::walletName() {
return QFileInfo(m_wallet->cachePath()).fileName();
}
QString MainWindow::walletCachePath() {
return m_wallet->cachePath();
}
QString MainWindow::walletKeysPath() {
return m_wallet->keysPath();
}
void MainWindow::onWalletOpened() {
qDebug() << Q_FUNC_INFO;
m_splashDialog->hide();
m_wallet->setRingDatabase(Utils::ringDatabasePath());
m_wallet->updateBalance();
if (m_wallet->isHwBacked()) {
m_statusBtnHwDevice->show();
}
this->bringToFront();
this->setEnabled(true);
// receive page
m_wallet->subaddress()->refresh();
if (m_wallet->subaddress()->count() == 1) {
for (int i = 0; i < 10; i++) {
m_wallet->subaddress()->addRow("");
}
}
// history page
m_wallet->history()->refresh();
// coins page
m_wallet->coins()->refresh();
m_coinsWidget->setModel(m_wallet->coinsModel(), m_wallet->coins());
m_wallet->coinsModel()->setCurrentSubaddressAccount(m_wallet->currentSubaddressAccount());
// Coin labeling uses set_tx_note, so we need to refresh history too
connect(m_wallet->coins(), &Coins::descriptionChanged, [this] {
m_wallet->history()->refresh();
});
// Vice versa
connect(m_wallet->transactionHistoryModel(), &TransactionHistoryModel::transactionDescriptionChanged, [this] {
m_wallet->coins()->refresh();
});
this->updatePasswordIcon();
this->updateTitle();
m_nodes->allowConnection();
m_nodes->connectToNode();
m_updateBytes.start(250);
if (conf()->get(Config::writeRecentlyOpenedWallets).toBool()) {
this->addToRecentlyOpened(m_wallet->cachePath());
}
}
void MainWindow::updateBalance() {
this->onBalanceUpdated(m_wallet->balance(), m_wallet->unlockedBalance());
}
void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
bool hide = conf()->get(Config::hideBalance).toBool();
int displaySetting = conf()->get(Config::balanceDisplay).toInt();
int decimals = conf()->get(Config::amountPrecision).toInt();
QString balance_str = "Balance: ";
if (hide) {
balance_str += "HIDDEN";
}
else if (displaySetting == Config::totalBalance) {
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(balance, false, decimals));
}
else if (displaySetting == Config::spendable || displaySetting == Config::spendablePlusUnconfirmed) {
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(spendable, false, decimals));
if (displaySetting == Config::spendablePlusUnconfirmed && balance > spendable) {
balance_str += QString(" (+%1 XMR unconfirmed)").arg(WalletManager::displayAmount(balance - spendable, false, decimals));
}
}
if (conf()->get(Config::balanceShowFiat).toBool() && !hide) {
QString fiatCurrency = conf()->get(Config::preferredFiatCurrency).toString();
double balanceFiatAmount = appData()->prices.convert("XMR", fiatCurrency, balance / constants::cdiv);
balance_str += QString(" (%1)").arg(Utils::amountToCurrencyString(balanceFiatAmount, fiatCurrency));
}
m_statusLabelBalance->setToolTip("Click for details");
m_statusLabelBalance->setText(balance_str);
}
void MainWindow::setStatusText(const QString &text, bool override, int timeout) {
if (override) {
m_statusOverrideActive = true;
m_statusLabelStatus->setText(text);
QTimer::singleShot(timeout, [this]{
m_statusOverrideActive = false;
this->setStatusText(m_statusText);
});
return;
}
m_statusText = text;
if (!m_statusOverrideActive && !m_constructingTransaction) {
m_statusLabelStatus->setText(text);
}
}
void MainWindow::tryStoreWallet() {
if (m_wallet->connectionStatus() == Wallet::ConnectionStatus::ConnectionStatus_Synchronizing) {
Utils::showError(this, "Unable to save wallet", "Can't save wallet during synchronization", {"Wait until synchronization is finished and try again"}, "synchronization");
return;
}
m_wallet->store();
}
void MainWindow::onWebsocketStatusChanged(bool enabled) {
ui->actionShow_Home->setVisible(enabled);
QStringList enabledTabs = conf()->get(Config::enabledTabs).toStringList();
for (const auto &plugin : m_plugins) {
if (plugin->hasParent()) {
continue;
}
if (plugin->requiresWebsocket()) {
// TODO: unload plugins
ui->tabWidget->setTabVisible(this->findTab(plugin->displayName()), enabled && enabledTabs.contains(plugin->displayName()));
}
}
m_historyWidget->setWebsocketEnabled(enabled);
m_sendWidget->setWebsocketEnabled(enabled);
}
void MainWindow::onProxySettingsChangedConnect() {
m_nodes->connectToNode();
this->onProxySettingsChanged();
}
void MainWindow::onProxySettingsChanged() {
int proxy = conf()->get(Config::proxy).toInt();
if (proxy == Config::Proxy::Tor) {
this->onTorConnectionStateChanged(torManager()->torConnected);
m_statusBtnProxySettings->show();
return;
}
if (proxy == Config::Proxy::i2p) {
m_statusBtnProxySettings->setIcon(icons()->icon("i2p.png"));
m_statusBtnProxySettings->show();
return;
}
m_statusBtnProxySettings->hide();
}
void MainWindow::onOfflineMode(bool offline) {
m_wallet->setOffline(offline);
if (m_wallet->viewOnly()) {
return;
}
if (ui->stackedWidget->currentIndex() != Stack::LOCKED) {
ui->stackedWidget->setCurrentIndex(offline ? Stack::OFFLINE: Stack::WALLET);
}
ui->actionPay_to_many->setVisible(!offline);
ui->menuView->setDisabled(offline);
m_statusLabelBalance->setVisible(!offline);
m_statusBtnProxySettings->setVisible(!offline);
}
void MainWindow::onManualFeeSelectionEnabled(bool enabled) {
m_sendWidget->setManualFeeSelectionEnabled(enabled);
}
void MainWindow::onSubtractFeeFromAmountEnabled(bool enabled) {
m_sendWidget->setSubtractFeeFromAmountEnabled(enabled);
}
void MainWindow::onMultiBroadcast(const QMap<QString, QString> &txHexMap) {
QMapIterator<QString, QString> i(txHexMap);
while (i.hasNext()) {
i.next();
for (const auto& node: m_nodes->nodes()) {
QString address = node.toURL();
qDebug() << QString("Relaying %1 to: %2").arg(i.key(), address);
m_rpc->setDaemonAddress(address);
m_rpc->sendRawTransaction(i.value());
}
}
}
void MainWindow::onSyncStatus(quint64 height, quint64 target, bool daemonSync) {
if (height >= (target - 1)) {
this->updateNetStats();
}
this->setStatusText(Utils::formatSyncStatus(height, target, daemonSync));
m_statusLabelStatus->setToolTip(QString("Wallet height: %1").arg(QString::number(height)));
}
void MainWindow::onConnectionStatusChanged(int status)
{
// Note: Wallet does not emit this signal unless status is changed, so calling this function from MainWindow may
// result in the wrong connection status being displayed.
qDebug() << "Wallet connection status changed " << Utils::QtEnumToString(static_cast<Wallet::ConnectionStatus>(status));
// Update connection info in status bar.
QIcon icon;
if (conf()->get(Config::offlineMode).toBool()) {
icon = icons()->icon("status_offline.svg");
this->setStatusText("Offline mode");
} else {
switch(status){
case Wallet::ConnectionStatus_Disconnected:
icon = icons()->icon("status_disconnected.svg");
this->setStatusText("Disconnected");
break;
case Wallet::ConnectionStatus_Connecting:
icon = icons()->icon("status_lagging.svg");
this->setStatusText("Connecting to node");
break;
case Wallet::ConnectionStatus_WrongVersion:
icon = icons()->icon("status_disconnected.svg");
this->setStatusText("Incompatible node");
break;
case Wallet::ConnectionStatus_Synchronizing:
icon = icons()->icon("status_waiting.svg");
break;
case Wallet::ConnectionStatus_Synchronized:
icon = icons()->icon("status_connected.svg");
break;
default:
icon = icons()->icon("status_disconnected.svg");
break;
}
}
m_statusBtnConnectionStatusIndicator->setIcon(icon);
}
void MainWindow::onTransactionCreated(PendingTransaction *tx, const QVector<QString> &address) {
// Clean up some UI
m_constructingTransaction = false;
m_txTimer.stop();
this->setStatusText(m_statusText);
if (m_wallet->isHwBacked()) {
m_splashDialog->hide();
}
if (tx->status() != PendingTransaction::Status_Ok) {
if (m_showDeviceError) {
// The hardware devices has disconnected during tx construction.
// Due to a macOS-specific Qt bug, we have to prevent it from stacking two QMessageBoxes, otherwise
// the UI becomes unresponsive. The reconnect dialog should take priority.
m_wallet->disposeTransaction(tx);
return;
}
QString errMsg = tx->errorString();
Utils::Message message{this, Utils::ERROR, "Failed to construct transaction", errMsg};
if (tx->getException()) {
try
{
std::rethrow_exception(tx->getException());
}
catch (const tools::error::daemon_busy &e) {
message.description = QString("Node was unable to respond. Failed request: %1").arg(QString::fromStdString(e.request()));
message.helpItems = {"Try sending the transaction again.", "If this keeps happening, connect to a different node."};
}
catch (const tools::error::no_connection_to_daemon &e) {
message.description = QString("Connection to node lost. Failed request: %1").arg(QString::fromStdString(e.request()));
message.helpItems = {"Try sending the transaction again.", "If this keeps happening, connect to a different node."};
}
catch (const tools::error::wallet_rpc_error &e) {
message.description = QString("RPC error: %1").arg(QString::fromStdString(e.to_string()));
message.helpItems = {"Try sending the transaction again.", "If this keeps happening, connect to a different node."};
}
catch (const tools::error::get_outs_error &e) {
message.description = "Failed to get enough decoy outputs from node";
message.helpItems = {"Your transaction has too many inputs. Try sending a lower amount."};
}
catch (const tools::error::not_enough_unlocked_money &e) {
QString error;
if (e.fee() > e.available()) {
error = QString("Transaction fee exceeds spendable balance.\n\nSpendable balance: %1\nTransaction fee: %2").arg(WalletManager::displayAmount(e.available()), WalletManager::displayAmount(e.fee()));
}
else {
error = QString("Spendable balance insufficient to pay for transaction.\n\nSpendable balance: %1\nTransaction needs: %2").arg(WalletManager::displayAmount(e.available()), WalletManager::displayAmount(e.tx_amount() + e.fee()));
}
message.description = error;
message.helpItems = {"Wait for more balance to unlock.", "Click 'Help' to learn more about how balance works."};
message.doc = "balance";
}
catch (const tools::error::not_enough_money &e) {
message.description = QString("Not enough money to transfer\n\nTotal balance: %1\nTransaction amount: %2").arg(WalletManager::displayAmount(e.available()), WalletManager::displayAmount(e.tx_amount()));
message.helpItems = {"If you are trying to send your entire balance, click 'Max'."};
message.doc = "balance";
}
catch (const tools::error::tx_not_possible &e) {
message.description = QString("Not enough money to transfer. Transaction amount + fee exceeds available balance.\n\n"
"Spendable balance: %1\n"
"Transaction needs: %2").arg(WalletManager::displayAmount(e.available()), WalletManager::displayAmount(e.tx_amount() + e.fee()));
message.helpItems = {"If you're trying to send your entire balance, click 'Max'."};
message.doc = "balance";
}
catch (const tools::error::not_enough_outs_to_mix &e) {
message.description = "Not enough outputs for specified ring size.";
}
catch (const tools::error::tx_not_constructed&) {
message.description = "Transaction was not constructed";
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
catch (const tools::error::tx_rejected &e) {
// TODO: provide helptext
message.description = QString("Transaction was rejected by node. Reason: %1.").arg(QString::fromStdString(e.status()));
}
catch (const tools::error::tx_sum_overflow &e) {
message.description = "Transaction tries to spend an unrealistic amount of XMR";
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
catch (const tools::error::zero_amount&) {
message.description = "Destination amount is zero";
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
catch (const tools::error::zero_destination&) {
message.description = "Transaction has no destination";
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
catch (const tools::error::tx_too_big &e) {
message.description = "Transaction too big";
message.helpItems = {"Try sending a smaller amount."};
}
catch (const tools::error::transfer_error &e) {
message.description = QString("Unknown transfer error: %1").arg(QString::fromStdString(e.what()));
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
catch (const tools::error::wallet_internal_error &e) {
bool bug = true;
QString msg = e.what();
message.description = QString("Internal error: %1").arg(QString::fromStdString(e.what()));
if (msg.contains("Daemon response did not include the requested real output")) {
QString currentNode = m_nodes->connection().toAddress();
message.description += QString("\nYou are currently connected to: %1\n\n"
"This node may be acting maliciously. You are strongly recommended to disconnect from this node."
"Please report this incident to the developers.").arg(currentNode);
message.doc = "report_an_issue";
}
if (msg.startsWith("No unlocked balance")) {
// TODO: We're sending ALL, but fractional outputs got ignored
message.description = "Spendable balance insufficient to pay for transaction fee.";
bug = false;
}
if (msg.contains("Failed to get height") || msg.contains("Failed to get earliest fork height")) {
message.description = QString("RPC error: %1").arg(QString::fromStdString(e.to_string()));
message.helpItems = {"Try sending the transaction again.", "If this keeps happening, connect to a different node."};
bug = false;
}
if (bug) {
message.helpItems = {"You have found a bug. Please contact the developers."};
message.doc = "report_an_issue";
}
}
catch (const std::exception &e) {
message.description = QString::fromStdString(e.what());
}
}
Utils::showMsg(message);
m_wallet->disposeTransaction(tx);
return;
}
else if (tx->txCount() == 0) {
Utils::showError(this, "Failed to construct transaction", "No transactions were constructed", {"You have found a bug. Please contact the developers."}, "report_an_issue");
m_wallet->disposeTransaction(tx);
return;
}
else if (tx->txCount() > 1) {
Utils::showError(this, "Failed to construct transaction", "Transaction tries to spend too many inputs", {"Send a smaller amount of XMR to yourself first."});
m_wallet->disposeTransaction(tx);
return;
}
// This is a weak check to see if we send to all specified destination addresses
// This is here to catch rare memory corruption errors during transaction construction
// TODO: also check that amounts match
tx->refresh();
QSet<QString> outputAddresses;
for (const auto &output : tx->transaction(0).outputs) {
outputAddresses.insert(WalletManager::baseAddressFromIntegratedAddress(output.address, constants::networkType));
}
QSet<QString> destAddresses;
for (const auto &addr : address) {
// TODO: Monero core bug, integrated address is not added to dests for transactions spending ALL
destAddresses.insert(WalletManager::baseAddressFromIntegratedAddress(addr, constants::networkType));
}
if (!outputAddresses.contains(destAddresses)) {
Utils::showError(this, "Transaction fails sanity check", "Constructed transaction doesn't appear to send to (all) specified destination address(es). Try creating the transaction again.");
m_wallet->disposeTransaction(tx);
return;
}
// Offline transaction signing
if (m_wallet->viewOnly()) {
#ifdef WITH_SCANNER
OfflineTxSigningWizard wizard(this, m_wallet, tx);
wizard.exec();
if (!wizard.readyToCommit()) {
return;
} else {
tx = wizard.signedTx();
}
if (tx->txCount() == 0) {
Utils::showError(this, "Failed to load transaction", "No transactions were found", {"You have found a bug. Please contact the developers."}, "report_an_issue");
m_wallet->disposeTransaction(tx);
return;
}
#else
Utils::showError(this, "Can't open offline transaction signing wizard", "Feather was built without webcam QR scanner support");
return;
#endif
}
m_wallet->addCacheTransaction(tx->txid()[0], tx->signedTxToHex(0));
// Show advanced dialog on multi-destination transactions
if (address.size() > 1) {
TxConfAdvDialog dialog_adv{m_wallet, m_wallet->tmpTxDescription, this};
dialog_adv.setTransaction(tx, !m_wallet->viewOnly());
dialog_adv.exec();
return;
}
TxConfDialog dialog{m_wallet, tx, address[0], m_wallet->tmpTxDescription, this};
switch (dialog.exec()) {
case QDialog::Rejected: