Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting group icons to children groups/entries #3273

Merged
merged 4 commits into from Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,10 @@ Entry* Group::addEntryWithPath(const QString& entryPath)
return entry;
}

void Group::applyGroupIconTo(Entry* entry)
void Group::applyGroupIconOnCreateTo(Entry* entry)
{
Q_ASSERT(entry);

if (!config()->get("UseGroupIconOnEntryCreation").toBool()) {
return;
}
Expand All @@ -1090,13 +1092,45 @@ void Group::applyGroupIconTo(Entry* entry)
return;
}

applyGroupIconTo(entry);
}

void Group::applyGroupIconTo(Entry* entry)
{
Q_ASSERT(entry);

if (iconUuid().isNull()) {
entry->setIcon(iconNumber());
} else {
entry->setIcon(iconUuid());
}
}

void Group::applyGroupIconTo(Group* other)
{
Q_ASSERT(other);

if (iconUuid().isNull()) {
other->setIcon(iconNumber());
} else {
other->setIcon(iconUuid());
}
}

void Group::applyGroupIconToChildGroups()
{
for (Group* recursiveChild : groupsRecursive(false)) {
applyGroupIconTo(recursiveChild);
}
}

void Group::applyGroupIconToChildEntries()
{
for (Entry* recursiveEntry : entriesRecursive(false)) {
applyGroupIconTo(recursiveEntry);
}
}

void Group::sortChildrenRecursively(bool reverse)
{
std::sort(
Expand Down
4 changes: 4 additions & 0 deletions src/core/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ class Group : public QObject
void addEntry(Entry* entry);
void removeEntry(Entry* entry);

void applyGroupIconOnCreateTo(Entry* entry);
void applyGroupIconTo(Entry* entry);
void applyGroupIconTo(Group* other);
void applyGroupIconToChildGroups();
void applyGroupIconToChildEntries();

void sortChildrenRecursively(bool reverse = false);

Expand Down
2 changes: 1 addition & 1 deletion src/fdosecrets/objects/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ namespace FdoSecrets
entry->setUuid(QUuid::createUuid());
entry->setTitle(itemName);
entry->setUsername(m_backend->database()->metadata()->defaultUserName());
group->applyGroupIconTo(entry);
group->applyGroupIconOnCreateTo(entry);

entry->setGroup(group);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void DatabaseWidget::createEntry()
m_newEntry->setUuid(QUuid::createUuid());
m_newEntry->setUsername(m_db->metadata()->defaultUserName());
m_newParent = m_groupView->currentGroup();
m_newParent->applyGroupIconTo(m_newEntry.data());
m_newParent->applyGroupIconOnCreateTo(m_newEntry.data());
switchToEntryEdit(m_newEntry.data(), true);
}

Expand Down
36 changes: 36 additions & 0 deletions src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ EditWidgetIcons::EditWidgetIcons(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::EditWidgetIcons())
, m_db(nullptr)
, m_applyIconTo(ApplyIconToOptions::THIS_ONLY)
#ifdef WITH_XC_NETWORKING
, m_netMgr(new QNetworkAccessManager(this))
, m_reply(nullptr)
Expand All @@ -57,6 +58,8 @@ EditWidgetIcons::EditWidgetIcons(QWidget* parent)
m_ui->defaultIconsView->setModel(m_defaultIconModel);
m_ui->customIconsView->setModel(m_customIconModel);

m_ui->applyIconToPushButton->setMenu(createApplyIconToMenu());

// clang-format off
connect(m_ui->defaultIconsView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateRadioButtonDefaultIcons()));
connect(m_ui->customIconsView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateRadioButtonCustomIcons()));
Expand All @@ -65,6 +68,7 @@ EditWidgetIcons::EditWidgetIcons(QWidget* parent)
connect(m_ui->addButton, SIGNAL(clicked()), SLOT(addCustomIconFromFile()));
connect(m_ui->deleteButton, SIGNAL(clicked()), SLOT(removeCustomIcon()));
connect(m_ui->faviconButton, SIGNAL(clicked()), SLOT(downloadFavicon()));
connect(m_ui->applyIconToPushButton->menu(), SIGNAL(triggered(QAction*)), SLOT(confirmApplyIconTo(QAction*)));

connect(m_ui->defaultIconsRadio, SIGNAL(toggled(bool)), this, SIGNAL(widgetUpdated()));
connect(m_ui->defaultIconsView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
Expand Down Expand Up @@ -103,6 +107,8 @@ IconStruct EditWidgetIcons::state()
}
}

iconStruct.applyTo = m_applyIconTo;

return iconStruct;
}

Expand Down Expand Up @@ -142,6 +148,30 @@ void EditWidgetIcons::load(const QUuid& currentUuid,
m_ui->defaultIconsRadio->setChecked(true);
}
}

m_applyIconTo = ApplyIconToOptions::THIS_ONLY;
m_ui->applyIconToPushButton->menu()->defaultAction()->activate(QAction::Trigger);
}

void EditWidgetIcons::setShowApplyIconToButton(bool state)
{
m_ui->applyIconToPushButton->setVisible(state);
}

QMenu* EditWidgetIcons::createApplyIconToMenu()
{
auto* applyIconToMenu = new QMenu(this);
QAction* defaultAction = applyIconToMenu->addAction(tr("Apply to this only"));
defaultAction->setData(QVariant::fromValue(ApplyIconToOptions::THIS_ONLY));
applyIconToMenu->setDefaultAction(defaultAction);
applyIconToMenu->addSeparator();
applyIconToMenu->addAction(tr("Also apply to child groups"))
->setData(QVariant::fromValue(ApplyIconToOptions::CHILD_GROUPS));
applyIconToMenu->addAction(tr("Also apply to child entries"))
->setData(QVariant::fromValue(ApplyIconToOptions::CHILD_ENTRIES));
applyIconToMenu->addAction(tr("Also apply to all children"))
->setData(QVariant::fromValue(ApplyIconToOptions::ALL_CHILDREN));
return applyIconToMenu;
}

void EditWidgetIcons::setUrl(const QString& url)
Expand Down Expand Up @@ -528,3 +558,9 @@ void EditWidgetIcons::updateRadioButtonCustomIcons()
{
m_ui->customIconsRadio->setChecked(true);
}

void EditWidgetIcons::confirmApplyIconTo(QAction* action)
{
m_applyIconTo = action->data().value<ApplyIconToOptions>();
m_ui->applyIconToPushButton->setText(action->text());
}
17 changes: 17 additions & 0 deletions src/gui/EditWidgetIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef KEEPASSX_EDITWIDGETICONS_H
#define KEEPASSX_EDITWIDGETICONS_H

#include <QMenu>
#include <QUrl>
#include <QUuid>
#include <QWidget>
Expand All @@ -40,12 +41,23 @@ namespace Ui
class EditWidgetIcons;
}

enum ApplyIconToOptions
{
THIS_ONLY = 0b00,
CHILD_GROUPS = 0b10,
CHILD_ENTRIES = 0b01,
ALL_CHILDREN = 0b11
};

Q_DECLARE_METATYPE(ApplyIconToOptions)

struct IconStruct
{
IconStruct();

QUuid uuid;
int number;
ApplyIconToOptions applyTo;
};

class EditWidgetIcons : public QWidget
Expand All @@ -62,6 +74,7 @@ class EditWidgetIcons : public QWidget
const QSharedPointer<Database>& database,
const IconStruct& iconStruct,
const QString& url = "");
void setShowApplyIconToButton(bool state);

public slots:
void setUrl(const QString& url);
Expand All @@ -84,11 +97,15 @@ private slots:
void updateWidgetsCustomIcons(bool checked);
void updateRadioButtonDefaultIcons();
void updateRadioButtonCustomIcons();
void confirmApplyIconTo(QAction* action);

private:
QMenu* createApplyIconToMenu();

const QScopedPointer<Ui::EditWidgetIcons> m_ui;
QSharedPointer<Database> m_db;
QUuid m_currentUuid;
ApplyIconToOptions m_applyIconTo;
#ifdef WITH_XC_NETWORKING
QUrl m_url;
QUrl m_fetchUrl;
Expand Down
36 changes: 35 additions & 1 deletion src/gui/EditWidgetIcons.ui
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="customIconButtonsHorizontalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
Expand All @@ -112,6 +112,39 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="applyToChildrenHorizontalLayout" stretch="0,0">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="applyIconToPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">padding: 4px 10px</string>
</property>
<property name="text">
<string>Apply icon &amp;to ...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
Expand All @@ -121,6 +154,7 @@
<tabstop>customIconsView</tabstop>
<tabstop>addButton</tabstop>
<tabstop>deleteButton</tabstop>
<tabstop>applyIconToPushButton</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
1 change: 1 addition & 0 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void EditEntryWidget::setupAdvanced()

void EditEntryWidget::setupIcon()
{
m_iconsWidget->setShowApplyIconToButton(false);
addPage(tr("Icon"), FilePath::instance()->icon("apps", "preferences-desktop-icons"), m_iconsWidget);
connect(this, SIGNAL(accepted()), m_iconsWidget, SLOT(abortRequests()));
connect(this, SIGNAL(rejected()), m_iconsWidget, SLOT(abortRequests()));
Expand Down
11 changes: 11 additions & 0 deletions src/gui/group/EditGroupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ void EditGroupWidget::apply()
// Icons add/remove are applied globally outside the transaction!
m_group->copyDataFrom(m_temporaryGroup.data());

// Assign the icon to children if selected
if (iconStruct.applyTo == ApplyIconToOptions::CHILD_GROUPS
|| iconStruct.applyTo == ApplyIconToOptions::ALL_CHILDREN) {
m_group->applyGroupIconToChildGroups();
}

if (iconStruct.applyTo == ApplyIconToOptions::CHILD_ENTRIES
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
|| iconStruct.applyTo == ApplyIconToOptions::ALL_CHILDREN) {
m_group->applyGroupIconToChildEntries();
}

setModified(false);
}

Expand Down
Loading