From c17f86af2dce6d1d4ad6a4e787404003c1ce495c Mon Sep 17 00:00:00 2001 From: ubbo Date: Fri, 14 May 2010 22:23:00 +0000 Subject: add mimetype-icons to model git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@330 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- attachments.cpp | 2 +- attachmenttablemodel.cpp | 26 +++++++++++++++++++++++++- attachmenttablemodel.h | 5 +++++ release/icons/mimetypes/image-x-generic.png | Bin 0 -> 1562 bytes release/icons/mimetypes/text-plain.png | Bin 0 -> 1138 bytes release/icons/mimetypes/unknown.png | Bin 0 -> 1091 bytes 6 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 release/icons/mimetypes/image-x-generic.png create mode 100644 release/icons/mimetypes/text-plain.png create mode 100644 release/icons/mimetypes/unknown.png 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 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 +#include +#include +#include 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 mimeparts, QObject *parent = 0); int rowCount(const QModelIndex &parent) const; @@ -26,6 +30,7 @@ public: private: QList 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 Binary files /dev/null and b/release/icons/mimetypes/image-x-generic.png differ diff --git a/release/icons/mimetypes/text-plain.png b/release/icons/mimetypes/text-plain.png new file mode 100644 index 0000000..adc2883 Binary files /dev/null and b/release/icons/mimetypes/text-plain.png differ diff --git a/release/icons/mimetypes/unknown.png b/release/icons/mimetypes/unknown.png new file mode 100644 index 0000000..6a84b79 Binary files /dev/null and b/release/icons/mimetypes/unknown.png differ -- cgit v1.2.3