diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-05-12 15:17:19 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-05-12 15:17:19 +0000 |
commit | e68b0b05b975a0ded43b7c1ee5b4063e290f6349 (patch) | |
tree | 76ec031a77e576f981d987c0f81feb0af9b0d31e | |
parent | own pri file for kgpg (diff) | |
download | gpg4usb-e68b0b05b975a0ded43b7c1ee5b4063e290f6349.tar.gz gpg4usb-e68b0b05b975a0ded43b7c1ee5b4063e290f6349.zip |
fileencryption working again
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1035 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rwxr-xr-x | fileencryptiondialog.cpp | 94 | ||||
-rwxr-xr-x | fileencryptiondialog.h | 4 | ||||
-rw-r--r-- | kgpg/transactions/kgpgencrypt.cpp | 7 | ||||
-rw-r--r-- | kgpg/transactions/kgpgtextorfiletransaction.cpp | 1 |
4 files changed, 70 insertions, 36 deletions
diff --git a/fileencryptiondialog.cpp b/fileencryptiondialog.cpp index 10b17c3..209909d 100755 --- a/fileencryptiondialog.cpp +++ b/fileencryptiondialog.cpp @@ -19,6 +19,12 @@ * along with gpg4usb. If not, see <http://www.gnu.org/licenses/> */ +/** + TODO: + - OK button should be enabled when at least one key selected + - option for ascii-armor or pgp binary output + */ + #include "fileencryptiondialog.h" FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList keyList, DialogAction action, QWidget *parent) @@ -47,6 +53,10 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotExecuteAction())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + // disable ok button till inputfile & outputfile correctly set + okButton = buttonBox->button(QDialogButtonBox::Ok); + okButton->setEnabled(false); + QGroupBox *groupBox1 = new QGroupBox(tr("File")); /* Setup input & Outputfileselection*/ @@ -57,8 +67,8 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k fl1->setBuddy(inputFileEdit); outputFileEdit = new QLineEdit(); - QPushButton *fb2 = new QPushButton("..."); - connect(fb2, SIGNAL(clicked()), this, SLOT(slotSelectOutputFile())); + outputFileEdit->setReadOnly(true); + QLabel *fl2 = new QLabel(tr("Output")); fl2->setBuddy(outputFileEdit); @@ -70,7 +80,6 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k if(mAction != Verify) { gLayout->addWidget(fl2, 1, 0); gLayout->addWidget(outputFileEdit, 1, 1); - gLayout->addWidget(fb2, 1, 2); } else { signFileEdit = new QLineEdit(); QPushButton *sfb1 = new QPushButton("..."); @@ -121,11 +130,20 @@ 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 > 0 ) { if (mAction == Encrypt) { outputFileEdit->setText(infileName + ".asc"); + QFile outfile(outputFileEdit->text()); + if (outfile.exists()){ + statusLabel->setText( tr("File %1 already existing").arg(outputFileEdit->text())); + outputFileEdit->setStyleSheet("QLineEdit { background: red }"); + okButton->setEnabled(false); + } else { + statusLabel->setText(""); + // TODO: this should match the system style for textedits + outputFileEdit->setStyleSheet("QLineEdit { background: white }"); + okButton->setEnabled(true); + } } else if (mAction == Sign) { outputFileEdit->setText(infileName + ".sig"); } else if (mAction == Verify) { @@ -175,20 +193,31 @@ void FileEncryptionDialog::slotSelectSignFile() void FileEncryptionDialog::slotExecuteAction() { - QFile infile; + /*QFile infile; infile.setFileName(inputFileEdit->text()); if (!infile.open(QIODevice::ReadOnly)) { statusLabel->setText( tr("Couldn't open file")); inputFileEdit->setStyleSheet("QLineEdit { background: yellow }"); return; - } + }*/ + + QUrl infileURL = QUrl::fromLocalFile(inputFileEdit->text()); - QByteArray inBuffer = infile.readAll(); - QByteArray *outBuffer = new QByteArray(); - infile.close(); if ( mAction == Encrypt ) { - // TODO - // if (! mCtx->encrypt(mKeyList->getChecked(), inBuffer, outBuffer)) return; + QList<QUrl> infileURLs; + infileURLs << infileURL; + QStringList *uidList = mKeyList->getChecked(); + QStringList options; + KGpgEncrypt::EncryptOptions opts = KGpgEncrypt::DefaultEncryption; + + opts |= KGpgEncrypt::AllowUntrustedEncryption; + opts |= KGpgEncrypt::AsciiArmored; + + KGpgEncrypt *encr = new KGpgEncrypt(this, *uidList, infileURLs, opts, options); + encr->start(); + connect(encr, SIGNAL(done(int)), SLOT(slotEncryptDone(int))); + + return; } if ( mAction == Decrypt ) { // TODO @@ -214,33 +243,28 @@ void FileEncryptionDialog::slotExecuteAction() return; } - QFile outfile(outputFileEdit->text()); - 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){ - return; - } - } - - if (!outfile.open(QFile::WriteOnly)) { - QMessageBox::warning(this, tr("File"), - tr("Cannot write file %1:\n%2.") - .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()); accept(); } +void FileEncryptionDialog::slotEncryptDone(int result) { + + KGpgEncrypt *enc = qobject_cast<KGpgEncrypt *>(sender()); + Q_ASSERT(enc != NULL); + sender()->deleteLater(); + + if (result == KGpgTransaction::TS_OK) { + qDebug() << "FileEncryption succesfull, code: " << result; + QMessageBox::information(0, tr("Filencryption succesfull"), tr("Output saved to %1").arg(outputFileEdit->text())); + accept(); + } else { + QMessageBox::critical(0, tr("Filencryption failed"), tr("The encryption failed.")); + qDebug() << "The fileencryption failed with error code " << result; + } + +} + void FileEncryptionDialog::slotShowKeyList() { mKeyList->show(); diff --git a/fileencryptiondialog.h b/fileencryptiondialog.h index 6a3e302..76f3caf 100755 --- a/fileencryptiondialog.h +++ b/fileencryptiondialog.h @@ -25,6 +25,7 @@ #include "gpgcontext.h" #include "keylist.h" #include "verifydetailsdialog.h" +#include "kgpg/transactions/kgpgencrypt.h" QT_BEGIN_NAMESPACE class QDialog; @@ -96,6 +97,8 @@ public slots: */ void slotExecuteAction(); + void slotEncryptDone(int result); + /** * @brief * @@ -116,6 +119,7 @@ private: QLineEdit *signFileEdit; /**< TODO */ DialogAction mAction; /**< TODO */ QLabel *statusLabel; /**< TODO */ + QPushButton *okButton; protected: GpgME::GpgContext *mCtx; /**< TODO */ diff --git a/kgpg/transactions/kgpgencrypt.cpp b/kgpg/transactions/kgpgencrypt.cpp index 4891bf0..4324a43 100644 --- a/kgpg/transactions/kgpgencrypt.cpp +++ b/kgpg/transactions/kgpgencrypt.cpp @@ -20,6 +20,7 @@ //#include <kio/renamedialog.h> //#include <KLocale> #include <QPointer> +#include <QDebug> static QStringList trustOptions(const QString &binary) { @@ -100,6 +101,7 @@ KGpgEncrypt::encryptedText() const bool KGpgEncrypt::nextLine(const QString &line) { + qDebug() << "KGpgEncrypt::nextLine called"; const QList<QUrl> &inputFiles = getInputFiles(); if (line.startsWith(QLatin1String("[GNUPG:] MISSING_PASSPHRASE"))) { @@ -120,6 +122,9 @@ KGpgEncrypt::nextLine(const QString &line) emit statusMessage(tr("Status message 'Encrypted <filename>' (operation was completed)", "Encrypted %1").arg(m_currentFile)); m_fileIndex++; emit infoProgress(2 * m_fileIndex, inputFiles.count() * 2); + } else if (line == askName) { + qDebug() << "KGpgEncrypt::nextLine - name asked for file..."; + } // TODO /* } else if (line == askName) { QPointer<KIO::RenameDialog> over = new KIO::RenameDialog(qobject_cast<QWidget *>(parent()), @@ -134,7 +139,7 @@ KGpgEncrypt::nextLine(const QString &line) } write(over->newDestUrl().path().toUtf8()); delete over;*/ - } + //} } return KGpgTextOrFileTransaction::nextLine(line); diff --git a/kgpg/transactions/kgpgtextorfiletransaction.cpp b/kgpg/transactions/kgpgtextorfiletransaction.cpp index 036d911..df46b69 100644 --- a/kgpg/transactions/kgpgtextorfiletransaction.cpp +++ b/kgpg/transactions/kgpgtextorfiletransaction.cpp @@ -61,6 +61,7 @@ KGpgTextOrFileTransaction::preStart() foreach (const QUrl &url, m_inpfiles) { // qt 4.8 ! todo mac + qDebug() << "fileurl: "<< url; qDebug() << "what the loc:" << url.isLocalFile(); if (url.isLocalFile()) { |