aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--attachments.cpp54
-rw-r--r--attachments.h12
-rw-r--r--attachmenttablemodel.cpp80
-rw-r--r--attachmenttablemodel.h29
-rw-r--r--gpg4usb.pro59
5 files changed, 192 insertions, 42 deletions
diff --git a/attachments.cpp b/attachments.cpp
index 4223043..cb62cbd 100644
--- a/attachments.cpp
+++ b/attachments.cpp
@@ -24,6 +24,11 @@
* - 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)
+ */
+
+/* implement model for mime, based on qabstracttablemodel
+ *
*/
#include "attachments.h"
@@ -34,25 +39,22 @@ Attachments::Attachments(QString iconpath, QWidget *parent)
this->iconPath = iconpath;
- mAttachmentTable = new QTableWidget(this);
- mAttachmentTable->setColumnCount(2);
- mAttachmentTable->setSelectionBehavior(QAbstractItemView::SelectRows);
- mAttachmentTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
- mAttachmentTable->setFocusPolicy(Qt::NoFocus);
- mAttachmentTable->setAlternatingRowColors(true);
- mAttachmentTable->verticalHeader()->hide();
- mAttachmentTable->setShowGrid(false);
- mAttachmentTable->setColumnWidth(0, 300);
-
- attachmentBodys = new QList<QByteArray>();
+ table = new AttachmentTableModel(this);
- QStringList labels;
- labels << "filename" << "content-type";
- mAttachmentTable->setHorizontalHeaderLabels(labels);
- mAttachmentTable->horizontalHeader()->setStretchLastSection(true);
+ tableView = new QTableView;
+ tableView->setModel(table);
+ tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ tableView->setFocusPolicy(Qt::NoFocus);
+ tableView->setAlternatingRowColors(true);
+ tableView->verticalHeader()->hide();
+ tableView->setShowGrid(false);
+ tableView->setColumnWidth(0, 300);
+ tableView->horizontalHeader()->setStretchLastSection(true);
QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(mAttachmentTable);
+ //layout->addWidget(mAttachmentTable);
+ layout->addWidget(tableView);
setLayout(layout);
createActions();
@@ -110,11 +112,13 @@ QStringList *Attachments::getSelected()
QStringList *ret = new QStringList();
- for (int i = 0; i < mAttachmentTable->rowCount(); i++) {
+ // TODO
+
+ /*for (int i = 0; i < mAttachmentTable->rowCount(); i++) {
if (mAttachmentTable->item(i, 0)->isSelected() == 1) {
*ret << mAttachmentTable->item(i, 0)->text();
}
- }
+ }*/
return ret;
}
@@ -123,11 +127,13 @@ QList<int> Attachments::getSelectedPos () {
QList<int> ret;
- for (int i = 0; i < mAttachmentTable->rowCount(); i++) {
+ // TODO
+
+ /*for (int i = 0; i < mAttachmentTable->rowCount(); i++) {
if (mAttachmentTable->item(i, 0)->isSelected() == 1) {
ret << i;
}
- }
+ }*/
return ret;
}
@@ -135,9 +141,12 @@ QList<int> Attachments::getSelectedPos () {
void Attachments::addMimePart(MimePart *mp)
{
- QString icon = mp->getValue("Content-Type").replace("/", "-");
- icon = iconPath + "/mimetypes/" + icon + ".png";
+ //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);
@@ -147,6 +156,7 @@ void Attachments::addMimePart(MimePart *mp)
//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 80cb04c..8283fb9 100644
--- a/attachments.h
+++ b/attachments.h
@@ -22,21 +22,24 @@
#ifndef __ATTACHMENTS_H__
#define __ATTACHMENTS_H__
-#include "context.h"
#include "keylist.h"
#include "mime.h"
+#include "attachmenttablemodel.h"
+class QWidget;
class QVBoxLayout;
class QDebug;
class QFileDialog;
-class QMessageBox;
-class iostream;
class QListWidget;
class QWidget;
class QAction;
class QMenu;
class QContextMenuEvent;
class QMenu;
+class QTableWidget;
+class QTableWidgetItem;
+class QtGui;
+
class Attachments : public QWidget
{
@@ -60,6 +63,9 @@ private:
QAction *saveFileAct;
QString iconPath;
+ AttachmentTableModel *table;
+ QTableView *tableView;
+
protected:
void contextMenuEvent(QContextMenuEvent *event);
diff --git a/attachmenttablemodel.cpp b/attachmenttablemodel.cpp
new file mode 100644
index 0000000..6ca640b
--- /dev/null
+++ b/attachmenttablemodel.cpp
@@ -0,0 +1,80 @@
+#include "attachmenttablemodel.h"
+
+/** compare with http://doc.qt.nokia.com/4.6/itemviews-addressbook.html
+ */
+
+AttachmentTableModel::AttachmentTableModel(QObject *parent) :
+ QAbstractTableModel(parent)
+{
+}
+
+AttachmentTableModel::AttachmentTableModel(QList<MimePart> mimeparts, QObject *parent) :
+ QAbstractTableModel(parent)
+{
+ listOfMimeparts = mimeparts;
+}
+
+void AttachmentTableModel::add(MimePart mp) {
+ listOfMimeparts.append(mp);
+ //QModelIndex changedIndex0 = createIndex(listOfMimeparts.size(), 0);
+ //QModelIndex changedIndex1 = createIndex(listOfMimeparts.size(), 1);
+
+ //emit(dataChanged(changedIndex0, changedIndex1));
+ // TODO: check the data-changed function
+ reset();
+}
+
+int AttachmentTableModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return listOfMimeparts.size();
+}
+
+int AttachmentTableModel::columnCount(const QModelIndex &parent) const
+ {
+ Q_UNUSED(parent);
+ return 2;
+ }
+
+QVariant AttachmentTableModel::data(const QModelIndex &index, int role) const
+{
+
+ //qDebug() << "called, index: " << index.column();
+
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= listOfMimeparts.size() || index.row() < 0)
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ MimePart mp = listOfMimeparts.at(index.row());
+
+ if (index.column() == 0)
+ return mp.getParam("Content-Type", "name");
+ if (index.column() == 1)
+ return mp.getValue("Content-Type");
+ }
+ return QVariant();
+}
+
+QVariant AttachmentTableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ //qDebug() << "called, section: " << section;
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Horizontal) {
+ switch (section) {
+ case 0:
+ return tr("Filename");
+
+ case 1:
+ return tr("Contenttype");
+
+ default:
+ return QVariant();
+ }
+ }
+ return QVariant();
+}
diff --git a/attachmenttablemodel.h b/attachmenttablemodel.h
new file mode 100644
index 0000000..0200656
--- /dev/null
+++ b/attachmenttablemodel.h
@@ -0,0 +1,29 @@
+#ifndef ATTACHMENTTABLEMODEL_H
+#define ATTACHMENTTABLEMODEL_H
+
+#include "mime.h"
+
+#include <QAbstractTableModel>
+
+
+class AttachmentTableModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ AttachmentTableModel(QObject *parent = 0);
+ AttachmentTableModel(QList<MimePart> mimeparts, QObject *parent = 0);
+
+ int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+ void add(MimePart mp);
+
+private:
+ QList<MimePart> listOfMimeparts;
+
+};
+
+#endif // ATTACHMENTTABLEMODEL_H
diff --git a/gpg4usb.pro b/gpg4usb.pro
index 06441c7..8265221 100644
--- a/gpg4usb.pro
+++ b/gpg4usb.pro
@@ -1,27 +1,52 @@
-######################################################################
+# #####################################################################
# Automatically generated by qmake (2.01a) Mi Mai 21 02:28:39 2008
-######################################################################
-
+# #####################################################################
TEMPLATE = app
-#unix:TARGET = start_linux
-#win32:TARGET = start_windows
-#mac:TARGET = start_mac
+
+# unix:TARGET = start_linux
+# win32:TARGET = start_windows
+# mac:TARGET = start_mac
DESTDIR = release
DEPENDPATH += .
-INCLUDEPATH += . ./include
-CONFIG += release static
+INCLUDEPATH += . \
+ ./include
+
+# CONFIG += release static
+CONFIG += debug
# Input
-HEADERS += attachments.h context.h gpgwin.h keylist.h keymgmt.h fileencryptiondialog.h mime.h keygenthread.h keydetailsdialog.h settingsdialog.h
-SOURCES += attachments.cpp context.cpp gpgwin.cpp main.cpp keylist.cpp keymgmt.cpp fileencryptiondialog.cpp mime.cpp keygenthread.cpp keydetailsdialog.cpp settingsdialog.cpp
+HEADERS += attachments.h \
+ context.h \
+ gpgwin.h \
+ keylist.h \
+ keymgmt.h \
+ fileencryptiondialog.h \
+ mime.h \
+ keygenthread.h \
+ keydetailsdialog.h \
+ settingsdialog.h \
+ attachmenttablemodel.h
+SOURCES += attachments.cpp \
+ context.cpp \
+ gpgwin.cpp \
+ main.cpp \
+ keylist.cpp \
+ keymgmt.cpp \
+ fileencryptiondialog.cpp \
+ mime.cpp \
+ keygenthread.cpp \
+ keydetailsdialog.cpp \
+ settingsdialog.cpp \
+ attachmenttablemodel.cpp
RC_FILE = gpg4usb.rc
+
# comment out line below for static building
-LIBS += -lgpgme -lgpg-error
+LIBS += -lgpgme \
+ -lgpg-error
DEFINES += _FILE_OFFSET_BITS=64
-
TRANSLATIONS = release/ts/gpg4usb_en.ts \
- release/ts/gpg4usb_de.ts \
- release/ts/gpg4usb_ru.ts \
- release/ts/gpg4usb_fr.ts \
- release/ts/gpg4usb_pt_BR.ts \
- release/ts/gpg4usb_es.ts \
+ release/ts/gpg4usb_de.ts \
+ release/ts/gpg4usb_ru.ts \
+ release/ts/gpg4usb_fr.ts \
+ release/ts/gpg4usb_pt_BR.ts \
+ release/ts/gpg4usb_es.ts