From 087ab7038d33093d5e517a72ddf9e2cb7a326276 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 26 Feb 2025 16:44:03 +0100 Subject: [PATCH 1/2] REFAC(client): boost classes replaced with std ones This commit replaces boost classes with its STL alternatives --- scripts/generate-ApplicationPalette-class.py | 4 ++-- scripts/generateIceWrapper.py | 6 ++---- src/mumble/ApplicationPaletteTemplate.h | 3 --- src/mumble/AudioInput.h | 7 ++----- src/mumble/AudioOutput.h | 5 +++-- src/mumble/Global.h | 11 +++++------ src/mumble/LookConfig.cpp | 12 +++++++----- src/mumble/LookConfig.h | 2 +- 8 files changed, 22 insertions(+), 28 deletions(-) diff --git a/scripts/generate-ApplicationPalette-class.py b/scripts/generate-ApplicationPalette-class.py index 564f9346516..a4f487a47cb 100755 --- a/scripts/generate-ApplicationPalette-class.py +++ b/scripts/generate-ApplicationPalette-class.py @@ -60,10 +60,10 @@ } """ -variable_template = """ boost::optional m_%(prop)s; +variable_template = """ std::optional m_%(prop)s; """ -reset_template = """ m_%(prop)s = boost::none; +reset_template = """ m_%(prop)s = std::nullopt_t; """ def rolename(role): diff --git a/scripts/generateIceWrapper.py b/scripts/generateIceWrapper.py index eaf2089833a..aa9fb016711 100755 --- a/scripts/generateIceWrapper.py +++ b/scripts/generateIceWrapper.py @@ -64,7 +64,7 @@ def generateFunction(className, functionName, wrapArgs, callArgs): function += "\t}\n" function += "#endif // ACCESS_" + className + "_" + functionName + "_ALL\n" function += "\n" - function += "\tExecEvent *ie = new ExecEvent(boost::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n" + function += "\tExecEvent *ie = new ExecEvent(std::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n" function += "\tQCoreApplication::instance()->postEvent(mi, ie);\n" function += "}\n" @@ -111,9 +111,7 @@ def main(): wrapperContent = create_disclaimerComment() - # Include boost-bind as we'll need it later - wrapperContent += "\n#include \n\n" - + wrapperContent +="\n#include \n\n" className = "" for currentLine in generatedIceHeader.split("\n"): diff --git a/src/mumble/ApplicationPaletteTemplate.h b/src/mumble/ApplicationPaletteTemplate.h index 93dd8b48220..7fa476a61a5 100644 --- a/src/mumble/ApplicationPaletteTemplate.h +++ b/src/mumble/ApplicationPaletteTemplate.h @@ -13,9 +13,6 @@ #include #include -#ifndef Q_MOC_RUN -# include -#endif #include #include diff --git a/src/mumble/AudioInput.h b/src/mumble/AudioInput.h index 5701b2ad85f..d44cc819a24 100644 --- a/src/mumble/AudioInput.h +++ b/src/mumble/AudioInput.h @@ -10,9 +10,6 @@ #include #include -#include -#include - #include #include #include @@ -34,7 +31,7 @@ class AudioInput; struct OpusEncoder; struct ReNameNoiseDenoiseState; -typedef boost::shared_ptr< AudioInput > AudioInputPtr; +typedef std::shared_ptr< AudioInput > AudioInputPtr; /** * A chunk of audio data to process @@ -195,7 +192,7 @@ class AudioInput : public QThread { bool selectCodec(); void selectNoiseCancel(); - typedef boost::array< unsigned char, 960 > EncodingOutputBuffer; + typedef std::array< unsigned char, 960 > EncodingOutputBuffer; int encodeOpusFrame(short *source, int size, EncodingOutputBuffer &buffer); diff --git a/src/mumble/AudioOutput.h b/src/mumble/AudioOutput.h index e71cda05a16..00046532857 100644 --- a/src/mumble/AudioOutput.h +++ b/src/mumble/AudioOutput.h @@ -8,7 +8,8 @@ #include #include -#include + +#include #include "MumbleProtocol.h" @@ -44,7 +45,7 @@ class ClientUser; class AudioOutputBuffer; class AudioOutputToken; -typedef boost::shared_ptr< AudioOutput > AudioOutputPtr; +typedef std::shared_ptr< AudioOutput > AudioOutputPtr; class AudioOutputRegistrar { private: diff --git a/src/mumble/Global.h b/src/mumble/Global.h index 255946bee36..2eb5e8c186a 100644 --- a/src/mumble/Global.h +++ b/src/mumble/Global.h @@ -7,7 +7,8 @@ #define MUMBLE_MUMBLE_GLOBAL_H_ #include -#include + +#include #include "ACL.h" #include "ChannelListenerManager.h" @@ -15,8 +16,6 @@ #include "Timer.h" #include "Version.h" -#include - // Global helper class to spread variables around across threads. class MainWindow; @@ -52,9 +51,9 @@ struct Global Q_DECL_FINAL { MainWindow *mw; TrayIcon *trayIcon; Settings s; - boost::shared_ptr< ServerHandler > sh; - boost::shared_ptr< AudioInput > ai; - boost::shared_ptr< AudioOutput > ao; + std::shared_ptr< ServerHandler > sh; + std::shared_ptr< AudioInput > ai; + std::shared_ptr< AudioOutput > ao; /** * @remark Must only be accessed from the main event loop */ diff --git a/src/mumble/LookConfig.cpp b/src/mumble/LookConfig.cpp index 939e4ed502c..797de6cd0ef 100644 --- a/src/mumble/LookConfig.cpp +++ b/src/mumble/LookConfig.cpp @@ -17,6 +17,8 @@ #include #include +#include + const QString LookConfig::name = QLatin1String("LookConfig"); static ConfigWidget *LookConfigNew(Settings &st) { @@ -39,7 +41,7 @@ LookConfig::LookConfig(Settings &st) : ConfigWidget(st) { qcbLanguage->addItem(tr("System default")); QDir d(QLatin1String(":"), QLatin1String("mumble_*.qm"), QDir::Name, QDir::Files); - foreach (const QString &key, d.entryList()) { + for (const QString &key : d.entryList()) { QString cc = key.mid(7, key.indexOf(QLatin1Char('.')) - 7); QLocale tmpLocale = QLocale(cc); @@ -117,7 +119,7 @@ QIcon LookConfig::icon() const { return QIcon(QLatin1String("skin:config_ui.png")); } -void LookConfig::reloadThemes(const boost::optional< ThemeInfo::StyleInfo > configuredStyle) { +void LookConfig::reloadThemes(const std::optional< ThemeInfo::StyleInfo > configuredStyle) { const ThemeMap themes = Themes::getThemes(); int selectedThemeEntry = 0; @@ -193,7 +195,7 @@ void LookConfig::load(const Settings &r) { loadCheckBox(qcbChatBarUseSelection, r.bChatBarUseSelection); loadCheckBox(qcbFilterHidesEmptyChannels, r.bFilterHidesEmptyChannels); - const boost::optional< ThemeInfo::StyleInfo > configuredStyle = Themes::getConfiguredStyle(r); + const std::optional< ThemeInfo::StyleInfo > configuredStyle = Themes::getConfiguredStyle(r); reloadThemes(configuredStyle); loadCheckBox(qcbUsersAlwaysVisible, r.talkingUI_UsersAlwaysVisible); @@ -263,7 +265,7 @@ void LookConfig::save() const { QVariant themeData = qcbTheme->itemData(qcbTheme->currentIndex()); if (themeData.isNull()) { - Themes::setConfiguredStyle(s, boost::none, s.requireRestartToApply); + Themes::setConfiguredStyle(s, std::nullopt, s.requireRestartToApply); } else { Themes::setConfiguredStyle(s, themeData.value< ThemeInfo::StyleInfo >(), s.requireRestartToApply); } @@ -297,7 +299,7 @@ void LookConfig::themeDirectoryChanged() { qWarning() << "Theme directory changed"; QVariant themeData = qcbTheme->itemData(qcbTheme->currentIndex()); if (themeData.isNull()) { - reloadThemes(boost::none); + reloadThemes(std::nullopt); } else { reloadThemes(themeData.value< ThemeInfo::StyleInfo >()); } diff --git a/src/mumble/LookConfig.h b/src/mumble/LookConfig.h index 49d81f1b10d..83fd9a06a11 100644 --- a/src/mumble/LookConfig.h +++ b/src/mumble/LookConfig.h @@ -36,7 +36,7 @@ public slots: private: /// Reload themes combobox and select given configuredStyle in it - void reloadThemes(const boost::optional< ThemeInfo::StyleInfo > configuredStyle); + void reloadThemes(const std::optional< ThemeInfo::StyleInfo > configuredStyle); /// Timer to prevent change event floods from triggering theme reloads QTimer *m_themeDirectoryDebouncer; From 38212d951d74e49823c5b37f31fa6bb5a02e8947 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 27 Feb 2025 09:48:25 +0100 Subject: [PATCH 2/2] REFAC(client,server): boost calls replaced with STL equivalents This commit replaces boost calls that can be simply replaced with STL ones --- CMakeLists.txt | 2 +- scripts/generate-ApplicationPalette-class.py | 2 +- src/Timer.cpp | 82 +------------------- src/User.h | 8 +- src/mumble/AudioOutput.cpp | 8 +- src/mumble/ConnectDialog.cpp | 5 +- src/mumble/LookConfig.cpp | 2 +- src/mumble/LookConfig.h | 2 +- src/mumble/ServerHandler.h | 9 ++- src/mumble/Settings.cpp | 43 +++------- src/mumble/ThemeInfo.cpp | 38 ++++----- src/mumble/ThemeInfo.h | 8 +- src/mumble/Themes.cpp | 12 +-- src/mumble/Themes.h | 9 +-- src/mumble/VoiceRecorder.cpp | 48 +++++++----- src/mumble/VoiceRecorder.h | 25 +++--- src/murmur/Server.cpp | 8 +- src/murmur/Server.h | 8 +- 18 files changed, 106 insertions(+), 213 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14485a3885e..7f75aa238b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ list(APPEND CMAKE_MODULE_PATH ) if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) endif() set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) diff --git a/scripts/generate-ApplicationPalette-class.py b/scripts/generate-ApplicationPalette-class.py index a4f487a47cb..48bd592557e 100755 --- a/scripts/generate-ApplicationPalette-class.py +++ b/scripts/generate-ApplicationPalette-class.py @@ -63,7 +63,7 @@ variable_template = """ std::optional m_%(prop)s; """ -reset_template = """ m_%(prop)s = std::nullopt_t; +reset_template = """ m_%(prop)s = std::nullopt; """ def rolename(role): diff --git a/src/Timer.cpp b/src/Timer.cpp index f2b6e700765..c5aa3b6909b 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -3,24 +3,8 @@ // that can be found in the LICENSE file at the root of the // Mumble source tree or at . -#include - -// Not all Boost versions can use a header-only -// boost_system without build failures. -// -// See mumble-voip/mumble#2366. -// -// This was fixed in Boost 1.56.0. -// -// See: -// https://github.com/boostorg/system/blob/boost-1.56.0/include/boost/system/error_code.hpp#L514-L516 -// vs. -// https://github.com/boostorg/system/blob/boost-1.55.0/include/boost/system/error_code.hpp#L515-L517 -#if BOOST_VERSION >= 105600 && !defined(__MINGW32__) -# define USE_BOOST_CHRONO -#endif - #include "Timer.h" +#include Timer::Timer(bool start) { uiStart = start ? now() : 0; @@ -59,68 +43,6 @@ bool Timer::operator>(const Timer &other) const { return uiStart < other.uiStart; } -#ifdef USE_BOOST_CHRONO -// Ensure boost_system is header only. -# define BOOST_ERROR_CODE_HEADER_ONLY -// Ensure boost_chrono is header only. -# define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING -# define BOOST_CHRONO_HEADER_ONLY - -# include - -quint64 Timer::now() { - using namespace boost::chrono; - time_point< steady_clock > now = steady_clock::now(); - time_point< steady_clock >::duration epochDuration = now.time_since_epoch(); - microseconds epochDurationUsec = duration_cast< microseconds >(epochDuration); - return static_cast< quint64 >(epochDurationUsec.count()); -} -#elif defined(Q_OS_WIN) -# include "win.h" - -quint64 Timer::now() { - static double scale = 0; - - if (scale == 0) { - LARGE_INTEGER freq; - QueryPerformanceFrequency(&freq); - scale = 1000000. / freq.QuadPart; - } - - LARGE_INTEGER li; - QueryPerformanceCounter(&li); - quint64 e = li.QuadPart; - - return static_cast< quint64 >(e * scale); -} -#elif defined(Q_OS_UNIX) -# include -# include -# include -# include -# if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) -quint64 Timer::now() { - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { - qFatal("Timer: clock_gettime() failed: (%i) %s", errno, strerror(errno)); - } - quint64 e = ts.tv_sec * 1000000LL; - e += ts.tv_nsec / 1000LL; - return e; -} -# else -quint64 Timer::now() { - struct timeval tv; - gettimeofday(&tv, nullptr); - quint64 e = tv.tv_sec * 1000000LL; - e += tv.tv_usec; - return e; -} -# endif -#else quint64 Timer::now() { - static QTime ticker; - quint64 elapsed = ticker.elapsed(); - return elapsed * 1000LL; + return static_cast(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); } -#endif diff --git a/src/User.h b/src/User.h index 87a22bd7777..b5c477de4f8 100644 --- a/src/User.h +++ b/src/User.h @@ -6,15 +6,13 @@ #ifndef MUMBLE_USER_H_ #define MUMBLE_USER_H_ -#ifndef Q_MOC_RUN -# include -#endif - #include #include #include #include +#include + class Channel; class User { @@ -46,7 +44,7 @@ class User { struct UserInfo { int user_id; QString name; - boost::optional< int > last_channel; + std::optional< int > last_channel; QDateTime last_active; UserInfo() : user_id(-1) {} diff --git a/src/mumble/AudioOutput.cpp b/src/mumble/AudioOutput.cpp index f24137ae850..85b702cae2b 100644 --- a/src/mumble/AudioOutput.cpp +++ b/src/mumble/AudioOutput.cpp @@ -58,7 +58,7 @@ AudioOutputPtr AudioOutputRegistrar::newFromChoice(QString choice) { } AudioOutputRegistrar *r = nullptr; - foreach (AudioOutputRegistrar *aor, *qmNew) + for (AudioOutputRegistrar *aor : *qmNew) if (!r || (aor->priority > r->priority)) r = aor; if (r) { @@ -508,9 +508,9 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) { bool validListener = false; // Initialize recorder if recording is enabled - boost::shared_array< float > recbuff; + std::shared_ptr recbuff; if (recorder) { - recbuff = boost::shared_array< float >(new float[frameCount]); + recbuff = std::make_shared(frameCount); memset(recbuff.get(), 0, sizeof(float) * frameCount); recorder->prepareBufferAdds(); } @@ -654,7 +654,7 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) { if (!recorder->isInMixDownMode()) { recorder->addBuffer(speech->p, recbuff, static_cast< int >(frameCount)); - recbuff = boost::shared_array< float >(new float[frameCount]); + recbuff = std::make_shared(frameCount); memset(recbuff.get(), 0, sizeof(float) * frameCount); } diff --git a/src/mumble/ConnectDialog.cpp b/src/mumble/ConnectDialog.cpp index 2f667eed8cf..958b0f32e5e 100644 --- a/src/mumble/ConnectDialog.cpp +++ b/src/mumble/ConnectDialog.cpp @@ -33,7 +33,8 @@ #include #include -#include + +#include #ifdef Q_OS_WIN # ifndef NOMINMAX @@ -61,7 +62,7 @@ PingStats::~PingStats() { } void PingStats::init() { - boost::array< double, 3 > probs = { { 0.75, 0.80, 0.95 } }; + std::array< double, 3 > probs = { { 0.75, 0.80, 0.95 } }; asQuantile = new asQuantileType(boost::accumulators::tag::extended_p_square::probabilities = probs); dPing = 0.0; diff --git a/src/mumble/LookConfig.cpp b/src/mumble/LookConfig.cpp index 797de6cd0ef..1dadc862968 100644 --- a/src/mumble/LookConfig.cpp +++ b/src/mumble/LookConfig.cpp @@ -119,7 +119,7 @@ QIcon LookConfig::icon() const { return QIcon(QLatin1String("skin:config_ui.png")); } -void LookConfig::reloadThemes(const std::optional< ThemeInfo::StyleInfo > configuredStyle) { +void LookConfig::reloadThemes(const std::optional< ThemeInfo::StyleInfo >& configuredStyle) { const ThemeMap themes = Themes::getThemes(); int selectedThemeEntry = 0; diff --git a/src/mumble/LookConfig.h b/src/mumble/LookConfig.h index 83fd9a06a11..69a1d4d2938 100644 --- a/src/mumble/LookConfig.h +++ b/src/mumble/LookConfig.h @@ -36,7 +36,7 @@ public slots: private: /// Reload themes combobox and select given configuredStyle in it - void reloadThemes(const std::optional< ThemeInfo::StyleInfo > configuredStyle); + void reloadThemes(const std::optional< ThemeInfo::StyleInfo >& configuredStyle); /// Timer to prevent change event floods from triggering theme reloads QTimer *m_themeDirectoryDebouncer; diff --git a/src/mumble/ServerHandler.h b/src/mumble/ServerHandler.h index 3c3c4244168..86d8fa2da7a 100644 --- a/src/mumble/ServerHandler.h +++ b/src/mumble/ServerHandler.h @@ -17,9 +17,10 @@ # include # include # include -# include #endif +#include + #include #include #include @@ -52,7 +53,7 @@ class ServerHandlerMessageEvent : public QEvent { ServerHandlerMessageEvent(const QByteArray &msg, Mumble::Protocol::TCPMessageType type, bool flush = false); }; -typedef boost::shared_ptr< Connection > ConnectionPtr; +typedef std::shared_ptr< Connection > ConnectionPtr; class ServerHandler : public QThread { private: @@ -102,7 +103,7 @@ class ServerHandler : public QThread { QSslCipher qscCipher; ConnectionPtr cConnection; QByteArray qbaDigest; - boost::shared_ptr< VoiceRecorder > recorder; + std::shared_ptr< VoiceRecorder > recorder; QSslSocket *qtsSock; QList< ServerAddress > qlAddresses; QHash< ServerAddress, QString > qhHostnames; @@ -208,6 +209,6 @@ public slots: void sendPing(); }; -typedef boost::shared_ptr< ServerHandler > ServerHandlerPtr; +typedef std::shared_ptr< ServerHandler > ServerHandlerPtr; #endif diff --git a/src/mumble/Settings.cpp b/src/mumble/Settings.cpp index 4a02bc0908a..854069aa8b7 100644 --- a/src/mumble/Settings.cpp +++ b/src/mumble/Settings.cpp @@ -34,8 +34,6 @@ #include #include -#include - #include #include #include @@ -94,7 +92,7 @@ std::size_t qHash(const ShortcutTarget &t) { } if (t.bUsers) { - foreach (unsigned int u, t.qlSessions) + for (unsigned int u : t.qlSessions) h ^= u; } else { h ^= static_cast< unsigned int >(t.iChannel); @@ -110,7 +108,7 @@ std::size_t qHash(const ShortcutTarget &t) { std::size_t qHash(const QList< ShortcutTarget > &l) { auto h = static_cast< std::size_t >(l.count()); - foreach (const ShortcutTarget &st, l) + for (const ShortcutTarget& st : l) h ^= qHash(st); return h; } @@ -631,36 +629,13 @@ void OverlaySettings::load(const QString &filename) { } } -#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() - - -BOOST_TYPEOF_REGISTER_TYPE(Qt::Alignment) -BOOST_TYPEOF_REGISTER_TYPE(Settings::AudioTransmit) -BOOST_TYPEOF_REGISTER_TYPE(Settings::VADSource) -BOOST_TYPEOF_REGISTER_TYPE(Settings::LoopMode) -BOOST_TYPEOF_REGISTER_TYPE(Settings::OverlayShow) -BOOST_TYPEOF_REGISTER_TYPE(Settings::ProxyType) -BOOST_TYPEOF_REGISTER_TYPE(Settings::ChannelExpand) -BOOST_TYPEOF_REGISTER_TYPE(Settings::ChannelDrag) -BOOST_TYPEOF_REGISTER_TYPE(Settings::ServerShow) -BOOST_TYPEOF_REGISTER_TYPE(Settings::NoiseCancel) -BOOST_TYPEOF_REGISTER_TYPE(Settings::WindowLayout) -BOOST_TYPEOF_REGISTER_TYPE(Settings::AlwaysOnTopBehaviour) -BOOST_TYPEOF_REGISTER_TYPE(Settings::RecordingMode) -BOOST_TYPEOF_REGISTER_TYPE(QString) -BOOST_TYPEOF_REGISTER_TYPE(QByteArray) -BOOST_TYPEOF_REGISTER_TYPE(QColor) -BOOST_TYPEOF_REGISTER_TYPE(QVariant) -BOOST_TYPEOF_REGISTER_TYPE(QFont) -BOOST_TYPEOF_REGISTER_TYPE(EchoCancelOptionID) -BOOST_TYPEOF_REGISTER_TEMPLATE(QList, 1) - - -#define LOAD(var, name) var = qvariant_cast< BOOST_TYPEOF(var) >(settings_ptr->value(QLatin1String(name), var)) +#define TYPEOF(var) std::remove_reference::type>::type + +#define LOAD(var, name) var = qvariant_cast< TYPEOF(var) >(settings_ptr->value(QLatin1String(name), var)) #define LOADENUM(var, name) \ - var = static_cast< BOOST_TYPEOF(var) >(settings_ptr->value(QLatin1String(name), var).toInt()) + var = static_cast< TYPEOF(var) >(settings_ptr->value(QLatin1String(name), var).toInt()) #define LOADFLAG(var, name) \ - var = static_cast< BOOST_TYPEOF(var) >(settings_ptr->value(QLatin1String(name), static_cast< int >(var)).toInt()) + var = static_cast< TYPEOF(var) >(settings_ptr->value(QLatin1String(name), static_cast< int >(var)).toInt()) #define DEPRECATED(name) \ do { \ } while (0) @@ -1088,14 +1063,14 @@ void Settings::legacyLoad(const QString &path) { settings_ptr->endArray(); settings_ptr->beginGroup(QLatin1String("lcd/devices")); - foreach (const QString &d, settings_ptr->childKeys()) { + for (const QString &d : settings_ptr->childKeys()) { qmLCDDevices.insert(d, settings_ptr->value(d, true).toBool()); } settings_ptr->endGroup(); // Plugins settings_ptr->beginGroup(QLatin1String("plugins")); - foreach (const QString &pluginKey, settings_ptr->childGroups()) { + for (const QString &pluginKey : settings_ptr->childGroups()) { QString pluginHash; if (pluginKey.contains(QLatin1String("_"))) { diff --git a/src/mumble/ThemeInfo.cpp b/src/mumble/ThemeInfo.cpp index b655b77adec..0de647780e2 100644 --- a/src/mumble/ThemeInfo.cpp +++ b/src/mumble/ThemeInfo.cpp @@ -22,7 +22,7 @@ QFileInfo ThemeInfo::StyleInfo::getPlatformQss() const { #endif } -boost::optional< ThemeInfo::StyleInfo > readStyleFromConfig(QSettings &themeConfig, const QString &styleId, +std::optional< ThemeInfo::StyleInfo > readStyleFromConfig(QSettings &themeConfig, const QString &styleId, const ThemeInfo &theme, const QDir &themeDir) { const QRegularExpression qssPlatformRegex(QString::fromLatin1("^%1/qss_(.*)").arg(styleId)); @@ -35,23 +35,23 @@ boost::optional< ThemeInfo::StyleInfo > readStyleFromConfig(QSettings &themeConf if (style.name.isNull()) { qWarning() << "Style " << styleId << " of theme" << theme.name << " has no name, skipping theme"; - return boost::none; + return {}; } if (!style.defaultQss.exists() || !style.defaultQss.isFile()) { qWarning() << "Style " << style.name << " of theme " << theme.name << " references invalid qss " << style.defaultQss.filePath() << ", skipping theme"; - return boost::none; + return {}; } - foreach (const QString &platformQssConfig, themeConfig.allKeys().filter(qssPlatformRegex)) { + for (const QString &platformQssConfig : themeConfig.allKeys().filter(qssPlatformRegex)) { const QString platform = qssPlatformRegex.match(platformQssConfig).captured(1); const auto platformQss = QFileInfo(themeDir.filePath(themeConfig.value(platformQssConfig).toString())); if (!platformQss.exists() || !platformQss.isFile()) { qWarning() << "Style" << style.name << " of theme " << theme.name << " references invalid qss " << platformQss.filePath() << " for platform " << platform << ", skipping theme"; - return boost::none; + return {}; } style.qssFiles.insert(platform, platformQss); @@ -60,14 +60,14 @@ boost::optional< ThemeInfo::StyleInfo > readStyleFromConfig(QSettings &themeConf return style; } -boost::optional< ThemeInfo > loadLegacyThemeInfo(const QDir &themeDirectory) { +std::optional< ThemeInfo > loadLegacyThemeInfo(const QDir &themeDirectory) { ThemeInfo theme; theme.name = themeDirectory.dirName(); QStringList filters; filters << QLatin1String("*.qss"); - foreach (const QFileInfo &qssFile, themeDirectory.entryInfoList(filters, QDir::Files)) { + for (const QFileInfo &qssFile : themeDirectory.entryInfoList(filters, QDir::Files)) { ThemeInfo::StyleInfo style; style.name = qssFile.baseName(); style.themeName = theme.name; @@ -78,7 +78,7 @@ boost::optional< ThemeInfo > loadLegacyThemeInfo(const QDir &themeDirectory) { if (theme.styles.isEmpty()) { qWarning() << themeDirectory.absolutePath() << " does not seem to contain a old-style theme, skipping"; - return boost::none; + return {}; } theme.defaultStyle = theme.styles.begin()->name; @@ -86,7 +86,7 @@ boost::optional< ThemeInfo > loadLegacyThemeInfo(const QDir &themeDirectory) { return theme; } -boost::optional< ThemeInfo > ThemeInfo::load(const QDir &themeDirectory) { +std::optional< ThemeInfo > ThemeInfo::load(const QDir &themeDirectory) { QFile themeFile(themeDirectory.absoluteFilePath(QLatin1String("theme.ini"))); if (!themeFile.exists()) { qWarning() << "Directory " << themeDirectory.absolutePath() << " has no theme.ini, trying fallback"; @@ -97,7 +97,7 @@ boost::optional< ThemeInfo > ThemeInfo::load(const QDir &themeDirectory) { QSettings themeConfig(themeFile.fileName(), QSettings::IniFormat); if (themeConfig.status() != QSettings::NoError) { qWarning() << "Failed to load theme config from " << themeFile.fileName() << ", skipping"; - return boost::none; + return {}; } ThemeInfo theme; @@ -108,19 +108,19 @@ boost::optional< ThemeInfo > ThemeInfo::load(const QDir &themeDirectory) { if (theme.name.isNull()) { qWarning() << "Theme in " << themeFile.fileName() << " does not have a name, skipping"; - return boost::none; + return {}; } if (styleIds.isEmpty()) { qWarning() << "Theme " << theme.name << " doesn't have any styles, skipping"; - return boost::none; + return {}; } - foreach (const QString &styleId, styleIds) { - boost::optional< ThemeInfo::StyleInfo > style = + for (const QString &styleId : styleIds) { + std::optional< ThemeInfo::StyleInfo > style = readStyleFromConfig(themeConfig, styleId, theme, themeDirectory); if (!style) { - return boost::none; + return {}; } theme.styles.insert(style->name, *style); } @@ -140,10 +140,10 @@ ThemeInfo::StyleInfo ThemeInfo::getStyle(QString name_) const { ThemeMap ThemeInfo::scanDirectory(const QDir &themesDirectory) { ThemeMap themes; - foreach (const QFileInfo &subdirInfo, themesDirectory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot)) { + for (const QFileInfo &subdirInfo : themesDirectory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot)) { QDir subdir(subdirInfo.absoluteFilePath()); - boost::optional< ThemeInfo > theme = ThemeInfo::load(subdir); + std::optional< ThemeInfo > theme = ThemeInfo::load(subdir); if (!theme) { continue; } @@ -157,8 +157,8 @@ ThemeMap ThemeInfo::scanDirectory(const QDir &themesDirectory) { ThemeMap ThemeInfo::scanDirectories(const QVector< QDir > &themesDirectories) { ThemeMap themes; - foreach (const QDir &themesDirectory, themesDirectories) { - foreach (const ThemeInfo &theme, scanDirectory(themesDirectory)) { themes.insert(theme.name, theme); } + for (const QDir &themesDirectory : themesDirectories) { + for (const ThemeInfo &theme : scanDirectory(themesDirectory)) { themes.insert(theme.name, theme); } } return themes; diff --git a/src/mumble/ThemeInfo.h b/src/mumble/ThemeInfo.h index 10cfc069790..0fe56d7ccb8 100644 --- a/src/mumble/ThemeInfo.h +++ b/src/mumble/ThemeInfo.h @@ -10,10 +10,6 @@ #include #include #include -#ifndef Q_MOC_RUN -# include -#endif - class QSettings; class QDir; @@ -69,8 +65,8 @@ class ThemeInfo { /// Loads the theme description from a given directory /// /// @param themeDirectory - /// @return Theme if description was correctly loaded. boost::none if not. - static boost::optional< ThemeInfo > load(const QDir &themeDirectory); + /// @return Theme if description was correctly loaded. std::nullopt if not. + static std::optional< ThemeInfo > load(const QDir &themeDirectory); /// @return Style with given name or default StyleInfo getStyle(QString name_) const; diff --git a/src/mumble/Themes.cpp b/src/mumble/Themes.cpp index 4b1a121c44d..f072c8fc9fb 100644 --- a/src/mumble/Themes.cpp +++ b/src/mumble/Themes.cpp @@ -8,29 +8,29 @@ #include "MumbleApplication.h" #include "Global.h" -boost::optional< ThemeInfo::StyleInfo > Themes::getConfiguredStyle(const Settings &settings) { +std::optional< ThemeInfo::StyleInfo > Themes::getConfiguredStyle(const Settings &settings) { if (settings.themeName.isEmpty() && settings.themeStyleName.isEmpty()) { - return boost::none; + return std::nullopt; } const ThemeMap themes = getThemes(); ThemeMap::const_iterator themeIt = themes.find(settings.themeName); if (themeIt == themes.end()) { qWarning() << "Could not find configured theme" << settings.themeName; - return boost::none; + return std::nullopt; } ThemeInfo::StylesMap::const_iterator styleIt = themeIt->styles.find(settings.themeStyleName); if (styleIt == themeIt->styles.end()) { qWarning() << "Configured theme" << settings.themeName << "does not have configured style" << settings.themeStyleName; - return boost::none; + return std::nullopt; } return *styleIt; } -void Themes::setConfiguredStyle(Settings &settings, boost::optional< ThemeInfo::StyleInfo > style, bool &outChanged) { +void Themes::setConfiguredStyle(Settings &settings, std::optional< ThemeInfo::StyleInfo > style, bool &outChanged) { if (style) { if (settings.themeName != style->themeName || settings.themeStyleName != style->name) { settings.themeName = style->themeName; @@ -55,7 +55,7 @@ void Themes::applyFallback() { } bool Themes::applyConfigured() { - boost::optional< ThemeInfo::StyleInfo > style = Themes::getConfiguredStyle(Global::get().s); + std::optional< ThemeInfo::StyleInfo > style = Themes::getConfiguredStyle(Global::get().s); if (!style) { return false; } diff --git a/src/mumble/Themes.h b/src/mumble/Themes.h index 000fd09b57c..2e95f4160e1 100644 --- a/src/mumble/Themes.h +++ b/src/mumble/Themes.h @@ -8,14 +8,13 @@ #include #include -#ifndef Q_MOC_RUN -# include -#endif + +#include class Themes { public: /// Returns the style configured in the given settings structure - static boost::optional< ThemeInfo::StyleInfo > getConfiguredStyle(const Settings &settings); + static std::optional< ThemeInfo::StyleInfo > getConfiguredStyle(const Settings &settings); /// Updates the given settings object to be configured to the given style /// @@ -24,7 +23,7 @@ class Themes { /// @param settings Settings object to update /// @param style Style to set /// @param outChanged Will be set to true if the style in settings actually changed. Will not be changed otherwise. - static void setConfiguredStyle(Settings &settings, boost::optional< ThemeInfo::StyleInfo > style, bool &outChanged); + static void setConfiguredStyle(Settings &settings, std::optional< ThemeInfo::StyleInfo > style, bool &outChanged); /// Applies the theme /// diff --git a/src/mumble/VoiceRecorder.cpp b/src/mumble/VoiceRecorder.cpp index 192a0eef975..b2ba76180b9 100644 --- a/src/mumble/VoiceRecorder.cpp +++ b/src/mumble/VoiceRecorder.cpp @@ -12,11 +12,9 @@ #include "../Timer.h" -#include - #include -VoiceRecorder::RecordBuffer::RecordBuffer(int recordInfoIndex_, boost::shared_array< float > buffer_, int samples_, +VoiceRecorder::RecordBuffer::RecordBuffer(int recordInfoIndex_, std::shared_ptr< float[] > buffer_, int samples_, quint64 absoluteStartSample_) : recordInfoIndex(recordInfoIndex_), buffer(buffer_), samples(samples_), absoluteStartSample(absoluteStartSample_) { @@ -117,18 +115,29 @@ QString VoiceRecorder::expandTemplateVariables(const QString &path, const QStrin // Reassemble and expand bool first = true; - foreach (QString str, comp) { + + for (const QString& str : comp) + { bool replacements = false; + QString tmp; tmp.reserve(str.length() * 2); - for (decltype(str.size()) i = 0; i < str.size(); ++i) { + + for (decltype(str.size()) i = 0; i < str.size(); ++i) + { bool replaced = false; - if (str[i] == QLatin1Char('%')) { + + if (str[i] == QLatin1Char('%')) + { QHashIterator< const QString, QString > it(vars); - while (it.hasNext()) { + + while (it.hasNext()) + { it.next(); - if (str.mid(i + 1, it.key().length()) == it.key()) { + + if (str.mid(i + 1, it.key().length()) == it.key()) + { i += it.key().length(); tmp += it.value(); replaced = true; @@ -142,18 +151,19 @@ QString VoiceRecorder::expandTemplateVariables(const QString &path, const QStrin tmp += str[i]; } - str = tmp; + QString part = tmp; if (replacements) - str = sanitizeFilenameOrPathComponent(str); + part = sanitizeFilenameOrPathComponent(part); if (first) { first = false; - res.append(str); + res.append(part); } else { - res.append(QLatin1Char('/') + str); + res.append(QLatin1Char('/') + part); } } + return res; } @@ -245,7 +255,7 @@ SF_INFO VoiceRecorder::createSoundFileInfo() const { return sfinfo; } -bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_ptr< RecordInfo > &ri) { +bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, std::shared_ptr< RecordInfo > &ri) { if (ri->soundFile) { // Nothing to do return true; @@ -327,7 +337,7 @@ void VoiceRecorder::run() { } while (!m_abort && !m_recordBuffer.isEmpty()) { - boost::shared_ptr< RecordBuffer > rb; + std::shared_ptr< RecordBuffer > rb; { QMutexLocker l(&m_bufferLock); rb = m_recordBuffer.takeFirst(); @@ -336,7 +346,7 @@ void VoiceRecorder::run() { // Create the file for this RecordInfo instance if it's not yet open. Q_ASSERT(m_recordInfo.contains(rb->recordInfoIndex)); - boost::shared_ptr< RecordInfo > ri = m_recordInfo.value(rb->recordInfoIndex); + std::shared_ptr< RecordInfo > ri = m_recordInfo.value(rb->recordInfoIndex); if (!ensureFileIsOpenedFor(soundFileInfo, ri)) { return; @@ -405,7 +415,7 @@ void VoiceRecorder::prepareBufferAdds() { m_absoluteSampleEstimation = (m_timestamp->elapsed() / 1000) * (static_cast< quint64 >(m_config.sampleRate) / 1000); } -void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array< float > buffer, int samples) { +void VoiceRecorder::addBuffer(const ClientUser *clientUser, std::shared_ptr buffer, int samples) { Q_ASSERT(!m_config.mixDownMode || !clientUser); if (!m_recording) @@ -415,8 +425,7 @@ void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array< const int index = indexForUser(clientUser); if (!m_recordInfo.contains(index)) { - boost::shared_ptr< RecordInfo > ri = - boost::make_shared< RecordInfo >(m_config.mixDownMode ? QLatin1String("Mixdown") : clientUser->qsName); + std::shared_ptr< RecordInfo > ri(new RecordInfo(m_config.mixDownMode ? QLatin1String("Mixdown") : clientUser->qsName)); m_recordInfo.insert(index, ri); } @@ -424,8 +433,7 @@ void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array< { // Save the buffer in |qlRecordBuffer|. QMutexLocker l(&m_bufferLock); - boost::shared_ptr< RecordBuffer > rb = - boost::make_shared< RecordBuffer >(index, buffer, samples, m_absoluteSampleEstimation); + std::shared_ptr< RecordBuffer > rb(new RecordBuffer(index, buffer, samples, m_absoluteSampleEstimation)); m_recordBuffer << rb; } diff --git a/src/mumble/VoiceRecorder.h b/src/mumble/VoiceRecorder.h index 91da1d5e3e3..d30f9674f2a 100644 --- a/src/mumble/VoiceRecorder.h +++ b/src/mumble/VoiceRecorder.h @@ -12,11 +12,6 @@ # include "win.h" #endif -#ifndef Q_MOC_RUN -# include -# include -#endif - #include #include #include @@ -30,6 +25,8 @@ #include +#include + class ClientUser; class RecordUser; class Timer; @@ -114,7 +111,7 @@ class VoiceRecorder : public QThread { /// The audio data will be assumed to be recorded at the time /// prepareBufferAdds was last called. /// @param clientUser User for which to add the audio data. nullptr in mixdown mode. - void addBuffer(const ClientUser *clientUser, boost::shared_array< float > buffer, int samples); + void addBuffer(const ClientUser *clientUser, std::shared_ptr buffer, int samples); /// Returns the elapsed time since the recording started. quint64 getElapsedTime() const; @@ -137,14 +134,14 @@ class VoiceRecorder : public QThread { /// Stores information about a recording buffer. struct RecordBuffer { /// Constructs a new RecordBuffer object. - RecordBuffer(int recordInfoIndex_, boost::shared_array< float > buffer_, int samples_, + RecordBuffer(int recordInfoIndex_, std::shared_ptr buffer_, int samples_, quint64 absoluteStartSample_); /// Hashmap index for the user const int recordInfoIndex; /// The buffer. - boost::shared_array< float > buffer; + std::shared_ptr buffer; /// The number of samples in the buffer. int samples; @@ -168,7 +165,7 @@ class VoiceRecorder : public QThread { quint64 lastWrittenAbsoluteSample; }; - typedef QHash< int, boost::shared_ptr< RecordInfo > > RecordInfoMap; + typedef QHash< int, std::shared_ptr< RecordInfo > > RecordInfoMap; /// Removes invalid characters in a path component. QString sanitizeFilenameOrPathComponent(const QString &str) const; @@ -184,20 +181,20 @@ class VoiceRecorder : public QThread { /// Opens the file for the given recording information /// Helper function for run method. Will abort recording on failure. - bool ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_ptr< RecordInfo > &ri); + bool ensureFileIsOpenedFor(SF_INFO &soundFileInfo, std::shared_ptr< RecordInfo > &ri); /// Hash which maps the |uiSession| of all users for which we have to keep a recording state to the corresponding /// RecordInfo object. RecordInfoMap m_recordInfo; /// List containing all unprocessed RecordBuffer objects. - QList< boost::shared_ptr< RecordBuffer > > m_recordBuffer; + QList< std::shared_ptr< RecordBuffer > > m_recordBuffer; /// The user which is used to record local audio. - boost::scoped_ptr< RecordUser > m_recordUser; + std::unique_ptr< RecordUser > m_recordUser; /// High precision timer for buffer timestamps. - boost::scoped_ptr< Timer > m_timestamp; + std::unique_ptr< Timer > m_timestamp; /// Protects the buffer list |qlRecordBuffer|. QMutex m_bufferLock; @@ -222,6 +219,6 @@ class VoiceRecorder : public QThread { quint64 m_absoluteSampleEstimation; }; -typedef boost::shared_ptr< VoiceRecorder > VoiceRecorderPtr; +typedef std::shared_ptr< VoiceRecorder > VoiceRecorderPtr; #endif diff --git a/src/murmur/Server.cpp b/src/murmur/Server.cpp index 64e07f91519..f007c428f8f 100644 --- a/src/murmur/Server.cpp +++ b/src/murmur/Server.cpp @@ -36,8 +36,6 @@ #include #include -#include - #include "TracyConstants.h" #include #include @@ -55,7 +53,7 @@ # include #endif -ExecEvent::ExecEvent(boost::function< void() > f) : QEvent(static_cast< QEvent::Type >(EXEC_QEVENT)) { +ExecEvent::ExecEvent(std::function< void() > f) : QEvent(static_cast< QEvent::Type >(EXEC_QEVENT)) { func = f; } @@ -1652,7 +1650,7 @@ void Server::connectionClosed(QAbstractSocket::SocketError err, const QString &r if (old && old->bTemporary && old->qlUsers.isEmpty()) QCoreApplication::instance()->postEvent(this, - new ExecEvent(boost::bind(&Server::removeChannel, this, old->iId))); + new ExecEvent([&]()->void { this->removeChannel(old->iId);})); if (u->uiSession > 0 && u->uiSession < iMaxUsers * 2) qqIds.enqueue(u->uiSession); // Reinsert session id into pool @@ -1965,7 +1963,7 @@ void Server::userEnterChannel(User *p, Channel *c, MumbleProto::UserState &mpus) if (old && old->bTemporary && old->qlUsers.isEmpty()) { QCoreApplication::instance()->postEvent(this, - new ExecEvent(boost::bind(&Server::removeChannel, this, old->iId))); + new ExecEvent([&]()->void{ this->removeChannel(old->iId);})); } sendClientPermission(static_cast< ServerUser * >(p), c); diff --git a/src/murmur/Server.h b/src/murmur/Server.h index 031e0fa33be..3eb22424b13 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -24,9 +24,7 @@ #include "Version.h" #include "VolumeAdjustment.h" -#ifndef Q_MOC_RUN -# include -#endif +#include #include #include @@ -83,10 +81,10 @@ class ExecEvent : public QEvent { Q_DISABLE_COPY(ExecEvent) protected: - boost::function< void() > func; + std::function< void() > func; public: - ExecEvent(boost::function< void() >); + ExecEvent(std::function< void() >); void execute(); };