Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2011-12-27 18:49:06 +0400
committerFelix Geyer <debfx@fobos.de>2011-12-27 18:49:06 +0400
commit019bcd380e5545f2dc8b34eb43f4987959c40e9b (patch)
treea896d3bae724fc31d6b06f5ca307d7c956ae44b2 /src
parentbce46c5ecea53ff976a9e97e8638a847819082b3 (diff)
Implement the GUI for editing and creating groups.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/gui/DatabaseManager.cpp15
-rw-r--r--src/gui/DatabaseManager.h5
-rw-r--r--src/gui/DatabaseWidget.cpp66
-rw-r--r--src/gui/DatabaseWidget.h19
-rw-r--r--src/gui/EditEntryWidget.cpp5
-rw-r--r--src/gui/EditEntryWidget.h2
-rw-r--r--src/gui/EditGroupWidget.cpp69
-rw-r--r--src/gui/EditGroupWidget.h54
-rw-r--r--src/gui/EditGroupWidget.ui74
-rw-r--r--src/gui/GroupView.cpp5
-rw-r--r--src/gui/GroupView.h1
-rw-r--r--src/gui/MainWindow.cpp3
13 files changed, 307 insertions, 14 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d8630f0db..21c99d805 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
)
diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp
index 36ecdf0e8..b36d34397 100644
--- a/src/gui/DatabaseManager.cpp
+++ b/src/gui/DatabaseManager.cpp
@@ -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);
diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseManager.h
index aa48b24f9..08b2dd5b0 100644
--- a/src/gui/DatabaseManager.h
+++ b/src/gui/DatabaseManager.h
@@ -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);
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp
index 89a5f6810..0708795d4 100644
--- a/src/gui/DatabaseWidget.cpp
+++ b/src/gui/DatabaseWidget.cpp
@@ -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);
+}
+
diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h
index e9529989c..2218bbed7 100644
--- a/src/gui/DatabaseWidget.h
+++ b/src/gui/DatabaseWidget.h
@@ -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
diff --git a/src/gui/EditEntryWidget.cpp b/src/gui/EditEntryWidget.cpp
index b3c2b8a97..9254c2acb 100644
--- a/src/gui/EditEntryWidget.cpp
+++ b/src/gui/EditEntryWidget.cpp
@@ -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);
}
diff --git a/src/gui/EditEntryWidget.h b/src/gui/EditEntryWidget.h
index e760bfa8e..7a2886d24 100644
--- a/src/gui/EditEntryWidget.h
+++ b/src/gui/EditEntryWidget.h
@@ -42,7 +42,7 @@ public:
void loadEntry(Entry* entry);
Q_SIGNALS:
- void editFinished();
+ void editFinished(bool accepted);
private Q_SLOTS:
void saveEntry();
diff --git a/src/gui/EditGroupWidget.cpp b/src/gui/EditGroupWidget.cpp
new file mode 100644
index 000000000..27a110c42
--- /dev/null
+++ b/src/gui/EditGroupWidget.cpp
@@ -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);
+}
diff --git a/src/gui/EditGroupWidget.h b/src/gui/EditGroupWidget.h
new file mode 100644
index 000000000..1a014eacb
--- /dev/null
+++ b/src/gui/EditGroupWidget.h
@@ -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
diff --git a/src/gui/EditGroupWidget.ui b/src/gui/EditGroupWidget.ui
new file mode 100644
index 000000000..448f07d43
--- /dev/null
+++ b/src/gui/EditGroupWidget.ui
@@ -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>
diff --git a/src/gui/GroupView.cpp b/src/gui/GroupView.cpp
index 46a269108..04599aaba 100644
--- a/src/gui/GroupView.cpp
+++ b/src/gui/GroupView.cpp
@@ -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);
diff --git a/src/gui/GroupView.h b/src/gui/GroupView.h
index 7d6f12492..bf4a0a47f 100644
--- a/src/gui/GroupView.h
+++ b/src/gui/GroupView.h
@@ -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);
diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp
index 550789d3b..d3cdf002f 100644
--- a/src/gui/MainWindow.cpp
+++ b/src/gui/MainWindow.cpp
@@ -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);
}