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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WelcomeWidget.h"
#include "ui_WelcomeWidget.h"
#include <QKeyEvent>
#include "config-keepassx.h"
#include "core/Config.h"
#include "gui/Icons.h"
WelcomeWidget::WelcomeWidget(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::WelcomeWidget())
{
m_ui->setupUi(this);
m_ui->welcomeLabel->setText(tr("Welcome to KeePassXC %1").arg(KEEPASSXC_VERSION));
QFont welcomeLabelFont = m_ui->welcomeLabel->font();
welcomeLabelFont.setBold(true);
welcomeLabelFont.setPointSize(welcomeLabelFont.pointSize() + 4);
m_ui->welcomeLabel->setFont(welcomeLabelFont);
m_ui->iconLabel->setPixmap(icons()->applicationIcon().pixmap(64));
refreshLastDatabases();
connect(m_ui->buttonNewDatabase, SIGNAL(clicked()), SIGNAL(newDatabase()));
connect(m_ui->buttonOpenDatabase, SIGNAL(clicked()), SIGNAL(openDatabase()));
connect(m_ui->buttonImportKeePass1, SIGNAL(clicked()), SIGNAL(importKeePass1Database()));
connect(m_ui->buttonImportOpVault, SIGNAL(clicked()), SIGNAL(importOpVaultDatabase()));
connect(m_ui->buttonImportCSV, SIGNAL(clicked()), SIGNAL(importCsv()));
connect(m_ui->recentListWidget,
SIGNAL(itemActivated(QListWidgetItem*)),
this,
SLOT(openDatabaseFromFile(QListWidgetItem*)));
}
WelcomeWidget::~WelcomeWidget()
{
}
void WelcomeWidget::openDatabaseFromFile(QListWidgetItem* item)
{
if (!item || item->text().isEmpty()) {
return;
}
emit openDatabaseFile(item->text());
}
void WelcomeWidget::removeFromLastDatabases(QListWidgetItem* item)
{
if (!item || item->text().isEmpty()) {
return;
}
if (config()->get(Config::RememberLastDatabases).toBool()) {
QStringList lastDatabases = config()->get(Config::LastDatabases).toStringList();
lastDatabases.removeOne(item->text());
config()->set(Config::LastDatabases, lastDatabases);
}
refreshLastDatabases();
}
void WelcomeWidget::refreshLastDatabases()
{
m_ui->recentListWidget->clear();
const QStringList lastDatabases = config()->get(Config::LastDatabases).toStringList();
for (const QString& database : lastDatabases) {
QListWidgetItem* itm = new QListWidgetItem;
itm->setText(database);
m_ui->recentListWidget->addItem(itm);
}
bool recent_visibility = (m_ui->recentListWidget->count() > 0);
m_ui->startLabel->setVisible(!recent_visibility);
m_ui->recentListWidget->setVisible(recent_visibility);
m_ui->recentLabel->setVisible(recent_visibility);
}
void WelcomeWidget::keyPressEvent(QKeyEvent* event)
{
if (m_ui->recentListWidget->hasFocus()) {
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
openDatabaseFromFile(m_ui->recentListWidget->currentItem());
} else if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) {
removeFromLastDatabases(m_ui->recentListWidget->currentItem());
}
}
QWidget::keyPressEvent(event);
}
void WelcomeWidget::showEvent(QShowEvent* event)
{
refreshLastDatabases();
QWidget::showEvent(event);
}
|