PRCYCoin  2.0.0.7rc1
P2P Digital Currency
2faqrdialog.cpp
Go to the documentation of this file.
1 #include "2faqrdialog.h"
2 #include "ui_2faqrdialog.h"
3 #include "receiverequestdialog.h"
4 #include "guiconstants.h"
5 #include "key.h"
6 #include "pubkey.h"
7 #include <string>
8 #include <algorithm>
9 
10 #include <QClipboard>
11 #include <QDrag>
12 #include <QMenu>
13 #include <QMimeData>
14 #include <QMouseEvent>
15 #include <QPixmap>
16 
17 // #define USE_QRCODE
18 
19 #if defined(HAVE_CONFIG_H)
20 #include "config/prcycoin-config.h" /* for USE_QRCODE */
21 #endif
22 
23 #ifdef USE_QRCODE
24 #include <qrencode.h>
25 #endif
26 
27 TwoFAQRDialog::TwoFAQRDialog(QWidget *parent) :
28  QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
29  ui(new Ui::TwoFAQRDialog)
30 {
31  ui->setupUi(this);
32 
33 #ifndef USE_QRCODE
34  ui->lblQRCode->setVisible(false);
35 #endif
36 
37  connect(ui->btnCopy, SIGNAL(clicked()), this, SLOT(on_btnCopyURI_clicked()));
38  connect(ui->btnNext, SIGNAL(clicked()), this, SLOT(accept()));
39  connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
40 
41  ui->label->setVisible(true);
42  ui->label_2->setVisible(true);
43  update();
44 }
45 
47 {
48  delete ui;
49 }
50 
52 {
53  this->model = model;
54 }
55 
57 {
58  CKey newKey;
59  newKey.MakeNewKey(true);
60 
61  CPubKey pubKey;
62  pubKey = newKey.GetPubKey();
63 
64  QString uri;
65  QString infoText;
66  CBitcoinAddress address(pubKey.GetID());
67  std::string addr = "";
68  for (char c : address.ToString()) {
69  if (!std::isdigit(c)) addr += c;
70  }
71 
73  QSettings settings;
74  int digits = settings.value("2fadigits").toInt();
75  if (digits == 8) {
76  uri.sprintf("otpauth://totp/PRCY:QT Wallet?secret=%s&issuer=prcycoin&algorithm=SHA1&digits=8&period=30", addr.c_str());
77  } else if (digits == 6) {
78  uri.sprintf("otpauth://totp/PRCY:QT Wallet?secret=%s&issuer=prcycoin&algorithm=SHA1&digits=6&period=30", addr.c_str());
79  }
80 
81  infoText = "Recovery Key: ";
82  ui->lblURI->setText(infoText + addr.c_str());
83 
84 #ifdef USE_QRCODE
85  ui->lblQRCode->setText("");
86  if (!uri.isEmpty()) {
87  // limit URI length
88  if (uri.length() > MAX_URI_LENGTH) {
89  ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
90  } else {
91  QRcode* code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
92  if (!code) {
93  ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
94  return;
95  }
96  QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
97  myImage.fill(0xffffff);
98  unsigned char* p = code->data;
99  for (int y = 0; y < code->width; y++) {
100  for (int x = 0; x < code->width; x++) {
101  myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
102  p++;
103  }
104  }
105  QRcode_free(code);
106 
107  ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
108  }
109  }
110 #endif
111 }
112 
114 {
115  QString secret = QString::fromStdString(pwalletMain->Read2FASecret());
116  GUIUtil::setClipboard(secret);
117 }
TwoFAQRDialog::setModel
void setModel(WalletModel *model)
Definition: 2faqrdialog.cpp:51
CKey::MakeNewKey
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:40
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:102
TwoFAQRDialog::model
WalletModel * model
Definition: 2faqrdialog.h:32
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
pubkey.h
TwoFAQRDialog::update
void update()
Definition: 2faqrdialog.cpp:56
2faqrdialog.h
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
GUIUtil::setClipboard
void setClipboard(const QString &str)
Definition: guiutil.cpp:785
CWallet::Write2FASecret
bool Write2FASecret(std::string secret)
Definition: wallet.cpp:384
prcycoin-config.h
TwoFAQRDialog
Definition: 2faqrdialog.h:13
TwoFAQRDialog::TwoFAQRDialog
TwoFAQRDialog(QWidget *parent=0)
Definition: 2faqrdialog.cpp:27
TwoFAQRDialog::ui
Ui::TwoFAQRDialog * ui
Definition: 2faqrdialog.h:31
TwoFAQRDialog::on_btnCopyURI_clicked
void on_btnCopyURI_clicked()
Definition: 2faqrdialog.cpp:113
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:79
TwoFAQRDialog::settings
QSettings settings
Definition: 2faqrdialog.h:33
key.h
TwoFAQRDialog::~TwoFAQRDialog
~TwoFAQRDialog()
Definition: 2faqrdialog.cpp:46
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
Ui
Definition: 2faconfirmdialog.h:7
guiconstants.h
CKey
An encapsulated private key.
Definition: key.h:39
CWallet::Read2FASecret
std::string Read2FASecret()
Definition: wallet.cpp:388
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
receiverequestdialog.h
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:143