Hard code copy action for default attributes.

This commit is contained in:
Florian Geyer 2013-12-01 09:43:41 +01:00
parent 3e4811791a
commit 4a3da3abe7
7 changed files with 113 additions and 26 deletions

View file

@ -185,27 +185,27 @@ const AutoTypeAssociations* Entry::autoTypeAssociations() const
QString Entry::title() const QString Entry::title() const
{ {
return m_attributes->value("Title"); return m_attributes->value(EntryAttributes::TitleKey);
} }
QString Entry::url() const QString Entry::url() const
{ {
return m_attributes->value("URL"); return m_attributes->value(EntryAttributes::URLNameKey);
} }
QString Entry::username() const QString Entry::username() const
{ {
return m_attributes->value("UserName"); return m_attributes->value(EntryAttributes::UserNameKey);
} }
QString Entry::password() const QString Entry::password() const
{ {
return m_attributes->value("Password"); return m_attributes->value(EntryAttributes::PasswordKey);
} }
QString Entry::notes() const QString Entry::notes() const
{ {
return m_attributes->value("Notes"); return m_attributes->value(EntryAttributes::NotesKey);
} }
bool Entry::isExpired() const bool Entry::isExpired() const
@ -311,27 +311,27 @@ void Entry::setDefaultAutoTypeSequence(const QString& sequence)
void Entry::setTitle(const QString& title) void Entry::setTitle(const QString& title)
{ {
m_attributes->set("Title", title, m_attributes->isProtected("Title")); m_attributes->set(EntryAttributes::TitleKey, title, m_attributes->isProtected(EntryAttributes::TitleKey));
} }
void Entry::setUrl(const QString& url) void Entry::setUrl(const QString& url)
{ {
m_attributes->set("URL", url, m_attributes->isProtected("URL")); m_attributes->set(EntryAttributes::URLNameKey, url, m_attributes->isProtected(EntryAttributes::URLNameKey));
} }
void Entry::setUsername(const QString& username) void Entry::setUsername(const QString& username)
{ {
m_attributes->set("UserName", username, m_attributes->isProtected("UserName")); m_attributes->set(EntryAttributes::UserNameKey, username, m_attributes->isProtected(EntryAttributes::UserNameKey));
} }
void Entry::setPassword(const QString& password) void Entry::setPassword(const QString& password)
{ {
m_attributes->set("Password", password, m_attributes->isProtected("Password")); m_attributes->set(EntryAttributes::PasswordKey, password, m_attributes->isProtected(EntryAttributes::PasswordKey));
} }
void Entry::setNotes(const QString& notes) void Entry::setNotes(const QString& notes)
{ {
m_attributes->set("Notes", notes, m_attributes->isProtected("Notes")); m_attributes->set(EntryAttributes::NotesKey, notes, m_attributes->isProtected(EntryAttributes::NotesKey));
} }
void Entry::setExpires(const bool& value) void Entry::setExpires(const bool& value)

View file

@ -17,10 +17,13 @@
#include "EntryAttributes.h" #include "EntryAttributes.h"
const QString EntryAttributes::TitleKey = "Title";
const QString EntryAttributes::UserNameKey = "UserName"; const QString EntryAttributes::UserNameKey = "UserName";
const QString EntryAttributes::PasswordKey = "Password"; const QString EntryAttributes::PasswordKey = "Password";
const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << UserNameKey const QString EntryAttributes::URLNameKey = "URL";
<< PasswordKey << "URL" << "Notes"); const QString EntryAttributes::NotesKey = "Notes";
const QStringList EntryAttributes::DefaultAttributes(QStringList() << TitleKey << UserNameKey
<< PasswordKey << URLNameKey << NotesKey);
EntryAttributes::EntryAttributes(QObject* parent) EntryAttributes::EntryAttributes(QObject* parent)
: QObject(parent) : QObject(parent)

View file

@ -46,8 +46,11 @@ public:
bool operator==(const EntryAttributes& other) const; bool operator==(const EntryAttributes& other) const;
bool operator!=(const EntryAttributes& other) const; bool operator!=(const EntryAttributes& other) const;
static const QString TitleKey;
static const QString UserNameKey; static const QString UserNameKey;
static const QString PasswordKey; static const QString PasswordKey;
static const QString URLNameKey;
static const QString NotesKey;
static const QStringList DefaultAttributes; static const QStringList DefaultAttributes;
static bool isDefaultAttribute(const QString& key); static bool isDefaultAttribute(const QString& key);

View file

@ -288,6 +288,21 @@ void DatabaseWidget::deleteEntries()
} }
} }
void DatabaseWidget::copyTitle()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
clipboard()->setText(currentEntry->title());
if (config()->get("MinimizeOnCopy").toBool()) {
window()->showMinimized();
}
}
void DatabaseWidget::copyUsername() void DatabaseWidget::copyUsername()
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();
@ -318,6 +333,36 @@ void DatabaseWidget::copyPassword()
} }
} }
void DatabaseWidget::copyURL()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
clipboard()->setText(currentEntry->url());
if (config()->get("MinimizeOnCopy").toBool()) {
window()->showMinimized();
}
}
void DatabaseWidget::copyNotes()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
clipboard()->setText(currentEntry->notes());
if (config()->get("MinimizeOnCopy").toBool()) {
window()->showMinimized();
}
}
void DatabaseWidget::copyAttribute(QAction* action) void DatabaseWidget::copyAttribute(QAction* action)
{ {
Entry* currentEntry = m_entryView->currentEntry(); Entry* currentEntry = m_entryView->currentEntry();

View file

@ -86,8 +86,11 @@ public Q_SLOTS:
void createEntry(); void createEntry();
void cloneEntry(); void cloneEntry();
void deleteEntries(); void deleteEntries();
void copyTitle();
void copyUsername(); void copyUsername();
void copyPassword(); void copyPassword();
void copyURL();
void copyNotes();
void copyAttribute(QAction* action); void copyAttribute(QAction* action);
void performAutoType(); void performAutoType();
void openUrl(); void openUrl();

View file

@ -163,10 +163,17 @@ MainWindow::MainWindow()
SLOT(switchToEntryEdit())); SLOT(switchToEntryEdit()));
m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()),
SLOT(deleteEntries())); SLOT(deleteEntries()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyTitle, SIGNAL(triggered()),
SLOT(copyTitle()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()),
SLOT(copyUsername())); SLOT(copyUsername()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()),
SLOT(copyPassword())); SLOT(copyPassword()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyURL, SIGNAL(triggered()),
SLOT(copyURL()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyNotes, SIGNAL(triggered()),
SLOT(copyNotes()));
m_actionMultiplexer.connect(m_ui->actionEntryAutoType, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryAutoType, SIGNAL(triggered()),
SLOT(performAutoType())); SLOT(performAutoType()));
m_actionMultiplexer.connect(m_ui->actionEntryOpenUrl, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryOpenUrl, SIGNAL(triggered()),
@ -214,24 +221,20 @@ void MainWindow::updateCopyAttributesMenu()
return; return;
} }
Q_FOREACH (QAction* action, m_ui->menuEntryCopyAttribute->actions()) { QList<QAction*> actionsToRemove = m_ui->menuEntryCopyAttribute->actions();
if (action != m_ui->actionEntryCopyPassword && action != m_ui->actionEntryCopyUsername) { actionsToRemove.removeOne(m_ui->actionEntryCopyTitle);
actionsToRemove.removeOne(m_ui->actionEntryCopyUsername);
actionsToRemove.removeOne(m_ui->actionEntryCopyPassword);
actionsToRemove.removeOne(m_ui->actionEntryCopyURL);
actionsToRemove.removeOne(m_ui->actionEntryCopyNotes);
Q_FOREACH (QAction* action, actionsToRemove) {
m_ui->menuEntryCopyAttribute->removeAction(action); m_ui->menuEntryCopyAttribute->removeAction(action);
delete action; delete action;
} }
}
Entry* entry = dbWidget->entryView()->currentEntry(); Entry* entry = dbWidget->entryView()->currentEntry();
QStringList defaultAttributesWithoutPasswordAndUsername = EntryAttributes::DefaultAttributes;
defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::PasswordKey);
defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::UserNameKey);
Q_FOREACH (const QString& key, defaultAttributesWithoutPasswordAndUsername) {
QAction* action = m_ui->menuEntryCopyAttribute->addAction(key);
m_copyAdditionalAttributeActions->addAction(action);
}
m_ui->menuEntryCopyAttribute->addSeparator(); m_ui->menuEntryCopyAttribute->addSeparator();
Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { Q_FOREACH (const QString& key, entry->attributes()->customKeys()) {
@ -279,8 +282,11 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch);
m_ui->actionEntryEdit->setEnabled(singleEntrySelected); m_ui->actionEntryEdit->setEnabled(singleEntrySelected);
m_ui->actionEntryDelete->setEnabled(entriesSelected); m_ui->actionEntryDelete->setEnabled(entriesSelected);
m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected);
m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected); m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected);
m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected); m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected);
m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected);
m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected);
m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected); m_ui->actionEntryAutoType->setEnabled(singleEntrySelected);
m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected); m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected);

View file

@ -114,8 +114,11 @@
<property name="title"> <property name="title">
<string>Copy attribute to clipboard</string> <string>Copy attribute to clipboard</string>
</property> </property>
<addaction name="actionEntryCopyTitle"/>
<addaction name="actionEntryCopyUsername"/> <addaction name="actionEntryCopyUsername"/>
<addaction name="actionEntryCopyPassword"/> <addaction name="actionEntryCopyPassword"/>
<addaction name="actionEntryCopyURL"/>
<addaction name="actionEntryCopyNotes"/>
</widget> </widget>
<addaction name="actionEntryNew"/> <addaction name="actionEntryNew"/>
<addaction name="actionEntryClone"/> <addaction name="actionEntryClone"/>
@ -346,6 +349,30 @@
<string>Lock databases</string> <string>Lock databases</string>
</property> </property>
</action> </action>
<action name="actionEntryCopyTitle">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Title</string>
</property>
</action>
<action name="actionEntryCopyURL">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>URL</string>
</property>
</action>
<action name="actionEntryCopyNotes">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Notes</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>