Avoid using const_string for constant consumed by std::string

This commit is contained in:
Ilya Fedin 2023-07-20 18:06:45 +04:00 committed by John Preston
parent 68fa3e36d7
commit 9ccb11bd1a
4 changed files with 58 additions and 61 deletions

View file

@ -114,8 +114,8 @@ LinuxIntegration::LinuxIntegration()
XdpInhibit::InhibitProxy::new_for_bus_sync( XdpInhibit::InhibitProxy::new_for_bus_sync(
Gio::BusType::SESSION_, Gio::BusType::SESSION_,
Gio::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION_, Gio::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION_,
std::string(base::Platform::XDP::kService), base::Platform::XDP::kService,
std::string(base::Platform::XDP::kObjectPath), base::Platform::XDP::kObjectPath,
nullptr)) nullptr))
, _darkModeWatcher([]( , _darkModeWatcher([](
const Glib::ustring &group, const Glib::ustring &group,

View file

@ -23,8 +23,8 @@ namespace File {
namespace internal { namespace internal {
namespace { namespace {
constexpr auto kXDPOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs; constexpr auto kXDPOpenURIInterface = "org.freedesktop.portal.OpenURI";
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties";
} // namespace } // namespace
@ -34,15 +34,14 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
const auto version = connection->call_sync( const auto version = connection->call_sync(
std::string(base::Platform::XDP::kObjectPath), base::Platform::XDP::kObjectPath,
std::string(kPropertiesInterface), kPropertiesInterface,
"Get", "Get",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
Glib::ustring( Glib::ustring(kXDPOpenURIInterface),
std::string(kXDPOpenURIInterface)),
Glib::ustring("version"), Glib::ustring("version"),
}), }),
std::string(base::Platform::XDP::kService) base::Platform::XDP::kService
).get_child(0).get_dynamic<Glib::Variant<uint>>().get(); ).get_child(0).get_dynamic<Glib::Variant<uint>>().get();
if (version < 3) { if (version < 3) {
@ -107,8 +106,8 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
const Glib::VariantContainerBase &parameters) { const Glib::VariantContainerBase &parameters) {
loop->quit(); loop->quit();
}, },
std::string(base::Platform::XDP::kService), base::Platform::XDP::kService,
std::string(base::Platform::XDP::kRequestInterface), base::Platform::XDP::kRequestInterface,
"Response", "Response",
requestPath); requestPath);
@ -121,8 +120,8 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
auto outFdList = Glib::RefPtr<Gio::UnixFDList>(); auto outFdList = Glib::RefPtr<Gio::UnixFDList>();
connection->call_sync( connection->call_sync(
std::string(base::Platform::XDP::kObjectPath), base::Platform::XDP::kObjectPath,
std::string(kXDPOpenURIInterface), kXDPOpenURIInterface,
"OpenFile", "OpenFile",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
parentWindowId, parentWindowId,
@ -144,7 +143,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
}), }),
Gio::UnixFDList::create(std::vector<int>{ fd }), Gio::UnixFDList::create(std::vector<int>{ fd }),
outFdList, outFdList,
std::string(base::Platform::XDP::kService)); base::Platform::XDP::kService);
if (signalId != 0) { if (signalId != 0) {
QWidget window; QWidget window;

View file

@ -37,10 +37,10 @@ namespace Platform {
namespace Notifications { namespace Notifications {
namespace { namespace {
constexpr auto kService = "org.freedesktop.Notifications"_cs; constexpr auto kService = "org.freedesktop.Notifications";
constexpr auto kObjectPath = "/org/freedesktop/Notifications"_cs; constexpr auto kObjectPath = "/org/freedesktop/Notifications";
constexpr auto kInterface = kService; constexpr auto kInterface = kService;
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties";
struct ServerInformation { struct ServerInformation {
QString name; QString name;
@ -76,7 +76,7 @@ std::unique_ptr<base::Platform::DBus::ServiceWatcher> CreateServiceWatcher() {
try { try {
return ranges::contains( return ranges::contains(
base::Platform::DBus::ListActivatableNames(connection), base::Platform::DBus::ListActivatableNames(connection),
std::string(kService), kService,
&Glib::ustring::raw); &Glib::ustring::raw);
} catch (...) { } catch (...) {
// avoid service restart loop in sandboxed environments // avoid service restart loop in sandboxed environments
@ -86,7 +86,7 @@ std::unique_ptr<base::Platform::DBus::ServiceWatcher> CreateServiceWatcher() {
return std::make_unique<base::Platform::DBus::ServiceWatcher>( return std::make_unique<base::Platform::DBus::ServiceWatcher>(
connection, connection,
std::string(kService), kService,
[=]( [=](
const Glib::ustring &service, const Glib::ustring &service,
const Glib::ustring &oldOwner, const Glib::ustring &oldOwner,
@ -115,7 +115,7 @@ void StartServiceAsync(Fn<void()> callback) {
base::Platform::DBus::StartServiceByNameAsync( base::Platform::DBus::StartServiceByNameAsync(
connection, connection,
std::string(kService), kService,
[=](Fn<base::Platform::DBus::StartReply()> result) { [=](Fn<base::Platform::DBus::StartReply()> result) {
Noexcept([&] { Noexcept([&] {
try { try {
@ -155,7 +155,7 @@ bool GetServiceRegistered() {
try { try {
return base::Platform::DBus::NameHasOwner( return base::Platform::DBus::NameHasOwner(
connection, connection,
std::string(kService)); kService);
} catch (...) { } catch (...) {
return false; return false;
} }
@ -165,7 +165,7 @@ bool GetServiceRegistered() {
try { try {
return ranges::contains( return ranges::contains(
base::Platform::DBus::ListActivatableNames(connection), base::Platform::DBus::ListActivatableNames(connection),
std::string(kService), kService,
&Glib::ustring::raw); &Glib::ustring::raw);
} catch (...) { } catch (...) {
return false; return false;
@ -186,8 +186,8 @@ void GetServerInformation(
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
connection->call( connection->call(
std::string(kObjectPath), kObjectPath,
std::string(kInterface), kInterface,
"GetServerInformation", "GetServerInformation",
{}, {},
[=](const Glib::RefPtr<Gio::AsyncResult> &result) { [=](const Glib::RefPtr<Gio::AsyncResult> &result) {
@ -224,7 +224,7 @@ void GetServerInformation(
crl::on_main([=] { callback(std::nullopt); }); crl::on_main([=] { callback(std::nullopt); });
}); });
}, },
std::string(kService)); kService);
}, [&] { }, [&] {
crl::on_main([=] { callback(std::nullopt); }); crl::on_main([=] { callback(std::nullopt); });
}); });
@ -236,8 +236,8 @@ void GetCapabilities(Fn<void(const QStringList &)> callback) {
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
connection->call( connection->call(
std::string(kObjectPath), kObjectPath,
std::string(kInterface), kInterface,
"GetCapabilities", "GetCapabilities",
{}, {},
[=](const Glib::RefPtr<Gio::AsyncResult> &result) { [=](const Glib::RefPtr<Gio::AsyncResult> &result) {
@ -257,7 +257,7 @@ void GetCapabilities(Fn<void(const QStringList &)> callback) {
crl::on_main([=] { callback({}); }); crl::on_main([=] { callback({}); });
}); });
}, },
std::string(kService)); kService);
}, [&] { }, [&] {
crl::on_main([=] { callback({}); }); crl::on_main([=] { callback({}); });
}); });
@ -269,11 +269,11 @@ void GetInhibited(Fn<void(bool)> callback) {
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
connection->call( connection->call(
std::string(kObjectPath), kObjectPath,
std::string(kPropertiesInterface), kPropertiesInterface,
"Get", "Get",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
Glib::ustring(std::string(kInterface)), Glib::ustring(kInterface),
Glib::ustring("Inhibited"), Glib::ustring("Inhibited"),
}), }),
[=](const Glib::RefPtr<Gio::AsyncResult> &result) { [=](const Glib::RefPtr<Gio::AsyncResult> &result) {
@ -290,7 +290,7 @@ void GetInhibited(Fn<void(bool)> callback) {
crl::on_main([=] { callback(false); }); crl::on_main([=] { callback(false); });
}); });
}, },
std::string(kService)); kService);
}, [&] { }, [&] {
crl::on_main([=] { callback(false); }); crl::on_main([=] { callback(false); });
}); });
@ -545,25 +545,25 @@ bool NotificationData::init(
_notificationRepliedSignalId = _notificationRepliedSignalId =
_dbusConnection->signal_subscribe( _dbusConnection->signal_subscribe(
signalEmitted, signalEmitted,
std::string(kService), kService,
std::string(kInterface), kInterface,
"NotificationReplied", "NotificationReplied",
std::string(kObjectPath)); kObjectPath);
} }
_actionInvokedSignalId = _dbusConnection->signal_subscribe( _actionInvokedSignalId = _dbusConnection->signal_subscribe(
signalEmitted, signalEmitted,
std::string(kService), kService,
std::string(kInterface), kInterface,
"ActionInvoked", "ActionInvoked",
std::string(kObjectPath)); kObjectPath);
_activationTokenSignalId = _dbusConnection->signal_subscribe( _activationTokenSignalId = _dbusConnection->signal_subscribe(
signalEmitted, signalEmitted,
std::string(kService), kService,
std::string(kInterface), kInterface,
"ActivationToken", "ActivationToken",
std::string(kObjectPath)); kObjectPath);
} }
if (capabilities.contains("action-icons")) { if (capabilities.contains("action-icons")) {
@ -594,10 +594,10 @@ bool NotificationData::init(
_notificationClosedSignalId = _dbusConnection->signal_subscribe( _notificationClosedSignalId = _dbusConnection->signal_subscribe(
signalEmitted, signalEmitted,
std::string(kService), kService,
std::string(kInterface), kInterface,
"NotificationClosed", "NotificationClosed",
std::string(kObjectPath)); kObjectPath);
return true; return true;
} }
@ -643,8 +643,8 @@ void NotificationData::show() {
const auto connection = _dbusConnection; const auto connection = _dbusConnection;
connection->call( connection->call(
std::string(kObjectPath), kObjectPath,
std::string(kInterface), kInterface,
"Notify", "Notify",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
Glib::ustring(std::string(AppName)), Glib::ustring(std::string(AppName)),
@ -673,7 +673,7 @@ void NotificationData::show() {
}); });
}); });
}, },
std::string(kService)); kService);
})); }));
} }
@ -690,14 +690,14 @@ void NotificationData::close() {
} }
_dbusConnection->call( _dbusConnection->call(
std::string(kObjectPath), kObjectPath,
std::string(kInterface), kInterface,
"CloseNotification", "CloseNotification",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
_notificationId, _notificationId,
}), }),
{}, {},
std::string(kService), kService,
-1, -1,
Gio::DBus::CallFlags::NO_AUTO_START); Gio::DBus::CallFlags::NO_AUTO_START);
_manager->clearNotification(_id); _manager->clearNotification(_id);
@ -987,7 +987,7 @@ Manager::Private::Private(not_null<Manager*> manager)
0 0
).get_dynamic<Glib::ustring>(); ).get_dynamic<Glib::ustring>();
if (interface != kInterface.data()) { if (interface != kInterface) {
return; return;
} }
@ -1003,10 +1003,10 @@ Manager::Private::Private(not_null<Manager*> manager)
}); });
}); });
}, },
std::string(kService), kService,
std::string(kPropertiesInterface), kPropertiesInterface,
"PropertiesChanged", "PropertiesChanged",
std::string(kObjectPath)); kObjectPath);
} }
} }

View file

@ -54,8 +54,6 @@ using Platform::internal::WaylandIntegration;
namespace Platform { namespace Platform {
namespace { namespace {
constexpr auto kDesktopFile = ":/misc/org.telegram.desktop.desktop"_cs;
bool PortalAutostart(bool start, bool silent) { bool PortalAutostart(bool start, bool silent) {
if (cExeName().isEmpty()) { if (cExeName().isEmpty()) {
return false; return false;
@ -138,8 +136,8 @@ bool PortalAutostart(bool start, bool silent) {
loop->quit(); loop->quit();
}, },
std::string(base::Platform::XDP::kService), base::Platform::XDP::kService,
std::string(base::Platform::XDP::kRequestInterface), base::Platform::XDP::kRequestInterface,
"Response", "Response",
requestPath); requestPath);
@ -150,14 +148,14 @@ bool PortalAutostart(bool start, bool silent) {
}); });
connection->call_sync( connection->call_sync(
std::string(base::Platform::XDP::kObjectPath), base::Platform::XDP::kObjectPath,
"org.freedesktop.portal.Background", "org.freedesktop.portal.Background",
"RequestBackground", "RequestBackground",
Glib::create_variant(std::tuple{ Glib::create_variant(std::tuple{
parentWindowId, parentWindowId,
options, options,
}), }),
std::string(base::Platform::XDP::kService)); base::Platform::XDP::kService);
if (signalId != 0) { if (signalId != 0) {
QWidget window; QWidget window;
@ -190,7 +188,7 @@ bool GenerateDesktopFile(
DEBUG_LOG(("App Info: placing .desktop file to %1").arg(targetPath)); DEBUG_LOG(("App Info: placing .desktop file to %1").arg(targetPath));
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath); if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
const auto sourceFile = kDesktopFile.utf16(); const auto sourceFile = u":/misc/org.telegram.desktop.desktop"_q;
const auto targetFile = targetPath const auto targetFile = targetPath
+ QGuiApplication::desktopFileName() + QGuiApplication::desktopFileName()
+ u".desktop"_q; + u".desktop"_q;