mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-17 13:02:49 -05:00
Implement the GUI for editing and creating groups.
This commit is contained in:
parent
bce46c5ece
commit
019bcd380e
@ -49,6 +49,7 @@ set(keepassx_SOURCES
|
||||
gui/DatabaseManager.cpp
|
||||
gui/DatabaseWidget.cpp
|
||||
gui/EditEntryWidget.cpp
|
||||
gui/EditGroupWidget.cpp
|
||||
gui/EntryModel.cpp
|
||||
gui/EntryView.cpp
|
||||
gui/FileDialog.cpp
|
||||
@ -74,6 +75,7 @@ set(keepassx_MOC
|
||||
gui/DatabaseManager.h
|
||||
gui/DatabaseWidget.h
|
||||
gui/EditEntryWidget.h
|
||||
gui/EditGroupWidget.h
|
||||
gui/EntryModel.h
|
||||
gui/EntryView.h
|
||||
gui/GroupModel.h
|
||||
@ -90,6 +92,7 @@ set(keepassx_FORMS
|
||||
gui/EditEntryWidget.ui
|
||||
gui/EditEntryWidgetMain.ui
|
||||
gui/EditEntryWidgetNotes.ui
|
||||
gui/EditGroupWidget.ui
|
||||
gui/KeyOpenDialog.ui
|
||||
gui/MainWindow.ui
|
||||
)
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "format/KeePass2XmlReader.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
#include "gui/FileDialog.h"
|
||||
#include "gui/GroupView.h"
|
||||
#include "gui/KeyOpenDialog.h"
|
||||
|
||||
DatabaseManagerStruct::DatabaseManagerStruct()
|
||||
@ -205,6 +206,20 @@ void DatabaseManager::saveDatabaseAs(int index)
|
||||
saveDatabaseAs(indexDatabase(index));
|
||||
}
|
||||
|
||||
void DatabaseManager::createGroup()
|
||||
{
|
||||
Database* db = indexDatabase(m_tabWidget->currentIndex());
|
||||
DatabaseWidget* dbWidget = m_dbList[db].dbWidget;
|
||||
dbWidget->createGroup();
|
||||
}
|
||||
|
||||
void DatabaseManager::editGroup()
|
||||
{
|
||||
Database* db = indexDatabase(m_tabWidget->currentIndex());
|
||||
DatabaseWidget* dbWidget = m_dbList[db].dbWidget;
|
||||
dbWidget->switchToGroupEdit();
|
||||
}
|
||||
|
||||
void DatabaseManager::updateTabName(Database* db)
|
||||
{
|
||||
int index = databaseIndex(db);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "format/KeePass2Reader.h"
|
||||
#include "format/KeePass2Writer.h"
|
||||
|
||||
class DatabaseWidget;
|
||||
class KeyOpenDialog;
|
||||
class QFile;
|
||||
class QTabWidget;
|
||||
@ -33,7 +34,7 @@ struct DatabaseManagerStruct
|
||||
DatabaseManagerStruct();
|
||||
|
||||
QFile* file;
|
||||
QWidget* dbWidget;
|
||||
DatabaseWidget* dbWidget;
|
||||
QString fileName;
|
||||
bool modified;
|
||||
bool readOnly;
|
||||
@ -56,6 +57,8 @@ public Q_SLOTS:
|
||||
void saveDatabase(int index = -1);
|
||||
void saveDatabaseAs(int index = -1);
|
||||
void closeDatabase(int index = -1);
|
||||
void createGroup();
|
||||
void editGroup();
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateTabName(Database* db);
|
||||
|
@ -21,11 +21,14 @@
|
||||
#include <QtGui/QSplitter>
|
||||
|
||||
#include "gui/EditEntryWidget.h"
|
||||
#include "gui/EditGroupWidget.h"
|
||||
#include "gui/EntryView.h"
|
||||
#include "gui/GroupView.h"
|
||||
|
||||
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
: QStackedWidget(parent)
|
||||
, m_newGroup(0)
|
||||
, m_newGroupParent(0)
|
||||
{
|
||||
m_mainWidget = new QWidget(this);
|
||||
QLayout* layout = new QHBoxLayout(m_mainWidget);
|
||||
@ -50,25 +53,74 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
layout->addWidget(splitter);
|
||||
m_mainWidget->setLayout(layout);
|
||||
|
||||
m_editWidget = new EditEntryWidget();
|
||||
m_editEntryWidget = new EditEntryWidget();
|
||||
m_editGroupWidget = new EditGroupWidget();
|
||||
|
||||
addWidget(m_mainWidget);
|
||||
addWidget(m_editWidget);
|
||||
addWidget(m_editEntryWidget);
|
||||
addWidget(m_editGroupWidget);
|
||||
|
||||
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
|
||||
connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEdit(Entry*)));
|
||||
connect(m_editWidget, SIGNAL(editFinished()), SLOT(switchToView()));
|
||||
connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*)));
|
||||
connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
|
||||
connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
|
||||
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToView()
|
||||
GroupView* DatabaseWidget::groupView()
|
||||
{
|
||||
return m_groupView;
|
||||
}
|
||||
|
||||
EntryView* DatabaseWidget::entryView()
|
||||
{
|
||||
return m_entryView;
|
||||
}
|
||||
|
||||
void DatabaseWidget::createGroup()
|
||||
{
|
||||
m_newGroup = new Group();
|
||||
m_newGroup->setUuid(Uuid::random());
|
||||
m_newGroupParent = m_groupView->currentGroup();
|
||||
switchToGroupEdit(m_newGroup, true);
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToView(bool accepted)
|
||||
{
|
||||
if (m_newGroup) {
|
||||
if (accepted) {
|
||||
m_newGroup->setParent(m_newGroupParent);
|
||||
}
|
||||
else {
|
||||
delete m_newGroup;
|
||||
}
|
||||
|
||||
m_newGroup = 0;
|
||||
m_newGroupParent = 0;
|
||||
}
|
||||
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToEdit(Entry* entry)
|
||||
void DatabaseWidget::switchToEntryEdit(Entry* entry)
|
||||
{
|
||||
m_editWidget->loadEntry(entry);
|
||||
m_editEntryWidget->loadEntry(entry);
|
||||
setCurrentIndex(1);
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
|
||||
{
|
||||
m_editGroupWidget->loadGroup(group, create);
|
||||
setCurrentIndex(2);
|
||||
}
|
||||
void DatabaseWidget::switchToEntryEdit()
|
||||
{
|
||||
// TODO switchToEntryEdit(m_entryView->currentEntry());
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToGroupEdit()
|
||||
{
|
||||
switchToGroupEdit(m_groupView->currentGroup(), false);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,10 @@
|
||||
|
||||
class Database;
|
||||
class EditEntryWidget;
|
||||
class EditGroupWidget;
|
||||
class Entry;
|
||||
class EntryView;
|
||||
class Group;
|
||||
class GroupView;
|
||||
|
||||
class DatabaseWidget : public QStackedWidget
|
||||
@ -32,16 +34,27 @@ class DatabaseWidget : public QStackedWidget
|
||||
|
||||
public:
|
||||
explicit DatabaseWidget(Database* db, QWidget* parent = 0);
|
||||
GroupView* groupView();
|
||||
EntryView* entryView();
|
||||
|
||||
public Q_SLOTS:
|
||||
void createGroup();
|
||||
void switchToEntryEdit();
|
||||
void switchToGroupEdit();
|
||||
|
||||
private Q_SLOTS:
|
||||
void switchToView();
|
||||
void switchToEdit(Entry* entry);
|
||||
void switchToView(bool accepted);
|
||||
void switchToEntryEdit(Entry* entry);
|
||||
void switchToGroupEdit(Group* entry, bool create);
|
||||
|
||||
private:
|
||||
QWidget* m_mainWidget;
|
||||
EditEntryWidget* m_editWidget;
|
||||
EditEntryWidget* m_editEntryWidget;
|
||||
EditGroupWidget* m_editGroupWidget;
|
||||
GroupView* m_groupView;
|
||||
EntryView* m_entryView;
|
||||
Group* m_newGroup;
|
||||
Group* m_newGroupParent;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_DATABASEWIDGET_H
|
||||
|
@ -85,11 +85,12 @@ void EditEntryWidget::saveEntry()
|
||||
|
||||
m_entry->setNotes(m_notesUi->notesEdit->toPlainText());
|
||||
|
||||
cancel();
|
||||
m_entry = 0;
|
||||
Q_EMIT editFinished(true);
|
||||
}
|
||||
|
||||
void EditEntryWidget::cancel()
|
||||
{
|
||||
m_entry = 0;
|
||||
Q_EMIT editFinished();
|
||||
Q_EMIT editFinished(false);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
void loadEntry(Entry* entry);
|
||||
|
||||
Q_SIGNALS:
|
||||
void editFinished();
|
||||
void editFinished(bool accepted);
|
||||
|
||||
private Q_SLOTS:
|
||||
void saveEntry();
|
||||
|
69
src/gui/EditGroupWidget.cpp
Normal file
69
src/gui/EditGroupWidget.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
|
||||
*
|
||||
* 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 "EditGroupWidget.h"
|
||||
#include "ui_EditGroupWidget.h"
|
||||
|
||||
EditGroupWidget::EditGroupWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::EditGroupWidget())
|
||||
, m_group(0)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
QFont labelHeaderFont = m_ui->labelHeader->font();
|
||||
labelHeaderFont.setBold(true);
|
||||
labelHeaderFont.setPointSize(labelHeaderFont.pointSize() + 2);
|
||||
m_ui->labelHeader->setFont(labelHeaderFont);
|
||||
|
||||
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(save()));
|
||||
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(cancel()));
|
||||
}
|
||||
|
||||
EditGroupWidget::~EditGroupWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void EditGroupWidget::loadGroup(Group* group, bool create)
|
||||
{
|
||||
m_group = group;
|
||||
|
||||
if (create) {
|
||||
m_ui->labelHeader->setText(tr("Add group"));
|
||||
}
|
||||
else {
|
||||
m_ui->labelHeader->setText(tr("Edit group"));
|
||||
}
|
||||
|
||||
m_ui->editName->setText(m_group->name());
|
||||
m_ui->editNotes->setPlainText(m_group->notes());
|
||||
}
|
||||
|
||||
void EditGroupWidget::save()
|
||||
{
|
||||
m_group->setName(m_ui->editName->text());
|
||||
m_group->setNotes(m_ui->editNotes->toPlainText());
|
||||
|
||||
m_group = 0;
|
||||
Q_EMIT editFinished(true);
|
||||
}
|
||||
|
||||
void EditGroupWidget::cancel()
|
||||
{
|
||||
m_group = 0;
|
||||
Q_EMIT editFinished(false);
|
||||
}
|
54
src/gui/EditGroupWidget.h
Normal file
54
src/gui/EditGroupWidget.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_GROUPDIALOG_H
|
||||
#define KEEPASSX_GROUPDIALOG_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
#include "core/Group.h"
|
||||
|
||||
namespace Ui {
|
||||
class EditGroupWidget;
|
||||
}
|
||||
|
||||
class EditGroupWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EditGroupWidget(QWidget* parent = 0);
|
||||
~EditGroupWidget();
|
||||
|
||||
void loadGroup(Group* group, bool create);
|
||||
|
||||
Q_SIGNALS:
|
||||
void editFinished(bool accepted);
|
||||
|
||||
private Q_SLOTS:
|
||||
void save();
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::EditGroupWidget> m_ui;
|
||||
Group* m_group;
|
||||
|
||||
Q_DISABLE_COPY(EditGroupWidget)
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_GROUPDIALOG_H
|
74
src/gui/EditGroupWidget.ui
Normal file
74
src/gui/EditGroupWidget.ui
Normal file
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditGroupWidget</class>
|
||||
<widget class="QWidget" name="EditGroupWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>544</width>
|
||||
<height>263</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelHeader"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>3</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelNotes">
|
||||
<property name="text">
|
||||
<string>Notes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="editName"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelName">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPlainTextEdit" name="editNotes"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -41,6 +41,11 @@ GroupView::GroupView(Database* db, QWidget* parent)
|
||||
Q_ARG(QModelIndex, m_model->index(0, 0)));
|
||||
}
|
||||
|
||||
Group* GroupView::currentGroup()
|
||||
{
|
||||
return m_model->groupFromIndex(currentIndex());
|
||||
}
|
||||
|
||||
void GroupView::expandedChanged(const QModelIndex& index)
|
||||
{
|
||||
Group* group = m_model->groupFromIndex(index);
|
||||
|
@ -31,6 +31,7 @@ class GroupView : public QTreeView
|
||||
public:
|
||||
explicit GroupView(Database* db, QWidget* parent = 0);
|
||||
void setModel(QAbstractItemModel* model);
|
||||
Group* currentGroup();
|
||||
|
||||
Q_SIGNALS:
|
||||
void groupChanged(Group* group);
|
||||
|
@ -37,6 +37,8 @@ MainWindow::MainWindow()
|
||||
connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabase()));
|
||||
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_dbManager, SLOT(saveDatabaseAs()));
|
||||
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_dbManager, SLOT(closeDatabase()));
|
||||
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_dbManager, SLOT(createGroup()));
|
||||
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_dbManager, SLOT(editGroup()));
|
||||
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
||||
}
|
||||
|
||||
@ -53,4 +55,5 @@ void MainWindow::currentTabChanged(int index)
|
||||
m_ui->actionDatabaseClose->setEnabled(hasTab);
|
||||
m_ui->actionEntryNew->setEnabled(hasTab);
|
||||
m_ui->actionGroupNew->setEnabled(hasTab);
|
||||
m_ui->actionGroupEdit->setEnabled(hasTab);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user