Implement GUI for creating entries.

This commit is contained in:
Felix Geyer 2011-12-27 16:04:59 +01:00
parent 019bcd380e
commit 4d8e9561a7
7 changed files with 51 additions and 11 deletions

View File

@ -206,6 +206,13 @@ void DatabaseManager::saveDatabaseAs(int index)
saveDatabaseAs(indexDatabase(index));
}
void DatabaseManager::createEntry()
{
Database* db = indexDatabase(m_tabWidget->currentIndex());
DatabaseWidget* dbWidget = m_dbList[db].dbWidget;
dbWidget->createEntry();
}
void DatabaseManager::createGroup()
{
Database* db = indexDatabase(m_tabWidget->currentIndex());

View File

@ -57,6 +57,7 @@ public Q_SLOTS:
void saveDatabase(int index = -1);
void saveDatabaseAs(int index = -1);
void closeDatabase(int index = -1);
void createEntry();
void createGroup();
void editGroup();

View File

@ -28,7 +28,7 @@
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
: QStackedWidget(parent)
, m_newGroup(0)
, m_newGroupParent(0)
, m_newParent(0)
{
m_mainWidget = new QWidget(this);
QLayout* layout = new QHBoxLayout(m_mainWidget);
@ -78,11 +78,19 @@ EntryView* DatabaseWidget::entryView()
return m_entryView;
}
void DatabaseWidget::createEntry()
{
m_newEntry = new Entry();
m_newEntry->setUuid(Uuid::random());
m_newParent = m_groupView->currentGroup();
switchToEntryEdit(m_newEntry, true);
}
void DatabaseWidget::createGroup()
{
m_newGroup = new Group();
m_newGroup->setUuid(Uuid::random());
m_newGroupParent = m_groupView->currentGroup();
m_newParent = m_groupView->currentGroup();
switchToGroupEdit(m_newGroup, true);
}
@ -90,14 +98,25 @@ void DatabaseWidget::switchToView(bool accepted)
{
if (m_newGroup) {
if (accepted) {
m_newGroup->setParent(m_newGroupParent);
m_newGroup->setParent(m_newParent);
}
else {
delete m_newGroup;
}
m_newGroup = 0;
m_newGroupParent = 0;
m_newParent = 0;
}
else if (m_newEntry) {
if (accepted) {
m_newEntry->setGroup(m_newParent);
}
else {
delete m_newEntry;
}
m_newEntry = 0;
m_newParent = 0;
}
setCurrentIndex(0);
@ -105,7 +124,12 @@ void DatabaseWidget::switchToView(bool accepted)
void DatabaseWidget::switchToEntryEdit(Entry* entry)
{
m_editEntryWidget->loadEntry(entry);
switchToEntryEdit(entry, false);
}
void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create)
{
m_editEntryWidget->loadEntry(entry, create, m_groupView->currentGroup()->name());
setCurrentIndex(1);
}
@ -116,11 +140,10 @@ void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
}
void DatabaseWidget::switchToEntryEdit()
{
// TODO switchToEntryEdit(m_entryView->currentEntry());
// TODO switchToEntryEdit(m_entryView->currentEntry(), false);
}
void DatabaseWidget::switchToGroupEdit()
{
switchToGroupEdit(m_groupView->currentGroup(), false);
}

View File

@ -38,6 +38,7 @@ public:
EntryView* entryView();
public Q_SLOTS:
void createEntry();
void createGroup();
void switchToEntryEdit();
void switchToGroupEdit();
@ -45,6 +46,7 @@ public Q_SLOTS:
private Q_SLOTS:
void switchToView(bool accepted);
void switchToEntryEdit(Entry* entry);
void switchToEntryEdit(Entry* entry, bool create);
void switchToGroupEdit(Group* entry, bool create);
private:
@ -54,7 +56,8 @@ private:
GroupView* m_groupView;
EntryView* m_entryView;
Group* m_newGroup;
Group* m_newGroupParent;
Entry* m_newEntry;
Group* m_newParent;
};
#endif // KEEPASSX_DATABASEWIDGET_H

View File

@ -62,11 +62,16 @@ EditEntryWidget::~EditEntryWidget()
{
}
void EditEntryWidget::loadEntry(Entry* entry)
void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupName)
{
m_entry = entry;
m_ui->headerLabel->setText(m_entry->group()->name()+" > "+tr("Edit entry"));
if (create) {
m_ui->headerLabel->setText(groupName+" > "+tr("Add entry"));
}
else {
m_ui->headerLabel->setText(groupName+" > "+tr("Edit entry"));
}
m_mainUi->titleEdit->setText(entry->title());
m_mainUi->usernameEdit->setText(entry->username());

View File

@ -39,7 +39,7 @@ public:
explicit EditEntryWidget(QWidget* parent = 0);
~EditEntryWidget();
void loadEntry(Entry* entry);
void loadEntry(Entry* entry, bool create, const QString& groupName);
Q_SIGNALS:
void editFinished(bool accepted);

View File

@ -37,6 +37,7 @@ 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->actionEntryNew, SIGNAL(triggered()), m_dbManager, SLOT(createEntry()));
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()));