Remove dependency to Group- and EntryView from MainWindow.

This commit is contained in:
Florian Geyer 2014-05-15 18:05:58 +02:00
parent b718e9d8f2
commit 9363d23e09
6 changed files with 39 additions and 12 deletions

View File

@ -811,3 +811,23 @@ void DatabaseWidget::updateFilename(const QString& fileName)
{ {
m_filename = fileName; m_filename = fileName;
} }
int DatabaseWidget::numberOfSelectedEntries()
{
return m_entryView->numberOfSelectedEntries();
}
QStringList DatabaseWidget::customEntryAttributes()
{
Entry* entry = m_entryView->currentEntry();
if (!entry) {
return QStringList();
}
return entry->attributes()->customKeys();
}
bool DatabaseWidget::isGroupSelected()
{
return m_groupView->currentGroup() != Q_NULLPTR;
}

View File

@ -71,6 +71,9 @@ public:
DatabaseWidget::Mode currentMode(); DatabaseWidget::Mode currentMode();
void lock(); void lock();
void updateFilename(const QString& filename); void updateFilename(const QString& filename);
int numberOfSelectedEntries();
QStringList customEntryAttributes();
bool isGroupSelected();
Q_SIGNALS: Q_SIGNALS:
void closeRequest(); void closeRequest();

View File

@ -23,15 +23,11 @@
#include "autotype/AutoType.h" #include "autotype/AutoType.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/FilePath.h" #include "core/FilePath.h"
#include "core/InactivityTimer.h" #include "core/InactivityTimer.h"
#include "core/Metadata.h" #include "core/Metadata.h"
#include "gui/AboutDialog.h" #include "gui/AboutDialog.h"
#include "gui/DatabaseWidget.h" #include "gui/DatabaseWidget.h"
#include "gui/entry/EntryView.h"
#include "gui/group/GroupView.h"
const QString MainWindow::BaseWindowTitle = "KeePassX"; const QString MainWindow::BaseWindowTitle = "KeePassX";
@ -40,6 +36,8 @@ MainWindow::MainWindow()
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size();
restoreGeometry(config()->get("window/Geometry").toByteArray()); restoreGeometry(config()->get("window/Geometry").toByteArray());
setWindowIcon(filePath()->applicationIcon()); setWindowIcon(filePath()->applicationIcon());
@ -229,17 +227,16 @@ void MainWindow::updateCopyAttributesMenu()
return; return;
} }
Entry* entry = dbWidget->entryView()->currentEntry(); if (!dbWidget->numberOfSelectedEntries() == 1) {
if (!entry || !dbWidget->entryView()->isSingleEntrySelected()) {
return; return;
} }
QList<QAction*> actions = m_ui->menuEntryCopyAttribute->actions(); QList<QAction*> actions = m_ui->menuEntryCopyAttribute->actions();
for (int i = EntryAttributes::DefaultAttributes.size() + 1; i < actions.size(); i++) { for (int i = m_countDefaultAttributes + 1; i < actions.size(); i++) {
delete actions[i]; delete actions[i];
} }
Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { Q_FOREACH (const QString& key, dbWidget->customEntryAttributes()) {
QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); QAction* action = m_ui->menuEntryCopyAttribute->addAction(key);
m_copyAdditionalAttributeActions->addAction(action); m_copyAdditionalAttributeActions->addAction(action);
} }
@ -276,9 +273,9 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
switch (mode) { switch (mode) {
case DatabaseWidget::ViewMode: { case DatabaseWidget::ViewMode: {
bool inSearch = dbWidget->isInSearchMode(); bool inSearch = dbWidget->isInSearchMode();
bool singleEntrySelected = dbWidget->entryView()->isSingleEntrySelected(); bool singleEntrySelected = dbWidget->numberOfSelectedEntries() == 1;
bool entriesSelected = !dbWidget->entryView()->selectionModel()->selectedRows().isEmpty(); bool entriesSelected = dbWidget->numberOfSelectedEntries() > 0;
bool groupSelected = dbWidget->groupView()->currentGroup(); bool groupSelected = dbWidget->isGroupSelected();
m_ui->actionEntryNew->setEnabled(!inSearch); m_ui->actionEntryNew->setEnabled(!inSearch);
m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch);

View File

@ -77,6 +77,7 @@ private:
QActionGroup* m_copyAdditionalAttributeActions; QActionGroup* m_copyAdditionalAttributeActions;
QStringList m_openDatabases; QStringList m_openDatabases;
InactivityTimer* m_inactivityTimer; InactivityTimer* m_inactivityTimer;
int m_countDefaultAttributes;
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
}; };

View File

@ -100,9 +100,14 @@ Entry* EntryView::currentEntry()
} }
} }
int EntryView::numberOfSelectedEntries()
{
return selectionModel()->selectedRows().size();
}
bool EntryView::isSingleEntrySelected() bool EntryView::isSingleEntrySelected()
{ {
return (selectionModel()->selectedRows().size() == 1); return (numberOfSelectedEntries() == 1);
} }
void EntryView::setCurrentEntry(Entry* entry) void EntryView::setCurrentEntry(Entry* entry)

View File

@ -42,6 +42,7 @@ public:
Entry* entryFromIndex(const QModelIndex& index); Entry* entryFromIndex(const QModelIndex& index);
void setEntryList(const QList<Entry*>& entries); void setEntryList(const QList<Entry*>& entries);
bool inEntryListMode(); bool inEntryListMode();
int numberOfSelectedEntries();
public Q_SLOTS: public Q_SLOTS:
void setGroup(Group* group); void setGroup(Group* group);