Changeset View
Changeset View
Standalone View
Standalone View
src/qt/guiutil.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
#define NSAppKitVersionNumber10_8 1187 | #define NSAppKitVersionNumber10_8 1187 | ||||
#endif | #endif | ||||
#if !defined(NSAppKitVersionNumber10_9) | #if !defined(NSAppKitVersionNumber10_9) | ||||
#define NSAppKitVersionNumber10_9 1265 | #define NSAppKitVersionNumber10_9 1265 | ||||
#endif | #endif | ||||
#endif | #endif | ||||
namespace GUIUtil { | namespace GUIUtil { | ||||
const QString URI_SCHEME("bitcoincash"); | |||||
QString dateTimeStr(const QDateTime &date) { | QString dateTimeStr(const QDateTime &date) { | ||||
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | ||||
date.toString("hh:mm"); | date.toString("hh:mm"); | ||||
} | } | ||||
QString dateTimeStr(qint64 nTime) { | QString dateTimeStr(qint64 nTime) { | ||||
return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); | return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
void setupAmountWidget(QLineEdit *widget, QWidget *parent) { | void setupAmountWidget(QLineEdit *widget, QWidget *parent) { | ||||
QDoubleValidator *amountValidator = new QDoubleValidator(parent); | QDoubleValidator *amountValidator = new QDoubleValidator(parent); | ||||
amountValidator->setDecimals(8); | amountValidator->setDecimals(8); | ||||
amountValidator->setBottom(0.0); | amountValidator->setBottom(0.0); | ||||
widget->setValidator(amountValidator); | widget->setValidator(amountValidator); | ||||
widget->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | widget->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||||
} | } | ||||
QString bitcoinURIScheme(const Config &cfg) { | |||||
if (!cfg.UseCashAddrEncoding()) return "bitcoincash"; | |||||
return QString::fromStdString(cfg.GetChainParams().CashAddrPrefix()); | |||||
} | |||||
static bool IsCashAddrEncoded(const QUrl &uri) { | static bool IsCashAddrEncoded(const QUrl &uri) { | ||||
const std::string addr = (uri.scheme() + ":" + uri.path()).toStdString(); | const std::string addr = (uri.scheme() + ":" + uri.path()).toStdString(); | ||||
auto decoded = cashaddr::Decode(addr); | auto decoded = cashaddr::Decode(addr); | ||||
return !decoded.first.empty(); | return !decoded.first.empty(); | ||||
} | } | ||||
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { | bool parseBitcoinURI(const QString &scheme, const QUrl &uri, | ||||
// return if URI is not valid or is no bitcoincash: URI | SendCoinsRecipient *out) { | ||||
if (!uri.isValid() || uri.scheme() != URI_SCHEME) return false; | // return if URI has wrong scheme. | ||||
if (!uri.isValid() || uri.scheme() != scheme) { | |||||
return false; | |||||
} | |||||
SendCoinsRecipient rv; | SendCoinsRecipient rv; | ||||
if (IsCashAddrEncoded(uri)) { | if (IsCashAddrEncoded(uri)) { | ||||
rv.address = uri.scheme() + ":" + uri.path(); | rv.address = uri.scheme() + ":" + uri.path(); | ||||
} else { | } else { | ||||
// strip out uri scheme for base58 encoded addresses | // strip out uri scheme for base58 encoded addresses | ||||
rv.address = uri.path(); | rv.address = uri.path(); | ||||
} | } | ||||
Show All 39 Lines | for (QList<QPair<QString, QString>>::iterator i = items.begin(); | ||||
} | } | ||||
} | } | ||||
if (out) { | if (out) { | ||||
*out = rv; | *out = rv; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out) { | bool parseBitcoinURI(const QString &scheme, QString uri, | ||||
// Convert bitcoincash:// to bitcoincash: | SendCoinsRecipient *out) { | ||||
// | // | ||||
// Cannot handle this later, because bitcoincash:// | // Cannot handle this later, because bitcoincash:// | ||||
// will cause Qt to see the part after // as host, | // will cause Qt to see the part after // as host, | ||||
// which will lower-case it (and thus invalidate the address). | // which will lower-case it (and thus invalidate the address). | ||||
if (uri.startsWith(URI_SCHEME + "://", Qt::CaseInsensitive)) { | if (uri.startsWith(scheme + "://", Qt::CaseInsensitive)) { | ||||
uri.replace(0, URI_SCHEME.length() + 3, URI_SCHEME + ":"); | uri.replace(0, scheme.length() + 3, scheme + ":"); | ||||
} | } | ||||
QUrl uriInstance(uri); | QUrl uriInstance(uri); | ||||
return parseBitcoinURI(uriInstance, out); | return parseBitcoinURI(scheme, uriInstance, out); | ||||
} | } | ||||
QString formatBitcoinURI(const Config &cfg, const SendCoinsRecipient &info) { | QString formatBitcoinURI(const Config &cfg, const SendCoinsRecipient &info) { | ||||
QString ret = info.address; | QString ret = info.address; | ||||
if (!cfg.UseCashAddrEncoding()) { | if (!cfg.UseCashAddrEncoding()) { | ||||
// prefix address with uri scheme for base58 encoded addresses. | // prefix address with uri scheme for base58 encoded addresses. | ||||
ret = (URI_SCHEME + ":%1").arg(ret); | ret = (bitcoinURIScheme(cfg) + ":%1").arg(ret); | ||||
} | } | ||||
int paramCount = 0; | int paramCount = 0; | ||||
if (info.amount) { | if (info.amount) { | ||||
ret += | ret += | ||||
QString("?amount=%1") | QString("?amount=%1") | ||||
.arg(BitcoinUnits::format(BitcoinUnits::BCH, info.amount, false, | .arg(BitcoinUnits::format(BitcoinUnits::BCH, info.amount, false, | ||||
BitcoinUnits::separatorNever)); | BitcoinUnits::separatorNever)); | ||||
▲ Show 20 Lines • Show All 756 Lines • Show Last 20 Lines |