From ee981c4c19a7e9a1fd8ab363c1aed24382047142 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Sat, 11 Feb 2017 19:04:37 +0100 Subject: [PATCH] closes #204. Welcome screen redesign --- src/gui/MainWindow.cpp | 29 ++++++ src/gui/MainWindow.h | 4 + src/gui/MainWindow.ui | 46 ++++++++- src/gui/WelcomeWidget.cpp | 37 +++++++ src/gui/WelcomeWidget.h | 10 ++ src/gui/WelcomeWidget.ui | 198 +++++++++++++++++++++++++++++++++++++- 6 files changed, 318 insertions(+), 6 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 993e28c8f..2f3d7083b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -277,6 +277,11 @@ MainWindow::MainWindow() connect(m_ui->actionPasswordGenerator, SIGNAL(toggled(bool)), SLOT(switchToPasswordGen(bool))); connect(m_ui->passwordGeneratorWidget, SIGNAL(dialogTerminated()), SLOT(closePasswordGen())); + connect(m_ui->welcomeWidget, SIGNAL(newDatabase()), SLOT(switchToNewDatabase())); + connect(m_ui->welcomeWidget, SIGNAL(openDatabase()), SLOT(switchToOpenDatabase())); + connect(m_ui->welcomeWidget, SIGNAL(openDatabaseFile(QString)), SLOT(switchToDatabaseFile(QString))); + connect(m_ui->welcomeWidget, SIGNAL(importKeePass1Database()), SLOT(switchToKeePass1Database())); + connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog())); connect(m_ui->tabWidget, SIGNAL(messageGlobal(QString,MessageWidget::MessageType)), this, SLOT(displayGlobalMessage(QString, MessageWidget::MessageType))); @@ -537,6 +542,30 @@ void MainWindow::closePasswordGen() switchToPasswordGen(false); } +void MainWindow::switchToNewDatabase() +{ + m_ui->tabWidget->newDatabase(); + switchToDatabases(); +} + +void MainWindow::switchToOpenDatabase() +{ + m_ui->tabWidget->openDatabase(); + switchToDatabases(); +} + +void MainWindow::switchToDatabaseFile(QString file) +{ + m_ui->tabWidget->openDatabase(file); + switchToDatabases(); +} + +void MainWindow::switchToKeePass1Database() +{ + m_ui->tabWidget->importKeePass1Database(); + switchToDatabases(); +} + void MainWindow::databaseStatusChanged(DatabaseWidget *) { updateTrayIcon(); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 4182140c7..694b38e7a 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -55,6 +55,10 @@ private Q_SLOTS: void switchToDatabases(); void switchToSettings(); void switchToPasswordGen(bool enabled); + void switchToNewDatabase(); + void switchToOpenDatabase(); + void switchToDatabaseFile(QString file); + void switchToKeePass1Database(); void closePasswordGen(); void databaseStatusChanged(DatabaseWidget *dbWidget); void databaseTabChanged(int tabIndex); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 44afe68ac..6e3ecf684 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -105,7 +105,45 @@ - + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 50 + 20 + + + + + + + horizontalSpacer_2 + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 50 + 20 + + + + + @@ -277,9 +315,9 @@ - - Merge from KeePassX database - + + Merge from KeePassX database + diff --git a/src/gui/WelcomeWidget.cpp b/src/gui/WelcomeWidget.cpp index 842546ecc..12a1b6db0 100644 --- a/src/gui/WelcomeWidget.cpp +++ b/src/gui/WelcomeWidget.cpp @@ -18,13 +18,50 @@ #include "WelcomeWidget.h" #include "ui_WelcomeWidget.h" +#include "config-keepassx.h" +#include "core/FilePath.h" +#include "core/Config.h" + WelcomeWidget::WelcomeWidget(QWidget* parent) : QWidget(parent) , m_ui(new Ui::WelcomeWidget()) { m_ui->setupUi(this); + + m_ui->welcomeLabel->setText(m_ui->welcomeLabel->text() + " " + KEEPASSX_VERSION); + QFont welcomeLabelFont = m_ui->welcomeLabel->font(); + welcomeLabelFont.setBold(true); + welcomeLabelFont.setPointSize(welcomeLabelFont.pointSize() + 4); + m_ui->welcomeLabel->setFont(welcomeLabelFont); + + m_ui->iconLabel->setPixmap(filePath()->applicationIcon().pixmap(64)); + + // waiting for CSV PR + m_ui->buttonImportCSV->hide(); + + m_ui->recentListWidget->clear(); + const QStringList lastDatabases = config()->get("LastDatabases", QVariant()).toStringList(); + for (const QString& database : lastDatabases) { + QListWidgetItem *itm = new QListWidgetItem; + itm->setText(database); + m_ui->recentListWidget->addItem(itm); + } + + 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->recentListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, + SLOT(openDatabaseFromFile(QListWidgetItem*))); } WelcomeWidget::~WelcomeWidget() { } + +void WelcomeWidget::openDatabaseFromFile(QListWidgetItem* item) +{ + if (item->text().isEmpty()) { + return; + } + Q_EMIT openDatabaseFile(item->text()); +} \ No newline at end of file diff --git a/src/gui/WelcomeWidget.h b/src/gui/WelcomeWidget.h index 80a0dde1c..dbd0d2e27 100644 --- a/src/gui/WelcomeWidget.h +++ b/src/gui/WelcomeWidget.h @@ -19,6 +19,7 @@ #define KEEPASSX_WELCOMEWIDGET_H #include +#include namespace Ui { class WelcomeWidget; @@ -32,6 +33,15 @@ public: explicit WelcomeWidget(QWidget* parent = nullptr); ~WelcomeWidget(); +Q_SIGNALS: + void newDatabase(); + void openDatabase(); + void openDatabaseFile(QString); + void importKeePass1Database(); + +private Q_SLOTS: + void openDatabaseFromFile(QListWidgetItem* item); + private: const QScopedPointer m_ui; }; diff --git a/src/gui/WelcomeWidget.ui b/src/gui/WelcomeWidget.ui index 4382e7c77..7591a6038 100644 --- a/src/gui/WelcomeWidget.ui +++ b/src/gui/WelcomeWidget.ui @@ -2,17 +2,211 @@ WelcomeWidget + + + 0 + 0 + 450 + 401 + + + + + 0 + 0 + + + + + 450 + 0 + + - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + - Welcome! + Welcome to KeePassXC Qt::AlignCenter + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + + + 0 + 255 + 0 + + + + + + + + + 0 + 255 + 0 + + + + + + + + + 0 + 255 + 0 + + + + + + + + Create new database + + + + + + + Open existing database + + + + + + + + + Import from KeePass1 + + + + + + + true + + + Import from CSV + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 0 + 5 + + + + + + + + Recent databases + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + +