Merge branch 'release/2.6.2' into develop

This commit is contained in:
Jonathan White 2020-10-07 11:27:14 -04:00
commit fb87b1c794
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
6 changed files with 48 additions and 27 deletions

View File

@ -1177,6 +1177,10 @@ bool BrowserService::checkLegacySettings(QSharedPointer<Database> db)
bool legacySettingsFound = false;
QList<Entry*> entries = db->rootGroup()->entriesRecursive();
for (const auto& e : entries) {
if (e->isRecycled()) {
continue;
}
if ((e->attributes()->contains(KEEPASSHTTP_NAME) || e->attributes()->contains(KEEPASSXCBROWSER_NAME))
|| (e->title() == KEEPASSHTTP_NAME || e->title().contains(KEEPASSXCBROWSER_NAME, Qt::CaseInsensitive))) {
legacySettingsFound = true;

View File

@ -37,7 +37,7 @@ namespace BrowserShared
: path + serverName;
#elif defined(Q_OS_WIN)
// Windows uses named pipes
return serverName;
return serverName + "_" + qgetenv("USERNAME");
#else // Q_OS_MACOS and others
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverName;
#endif

View File

@ -58,6 +58,28 @@ namespace AsyncTask
return waitForFuture<FunctionObject>(QtConcurrent::run(task));
}
/**
* Run a given task then call the defined callback. Prevents event loop blocking and
* ensures the validity of the follow-on task through the context. If the context is
* deleted, the callback will not be processed preventing use after free errors.
*
* @param task std::function object to run
* @param context QObject responsible for calling this function
* @param callback std::function object to run after the task completess
*/
template <typename FunctionObject, typename FunctionObject2>
void runThenCallback(FunctionObject task, QObject* context, FunctionObject2 callback)
{
typedef QFutureWatcher<typename std::result_of<FunctionObject()>::type> FutureWatcher;
auto future = QtConcurrent::run(task);
auto watcher = new FutureWatcher(context);
QObject::connect(watcher, &QFutureWatcherBase::finished, context, [=]() {
watcher->deleteLater();
callback(future.result());
});
watcher->setFuture(future);
}
}; // namespace AsyncTask
#endif // KEEPASSXC_ASYNCTASK_HPP

View File

@ -118,13 +118,16 @@ void FileWatcher::checkFileChanged()
// Prevent reentrance
m_ignoreFileChange = true;
auto checksum = AsyncTask::runAndWaitForFuture([this]() -> QByteArray { return calculateChecksum(); });
if (checksum != m_fileChecksum) {
m_fileChecksum = checksum;
m_fileChangeDelayTimer.start(0);
}
AsyncTask::runThenCallback([=] { return calculateChecksum(); },
this,
[=](QByteArray checksum) {
if (checksum != m_fileChecksum) {
m_fileChecksum = checksum;
m_fileChangeDelayTimer.start(0);
}
m_ignoreFileChange = false;
m_ignoreFileChange = false;
});
}
QByteArray FileWatcher::calculateChecksum()

View File

@ -21,20 +21,6 @@
#include <QDir>
namespace
{
QString modFilter(const QString& filter)
{
#ifdef Q_OS_MACOS
// Fix macOS bug that causes the file dialog to freeze when a dot is included in the filters
// See https://github.com/keepassxreboot/keepassxc/issues/3895#issuecomment-586724167
auto mod = filter;
return mod.replace("*.", "*");
#endif
return filter;
}
} // namespace
FileDialog* FileDialog::m_instance(nullptr);
QString FileDialog::getOpenFileName(QWidget* parent,
@ -51,7 +37,7 @@ QString FileDialog::getOpenFileName(QWidget* parent,
} else {
const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
const auto result = QDir::toNativeSeparators(
QFileDialog::getOpenFileName(parent, caption, workingDir, modFilter(filter), selectedFilter, options));
QFileDialog::getOpenFileName(parent, caption, workingDir, filter, selectedFilter, options));
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog
@ -77,8 +63,7 @@ QStringList FileDialog::getOpenFileNames(QWidget* parent,
return results;
} else {
const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
auto results =
QFileDialog::getOpenFileNames(parent, caption, workingDir, modFilter(filter), selectedFilter, options);
auto results = QFileDialog::getOpenFileNames(parent, caption, workingDir, filter, selectedFilter, options);
for (auto& path : results) {
path = QDir::toNativeSeparators(path);
@ -111,7 +96,7 @@ QString FileDialog::getSaveFileName(QWidget* parent,
} else {
const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
const auto result = QDir::toNativeSeparators(
QFileDialog::getSaveFileName(parent, caption, workingDir, modFilter(filter), selectedFilter, options));
QFileDialog::getSaveFileName(parent, caption, workingDir, filter, selectedFilter, options));
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog

View File

@ -259,8 +259,15 @@ MainWindow::MainWindow()
m_ui->actionEntryAutoType->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_V);
m_ui->actionEntryOpenUrl->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_U);
m_ui->actionEntryCopyURL->setShortcut(Qt::CTRL + Qt::Key_U);
m_ui->actionEntryAddToAgent->setShortcut(Qt::CTRL + Qt::Key_H);
m_ui->actionEntryRemoveFromAgent->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_H);
// Prevent conflicts with global Mac shortcuts (force Control on all platforms)
#ifdef Q_OS_MAC
auto modifier = Qt::META;
#else
auto modifier = Qt::CTRL;
#endif
m_ui->actionEntryAddToAgent->setShortcut(modifier + Qt::Key_H);
m_ui->actionEntryRemoveFromAgent->setShortcut(modifier + Qt::SHIFT + Qt::Key_H);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// Qt 5.10 introduced a new "feature" to hide shortcuts in context menus