diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-11 19:43:48 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-11 19:43:48 +0000 |
commit | 6f173ff4d90e6add56fc55b1ec077f14c622119b (patch) | |
tree | b19460e8ea07d612b24f463525db8eec5c56bf74 | |
parent | add mime-parser and basic attachment-recognise and show functionality (diff) | |
download | gpg4usb-6f173ff4d90e6add56fc55b1ec077f14c622119b.tar.gz gpg4usb-6f173ff4d90e6add56fc55b1ec077f14c622119b.zip |
save attachment works now for testfile
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@323 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | attachments.cpp | 59 | ||||
-rw-r--r-- | attachments.h | 4 |
2 files changed, 52 insertions, 11 deletions
diff --git a/attachments.cpp b/attachments.cpp index 07988ff..0b12525 100644 --- a/attachments.cpp +++ b/attachments.cpp @@ -30,6 +30,8 @@ Attachments::Attachments(QString iconpath, QWidget *parent) mAttachmentTable = new QTableWidget(this); mAttachmentTable->setColumnCount(2); + attachmentBodys = new QList<QByteArray>(); + QStringList labels; labels << "filename" << "content-type"; mAttachmentTable->setHorizontalHeaderLabels(labels); @@ -62,10 +64,30 @@ void Attachments::saveFile() qDebug() << "want to save file"; - foreach (QString tmp, *getSelected()) { - qDebug() << tmp; + foreach (int tmp, getSelectedPos()) { + qDebug() << "int is: " << tmp; + saveByteArrayToFile(attachmentBodys->at(tmp)); + } + +} + +void Attachments::saveByteArrayToFile(QByteArray outBuffer) +{ + + QString path=""; + QString outfileName = QFileDialog::getSaveFileName(this, tr("Save File"), path); + + 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; } + QDataStream out(&outfile); + out.writeRawData(outBuffer.data(), outBuffer.length()); } QStringList *Attachments::getSelected() @@ -82,19 +104,34 @@ QStringList *Attachments::getSelected() } +QList<int> Attachments::getSelectedPos () { + + QList<int> ret; + + for (int i = 0; i < mAttachmentTable->rowCount(); i++) { + if (mAttachmentTable->item(i, 0)->isSelected() == 1) { + ret << i; + } + } + return ret; + +} + void Attachments::addMimePart(MimePart *mp) { - QString icoPath = "/usr/lib/kde4/share/icons/oxygen/32x32/mimetypes/"; - QString icon = mp->getValue("Content-Type").replace("/", "-"); - icon = icoPath + icon + ".png"; - //QIcon *icon = new QIcon("/usr/lib/kde4/share/icons/oxygen/32x32/mimetypes/" + ) - mAttachmentTable->setRowCount(mAttachmentTable->rowCount()+1); - QTableWidgetItem *tmp = new QTableWidgetItem(QIcon(icon) , mp->getParam("Content-Type", "name")); - mAttachmentTable->setItem(mAttachmentTable->rowCount()-1, 0, tmp); + QString icon = mp->getValue("Content-Type").replace("/", "-"); + icon = iconPath + "/mimetypes/" + icon + ".png"; + + mAttachmentTable->setRowCount(mAttachmentTable->rowCount()+1); + QTableWidgetItem *tmp = new QTableWidgetItem(QIcon(icon) , mp->getParam("Content-Type", "name")); + mAttachmentTable->setItem(mAttachmentTable->rowCount()-1, 0, tmp); + + QTableWidgetItem *tmp2 = new QTableWidgetItem(mp->getValue("Content-Type")); + mAttachmentTable->setItem(mAttachmentTable->rowCount()-1, 1, tmp2); - // QTableWidgetItem *tmp2 = new QTableWidgetItem(mp->getValue("Content-Type")); - // mAttachmentTable->setItem(mAttachmentTable->rowCount()-1, 1, tmp2); + //TODO: check, if content-encoding is base64 (get from header) + attachmentBodys->append(QByteArray::fromBase64(mp->body)); } diff --git a/attachments.h b/attachments.h index 4c143bb..80cb04c 100644 --- a/attachments.h +++ b/attachments.h @@ -51,8 +51,12 @@ public: private: void createActions(); + void saveByteArrayToFile(QByteArray outBuffer); QStringList *getSelected(); + QList<int> getSelectedPos(); QTableWidget *mAttachmentTable; + //QList<QPointer<QByteArray>> + QList<QByteArray> *attachmentBodys; QAction *saveFileAct; QString iconPath; |