From 533136fb0eb0391a294f742ddfb099adb69cec92 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Mon, 8 May 2017 16:03:19 +0200 Subject: [PATCH] Add file header, use nullptr instead of NULL, fix code style --- src/core/ScreenLockListener.cpp | 17 ++++++++++++++++ src/core/ScreenLockListener.h | 19 +++++++++++++++++- src/core/ScreenLockListenerDBus.cpp | 17 ++++++++++++++++ src/core/ScreenLockListenerDBus.h | 17 ++++++++++++++++ src/core/ScreenLockListenerMac.cpp | 25 ++++++++++++++++++++---- src/core/ScreenLockListenerMac.h | 19 +++++++++++++++++- src/core/ScreenLockListenerPrivate.cpp | 17 ++++++++++++++++ src/core/ScreenLockListenerPrivate.h | 21 ++++++++++++++++++-- src/core/ScreenLockListenerWin.cpp | 27 +++++++++++++++++++++----- src/core/ScreenLockListenerWin.h | 23 +++++++++++++++++++--- 10 files changed, 186 insertions(+), 16 deletions(-) diff --git a/src/core/ScreenLockListener.cpp b/src/core/ScreenLockListener.cpp index 2c17dfa1..eb78cd60 100644 --- a/src/core/ScreenLockListener.cpp +++ b/src/core/ScreenLockListener.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ScreenLockListener.h" #include "ScreenLockListenerPrivate.h" diff --git a/src/core/ScreenLockListener.h b/src/core/ScreenLockListener.h index 7339054f..bc115d19 100644 --- a/src/core/ScreenLockListener.h +++ b/src/core/ScreenLockListener.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef SCREENLOCKLISTENER_H #define SCREENLOCKLISTENER_H #include @@ -8,7 +25,7 @@ class ScreenLockListener : public QObject { Q_OBJECT public: - ScreenLockListener(QWidget* parent=NULL); + ScreenLockListener(QWidget* parent = nullptr); ~ScreenLockListener(); Q_SIGNALS: diff --git a/src/core/ScreenLockListenerDBus.cpp b/src/core/ScreenLockListenerDBus.cpp index 2b4de9da..e24e388a 100644 --- a/src/core/ScreenLockListenerDBus.cpp +++ b/src/core/ScreenLockListenerDBus.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ScreenLockListenerDBus.h" #include diff --git a/src/core/ScreenLockListenerDBus.h b/src/core/ScreenLockListenerDBus.h index 0c49323f..a907f20c 100644 --- a/src/core/ScreenLockListenerDBus.h +++ b/src/core/ScreenLockListenerDBus.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef SCREENLOCKLISTENERDBUS_H #define SCREENLOCKLISTENERDBUS_H #include diff --git a/src/core/ScreenLockListenerMac.cpp b/src/core/ScreenLockListenerMac.cpp index 7be9dd2f..3917a888 100644 --- a/src/core/ScreenLockListenerMac.cpp +++ b/src/core/ScreenLockListenerMac.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ScreenLockListenerMac.h" #include @@ -8,8 +25,8 @@ ScreenLockListenerMac* ScreenLockListenerMac::instance() static QMutex mutex; QMutexLocker lock(&mutex); - static ScreenLockListenerMac* m_ptr=NULL; - if (m_ptr == NULL) { + static ScreenLockListenerMac* m_ptr = nullptr; + if (m_ptr == nullptr) { m_ptr = new ScreenLockListenerMac(); } return m_ptr; @@ -27,7 +44,7 @@ ScreenLockListenerMac::ScreenLockListenerMac(QWidget* parent) CFNotificationCenterRef distCenter; CFStringRef screenIsLockedSignal = CFSTR("com.apple.screenIsLocked"); distCenter = CFNotificationCenterGetDistributedCenter(); - if (NULL == distCenter) { + if (nullptr == distCenter) { return; } @@ -35,7 +52,7 @@ ScreenLockListenerMac::ScreenLockListenerMac(QWidget* parent) distCenter, this, &ScreenLockListenerMac::notificationCenterCallBack, screenIsLockedSignal, - NULL, + nullptr, CFNotificationSuspensionBehaviorDeliverImmediately); } diff --git a/src/core/ScreenLockListenerMac.h b/src/core/ScreenLockListenerMac.h index 5824339f..733cb375 100644 --- a/src/core/ScreenLockListenerMac.h +++ b/src/core/ScreenLockListenerMac.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef SCREENLOCKLISTENERMAC_H #define SCREENLOCKLISTENERMAC_H #include @@ -16,7 +33,7 @@ public: CFNotificationName /*name*/, const void */*object*/, CFDictionaryRef /*userInfo*/); private: - ScreenLockListenerMac(QWidget* parent=NULL); + ScreenLockListenerMac(QWidget* parent = nullptr); void onSignalReception(); }; diff --git a/src/core/ScreenLockListenerPrivate.cpp b/src/core/ScreenLockListenerPrivate.cpp index e0c6d234..9a0ebd69 100644 --- a/src/core/ScreenLockListenerPrivate.cpp +++ b/src/core/ScreenLockListenerPrivate.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ScreenLockListenerPrivate.h" #if defined(Q_OS_OSX) #include "ScreenLockListenerMac.h" diff --git a/src/core/ScreenLockListenerPrivate.h b/src/core/ScreenLockListenerPrivate.h index aef20edc..781d6452 100644 --- a/src/core/ScreenLockListenerPrivate.h +++ b/src/core/ScreenLockListenerPrivate.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef SCREENLOCKLISTENERPRIVATE_H #define SCREENLOCKLISTENERPRIVATE_H #include @@ -7,10 +24,10 @@ class ScreenLockListenerPrivate : public QObject { Q_OBJECT public: - static ScreenLockListenerPrivate* instance(QWidget *parent = 0); + static ScreenLockListenerPrivate* instance(QWidget* parent = 0); protected: - ScreenLockListenerPrivate(QWidget *parent = 0); + ScreenLockListenerPrivate(QWidget* parent = 0); Q_SIGNALS: void screenLocked(); diff --git a/src/core/ScreenLockListenerWin.cpp b/src/core/ScreenLockListenerWin.cpp index 4aae8a28..3e7950ab 100644 --- a/src/core/ScreenLockListenerWin.cpp +++ b/src/core/ScreenLockListenerWin.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ScreenLockListenerWin.h" #include #include @@ -8,11 +25,11 @@ * See https://msdn.microsoft.com/en-us/library/aa383841(v=vs.85).aspx * See https://blogs.msdn.microsoft.com/oldnewthing/20060104-50/?p=32783 */ -ScreenLockListenerWin::ScreenLockListenerWin(QWidget *parent) +ScreenLockListenerWin::ScreenLockListenerWin(QWidget* parent) : ScreenLockListenerPrivate(parent) , QAbstractNativeEventFilter() { - Q_ASSERT(parent != NULL); + Q_ASSERT(parent != nullptr); // On windows, we need to register for platform specific messages and // install a message handler for them QCoreApplication::instance()->installNativeEventFilter(this); @@ -21,7 +38,7 @@ ScreenLockListenerWin::ScreenLockListenerWin(QWidget *parent) HPOWERNOTIFY hPnotify = RegisterPowerSettingNotification( reinterpret_cast(parent->winId()), &GUID_LIDSWITCH_STATE_CHANGE, DEVICE_NOTIFY_WINDOW_HANDLE); - m_powernotificationhandle = reinterpret_cast(hPnotify); + m_powerNotificationHandle = reinterpret_cast(hPnotify); // This call requests a notification for session changes if (!WTSRegisterSessionNotification( @@ -40,10 +57,10 @@ ScreenLockListenerWin::~ScreenLockListenerWin() } } -bool ScreenLockListenerWin::nativeEventFilter(const QByteArray &eventType, void *message, long *) +bool ScreenLockListenerWin::nativeEventFilter(const QByteArray &eventType, void* message, long *) { if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") { - MSG* m = static_cast(message); + MSG* m = static_cast(message); if (m->message == WM_POWERBROADCAST) { if (m->wParam == PBT_POWERSETTINGCHANGE) { const POWERBROADCAST_SETTING* setting = reinterpret_cast(m->lParam); diff --git a/src/core/ScreenLockListenerWin.h b/src/core/ScreenLockListenerWin.h index ccf42ad7..0a1c37f9 100644 --- a/src/core/ScreenLockListenerWin.h +++ b/src/core/ScreenLockListenerWin.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef SCREENLOCKLISTENERWIN_H #define SCREENLOCKLISTENERWIN_H #include @@ -10,12 +27,12 @@ class ScreenLockListenerWin : public ScreenLockListenerPrivate, public QAbstract { Q_OBJECT public: - explicit ScreenLockListenerWin(QWidget *parent = 0); + explicit ScreenLockListenerWin(QWidget* parent = 0); ~ScreenLockListenerWin(); - virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE; + virtual bool nativeEventFilter(const QByteArray &eventType, void* message, long *) override; private: - void * m_powernotificationhandle; + void* m_powerNotificationHandle ; }; #endif // SCREENLOCKLISTENERWIN_H