keepassxc

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

19
#include "BrowserEntrySaveDialog.h"
20
#include "ui_BrowserEntrySaveDialog.h"
21

22
#include "gui/DatabaseWidget.h"
23

24
BrowserEntrySaveDialog::BrowserEntrySaveDialog(QWidget* parent)
25
    : QDialog(parent)
26
    , m_ui(new Ui::BrowserEntrySaveDialog())
27
{
28
    this->setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
29

30
    m_ui->setupUi(this);
31
    connect(m_ui->okButton, SIGNAL(clicked()), this, SLOT(accept()));
32
    connect(m_ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
33

34
    m_ui->itemsList->setSelectionMode(QAbstractItemView::SingleSelection);
35
    m_ui->label->setText(QString(tr("You have multiple databases open.\n"
36
                                    "Please select the correct database for saving credentials.")));
37
}
38

39
BrowserEntrySaveDialog::~BrowserEntrySaveDialog()
40
{
41
}
42

43
int BrowserEntrySaveDialog::setItems(QList<DatabaseWidget*>& databaseWidgets, DatabaseWidget* currentWidget) const
44
{
45
    uint counter = 0;
46
    int activeIndex = -1;
47
    for (const auto dbWidget : databaseWidgets) {
48
        QString databaseName = dbWidget->database()->metadata()->name();
49
        QString databaseFileName = dbWidget->database()->filePath();
50

51
        auto* item = new QListWidgetItem();
52
        item->setData(Qt::UserRole, counter);
53

54
        // Show database name (and filename if the name has been set in metadata)
55
        if (databaseName == databaseFileName) {
56
            item->setText(databaseFileName);
57
        } else {
58
            item->setText(QString("%1 (%2)").arg(databaseName, databaseFileName));
59
        }
60

61
        if (currentWidget == dbWidget) {
62
            activeIndex = counter;
63
        }
64

65
        m_ui->itemsList->addItem(item);
66
        ++counter;
67
    }
68

69
    // This must be done after the whole list is filled
70
    if (activeIndex >= 0) {
71
        m_ui->itemsList->item(activeIndex)->setSelected(true);
72
    }
73

74
    m_ui->itemsList->selectAll();
75
    return databaseWidgets.length();
76
}
77

78
QList<QListWidgetItem*> BrowserEntrySaveDialog::getSelected() const
79
{
80
    return m_ui->itemsList->selectedItems();
81
}
82

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

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

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

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