0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 04:12:15 +02:00

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ HostInstaller::HostInstaller()
, ALLOWED_EXTENSIONS(QStringList() << "keepassxc-browser@keepassxc.org")
, ALLOWED_ORIGINS(QStringList() << "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/"
<< "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/")
#if defined(Q_OS_OSX)
#if defined(Q_OS_MACOS)
, TARGET_DIR_CHROME("/Library/Application Support/Google/Chrome/NativeMessagingHosts")
, TARGET_DIR_CHROMIUM("/Library/Application Support/Chromium/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
{
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
QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
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;
#endif
}

View File

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

View File

@ -110,7 +110,7 @@ Config::Config(QObject* parent)
QString userPath;
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
QByteArray env = qgetenv("XDG_CONFIG_HOME");
if (env.isEmpty()) {

View File

@ -50,7 +50,7 @@ QString FilePath::pluginPath(const QString& name)
// for TestAutoType
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";
#endif
@ -223,13 +223,13 @@ FilePath::FilePath()
else if (testSetDir(QString(KEEPASSX_SOURCE_DIR) + "/share")) {
}
#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(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) {
} else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) {
}
#endif
#if defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE)
#if defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
else if (testSetDir(appDirPath + "/../Resources")) {
}
#endif

View File

@ -450,7 +450,11 @@ void Metadata::copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* othe
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());
#endif
return QCryptographicHash::hash(data, QCryptographicHash::Md5);
}

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@
#define KEEPASSX_CLIPBOARD_H
#include <QObject>
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
#include "core/MacPasteboard.h"
#include <QPointer>
#endif
@ -48,7 +48,7 @@ private:
static Clipboard* m_instance;
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,
// so ignore leak warnings. See https://bugreports.qt.io/browse/QTBUG-54832
static QPointer<MacPasteboard> m_pasteboard;

View File

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

View File

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

View File

@ -97,7 +97,7 @@ QString FileDialog::getSaveFileName(QWidget* parent,
}
QString result;
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
Q_UNUSED(defaultExtension);
// the native dialogs on these platforms already append the file extension
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->setDefaultAction(closeAction);
closeButtonPixmap = QPixmap(closeButton->icon().pixmap(closeButton->icon().actualSize(QSize(16, 16))));
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
closeButton->setStyleSheet("QToolButton { background: transparent;"
"border-radius: 2px; padding: 3px; }"
"QToolButton::hover, QToolButton::focus {"

View File

@ -47,7 +47,7 @@
#include "browser/NativeMessagingHost.h"
#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 <QList>
#include <QtDBus/QtDBus>
@ -117,7 +117,7 @@ MainWindow::MainWindow()
{
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);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject("/keepassxc", this);
@ -314,7 +314,7 @@ MainWindow::MainWindow()
connect(m_ui->actionDonate, SIGNAL(triggered()), SLOT(openDonateUrl()));
connect(m_ui->actionBugReport, SIGNAL(triggered()), SLOT(openBugReportUrl()));
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
setUnifiedTitleAndToolBarOnMac(true);
#endif
@ -817,7 +817,7 @@ void MainWindow::updateTrayIcon()
QAction* actionToggle = new QAction(tr("Toggle window"), menu);
menu->addAction(actionToggle);
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
QAction* actionQuit = new QAction(tr("Quit KeePassXC"), menu);
menu->addAction(actionQuit);
@ -918,7 +918,7 @@ void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason)
void MainWindow::hideWindow()
{
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
// 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.
@ -944,7 +944,7 @@ void MainWindow::toggleWindow()
} else {
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)
// see https://github.com/keepassxreboot/keepassxc/issues/271
// and https://bugreports.qt.io/browse/QTBUG-58723

View File

@ -39,7 +39,7 @@ class MainWindow : public QMainWindow
{
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")
#endif

View File

@ -37,7 +37,6 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
, m_ui(new Ui::CsvImportWidget())
, m_parserModel(new CsvParserModel(this))
, m_comboModel(new QStringListModel(this))
, m_comboMapper(new QSignalMapper(this))
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
<< QObject::tr("Last Modified") << QObject::tr("Created")
@ -87,8 +86,11 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
combo->setFont(font);
m_combos.append(combo);
combo->setModel(m_comboModel);
m_comboMapper->setMapping(combo, i);
connect(combo, SIGNAL(currentIndexChanged(int)), m_comboMapper, SLOT(map()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
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
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->checkBoxBackslash, SIGNAL(toggled(bool)), SLOT(parse()));
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(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) {
// this line is the one that actually updates GUI table
m_parserModel->mapColumns(currentSender->currentIndex(), comboId);

View File

@ -23,7 +23,6 @@
#include <QList>
#include <QPushButton>
#include <QScopedPointer>
#include <QSignalMapper>
#include <QStackedWidget>
#include <QStringListModel>
@ -50,7 +49,7 @@ signals:
private slots:
void parse();
void comboChanged(int comboId);
void comboChanged(QComboBox* currentSender, int comboId);
void skippedChanged(int rows);
void writeDatabase();
void updatePreview();
@ -62,7 +61,6 @@ private:
const QScopedPointer<Ui::CsvImportWidget> m_ui;
CsvParserModel* const m_parserModel;
QStringListModel* const m_comboModel;
QSignalMapper* m_comboMapper;
QList<QComboBox*> m_combos;
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()) {
emitMatchActivated(currentIndex());
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
// Pressing return does not emit the QTreeView::activated signal on mac os
emit activated(currentIndex());
#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()) {
emitEntryActivated(currentIndex());
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
// Pressing return does not emit the QTreeView::activated signal on mac os
emit activated(currentIndex());
#endif

View File

@ -39,7 +39,7 @@
#if defined(Q_OS_WIN)
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)
#endif
#endif