Replace deprecated parts of the code (#2419)

Performing a dev build against the latest version of Qt failed
because of some deprecated members. They have been replaced
according to the Qt documentation.

Further, Q_OS_MACOS is now the only macro available to identify a
machine running macOS, the others are now deprecated.
See https://doc.qt.io/qt-5/qtglobal.html#Q_OS_OSX and
https://doc.qt.io/qt-5/qtglobal.html#Q_OS_MAC.
This commit is contained in:
Gianluca Recchia 2018-10-26 15:19:04 +02:00 committed by Janek Bevendorff
parent efdb43dc53
commit f31d65bdaf
26 changed files with 57 additions and 47 deletions

View File

@ -142,7 +142,7 @@ QStringList AutoType::windowTitles()
void AutoType::raiseWindow() void AutoType::raiseWindow()
{ {
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
m_plugin->raiseOwnWindow(); m_plugin->raiseOwnWindow();
#endif #endif
} }
@ -213,7 +213,7 @@ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, c
} }
if (hideWindow) { if (hideWindow) {
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
m_plugin->raiseLastActiveWindow(); m_plugin->raiseLastActiveWindow();
#else #else
hideWindow->showMinimized(); hideWindow->showMinimized();
@ -327,7 +327,7 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
connect(selectDialog, SIGNAL(rejected()), SLOT(autoTypeRejectedFromGlobal())); connect(selectDialog, SIGNAL(rejected()), SLOT(autoTypeRejectedFromGlobal()));
selectDialog->setMatchList(matchList); selectDialog->setMatchList(matchList);
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
m_plugin->raiseOwnWindow(); m_plugin->raiseOwnWindow();
Tools::wait(500); Tools::wait(500);
#endif #endif

View File

@ -42,7 +42,7 @@ public:
virtual AutoTypeExecutor* createExecutor() = 0; virtual AutoTypeExecutor* createExecutor() = 0;
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
virtual bool raiseLastActiveWindow() = 0; virtual bool raiseLastActiveWindow() = 0;
virtual bool raiseOwnWindow() = 0; virtual bool raiseOwnWindow() = 0;
#endif #endif

View File

@ -19,7 +19,11 @@
#include "AutoTypeSelectDialog.h" #include "AutoTypeSelectDialog.h"
#include <QApplication> #include <QApplication>
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QScreen>
#else
#include <QDesktopWidget> #include <QDesktopWidget>
#endif
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QHeaderView> #include <QHeaderView>
#include <QLabel> #include <QLabel>
@ -44,7 +48,11 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
setWindowTitle(tr("Auto-Type - KeePassXC")); setWindowTitle(tr("Auto-Type - KeePassXC"));
setWindowIcon(filePath()->applicationIcon()); setWindowIcon(filePath()->applicationIcon());
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QRect screenGeometry = QApplication::screenAt(QCursor::pos())->availableGeometry();
#else
QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos()); QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos());
#endif
QSize size = config()->get("GUI/AutoTypeSelectDialogSize", QSize(600, 250)).toSize(); QSize size = config()->get("GUI/AutoTypeSelectDialogSize", QSize(600, 250)).toSize();
size.setWidth(qMin(size.width(), screenGeometry.width())); size.setWidth(qMin(size.width(), screenGeometry.width()));
size.setHeight(qMin(size.height(), screenGeometry.height())); size.setHeight(qMin(size.height(), screenGeometry.height()));

View File

@ -110,7 +110,7 @@ bool AutoTypePlatformTest::raiseWindow(WId window)
return false; return false;
} }
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
bool AutoTypePlatformTest::raiseLastActiveWindow() bool AutoTypePlatformTest::raiseLastActiveWindow()
{ {
return false; return false;

View File

@ -43,7 +43,7 @@ public:
bool raiseWindow(WId window) override; bool raiseWindow(WId window) override;
AutoTypeExecutor* createExecutor() override; AutoTypeExecutor* createExecutor() override;
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
bool raiseLastActiveWindow() override; bool raiseLastActiveWindow() override;
bool raiseOwnWindow() override; bool raiseOwnWindow() override;
#endif #endif

View File

@ -33,7 +33,7 @@ HostInstaller::HostInstaller()
, ALLOWED_EXTENSIONS(QStringList() << "keepassxc-browser@keepassxc.org") , ALLOWED_EXTENSIONS(QStringList() << "keepassxc-browser@keepassxc.org")
, ALLOWED_ORIGINS(QStringList() << "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/" , ALLOWED_ORIGINS(QStringList() << "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/"
<< "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/") << "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/")
#if defined(Q_OS_OSX) #if defined(Q_OS_MACOS)
, TARGET_DIR_CHROME("/Library/Application Support/Google/Chrome/NativeMessagingHosts") , TARGET_DIR_CHROME("/Library/Application Support/Google/Chrome/NativeMessagingHosts")
, TARGET_DIR_CHROMIUM("/Library/Application Support/Chromium/NativeMessagingHosts") , TARGET_DIR_CHROMIUM("/Library/Application Support/Chromium/NativeMessagingHosts")
, TARGET_DIR_FIREFOX("/Library/Application Support/Mozilla/NativeMessagingHosts") , TARGET_DIR_FIREFOX("/Library/Application Support/Mozilla/NativeMessagingHosts")

View File

@ -135,11 +135,11 @@ void NativeMessagingBase::sendReply(const QString& reply)
QString NativeMessagingBase::getLocalServerPath() const QString NativeMessagingBase::getLocalServerPath() const
{ {
const QString serverPath = "/kpxc_server"; const QString serverPath = "/kpxc_server";
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
// Use XDG_RUNTIME_DIR instead of /tmp if it's available // Use XDG_RUNTIME_DIR instead of /tmp if it's available
QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
return path.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverPath : path + serverPath; return path.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverPath : path + serverPath;
#else // Q_OS_MAC, Q_OS_WIN and others #else // Q_OS_MACOS, Q_OS_WIN and others
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverPath; return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverPath;
#endif #endif
} }

View File

@ -57,7 +57,7 @@ void bootstrapApplication()
applyEarlyQNetworkAccessManagerWorkaround(); applyEarlyQNetworkAccessManagerWorkaround();
Translator::installTranslators(); Translator::installTranslators();
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
// Don't show menu icons on OSX // Don't show menu icons on OSX
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
#endif #endif

View File

@ -110,7 +110,7 @@ Config::Config(QObject* parent)
QString userPath; QString userPath;
QString homePath = QDir::homePath(); QString homePath = QDir::homePath();
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
// we can't use QStandardPaths on X11 as it uses XDG_DATA_HOME instead of XDG_CONFIG_HOME // we can't use QStandardPaths on X11 as it uses XDG_DATA_HOME instead of XDG_CONFIG_HOME
QByteArray env = qgetenv("XDG_CONFIG_HOME"); QByteArray env = qgetenv("XDG_CONFIG_HOME");
if (env.isEmpty()) { if (env.isEmpty()) {

View File

@ -50,7 +50,7 @@ QString FilePath::pluginPath(const QString& name)
// for TestAutoType // for TestAutoType
pluginPaths << QCoreApplication::applicationDirPath() + "/../src/autotype/test"; pluginPaths << QCoreApplication::applicationDirPath() + "/../src/autotype/test";
#if defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE) #if defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
pluginPaths << QCoreApplication::applicationDirPath() + "/../PlugIns"; pluginPaths << QCoreApplication::applicationDirPath() + "/../PlugIns";
#endif #endif
@ -223,13 +223,13 @@ FilePath::FilePath()
else if (testSetDir(QString(KEEPASSX_SOURCE_DIR) + "/share")) { else if (testSetDir(QString(KEEPASSX_SOURCE_DIR) + "/share")) {
} }
#endif #endif
#if defined(Q_OS_UNIX) && !(defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE)) #if defined(Q_OS_UNIX) && !(defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE))
else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) { else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) {
} else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) { } else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) {
} else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) { } else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) {
} }
#endif #endif
#if defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE) #if defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
else if (testSetDir(appDirPath + "/../Resources")) { else if (testSetDir(appDirPath + "/../Resources")) {
} }
#endif #endif

View File

@ -450,7 +450,11 @@ void Metadata::copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* othe
QByteArray Metadata::hashImage(const QImage& image) QByteArray Metadata::hashImage(const QImage& image)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
auto data = QByteArray(reinterpret_cast<const char*>(image.bits()), static_cast<int>(image.sizeInBytes()));
#else
auto data = QByteArray(reinterpret_cast<const char*>(image.bits()), image.byteCount()); auto data = QByteArray(reinterpret_cast<const char*>(image.bits()), image.byteCount());
#endif
return QCryptographicHash::hash(data, QCryptographicHash::Md5); return QCryptographicHash::hash(data, QCryptographicHash::Md5);
} }

View File

@ -16,7 +16,7 @@
*/ */
#include "ScreenLockListenerPrivate.h" #include "ScreenLockListenerPrivate.h"
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
#include "ScreenLockListenerMac.h" #include "ScreenLockListenerMac.h"
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)
#include "ScreenLockListenerDBus.h" #include "ScreenLockListenerDBus.h"
@ -31,7 +31,7 @@ ScreenLockListenerPrivate::ScreenLockListenerPrivate(QWidget* parent)
ScreenLockListenerPrivate* ScreenLockListenerPrivate::instance(QWidget* parent) ScreenLockListenerPrivate* ScreenLockListenerPrivate::instance(QWidget* parent)
{ {
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
Q_UNUSED(parent); Q_UNUSED(parent);
return ScreenLockListenerMac::instance(); return ScreenLockListenerMac::instance();
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)

View File

@ -44,7 +44,7 @@ namespace
const char BlockSizeProperty[] = "blockSize"; const char BlockSizeProperty[] = "blockSize";
} }
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
class XcbEventFilter : public QAbstractNativeEventFilter class XcbEventFilter : public QAbstractNativeEventFilter
{ {
public: public:
@ -92,7 +92,7 @@ Application::Application(int& argc, char** argv)
, m_alreadyRunning(false) , m_alreadyRunning(false)
, m_lockFile(nullptr) , m_lockFile(nullptr)
{ {
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
installNativeEventFilter(new XcbEventFilter()); installNativeEventFilter(new XcbEventFilter());
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
installNativeEventFilter(new WinEventFilter()); installNativeEventFilter(new WinEventFilter());
@ -195,7 +195,7 @@ bool Application::event(QEvent* event)
emit openFile(static_cast<QFileOpenEvent*>(event)->file()); emit openFile(static_cast<QFileOpenEvent*>(event)->file());
return true; return true;
} }
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
// restore main window when clicking on the docker icon // restore main window when clicking on the docker icon
else if (event->type() == QEvent::ApplicationActivate) { else if (event->type() == QEvent::ApplicationActivate) {
emit applicationActivated(); emit applicationActivated();

View File

@ -26,7 +26,7 @@
#include "core/Config.h" #include "core/Config.h"
Clipboard* Clipboard::m_instance(nullptr); Clipboard* Clipboard::m_instance(nullptr);
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
QPointer<MacPasteboard> Clipboard::m_pasteboard(nullptr); QPointer<MacPasteboard> Clipboard::m_pasteboard(nullptr);
#endif #endif
@ -34,7 +34,7 @@ Clipboard::Clipboard(QObject* parent)
: QObject(parent) : QObject(parent)
, m_timer(new QTimer(this)) , m_timer(new QTimer(this))
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
if (!m_pasteboard) { if (!m_pasteboard) {
m_pasteboard = new MacPasteboard(); m_pasteboard = new MacPasteboard();
} }
@ -49,7 +49,7 @@ void Clipboard::setText(const QString& text)
QClipboard* clipboard = QApplication::clipboard(); QClipboard* clipboard = QApplication::clipboard();
QMimeData* mime = new QMimeData; QMimeData* mime = new QMimeData;
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
mime->setText(text); mime->setText(text);
mime->setData("application/x-nspasteboard-concealed-type", text.toUtf8()); mime->setData("application/x-nspasteboard-concealed-type", text.toUtf8());
clipboard->setMimeData(mime, QClipboard::Clipboard); clipboard->setMimeData(mime, QClipboard::Clipboard);

View File

@ -20,7 +20,7 @@
#define KEEPASSX_CLIPBOARD_H #define KEEPASSX_CLIPBOARD_H
#include <QObject> #include <QObject>
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
#include "core/MacPasteboard.h" #include "core/MacPasteboard.h"
#include <QPointer> #include <QPointer>
#endif #endif
@ -48,7 +48,7 @@ private:
static Clipboard* m_instance; static Clipboard* m_instance;
QTimer* m_timer; QTimer* m_timer;
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
// This object lives for the whole program lifetime and we cannot delete it on exit, // This object lives for the whole program lifetime and we cannot delete it on exit,
// so ignore leak warnings. See https://bugreports.qt.io/browse/QTBUG-54832 // so ignore leak warnings. See https://bugreports.qt.io/browse/QTBUG-54832
static QPointer<MacPasteboard> m_pasteboard; static QPointer<MacPasteboard> m_pasteboard;

View File

@ -1432,7 +1432,7 @@ void DatabaseWidget::showUnlockDialog()
m_unlockDatabaseDialog->clearForms(); m_unlockDatabaseDialog->clearForms();
m_unlockDatabaseDialog->setFilePath(m_filePath); m_unlockDatabaseDialog->setFilePath(m_filePath);
#if defined(Q_OS_MAC) #if defined(Q_OS_MACOS)
autoType()->raiseWindow(); autoType()->raiseWindow();
Tools::wait(500); Tools::wait(500);
#endif #endif

View File

@ -28,7 +28,7 @@ DialogyWidget::DialogyWidget(QWidget* parent)
void DialogyWidget::keyPressEvent(QKeyEvent* e) void DialogyWidget::keyPressEvent(QKeyEvent* e)
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
if (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) { if (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) {
if (!clickButton(QDialogButtonBox::Cancel)) { if (!clickButton(QDialogButtonBox::Cancel)) {
e->ignore(); e->ignore();

View File

@ -97,7 +97,7 @@ QString FileDialog::getSaveFileName(QWidget* parent,
} }
QString result; QString result;
#if defined(Q_OS_MAC) || defined(Q_OS_WIN) #if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
Q_UNUSED(defaultExtension); Q_UNUSED(defaultExtension);
// the native dialogs on these platforms already append the file extension // the native dialogs on these platforms already append the file extension
result = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); result = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);

View File

@ -102,7 +102,7 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
closeButton->setAutoRaise(true); closeButton->setAutoRaise(true);
closeButton->setDefaultAction(closeAction); closeButton->setDefaultAction(closeAction);
closeButtonPixmap = QPixmap(closeButton->icon().pixmap(closeButton->icon().actualSize(QSize(16, 16)))); closeButtonPixmap = QPixmap(closeButton->icon().pixmap(closeButton->icon().actualSize(QSize(16, 16))));
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
closeButton->setStyleSheet("QToolButton { background: transparent;" closeButton->setStyleSheet("QToolButton { background: transparent;"
"border-radius: 2px; padding: 3px; }" "border-radius: 2px; padding: 3px; }"
"QToolButton::hover, QToolButton::focus {" "QToolButton::hover, QToolButton::focus {"

View File

@ -47,7 +47,7 @@
#include "browser/NativeMessagingHost.h" #include "browser/NativeMessagingHost.h"
#endif #endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
#include "gui/MainWindowAdaptor.h" #include "gui/MainWindowAdaptor.h"
#include <QList> #include <QList>
#include <QtDBus/QtDBus> #include <QtDBus/QtDBus>
@ -117,7 +117,7 @@ MainWindow::MainWindow()
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
new MainWindowAdaptor(this); new MainWindowAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject("/keepassxc", this); dbus.registerObject("/keepassxc", this);
@ -314,7 +314,7 @@ MainWindow::MainWindow()
connect(m_ui->actionDonate, SIGNAL(triggered()), SLOT(openDonateUrl())); connect(m_ui->actionDonate, SIGNAL(triggered()), SLOT(openDonateUrl()));
connect(m_ui->actionBugReport, SIGNAL(triggered()), SLOT(openBugReportUrl())); connect(m_ui->actionBugReport, SIGNAL(triggered()), SLOT(openBugReportUrl()));
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
#endif #endif
@ -817,7 +817,7 @@ void MainWindow::updateTrayIcon()
QAction* actionToggle = new QAction(tr("Toggle window"), menu); QAction* actionToggle = new QAction(tr("Toggle window"), menu);
menu->addAction(actionToggle); menu->addAction(actionToggle);
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
QAction* actionQuit = new QAction(tr("Quit KeePassXC"), menu); QAction* actionQuit = new QAction(tr("Quit KeePassXC"), menu);
menu->addAction(actionQuit); menu->addAction(actionQuit);
@ -918,7 +918,7 @@ void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason)
void MainWindow::hideWindow() void MainWindow::hideWindow()
{ {
saveWindowInformation(); saveWindowInformation();
#if !defined(Q_OS_LINUX) && !defined(Q_OS_MAC) #if !defined(Q_OS_LINUX) && !defined(Q_OS_MACOS)
// On some Linux systems, the window should NOT be minimized and hidden (i.e. not shown), at // On some Linux systems, the window should NOT be minimized and hidden (i.e. not shown), at
// the same time (which would happen if both minimize on startup and minimize to tray are set) // the same time (which would happen if both minimize on startup and minimize to tray are set)
// since otherwise it causes problems on restore as seen on issue #1595. Hiding it is enough. // since otherwise it causes problems on restore as seen on issue #1595. Hiding it is enough.
@ -944,7 +944,7 @@ void MainWindow::toggleWindow()
} else { } else {
bringToFront(); bringToFront();
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) && (QT_VERSION < QT_VERSION_CHECK(5, 9, 0)) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS) && (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
// re-register global D-Bus menu (needed on Ubuntu with Unity) // re-register global D-Bus menu (needed on Ubuntu with Unity)
// see https://github.com/keepassxreboot/keepassxc/issues/271 // see https://github.com/keepassxreboot/keepassxc/issues/271
// and https://bugreports.qt.io/browse/QTBUG-58723 // and https://bugreports.qt.io/browse/QTBUG-58723

View File

@ -39,7 +39,7 @@ class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && !defined(QT_NO_DBUS)
Q_CLASSINFO("D-Bus Interface", "org.keepassxc.KeePassXC.MainWindow") Q_CLASSINFO("D-Bus Interface", "org.keepassxc.KeePassXC.MainWindow")
#endif #endif

View File

@ -37,7 +37,6 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
, m_ui(new Ui::CsvImportWidget()) , m_ui(new Ui::CsvImportWidget())
, m_parserModel(new CsvParserModel(this)) , m_parserModel(new CsvParserModel(this))
, m_comboModel(new QStringListModel(this)) , m_comboModel(new QStringListModel(this))
, m_comboMapper(new QSignalMapper(this))
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username") , m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes") << QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
<< QObject::tr("Last Modified") << QObject::tr("Created") << QObject::tr("Last Modified") << QObject::tr("Created")
@ -87,8 +86,11 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
combo->setFont(font); combo->setFont(font);
m_combos.append(combo); m_combos.append(combo);
combo->setModel(m_comboModel); combo->setModel(m_comboModel);
m_comboMapper->setMapping(combo, i); #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(combo, SIGNAL(currentIndexChanged(int)), m_comboMapper, SLOT(map())); connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=]{ comboChanged(combo, i); });
#else
connect(combo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]{ comboChanged(combo, i); });
#endif
// layout labels and combo fields in column-first order // layout labels and combo fields in column-first order
int combo_rows = 1 + (m_columnHeader.count() - 1) / 2; int combo_rows = 1 + (m_columnHeader.count() - 1) / 2;
@ -110,15 +112,13 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
connect(m_ui->comboBoxFieldSeparator, SIGNAL(currentIndexChanged(int)), SLOT(parse())); connect(m_ui->comboBoxFieldSeparator, SIGNAL(currentIndexChanged(int)), SLOT(parse()));
connect(m_ui->checkBoxBackslash, SIGNAL(toggled(bool)), SLOT(parse())); connect(m_ui->checkBoxBackslash, SIGNAL(toggled(bool)), SLOT(parse()));
connect(m_ui->checkBoxFieldNames, SIGNAL(toggled(bool)), SLOT(updatePreview())); connect(m_ui->checkBoxFieldNames, SIGNAL(toggled(bool)), SLOT(updatePreview()));
connect(m_comboMapper, SIGNAL(mapped(int)), this, SLOT(comboChanged(int)));
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(writeDatabase())); connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(writeDatabase()));
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
} }
void CsvImportWidget::comboChanged(int comboId) void CsvImportWidget::comboChanged(QComboBox* currentSender, int comboId)
{ {
QComboBox* currentSender = qobject_cast<QComboBox*>(m_comboMapper->mapping(comboId));
if (currentSender->currentIndex() != -1) { if (currentSender->currentIndex() != -1) {
// this line is the one that actually updates GUI table // this line is the one that actually updates GUI table
m_parserModel->mapColumns(currentSender->currentIndex(), comboId); m_parserModel->mapColumns(currentSender->currentIndex(), comboId);

View File

@ -23,7 +23,6 @@
#include <QList> #include <QList>
#include <QPushButton> #include <QPushButton>
#include <QScopedPointer> #include <QScopedPointer>
#include <QSignalMapper>
#include <QStackedWidget> #include <QStackedWidget>
#include <QStringListModel> #include <QStringListModel>
@ -50,7 +49,7 @@ signals:
private slots: private slots:
void parse(); void parse();
void comboChanged(int comboId); void comboChanged(QComboBox* currentSender, int comboId);
void skippedChanged(int rows); void skippedChanged(int rows);
void writeDatabase(); void writeDatabase();
void updatePreview(); void updatePreview();
@ -62,7 +61,6 @@ private:
const QScopedPointer<Ui::CsvImportWidget> m_ui; const QScopedPointer<Ui::CsvImportWidget> m_ui;
CsvParserModel* const m_parserModel; CsvParserModel* const m_parserModel;
QStringListModel* const m_comboModel; QStringListModel* const m_comboModel;
QSignalMapper* m_comboMapper;
QList<QComboBox*> m_combos; QList<QComboBox*> m_combos;
Database* m_db; Database* m_db;

View File

@ -51,7 +51,7 @@ void AutoTypeMatchView::keyPressEvent(QKeyEvent* event)
{ {
if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) { if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) {
emitMatchActivated(currentIndex()); emitMatchActivated(currentIndex());
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
// Pressing return does not emit the QTreeView::activated signal on mac os // Pressing return does not emit the QTreeView::activated signal on mac os
emit activated(currentIndex()); emit activated(currentIndex());
#endif #endif

View File

@ -123,7 +123,7 @@ void EntryView::keyPressEvent(QKeyEvent* event)
{ {
if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) { if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) {
emitEntryActivated(currentIndex()); emitEntryActivated(currentIndex());
#ifdef Q_OS_MAC #ifdef Q_OS_MACOS
// Pressing return does not emit the QTreeView::activated signal on mac os // Pressing return does not emit the QTreeView::activated signal on mac os
emit activated(currentIndex()); emit activated(currentIndex());
#endif #endif

View File

@ -39,7 +39,7 @@
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) #elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
#endif #endif
#endif #endif