aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 20:28:01 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 20:28:01 +0000
commit7daaccd9a16f1a39e7b0b4df94876de113a3523b (patch)
treec63943ab3a9b5429051257b28c75c875e5f5bd1e
parentstart of using own model for attachment-table-view, not all functionality (sa... (diff)
downloadgpg4usb-7daaccd9a16f1a39e7b0b4df94876de113a3523b.tar.gz
gpg4usb-7daaccd9a16f1a39e7b0b4df94876de113a3523b.zip
more work on tablemodel, attached files are saveable again
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@329 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--attachments.cpp72
-rw-r--r--attachments.h8
-rw-r--r--attachmenttablemodel.cpp16
-rw-r--r--attachmenttablemodel.h3
-rw-r--r--gpgwin.cpp6
5 files changed, 38 insertions, 67 deletions
diff --git a/attachments.cpp b/attachments.cpp
index cb62cbd..a4b2886 100644
--- a/attachments.cpp
+++ b/attachments.cpp
@@ -22,14 +22,11 @@
/* TODO:
* - check content encoding (base64 / quoted-printable) and apply appropriate opperation (maybe already in mime.cpp)
* - check memory usage, use less copy operations / more references
- * - try table-model-view for mimeparts
* - possibility to clear attachment-view , e.g. with decryption or encrypting a new message
* - clean header-file (remove dep. on keylist.h)
+ * - save all: like in thunderbird, one folder, all files go there
*/
-/* implement model for mime, based on qabstracttablemodel
- *
- */
#include "attachments.h"
@@ -44,6 +41,8 @@ Attachments::Attachments(QString iconpath, QWidget *parent)
tableView = new QTableView;
tableView->setModel(table);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ // only one entry should be selected at time
+ tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableView->setFocusPolicy(Qt::NoFocus);
tableView->setAlternatingRowColors(true);
@@ -79,19 +78,24 @@ void Attachments::createActions()
void Attachments::saveFile()
{
- qDebug() << "want to save file";
+ QModelIndexList indexes = tableView->selectionModel()->selection().indexes();
- foreach (int tmp, getSelectedPos()) {
- qDebug() << "int is: " << tmp;
- saveByteArrayToFile(attachmentBodys->at(tmp));
- }
+ // only singe-selection possible now: TODO: foreach
+ MimePart mp = table->getMimePart(indexes.at(0).row());
+ QString filename = mp.getParam("Content-Type", "name");
+ // TODO: find out why filename is quoted
+ filename.chop(1);
+ filename.remove(0,1);
+ // TODO: check if really base64
+ saveByteArrayToFile(QByteArray::fromBase64(mp.body), filename);
}
-void Attachments::saveByteArrayToFile(QByteArray outBuffer)
+void Attachments::saveByteArrayToFile(QByteArray outBuffer, QString filename)
{
- QString path="";
+ //QString path="";
+ QString path=filename;
QString outfileName = QFileDialog::getSaveFileName(this, tr("Save File"), path);
QFile outfile(outfileName);
@@ -107,56 +111,10 @@ void Attachments::saveByteArrayToFile(QByteArray outBuffer)
out.writeRawData(outBuffer.data(), outBuffer.length());
}
-QStringList *Attachments::getSelected()
-{
-
- QStringList *ret = new QStringList();
-
- // TODO
-
- /*for (int i = 0; i < mAttachmentTable->rowCount(); i++) {
- if (mAttachmentTable->item(i, 0)->isSelected() == 1) {
- *ret << mAttachmentTable->item(i, 0)->text();
- }
- }*/
- return ret;
-
-}
-
-QList<int> Attachments::getSelectedPos () {
- QList<int> ret;
-
- // TODO
-
- /*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 icon = mp->getValue("Content-Type").replace("/", "-");
- //icon = iconPath + "/mimetypes/" + icon + ".png";
-
table->add(*mp);
- //tableView->update();
- /*
- 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);
-
- //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 8283fb9..189b3cc 100644
--- a/attachments.h
+++ b/attachments.h
@@ -54,15 +54,9 @@ public:
private:
void createActions();
- void saveByteArrayToFile(QByteArray outBuffer);
- QStringList *getSelected();
- QList<int> getSelectedPos();
- QTableWidget *mAttachmentTable;
- //QList<QPointer<QByteArray>>
- QList<QByteArray> *attachmentBodys;
+ void saveByteArrayToFile(QByteArray outBuffer, QString filename);
QAction *saveFileAct;
QString iconPath;
-
AttachmentTableModel *table;
QTableView *tableView;
diff --git a/attachmenttablemodel.cpp b/attachmenttablemodel.cpp
index 6ca640b..ef30f84 100644
--- a/attachmenttablemodel.cpp
+++ b/attachmenttablemodel.cpp
@@ -24,6 +24,22 @@ void AttachmentTableModel::add(MimePart mp) {
reset();
}
+MimePart AttachmentTableModel::getSelectedMimePart(QModelIndex index){
+ return listOfMimeparts.at(index.row());
+}
+
+MimePart AttachmentTableModel::getMimePart(int index){
+ return listOfMimeparts.at(index);
+}
+
+/*QList<MimePart> AttachmentTableModel::getSelectedMimeParts(QModelIndexList indexes){
+
+ foreach(QModelIndex index, indexes) {
+ qDebug() << "ir: "<< index.row();
+ }
+
+}*/
+
int AttachmentTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
diff --git a/attachmenttablemodel.h b/attachmenttablemodel.h
index 0200656..0f93ac2 100644
--- a/attachmenttablemodel.h
+++ b/attachmenttablemodel.h
@@ -20,6 +20,9 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
void add(MimePart mp);
+ MimePart getSelectedMimePart(QModelIndex index);
+ MimePart getMimePart(int index);
+ //QList<MimePart> getSelectedMimeParts(QModelIndexList indexes);
private:
QList<MimePart> listOfMimeparts;
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 2fd7b32..1742b4a 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -523,10 +523,10 @@ void GpgWin::parseMime(QByteArray *message) {
Mime *mime = new Mime(message);
foreach(MimePart tmp, mime->parts()) {
- if(tmp.getValue("Content-Type")=="text/plain") {
+ if(tmp.getValue("Content-Type")=="text/plain"
+ && tmp.getValue("Content-Transfer-Encoding") != "base64") {
pText.append(QString(tmp.body));
- }
- else {
+ } else {
(mAttachments->addMimePart(&tmp));
showmadock=true;
}