keepassxc

Форк
0
/
EditWidgetProperties.cpp 
120 строк · 4.0 Кб
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 "EditWidgetProperties.h"
19
#include "ui_EditWidgetProperties.h"
20

21
#include "MessageBox.h"
22
#include "core/CustomData.h"
23
#include "core/TimeInfo.h"
24

25
#include <QUuid>
26

27
EditWidgetProperties::EditWidgetProperties(QWidget* parent)
28
    : QWidget(parent)
29
    , m_ui(new Ui::EditWidgetProperties())
30
    , m_customDataModel(new QStandardItemModel(this))
31
{
32
    m_ui->setupUi(this);
33
    m_ui->removeCustomDataButton->setEnabled(false);
34
    m_ui->customDataTable->setModel(m_customDataModel);
35

36
    // clang-format off
37
    connect(m_ui->customDataTable->selectionModel(),
38
            SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
39
            SLOT(toggleRemoveButton(QItemSelection)));
40
    // clang-format on
41
    connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedPluginData()));
42
}
43

44
EditWidgetProperties::~EditWidgetProperties() = default;
45

46
void EditWidgetProperties::setFields(const TimeInfo& timeInfo, const QUuid& uuid)
47
{
48
    static const QString timeFormat("d MMM yyyy HH:mm:ss");
49
    m_ui->modifiedEdit->setText(timeInfo.lastModificationTime().toLocalTime().toString(timeFormat));
50
    m_ui->createdEdit->setText(timeInfo.creationTime().toLocalTime().toString(timeFormat));
51
    m_ui->accessedEdit->setText(timeInfo.lastAccessTime().toLocalTime().toString(timeFormat));
52
    m_ui->uuidEdit->setText(uuid.toRfc4122().toHex());
53
}
54

55
void EditWidgetProperties::setCustomData(CustomData* customData)
56
{
57
    if (m_customData) {
58
        m_customData->disconnect(this);
59
    }
60

61
    m_customData = customData;
62

63
    if (m_customData) {
64
        connect(m_customData, &CustomData::modified, this, &EditWidgetProperties::update);
65
    }
66

67
    update();
68
}
69

70
void EditWidgetProperties::removeSelectedPluginData()
71
{
72
    QModelIndexList indexes = m_ui->customDataTable->selectionModel()->selectedRows(0);
73
    if (indexes.isEmpty()) {
74
        return;
75
    }
76

77
    auto result = MessageBox::question(this,
78
                                       tr("Delete plugin data?"),
79
                                       tr("Do you really want to delete the selected plugin data?\n"
80
                                          "This may cause the affected plugins to malfunction."),
81
                                       MessageBox::Delete | MessageBox::Cancel,
82
                                       MessageBox::Cancel);
83

84
    if (result == MessageBox::Cancel) {
85
        return;
86
    }
87

88
    QStringList selectedData;
89
    for (const auto& index : indexes) {
90
        const QString key = index.data().toString();
91
        selectedData.append(key);
92
    }
93

94
    std::sort(selectedData.begin(), selectedData.end());
95
    for (const auto& key : selectedData) {
96
        m_customData->remove(key);
97
    }
98

99
    update();
100
}
101

102
void EditWidgetProperties::toggleRemoveButton(const QItemSelection& selected)
103
{
104
    m_ui->removeCustomDataButton->setEnabled(!selected.isEmpty());
105
}
106

107
void EditWidgetProperties::update()
108
{
109
    m_customDataModel->clear();
110
    m_customDataModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")});
111
    if (!m_customData) {
112
        m_ui->removeCustomDataButton->setEnabled(false);
113
    } else {
114
        for (const QString& key : m_customData->keys()) {
115
            m_customDataModel->appendRow(QList<QStandardItem*>()
116
                                         << new QStandardItem(key) << new QStandardItem(m_customData->value(key)));
117
        }
118
        m_ui->removeCustomDataButton->setEnabled(!m_customData->isEmpty());
119
    }
120
}
121

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

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

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

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