diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-10 21:28:13 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-10 21:28:13 +0000 |
commit | 00bebcf42b3cd9cfdba11442d34ac2e3ed7da3bd (patch) | |
tree | 1d758444bc55f273226ecbff43862a742d836274 /attachments.cpp | |
parent | updated TODO (diff) | |
download | gpg4usb-00bebcf42b3cd9cfdba11442d34ac2e3ed7da3bd.tar.gz gpg4usb-00bebcf42b3cd9cfdba11442d34ac2e3ed7da3bd.zip |
add mime-parser and basic attachment-recognise and show functionality
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@322 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'attachments.cpp')
-rw-r--r-- | attachments.cpp | 165 |
1 files changed, 41 insertions, 124 deletions
diff --git a/attachments.cpp b/attachments.cpp index 09c76be..07988ff 100644 --- a/attachments.cpp +++ b/attachments.cpp @@ -21,163 +21,80 @@ #include "attachments.h" -Attachments::Attachments(QWidget *parent) +Attachments::Attachments(QString iconpath, QWidget *parent) : QWidget(parent) { - m_attachmentList = new QListWidget(); - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(m_attachmentList); - setLayout(layout); - createActions(); -} + this->iconPath = iconpath; -void Attachments::setIconPath(QString path) -{ - this->iconPath = path; -} + mAttachmentTable = new QTableWidget(this); + mAttachmentTable->setColumnCount(2); -void Attachments::setContext(GpgME::Context *ctx) -{ - m_ctx = ctx; -} + QStringList labels; + labels << "filename" << "content-type"; + mAttachmentTable->setHorizontalHeaderLabels(labels); -void Attachments::setKeyList(KeyList *keylist) -{ - m_keyList = keylist; -} + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(mAttachmentTable); + setLayout(layout); + createActions(); +} void Attachments::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); - menu.addAction(addFileAct); - menu.addAction(encryptAct); - menu.addAction(decryptAct); + menu.addAction(saveFileAct); menu.exec(event->globalPos()); } void Attachments::createActions() { - addFileAct = new QAction(tr("Add File"), this); - addFileAct->setToolTip(tr("Add a file")); - addFileAct->setIcon(QIcon(iconPath + "fileopen.png")); - connect(addFileAct, SIGNAL(triggered()), this, SLOT(addFile())); - - encryptAct = new QAction(tr("Encrypt"), this); - encryptAct->setToolTip(tr("Encrypt marked File(s)")); - encryptAct->setIcon(QIcon(iconPath + "encrypted.png")); - connect(encryptAct, SIGNAL(triggered()), this, SLOT(encryptFile())); - - decryptAct = new QAction(tr("Decrypt"), this); - decryptAct->setToolTip(tr("Decrypt marked File(s)")); - decryptAct->setIcon(QIcon(iconPath + "decrypted.png")); - connect(decryptAct, SIGNAL(triggered()), this, SLOT(decryptFile())); + saveFileAct = new QAction(tr("Save File"), this); + saveFileAct->setToolTip(tr("Save this file")); + saveFileAct->setIcon(QIcon(iconPath + "filesave.png")); + connect(saveFileAct, SIGNAL(triggered()), this, SLOT(saveFile())); + } -void Attachments::addFile() +void Attachments::saveFile() { - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::ExistingFiles); - QStringList fileNames; - if (dialog.exec()) - fileNames = dialog.selectedFiles(); + qDebug() << "want to save file"; + + foreach (QString tmp, *getSelected()) { + qDebug() << tmp; + } - //foreach(QString tmp, fileNames) qDebug() << tmp; - m_attachmentList->addItems(fileNames); } -void Attachments::encryptFile() +QStringList *Attachments::getSelected() { - qDebug() << "enc"; - - foreach(QString inFilename, *(getSelected())) { - QByteArray *outBuffer = new QByteArray(); - QStringList *uidList = m_keyList->getChecked(); - - QFile infile; - infile.setFileName(inFilename); + QStringList *ret = new QStringList(); - if (!infile.open(QIODevice::ReadOnly)) { - qDebug() << tr("couldn't open file: ") + inFilename; - } - //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(); - 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(); + for (int i = 0; i < mAttachmentTable->rowCount(); i++) { + if (mAttachmentTable->item(i, 0)->isSelected() == 1) { + *ret << mAttachmentTable->item(i, 0)->text(); } } + return ret; + } -void Attachments::decryptFile() +void Attachments::addMimePart(MimePart *mp) { - qDebug() << "dec"; - foreach(QString inFilename, *(getSelected())) { - qDebug() << inFilename; - - QFile infile; - infile.setFileName(inFilename); - if (!infile.open(QIODevice::ReadOnly)) { - qDebug() << tr("couldn't open file: ") + inFilename; - } - - QByteArray inBuffer = infile.readAll(); - QByteArray *outBuffer = new QByteArray(); - m_ctx->decrypt(inBuffer, outBuffer); + QString icoPath = "/usr/lib/kde4/share/icons/oxygen/32x32/mimetypes/"; + QString icon = mp->getValue("Content-Type").replace("/", "-"); + icon = icoPath + icon + ".png"; - 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; - } + //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); - QDataStream out(&outfile); - //out << outBuffer; - out.writeRawData(outBuffer->data(), outBuffer->length()); - //qDebug() << "outb: " << outBuffer->toHex(); - - } + // QTableWidgetItem *tmp2 = new QTableWidgetItem(mp->getValue("Content-Type")); + // mAttachmentTable->setItem(mAttachmentTable->rowCount()-1, 1, tmp2); } -QStringList *Attachments::getSelected() -{ - QStringList *ret = new QStringList(); - for (int i = 0; i < m_attachmentList->count(); i++) { - if (m_attachmentList->item(i)->isSelected() == 1) { - *ret << m_attachmentList->item(i)->text(); - } - } - return ret; -} |