diff options
author | Saturneric <[email protected]> | 2021-05-12 00:50:08 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-05-12 00:50:08 +0000 |
commit | b3ad42f01dcfaffeca4b906400df4094a978d095 (patch) | |
tree | 0a88a0168d5f9045d4144dd347fe25bd451000d2 /src/fileencryptiondialog.cpp | |
parent | Change CXX Standard to C++14 (diff) | |
download | GpgFrontend-b3ad42f01dcfaffeca4b906400df4094a978d095.tar.gz GpgFrontend-b3ad42f01dcfaffeca4b906400df4094a978d095.zip |
Srouce Files Tidy and Reform
Diffstat (limited to '')
-rwxr-xr-x | src/fileencryptiondialog.cpp | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/src/fileencryptiondialog.cpp b/src/fileencryptiondialog.cpp index 38b7de56..9b433ce8 100755 --- a/src/fileencryptiondialog.cpp +++ b/src/fileencryptiondialog.cpp @@ -21,10 +21,9 @@ #include "fileencryptiondialog.h" -FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList keyList, DialogAction action, QWidget *parent) - : QDialog(parent) - -{ +FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList keyList, DialogAction action, + QWidget *parent) + : QDialog(parent) { mAction = action; mCtx = ctx; if (mAction == Decrypt) { @@ -43,39 +42,39 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k setModal(true); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotExecuteAction())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - QGroupBox *groupBox1 = new QGroupBox(tr("File")); + auto *groupBox1 = new QGroupBox(tr("File")); /* Setup input & Outputfileselection*/ inputFileEdit = new QLineEdit(); - QPushButton *fb1 = new QPushButton("..."); + auto *fb1 = new QPushButton("..."); connect(fb1, SIGNAL(clicked()), this, SLOT(slotSelectInputFile())); - QLabel *fl1 = new QLabel(tr("Input")); + auto *fl1 = new QLabel(tr("Input")); fl1->setBuddy(inputFileEdit); outputFileEdit = new QLineEdit(); - QPushButton *fb2 = new QPushButton("..."); + auto *fb2 = new QPushButton("..."); connect(fb2, SIGNAL(clicked()), this, SLOT(slotSelectOutputFile())); - QLabel *fl2 = new QLabel(tr("Output")); + auto *fl2 = new QLabel(tr("Output")); fl2->setBuddy(outputFileEdit); - QGridLayout *gLayout = new QGridLayout(); + auto *gLayout = new QGridLayout(); gLayout->addWidget(fl1, 0, 0); gLayout->addWidget(inputFileEdit, 0, 1); gLayout->addWidget(fb1, 0, 2); signFileEdit = new QLineEdit(); // verify does not need outfile, but signature file - if(mAction != Verify) { + if (mAction != Verify) { gLayout->addWidget(fl2, 1, 0); gLayout->addWidget(outputFileEdit, 1, 1); gLayout->addWidget(fb2, 1, 2); } else { - QPushButton *sfb1 = new QPushButton("..."); + auto *sfb1 = new QPushButton("..."); connect(sfb1, SIGNAL(clicked()), this, SLOT(slotSelectSignFile())); - QLabel *sfl1 = new QLabel(tr("Signature")); + auto *sfl1 = new QLabel(tr("Signature")); sfl1->setBuddy(signFileEdit); gLayout->addWidget(sfl1, 1, 0); @@ -94,7 +93,7 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k statusLabel = new QLabel(); statusLabel->setStyleSheet("QLabel {color: red;}"); - QVBoxLayout *vbox2 = new QVBoxLayout(); + auto *vbox2 = new QVBoxLayout(); vbox2->addWidget(groupBox1); vbox2->addWidget(mKeyList); vbox2->addWidget(statusLabel); @@ -102,15 +101,14 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k vbox2->addStretch(0); setLayout(vbox2); - if(action == Encrypt || action == Sign) { + if (action == Encrypt || action == Sign) { slotShowKeyList(); } exec(); } -void FileEncryptionDialog::slotSelectInputFile() -{ +void FileEncryptionDialog::slotSelectInputFile() { QString path = ""; if (inputFileEdit->text().size() > 0) { path = QFileInfo(inputFileEdit->text()).absolutePath(); @@ -121,9 +119,9 @@ void FileEncryptionDialog::slotSelectInputFile() inputFileEdit->setText(infileName); // try to find a matching output-filename, if not yet done - if (infileName > 0 - && outputFileEdit->text().size() == 0 - && signFileEdit->text().size() == 0) { + if (!infileName.isEmpty() + && outputFileEdit->text().size() == 0 + && signFileEdit->text().size() == 0) { if (mAction == Encrypt) { outputFileEdit->setText(infileName + ".asc"); } else if (mAction == Sign) { @@ -142,26 +140,26 @@ void FileEncryptionDialog::slotSelectInputFile() } } -void FileEncryptionDialog::slotSelectOutputFile() -{ +void FileEncryptionDialog::slotSelectOutputFile() { QString path = ""; if (outputFileEdit->text().size() > 0) { path = QFileInfo(outputFileEdit->text()).absolutePath(); } - QString outfileName = QFileDialog::getSaveFileName(this, tr("Save File"),path, NULL ,NULL ,QFileDialog::DontConfirmOverwrite); + QString outfileName = QFileDialog::getSaveFileName(this, tr("Save File"), path, nullptr, nullptr, + QFileDialog::DontConfirmOverwrite); outputFileEdit->setText(outfileName); } -void FileEncryptionDialog::slotSelectSignFile() -{ +void FileEncryptionDialog::slotSelectSignFile() { QString path = ""; if (signFileEdit->text().size() > 0) { path = QFileInfo(signFileEdit->text()).absolutePath(); } - QString signfileName = QFileDialog::getSaveFileName(this, tr("Open File"),path, NULL ,NULL ,QFileDialog::DontConfirmOverwrite); + QString signfileName = QFileDialog::getSaveFileName(this, tr("Open File"), path, nullptr, nullptr, + QFileDialog::DontConfirmOverwrite); signFileEdit->setText(signfileName); if (inputFileEdit->text().size() == 0 && signfileName.endsWith(".sig", Qt::CaseInsensitive)) { @@ -172,37 +170,36 @@ void FileEncryptionDialog::slotSelectSignFile() } -void FileEncryptionDialog::slotExecuteAction() -{ +void FileEncryptionDialog::slotExecuteAction() { QFile infile; infile.setFileName(inputFileEdit->text()); if (!infile.open(QIODevice::ReadOnly)) { - statusLabel->setText( tr("Couldn't open file")); + statusLabel->setText(tr("Couldn't open file")); inputFileEdit->setStyleSheet("QLineEdit { background: yellow }"); return; } QByteArray inBuffer = infile.readAll(); - QByteArray *outBuffer = new QByteArray(); + auto *outBuffer = new QByteArray(); infile.close(); - if ( mAction == Encrypt ) { - if (! mCtx->encrypt(mKeyList->getChecked(), inBuffer, outBuffer)) return; + if (mAction == Encrypt) { + if (!mCtx->encrypt(mKeyList->getChecked(), inBuffer, outBuffer)) return; } - if ( mAction == Decrypt ) { - if (! mCtx->decrypt(inBuffer, outBuffer)) return; + if (mAction == Decrypt) { + if (!mCtx->decrypt(inBuffer, outBuffer)) return; } - if( mAction == Sign ) { - if(! mCtx->sign(mKeyList->getChecked(), inBuffer, outBuffer, true)) return; + if (mAction == Sign) { + if (!mCtx->sign(mKeyList->getChecked(), inBuffer, outBuffer, true)) return; } - if( mAction == Verify ) { + if (mAction == Verify) { QFile signfile; signfile.setFileName(signFileEdit->text()); if (!signfile.open(QIODevice::ReadOnly)) { - statusLabel->setText( tr("Couldn't open file")); + statusLabel->setText(tr("Couldn't open file")); signFileEdit->setStyleSheet("QLineEdit { background: yellow }"); return; } @@ -212,12 +209,12 @@ void FileEncryptionDialog::slotExecuteAction() } QFile outfile(outputFileEdit->text()); - if (outfile.exists()){ + if (outfile.exists()) { QMessageBox::StandardButton ret; ret = QMessageBox::warning(this, tr("File"), - tr("File exists! Do you want to overwrite it?"), - QMessageBox::Ok|QMessageBox::Cancel); - if (ret == QMessageBox::Cancel){ + tr("File exists! Do you want to overwrite it?"), + QMessageBox::Ok | QMessageBox::Cancel); + if (ret == QMessageBox::Cancel) { return; } } @@ -225,25 +222,23 @@ void FileEncryptionDialog::slotExecuteAction() if (!outfile.open(QFile::WriteOnly)) { QMessageBox::warning(this, tr("File"), tr("Cannot write file %1:\n%2.") - .arg(outputFileEdit->text()) - .arg(outfile.errorString())); + .arg(outputFileEdit->text()) + .arg(outfile.errorString())); return; } QDataStream out(&outfile); out.writeRawData(outBuffer->data(), outBuffer->length()); outfile.close(); - QMessageBox::information(0, "Done", "Output saved to " + outputFileEdit->text()); + QMessageBox::information(nullptr, "Done", "Output saved to " + outputFileEdit->text()); accept(); } -void FileEncryptionDialog::slotShowKeyList() -{ +void FileEncryptionDialog::slotShowKeyList() { mKeyList->show(); } -void FileEncryptionDialog::slotHideKeyList() -{ +void FileEncryptionDialog::slotHideKeyList() { mKeyList->hide(); } |