keepassxc

Форк
0
/
AutoTypeAssociationsModel.cpp 
148 строк · 4.1 Кб
1
/*
2
 *  Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "AutoTypeAssociationsModel.h"
19

20
#include "core/Entry.h"
21

22
AutoTypeAssociationsModel::AutoTypeAssociationsModel(QObject* parent)
23
    : QAbstractListModel(parent)
24
    , m_autoTypeAssociations(nullptr)
25
    , m_entry(nullptr)
26
{
27
}
28

29
void AutoTypeAssociationsModel::setAutoTypeAssociations(AutoTypeAssociations* autoTypeAssociations)
30
{
31
    beginResetModel();
32

33
    if (m_autoTypeAssociations) {
34
        m_autoTypeAssociations->disconnect(this);
35
    }
36

37
    m_autoTypeAssociations = autoTypeAssociations;
38

39
    if (m_autoTypeAssociations) {
40
        connect(m_autoTypeAssociations, SIGNAL(dataChanged(int)), SLOT(associationChange(int)));
41
        connect(m_autoTypeAssociations, SIGNAL(aboutToAdd(int)), SLOT(associationAboutToAdd(int)));
42
        connect(m_autoTypeAssociations, SIGNAL(added(int)), SLOT(associationAdd()));
43
        connect(m_autoTypeAssociations, SIGNAL(aboutToRemove(int)), SLOT(associationAboutToRemove(int)));
44
        connect(m_autoTypeAssociations, SIGNAL(removed(int)), SLOT(associationRemove()));
45
        connect(m_autoTypeAssociations, SIGNAL(aboutToReset()), SLOT(aboutToReset()));
46
        connect(m_autoTypeAssociations, SIGNAL(reset()), SLOT(reset()));
47
    }
48

49
    endResetModel();
50
}
51

52
void AutoTypeAssociationsModel::setEntry(Entry* entry)
53
{
54
    m_entry = entry;
55
}
56

57
int AutoTypeAssociationsModel::rowCount(const QModelIndex& parent) const
58
{
59
    if (!m_autoTypeAssociations || parent.isValid()) {
60
        return 0;
61
    } else {
62
        return m_autoTypeAssociations->size();
63
    }
64
}
65

66
int AutoTypeAssociationsModel::columnCount(const QModelIndex& parent) const
67
{
68
    Q_UNUSED(parent);
69

70
    return 2;
71
}
72

73
QVariant AutoTypeAssociationsModel::headerData(int section, Qt::Orientation orientation, int role) const
74
{
75
    if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) {
76
        if (section == 0) {
77
            return tr("Window");
78
        } else {
79
            return tr("Sequence");
80
        }
81
    } else {
82
        return {};
83
    }
84
}
85

86
QVariant AutoTypeAssociationsModel::data(const QModelIndex& index, int role) const
87
{
88
    if (!index.isValid()) {
89
        return {};
90
    }
91

92
    if (role == Qt::DisplayRole) {
93
        if (index.column() == 0) {
94
            QString window = m_autoTypeAssociations->get(index.row()).window;
95
            if (window.isEmpty()) {
96
                return tr("(empty)");
97
            }
98
            if (m_entry) {
99
                window = m_entry->maskPasswordPlaceholders(window);
100
                window = m_entry->resolveMultiplePlaceholders(window);
101
            }
102
            return window;
103
        } else {
104
            QString sequence = m_autoTypeAssociations->get(index.row()).sequence;
105
            if (sequence.isEmpty()) {
106
                sequence = tr("Default sequence");
107
            }
108
            return sequence;
109
        }
110
    } else {
111
        return {};
112
    }
113
}
114

115
void AutoTypeAssociationsModel::associationChange(int i)
116
{
117
    emit dataChanged(index(i, 0), index(i, columnCount() - 1));
118
}
119

120
void AutoTypeAssociationsModel::associationAboutToAdd(int i)
121
{
122
    beginInsertRows(QModelIndex(), i, i);
123
}
124

125
void AutoTypeAssociationsModel::associationAdd()
126
{
127
    endInsertRows();
128
}
129

130
void AutoTypeAssociationsModel::associationAboutToRemove(int i)
131
{
132
    beginRemoveRows(QModelIndex(), i, i);
133
}
134

135
void AutoTypeAssociationsModel::associationRemove()
136
{
137
    endRemoveRows();
138
}
139

140
void AutoTypeAssociationsModel::aboutToReset()
141
{
142
    beginResetModel();
143
}
144

145
void AutoTypeAssociationsModel::reset()
146
{
147
    endResetModel();
148
}
149

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.