| 186 | } |
| 187 | |
| 188 | auto UPower::update() -> void { |
| 189 | std::lock_guard<std::mutex> guard{mutex_}; |
| 190 | // Don't update widget if the UPower service isn't running |
| 191 | if (!upRunning_ || sleeping_) { |
| 192 | if (hideIfEmpty_) box_.hide(); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | getUpDeviceInfo(upDevice_); |
| 197 | |
| 198 | if (upDevice_.upDevice == NULL && hideIfEmpty_) { |
| 199 | box_.hide(); |
| 200 | return; |
| 201 | } |
| 202 | /* Every Device which is handled by Upower and which is not |
| 203 | * UP_DEVICE_KIND_UNKNOWN (0) or UP_DEVICE_KIND_LINE_POWER (1) is a Battery |
| 204 | */ |
| 205 | const bool upDeviceValid{upDevice_.kind != UpDeviceKind::UP_DEVICE_KIND_UNKNOWN && |
| 206 | upDevice_.kind != UpDeviceKind::UP_DEVICE_KIND_LINE_POWER}; |
| 207 | // Get CSS status |
| 208 | const auto status{getDeviceStatus(upDevice_.state)}; |
| 209 | // Remove last status if it exists |
| 210 | if (!lastStatus_.empty() && box_.get_style_context()->has_class(lastStatus_)) |
| 211 | box_.get_style_context()->remove_class(lastStatus_); |
| 212 | if (!box_.get_style_context()->has_class(status)) box_.get_style_context()->add_class(status); |
| 213 | lastStatus_ = status; |
| 214 | |
| 215 | if (devices_.size() == 0 && !upDeviceValid && hideIfEmpty_) { |
| 216 | box_.hide(); |
| 217 | // Call parent update |
| 218 | AModule::update(); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | label_.set_markup(getText(upDevice_, format_)); |
| 223 | // Set icon |
| 224 | if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name)) |
| 225 | upDevice_.icon_name = (char*)NO_BATTERY.c_str(); |
| 226 | image_.set_from_icon_name(upDevice_.icon_name, Gtk::ICON_SIZE_INVALID); |
| 227 | |
| 228 | box_.show(); |
| 229 | |
| 230 | // Call parent update |
| 231 | ALabel::update(); |
| 232 | } |
| 233 | |
| 234 | void UPower::getConn_cb(Glib::RefPtr<Gio::AsyncResult>& result) { |
| 235 | try { |
nothing calls this directly
no test coverage detected