diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a1b72bc9..28eb5a05c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,7 +219,7 @@ set(HEADERS src/components/timeline/TimelineModel.hpp src/components/url-handlers/UrlHandlers.hpp src/utils/LinphoneUtils.hpp - src/utils/QExifImageHeader.h + src/utils/QExifImageHeader.hpp src/utils/Utils.hpp ) @@ -227,41 +227,43 @@ set(MAIN_FILE src/app/main.cpp) if (APPLE) list(APPEND SOURCES + src/app/single-application/SingleApplication.cpp src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m src/components/other/desktop-tools/DesktopToolsMacOs.cpp ) list(APPEND HEADERS + src/app/single-application/SingleApplicationPrivate.hpp src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp src/components/other/desktop-tools/DesktopToolsMacOs.hpp ) elseif (WIN32) list(APPEND SOURCES + src/app/single-application/SingleApplication.cpp src/components/core/messages-count-notifier/MessagesCountNotifierSystemTrayIcon.cpp src/components/other/desktop-tools/DesktopToolsWindows.cpp ) list(APPEND HEADERS + src/app/single-application/SingleApplicationPrivate.hpp src/components/core/messages-count-notifier/MessagesCountNotifierSystemTrayIcon.hpp src/components/other/desktop-tools/DesktopToolsWindows.hpp ) else () list(APPEND SOURCES + src/app/single-application/SingleApplicationDBus.cpp src/components/core/messages-count-notifier/MessagesCountNotifierSystemTrayIcon.cpp src/components/other/desktop-tools/DesktopToolsLinux.cpp + src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.cpp + src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.cpp ) list(APPEND HEADERS + src/app/single-application/SingleApplicationDBusPrivate.hpp src/components/core/messages-count-notifier/MessagesCountNotifierSystemTrayIcon.hpp src/components/other/desktop-tools/DesktopToolsLinux.hpp + src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp + src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp ) endif () -if (UNIX AND NOT APPLE) - list(APPEND SOURCES src/app/single-application/SingleApplicationDBus.cpp) - list(APPEND HEADERS src/app/single-application/SingleApplicationDBusPrivate.hpp) -else () - list(APPEND SOURCES src/app/single-application/SingleApplication.cpp) - list(APPEND HEADERS src/app/single-application/SingleApplicationPrivate.hpp) -endif () - set(QRC_RESOURCES resources.qrc) set(LANGUAGES_DIRECTORY "${ASSETS_DIR}/languages") diff --git a/src/app/AppController.cpp b/src/app/AppController.cpp index ecdbe208a..4e16da4c7 100644 --- a/src/app/AppController.cpp +++ b/src/app/AppController.cpp @@ -81,7 +81,7 @@ AppController::AppController (int &argc, char *argv[]) { while (it.hasNext()) { QFileInfo info(it.next()); - if (info.suffix() == "ttf") { + if (info.suffix() == QLatin1String("ttf")) { QString path = info.absoluteFilePath(); if (path.startsWith(":/assets/fonts/")) QFontDatabase::addApplicationFont(path); diff --git a/src/app/paths/Paths.cpp b/src/app/paths/Paths.cpp index 3b234e1b7..214589c33 100644 --- a/src/app/paths/Paths.cpp +++ b/src/app/paths/Paths.cpp @@ -106,7 +106,7 @@ static inline string getWritableFilePath (const QString &filename) { static inline QDir getAppPackageDir () { QDir dir(QCoreApplication::applicationDirPath()); - if (dir.dirName() == "MacOS") { + if (dir.dirName() == QLatin1String("MacOS")) { dir.cdUp(); dir.cd("Resources"); } else @@ -272,7 +272,7 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new void Paths::migrate () { QString newPath = getAppConfigFilePath(); - QString oldBaseDir = QSysInfo::productType() == "windows" + QString oldBaseDir = QSysInfo::productType() == QLatin1String("windows") ? QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) : QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QString oldPath = oldBaseDir + "/.linphonerc"; diff --git a/src/app/translator/DefaultTranslator.cpp b/src/app/translator/DefaultTranslator.cpp index 520ad9995..be8df7433 100644 --- a/src/app/translator/DefaultTranslator.cpp +++ b/src/app/translator/DefaultTranslator.cpp @@ -32,11 +32,11 @@ DefaultTranslator::DefaultTranslator (QObject *parent) : QTranslator(parent) { while (it.hasNext()) { QFileInfo info(it.next()); - if (info.suffix() == "qml") { + if (info.suffix() == QLatin1String("qml")) { QString dir = info.absoluteDir().absolutePath(); // Ignore extra selectors. - // TODO: Remove 5.9 support in July 2018. + // TODO: Remove 5.9 support in July 2019. for (const auto &selector : { "+linux", "+mac", "+windows", "+5.9" }) if (dir.contains(selector)) goto end; diff --git a/src/components/chat/ChatModel.cpp b/src/components/chat/ChatModel.cpp index 68c41f894..d50b4e13b 100644 --- a/src/components/chat/ChatModel.cpp +++ b/src/components/chat/ChatModel.cpp @@ -36,7 +36,7 @@ #include "components/core/CoreManager.hpp" #include "components/notifier/Notifier.hpp" #include "components/settings/SettingsModel.hpp" -#include "utils/QExifImageHeader.h" +#include "utils/QExifImageHeader.hpp" #include "utils/Utils.hpp" #include "ChatModel.hpp" diff --git a/src/components/codecs/VideoCodecsModel.cpp b/src/components/codecs/VideoCodecsModel.cpp index 119dac005..5c9853024 100644 --- a/src/components/codecs/VideoCodecsModel.cpp +++ b/src/components/codecs/VideoCodecsModel.cpp @@ -132,7 +132,7 @@ void VideoCodecsModel::updateCodecs () { QDirIterator it(Utils::coreStringToAppString(Paths::getCodecsDirPath())); while (it.hasNext()) { QFileInfo info(it.next()); - if (info.suffix() == "in") { + if (info.suffix() == QLatin1String("in")) { QString codecName = info.completeBaseName(); if (codecName.endsWith(codecSuffix)) { QString codecPath = info.dir().path() + QDir::separator() + codecName; diff --git a/src/components/other/desktop-tools/DesktopToolsLinux.cpp b/src/components/other/desktop-tools/DesktopToolsLinux.cpp index 614879d92..772e4a908 100644 --- a/src/components/other/desktop-tools/DesktopToolsLinux.cpp +++ b/src/components/other/desktop-tools/DesktopToolsLinux.cpp @@ -24,8 +24,6 @@ // ============================================================================= -DesktopTools::DesktopTools (QObject *parent) : QObject(parent) {} - DesktopTools::~DesktopTools () { setScreenSaverStatus(true); } @@ -35,9 +33,12 @@ bool DesktopTools::getScreenSaverStatus () const { } void DesktopTools::setScreenSaverStatus (bool status) { - if (status == mScreenSaverStatus) - return; + screenSaverDBus.setScreenSaverStatus(status); + screenSaverXdg.setScreenSaverStatus(status); - // TODO: Deal with me. - emit screenSaverStatusChanged(status); + bool newStatus = screenSaverDBus.getScreenSaverStatus() || screenSaverXdg.getScreenSaverStatus(); + if (newStatus != mScreenSaverStatus) { + mScreenSaverStatus = newStatus; + emit screenSaverStatusChanged(mScreenSaverStatus); + } } diff --git a/src/components/other/desktop-tools/DesktopToolsLinux.hpp b/src/components/other/desktop-tools/DesktopToolsLinux.hpp index 65f7ae2e7..fb0385174 100644 --- a/src/components/other/desktop-tools/DesktopToolsLinux.hpp +++ b/src/components/other/desktop-tools/DesktopToolsLinux.hpp @@ -23,7 +23,8 @@ #ifndef DESKTOP_TOOLS_LINUX_H_ #define DESKTOP_TOOLS_LINUX_H_ -#include +#include "components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp" +#include "components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp" // ============================================================================= @@ -33,7 +34,7 @@ class DesktopTools : public QObject { Q_PROPERTY(bool screenSaverStatus READ getScreenSaverStatus WRITE setScreenSaverStatus NOTIFY screenSaverStatusChanged); public: - DesktopTools (QObject *parent = Q_NULLPTR); + DesktopTools (QObject *parent = Q_NULLPTR) : QObject(parent) {} ~DesktopTools (); bool getScreenSaverStatus () const; @@ -44,6 +45,9 @@ signals: private: bool mScreenSaverStatus = true; + + ScreenSaverDBus screenSaverDBus; + ScreenSaverXdg screenSaverXdg; }; #endif // DESKTOP_TOOLS_LINUX_H_ diff --git a/src/components/other/desktop-tools/DesktopToolsWindows.cpp b/src/components/other/desktop-tools/DesktopToolsWindows.cpp index 4c9b6930d..64c6c574e 100644 --- a/src/components/other/desktop-tools/DesktopToolsWindows.cpp +++ b/src/components/other/desktop-tools/DesktopToolsWindows.cpp @@ -40,11 +40,11 @@ void DesktopTools::setScreenSaverStatus (bool status) { if (status == mScreenSaverStatus) return; - if (!status) - SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); - else { + if (status) SetThreadExecutionState(ES_CONTINUOUS); - } + else + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + mScreenSaverStatus = status; emit screenSaverStatusChanged(status); } diff --git a/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.cpp b/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.cpp new file mode 100644 index 000000000..f811436cf --- /dev/null +++ b/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.cpp @@ -0,0 +1,73 @@ +/* + * ScreenSaverDBusLinux.cpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * 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 + * of the License, or (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 21, 2018 + * Author: Ronan Abhamon + */ + +#include +#include +#include +#include + +#include "ScreenSaverDBus.hpp" + +// ============================================================================= + +namespace { + constexpr char ServiceName[] = "org.freedesktop.ScreenSaver"; + constexpr char ServicePath[] = "/ScreenSaver"; +} + +ScreenSaverDBus::ScreenSaverDBus (QObject *parent) : QObject(parent), mBus(ServiceName, ServicePath, ServiceName) {} + +ScreenSaverDBus::~ScreenSaverDBus () { + setScreenSaverStatus(true); +} + +bool ScreenSaverDBus::getScreenSaverStatus () const { + return mScreenSaverStatus; +} + +void ScreenSaverDBus::setScreenSaverStatus (bool status) { + if (status == mScreenSaverStatus) + return; + + if (status) { + QDBusMessage reply(mBus.call("UnInhibit", mToken)); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << QStringLiteral("Uninhibit screen saver failed: `%1: %2`.") + .arg(reply.errorName()).arg(reply.errorMessage()); + return; + } + mToken = uint32_t(reply.arguments().first().toULongLong()); + mScreenSaverStatus = false; + emit screenSaverStatusChanged(mScreenSaverStatus); + return; + } + + QDBusMessage reply(mBus.call("Inhibit", QCoreApplication::applicationName())); + if (reply.type() == QDBusMessage::ErrorMessage) { + if (reply.errorName() != QLatin1String("org.freedesktop.DBus.Error.ServiceUnknown")) + qWarning() << QStringLiteral("Inhibit screen saver failed: `%1: %2`.") + .arg(reply.errorName()).arg(reply.errorMessage()); + return; + } + mScreenSaverStatus = true; + emit screenSaverStatusChanged(mScreenSaverStatus); +} diff --git a/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp b/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp new file mode 100644 index 000000000..34146edaf --- /dev/null +++ b/src/components/other/desktop-tools/screen-saver/ScreenSaverDBus.hpp @@ -0,0 +1,52 @@ +/* + * ScreenSaverDBus.hpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * 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 + * of the License, or (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: July 11, 2018 + * Author: Ronan Abhamon + */ + +#ifndef SCREEN_SAVER_DBUS_H_ +#define SCREEN_SAVER_DBUS_H_ + +#include + +// ============================================================================= + +class QDBusPendingCallWatcher; + +class ScreenSaverDBus : public QObject { + Q_OBJECT; + +public: + ScreenSaverDBus (QObject *parent = Q_NULLPTR); + ~ScreenSaverDBus (); + + bool getScreenSaverStatus () const; + void setScreenSaverStatus (bool status); + +signals: + void screenSaverStatusChanged (bool status); + +private: + bool mScreenSaverStatus = true; + + QDBusInterface mBus; + uint32_t mToken; +}; + +#endif // SCREEN_SAVER_DBUS_H_ diff --git a/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.cpp b/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.cpp new file mode 100644 index 000000000..beb3b38ca --- /dev/null +++ b/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.cpp @@ -0,0 +1,57 @@ +/* + * ScreenSaverXdg.cpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * 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 + * of the License, or (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 21, 2018 + * Author: Ronan Abhamon + */ + +#include + +#include "ScreenSaverXdg.hpp" + +// ============================================================================= + +namespace { + constexpr char Program[] = "xdg-screensaver"; + const QStringList Arguments{"reset"}; + + constexpr int Interval = 30000; +} + +ScreenSaverXdg::ScreenSaverXdg (QObject *parent) : QObject(parent) { + mTimer.setInterval(Interval); + QObject::connect(&mTimer, &QTimer::timeout, []() { + QProcess::startDetached(Program, Arguments); + }); +} + +bool ScreenSaverXdg::getScreenSaverStatus () const { + return !mTimer.isActive(); +} + +void ScreenSaverXdg::setScreenSaverStatus (bool status) { + if (status == !mTimer.isActive()) + return; + + if (status) + mTimer.stop(); + else + mTimer.start(); + + emit screenSaverStatusChanged(status); +} diff --git a/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp b/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp new file mode 100644 index 000000000..1f24ecc4a --- /dev/null +++ b/src/components/other/desktop-tools/screen-saver/ScreenSaverXdg.hpp @@ -0,0 +1,46 @@ +/* + * ScreenSaverXdg.hpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * 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 + * of the License, or (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: July 11, 2018 + * Author: Ronan Abhamon + */ + +#ifndef SCREEN_SAVER_XDG_H_ +#define SCREEN_SAVER_XDG_H_ + +#include + +// ============================================================================= + +class ScreenSaverXdg : public QObject { + Q_OBJECT; + +public: + ScreenSaverXdg (QObject *parent = Q_NULLPTR); + + bool getScreenSaverStatus () const; + void setScreenSaverStatus (bool status); + +signals: + void screenSaverStatusChanged (bool status); + +private: + QTimer mTimer; +}; + +#endif // SCREEN_SAVER_XDG_H_ diff --git a/src/utils/LinphoneUtils.cpp b/src/utils/LinphoneUtils.cpp index 02f99d234..02e9a0652 100644 --- a/src/utils/LinphoneUtils.cpp +++ b/src/utils/LinphoneUtils.cpp @@ -27,11 +27,11 @@ // ============================================================================= linphone::TransportType LinphoneUtils::stringToTransportType (const QString &transport) { - if (transport == "TCP") + if (transport == QLatin1String("TCP")) return linphone::TransportType::TransportTypeTcp; - if (transport == "UDP") + if (transport == QLatin1String("UDP")) return linphone::TransportType::TransportTypeUdp; - if (transport == "TLS") + if (transport == QLatin1String("TLS")) return linphone::TransportType::TransportTypeTls; return linphone::TransportType::TransportTypeDtls; diff --git a/src/utils/QExifImageHeader.cpp b/src/utils/QExifImageHeader.cpp index 732a9b61b..fc799f7c2 100644 --- a/src/utils/QExifImageHeader.cpp +++ b/src/utils/QExifImageHeader.cpp @@ -51,7 +51,7 @@ #include "Utils.hpp" -#include "QExifImageHeader.h" +#include "QExifImageHeader.hpp" /*! \typedef QExifSRational diff --git a/src/utils/QExifImageHeader.h b/src/utils/QExifImageHeader.hpp similarity index 100% rename from src/utils/QExifImageHeader.h rename to src/utils/QExifImageHeader.hpp