diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2008-08-16 15:32:56 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2008-08-16 15:32:56 +0000 |
commit | ee4c739b64f2c71a39d301a21a86e7790289919f (patch) | |
tree | a30748bbbe155a58c3ed52529ef794c694375016 /attachments.cpp | |
parent | start of binary-file handling (decrypt/encrypt), kind of works, but still a l... (diff) | |
download | gpg4usb-ee4c739b64f2c71a39d301a21a86e7790289919f.tar.gz gpg4usb-ee4c739b64f2c71a39d301a21a86e7790289919f.zip |
added / fixed file-output for attachment-enc/decryption
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@146 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'attachments.cpp')
-rw-r--r-- | attachments.cpp | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/attachments.cpp b/attachments.cpp index 6224171..60d28b3 100644 --- a/attachments.cpp +++ b/attachments.cpp @@ -97,24 +97,41 @@ void Attachments::encryptFile() { qDebug() << "enc"; - foreach(QString filename, *(getSelected())) { + foreach(QString inFilename, *(getSelected())) { QByteArray *outBuffer = new QByteArray(); QList<QString> *uidList = m_keyList->getChecked(); - QFile file; - file.setFileName(filename); + QFile infile; + infile.setFileName(inFilename); - if (!file.open(QIODevice::ReadOnly)) { - qDebug() << tr("couldn't open file: ") + filename; + if (!infile.open(QIODevice::ReadOnly)) { + qDebug() << tr("couldn't open file: ") + inFilename; } - qDebug() << "filesize: " << file.size(); - QByteArray inBuffer = file.readAll(); - qDebug() << "buffsize: " << inBuffer.size(); + //qDebug() << "filesize: " << file.size(); + QByteArray inBuffer = infile.readAll(); + //qDebug() << "buffsize: " << inBuffer.size(); if (m_ctx->encrypt(uidList, inBuffer, outBuffer)) { //qDebug() << "inb: " << inBuffer.toHex(); - qDebug() << "outb: " << outBuffer->data(); + //qDebug() << "outb: " << outBuffer->data(); + QString outFilename = QFileDialog::getSaveFileName(this); + if (outFilename.isEmpty()) { + qDebug() << "need Filename"; + return; + } + + QFile outfile(outFilename); + if (!outfile.open(QFile::WriteOnly)) { + QMessageBox::warning(this, tr("File"), + tr("Cannot write file %1:\n%2.") + .arg(outFilename) + .arg(outfile.errorString())); + return; + } + + QTextStream out(&outfile); + out << outBuffer->data(); } } } @@ -151,8 +168,8 @@ void Attachments::decryptFile() } QDataStream out(&outfile); - out << outBuffer; - + //out << outBuffer; + out.writeRawData(outBuffer->data(), outBuffer->length()); //qDebug() << "outb: " << outBuffer->toHex(); } |