diff --git a/src/qt/encryptdecryptdialog.cpp b/src/qt/encryptdecryptdialog.cpp index e6300c7..f0694b5 100644 --- a/src/qt/encryptdecryptdialog.cpp +++ b/src/qt/encryptdecryptdialog.cpp @@ -597,36 +597,50 @@ void EncryptDecryptDialog::decodebase64Clicked() void EncryptDecryptDialog::on_cmdShowSave_clicked() { std::string delctype = "Files (*.png *.jpeg *.jpg *.gif *.tiff *.bmp)"; - QString encodestringqt = ui->lineEditimgbase64->text(); + std::string savefile= "c:/image.png"; + + QString encodestringqt = ui->lineEditimgbase64->text(); std::string encodestr = encodestringqt.toUtf8().constData(); std::string typebase64 = encodestr.substr(0, 1); - if(typebase64=="J" /*pdf*/ || typebase64=="V"){ - delctype = "Files (*.pdf *.txt)";; - } - else if(typebase64=="A" /*mp4*/) - { - delctype = "Files (*.mp4)";; - } - else if( typebase64=="R") /*gif*/ - { - delctype = "Files (*.gif)";; - } - else if( typebase64=="U") /*avi*/ - { - delctype = "Files (*.avi)";; - } - else if( typebase64=="S") /*mp3*/ - { - delctype = "Files (*.mp3)";; - } + if(typebase64=="J" /*pdf*/ ){ + delctype = "Files (*.pdf)"; + savefile = "c:/doc.pdf"; + } + else if(typebase64=="V" /*txt*/) + { + delctype = "Files (*.txt)"; + savefile = "c:/text.txt"; + } + else if(typebase64=="A" /*mp4*/) + { + delctype = "Files (*.mp4)"; + savefile = "c:/movie.mp4"; + } + else if( typebase64=="R") /*gif*/ + { + delctype = "Files (*.gif)"; + savefile = "c:/image.gif"; + } + else if( typebase64=="U") /*avi*/ + { + delctype = "Files (*.avi)"; + savefile = "c:/movie.avi"; + } + else if( typebase64=="S") /*mp3*/ + { + delctype = "Files (*.mp3)"; + savefile = "c:/music.mp3"; + } + + QString fileNamesave = QFileDialog::getSaveFileName(this, tr("Save File"), - "c:/image.png", + savefile.c_str(), tr(delctype.c_str())); QByteArray base64decodefilearray; diff --git a/src/qt/forms/sendcoinsentry.ui b/src/qt/forms/sendcoinsentry.ui index 39c29a1..bde6852 100644 --- a/src/qt/forms/sendcoinsentry.ui +++ b/src/qt/forms/sendcoinsentry.ui @@ -242,7 +242,7 @@ - Base64: + Message: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter diff --git a/src/qt/forms/transactiondescdialog.ui b/src/qt/forms/transactiondescdialog.ui index 087cd69..e67e794 100644 --- a/src/qt/forms/transactiondescdialog.ui +++ b/src/qt/forms/transactiondescdialog.ui @@ -35,14 +35,61 @@ - - - Qt::Horizontal + + + 0 - - QDialogButtonBox::Close + + 0 - + + + + true + + + + 120 + 16777215 + + + + Qt::LeftToRight + + + + + + Download + + + + + + + + 16777015 + 16777215 + + + + Qt::LeftToRight + + + false + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index d13ab35..842f6cb 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -26,6 +26,8 @@ base64 base64; typedef unsigned char BYTE; +bool fileselected=false; + SendCoinsEntry::SendCoinsEntry(const PlatformStyle *platformStyle, QWidget *parent) : QStackedWidget(parent), ui(new Ui::SendCoinsEntry), @@ -121,6 +123,8 @@ void SendCoinsEntry::clear() ui->addAsLabel->clear(); ui->payAmount->clear(); ui->Imgbase64Edit->clear(); + ui->Imgbase64Edit->setEnabled(1); + fileselected=false; ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked); ui->messageTextLabel->clear(); ui->messageTextLabel->hide(); @@ -156,15 +160,15 @@ void SendCoinsEntry::on_chooserButton_clicked() if (dialog.exec()){ QStringList fileNames = dialog.selectedFiles(); - if(fileNames.size()>0){ + if(fileNames.size()>0){ QString file = fileNames[0]; ui->FileNamesTxt->setText(file); - std::string filestr = file.toUtf8().constData(); - std::string encodedstring = base64.encode(filestr); - QString qsencoded = QString::fromStdString(encodedstring); + std::string filestr = file.toUtf8().constData(); + std::string encodedstring = base64.encode(filestr); + QString qsencoded = QString::fromStdString(encodedstring); if(!base64.base64Validator(encodedstring)){ @@ -180,8 +184,9 @@ void SendCoinsEntry::on_chooserButton_clicked() ui->Imgbase64Edit->setText(""); return; } - + fileselected=true; ui->Imgbase64Edit->setText(qsencoded); + ui->Imgbase64Edit->setDisabled(1); } } } @@ -215,13 +220,20 @@ bool SendCoinsEntry::validate() { std::string imgbase64=ui->Imgbase64Edit->text().toUtf8().constData(); - if(!base64.base64Validator(imgbase64)){ + + + if(fileselected) + { + if(!base64.base64Validator(imgbase64)){ ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); ui->Imgbase64Edit->setToolTip("Base64 string not valid."); ui->Imgbase64Edit->setText(""); retval = false; - } + } + } + + if(ui->Imgbase64Edit->text().length()>10000000) { ui->Imgbase64Edit->setStyleSheet("QLineEdit { background: rgb(220, 20, 60); selection-background-color: rgb(233, 99, 0); }"); @@ -262,6 +274,9 @@ SendCoinsRecipient SendCoinsEntry::getValue() recipient.address = ui->payTo->text(); recipient.label = ui->addAsLabel->text(); recipient.imgbase64 = ui->Imgbase64Edit->text(); + if(ui->Imgbase64Edit->text().size()>0 && !fileselected){ //message + recipient.imgbase64 ="m:"+ ui->Imgbase64Edit->text(); + } recipient.amount = ui->payAmount->value(); recipient.message = ui->messageTextLabel->text(); recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); diff --git a/src/qt/transactiondescdialog.cpp b/src/qt/transactiondescdialog.cpp index fc126b8..08becd8 100644 --- a/src/qt/transactiondescdialog.cpp +++ b/src/qt/transactiondescdialog.cpp @@ -20,14 +20,16 @@ #include #include #include +#include #include #include #include +#include #include #include - + QString encodeqstring ; TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *parent) : QDialog(parent), @@ -35,6 +37,7 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa { ui->setupUi(this); ui->graphicsView->setVisible(false); + ui->DownloadButton->setVisible(false); /* Open CSS when configured */ this->setStyleSheet(GUIUtil::loadStyleSheet()); @@ -42,15 +45,24 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa ui->detailText->setHtml(desc); /* Start ImageView */ - QString encodeqstring = idx.data(TransactionTableModel::Imgbase64Role).toString(); + encodeqstring = idx.data(TransactionTableModel::Imgbase64Role).toString(); std::string encodestr = encodeqstring.toUtf8().constData(); std::string extension = "png"; float delctype = 0; - - if(encodestr.size()>5) + + + + if(encodestr.size()>2) { + std::string ismessage = encodestr.substr(0, 2); + + if(ismessage != "m:") + { + + ui->DownloadButton->setVisible(true); + std::string typebase64 = encodestr.substr(0, 1); if(typebase64=="J" /*pdf*/ || typebase64=="V"){ delctype = 2; @@ -93,7 +105,7 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa else if(delctype==1){ ui->graphicsView->setVisible(true); ui->graphicsView->setGeometry(QRect(0, 0, 400, 250)); - ui->graphicsView->show(); + QLabel *gif_anim = new QLabel(); gif_anim->setGeometry(0, 0, 400, 250); @@ -107,7 +119,7 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa QGraphicsProxyWidget *proxy = scene->addWidget(gif_anim); scene->addWidget(gif_anim); ui->graphicsView->setScene( scene ); - + ui->graphicsView->show(); } /* Start Document */ else if (delctype==2) @@ -131,9 +143,90 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa } } } + else { //message + ui->DownloadButton->setVisible(false); + desc = desc + "
"+encodestr.c_str(); + ui->detailText->setHtml(desc); + } + + } } +void TransactionDescDialog::on_DownloadButton_clicked() + { + + + std::string delctype = "Files (*.png *.jpeg *.jpg *.gif *.tiff *.bmp)"; + + std::string savefile = "c:/image.png"; + + std::string encodestr = encodeqstring.toUtf8().constData(); + + std::string typebase64 = encodestr.substr(0, 1); + + + + if(typebase64=="J" /*pdf*/ ){ + delctype = "Files (*.pdf)"; + savefile = "c:/doc.pdf"; + } + else if(typebase64=="V" /*txt*/) + { + delctype = "Files (*.txt)"; + savefile = "c:/text.txt"; + } + else if(typebase64=="A" /*mp4*/) + { + delctype = "Files (*.mp4)"; + savefile = "c:/movie.mp4"; + } + else if( typebase64=="R") /*gif*/ + { + delctype = "Files (*.gif)"; + savefile = "c:/image.gif"; + } + else if( typebase64=="U") /*avi*/ + { + delctype = "Files (*.avi)"; + savefile = "c:/movie.avi"; + } + else if( typebase64=="S") /*mp3*/ + { + delctype = "Files (*.mp3)"; + savefile = "c:/music.mp3"; + } + + base64 base64trdialog; + + std::vector bytesarray = base64trdialog.decode(encodestr); + + if(bytesarray.size()>0) + { + + QByteArray *base64decodearray; + base64decodearray = new QByteArray(reinterpret_cast(bytesarray.data()), bytesarray.size()); + + + + QString fileNamesave = QFileDialog::getSaveFileName(this, tr("Save File"), + savefile.c_str(), + tr(delctype.c_str())); + + QByteArray base64decodefilearray; + + base64decodefilearray.setRawData(base64decodearray->data(), base64decodearray->size()); + // ... fill the array with data ... + + QFile file(fileNamesave.toUtf8().constData()); + file.open(QIODevice::WriteOnly); + + + file.write(base64decodefilearray); + file.close(); + } + } + TransactionDescDialog::~TransactionDescDialog() { delete ui; diff --git a/src/qt/transactiondescdialog.h b/src/qt/transactiondescdialog.h index 54374e3..7ff343b 100644 --- a/src/qt/transactiondescdialog.h +++ b/src/qt/transactiondescdialog.h @@ -24,8 +24,13 @@ class TransactionDescDialog : public QDialog explicit TransactionDescDialog(const QModelIndex &idx, QWidget *parent = 0); ~TransactionDescDialog(); + private: Ui::TransactionDescDialog *ui; + +private Q_SLOTS: + void on_DownloadButton_clicked(); + }; #endif // BITCOIN_QT_TRANSACTIONDESCDIALOG_H diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 7e1808a..50a4cea 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -165,7 +165,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa QAction *copyAddressAction = new QAction(tr("Copy address"), this); QAction *copyLabelAction = new QAction(tr("Copy label"), this); QAction *copyAmountAction = new QAction(tr("Copy amount"), this); - QAction *copyImgbase64Action = new QAction(tr("Copy imgbase64"), this); + QAction *copyImgbase64Action = new QAction(tr("Copy img"), this); QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this); QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this); QAction *copyTxPlainText = new QAction(tr("Copy full transaction details"), this);