Skip to content

Commit

Permalink
Merge pull request #47 from mceme/masterendecrypt
Browse files Browse the repository at this point in the history
Masterendecrypt
  • Loading branch information
mceme committed Jun 23, 2019
2 parents 9db070b + 09747de commit 409ba86
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 42 deletions.
56 changes: 35 additions & 21 deletions src/qt/encryptdecryptdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/forms/sendcoinsentry.ui
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<item>
<widget class="QLabel" name="Labelimgbase64">
<property name="text">
<string>Base64:</string>
<string>Message:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down
59 changes: 53 additions & 6 deletions src/qt/forms/transactiondescdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,61 @@
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
<property name="rightMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QPushButton" name="DownloadButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="maximumSize">
<size>
<width>16777015</width>
<height>16777215</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down
29 changes: 22 additions & 7 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)){

Expand All @@ -180,8 +184,9 @@ void SendCoinsEntry::on_chooserButton_clicked()
ui->Imgbase64Edit->setText("");
return;
}

fileselected=true;
ui->Imgbase64Edit->setText(qsencoded);
ui->Imgbase64Edit->setDisabled(1);
}
}
}
Expand Down Expand Up @@ -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); }");
Expand Down Expand Up @@ -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);
Expand Down
105 changes: 99 additions & 6 deletions src/qt/transactiondescdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,49 @@
#include <QPixmap>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QLabel>
#include <QMovie>
#include <QGraphicsProxyWidget>
#include <QFileDialog>
#include <string>
#include <vector>



QString encodeqstring ;

TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *parent) :
QDialog(parent),
ui(new Ui::TransactionDescDialog)
{
ui->setupUi(this);
ui->graphicsView->setVisible(false);
ui->DownloadButton->setVisible(false);
/* Open CSS when configured */
this->setStyleSheet(GUIUtil::loadStyleSheet());

QString desc = idx.data(TransactionTableModel::LongDescriptionRole).toString();
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -131,9 +143,90 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa
}
}
}
else { //message

ui->DownloadButton->setVisible(false);
desc = desc + "<br><b><b>"+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<unsigned char> bytesarray = base64trdialog.decode(encodestr);

if(bytesarray.size()>0)
{

QByteArray *base64decodearray;
base64decodearray = new QByteArray(reinterpret_cast<const char*>(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;
Expand Down

0 comments on commit 409ba86

Please sign in to comment.