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