mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Cleanup welcome screen recent databases view (#4822)
* Press "Delete" to remove recent database * Refresh recent databases on becoming visible
This commit is contained in:
parent
712b8224c6
commit
6c9125402a
@ -40,11 +40,6 @@ WelcomeWidget::WelcomeWidget(QWidget* parent)
|
||||
|
||||
refreshLastDatabases();
|
||||
|
||||
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);
|
||||
|
||||
connect(m_ui->buttonNewDatabase, SIGNAL(clicked()), SIGNAL(newDatabase()));
|
||||
connect(m_ui->buttonOpenDatabase, SIGNAL(clicked()), SIGNAL(openDatabase()));
|
||||
connect(m_ui->buttonImportKeePass1, SIGNAL(clicked()), SIGNAL(importKeePass1Database()));
|
||||
@ -62,12 +57,26 @@ WelcomeWidget::~WelcomeWidget()
|
||||
|
||||
void WelcomeWidget::openDatabaseFromFile(QListWidgetItem* item)
|
||||
{
|
||||
if (item->text().isEmpty()) {
|
||||
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();
|
||||
@ -77,13 +86,28 @@ void WelcomeWidget::refreshLastDatabases()
|
||||
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() && (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
|
||||
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);
|
||||
}
|
||||
|
@ -46,12 +46,14 @@ signals:
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void openDatabaseFromFile(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
const QScopedPointer<Ui::WelcomeWidget> m_ui;
|
||||
void removeFromLastDatabases(QListWidgetItem* item);
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_WELCOMEWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user