Skip to content

Commit

Permalink
Merge pull request #3108 from Diapolo/paymentserver_style
Browse files Browse the repository at this point in the history
paymentserver: style fixes / cleanup
  • Loading branch information
laanwj committed Oct 20, 2013
2 parents 00f198c + 95d4a2b commit 76eb192
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ int main(int argc, char *argv[])
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
QObject::connect(paymentServer, SIGNAL(receivedPaymentACK(QString)),
&window, SLOT(showPaymentACK(QString)));
QObject::connect(paymentServer, SIGNAL(reportError(QString, QString, unsigned int)),
guiref, SLOT(message(QString, QString, unsigned int)));
QObject::connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)),
guiref, SLOT(message(QString,QString,unsigned int)));
QTimer::singleShot(100, paymentServer, SLOT(uiReady()));

app.exec();
Expand Down
52 changes: 30 additions & 22 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool PaymentServer::ipcSendCommandLine(int argc, char* argv[])
if (arg.startsWith("-"))
continue;

if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) // bitcoin:
if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) // bitcoin: URI
{
savedPaymentRequests.append(arg);

Expand Down Expand Up @@ -220,9 +220,9 @@ bool PaymentServer::ipcSendCommandLine(int argc, char* argv[])
}
else
{
qDebug() << "PaymentServer::ipcSendCommandLine : Payment request file does not exist: " << argv[i];
// Printing to debug.log is about the best we can do here, the
// GUI hasn't started yet so we can't pop up a message box.
qDebug() << "PaymentServer::ipcSendCommandLine : Payment request file does not exist: " << arg;
}
}

Expand All @@ -246,6 +246,7 @@ bool PaymentServer::ipcSendCommandLine(int argc, char* argv[])
delete socket;
fResult = true;
}

return fResult;
}

Expand All @@ -255,7 +256,9 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : QObject(p
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;

// Install global event filter to catch QFileOpenEvents on the mac (sent when you click bitcoin: links)
// Install global event filter to catch QFileOpenEvents
// on Mac: sent when you click bitcoin: links
// other OSes: helpful when dealing with payment-request files (in the future)
if (parent)
parent->installEventFilter(this);

Expand Down Expand Up @@ -310,7 +313,7 @@ void PaymentServer::initNetManager()
if (netManager != NULL)
delete netManager;

// netManager is used to fetch paymentrequests given in bitcoin: URI's
// netManager is used to fetch paymentrequests given in bitcoin: URIs
netManager = new QNetworkAccessManager(this);

// Use proxy settings from optionsModel:
Expand Down Expand Up @@ -360,7 +363,8 @@ void PaymentServer::handleURIOrFile(const QString& s)
#endif
if (uri.hasQueryItem("request"))
{
QByteArray temp; temp.append(uri.queryItemValue("request"));
QByteArray temp;
temp.append(uri.queryItemValue("request"));
QString decoded = QUrl::fromPercentEncoding(temp);
QUrl fetchUrl(decoded, QUrl::StrictMode);

Expand All @@ -370,13 +374,17 @@ void PaymentServer::handleURIOrFile(const QString& s)
if (fetchUrl.isValid())
fetchRequest(fetchUrl);
else
qDebug() << "PaymentServer::handleURIOrFile : Invalid url: " << fetchUrl;
qDebug() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl;
return;
}

SendCoinsRecipient recipient;
if (GUIUtil::parseBitcoinURI(s, &recipient))
emit receivedPaymentRequest(recipient);
else
emit message(tr("URI handling"),
tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
CClientUIInterface::ICON_WARNING);
return;
}

Expand Down Expand Up @@ -408,10 +416,10 @@ void PaymentServer::handleURIConnection()
if (clientConnection->bytesAvailable() < (int)sizeof(quint16)) {
return;
}
QString message;
in >> message;
QString msg;
in >> msg;

handleURIOrFile(message);
handleURIOrFile(msg);
}

bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPlus& request)
Expand Down Expand Up @@ -444,11 +452,11 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) {
CTxOut txOut(sendingTo.second, sendingTo.first);
if (txOut.IsDust(CTransaction::nMinRelayTxFee)) {
QString message = QObject::tr("Requested payment amount (%1) too small")
QString msg = QObject::tr("Requested payment amount (%1) too small")
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second));

qDebug() << "PaymentServer::processPaymentRequest : " << message;
emit reportError(tr("Payment request error"), message, CClientUIInterface::MODAL);
qDebug() << "PaymentServer::processPaymentRequest : " << msg;
emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
return false;
}

Expand Down Expand Up @@ -485,9 +493,9 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
// Insecure payments to custom bitcoin addresses are not supported
// (there is no good way to tell the user where they are paying in a way
// they'd have a chance of understanding).
emit reportError(tr("Payment request error"),
tr("Insecure requests to custom payment scripts unsupported"),
CClientUIInterface::MODAL);
emit message(tr("Payment request error"),
tr("Insecure requests to custom payment scripts unsupported"),
CClientUIInterface::MSG_ERROR);
return false;
}
}
Expand Down Expand Up @@ -566,11 +574,11 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
reply->deleteLater();
if (reply->error() != QNetworkReply::NoError)
{
QString message = QObject::tr("Error communicating with %1: %2")
QString msg = QObject::tr("Error communicating with %1: %2")
.arg(reply->request().url().toString())
.arg(reply->errorString());
qDebug() << "PaymentServer::netRequestFinished : " << message;
emit reportError(tr("Network request error"), message, CClientUIInterface::MODAL);
qDebug() << "PaymentServer::netRequestFinished : " << msg;
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
return;
}

Expand All @@ -595,10 +603,10 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
payments::PaymentACK paymentACK;
if (!paymentACK.ParseFromArray(data.data(), data.size()))
{
QString message = QObject::tr("Bad response from server %1")
QString msg = QObject::tr("Bad response from server %1")
.arg(reply->request().url().toString());
qDebug() << "PaymentServer::netRequestFinished : " << message;
emit reportError(tr("Network request error"), message, CClientUIInterface::MODAL);
qDebug() << "PaymentServer::netRequestFinished : " << msg;
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
}
else {
emit receivedPaymentACK(QString::fromStdString(paymentACK.memo()));
Expand All @@ -615,7 +623,7 @@ void PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError>
qDebug() << "PaymentServer::reportSslErrors : " << err;
errString += err.errorString() + "\n";
}
emit reportError(tr("Network request error"), errString, CClientUIInterface::MODAL);
emit message(tr("Network request error"), errString, CClientUIInterface::MSG_ERROR);
}

void PaymentServer::setOptionsModel(OptionsModel *optionsModel)
Expand Down
4 changes: 2 additions & 2 deletions src/qt/paymentserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class PaymentServer : public QObject
// Fired when a valid PaymentACK is received
void receivedPaymentACK(QString);

// Fired when an error should be reported to the user
void reportError(QString, QString, unsigned int);
// Fired when a message should be reported to the user
void message(const QString &title, const QString &message, unsigned int style);

public slots:
// Signal this when the main window's UI is ready
Expand Down

0 comments on commit 76eb192

Please sign in to comment.