aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 22:23:00 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 22:23:00 +0000
commitc17f86af2dce6d1d4ad6a4e787404003c1ce495c (patch)
treedabef71f91f1ccaa9e1d9ff53cb39497bcaf204c
parentmore work on tablemodel, attached files are saveable again (diff)
downloadgpg4usb-c17f86af2dce6d1d4ad6a4e787404003c1ce495c.tar.gz
gpg4usb-c17f86af2dce6d1d4ad6a4e787404003c1ce495c.zip
add mimetype-icons to model
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@330 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--attachments.cpp2
-rw-r--r--attachmenttablemodel.cpp26
-rw-r--r--attachmenttablemodel.h5
-rw-r--r--release/icons/mimetypes/image-x-generic.pngbin0 -> 1562 bytes
-rw-r--r--release/icons/mimetypes/text-plain.pngbin0 -> 1138 bytes
-rw-r--r--release/icons/mimetypes/unknown.pngbin0 -> 1091 bytes
6 files changed, 31 insertions, 2 deletions
diff --git a/attachments.cpp b/attachments.cpp
index a4b2886..4e62bd9 100644
--- a/attachments.cpp
+++ b/attachments.cpp
@@ -36,7 +36,7 @@ Attachments::Attachments(QString iconpath, QWidget *parent)
this->iconPath = iconpath;
- table = new AttachmentTableModel(this);
+ table = new AttachmentTableModel(iconpath, this);
tableView = new QTableView;
tableView->setModel(table);
diff --git a/attachmenttablemodel.cpp b/attachmenttablemodel.cpp
index ef30f84..8aac394 100644
--- a/attachmenttablemodel.cpp
+++ b/attachmenttablemodel.cpp
@@ -14,13 +14,20 @@ AttachmentTableModel::AttachmentTableModel(QList<MimePart> mimeparts, QObject *p
listOfMimeparts = mimeparts;
}
+AttachmentTableModel::AttachmentTableModel(QString iconpath, QObject *parent) :
+ QAbstractTableModel(parent)
+{
+ iconPath = iconpath;
+}
+
+
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
+ // TODO: check the data-changed signal
reset();
}
@@ -70,7 +77,24 @@ QVariant AttachmentTableModel::data(const QModelIndex &index, int role) const
return mp.getParam("Content-Type", "name");
if (index.column() == 1)
return mp.getValue("Content-Type");
+
}
+
+ // set icon
+ // TODO more generic matching, e.g. for audio
+ if (role == Qt::DecorationRole && index.column() == 0) {
+ MimePart mp = listOfMimeparts.at(index.row());
+ QString icon;
+ if(mp.getValue("Content-Type").startsWith("image")) {
+ icon = iconPath + "/mimetypes/image-x-generic.png";
+ } else {
+ icon = mp.getValue("Content-Type").replace("/", "-");
+ icon = iconPath + "/mimetypes/" + icon + ".png";
+ }
+ if(!QFile::exists(icon)) icon = iconPath + "/mimetypes/unknown.png";
+ return QIcon(icon);
+ }
+
return QVariant();
}
diff --git a/attachmenttablemodel.h b/attachmenttablemodel.h
index 0f93ac2..cac8d7f 100644
--- a/attachmenttablemodel.h
+++ b/attachmenttablemodel.h
@@ -4,6 +4,9 @@
#include "mime.h"
#include <QAbstractTableModel>
+#include <QStandardItem>
+#include <QIcon>
+#include <QFile>
class AttachmentTableModel : public QAbstractTableModel
@@ -12,6 +15,7 @@ class AttachmentTableModel : public QAbstractTableModel
public:
AttachmentTableModel(QObject *parent = 0);
+ AttachmentTableModel(QString iconpath, QObject *parent = 0);
AttachmentTableModel(QList<MimePart> mimeparts, QObject *parent = 0);
int rowCount(const QModelIndex &parent) const;
@@ -26,6 +30,7 @@ public:
private:
QList<MimePart> listOfMimeparts;
+ QString iconPath;
};
diff --git a/release/icons/mimetypes/image-x-generic.png b/release/icons/mimetypes/image-x-generic.png
new file mode 100644
index 0000000..b0c9a3c
--- /dev/null
+++ b/release/icons/mimetypes/image-x-generic.png
Binary files differ
diff --git a/release/icons/mimetypes/text-plain.png b/release/icons/mimetypes/text-plain.png
new file mode 100644
index 0000000..adc2883
--- /dev/null
+++ b/release/icons/mimetypes/text-plain.png
Binary files differ
diff --git a/release/icons/mimetypes/unknown.png b/release/icons/mimetypes/unknown.png
new file mode 100644
index 0000000..6a84b79
--- /dev/null
+++ b/release/icons/mimetypes/unknown.png
Binary files differ