mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-06 14:07:38 +03:00
Choose database for saving or updating entries from KeePassXC-Browser (#2391)
This commit is contained in:
parent
bb16dc6d01
commit
b8d2d5d877
13 changed files with 307 additions and 22 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "BrowserService.h"
|
||||
#include "BrowserAccessControlDialog.h"
|
||||
#include "BrowserEntryConfig.h"
|
||||
#include "BrowserEntrySaveDialog.h"
|
||||
#include "BrowserSettings.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/EntrySearcher.h"
|
||||
|
@ -289,14 +290,33 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
|
|||
return result;
|
||||
}
|
||||
|
||||
void BrowserService::addEntry(const QString&,
|
||||
void BrowserService::addEntry(const QString& id,
|
||||
const QString& login,
|
||||
const QString& password,
|
||||
const QString& url,
|
||||
const QString& submitUrl,
|
||||
const QString& realm)
|
||||
const QString& realm,
|
||||
Database* selectedDb)
|
||||
{
|
||||
Group* group = findCreateAddEntryGroup();
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this,
|
||||
"addEntry",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const QString&, id),
|
||||
Q_ARG(const QString&, login),
|
||||
Q_ARG(const QString&, password),
|
||||
Q_ARG(const QString&, url),
|
||||
Q_ARG(const QString&, submitUrl),
|
||||
Q_ARG(const QString&, realm),
|
||||
Q_ARG(Database*, selectedDb));
|
||||
}
|
||||
|
||||
Database* db = selectedDb ? selectedDb : selectedDatabase();
|
||||
if (!db) {
|
||||
return;
|
||||
}
|
||||
|
||||
Group* group = findCreateAddEntryGroup(db);
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
@ -328,7 +348,8 @@ void BrowserService::updateEntry(const QString& id,
|
|||
const QString& uuid,
|
||||
const QString& login,
|
||||
const QString& password,
|
||||
const QString& url)
|
||||
const QString& url,
|
||||
const QString& submitUrl)
|
||||
{
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this,
|
||||
|
@ -338,16 +359,19 @@ void BrowserService::updateEntry(const QString& id,
|
|||
Q_ARG(const QString&, uuid),
|
||||
Q_ARG(const QString&, login),
|
||||
Q_ARG(const QString&, password),
|
||||
Q_ARG(const QString&, url));
|
||||
Q_ARG(const QString&, url),
|
||||
Q_ARG(const QString&, submitUrl));
|
||||
}
|
||||
|
||||
Database* db = getDatabase();
|
||||
Database* db = selectedDatabase();
|
||||
if (!db) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entry* entry = db->resolveEntry(QUuid::fromRfc4122(QByteArray::fromHex(uuid.toLatin1())));
|
||||
if (!entry) {
|
||||
// If entry is not found for update, add a new one to the selected database
|
||||
addEntry(id, login, password, url, submitUrl, "", db);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -679,9 +703,9 @@ BrowserService::checkAccess(const Entry* entry, const QString& host, const QStri
|
|||
return Unknown;
|
||||
}
|
||||
|
||||
Group* BrowserService::findCreateAddEntryGroup()
|
||||
Group* BrowserService::findCreateAddEntryGroup(Database* selectedDb)
|
||||
{
|
||||
Database* db = getDatabase();
|
||||
Database* db = selectedDb ? selectedDb : getDatabase();
|
||||
if (!db) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -813,6 +837,42 @@ Database* BrowserService::getDatabase()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Database* BrowserService::selectedDatabase()
|
||||
{
|
||||
QList<DatabaseWidget*> databaseWidgets;
|
||||
for (int i = 0;; ++i) {
|
||||
const auto dbStruct = m_dbTabWidget->indexDatabaseManagerStruct(i);
|
||||
// Add only open databases
|
||||
if (dbStruct.dbWidget && dbStruct.dbWidget->dbHasKey() &&
|
||||
(dbStruct.dbWidget->currentMode() == DatabaseWidget::ViewMode ||
|
||||
dbStruct.dbWidget->currentMode() == DatabaseWidget::EditMode)) {
|
||||
databaseWidgets.push_back(dbStruct.dbWidget);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Break out if dbStruct.dbWidget is nullptr
|
||||
break;
|
||||
}
|
||||
|
||||
BrowserEntrySaveDialog browserEntrySaveDialog;
|
||||
int openDatabaseCount = browserEntrySaveDialog.setItems(databaseWidgets, m_dbTabWidget->currentDatabaseWidget());
|
||||
if (openDatabaseCount > 1) {
|
||||
int res = browserEntrySaveDialog.exec();
|
||||
if (res == QDialog::Accepted) {
|
||||
const auto selectedDatabase = browserEntrySaveDialog.getSelected();
|
||||
if (selectedDatabase.length() > 0) {
|
||||
int index = selectedDatabase[0]->data(Qt::UserRole).toUInt();
|
||||
return databaseWidgets[index]->database();
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Return current database
|
||||
return getDatabase();
|
||||
}
|
||||
|
||||
void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
|
||||
{
|
||||
if (dbWidget) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue