aboutsummaryrefslogtreecommitdiffstats
path: root/keytablemodel.cpp
blob: d51b865b1ec86b77253feeb1dc3980bdfb839daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "keytablemodel.h"

KeyTableModel::KeyTableModel(GpgME::Context *ctx, QString iconpath, QObject *parent) :
                             QAbstractTableModel(parent)
{
    mCtx = ctx;
    iconPath = iconpath;
    keys = mCtx->listKeys();
}

int KeyTableModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return keys.size();
}

int KeyTableModel::columnCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return 4;
}

QVariant KeyTableModel::data(const QModelIndex &index, int role) const
{

    //qDebug() << "called, index: " << index.column();

    if (!index.isValid())
        return QVariant();

    if (index.row() >= keys.size() || index.row() < 0)
        return QVariant();

    if (role == Qt::DisplayRole) {
        GpgKey key = keys.at(index.row());

        if (index.column() == 0)
            return "";
        if (index.column() == 1)
            return "";
        if (index.column() == 2)
            return key.name;
        if (index.column() == 3)
            return key.email;


    }

    // set icon
    if (role == Qt::DecorationRole && index.column() == 1) {
        //return QIcon(icon);
        GpgKey key = keys.at(index.row());
        if(key.privkey) return QIcon(iconPath + "kgpg_key2.png");
    }

    return QVariant();
}

QVariant KeyTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{

    if (role != Qt::DisplayRole)
        return QVariant();

    if (orientation == Qt::Horizontal) {
        switch (section) {

        case 0:
            return tr("");

        case 1:
            return tr("");

        case 2:
            return tr("Name");

        case 3:
            return tr("EMail");

        default:
            return QVariant();
        }
    }
    return QVariant();
}