2
* Copyright (C) 2013 Francois Ferrand
3
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
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.
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.
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/>.
19
#include "BrowserEntrySaveDialog.h"
20
#include "ui_BrowserEntrySaveDialog.h"
22
#include "gui/DatabaseWidget.h"
24
BrowserEntrySaveDialog::BrowserEntrySaveDialog(QWidget* parent)
26
, m_ui(new Ui::BrowserEntrySaveDialog())
28
this->setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
31
connect(m_ui->okButton, SIGNAL(clicked()), this, SLOT(accept()));
32
connect(m_ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
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.")));
39
BrowserEntrySaveDialog::~BrowserEntrySaveDialog()
43
int BrowserEntrySaveDialog::setItems(QList<DatabaseWidget*>& databaseWidgets, DatabaseWidget* currentWidget) const
47
for (const auto dbWidget : databaseWidgets) {
48
QString databaseName = dbWidget->database()->metadata()->name();
49
QString databaseFileName = dbWidget->database()->filePath();
51
auto* item = new QListWidgetItem();
52
item->setData(Qt::UserRole, counter);
54
// Show database name (and filename if the name has been set in metadata)
55
if (databaseName == databaseFileName) {
56
item->setText(databaseFileName);
58
item->setText(QString("%1 (%2)").arg(databaseName, databaseFileName));
61
if (currentWidget == dbWidget) {
62
activeIndex = counter;
65
m_ui->itemsList->addItem(item);
69
// This must be done after the whole list is filled
70
if (activeIndex >= 0) {
71
m_ui->itemsList->item(activeIndex)->setSelected(true);
74
m_ui->itemsList->selectAll();
75
return databaseWidgets.length();
78
QList<QListWidgetItem*> BrowserEntrySaveDialog::getSelected() const
80
return m_ui->itemsList->selectedItems();