diff --git a/src/coinswidget.cpp b/src/coinswidget.cpp index 507da8b..78d80a4 100644 --- a/src/coinswidget.cpp +++ b/src/coinswidget.cpp @@ -11,14 +11,14 @@ #include #include -CoinsWidget::CoinsWidget(QWidget *parent) +CoinsWidget::CoinsWidget(AppContext *ctx, QWidget *parent) : QWidget(parent) , ui(new Ui::CoinsWidget) + , m_ctx(ctx) , m_headerMenu(new QMenu(this)) , m_copyMenu(new QMenu("Copy",this)) { ui->setupUi(this); - m_ctx = MainWindow::getContext(); // header context menu ui->coins->header()->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/src/coinswidget.h b/src/coinswidget.h index 0550c5d..38c1777 100644 --- a/src/coinswidget.h +++ b/src/coinswidget.h @@ -22,7 +22,7 @@ class CoinsWidget : public QWidget Q_OBJECT public: - explicit CoinsWidget(QWidget *parent = nullptr); + explicit CoinsWidget(AppContext *ctx, QWidget *parent = nullptr); void setModel(CoinsModel * model, Coins * coins); ~CoinsWidget() override; @@ -54,6 +54,7 @@ private: }; Ui::CoinsWidget *ui; + AppContext *m_ctx; QMenu *m_contextMenu; QMenu *m_headerMenu; @@ -68,7 +69,6 @@ private: Coins *m_coins; CoinsModel * m_model; CoinsProxyModel * m_proxyModel; - AppContext *m_ctx; void showContextMenu(const QPoint & point); void copy(copyField field); diff --git a/src/contactswidget.cpp b/src/contactswidget.cpp index a7a7bc3..e7d9c01 100644 --- a/src/contactswidget.cpp +++ b/src/contactswidget.cpp @@ -11,12 +11,11 @@ #include -ContactsWidget::ContactsWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::ContactsWidget) +ContactsWidget::ContactsWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ContactsWidget) { ui->setupUi(this); - m_ctx = MainWindow::getContext(); // header context menu ui->contacts->header()->setContextMenuPolicy(Qt::CustomContextMenu); @@ -69,9 +68,10 @@ void ContactsWidget::payTo() { emit fillAddress(address); } -void ContactsWidget::setModel(AddressBookModel *model) +void ContactsWidget::setModel(AddressBookModel *model, Wallet *wallet) { m_model = model; + m_wallet = wallet; m_proxyModel = new AddressBookProxyModel; m_proxyModel->setSourceModel(m_model); ui->contacts->setModel(m_proxyModel); @@ -104,24 +104,31 @@ void ContactsWidget::showHeaderMenu(const QPoint& position) void ContactsWidget::newContact(QString address, QString name) { - auto * dialog = new ContactsDialog(this, address, name); - int ret = dialog->exec(); - if (!ret) return; + if (!m_wallet) { + QMessageBox::warning(this, "Error", "No wallet opened."); + return; + } - address = dialog->getAddress(); - name = dialog->getName(); + ContactsDialog dialog{this, address, name}; + int ret = dialog.exec(); + if (ret != QDialog::Accepted) { + return; + } - bool addressValid = WalletManager::addressValid(address, m_ctx->currentWallet->nettype()); + address = dialog.getAddress(); + name = dialog.getName(); + + bool addressValid = WalletManager::addressValid(address, m_wallet->nettype()); if (!addressValid) { QMessageBox::warning(this, "Invalid address", "Invalid address"); return; } - int num_addresses = m_ctx->currentWallet->addressBook()->count(); + int num_addresses = m_wallet->addressBook()->count(); QString address_entry; QString name_entry; for (int i=0; icurrentWallet->addressBook()->getRow(i, [&address_entry, &name_entry](const AddressBookInfo &entry){ + m_wallet->addressBook()->getRow(i, [&address_entry, &name_entry](const AddressBookInfo &entry){ address_entry = entry.address(); name_entry = entry.description(); }); @@ -138,7 +145,7 @@ void ContactsWidget::newContact(QString address, QString name) } } - m_ctx->currentWallet->addressBook()->addRow(address, "", name); + m_wallet->addressBook()->addRow(address, "", name); } void ContactsWidget::deleteContact() diff --git a/src/contactswidget.h b/src/contactswidget.h index 4035773..cf9a3a5 100644 --- a/src/contactswidget.h +++ b/src/contactswidget.h @@ -21,7 +21,7 @@ class ContactsWidget : public QWidget public: explicit ContactsWidget(QWidget *parent = nullptr); - void setModel(AddressBookModel * model); + void setModel(AddressBookModel *model, Wallet *wallet); ~ContactsWidget() override; public slots: @@ -42,7 +42,6 @@ private slots: private: Ui::ContactsWidget *ui; - AppContext *m_ctx; QAction *m_showFullAddressesAction; QMenu *m_rowMenu; @@ -50,6 +49,7 @@ private: QMenu *m_headerMenu; AddressBookModel * m_model; AddressBookProxyModel * m_proxyModel; + Wallet *m_wallet; }; #endif // CONTACTSWIDGET_H diff --git a/src/libwalletqt/Subaddress.cpp b/src/libwalletqt/Subaddress.cpp index 308eb4a..dc68357 100644 --- a/src/libwalletqt/Subaddress.cpp +++ b/src/libwalletqt/Subaddress.cpp @@ -5,7 +5,9 @@ #include Subaddress::Subaddress(Monero::Subaddress *subaddressImpl, QObject *parent) - : QObject(parent), m_subaddressImpl(subaddressImpl), m_unusedLookahead(0) + : QObject(parent) + , m_subaddressImpl(subaddressImpl) + , m_unusedLookahead(0) { getAll(); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index a3b9612..84311d9 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -423,7 +423,7 @@ public: // Passphrase entry for hardware wallets void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort=false); - virtual void onWalletPassphraseNeeded(bool on_device) override; + void onWalletPassphraseNeeded(bool on_device) override; quint64 getBytesReceived() const; quint64 getBytesSent() const; @@ -466,7 +466,7 @@ signals: private: Wallet(QObject * parent = nullptr); - Wallet(Monero::Wallet *w, QObject * parent = 0); + Wallet(Monero::Wallet *w, QObject * parent = nullptr); ~Wallet(); //! initializes wallet diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7b0b72d..7c1e0e4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -32,17 +32,14 @@ #include "utils/WebsocketNotifier.h" #include "utils/Updater.h" -MainWindow * MainWindow::pMainWindow = nullptr; - MainWindow::MainWindow(AppContext *ctx, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_ctx(ctx) { - pMainWindow = this; ui->setupUi(this); - m_windowSettings = new Settings(this); + m_windowSettings = new Settings(m_ctx, this); m_windowCalc = new CalcWindow(this); m_splashDialog = new SplashDialog(this); @@ -71,7 +68,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged); - connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged)); + connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged)); connect(m_windowSettings, &Settings::amountPrecisionChanged, m_ctx, &AppContext::onAmountPrecisionChanged); connect(m_windowSettings, &Settings::skinChanged, this, &MainWindow::skinChanged); @@ -192,13 +189,20 @@ void MainWindow::initWidgets() { connect(ui->historyWidget, &HistoryWidget::viewOnBlockExplorer, this, &MainWindow::onViewOnBlockExplorer); connect(ui->historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction); + // [Send] + m_sendWidget = new SendWidget(m_ctx, this); + ui->sendWidgetLayout->addWidget(m_sendWidget); + // [Receive] connect(ui->receiveWidget, &ReceiveWidget::showTransactions, [this](const QString &text) { ui->historyWidget->setSearchText(text); ui->tabWidget->setCurrentIndex(Tabs::HISTORY); }); - connect(ui->contactWidget, &ContactsWidget::fillAddress, ui->sendWidget, &SendWidget::fillAddress); + connect(ui->contactWidget, &ContactsWidget::fillAddress, m_sendWidget, &SendWidget::fillAddress); + // [Coins] + m_coinsWidget = new CoinsWidget(m_ctx, this); + ui->coinsWidgetLayout->addWidget(m_coinsWidget); #ifdef HAS_LOCALMONERO m_localMoneroWidget = new LocalMoneroWidget(this, m_ctx); @@ -618,11 +622,11 @@ void MainWindow::onWalletOpened() { ui->historyWidget->setModel(m_ctx->currentWallet->historyModel(), m_ctx->currentWallet); // contacts widget - ui->contactWidget->setModel(m_ctx->currentWallet->addressBookModel()); + ui->contactWidget->setModel(m_ctx->currentWallet->addressBookModel(), m_ctx->currentWallet); // coins page m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount()); - ui->coinsWidget->setModel(m_ctx->currentWallet->coinsModel(), m_ctx->currentWallet->coins()); + m_coinsWidget->setModel(m_ctx->currentWallet->coinsModel(), m_ctx->currentWallet->coins()); this->touchbarShowWallet(); this->updatePasswordIcon(); @@ -784,7 +788,7 @@ void MainWindow::onTransactionCommitted(bool status, PendingTransaction *tx, con if (status) { // success QString body = QString("Successfully sent %1 transaction(s).").arg(txid.count()); QMessageBox::information(this, "Transactions sent", body); - ui->sendWidget->clearFields(); + m_sendWidget->clearFields(); } else { auto err = tx->errorString(); QString body = QString("Error committing transaction: %1").arg(err); @@ -994,7 +998,7 @@ void MainWindow::donateButtonClicked() { if (donation <= 0) donation = 0.1337; - ui->sendWidget->fill(globals::donationAddress, "Donation to the Feather development team", donation); + m_sendWidget->fill(globals::donationAddress, "Donation to the Feather development team", donation); ui->tabWidget->setCurrentIndex(Tabs::SEND); } @@ -1014,7 +1018,7 @@ void MainWindow::showCalcWindow() { void MainWindow::payToMany() { ui->tabWidget->setCurrentIndex(Tabs::SEND); - ui->sendWidget->payToMany(); + m_sendWidget->payToMany(); QMessageBox::information(this, "Pay to many", "Enter a list of outputs in the 'Pay to' field.\n" "One output per line.\n" "Format: address, amount\n" @@ -1022,7 +1026,7 @@ void MainWindow::payToMany() { } void MainWindow::showSendScreen(const CCSEntry &entry) { - ui->sendWidget->fill(entry); + m_sendWidget->fill(entry); ui->tabWidget->setCurrentIndex(Tabs::SEND); } @@ -1064,14 +1068,6 @@ void MainWindow::importContacts() { QMessageBox::information(this, "Contacts imported", QString("Total contacts imported: %1").arg(inserts)); } -MainWindow *MainWindow::getInstance() { - return pMainWindow; -} - -AppContext *MainWindow::getContext(){ - return pMainWindow->m_ctx; -} - QString MainWindow::loadStylesheet(const QString &resource) { QFile f(resource); if (!f.exists()) { @@ -1481,7 +1477,7 @@ void MainWindow::onWalletAboutToClose() { ui->historyWidget->resetModel(); ui->contactWidget->resetModel(); ui->receiveWidget->resetModel(); - ui->coinsWidget->resetModel(); + m_coinsWidget->resetModel(); } void MainWindow::onExportHistoryCSV(bool checked) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 807a403..a32e2ad 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,6 +36,9 @@ #include "widgets/tickerwidget.h" #include "wizard/WalletWizard.h" +#include "sendwidget.h" +#include "coinswidget.h" + #ifdef HAS_LOCALMONERO #include "widgets/LocalMoneroWidget.h" #endif @@ -68,8 +71,6 @@ Q_OBJECT public: explicit MainWindow(AppContext *ctx, QWidget *parent = nullptr); - static MainWindow *getInstance(); - static AppContext *getContext(); ~MainWindow() override; enum Tabs { @@ -181,7 +182,6 @@ private: void startupWarning(); bool autoOpenWallet(); - static MainWindow * pMainWindow; void closeEvent(QCloseEvent *event) override; void cleanupBeforeClose(); QString loadStylesheet(const QString &resource); @@ -216,6 +216,8 @@ private: XMRigWidget *m_xmrig = nullptr; SplashDialog *m_splashDialog = nullptr; + SendWidget *m_sendWidget = nullptr; + CoinsWidget *m_coinsWidget = nullptr; #ifdef HAS_LOCALMONERO LocalMoneroWidget *m_localMoneroWidget = nullptr; #endif diff --git a/src/mainwindow.ui b/src/mainwindow.ui index be1b381..0b38545 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -188,29 +188,11 @@ 11 - - - - 0 - 0 - + + + 0 - - - 0 - 100 - - - - - 16777215 - 16777215 - - - - - - + @@ -226,7 +208,14 @@ - + + + + 0 + 0 + + + @@ -254,7 +243,7 @@ - + @@ -735,12 +724,6 @@ - - SendWidget - QWidget -
sendwidget.h
- 1 -
ContactsWidget QWidget @@ -753,12 +736,6 @@
receivewidget.h
1
- - CoinsWidget - QWidget -
coinswidget.h
- 1 -
HistoryWidget QWidget diff --git a/src/sendwidget.cpp b/src/sendwidget.cpp index cc09f9c..7c6eb3b 100644 --- a/src/sendwidget.cpp +++ b/src/sendwidget.cpp @@ -8,12 +8,12 @@ #include "globals.h" #include "utils/AppData.h" -SendWidget::SendWidget(QWidget *parent) +SendWidget::SendWidget(AppContext *ctx, QWidget *parent) : QWidget(parent) , ui(new Ui::SendWidget) + , m_ctx(ctx) { ui->setupUi(this); - m_ctx = MainWindow::getContext(); QString amount_rx = R"(^\d{0,8}[\.,]\d{0,12}|(all)$)"; QRegExp rx; diff --git a/src/sendwidget.h b/src/sendwidget.h index 056fb40..94b4163 100644 --- a/src/sendwidget.h +++ b/src/sendwidget.h @@ -17,7 +17,7 @@ class SendWidget : public QWidget Q_OBJECT public: - explicit SendWidget(QWidget *parent = nullptr); + explicit SendWidget(AppContext *ctx, QWidget *parent = nullptr); void fill(const CCSEntry &entry); void fill(const QString &address, const QString& description, double amount = 0); void fill(double amount); diff --git a/src/sendwidget.ui b/src/sendwidget.ui index 566459d..5de0934 100644 --- a/src/sendwidget.ui +++ b/src/sendwidget.ui @@ -10,6 +10,12 @@ 231 + + + 0 + 0 + + Form diff --git a/src/settings.cpp b/src/settings.cpp index bf73847..4be0ae2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -7,12 +7,12 @@ #include -Settings::Settings(QWidget *parent) : - QDialog(parent), - ui(new Ui::Settings) +Settings::Settings(AppContext *ctx, QWidget *parent) + : QDialog(parent) + , ui(new Ui::Settings) + , m_ctx(ctx) { ui->setupUi(this); - m_ctx = MainWindow::getContext(); this->setWindowIcon(QIcon("://assets/images/appicons/64x64.png")); diff --git a/src/settings.h b/src/settings.h index 65b9078..e02c3b0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -20,7 +20,7 @@ class Settings : public QDialog Q_OBJECT public: - explicit Settings(QWidget *parent = nullptr); + explicit Settings(AppContext *ctx, QWidget *parent = nullptr); ~Settings() override; signals: @@ -49,8 +49,8 @@ private: void setupSkinCombobox(); void setupLocalMoneroFrontendCombobox(); - AppContext *m_ctx; Ui::Settings *ui; + AppContext *m_ctx; QStringList m_skins{"Native", "QDarkStyle", "Breeze/Dark", "Breeze/Light"}; QStringList m_dateFormats{"yyyy-MM-dd", "MM-dd-yyyy", "dd-MM-yyyy"};