diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-14 22:23:00 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-05-14 22:23:00 +0000 |
commit | c17f86af2dce6d1d4ad6a4e787404003c1ce495c (patch) | |
tree | dabef71f91f1ccaa9e1d9ff53cb39497bcaf204c /attachmenttablemodel.cpp | |
parent | more work on tablemodel, attached files are saveable again (diff) | |
download | gpg4usb-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
Diffstat (limited to 'attachmenttablemodel.cpp')
-rw-r--r-- | attachmenttablemodel.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
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(); } |