mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-26 09:21:21 -05:00
Add enum to describe current mode of database widget.
This commit is contained in:
parent
93c231ec2b
commit
c29c423ec8
@ -160,7 +160,7 @@ bool DatabaseTabWidget::closeDatabase(Database* db)
|
|||||||
if (dbName.right(1) == "*") {
|
if (dbName.right(1) == "*") {
|
||||||
dbName.chop(1);
|
dbName.chop(1);
|
||||||
}
|
}
|
||||||
if (dbStruct.dbWidget->currentIndex() != 0) {
|
if (dbStruct.dbWidget->currentMode() == DatabaseWidget::EditMode){
|
||||||
QMessageBox::StandardButton result =
|
QMessageBox::StandardButton result =
|
||||||
QMessageBox::question(
|
QMessageBox::question(
|
||||||
this, tr("Close?"),
|
this, tr("Close?"),
|
||||||
@ -407,7 +407,7 @@ void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct
|
|||||||
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
||||||
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabase()));
|
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabase()));
|
||||||
connect(db, SIGNAL(modified()), SLOT(modified()));
|
connect(db, SIGNAL(modified()), SLOT(modified()));
|
||||||
connect(dbStruct.dbWidget, SIGNAL(currentChanged(int)), this, SIGNAL(currentWidgetIndexChanged(int)));
|
connect(dbStruct.dbWidget, SIGNAL(currentModeChanged(DatabaseWidget::Mode)), this, SIGNAL(currentWidgetModeChanged(DatabaseWidget::Mode)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QtGui/QTabWidget>
|
#include <QtGui/QTabWidget>
|
||||||
|
|
||||||
#include "format/KeePass2Writer.h"
|
#include "format/KeePass2Writer.h"
|
||||||
|
#include "gui/DatabaseWidget.h"
|
||||||
|
|
||||||
class DatabaseWidget;
|
class DatabaseWidget;
|
||||||
class DatabaseOpenDialog;
|
class DatabaseOpenDialog;
|
||||||
@ -71,7 +72,7 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void entrySelectionChanged(bool singleEntrySelected);
|
void entrySelectionChanged(bool singleEntrySelected);
|
||||||
void currentWidgetIndexChanged(int index);
|
void currentWidgetModeChanged(DatabaseWidget::Mode);
|
||||||
void tabNameChanged();
|
void tabNameChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "gui/EntryView.h"
|
#include "gui/EntryView.h"
|
||||||
#include "gui/GroupView.h"
|
#include "gui/GroupView.h"
|
||||||
|
|
||||||
|
|
||||||
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||||
: QStackedWidget(parent)
|
: QStackedWidget(parent)
|
||||||
, m_db(db)
|
, m_db(db)
|
||||||
@ -87,10 +86,36 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
|||||||
connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
|
connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
|
||||||
connect(m_changeMasterKeyWidget, SIGNAL(editFinished(bool)), SLOT(updateMasterKey(bool)));
|
connect(m_changeMasterKeyWidget, SIGNAL(editFinished(bool)), SLOT(updateMasterKey(bool)));
|
||||||
connect(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(updateSettings(bool)));
|
connect(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(updateSettings(bool)));
|
||||||
|
connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged()));
|
||||||
|
|
||||||
setCurrentIndex(0);
|
setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseWidget::Mode DatabaseWidget::currentMode()
|
||||||
|
{
|
||||||
|
switch (currentIndex()) {
|
||||||
|
case -1:
|
||||||
|
return DatabaseWidget::None;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
return DatabaseWidget::ViewMode;
|
||||||
|
break;
|
||||||
|
case 1: // entry edit
|
||||||
|
case 2: // group edit
|
||||||
|
case 3: // change master key
|
||||||
|
case 4: // database settings
|
||||||
|
return DatabaseWidget::EditMode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DatabaseWidget::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseWidget::emitCurrentModeChanged()
|
||||||
|
{
|
||||||
|
Q_EMIT currentModeChanged(currentMode());
|
||||||
|
}
|
||||||
|
|
||||||
GroupView* DatabaseWidget::groupView()
|
GroupView* DatabaseWidget::groupView()
|
||||||
{
|
{
|
||||||
return m_groupView;
|
return m_groupView;
|
||||||
|
@ -35,6 +35,13 @@ class DatabaseWidget : public QStackedWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum Mode
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
ViewMode = 1,
|
||||||
|
EditMode = 2
|
||||||
|
};
|
||||||
|
|
||||||
explicit DatabaseWidget(Database* db, QWidget* parent = 0);
|
explicit DatabaseWidget(Database* db, QWidget* parent = 0);
|
||||||
GroupView* groupView();
|
GroupView* groupView();
|
||||||
EntryView* entryView();
|
EntryView* entryView();
|
||||||
@ -44,9 +51,11 @@ public:
|
|||||||
bool canDeleteCurrentGoup();
|
bool canDeleteCurrentGoup();
|
||||||
int addWidget(QWidget* w);
|
int addWidget(QWidget* w);
|
||||||
void setCurrentIndex(int index);
|
void setCurrentIndex(int index);
|
||||||
|
DatabaseWidget::Mode currentMode();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
|
void currentModeChanged(DatabaseWidget::Mode);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void createEntry();
|
void createEntry();
|
||||||
@ -63,6 +72,7 @@ private Q_SLOTS:
|
|||||||
void switchToGroupEdit(Group* entry, bool create);
|
void switchToGroupEdit(Group* entry, bool create);
|
||||||
void updateMasterKey(bool accepted);
|
void updateMasterKey(bool accepted);
|
||||||
void updateSettings(bool accepted);
|
void updateSettings(bool accepted);
|
||||||
|
void emitCurrentModeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Database* const m_db;
|
Database* const m_db;
|
||||||
|
@ -34,7 +34,7 @@ MainWindow::MainWindow()
|
|||||||
setWindowIcon(dataPath()->applicationIcon());
|
setWindowIcon(dataPath()->applicationIcon());
|
||||||
|
|
||||||
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), SLOT(setMenuActionState()));
|
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), SLOT(setMenuActionState()));
|
||||||
connect(m_ui->tabWidget, SIGNAL(currentWidgetIndexChanged(int)), SLOT(setMenuActionState(int)));
|
connect(m_ui->tabWidget, SIGNAL(currentWidgetModeChanged(DatabaseWidget::Mode)), SLOT(setMenuActionState(DatabaseWidget::Mode)));
|
||||||
connect(m_ui->tabWidget, SIGNAL(tabNameChanged()), SLOT(updateWindowTitle()));
|
connect(m_ui->tabWidget, SIGNAL(tabNameChanged()), SLOT(updateWindowTitle()));
|
||||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle()));
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle()));
|
||||||
|
|
||||||
@ -65,19 +65,19 @@ void MainWindow::openDatabase(const QString& fileName, const QString& pw, const
|
|||||||
|
|
||||||
const QString MainWindow::m_baseWindowTitle = "KeePassX";
|
const QString MainWindow::m_baseWindowTitle = "KeePassX";
|
||||||
|
|
||||||
void MainWindow::setMenuActionState(int index)
|
void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||||
{
|
{
|
||||||
if (m_ui->tabWidget->currentIndex() != -1) {
|
if (m_ui->tabWidget->currentIndex() != -1) {
|
||||||
m_ui->actionDatabaseClose->setEnabled(true);
|
m_ui->actionDatabaseClose->setEnabled(true);
|
||||||
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
||||||
Q_ASSERT(dbWidget);
|
Q_ASSERT(dbWidget);
|
||||||
|
|
||||||
if (index == -1) {
|
if (mode == DatabaseWidget::None) {
|
||||||
index = dbWidget->currentIndex();
|
mode = dbWidget->currentMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (index) {
|
switch (mode) {
|
||||||
case 0: // view
|
case DatabaseWidget::ViewMode:
|
||||||
m_ui->actionEntryNew->setEnabled(true);
|
m_ui->actionEntryNew->setEnabled(true);
|
||||||
m_ui->actionGroupNew->setEnabled(true);
|
m_ui->actionGroupNew->setEnabled(true);
|
||||||
if (dbWidget->entryView()->currentIndex().isValid()) {
|
if (dbWidget->entryView()->currentIndex().isValid()) {
|
||||||
@ -101,10 +101,7 @@ void MainWindow::setMenuActionState(int index)
|
|||||||
m_ui->actionDatabaseSave->setEnabled(true);
|
m_ui->actionDatabaseSave->setEnabled(true);
|
||||||
m_ui->actionDatabaseSaveAs->setEnabled(true);
|
m_ui->actionDatabaseSaveAs->setEnabled(true);
|
||||||
break;
|
break;
|
||||||
case 1: // entry edit
|
case DatabaseWidget::EditMode:
|
||||||
case 2: // group edit
|
|
||||||
case 3: // change master key
|
|
||||||
case 4: // database settings
|
|
||||||
m_ui->actionEntryNew->setEnabled(false);
|
m_ui->actionEntryNew->setEnabled(false);
|
||||||
m_ui->actionGroupNew->setEnabled(false);
|
m_ui->actionGroupNew->setEnabled(false);
|
||||||
m_ui->actionEntryEdit->setEnabled(false);
|
m_ui->actionEntryEdit->setEnabled(false);
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
|
||||||
|
#include "gui/DatabaseWidget.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
@ -37,7 +39,7 @@ protected:
|
|||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void setMenuActionState(int index = -1);
|
void setMenuActionState(DatabaseWidget::Mode mode = DatabaseWidget::None);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user