Skip to content

Commit

Permalink
Merge remote-tracking branch 'PR/pr/192' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaqueeee committed Nov 21, 2016
2 parents 675d294 + 96c7dde commit 6f2b45b
Show file tree
Hide file tree
Showing 12 changed files with 1,627 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "oshelper.h"
#include "WalletManager.h"
#include "Wallet.h"
#include "QRCodeImageProvider.h"
#include "PendingTransaction.h"
#include "TranslationManager.h"
#include "TransactionInfo.h"
Expand Down Expand Up @@ -102,6 +103,7 @@ int main(int argc, char *argv[])

engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());

engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());

// export to QML monero accounts root directory
// wizard is talking about where
Expand Down
13 changes: 11 additions & 2 deletions monero-core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ QMAKE_DISTCLEAN += -r $$WALLET_ROOT

INCLUDEPATH += $$WALLET_ROOT/include \
$$PWD/src/libwalletqt \
$$PWD/src/QR-Code-generator \
$$PWD/src

HEADERS += \
Expand All @@ -22,10 +23,14 @@ HEADERS += \
src/libwalletqt/PendingTransaction.h \
src/libwalletqt/TransactionHistory.h \
src/libwalletqt/TransactionInfo.h \
src/libwalletqt/QRCodeImageProvider.h \
oshelper.h \
TranslationManager.h \
src/model/TransactionHistoryModel.h \
src/model/TransactionHistorySortFilterModel.h
src/model/TransactionHistorySortFilterModel.h \
src/QR-Code-generator/BitBuffer.hpp \
src/QR-Code-generator/QrCode.hpp \
src/QR-Code-generator/QrSegment.hpp


SOURCES += main.cpp \
Expand All @@ -37,10 +42,14 @@ SOURCES += main.cpp \
src/libwalletqt/PendingTransaction.cpp \
src/libwalletqt/TransactionHistory.cpp \
src/libwalletqt/TransactionInfo.cpp \
src/libwalletqt/QRCodeImageProvider.cpp \
oshelper.cpp \
TranslationManager.cpp \
src/model/TransactionHistoryModel.cpp \
src/model/TransactionHistorySortFilterModel.cpp
src/model/TransactionHistorySortFilterModel.cpp \
src/QR-Code-generator/BitBuffer.cpp \
src/QR-Code-generator/QrCode.cpp \
src/QR-Code-generator/QrSegment.cpp

lupdate_only {
SOURCES = *.qml \
Expand Down
55 changes: 55 additions & 0 deletions pages/Receive.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ Rectangle {
integratedAddressLine.text = qsTr("Invalid payment ID")
}

function makeQRCodeString() {
var s = "monero:"
var nfields = 0
s += addressLine.text
var amount = amountLine.text.trim()
if (amount !== "") {
s += (nfields++ ? "&" : "?")
s += "tx_amount=" + amount
}
var pid = paymentIdLine.text.trim()
if (pid !== "") {
s += (nfields++ ? "&" : "?")
s += "tx_payment_id=" + pid
}
return s
}

Clipboard { id: clipboard }


Expand All @@ -71,6 +88,7 @@ Rectangle {
property int labelWidth: 120
property int editWidth: 400
property int lineEditFontSize: 12
property int qrCodeSize: 240


RowLayout {
Expand Down Expand Up @@ -183,6 +201,43 @@ Rectangle {
}
}

RowLayout {
id: amountRow
Label {
id: amountLabel
fontSize: 14
text: qsTr("Amount") + translationManager.emptyString
width: mainLayout.labelWidth
}


LineEdit {
id: amountLine
fontSize: mainLayout.lineEditFontSize
placeholderText: qsTr("Amount") + translationManager.emptyString
readOnly: false
width: mainLayout.editWidth
Layout.fillWidth: true
validator: DoubleValidator {
bottom: 0.0
top: 18446744.073709551615
decimals: 12
notation: DoubleValidator.StandardNotation
locale: "C"
}
}
}

Image {
id: qrCode
anchors.margins: 50
anchors.top: amountRow.bottom
Layout.fillWidth: true
Layout.minimumHeight: mainLayout.qrCodeSize
smooth: false
fillMode: Image.PreserveAspectFit
source: "image://qrcode/" + makeQRCodeString()
}
}

function onPageCompleted() {
Expand Down
63 changes: 63 additions & 0 deletions src/QR-Code-generator/BitBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* QR Code generator library (C++)
*
* Copyright (c) 2016 Project Nayuki
* https://www.nayuki.io/page/qr-code-generator-library
*
* (MIT License)
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* - The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* - The Software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. In no event shall the
* authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising from,
* out of or in connection with the Software or the use or other dealings in the
* Software.
*/

#include <cstddef>
#include "BitBuffer.hpp"


qrcodegen::BitBuffer::BitBuffer() :
data(),
bitLength(0) {}


int qrcodegen::BitBuffer::getBitLength() const {
return bitLength;
}


std::vector<uint8_t> qrcodegen::BitBuffer::getBytes() const {
return data;
}


void qrcodegen::BitBuffer::appendBits(uint32_t val, int len) {
if (len < 0 || len > 32 || (len < 32 && (val >> len) != 0))
throw "Value out of range";
size_t newBitLen = bitLength + len;
while (data.size() * 8 < newBitLen)
data.push_back(0);
for (int i = len - 1; i >= 0; i--, bitLength++) // Append bit by bit
data.at(bitLength >> 3) |= ((val >> i) & 1) << (7 - (bitLength & 7));
}


void qrcodegen::BitBuffer::appendData(const QrSegment &seg) {
size_t newBitLen = bitLength + seg.bitLength;
while (data.size() * 8 < newBitLen)
data.push_back(0);
for (int i = 0; i < seg.bitLength; i++, bitLength++) { // Append bit by bit
int bit = (seg.data.at(i >> 3) >> (7 - (i & 7))) & 1;
data.at(bitLength >> 3) |= bit << (7 - (bitLength & 7));
}
}
76 changes: 76 additions & 0 deletions src/QR-Code-generator/BitBuffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* QR Code generator library (C++)
*
* Copyright (c) 2016 Project Nayuki
* https://www.nayuki.io/page/qr-code-generator-library
*
* (MIT License)
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* - The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* - The Software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. In no event shall the
* authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising from,
* out of or in connection with the Software or the use or other dealings in the
* Software.
*/

#pragma once

#include <cstdint>
#include <vector>
#include "QrSegment.hpp"


namespace qrcodegen {

/*
* An appendable sequence of bits. Bits are packed in big endian within a byte.
*/
class BitBuffer final {

/*---- Fields ----*/
private:

std::vector<uint8_t> data;
int bitLength;



/*---- Constructor ----*/
public:

// Creates an empty bit buffer (length 0).
BitBuffer();



/*---- Methods ----*/
public:

// Returns the number of bits in the buffer, which is a non-negative value.
int getBitLength() const;


// Returns a copy of all bytes, padding up to the nearest byte.
std::vector<uint8_t> getBytes() const;


// Appends the given number of bits of the given value to this sequence.
// If 0 <= len <= 31, then this requires 0 <= val < 2^len.
void appendBits(uint32_t val, int len);


// Appends the data of the given segment to this bit buffer.
void appendData(const QrSegment &seg);

};

}
Loading

0 comments on commit 6f2b45b

Please sign in to comment.