URL handling
Well, carp. Both Qt and the code base were quite broken for this. I implemented workarounds and fixes such that things that weren’t broken before should stay working, for example, if qt4 worked for a lot of this, it still would, and if Qt on Windows / Linux worked for this before, it shall still work for it.
This commit is contained in:
parent
2eebeb2f4c
commit
9dd5cdf841
|
@ -2,6 +2,17 @@
|
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>dogecoin</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>dogecoin</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.5.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <QKeyEvent>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QApplication>
|
||||
#include <QLocale>
|
||||
#include <qmath.h> // for qPow()
|
||||
|
||||
BitcoinAmountField::BitcoinAmountField(QWidget *parent):
|
||||
|
@ -45,8 +46,10 @@ void BitcoinAmountField::setText(const QString &text)
|
|||
{
|
||||
if (text.isEmpty())
|
||||
amount->clear();
|
||||
else
|
||||
amount->setValue(text.toDouble());
|
||||
else {
|
||||
QLocale locale;
|
||||
amount->setValue(locale.toDouble(text));
|
||||
}
|
||||
}
|
||||
|
||||
void BitcoinAmountField::clear()
|
||||
|
|
|
@ -81,6 +81,27 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent)
|
|||
widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
QList<QPair<QString, QString> > queryItems(const QString& queryData) {
|
||||
QList<QPair<QString, QString> > items;
|
||||
|
||||
int rightCount = queryData.count();
|
||||
if ( queryData[0] == '?' ) {
|
||||
rightCount -= 1;
|
||||
}
|
||||
|
||||
QStringList params = queryData.right(rightCount).split('&');
|
||||
|
||||
for ( int i = 0; i < params.size(); ++i ) {
|
||||
QStringList keyVal = params[i].split('=');
|
||||
|
||||
if ( keyVal.size() > 1 ) {
|
||||
items.append( QPair<QString, QString>(keyVal[0], keyVal[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
|
||||
{
|
||||
// return if URI is not valid or is no bitcoin URI
|
||||
|
@ -88,14 +109,21 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
|
|||
return false;
|
||||
|
||||
SendCoinsRecipient rv;
|
||||
rv.address = uri.path();
|
||||
|
||||
// WTF Qt?
|
||||
const int addrlen = 34;
|
||||
QString address = uri.path().left(addrlen);
|
||||
rv.address = address;
|
||||
rv.amount = 0;
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
QList<QPair<QString, QString> > items = uri.queryItems();
|
||||
#else
|
||||
QUrlQuery uriQuery(uri);
|
||||
QList<QPair<QString, QString> > items = uriQuery.queryItems();
|
||||
// Apparently Qt 5 is broken a *lot*
|
||||
// QUrlQuery uriQuery(uri);
|
||||
// QList<QPair<QString, QString> > items = uriQuery.queryItems();
|
||||
QString uriString = uri.path();
|
||||
QList<QPair<QString, QString> > items = queryItems(uriString.right(uriString.size() - addrlen - 1));
|
||||
#endif
|
||||
for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
|
||||
{
|
||||
|
|
|
@ -119,10 +119,16 @@ bool PaymentServer::eventFilter(QObject *object, QEvent *event)
|
|||
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
||||
if (!fileEvent->url().isEmpty())
|
||||
{
|
||||
// WTF Qt?
|
||||
QString url = fileEvent->url().toString();
|
||||
if ( url.startsWith( "file:dogecoin:/D" ) ) {
|
||||
url.replace( "file:dogecoin:/D", "dogecoin://D" );
|
||||
}
|
||||
|
||||
if (saveURIs) // Before main window is ready:
|
||||
savedPaymentRequests.append(fileEvent->url().toString());
|
||||
savedPaymentRequests.append(url);
|
||||
else
|
||||
emit receivedURI(fileEvent->url().toString());
|
||||
emit receivedURI(url);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue