diff --git a/accounts/accountsmanager.cpp b/accounts/accountsmanager.cpp index d450b2f..5a5caba 100644 --- a/accounts/accountsmanager.cpp +++ b/accounts/accountsmanager.cpp @@ -6,11 +6,7 @@ namespace QtAccountsService { -namespace { - -const QString userPathPrefix = QStringLiteral("/org/freedesktop/Accounts/User"); - -} +static const QString userPathPrefix = QStringLiteral("/org/freedesktop/Accounts/User"); AccountsManagerPrivate::AccountsManagerPrivate(AccountsManager *manager, const QDBusConnection &bus) diff --git a/accounts/useraccount.cpp b/accounts/useraccount.cpp index c43dc25..f0b83ca 100644 --- a/accounts/useraccount.cpp +++ b/accounts/useraccount.cpp @@ -12,13 +12,9 @@ namespace QtAccountsService { -namespace { - -const QString serviceName = QStringLiteral("org.freedesktop.Accounts"); -const QString userInterface = QStringLiteral("org.freedesktop.Accounts.User"); -const QString userPathPrefix = QStringLiteral("/org/freedesktop/Accounts/User"); - -} +static const QString serviceName = QStringLiteral("org.freedesktop.Accounts"); +static const QString userInterface = QStringLiteral("org.freedesktop.Accounts.User"); +static const QString userPathPrefix = QStringLiteral("/org/freedesktop/Accounts/User"); UserAccountPrivate::UserAccountPrivate(const QDBusConnection &connection) : bus(connection) diff --git a/appearance/appearance.cpp b/appearance/appearance.cpp index 3c96070..04276ff 100644 --- a/appearance/appearance.cpp +++ b/appearance/appearance.cpp @@ -5,11 +5,9 @@ #include #include -namespace { -constexpr auto Service = "com.cutefish.Services"; -constexpr auto ObjectPath = "/com/cutefish/Services/Appearance"; -constexpr auto Interface = "com.cutefish.Services.Appearance"; -} // namespace +static constexpr auto Service = "com.cutefish.Services"; +static constexpr auto ObjectPath = "/com/cutefish/Services/Appearance"; +static constexpr auto Interface = "com.cutefish.Services.Appearance"; Appearance::Appearance(QObject *parent) : QObject(parent) diff --git a/appearance/wallpaper.cpp b/appearance/wallpaper.cpp index 08d7d3c..62446a7 100644 --- a/appearance/wallpaper.cpp +++ b/appearance/wallpaper.cpp @@ -8,8 +8,7 @@ #include -namespace { -const QStringList imageNameFilters = { +static const QStringList imageNameFilters = { QStringLiteral("*.jpg"), QStringLiteral("*.jpeg"), QStringLiteral("*.png"), QStringLiteral("*.webp"), QStringLiteral("*.bmp"), QStringLiteral("*.tif"), QStringLiteral("*.tiff"), QStringLiteral("*.avif"), @@ -17,7 +16,7 @@ const QStringList imageNameFilters = { // Sorted by file name, not by path: a wallpaper library may hold // subdirectories, and what is read in the grid is the name. -void sortByFileName(QStringList &paths) +static void sortByFileName(QStringList &paths) { QCollator collator; collator.setNumericMode(true); @@ -28,7 +27,7 @@ void sortByFileName(QStringList &paths) }); } -QStringList wallpapersIn(const QStringList &directories) +static QStringList wallpapersIn(const QStringList &directories) { QStringList result; for (const QString &directory : directories) { @@ -42,7 +41,6 @@ QStringList wallpapersIn(const QStringList &directories) sortByFileName(result); return result; } -} // namespace Wallpaper::Wallpaper(QObject *parent) : Appearance(parent) diff --git a/application/applicationregistry.cpp b/application/applicationregistry.cpp index 45eb2c4..ed2099b 100644 --- a/application/applicationregistry.cpp +++ b/application/applicationregistry.cpp @@ -78,14 +78,16 @@ private: QString m_language; }; -QString normalized(const QString &value) +} // namespace + +static QString normalized(const QString &value) { return value.trimmed().toLower(); } // A bare prefix lets a short or unrelated id claim an entry ("code" and // "Code::Blocks"), so the prefix has to end where a word does. -bool startsWithWord(const QString &value, const QString &prefix) +static bool startsWithWord(const QString &value, const QString &prefix) { if (prefix.isEmpty() || !value.startsWith(prefix)) return false; @@ -97,8 +99,6 @@ bool startsWithWord(const QString &value, const QString &prefix) || next == QLatin1Char(' '); } -} // namespace - DesktopEntryModel::DesktopEntryModel(QObject *parent) : QAbstractListModel(parent) { diff --git a/application/applicationruntime.cpp b/application/applicationruntime.cpp index 39b28ed..ac8033f 100644 --- a/application/applicationruntime.cpp +++ b/application/applicationruntime.cpp @@ -12,8 +12,6 @@ static const char *kService = "com.cutefish.AppRuntime"; static const char *kPath = "/AppRuntime"; -namespace -{ // The environment an ordinary application must be started in. // // cutefish-shell runs on a privileged Wayland connection it inherited as @@ -22,7 +20,7 @@ namespace // private cutefish_shell_v1 and cutefish_window_management_v1 globals. The fd // itself is close-on-exec, but the variable naming it has to go as well, so // children fall back to the public WAYLAND_DISPLAY the session also set. -QProcessEnvironment applicationEnvironment(const QString &activationToken) +static QProcessEnvironment applicationEnvironment(const QString &activationToken) { QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); environment.remove(QStringLiteral("WAYLAND_SOCKET")); @@ -43,7 +41,7 @@ QProcessEnvironment applicationEnvironment(const QString &activationToken) } template -bool callBool(QDBusInterface *iface, const QString &method, const Args &...args) +static bool callBool(QDBusInterface *iface, const QString &method, const Args &...args) { if (!iface->isValid()) return false; @@ -52,7 +50,6 @@ bool callBool(QDBusInterface *iface, const QString &method, const Args &...args) return reply.isValid() && reply.value(); } -} ApplicationRuntime *ApplicationRuntime::instance() { diff --git a/application/cutefishnotification.cpp b/application/cutefishnotification.cpp index 51dc79a..b88bf19 100644 --- a/application/cutefishnotification.cpp +++ b/application/cutefishnotification.cpp @@ -9,10 +9,8 @@ #include #include -namespace { -const QString kService = QStringLiteral("org.freedesktop.Notifications"); -const QString kPath = QStringLiteral("/org/freedesktop/Notifications"); -} +static const QString kService = QStringLiteral("org.freedesktop.Notifications"); +static const QString kPath = QStringLiteral("/org/freedesktop/Notifications"); namespace Cutefish { diff --git a/application/desktopentry.cpp b/application/desktopentry.cpp index 860c6a2..7db48c1 100644 --- a/application/desktopentry.cpp +++ b/application/desktopentry.cpp @@ -9,9 +9,7 @@ #include #include -namespace { - -QStringList splitList(const QString &value) +static QStringList splitList(const QString &value) { QStringList result; for (const QString &item : value.split(QLatin1Char(';'), Qt::SkipEmptyParts)) @@ -19,7 +17,7 @@ QStringList splitList(const QString &value) return result; } -QString unescapeValue(const QString &value) +static QString unescapeValue(const QString &value) { // One pass, so an escaped backslash cannot start another escape. QString result; @@ -60,13 +58,13 @@ QString unescapeValue(const QString &value) return result; } -bool parseBool(const QString &value) +static bool parseBool(const QString &value) { return value.compare(QStringLiteral("true"), Qt::CaseInsensitive) == 0; } // TryExec may be a bare name to look up in PATH or an absolute path. -bool executableExists(const QString &program) +static bool executableExists(const QString &program) { if (program.contains(QLatin1Char('/'))) { const QFileInfo info(program); @@ -75,7 +73,7 @@ bool executableExists(const QString &program) return !QStandardPaths::findExecutable(program).isEmpty(); } -bool listContainsDesktop(const QStringList &list, const QStringList &desktops) +static bool listContainsDesktop(const QStringList &list, const QStringList &desktops) { for (const QString &wanted : list) { for (const QString ¤t : desktops) { @@ -87,7 +85,7 @@ bool listContainsDesktop(const QStringList &list, const QStringList &desktops) } // XDG locale matching order: lang_COUNTRY@MODIFIER, lang_COUNTRY, lang@MODIFIER, lang. -QStringList localeCandidates(const QString &language) +static QStringList localeCandidates(const QString &language) { const int modifierStart = language.indexOf(QLatin1Char('@')); const QString modifier = modifierStart < 0 ? QString() : language.mid(modifierStart); @@ -106,10 +104,10 @@ QStringList localeCandidates(const QString &language) return candidates; } -QString localizedValue(const QMap &values, - const QMap &localized, - const QString &key, - const QStringList &candidates) +static QString localizedValue(const QMap &values, + const QMap &localized, + const QString &key, + const QStringList &candidates) { for (const QString &candidate : candidates) { const auto it = localized.constFind(key + QLatin1Char('[') + candidate @@ -121,7 +119,7 @@ QString localizedValue(const QMap &values, return values.value(key); } -QStringList tokenizeExec(const QString &exec) +static QStringList tokenizeExec(const QString &exec) { QStringList result; QString token; @@ -165,8 +163,8 @@ QStringList tokenizeExec(const QString &exec) return result; } -QString substituteToken(const QString &token, const DesktopEntry *entry, - const QStringList &arguments) +static QString substituteToken(const QString &token, const DesktopEntry *entry, + const QStringList &arguments) { QString result; @@ -196,8 +194,6 @@ QString substituteToken(const QString &token, const DesktopEntry *entry, return result; } -} // namespace - DesktopEntry::DesktopEntry(const QString &id, QObject *parent) : QObject(parent) , m_id(id) diff --git a/application/keyfile.cpp b/application/keyfile.cpp index fa318bb..19ad32b 100644 --- a/application/keyfile.cpp +++ b/application/keyfile.cpp @@ -7,9 +7,7 @@ #include #include -namespace -{ -QStringList readLines(const QString &path) +static QStringList readLines(const QString &path) { QStringList lines; QFile file(path); @@ -20,12 +18,12 @@ QStringList readLines(const QString &path) return lines; } -bool isGroupHeader(const QString &line) +static bool isGroupHeader(const QString &line) { return line.startsWith(QLatin1Char('[')); } -QString gvariantString(const QString &value) +static QString gvariantString(const QString &value) { QString escaped = value; escaped.replace(QLatin1Char('\\'), QLatin1String("\\\\")); @@ -34,7 +32,7 @@ QString gvariantString(const QString &value) return QLatin1Char('\'') + escaped + QLatin1Char('\''); } -QString gvariantValue(const QVariant &value) +static QString gvariantValue(const QVariant &value) { switch (value.typeId()) { case QMetaType::Bool: @@ -53,7 +51,7 @@ QString gvariantValue(const QVariant &value) } // Parses one quoted GVariant string starting at text[pos] and moves pos past it. -bool parseString(const QString &text, int &pos, QString &result) +static bool parseString(const QString &text, int &pos, QString &result) { if (pos >= text.size()) return false; @@ -102,12 +100,11 @@ bool parseString(const QString &text, int &pos, QString &result) return false; } -void skipSpaces(const QString &text, int &pos) +static void skipSpaces(const QString &text, int &pos) { while (pos < text.size() && text.at(pos).isSpace()) ++pos; } -} QMap KeyFile::read(const QString &path) { diff --git a/application/languageenvironment.cpp b/application/languageenvironment.cpp index 5b32209..aead032 100644 --- a/application/languageenvironment.cpp +++ b/application/languageenvironment.cpp @@ -10,9 +10,7 @@ #include #include -namespace -{ -QString posixLanguage(const QString &code) +static QString posixLanguage(const QString &code) { const QLocale locale(code); if (locale.language() == QLocale::C) @@ -28,14 +26,14 @@ QString posixLanguage(const QString &code) return name; } -QString utf8Locale(QString name) +static QString utf8Locale(QString name) { const int modifier = name.indexOf('@'); name.insert(modifier < 0 ? name.size() : modifier, ".UTF-8"); return name; } -bool isAvailable(const QString &name) +static bool isAvailable(const QString &name) { locale_t locale = newlocale(LC_ALL_MASK, name.toUtf8().constData(), nullptr); if (!locale) @@ -44,7 +42,7 @@ bool isAvailable(const QString &name) return true; } -bool isUtf8Locale(const QString &name) +static bool isUtf8Locale(const QString &name) { locale_t locale = newlocale(LC_ALL_MASK, name.toUtf8().constData(), nullptr); if (!locale) @@ -54,7 +52,7 @@ bool isUtf8Locale(const QString &name) return encoding == "UTF-8" || encoding == "UTF8"; } -QString fallbackLocale() +static QString fallbackLocale() { if (isAvailable("en_US.UTF-8")) return QStringLiteral("en_US.UTF-8"); @@ -74,7 +72,6 @@ QString fallbackLocale() }(); return installedLocale; } -} QString LanguageEnvironment::systemLanguage() { diff --git a/application/mimeapps.cpp b/application/mimeapps.cpp index b5cff0d..e71cf77 100644 --- a/application/mimeapps.cpp +++ b/application/mimeapps.cpp @@ -10,8 +10,7 @@ #include #include -namespace { -QStringList readEntries(const QStringList &lines, const QString &group, const QString &key) +static QStringList readEntries(const QStringList &lines, const QString &group, const QString &key) { QString current; for (const QString &line : lines) { @@ -27,8 +26,8 @@ QStringList readEntries(const QStringList &lines, const QString &group, const QS return {}; } -void writeEntry(QStringList &lines, const QString &group, const QString &key, - const QStringList &values) +static void writeEntry(QStringList &lines, const QString &group, const QString &key, + const QStringList &values) { const QString entry = key + '=' + values.join(';') + ';'; QString current; @@ -58,7 +57,7 @@ void writeEntry(QStringList &lines, const QString &group, const QString &key, } // An entry may carry a "+" (include) or "-" (exclude) prefix and an ":action" suffix. -QString terminalId(const QString &line) +static QString terminalId(const QString &line) { QString entry = line.trimmed(); if (entry.startsWith('+') || entry.startsWith('-')) @@ -66,7 +65,7 @@ QString terminalId(const QString &line) return entry.section(':', 0, 0); } -bool writeLines(const QString &path, const QStringList &lines) +static bool writeLines(const QString &path, const QStringList &lines) { QSaveFile output(path); if (!output.open(QIODevice::WriteOnly)) @@ -74,7 +73,6 @@ bool writeLines(const QString &path, const QStringList &lines) const auto data = (lines.join('\n') + '\n').toUtf8(); return output.write(data) == data.size() && output.commit(); } -} // namespace QString MimeApps::userListPath() { diff --git a/application/proxysettings.cpp b/application/proxysettings.cpp index 7f18c27..55768e4 100644 --- a/application/proxysettings.cpp +++ b/application/proxysettings.cpp @@ -3,16 +3,14 @@ #include -namespace -{ -const QString kProxyGroup = QStringLiteral("system/proxy"); +static const QString kProxyGroup = QStringLiteral("system/proxy"); -QString serverGroup(const QString &scheme) +static QString serverGroup(const QString &scheme) { return kProxyGroup + QLatin1Char('/') + scheme; } -ProxySettings::Server loadServer(const KeyFile::Group &values, int defaultPort) +static ProxySettings::Server loadServer(const KeyFile::Group &values, int defaultPort) { ProxySettings::Server server; server.host = GSettingsKeyfile::toString(values.value(QStringLiteral("host"))); @@ -20,7 +18,7 @@ ProxySettings::Server loadServer(const KeyFile::Group &values, int defaultPort) return server; } -void saveServer(const QString &scheme, const ProxySettings::Server &server) +static void saveServer(const QString &scheme, const ProxySettings::Server &server) { GSettingsKeyfile::writeGroup(serverGroup(scheme), { {QStringLiteral("host"), server.host}, @@ -28,7 +26,7 @@ void saveServer(const QString &scheme, const ProxySettings::Server &server) }); } -QString hostPort(const ProxySettings::Server &server) +static QString hostPort(const ProxySettings::Server &server) { QString host = server.host; if (host.contains(QLatin1Char(':')) && !host.startsWith(QLatin1Char('['))) @@ -36,7 +34,7 @@ QString hostPort(const ProxySettings::Server &server) return host + QLatin1Char(':') + QString::number(server.port); } -QString modeName(ProxySettings::Mode mode) +static QString modeName(ProxySettings::Mode mode) { switch (mode) { case ProxySettings::Auto: @@ -48,7 +46,7 @@ QString modeName(ProxySettings::Mode mode) } } -ProxySettings::Mode modeFromName(const QString &name) +static ProxySettings::Mode modeFromName(const QString &name) { if (name == QLatin1String("auto")) return ProxySettings::Auto; @@ -56,7 +54,6 @@ ProxySettings::Mode modeFromName(const QString &name) return ProxySettings::Manual; return ProxySettings::None; } -} bool ProxySettings::Server::isValid() const { diff --git a/application/tests/tst_notification.cpp b/application/tests/tst_notification.cpp index 9627fd9..5c3226f 100644 --- a/application/tests/tst_notification.cpp +++ b/application/tests/tst_notification.cpp @@ -12,16 +12,17 @@ using Cutefish::Notification; -namespace { -const QString kService = QStringLiteral("org.freedesktop.Notifications"); -const QString kPath = QStringLiteral("/org/freedesktop/Notifications"); +static const QString kService = QStringLiteral("org.freedesktop.Notifications"); +static const QString kPath = QStringLiteral("/org/freedesktop/Notifications"); // The fake lives on a connection of its own, so every call crosses the bus. -QDBusConnection fakeBus() +static QDBusConnection fakeBus() { return QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("fake")); } +namespace { + struct Call { QString appName; uint replacesId; @@ -32,7 +33,8 @@ struct Call { QVariantMap hints; int timeout; }; -} + +} // namespace class FakeServer : public QObject, protected QDBusContext { diff --git a/application/waylandactivation.cpp b/application/waylandactivation.cpp index 82fc1a0..71f4f48 100644 --- a/application/waylandactivation.cpp +++ b/application/waylandactivation.cpp @@ -22,7 +22,9 @@ struct Request { bool done = false; }; -void global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t) +} // namespace + +static void global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t) { auto *request = static_cast(data); if (std::strcmp(interface, xdg_activation_v1_interface.name) != 0 || request->activation) @@ -31,19 +33,17 @@ void global(void *data, wl_registry *registry, uint32_t name, const char *interf wl_registry_bind(registry, name, &xdg_activation_v1_interface, 1)); } -void globalRemove(void *, wl_registry *, uint32_t) +static void globalRemove(void *, wl_registry *, uint32_t) { } -void tokenDone(void *data, xdg_activation_token_v1 *, const char *token) +static void tokenDone(void *data, xdg_activation_token_v1 *, const char *token) { auto *request = static_cast(data); request->token = QString::fromUtf8(token); request->done = true; } -} // namespace - QString WaylandActivation::requestToken() { auto *native = qGuiApp ? qGuiApp->nativeInterface() diff --git a/application/waylandwindowhints.cpp b/application/waylandwindowhints.cpp index 709476d..fde7b4a 100644 --- a/application/waylandwindowhints.cpp +++ b/application/waylandwindowhints.cpp @@ -9,16 +9,12 @@ namespace Cutefish { -namespace { - -void flushDisplay() +static void flushDisplay() { auto *native = qGuiApp->nativeInterface(); wl_display_flush(native->display()); } -} // namespace - WaylandWindowHints *WaylandWindowHints::instance() { static auto *manager = new WaylandWindowHints(qApp); diff --git a/audio/audiomodel.cpp b/audio/audiomodel.cpp index 57fcdca..cba20f9 100644 --- a/audio/audiomodel.cpp +++ b/audio/audiomodel.cpp @@ -6,10 +6,8 @@ #include namespace CutefishAudio { -namespace { -constexpr int ObjectRole = Qt::UserRole + 1; -constexpr int SortByDefaultRole = ObjectRole + 1; -} +static constexpr int ObjectRole = Qt::UserRole + 1; +static constexpr int SortByDefaultRole = ObjectRole + 1; AudioModel::AudioModel(AudioObject::Kind kind, Backend *backend, QObject *parent) : QAbstractListModel(parent) diff --git a/audio/audioobject.cpp b/audio/audioobject.cpp index b20f5d4..16df371 100644 --- a/audio/audioobject.cpp +++ b/audio/audioobject.cpp @@ -12,10 +12,8 @@ #include namespace CutefishAudio { -namespace { - template -QVector arrayValues(const spa_pod *pod, quint32 type) +static QVector arrayValues(const spa_pod *pod, quint32 type) { if (!spa_pod_is_array(pod) || SPA_POD_ARRAY_VALUE_TYPE(pod) != type || SPA_POD_ARRAY_VALUE_SIZE(pod) != sizeof(T)) { @@ -26,7 +24,7 @@ QVector arrayValues(const spa_pod *pod, quint32 type) return QVector(values, values + count); } -QVariantList intValues(const spa_pod *object, quint32 key) +static QVariantList intValues(const spa_pod *object, quint32 key) { QVariantList values; const spa_pod_prop *prop = spa_pod_find_prop(object, nullptr, key); @@ -37,7 +35,7 @@ QVariantList intValues(const spa_pod *object, quint32 key) return values; } -int availability(quint32 value) +static int availability(quint32 value) { if (value == SPA_PARAM_AVAILABILITY_yes) return AudioObject::Available; @@ -46,7 +44,7 @@ int availability(quint32 value) return AudioObject::Unknown; } -void updateChoice(QVariantList &list, const QVariantMap &choice) +static void updateChoice(QVariantList &list, const QVariantMap &choice) { for (QVariant &item : list) { if (item.toMap().value("index") == choice.value("index")) { @@ -57,8 +55,6 @@ void updateChoice(QVariantList &list, const QVariantMap &choice) list.append(choice); } -} - AudioObject::AudioObject(Backend *backend, quint32 id, Kind kind) : QObject(backend) , m_backend(backend) diff --git a/bluetooth/tests/fakebluez.h b/bluetooth/tests/fakebluez.h index 575b464..d80a372 100644 --- a/bluetooth/tests/fakebluez.h +++ b/bluetooth/tests/fakebluez.h @@ -5,12 +5,10 @@ #include #include -namespace { -const QString adapter = QStringLiteral("/org/bluez/hci0"); -const QString device = adapter + QStringLiteral("/dev_AA_BB_CC_DD_EE_FF"); -const QString adapterInterface = QStringLiteral("org.bluez.Adapter1"); -const QString deviceInterface = QStringLiteral("org.bluez.Device1"); -} // namespace +static const QString adapter = QStringLiteral("/org/bluez/hci0"); +static const QString device = adapter + QStringLiteral("/dev_AA_BB_CC_DD_EE_FF"); +static const QString adapterInterface = QStringLiteral("org.bluez.Adapter1"); +static const QString deviceInterface = QStringLiteral("org.bluez.Device1"); class FakeBluez : public QDBusVirtualObject { diff --git a/capture/captureclient.cpp b/capture/captureclient.cpp index 3a20393..02e862c 100644 --- a/capture/captureclient.cpp +++ b/capture/captureclient.cpp @@ -11,11 +11,9 @@ #include "linux-dmabuf-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h" -namespace { - // Only a release tells the compositor; a plain destroy leaves the server // object until the connection closes. -void releaseOutput(const CaptureClient::Output &output) +static void releaseOutput(const CaptureClient::Output &output) { if (output.xdgOutput) zxdg_output_v1_destroy(output.xdgOutput); @@ -25,8 +23,6 @@ void releaseOutput(const CaptureClient::Output &output) wl_output_destroy(output.output); } -} // namespace - struct CaptureClientListeners { static void global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) diff --git a/capture/capturesession.cpp b/capture/capturesession.cpp index 00e2020..ffc288a 100644 --- a/capture/capturesession.cpp +++ b/capture/capturesession.cpp @@ -25,10 +25,8 @@ Q_LOGGING_CATEGORY(cfCapture, "cutefish.capture", QtWarningMsg) -namespace { - // The DRM node with this st_rdev, which is how the compositor names its device. -QString nodeFor(dev_t device) +static QString nodeFor(dev_t device) { QDirIterator nodes(QStringLiteral("/dev/dri"), QDir::System | QDir::Files); while (nodes.hasNext()) { @@ -43,7 +41,7 @@ QString nodeFor(dev_t device) // An implicit modifier (INVALID) is what a driver without modifiers reports for // a buffer allocated linear by flag, as amdgpu does; only the flag form makes // one. Some backends also refuse the modifier form for LINEAR itself. -gbm_bo *allocateBo(gbm_device *gbm, const QSize &size, uint32_t format, uint64_t modifier) +static gbm_bo *allocateBo(gbm_device *gbm, const QSize &size, uint32_t format, uint64_t modifier) { const auto width = uint32_t(size.width()); const auto height = uint32_t(size.height()); @@ -57,8 +55,6 @@ gbm_bo *allocateBo(gbm_device *gbm, const QSize &size, uint32_t format, uint64_t return gbm_bo_create(gbm, width, height, format, GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR); } -} // namespace - struct CaptureSessionListeners { static void bufferSize(void *data, ext_image_copy_capture_session_v1 *, uint32_t width, uint32_t height) diff --git a/io/directorylister.cpp b/io/directorylister.cpp index 5a7298e..92f0e92 100644 --- a/io/directorylister.cpp +++ b/io/directorylister.cpp @@ -22,7 +22,9 @@ struct TypeDatabase bool settled = false; }; -TypeDatabase currentTypeDatabase() +} // namespace + +static TypeDatabase currentTypeDatabase() { const QStringList paths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, @@ -44,7 +46,7 @@ TypeDatabase currentTypeDatabase() return database; } -QString existingAncestor(QString path) +static QString existingAncestor(QString path) { while (!QFileInfo(path).isDir()) { const QString parent = QFileInfo(path).absolutePath(); @@ -58,8 +60,8 @@ QString existingAncestor(QString path) // Stats every item and reads the files whose names do not decide their type, // spread over pool threads for a first listing or a large folder. -void prepareItems(FileItemList &items, const QHash &previousByName, - const std::function &preparer, const OperationContext *context) +static void prepareItems(FileItemList &items, const QHash &previousByName, + const std::function &preparer, const OperationContext *context) { constexpr qsizetype BlockSize = 64; @@ -92,8 +94,6 @@ void prepareItems(FileItemList &items, const QHash &p }); } -} // namespace - DirectoryLister::DirectoryLister(QObject *parent) : QObject(parent) { diff --git a/io/fileenumerator.cpp b/io/fileenumerator.cpp index 87aa88a..e0b3b75 100644 --- a/io/fileenumerator.cpp +++ b/io/fileenumerator.cpp @@ -16,9 +16,7 @@ namespace Cutefish::IO { using namespace Internal; -namespace { - -quint64 sizeAt(int parent, const QByteArray &name, const QString &path, OperationContext &ctx) +static quint64 sizeAt(int parent, const QByteArray &name, const QString &path, OperationContext &ctx) { ctx.checkpoint(path); @@ -46,7 +44,7 @@ quint64 sizeAt(int parent, const QByteArray &name, const QString &path, Operatio } // Kernel interfaces, whose trees are huge or never end and hold no user files. -bool isKernelFileSystem(int fd) +static bool isKernelFileSystem(int fd) { struct statfs fs; if (::fstatfs(fd, &fs) < 0) @@ -69,8 +67,6 @@ bool isKernelFileSystem(int fd) } } -} // namespace - FileItemList FileEnumerator::list(const QUrl &url, bool hidden, OperationContext *context) { if (context) diff --git a/io/localfilesystem.cpp b/io/localfilesystem.cpp index aadbc6f..b4702d0 100644 --- a/io/localfilesystem.cpp +++ b/io/localfilesystem.cpp @@ -45,13 +45,13 @@ void Internal::eraseAt(int parent, const QByteArray &name, const QString &path, ctx.advance(0); } -namespace { - // Copies drive their own writeback so the page cache holds a bounded amount of unwritten data: // progress follows the disk, and a slow drive can be ejected soon after the copy ends. -constexpr off_t kWritebackChunk = 8 * 1024 * 1024; -constexpr off_t kWritebackLimit = 32 * 1024 * 1024; -constexpr size_t kWritebackFiles = 256; +static constexpr off_t kWritebackChunk = 8 * 1024 * 1024; +static constexpr off_t kWritebackLimit = 32 * 1024 * 1024; +static constexpr size_t kWritebackFiles = 256; + +namespace { class Writeback { @@ -105,8 +105,10 @@ private: off_t m_pending = 0; }; -void copyAt(int sourceParent, const QByteArray &source, int targetParent, const QByteArray &target, - const QString &path, OperationContext &ctx, Writeback &writeback) +} // namespace + +static void copyAt(int sourceParent, const QByteArray &source, int targetParent, const QByteArray &target, + const QString &path, OperationContext &ctx, Writeback &writeback) { ctx.checkpoint(path); @@ -283,7 +285,7 @@ void copyAt(int sourceParent, const QByteArray &source, int targetParent, const ++ctx.files; } -void validateDestination(const QString &source, const QString &destination) +static void validateDestination(const QString &source, const QString &destination) { const auto src = QFileInfo(source).canonicalFilePath(); const auto dstParent = QFileInfo(QFileInfo(destination).absolutePath()).canonicalFilePath(); @@ -297,7 +299,7 @@ void validateDestination(const QString &source, const QString &destination) throw Failure(EINVAL, destination); } -void mergeStaged(int source, int target, const QString &path, OperationContext &ctx) +static void mergeStaged(int source, int target, const QString &path, OperationContext &ctx) { children(source, path, [&](const QByteArray &name, const QString &childPath) { ctx.checkpoint(childPath); @@ -320,8 +322,8 @@ void mergeStaged(int source, int target, const QString &path, OperationContext & }); } -QString publish(int parent, const QByteArray &temporary, const QString &source, - const QString &destination, ConflictPolicy policy, OperationContext &ctx) +static QString publish(int parent, const QByteArray &temporary, const QString &source, + const QString &destination, ConflictPolicy policy, OperationContext &ctx) { QByteArray name = native(QFileInfo(destination).fileName()); int suffix = 1; @@ -379,8 +381,6 @@ QString publish(int parent, const QByteArray &temporary, const QString &source, } } -} // namespace - QString LocalFileSystem::copy(const QString &source, const QString &destination, ConflictPolicy policy, OperationContext &ctx) { diff --git a/io/mimesniffer.cpp b/io/mimesniffer.cpp index a8a9e45..368527e 100644 --- a/io/mimesniffer.cpp +++ b/io/mimesniffer.cpp @@ -21,17 +21,15 @@ namespace Cutefish::IO::Internal { -namespace { - // Qt reads this much of a file for content matching (QIODEVICE_BUFFERSIZE). -constexpr qint64 SniffLength = 16384; +static constexpr qint64 SniffLength = 16384; // Qt's own directory for a built-in database, searched after the XDG ones. -const QString InternalDirectory = QStringLiteral(":/qt-project.org/qmime"); +static const QString InternalDirectory = QStringLiteral(":/qt-project.org/qmime"); -const QString DefaultType = QStringLiteral("application/octet-stream"); +static const QString DefaultType = QStringLiteral("application/octet-stream"); -QStringList mimeDirectories() +static QStringList mimeDirectories() { return QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("mime"), QStandardPaths::LocateDirectory) @@ -39,7 +37,7 @@ QStringList mimeDirectories() } // What a reload has to notice: the directories, and each cache's replacement. -QString databaseVersion(const QStringList &directories) +static QString databaseVersion(const QStringList &directories) { QString version; for (const QString &directory : directories) { @@ -51,6 +49,8 @@ QString databaseVersion(const QStringList &directories) return version; } +namespace { + // QMimeGlobMatchResult: the highest weight wins, then the longest pattern. struct NameMatches { @@ -267,9 +267,11 @@ private: bool m_deletes = false; }; +} // namespace + // QMimeProviderBase::isMimeTypeGlobsExcluded(): whether a directory before this // one deletes the type's globs. -bool globsExcluded(std::span earlier, const QString &type) +static bool globsExcluded(std::span earlier, const QString &type) { for (const TypeOverrides &overrides : earlier) { if (overrides.deletesGlobs(type)) @@ -279,6 +281,8 @@ bool globsExcluded(std::span earlier, const QString &type) return false; } +namespace { + // QMimeBinaryProvider's reading of a mime.cache, which trusts its offsets too. class CacheFile { @@ -518,8 +522,10 @@ private: std::vector m_globs; }; +} // namespace + // QMimeDatabasePrivate's isTextFile(). -bool isTextFile(const QByteArray &data) +static bool isTextFile(const QByteArray &data) { if (data.startsWith("\xFE\xFF") || data.startsWith("\xFF\xFE")) return true; @@ -534,8 +540,6 @@ bool isTextFile(const QByteArray &data) return true; } -} // namespace - struct MimeSniffer::Database { // QMimeDatabasePrivate::findByData(): the type and its accuracy. diff --git a/io/task.cpp b/io/task.cpp index 8398b12..b6ab8b6 100644 --- a/io/task.cpp +++ b/io/task.cpp @@ -18,10 +18,8 @@ namespace Cutefish::IO { -namespace { - // A copy within a filesystem that shares extents may take no space at all, so it is not counted. -bool takesSpace(const QString &source, const QString &directory, bool move) +static bool takesSpace(const QString &source, const QString &directory, bool move) { const auto sourcePath = Internal::native(source); const auto directoryPath = Internal::native(directory); @@ -41,8 +39,8 @@ bool takesSpace(const QString &source, const QString &directory, bool move) && type != BCACHEFS_SUPER_MAGIC); } -TaskResult execute(const TaskRequest &request, OperationContext &ctx, - const std::function &report) +static TaskResult execute(const TaskRequest &request, OperationContext &ctx, + const std::function &report) { TaskResult result; TaskProgress info; @@ -239,8 +237,6 @@ TaskResult execute(const TaskRequest &request, OperationContext &ctx, return result; } -} // namespace - Task::Task(TaskRequest request, QObject *parent) : QObject(parent) , m_request(std::move(request)) diff --git a/io/tests/tst_io.cpp b/io/tests/tst_io.cpp index bac9a4e..f44dc57 100644 --- a/io/tests/tst_io.cpp +++ b/io/tests/tst_io.cpp @@ -21,16 +21,14 @@ using namespace Cutefish::IO; -namespace { - -void writeFile(const QString &path, const QByteArray &data = "contents") +static void writeFile(const QString &path, const QByteArray &data = "contents") { QFile file(path); if (!file.open(QIODevice::WriteOnly) || file.write(data) != data.size()) throw Failure(EIO, path); } -QByteArray readFile(const QString &path) +static QByteArray readFile(const QString &path) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) @@ -39,7 +37,7 @@ QByteArray readFile(const QString &path) return file.readAll(); } -template int errorCode(F action) +template static int errorCode(F action) { try { action(); @@ -50,13 +48,11 @@ template int errorCode(F action) return 0; } -QUrl local(const QString &path) +static QUrl local(const QString &path) { return QUrl::fromLocalFile(path); } -} // namespace - class IOTest : public QObject { Q_OBJECT diff --git a/io/tests/tst_mimesniffer.cpp b/io/tests/tst_mimesniffer.cpp index 5575251..32ed1e6 100644 --- a/io/tests/tst_mimesniffer.cpp +++ b/io/tests/tst_mimesniffer.cpp @@ -11,10 +11,8 @@ using Cutefish::IO::Internal::MimeSniffer; -namespace { - // moc cannot read a raw string literal holding quotes. -const QByteArray UserPackage = +static const QByteArray UserPackage = "\n" "\n" " \n" @@ -27,8 +25,6 @@ const QByteArray UserPackage = " \n" "\n"; -} // namespace - // A user MIME directory, before the system one, that deletes system globs from // the literal list, the suffix tree and the complex globs, and adds its own. class MimeSnifferTest : public QObject diff --git a/io/tests/tst_thumbnailers.cpp b/io/tests/tst_thumbnailers.cpp index 0c05571..6719017 100644 --- a/io/tests/tst_thumbnailers.cpp +++ b/io/tests/tst_thumbnailers.cpp @@ -15,28 +15,24 @@ #include -namespace { - -void writeFile(const QString &path, const QByteArray &data) +static void writeFile(const QString &path, const QByteArray &data) { QFile file(path); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write(data), data.size()); } -QByteArray readFile(const QString &path) +static QByteArray readFile(const QString &path) { QFile file(path); return file.open(QIODevice::ReadOnly) ? file.readAll() : QByteArray(); } -QString localUrl(const QString &path) +static QString localUrl(const QString &path) { return QUrl::fromLocalFile(path).toString(); } -} // namespace - class ThumbnailersTest : public QObject { Q_OBJECT diff --git a/io/tests/tst_volumemanager.cpp b/io/tests/tst_volumemanager.cpp index 405aa86..a042a4c 100644 --- a/io/tests/tst_volumemanager.cpp +++ b/io/tests/tst_volumemanager.cpp @@ -8,14 +8,10 @@ using namespace Cutefish::IO; -namespace { - -const QString service = "org.freedesktop.UDisks2"; -const QString root = "/org/freedesktop/UDisks2"; -const QString disk = root + "/block_devices/sdb1"; -const QString drive = root + "/drives/usb"; - -} // namespace +static const QString service = "org.freedesktop.UDisks2"; +static const QString root = "/org/freedesktop/UDisks2"; +static const QString disk = root + "/block_devices/sdb1"; +static const QString drive = root + "/drives/usb"; class FakeUDisks : public QDBusVirtualObject { diff --git a/io/thumbnailcache.cpp b/io/thumbnailcache.cpp index 69a9c69..7d082cd 100644 --- a/io/thumbnailcache.cpp +++ b/io/thumbnailcache.cpp @@ -15,25 +15,28 @@ #include namespace { + struct Flavor { int size; const char *name; }; +} // namespace + // Sizes and names follow the freedesktop.org Thumbnail Managing Standard. -constexpr Flavor flavors[] = { +static constexpr Flavor flavors[] = { {128, "normal"}, {256, "large"}, {512, "x-large"}, {1024, "xx-large"}, }; -const QString uriKey = QStringLiteral("Thumb::URI"); -const QString mtimeKey = QStringLiteral("Thumb::MTime"); -const QString sizeKey = QStringLiteral("Thumb::Size"); +static const QString uriKey = QStringLiteral("Thumb::URI"); +static const QString mtimeKey = QStringLiteral("Thumb::MTime"); +static const QString sizeKey = QStringLiteral("Thumb::Size"); -const Flavor &flavorFor(const QSize &requestedSize) +static const Flavor &flavorFor(const QSize &requestedSize) { const int extent = qMax(requestedSize.width(), requestedSize.height()); for (const Flavor &flavor : flavors) { @@ -44,7 +47,7 @@ const Flavor &flavorFor(const QSize &requestedSize) return flavors[std::size(flavors) - 1]; } -bool ensurePrivateDirectory(const QString &path) +static bool ensurePrivateDirectory(const QString &path) { if (QFileInfo(path).isDir()) return true; @@ -56,7 +59,7 @@ bool ensurePrivateDirectory(const QString &path) } // QImageReader::text() splits keys at the first colon, so only a decoded image sees Thumb::*. -bool isCurrent(const QImage &image, const QString &uri, qint64 mtime, qint64 size) +static bool isCurrent(const QImage &image, const QString &uri, qint64 mtime, qint64 size) { if (image.isNull() || image.text(uriKey) != uri) return false; @@ -71,19 +74,21 @@ bool isCurrent(const QImage &image, const QString &uri, qint64 mtime, qint64 siz return cachedSize.isEmpty() || cachedSize.toLongLong() == size; } -bool isReadableMimeType(const QString &mimeType) +static bool isReadableMimeType(const QString &mimeType) { static const QList readable = QImageReader::supportedMimeTypes(); return readable.contains(mimeType.toLatin1()); } -void setMetadata(QImage &image, const QString &uri, qint64 mtime, qint64 size) +static void setMetadata(QImage &image, const QString &uri, qint64 mtime, qint64 size) { image.setText(uriKey, uri); image.setText(mtimeKey, QString::number(mtime)); image.setText(sizeKey, QString::number(size)); } +namespace { + // Where the thumbnail of one file at one size lives in the cache. struct Entry { @@ -101,7 +106,9 @@ struct Entry QString failTarget; }; -Entry locate(const QString &filePath, const QSize &requestedSize) +} // namespace + +static Entry locate(const QString &filePath, const QSize &requestedSize) { Entry entry; if (!requestedSize.isValid() || requestedSize.isEmpty()) @@ -133,7 +140,6 @@ Entry locate(const QString &filePath, const QSize &requestedSize) entry.failTarget = entry.failDirectory + '/' + name; return entry; } -} ThumbnailCache *ThumbnailCache::self() { diff --git a/io/thumbnailers.cpp b/io/thumbnailers.cpp index c3af6ae..ba123e3 100644 --- a/io/thumbnailers.cpp +++ b/io/thumbnailers.cpp @@ -17,18 +17,17 @@ #include #include -namespace { // Decoders of untrusted media can hang; a stuck one must not hold a pool thread for good. -constexpr int timeoutMs = 10000; -constexpr qint64 refreshIntervalMs = 3000; +static constexpr int timeoutMs = 10000; +static constexpr qint64 refreshIntervalMs = 3000; -QString canonicalName(const QString &mimeType) +static QString canonicalName(const QString &mimeType) { const QMimeType type = QMimeDatabase().mimeTypeForName(mimeType); return type.isValid() ? type.name() : mimeType; } -QStringList thumbnailerDirectories() +static QStringList thumbnailerDirectories() { QStringList directories; for (const QString &data : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) @@ -37,7 +36,7 @@ QStringList thumbnailerDirectories() return directories; } -bool isRunnable(const QString &program) +static bool isRunnable(const QString &program) { if (program.isEmpty()) return false; @@ -48,14 +47,18 @@ bool isRunnable(const QString &program) return !QStandardPaths::findExecutable(program).isEmpty(); } +namespace { + struct Entry { QStringList command; QStringList mimeTypes; }; +} // namespace + // The key file subset thumbnailers use: one group, plain keys, no localized values. -Entry parseEntry(const QString &path) +static Entry parseEntry(const QString &path) { QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -97,8 +100,8 @@ Entry parseEntry(const QString &path) return {command, mimeTypes.split(u';', Qt::SkipEmptyParts)}; } -QStringList expand(const QStringList &command, const QString &input, const QString &output, - int size) +static QStringList expand(const QStringList &command, const QString &input, const QString &output, + int size) { QStringList arguments; for (const QString &argument : command) { @@ -126,7 +129,6 @@ QStringList expand(const QStringList &command, const QString &input, const QStri return arguments; } -} Thumbnailers *Thumbnailers::self() { diff --git a/io/thumbnailprovider.cpp b/io/thumbnailprovider.cpp index 45e788d..cc126dc 100644 --- a/io/thumbnailprovider.cpp +++ b/io/thumbnailprovider.cpp @@ -11,8 +11,7 @@ #include -namespace { -QThreadPool &thumbnailPool() +static QThreadPool &thumbnailPool() { static QThreadPool pool; static const bool configured = [] { @@ -24,6 +23,8 @@ QThreadPool &thumbnailPool() return pool; } +namespace { + class ThumbnailResponse final : public QQuickImageResponse { public: @@ -55,7 +56,8 @@ private: QImage m_image; std::atomic_bool m_cancelled = false; }; -} + +} // namespace QQuickImageResponse *ThumbnailProvider::requestImageResponse(const QString &id, const QSize &requestedSize) diff --git a/io/trash.cpp b/io/trash.cpp index 6a16a6d..a1dbce8 100644 --- a/io/trash.cpp +++ b/io/trash.cpp @@ -11,9 +11,7 @@ namespace Cutefish::IO { using namespace Internal; -namespace { - -void ensureTrash() +static void ensureTrash() { const auto root = FileSystemUrl::trashRoot(); @@ -31,6 +29,8 @@ void ensureTrash() } } +namespace { + class TrashLock { public: @@ -56,7 +56,9 @@ private: Fd m_fd; }; -QString trashInfo(const QUrl &url) +} // namespace + +static QString trashInfo(const QUrl &url) { if (url.scheme() != "trash" || url.path().mid(1).contains('/') || url.fileName().isEmpty()) throw Failure(EINVAL, url.toString()); @@ -65,8 +67,6 @@ QString trashInfo(const QUrl &url) return FileSystemUrl::trashRoot() + "/info/" + url.fileName() + ".trashinfo"; } -} // namespace - void LocalFileSystem::remove(const QUrl &url, OperationContext &ctx) { const auto path = FileSystemUrl(url).localPath(); diff --git a/io/volumemanager.cpp b/io/volumemanager.cpp index 929c362..30abcab 100644 --- a/io/volumemanager.cpp +++ b/io/volumemanager.cpp @@ -10,15 +10,13 @@ namespace Cutefish::IO { -namespace { +static const QString service = QStringLiteral("org.freedesktop.UDisks2"); +static const QString root = QStringLiteral("/org/freedesktop/UDisks2"); +static const QString blockInterface = service + ".Block"; +static const QString driveInterface = service + ".Drive"; +static const QString filesystemInterface = service + ".Filesystem"; -const QString service = QStringLiteral("org.freedesktop.UDisks2"); -const QString root = QStringLiteral("/org/freedesktop/UDisks2"); -const QString blockInterface = service + ".Block"; -const QString driveInterface = service + ".Drive"; -const QString filesystemInterface = service + ".Filesystem"; - -QString decodePath(QByteArray bytes) +static QString decodePath(QByteArray bytes) { if (bytes.endsWith('\0')) bytes.chop(1); @@ -26,8 +24,6 @@ QString decodePath(QByteArray bytes) return QFile::decodeName(bytes); } -} // namespace - VolumeManager::VolumeManager(QObject *parent) : VolumeManager(QDBusConnection::systemBus(), parent) { diff --git a/network/handler.cpp b/network/handler.cpp index 3e913fd..55bbd14 100644 --- a/network/handler.cpp +++ b/network/handler.cpp @@ -37,26 +37,24 @@ using namespace NetworkDBus; -namespace { - // The shell's secret agent, which asks for a new network's password up front. -const QString promptService = QStringLiteral("com.cutefish.SecretAgent"); -const QString promptPath = QStringLiteral("/SecretAgent"); -const QString promptInterface = QStringLiteral("com.cutefish.SecretAgent"); +static const QString promptService = QStringLiteral("com.cutefish.SecretAgent"); +static const QString promptPath = QStringLiteral("/SecretAgent"); +static const QString promptInterface = QStringLiteral("com.cutefish.SecretAgent"); -const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); +static const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); // Activations and profile changes may wait on an administrator password. -constexpr int kAuthorizedCallTimeoutMs = 2 * 60 * 1000; -constexpr int kForgetWatchTimeoutMs = 2 * 60 * 1000; +static constexpr int kAuthorizedCallTimeoutMs = 2 * 60 * 1000; +static constexpr int kForgetWatchTimeoutMs = 2 * 60 * 1000; -QVariant objectPath(const QString &path) +static QVariant objectPath(const QString &path) { return QVariant::fromValue(QDBusObjectPath(path.isEmpty() ? QStringLiteral("/") : path)); } // At most 32 bytes, cut on a character boundary. -QByteArray ssidBytes(const QString &name) +static QByteArray ssidBytes(const QString &name) { QByteArray bytes = name.toUtf8(); if (bytes.size() <= 32) @@ -67,8 +65,6 @@ QByteArray ssidBytes(const QString &name) return bytes.left(size); } -} // namespace - Handler::Handler(QObject *parent) : QObject(parent) , m_client(NetworkClient::instance()) diff --git a/network/networkdbustypes.cpp b/network/networkdbustypes.cpp index 9c60ffd..df089be 100644 --- a/network/networkdbustypes.cpp +++ b/network/networkdbustypes.cpp @@ -4,9 +4,7 @@ #include #include -namespace { - -QVariant read(const QDBusArgument &argument) +static QVariant read(const QDBusArgument &argument) { switch (argument.currentType()) { case QDBusArgument::BasicType: @@ -63,8 +61,6 @@ QVariant read(const QDBusArgument &argument) } } -} // namespace - QVariant NetworkDBus::plain(const QVariant &value) { const QMetaType type = value.metaType(); diff --git a/network/networkmodel.cpp b/network/networkmodel.cpp index abf4203..652d928 100644 --- a/network/networkmodel.cpp +++ b/network/networkmodel.cpp @@ -31,11 +31,11 @@ using namespace NetworkDBus; -namespace { +static const QString connectionSetting = QStringLiteral("connection"); +static const QString wirelessSetting = QStringLiteral("802-11-wireless"); +static const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); -const QString connectionSetting = QStringLiteral("connection"); -const QString wirelessSetting = QStringLiteral("802-11-wireless"); -const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); +namespace { // How networks are told apart: by what joining one asks for, not by the exact scheme, so // a router whose bands differ only in WPA2 and WPA3 is still one network. @@ -46,7 +46,9 @@ enum class SecurityClass { Enterprise, }; -SecurityClass classOf(Enums::SecurityType type) +} // namespace + +static SecurityClass classOf(Enums::SecurityType type) { switch (type) { case Enums::StaticWep: @@ -66,7 +68,7 @@ SecurityClass classOf(Enums::SecurityType type) } } -SecurityClass profileClass(const NetworkClient *client, const QString &profile) +static SecurityClass profileClass(const NetworkClient *client, const QString &profile) { if (!client->settings(profile).contains(wirelessSecurity)) return SecurityClass::Open; @@ -81,25 +83,25 @@ SecurityClass profileClass(const NetworkClient *client, const QString &profile) return SecurityClass::Personal; } -bool isPort(const NetworkClient *client, const QString &profile) +static bool isPort(const NetworkClient *client, const QString &profile) { return !client->setting(profile, connectionSetting, QStringLiteral("controller")).toString().isEmpty() || !client->setting(profile, connectionSetting, QStringLiteral("master")).toString().isEmpty(); } -QDateTime lastUsed(const NetworkClient *client, const QString &profile) +static QDateTime lastUsed(const NetworkClient *client, const QString &profile) { const qulonglong seconds = client->setting(profile, connectionSetting, QStringLiteral("timestamp")).toULongLong(); return seconds ? QDateTime::fromSecsSinceEpoch(qint64(seconds)) : QDateTime(); } -QString profileOf(const NetworkClient *client, const QString &active) +static QString profileOf(const NetworkClient *client, const QString &active) { return NetworkClient::path(client->property(active, activeInterface, QStringLiteral("Connection"))); } // The profiles NetworkManager would activate on the device, and the one it has active. -QStringList profilesFor(const NetworkClient *client, const QString &device, const QString &type) +static QStringList profilesFor(const NetworkClient *client, const QString &device, const QString &type) { QStringList profiles; QStringList candidates = client->property(device, deviceInterface, QStringLiteral("AvailableConnections")).toStringList(); @@ -116,7 +118,7 @@ QStringList profilesFor(const NetworkClient *client, const QString &device, cons return profiles; } -QString firstAddress(const QVariantList &addressData, bool skipLinkLocal) +static QString firstAddress(const QVariantList &addressData, bool skipLinkLocal) { QString fallback; for (const QVariant &entry : addressData) { @@ -129,8 +131,6 @@ QString firstAddress(const QVariantList &addressData, bool skipLinkLocal) return fallback; } -} // namespace - NetworkModel::NetworkModel(QObject *parent) : QAbstractListModel(parent) , m_client(NetworkClient::instance()) diff --git a/network/secretagent.cpp b/network/secretagent.cpp index a0a8dd7..88b9dec 100644 --- a/network/secretagent.cpp +++ b/network/secretagent.cpp @@ -11,34 +11,32 @@ using namespace NetworkDBus; -namespace { - -const QString connectionSetting = QStringLiteral("connection"); -const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); -const QString ieee8021x = QStringLiteral("802-1x"); -const QString agentIdentifier = QStringLiteral("com.cutefish.network"); - -const QString noSecrets = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.NoSecrets"); -const QString userCanceled = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.UserCanceled"); -const QString agentCanceled = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.AgentCanceled"); -const QString permissionDenied = +static const QString connectionSetting = QStringLiteral("connection"); +static const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); +static const QString ieee8021x = QStringLiteral("802-1x"); +static const QString agentIdentifier = QStringLiteral("com.cutefish.network"); + +static const QString noSecrets = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.NoSecrets"); +static const QString userCanceled = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.UserCanceled"); +static const QString agentCanceled = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.AgentCanceled"); +static const QString permissionDenied = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent.PermissionDenied"); // NetworkManager keeps one flags property for all four WEP keys. -QString flagsKey(const QString &key) +static QString flagsKey(const QString &key) { if (key.startsWith(QLatin1String("wep-key")) && key.size() == 8) return QStringLiteral("wep-key-flags"); return key + QLatin1String("-flags"); } -bool savedByAgent(uint flags) +static bool savedByAgent(uint flags) { return (flags & SecretAgentOwned) && !(flags & SecretNotSaved); } // A VPN's data and secrets: string to string, nested in the vpn setting. -QMap stringMap(const QVariant &value) +static QMap stringMap(const QVariant &value) { QMap map; const QVariantMap entries = NetworkDBus::plain(value).toMap(); @@ -47,8 +45,6 @@ QMap stringMap(const QVariant &value) return map; } -} // namespace - // The object NetworkManager calls. It stays out of the QML type, which also serves the // session's own com.cutefish.SecretAgent interface. class SecretAgentService : public QObject, protected QDBusContext diff --git a/network/secretstore.cpp b/network/secretstore.cpp index fca56e9..5da2fbb 100644 --- a/network/secretstore.cpp +++ b/network/secretstore.cpp @@ -11,17 +11,17 @@ #include -namespace { +static const QString service = QStringLiteral("org.freedesktop.secrets"); +static const QString servicePath = QStringLiteral("/org/freedesktop/secrets"); +static const QString serviceInterface = QStringLiteral("org.freedesktop.Secret.Service"); +static const QString collectionInterface = QStringLiteral("org.freedesktop.Secret.Collection"); +static const QString itemInterface = QStringLiteral("org.freedesktop.Secret.Item"); +static const QString promptInterface = QStringLiteral("org.freedesktop.Secret.Prompt"); +static const QString sessionInterface = QStringLiteral("org.freedesktop.Secret.Session"); +static const QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +static const QString noPrompt = QStringLiteral("/"); -const QString service = QStringLiteral("org.freedesktop.secrets"); -const QString servicePath = QStringLiteral("/org/freedesktop/secrets"); -const QString serviceInterface = QStringLiteral("org.freedesktop.Secret.Service"); -const QString collectionInterface = QStringLiteral("org.freedesktop.Secret.Collection"); -const QString itemInterface = QStringLiteral("org.freedesktop.Secret.Item"); -const QString promptInterface = QStringLiteral("org.freedesktop.Secret.Prompt"); -const QString sessionInterface = QStringLiteral("org.freedesktop.Secret.Session"); -const QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); -const QString noPrompt = QStringLiteral("/"); +namespace { using Attributes = QMap; diff --git a/network/tests/tst_secretagent.cpp b/network/tests/tst_secretagent.cpp index 6417773..3826478 100644 --- a/network/tests/tst_secretagent.cpp +++ b/network/tests/tst_secretagent.cpp @@ -9,21 +9,19 @@ #include -namespace { - -const QString agentPath = QStringLiteral("/org/freedesktop/NetworkManager/SecretAgent"); -const QString agentInterface = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent"); -const QString connectionPath = QStringLiteral("/org/freedesktop/NetworkManager/Settings/7"); -const QString uuid = QStringLiteral("5e3c1b64-3b43-4a2c-9d53-0d6c1a1f4f10"); -const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); +static const QString agentPath = QStringLiteral("/org/freedesktop/NetworkManager/SecretAgent"); +static const QString agentInterface = QStringLiteral("org.freedesktop.NetworkManager.SecretAgent"); +static const QString connectionPath = QStringLiteral("/org/freedesktop/NetworkManager/Settings/7"); +static const QString uuid = QStringLiteral("5e3c1b64-3b43-4a2c-9d53-0d6c1a1f4f10"); +static const QString wirelessSecurity = QStringLiteral("802-11-wireless-security"); // NMSecretAgentGetSecretsFlags -constexpr uint allowInteraction = 0x1; -constexpr uint requestNew = 0x2; -constexpr uint userRequested = 0x4; -constexpr uint noErrors = 0x40000000; +static constexpr uint allowInteraction = 0x1; +static constexpr uint requestNew = 0x2; +static constexpr uint userRequested = 0x4; +static constexpr uint noErrors = 0x40000000; -NMVariantMapMap wpaConnection(uint pskFlags = 0) +static NMVariantMapMap wpaConnection(uint pskFlags = 0) { NMVariantMapMap connection; connection[QStringLiteral("connection")] = {{QStringLiteral("id"), QStringLiteral("Cafe")}, @@ -33,7 +31,7 @@ NMVariantMapMap wpaConnection(uint pskFlags = 0) return connection; } -NMVariantMapMap vpnConnection(const QString &service, const QMap &data) +static NMVariantMapMap vpnConnection(const QString &service, const QMap &data) { NMVariantMapMap connection; connection[QStringLiteral("connection")] = {{QStringLiteral("id"), QStringLiteral("Office")}, @@ -43,11 +41,9 @@ NMVariantMapMap vpnConnection(const QString &service, const QMap passwordData {{QStringLiteral("connection-type"), QStringLiteral("password")}, - {QStringLiteral("password-flags"), QStringLiteral("1")}}; - -} // namespace +static const QString openvpn = QStringLiteral("org.freedesktop.NetworkManager.openvpn"); +static const QMap passwordData {{QStringLiteral("connection-type"), QStringLiteral("password")}, + {QStringLiteral("password-flags"), QStringLiteral("1")}}; class SecretAgentTest : public QObject { diff --git a/network/tests/tst_vpnutils.cpp b/network/tests/tst_vpnutils.cpp index 83e035f..51ee4e3 100644 --- a/network/tests/tst_vpnutils.cpp +++ b/network/tests/tst_vpnutils.cpp @@ -3,9 +3,7 @@ #include #include -namespace { - -QStringList keys(const QList &fields) +static QStringList keys(const QList &fields) { QStringList keys; for (const auto &field : fields) @@ -13,9 +11,7 @@ QStringList keys(const QList &fields) return keys; } -const QString openvpn = QStringLiteral("org.freedesktop.NetworkManager.openvpn"); - -} // namespace +static const QString openvpn = QStringLiteral("org.freedesktop.NetworkManager.openvpn"); class VpnUtilsTest : public QObject { diff --git a/network/vpnutils.cpp b/network/vpnutils.cpp index 8ac6023..2ee664c 100644 --- a/network/vpnutils.cpp +++ b/network/vpnutils.cpp @@ -13,9 +13,9 @@ using namespace NetworkDBus; -namespace { +static const QString servicePrefix = QStringLiteral("org.freedesktop.NetworkManager."); -const QString servicePrefix = QStringLiteral("org.freedesktop.NetworkManager."); +namespace { struct Plugin { QString name; @@ -29,14 +29,16 @@ struct PluginCache { QList plugins; }; -PluginCache &cache() +} // namespace + +static PluginCache &cache() { static PluginCache cache; return cache; } // The [VPN Connection] group of a plugin's .name file. -Plugin readNameFile(const QString &path) +static Plugin readNameFile(const QString &path) { Plugin plugin; QFile file(path); @@ -67,7 +69,7 @@ Plugin readNameFile(const QString &path) } // Read again only when a directory changed: plugins come and go with packages. -const QList &plugins() +static const QList &plugins() { PluginCache &cache = ::cache(); QList stamps; @@ -89,7 +91,7 @@ const QList &plugins() return cache.plugins; } -QString shortName(const QString &serviceType) +static QString shortName(const QString &serviceType) { for (const Plugin &plugin : plugins()) { if (plugin.services.contains(serviceType)) @@ -99,8 +101,6 @@ QString shortName(const QString &serviceType) : serviceType.section(QLatin1Char('.'), -1); } -} // namespace - namespace VpnUtils { bool isVpn(const NetworkClient *client, const QString &connection) diff --git a/network/wifiutils.cpp b/network/wifiutils.cpp index 9369ce3..1edfb6b 100644 --- a/network/wifiutils.cpp +++ b/network/wifiutils.cpp @@ -26,8 +26,10 @@ struct LocaleEncodings { QList encodings; }; +} // namespace + // NetworkManager's table in libnm-core-impl/nm-utils.c, by language and then country. -const LocaleEncodings localeEncodings[] = { +static const LocaleEncodings localeEncodings[] = { {"zh_cn", {"GB18030", "EUC-CN", "GB2312"}}, {"zh_sg", {"GB18030", "EUC-CN", "GB2312"}}, {"zh_hk", {"BIG5", "BIG5-HKSCS", "EUC-TW"}}, @@ -60,7 +62,7 @@ const LocaleEncodings localeEncodings[] = { {"uk", {"KOI8-U", "KOI8-R", "WINDOWS-1251"}}, }; -QList encodingsForLocale() +static QList encodingsForLocale() { const QString name = QLocale::system().name().toLower(); for (const auto &entry : localeEncodings) { @@ -75,7 +77,7 @@ QList encodingsForLocale() return {}; } -bool decode(const QByteArray &bytes, const char *encoding, QString *text) +static bool decode(const QByteArray &bytes, const char *encoding, QString *text) { iconv_t converter = iconv_open("UTF-8", encoding); if (converter == iconv_t(-1)) @@ -97,7 +99,7 @@ bool decode(const QByteArray &bytes, const char *encoding, QString *text) } // A control character in a label would break the line it sits in. -QString printable(QString text) +static QString printable(QString text) { for (QChar &c : text) { if (c.category() == QChar::Other_Control) @@ -106,7 +108,7 @@ QString printable(QString text) return text; } -bool supportsCiphers(uint caps, uint flags, bool staticWep) +static bool supportsCiphers(uint caps, uint flags, bool staticWep) { bool pair = staticWep; if (!staticWep) { @@ -121,13 +123,13 @@ bool supportsCiphers(uint caps, uint flags, bool staticWep) return pair && group; } -bool pskCipher(uint caps, uint flags) +static bool pskCipher(uint caps, uint flags) { return ((flags & PairTkip) && (caps & CapTkip)) || ((flags & PairCcmp) && (caps & CapCcmp)); } // nm_utils_security_valid() for an access point that is in range. -bool valid(Enums::SecurityType type, uint caps, bool adhoc, uint apFlags, uint wpa, uint rsn) +static bool valid(Enums::SecurityType type, uint caps, bool adhoc, uint apFlags, uint wpa, uint rsn) { switch (type) { case Enums::NoneSecurity: @@ -173,7 +175,7 @@ bool valid(Enums::SecurityType type, uint caps, bool adhoc, uint apFlags, uint w } // What the access point advertises, for devices that report no capabilities. -Enums::SecurityType advertised(uint apFlags, uint wpa, uint rsn) +static Enums::SecurityType advertised(uint apFlags, uint wpa, uint rsn) { if (rsn & KeyMgmtEapSuiteB192) return Enums::Wpa3SuiteB192; @@ -194,8 +196,6 @@ Enums::SecurityType advertised(uint apFlags, uint wpa, uint rsn) return Enums::NoneSecurity; } -} // namespace - namespace WifiUtils { QString ssidLabel(const QByteArray &ssid) diff --git a/network/wirelessitemsettings.cpp b/network/wirelessitemsettings.cpp index 2c278b3..dbf9f8f 100644 --- a/network/wirelessitemsettings.cpp +++ b/network/wirelessitemsettings.cpp @@ -5,11 +5,7 @@ using namespace NetworkDBus; -namespace { - -const QString connectionSetting = QStringLiteral("connection"); - -} // namespace +static const QString connectionSetting = QStringLiteral("connection"); WirelessItemSettings::WirelessItemSettings(QObject *parent) : QObject(parent) diff --git a/power/batterystatus.cpp b/power/batterystatus.cpp index baea75e..69fa8c9 100644 --- a/power/batterystatus.cpp +++ b/power/batterystatus.cpp @@ -9,17 +9,15 @@ #include #include -namespace { -const QString service = QStringLiteral("com.cutefish.Services"); -const QString path = QStringLiteral("/com/cutefish/Services/Battery"); -const QString interface = QStringLiteral("com.cutefish.Services.Battery"); +static const QString service = QStringLiteral("com.cutefish.Services"); +static const QString path = QStringLiteral("/com/cutefish/Services/Battery"); +static const QString interface = QStringLiteral("com.cutefish.Services.Battery"); -const QString upowerService = QStringLiteral("org.freedesktop.UPower"); -const QString upowerPath = QStringLiteral("/org/freedesktop/UPower"); -const QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +static const QString upowerService = QStringLiteral("org.freedesktop.UPower"); +static const QString upowerPath = QStringLiteral("/org/freedesktop/UPower"); +static const QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); -BatteryStatus *s_instance = nullptr; -} // namespace +static BatteryStatus *s_instance = nullptr; BatteryStatus *BatteryStatus::instance() { diff --git a/power/tests/batterystatus_test.cpp b/power/tests/batterystatus_test.cpp index 0351b69..f2402cc 100644 --- a/power/tests/batterystatus_test.cpp +++ b/power/tests/batterystatus_test.cpp @@ -8,6 +8,7 @@ #include namespace { + // cutefish-services' battery object, on a connection of its own as in another process. class FakeBattery : public QObject { @@ -37,6 +38,7 @@ public slots: signals: void chargePercentChanged(int value); }; + } // namespace class BatteryStatusTest : public QObject diff --git a/screen/nightlight.cpp b/screen/nightlight.cpp index b1eb246..b94ee71 100644 --- a/screen/nightlight.cpp +++ b/screen/nightlight.cpp @@ -9,13 +9,9 @@ #include #include -namespace { - -const QString s_service = QStringLiteral("com.cutefish.Services"); -const QString s_path = QStringLiteral("/com/cutefish/Services/NightLight"); -const QString s_interface = QStringLiteral("com.cutefish.Services.NightLight"); - -} // namespace +static const QString s_service = QStringLiteral("com.cutefish.Services"); +static const QString s_path = QStringLiteral("/com/cutefish/Services/NightLight"); +static const QString s_interface = QStringLiteral("com.cutefish.Services.NightLight"); NightLight::NightLight(QObject *parent) : QObject(parent) diff --git a/screen/tests/displayclient_test.cpp b/screen/tests/displayclient_test.cpp index ac17a5b..f66f93a 100644 --- a/screen/tests/displayclient_test.cpp +++ b/screen/tests/displayclient_test.cpp @@ -10,9 +10,10 @@ using cutefish::display::ipc::ErrorCode; +static const QString serviceName = QStringLiteral("com.cutefish.DisplayConfig.ClientTest"); +static const QString objectPath = QStringLiteral("/com/cutefish/DisplayConfig1"); + namespace { -const QString serviceName = QStringLiteral("com.cutefish.DisplayConfig.ClientTest"); -const QString objectPath = QStringLiteral("/com/cutefish/DisplayConfig1"); class FakeDisplayConfig : public QObject { @@ -114,6 +115,7 @@ struct Result { bool succeeded = false; ErrorCode error = ErrorCode::None; }; + } // namespace class DisplayClientTest : public QObject diff --git a/scrolling/scroller.cpp b/scrolling/scroller.cpp index e4299a8..593845c 100644 --- a/scrolling/scroller.cpp +++ b/scrolling/scroller.cpp @@ -17,30 +17,28 @@ namespace Cutefish { -namespace { - -constexpr qreal friction = 4.5; -constexpr qreal springFrequency = 18.0; -constexpr qreal rubberBandResistance = 0.55; -constexpr qreal minimumFlickSpeed = 40.0; -constexpr qreal maximumFlickSpeed = 6000.0; -constexpr qreal stopSpeed = 5.0; -constexpr qreal velocityTimeout = 80; +static constexpr qreal friction = 4.5; +static constexpr qreal springFrequency = 18.0; +static constexpr qreal rubberBandResistance = 0.55; +static constexpr qreal minimumFlickSpeed = 40.0; +static constexpr qreal maximumFlickSpeed = 6000.0; +static constexpr qreal stopSpeed = 5.0; +static constexpr qreal velocityTimeout = 80; // The flick velocity is a line fitted to the last samples of this window. -constexpr qreal velocityWindow = 100; -constexpr int velocitySamples = 10; +static constexpr qreal velocityWindow = 100; +static constexpr int velocitySamples = 10; // Frames predict past the last sample only while samples arrive at a steady rate. -constexpr qreal minimumSampleInterval = 2; -constexpr qreal maximumSampleInterval = 20; -constexpr qreal maximumPrediction = 8; +static constexpr qreal minimumSampleInterval = 2; +static constexpr qreal maximumSampleInterval = 20; +static constexpr qreal maximumPrediction = 8; // A release faster than this turns the page however little it moved. -constexpr qreal pageFlickSpeed = 400.0; -constexpr qreal snapDuration = 180; -constexpr qreal snapPageDuration = 220; -constexpr qreal minimumSnapDuration = 120; -constexpr qreal never = -std::numeric_limits::infinity(); +static constexpr qreal pageFlickSpeed = 400.0; +static constexpr qreal snapDuration = 180; +static constexpr qreal snapPageDuration = 220; +static constexpr qreal minimumSnapDuration = 120; +static constexpr qreal never = -std::numeric_limits::infinity(); -qreal monotonicClock() +static qreal monotonicClock() { static QElapsedTimer timer; if (!timer.isValid()) @@ -48,25 +46,23 @@ qreal monotonicClock() return timer.nsecsElapsed() / 1e6; } -qreal (*currentClock)() = monotonicClock; +static qreal (*currentClock)() = monotonicClock; // Event timestamps come from the compositor's clock; its offset to ours is the // smallest delivery delay seen. -qreal eventClockOffset = 0; -bool eventClockKnown = false; +static qreal eventClockOffset = 0; +static bool eventClockKnown = false; -qreal bounded(qreal position, qreal minimum, qreal maximum) +static qreal bounded(qreal position, qreal minimum, qreal maximum) { return qBound(minimum, position, maximum); } -QList &allScrollers() +static QList &allScrollers() { static QList scrollers; return scrollers; } -} // namespace - // The frame clock of one window, shared by the scrollers shown in it. class ScrollFrames : public QObject {