MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / battery_level_cb

Function battery_level_cb

gtk/src/power-manager.c:73–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73static void
74battery_level_cb (GDBusProxy *proxy, GVariant *changed_properties,
75 GStrv invalidated_properties, signal_user_data_t *ud)
76{
77 int battery_level = -1;
78 const char *prop_name;
79 int queue_state;
80 GVariant *var;
81 GVariantIter iter;
82 int low_battery_level = 0;
83
84 if (!ghb_dict_get_bool(ud->prefs, "PauseEncodingOnLowBattery"))
85 return;
86
87 low_battery_level = ghb_dict_get_int(ud->prefs, "LowBatteryLevel");
88
89 g_variant_iter_init(&iter, changed_properties);
90 while (g_variant_iter_next(&iter, "{&sv}", &prop_name, &var))
91 {
92 if (g_strcmp0("Percentage", prop_name) == 0)
93 battery_level = (int) g_variant_get_double(var);
94
95 g_variant_unref(var);
96 }
97 if (battery_level < 0)
98 return;
99
100 queue_state = ghb_get_queue_state();
101
102 if (battery_level <= low_battery_level
103 && prev_battery_level > low_battery_level
104 && (queue_state & GHB_STATE_WORKING)
105 && !(queue_state & GHB_STATE_PAUSED))
106 {
107 power_state = GHB_POWER_PAUSED_LOW_BATTERY;
108 ghb_log("Battery level %d%%: pausing encode", battery_level);
109 ghb_send_notification(GHB_NOTIFY_PAUSED_LOW_BATTERY, 0, ud);
110 ghb_pause_queue();
111 }
112 else if (battery_level > low_battery_level
113 && prev_battery_level <= low_battery_level
114 && (power_state == GHB_POWER_PAUSED_LOW_BATTERY))
115 {
116 if (queue_state & GHB_STATE_PAUSED)
117 {
118 ghb_resume_queue();
119 ghb_log("Battery level %d%%: resuming encode", battery_level);
120 ghb_withdraw_notification(GHB_NOTIFY_PAUSED_LOW_BATTERY);
121 }
122 power_state = GHB_POWER_OK;
123 }
124 prev_battery_level = battery_level;
125}
126
127static void
128battery_proxy_new_cb (GObject *source, GAsyncResult *result,

Callers

nothing calls this directly

Calls 8

ghb_dict_get_boolFunction · 0.85
ghb_dict_get_intFunction · 0.85
ghb_get_queue_stateFunction · 0.85
ghb_logFunction · 0.85
ghb_send_notificationFunction · 0.85
ghb_pause_queueFunction · 0.85
ghb_resume_queueFunction · 0.85

Tested by

no test coverage detected