X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fcoincontroldialog.cpp;h=7b7472b5ba133954bc0d6b460695025e9567f97b;hb=db1eaec482383385156b3e7cb6b2baa9454975f0;hp=9df1b0d3fd0fa0aaab9543212c6d8a767136cd74;hpb=77a43545b4491b9703d803765da9059d2bdd5aaa;p=novacoin.git diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 9df1b0d..7b7472b 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -2,7 +2,9 @@ #include "ui_coincontroldialog.h" #include "init.h" +#include "base58.h" #include "bitcoinunits.h" +#include "script.h" #include "walletmodel.h" #include "addresstablemodel.h" #include "optionsmodel.h" @@ -21,13 +23,14 @@ #include #include #include +#include using namespace std; QList CoinControlDialog::payAmounts; CCoinControl* CoinControlDialog::coinControl = new CCoinControl(); CoinControlDialog::CoinControlDialog(QWidget *parent) : - QDialog(parent, DIALOGWINDOWHINTS), + QWidget(parent, DIALOGWINDOWHINTS), ui(new Ui::CoinControlDialog), model(0) { @@ -103,11 +106,10 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) : #endif connect(ui->treeWidget->header(), SIGNAL(sectionClicked(int)), this, SLOT(headerSectionClicked(int))); - // ok button - connect(ui->buttonBox, SIGNAL(clicked( QAbstractButton*)), this, SLOT(buttonBoxClicked(QAbstractButton*))); - // (un)select all connect(ui->pushButtonSelectAll, SIGNAL(clicked()), this, SLOT(buttonSelectAllClicked())); + + ui->treeWidget->headerItem()->setText(COLUMN_CHECKBOX, QString()); ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84); ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 100); @@ -153,10 +155,9 @@ QString CoinControlDialog::strPad(QString s, int nPadLength, QString sPadding) } // ok button -void CoinControlDialog::buttonBoxClicked(QAbstractButton* button) +void CoinControlDialog::on_buttonBox_accepted() { - if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) - done(QDialog::Accepted); // closes the dialog + close(); // closes the dialog } // (un)select all @@ -416,7 +417,7 @@ QString CoinControlDialog::getPriorityLabel(double dPriority) else ui->labelLocked->setVisible(false); }*/ -void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) +void CoinControlDialog::updateLabels(WalletModel *model, QWidget* dialog) { if (!model) return; @@ -469,17 +470,21 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) dPriorityInputs += (double)out.tx->vout[out.i].nValue * (out.nDepth+1); // Bytes - CTxDestination address; - if(ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + CBitcoinAddress address; + if(ExtractAddress(*pwalletMain, out.tx->vout[out.i].scriptPubKey, address)) { - CPubKey pubkey; - CKeyID *keyid = boost::get< CKeyID >(&address); - if (keyid && model->getPubKey(*keyid, pubkey)) - nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); - else - nBytesInputs += 148; // in all error cases, simply assume 148 here + if (address.IsPair()) + nBytesInputs += 213; + else if (address.IsPubKey()) + { + CPubKey pubkey; + CKeyID keyid; + if (address.GetKeyID(keyid) && model->getPubKey(keyid, pubkey)) + nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); + else + nBytesInputs += 148; // in all error cases, simply assume 148 here + } } - else nBytesInputs += 148; } // calculation @@ -491,19 +496,11 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // Priority dPriority = dPriorityInputs / nBytes; sPriorityLabel = CoinControlDialog::getPriorityLabel(dPriority); + bool fAllowFree = CTransaction::AllowFree(dPriority); // Fee int64_t nFee = nTransactionFee * (1 + (int64_t)nBytes / 1000); - // Min Fee - bool fAllowFree = CTransaction::AllowFree(dPriority); - - // Disable free transactions until 1 July 2014 - if (!fTestNet && txDummy.nTime < FEE_SWITCH_TIME) - { - fAllowFree = false; - } - int64_t nMinFee = txDummy.GetMinFee(1, fAllowFree, GMF_SEND, nBytes); nPayFee = max(nFee, nMinFee); @@ -512,24 +509,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) { nChange = nAmount - nPayFee - nPayAmount; - // if sub-cent change is required, the fee must be raised to at least CTransaction::nMinTxFee - if (txDummy.nTime < FEE_SWITCH_TIME && !fTestNet) - { - if (nPayFee < CENT && nChange > 0 && nChange < CENT) - { - if (nChange < CENT) // change < 0.01 => simply move all change to fees - { - nPayFee = nChange; - nChange = 0; - } - else - { - nChange = nChange + nPayFee - CENT; - nPayFee = CENT; - } - } - } - if (nChange == 0) nBytes -= 34; } @@ -561,14 +540,14 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) dialog->findChild("labelCoinControlChange") ->setEnabled(nPayAmount > 0); // stats - l1->setText(QString::number(nQuantity)); // Quantity - l2->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); // Amount - l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee)); // Fee - l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); // After Fee - l5->setText(((nBytes > 0) ? "~" : "") + QString::number(nBytes)); // Bytes - l6->setText(sPriorityLabel); // Priority - l7->setText((fLowOutput ? (fDust ? tr("DUST") : tr("yes")) : tr("no"))); // Low Output / Dust - l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); // Change + l1->setText(QString::number(nQuantity)); // Quantity + l2->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAmount)); // Amount + l3->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nPayFee, false, 3)); // Fee + l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); // After Fee + l5->setText(((nBytes > 0) ? ASYMP_UTF8 : "") + QString::number(nBytes)); // Bytes + l6->setText(sPriorityLabel); // Priority + l7->setText((fLowOutput ? (fDust ? tr("DUST") : tr("yes")) : tr("no"))); // Low Output / Dust + l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); // Change // turn labels "red" l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000 @@ -577,10 +556,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) l8->setStyleSheet((nChange > 0 && nChange < CENT) ? "color:red;" : ""); // Change < 0.01BTC // tool tips - l5->setToolTip(tr("This label turns red, if the transaction size is bigger than 1000 bytes.\n\n This means a fee of at least %1 per kb is required.\n\n Can vary +/- 1 Byte per input.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, fTestNet || FEE_SWITCH_TIME < GetTime() ? MIN_TX_FEE : CENT))); - l6->setToolTip(tr("Transactions with higher priority get more likely into a block.\n\nThis label turns red, if the priority is smaller than \"medium\".\n\n This means a fee of at least %1 per kb is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, fTestNet || FEE_SWITCH_TIME < GetTime() ? MIN_TX_FEE : CENT))); - l7->setToolTip(tr("This label turns red, if any recipient receives an amount smaller than %1.\n\n This means a fee of at least %2 is required. \n\n Amounts below the minimum fee are shown as DUST.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)).arg(BitcoinUnits::formatWithUnit(nDisplayUnit, fTestNet || FEE_SWITCH_TIME < GetTime() ? MIN_RELAY_TX_FEE : CENT))); - l8->setToolTip(tr("This label turns red, if the change is smaller than %1.\n\n This means a fee of at least %2 is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)).arg(BitcoinUnits::formatWithUnit(nDisplayUnit, fTestNet || FEE_SWITCH_TIME < GetTime() ? MIN_TX_FEE : CENT))); + l5->setToolTip(tr("This label turns red, if the transaction size is bigger than 1000 bytes.\n\n This means a fee of at least %1 per kb is required.\n\n Can vary +/- 1 Byte per input.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, MIN_TX_FEE))); + l6->setToolTip(tr("Transactions with higher priority get more likely into a block.\n\nThis label turns red, if the priority is smaller than \"medium\".\n\n This means a fee of at least %1 per kb is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, MIN_TX_FEE))); + l7->setToolTip(tr("This label turns red, if any recipient receives an amount smaller than %1.\n\n This means a fee of at least %2 is required. \n\n Amounts below the minimum fee are shown as DUST.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)).arg(BitcoinUnits::formatWithUnit(nDisplayUnit, MIN_RELAY_TX_FEE))); + l8->setToolTip(tr("This label turns red, if the change is smaller than %1.\n\n This means a fee of at least %2 is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)).arg(BitcoinUnits::formatWithUnit(nDisplayUnit, MIN_TX_FEE))); dialog->findChild("labelCoinControlBytesText") ->setToolTip(l5->toolTip()); dialog->findChild("labelCoinControlPriorityText") ->setToolTip(l6->toolTip()); dialog->findChild("labelCoinControlLowOutputText")->setToolTip(l7->toolTip()); @@ -657,9 +636,10 @@ void CoinControlDialog::updateView() itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked); // address - CTxDestination outputAddress; + CBitcoinAddress outputAddress; QString sAddress = ""; - if(ExtractDestination(out.tx->vout[out.i].scriptPubKey, outputAddress)) + + if(ExtractAddress(*pwalletMain, out.tx->vout[out.i].scriptPubKey, outputAddress)) { sAddress = CBitcoinAddress(outputAddress).ToString().c_str(); @@ -667,10 +647,13 @@ void CoinControlDialog::updateView() if (!treeMode || (!(sAddress == sWalletAddress))) itemOutput->setText(COLUMN_ADDRESS, sAddress); - CPubKey pubkey; - CKeyID *keyid = boost::get< CKeyID >(&outputAddress); - if (keyid && model->getPubKey(*keyid, pubkey) && !pubkey.IsCompressed()) - nInputSize = 180; + if (outputAddress.IsPubKey()) + { + CPubKey pubkey; + CKeyID keyid; + if (outputAddress.GetKeyID(keyid) && model->getPubKey(keyid, pubkey) && !pubkey.IsCompressed()) + nInputSize = 180; + } } // label @@ -763,3 +746,24 @@ void CoinControlDialog::updateView() sortView(sortColumn, sortOrder); ui->treeWidget->setEnabled(true); } + +void CoinControlDialog::keyPressEvent(QKeyEvent *event) +{ +#ifdef ANDROID + if(event->key() == Qt::Key_Back) + { + close(); + } +#else + if(event->key() == Qt::Key_Escape) + { + close(); + } +#endif +} + +void CoinControlDialog::closeEvent(QCloseEvent* e) +{ + QWidget::closeEvent(e); + emit beforeClose(); +}