mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-27 00:35:27 -04:00
Allow creating new groups with Browser Integration
Added a confirmation dialog
This commit is contained in:
parent
84f5adb24a
commit
14e868d2f7
4 changed files with 122 additions and 5 deletions
|
@ -150,7 +150,7 @@ QString BrowserService::getDatabaseRecycleBinUuid()
|
|||
return recycleBin->uuidToHex();
|
||||
}
|
||||
|
||||
QJsonArray BrowserService::addChildrenToGroup(Group* group)
|
||||
QJsonArray BrowserService::getChildrenFromGroup(Group* group)
|
||||
{
|
||||
QJsonArray groupList;
|
||||
|
||||
|
@ -166,7 +166,7 @@ QJsonArray BrowserService::addChildrenToGroup(Group* group)
|
|||
QJsonObject jsonGroup;
|
||||
jsonGroup["name"] = c->name();
|
||||
jsonGroup["uuid"] = Tools::uuidToHex(c->uuid());
|
||||
jsonGroup["children"] = addChildrenToGroup(c);
|
||||
jsonGroup["children"] = getChildrenFromGroup(c);
|
||||
groupList.push_back(jsonGroup);
|
||||
}
|
||||
return groupList;
|
||||
|
@ -187,7 +187,7 @@ QJsonObject BrowserService::getDatabaseGroups()
|
|||
QJsonObject root;
|
||||
root["name"] = rootGroup->name();
|
||||
root["uuid"] = Tools::uuidToHex(rootGroup->uuid());
|
||||
root["children"] = addChildrenToGroup(rootGroup);
|
||||
root["children"] = getChildrenFromGroup(rootGroup);
|
||||
|
||||
QJsonArray groups;
|
||||
groups.push_back(root);
|
||||
|
@ -198,6 +198,80 @@ QJsonObject BrowserService::getDatabaseGroups()
|
|||
return result;
|
||||
}
|
||||
|
||||
QJsonObject BrowserService::createNewGroup(const QString& groupName)
|
||||
{
|
||||
QJsonObject result;
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this, "createNewGroup", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QJsonObject, result), Q_ARG(QString, groupName));
|
||||
return result;
|
||||
}
|
||||
|
||||
auto db = getDatabase();
|
||||
if (!db) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Group* rootGroup = db->rootGroup();
|
||||
if (!rootGroup) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto group = rootGroup->findGroupByPath(groupName);
|
||||
|
||||
// Group already exists
|
||||
if (group) {
|
||||
result["name"] = group->name();
|
||||
result["uuid"] = Tools::uuidToHex(group->uuid());
|
||||
return result;
|
||||
}
|
||||
|
||||
auto dialogResult = MessageBox::warning(nullptr,
|
||||
tr("KeePassXC: Create a new group"),
|
||||
tr("A request for creating a new group \"%1\" has been received.\n"
|
||||
"Do you want to create this group?\n").arg(groupName),
|
||||
MessageBox::Yes | MessageBox::No);
|
||||
|
||||
if (dialogResult != MessageBox::Yes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
QString name, uuid;
|
||||
Group* previousGroup = rootGroup;
|
||||
auto groups = groupName.split("/");
|
||||
|
||||
// Returns the group name based on depth
|
||||
auto getGroupName = [&](int depth) {
|
||||
QString gName;
|
||||
for (int i = 0; i < depth+1; ++i) {
|
||||
gName.append((i == 0 ? "" : "/") + groups[i]);
|
||||
}
|
||||
return gName;
|
||||
};
|
||||
|
||||
// Create new group(s) always when the path is not found
|
||||
for (int i = 0; i < groups.length(); ++i) {
|
||||
QString gName = getGroupName(i);
|
||||
auto tempGroup = rootGroup->findGroupByPath(gName);
|
||||
if (!tempGroup) {
|
||||
Group* newGroup = new Group();
|
||||
newGroup->setName(groups[i]);
|
||||
newGroup->setUuid(QUuid::createUuid());
|
||||
newGroup->setParent(previousGroup);
|
||||
name = newGroup->name();
|
||||
uuid = Tools::uuidToHex(newGroup->uuid());
|
||||
previousGroup = newGroup;
|
||||
continue;
|
||||
}
|
||||
|
||||
previousGroup = tempGroup;
|
||||
}
|
||||
|
||||
result["name"] = name;
|
||||
result["uuid"] = uuid;
|
||||
return result;
|
||||
}
|
||||
|
||||
QString BrowserService::storeKey(const QString& key)
|
||||
{
|
||||
QString id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue