From 771a0417506802f609251cce8ca51b998d402887 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 29 Oct 2012 22:41:37 +0100 Subject: [PATCH] Refactor EditWidgetProperties. --- src/CMakeLists.txt | 2 ++ src/gui/EditWidgetProperties.cpp | 42 +++++++++++++++++++++++++++ src/gui/EditWidgetProperties.h | 47 +++++++++++++++++++++++++++++++ src/gui/entry/EditEntryWidget.cpp | 16 +++-------- src/gui/entry/EditEntryWidget.h | 5 ++-- src/gui/group/EditGroupWidget.cpp | 16 +++-------- src/gui/group/EditGroupWidget.h | 5 ++-- 7 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 src/gui/EditWidgetProperties.cpp create mode 100644 src/gui/EditWidgetProperties.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6c98904e6..5b36850b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,6 +75,7 @@ set(keepassx_SOURCES gui/DragTabBar.cpp gui/EditWidget.cpp gui/EditWidgetIcons.cpp + gui/EditWidgetProperties.cpp gui/FileDialog.cpp gui/IconModels.cpp gui/KeePass1OpenWidget.cpp @@ -136,6 +137,7 @@ set(keepassx_MOC gui/DragTabBar.h gui/EditWidget.h gui/EditWidgetIcons.h + gui/EditWidgetProperties.h gui/IconModels.h gui/KeePass1OpenWidget.h gui/LineEdit.h diff --git a/src/gui/EditWidgetProperties.cpp b/src/gui/EditWidgetProperties.cpp new file mode 100644 index 000000000..a278d6cb3 --- /dev/null +++ b/src/gui/EditWidgetProperties.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012 Felix Geyer + * + * 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 . + */ + +#include "EditWidgetProperties.h" +#include "ui_EditWidgetProperties.h" + +EditWidgetProperties::EditWidgetProperties(QWidget* parent) + : QWidget(parent) + , m_ui(new Ui::EditWidgetProperties()) +{ + m_ui->setupUi(this); +} + +EditWidgetProperties::~EditWidgetProperties() +{ +} + +void EditWidgetProperties::setFields(TimeInfo timeInfo, Uuid uuid) +{ + QString timeFormat("d MMM yyyy HH:mm:ss"); + m_ui->modifiedEdit->setText( + timeInfo.lastModificationTime().toLocalTime().toString(timeFormat)); + m_ui->createdEdit->setText( + timeInfo.creationTime().toLocalTime().toString(timeFormat)); + m_ui->accessedEdit->setText( + timeInfo.lastAccessTime().toLocalTime().toString(timeFormat)); + m_ui->uuidEdit->setText(uuid.toHex()); +} diff --git a/src/gui/EditWidgetProperties.h b/src/gui/EditWidgetProperties.h new file mode 100644 index 000000000..e9a253049 --- /dev/null +++ b/src/gui/EditWidgetProperties.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2012 Felix Geyer + * + * 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 . + */ + +#ifndef KEEPASSX_EDITWIDGETPROPERTIES_H +#define KEEPASSX_EDITWIDGETPROPERTIES_H + +#include + +#include "core/Global.h" +#include "core/TimeInfo.h" +#include "core/Uuid.h" + +namespace Ui { + class EditWidgetProperties; +} + +class EditWidgetProperties : public QWidget +{ + Q_OBJECT + +public: + explicit EditWidgetProperties(QWidget* parent = Q_NULLPTR); + ~EditWidgetProperties(); + + void setFields(TimeInfo timeInfo, Uuid uuid); + +private: + const QScopedPointer m_ui; + + Q_DISABLE_COPY(EditWidgetProperties) +}; + +#endif // KEEPASSX_EDITWIDGETPROPERTIES_H diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 8112de1eb..9e4765c09 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -37,6 +37,7 @@ #include "core/TimeDelta.h" #include "core/Tools.h" #include "gui/EditWidgetIcons.h" +#include "gui/EditWidgetProperties.h" #include "gui/FileDialog.h" #include "gui/entry/AutoTypeAssociationsModel.h" #include "gui/entry/EntryAttachmentsModel.h" @@ -51,14 +52,13 @@ EditEntryWidget::EditEntryWidget(QWidget* parent) , m_advancedUi(new Ui::EditEntryWidgetAdvanced()) , m_autoTypeUi(new Ui::EditEntryWidgetAutoType()) , m_historyUi(new Ui::EditEntryWidgetHistory()) - , m_propertiesUi(new Ui::EditWidgetProperties()) , m_mainWidget(new QWidget()) , m_notesWidget(new QWidget()) , m_advancedWidget(new QWidget()) , m_iconsWidget(new EditWidgetIcons()) , m_autoTypeWidget(new QWidget()) + , m_editWidgetProperties(new EditWidgetProperties()) , m_historyWidget(new QWidget()) - , m_editWidgetProperties(new QWidget()) , m_entryAttachments(new EntryAttachments(this)) , m_attachmentsModel(new EntryAttachmentsModel(m_advancedWidget)) , m_entryAttributes(new EntryAttributes(this)) @@ -84,7 +84,6 @@ EditEntryWidget::EditEntryWidget(QWidget* parent) m_autoTypeUi->setupUi(m_autoTypeWidget); add(tr("Auto-Type"), m_autoTypeWidget); - m_propertiesUi->setupUi(m_editWidgetProperties); add(tr("Properties"), m_editWidgetProperties); // when adding a new row, update setRowHidden() call @@ -339,6 +338,8 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) } updateAutoTypeEnabled(); + m_editWidgetProperties->setFields(entry->timeInfo(), entry->uuid()); + if (!m_history && !restore) { m_historyModel->setEntries(entry->historyItems()); m_historyUi->historyView->sortByColumn(0, Qt::DescendingOrder); @@ -352,15 +353,6 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) updateHistoryButtons(m_historyUi->historyView->currentIndex(), QModelIndex()); - QString timeFormat("d MMM yyyy HH:mm:ss"); - m_propertiesUi->modifiedEdit->setText( - entry->timeInfo().lastModificationTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->createdEdit->setText( - entry->timeInfo().creationTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->accessedEdit->setText( - entry->timeInfo().lastAccessTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->uuidEdit->setText(entry->uuid().toHex()); - m_mainUi->titleEdit->setFocus(); } diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index 854871cba..5a5607eab 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -27,6 +27,7 @@ class AutoTypeAssociations; class AutoTypeAssociationsModel; class Database; class EditWidgetIcons; +class EditWidgetProperties; class Entry; class EntryAttachments; class EntryAttachmentsModel; @@ -44,7 +45,6 @@ namespace Ui { class EditEntryWidgetMain; class EditEntryWidgetHistory; class EditEntryWidgetNotes; - class EditWidgetProperties; class EditWidget; } @@ -110,14 +110,13 @@ private: const QScopedPointer m_advancedUi; const QScopedPointer m_autoTypeUi; const QScopedPointer m_historyUi; - const QScopedPointer m_propertiesUi; QWidget* const m_mainWidget; QWidget* const m_notesWidget; QWidget* const m_advancedWidget; EditWidgetIcons* const m_iconsWidget; QWidget* const m_autoTypeWidget; + EditWidgetProperties* const m_editWidgetProperties; QWidget* const m_historyWidget; - QWidget* const m_editWidgetProperties; EntryAttachments* const m_entryAttachments; EntryAttachmentsModel* const m_attachmentsModel; EntryAttributes* const m_entryAttributes; diff --git a/src/gui/group/EditGroupWidget.cpp b/src/gui/group/EditGroupWidget.cpp index 0b2dc5428..1d068195b 100644 --- a/src/gui/group/EditGroupWidget.cpp +++ b/src/gui/group/EditGroupWidget.cpp @@ -17,23 +17,21 @@ #include "EditGroupWidget.h" #include "ui_EditGroupWidgetMain.h" -#include "ui_EditWidgetProperties.h" #include "ui_EditWidget.h" #include "core/Metadata.h" #include "gui/EditWidgetIcons.h" +#include "gui/EditWidgetProperties.h" EditGroupWidget::EditGroupWidget(QWidget* parent) : EditWidget(parent) , m_mainUi(new Ui::EditGroupWidgetMain()) - , m_propertiesUi(new Ui::EditWidgetProperties()) , m_editGroupWidgetMain(new QWidget()) , m_editGroupWidgetIcons(new EditWidgetIcons()) - , m_editWidgetProperties(new QWidget()) + , m_editWidgetProperties(new EditWidgetProperties()) , m_group(Q_NULLPTR) { m_mainUi->setupUi(m_editGroupWidgetMain); - m_propertiesUi->setupUi(m_editWidgetProperties); add(tr("Group"), m_editGroupWidgetMain); add(tr("Icon"), m_editGroupWidgetIcons); @@ -68,14 +66,6 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database) m_mainUi->editNotes->setPlainText(m_group->notes()); m_mainUi->expireCheck->setChecked(group->timeInfo().expires()); m_mainUi->expireDatePicker->setDateTime(group->timeInfo().expiryTime().toLocalTime()); - QString timeFormat("d MMM yyyy HH:mm:ss"); - m_propertiesUi->modifiedEdit->setText( - group->timeInfo().lastModificationTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->createdEdit->setText( - group->timeInfo().creationTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->accessedEdit->setText( - group->timeInfo().lastAccessTime().toLocalTime().toString(timeFormat)); - m_propertiesUi->uuidEdit->setText(group->uuid().toHex()); m_mainUi->searchComboBox->setCurrentIndex(indexFromTriState(group->searchingEnabled())); m_mainUi->autotypeComboBox->setCurrentIndex(indexFromTriState(group->autoTypeEnabled())); @@ -84,6 +74,8 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database) iconStruct.number = group->iconNumber(); m_editGroupWidgetIcons->load(group->uuid(), database, iconStruct); + m_editWidgetProperties->setFields(group->timeInfo(), group->uuid()); + setCurrentRow(0); m_mainUi->editName->setFocus(); diff --git a/src/gui/group/EditGroupWidget.h b/src/gui/group/EditGroupWidget.h index eb92d733c..454b2fb5c 100644 --- a/src/gui/group/EditGroupWidget.h +++ b/src/gui/group/EditGroupWidget.h @@ -25,10 +25,10 @@ #include "gui/EditWidget.h" class EditWidgetIcons; +class EditWidgetProperties; namespace Ui { class EditGroupWidgetMain; - class EditWidgetProperties; class EditWidget; } @@ -55,10 +55,9 @@ private: Group::TriState triStateFromIndex(int index); const QScopedPointer m_mainUi; - const QScopedPointer m_propertiesUi; QWidget* const m_editGroupWidgetMain; EditWidgetIcons* const m_editGroupWidgetIcons; - QWidget* const m_editWidgetProperties; + EditWidgetProperties* const m_editWidgetProperties; Group* m_group; Database* m_database;