Use ServerInformation without std::optional

This commit is contained in:
Ilya Fedin 2023-09-19 15:25:30 +04:00 committed by John Preston
parent 90f52d80d7
commit 0f86968afd

View file

@ -50,7 +50,7 @@ struct ServerInformation {
}; };
bool ServiceRegistered = false; bool ServiceRegistered = false;
std::optional<ServerInformation> CurrentServerInformation; ServerInformation CurrentServerInformation;
std::vector<Glib::ustring> CurrentCapabilities; std::vector<Glib::ustring> CurrentCapabilities;
void Noexcept(Fn<void()> callback, Fn<void()> failed = nullptr) noexcept { void Noexcept(Fn<void()> callback, Fn<void()> failed = nullptr) noexcept {
@ -177,8 +177,7 @@ bool GetServiceRegistered() {
return false; return false;
} }
void GetServerInformation( void GetServerInformation(Fn<void(const ServerInformation &)> callback) {
Fn<void(const std::optional<ServerInformation> &)> callback) {
Noexcept([&] { Noexcept([&] {
const auto connection = Gio::DBus::Connection::get_sync( const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
@ -218,13 +217,13 @@ void GetServerInformation(
QString::fromStdString(specVersion)), QString::fromStdString(specVersion)),
}); });
}, [&] { }, [&] {
callback(std::nullopt); callback({});
}); });
}); });
}, },
kService); kService);
}, [&] { }, [&] {
callback(std::nullopt); callback({});
}); });
} }
@ -294,10 +293,6 @@ void GetInhibited(Fn<void(bool)> callback) {
}); });
} }
ServerInformation CurrentServerInformationValue() {
return CurrentServerInformation.value_or(ServerInformation{});
}
Glib::ustring GetImageKey(const QVersionNumber &specificationVersion) { Glib::ustring GetImageKey(const QVersionNumber &specificationVersion) {
const auto normalizedVersion = specificationVersion.normalized(); const auto normalizedVersion = specificationVersion.normalized();
@ -509,7 +504,7 @@ bool NotificationData::init(
}); });
}); });
_imageKey = GetImageKey(CurrentServerInformationValue().specVersion); _imageKey = GetImageKey(CurrentServerInformation.specVersion);
if (ranges::contains(capabilities, "body-markup")) { if (ranges::contains(capabilities, "body-markup")) {
_title = title.toStdString(); _title = title.toStdString();
@ -867,14 +862,13 @@ void Create(Window::Notifications::System *system) {
ServiceRegistered = GetServiceRegistered(); ServiceRegistered = GetServiceRegistered();
if (!ServiceRegistered) { if (!ServiceRegistered) {
CurrentServerInformation = std::nullopt; CurrentServerInformation = {};
CurrentCapabilities = {}; CurrentCapabilities = {};
managerSetter(); managerSetter();
return; return;
} }
GetServerInformation([=]( GetServerInformation([=](const ServerInformation &result) {
const std::optional<ServerInformation> &result) {
CurrentServerInformation = result; CurrentServerInformation = result;
oneReady(); oneReady();
}); });
@ -927,18 +921,24 @@ Manager::Private::Private(not_null<Manager*> manager)
const auto &serverInformation = CurrentServerInformation; const auto &serverInformation = CurrentServerInformation;
const auto &capabilities = CurrentCapabilities; const auto &capabilities = CurrentCapabilities;
if (serverInformation.has_value()) { if (!serverInformation.name.empty()) {
LOG(("Notification daemon product name: %1") LOG(("Notification daemon product name: %1")
.arg(serverInformation->name.c_str())); .arg(serverInformation.name.c_str()));
}
if (!serverInformation.vendor.empty()) {
LOG(("Notification daemon vendor name: %1") LOG(("Notification daemon vendor name: %1")
.arg(serverInformation->vendor.c_str())); .arg(serverInformation.vendor.c_str()));
}
if (!serverInformation.version.isNull()) {
LOG(("Notification daemon version: %1") LOG(("Notification daemon version: %1")
.arg(serverInformation->version.toString())); .arg(serverInformation.version.toString()));
}
if (!serverInformation.specVersion.isNull()) {
LOG(("Notification daemon specification version: %1") LOG(("Notification daemon specification version: %1")
.arg(serverInformation->specVersion.toString())); .arg(serverInformation.specVersion.toString()));
} }
if (!capabilities.empty()) { if (!capabilities.empty()) {