📄 battery.c
字号:
gkrellm_save_alertconfig(f, bat_alert, BAT_CONFIG_KEYWORD, NULL); }static voidload_battery_config(gchar *arg) { Battery *bat; gint display_mode, n = 0; gchar config[32], item[CFG_BUFSIZE], name[CFG_BUFSIZE], item1[CFG_BUFSIZE]; if (sscanf(arg, "%31s %[^\n]", config, item) == 2) { if (!strcmp(config, "enable")) sscanf(item, "%d", &enable_each); if (!strcmp(config, "enable_composite")) sscanf(item, "%d", &enable_composite); else if (!strcmp(config, "estimate_time")) sscanf(item, "%d", &enable_estimate); else if (!strcmp(config, "estimate_time_discharge")) { sscanf(item, "%f", &estimate_runtime[0]); estimate_runtime[0] /= _GK.float_factor; } else if (!strcmp(config, "estimate_time_charge")) { sscanf(item, "%f", &estimate_runtime[1]); estimate_runtime[1] /= _GK.float_factor; } else if (!strcmp(config, "estimate_time_charge_model")) sscanf(item, "%d", &estimate_model[1]); else if (!strcmp(config, "full_cap_fallback")) sscanf(item, "%d", &full_cap_fallback); else if (!strcmp(config, "poll_interval")) sscanf(item, "%d", &poll_interval); else if (!strcmp(config, "launch1")) launch.command = g_strdup(item); else if (!strcmp(config, "tooltip_comment")) launch.tooltip_comment = g_strdup(item); else if (!strncmp(config, "display_mode", 12)) { sscanf(item, "%d %d", &display_mode, &n); if ((bat = battery_nth(n, FALSE)) != NULL) bat->display_mode = display_mode; } else if (!strcmp(config, "alert_units_percent")) sscanf(item, "%d", &alert_units_percent); else if (!strcmp(config, GKRELLM_ALERTCONFIG_KEYWORD)) { if (!strncmp(item, "BAT", 3)) /* Config compat musical chairs */ sscanf(item, "%32s %[^\n]", name, item1); else strcpy(item1, item); create_alert(); gkrellm_load_alertconfig(&bat_alert, item1); dup_battery_alert(); } } }static GtkWidget *launch_entry, *tooltip_entry;static GtkWidget *estimate_runtime_spin_button[2], *estimate_model_button[2];static voidupdate_battery_panels(void) { GList *list; Battery *bat; for (list = battery_list; list; list = list->next) { bat = (Battery *) list->data; if (bat->enabled) update_battery_panel(bat); } }static voidcb_set_alert(GtkWidget *button, Battery *bat) { create_alert(); gkrellm_alert_config_window(&bat_alert); }static voidalert_units_percent_cb(GtkToggleButton *button, gpointer data) { GList *list; Battery *bat; alert_units_percent = button->active; if (bat_alert) { for (list = battery_list; list; list = list->next) { bat = (Battery *) list->data; gkrellm_reset_alert(bat->alert); gkrellm_alert_destroy(&bat->alert); } gkrellm_alert_destroy(&bat_alert); gkrellm_config_message_dialog(_("GKrellM Battery"), _("The Battery alert units are changed\n" "and the alert must be reconfigured.")); } }static voidcb_enable_estimate(GtkToggleButton *button, GtkWidget *box) { GList *list; Battery *bat; gboolean enable; enable = button->active; gtk_widget_set_sensitive(box, enable); if (enable_estimate != enable) { /* If alert units need estimated time mode and estimation switches off, | destroy the alert because the alert units can now only be percent. */ for (list = battery_list; list; list = list->next) { bat = (Battery *) list->data; if (bat->alert && (!enable && alert_units_need_estimate_mode)) gkrellm_alert_destroy(&bat->alert); } if ( bat_alert && (!enable && alert_units_need_estimate_mode) && !alert_units_percent ) { gkrellm_alert_destroy(&bat_alert); gkrellm_config_message_dialog(_("GKrellM Battery"), _("The Battery alert units are changed\n" "and the alert must be reconfigured.")); } } enable_estimate = enable; update_battery_panels(); }static voidcb_runtime(GtkWidget *entry, gpointer data) { gint i = GPOINTER_TO_INT(data) - 1; estimate_runtime[i] = gtk_spin_button_get_value( GTK_SPIN_BUTTON(estimate_runtime_spin_button[i])); reset_estimate = TRUE; update_battery_panels(); }static voidcb_enable(GtkToggleButton *button, gpointer data) { GList *list; Battery *bat; gint which = GPOINTER_TO_INT(data); if (which == 0) enable_composite = enable_each = button->active; else if (which == 1) enable_each = button->active; else if (which == 2) enable_composite = button->active; for (list = battery_list; list; list = list->next) { bat = (Battery *) list->data; if (bat == composite_battery) bat->enabled = enable_composite; else bat->enabled = enable_each; if (bat->enabled) { gkrellm_panel_show(bat->panel); update_battery_panel(bat); } else { gkrellm_reset_alert(bat->alert); gkrellm_panel_hide(bat->panel); } } if (composite_battery) { gkrellm_remove_launcher(&launch); if (composite_battery->enabled) { gkrellm_setup_decal_launcher(composite_battery->panel, &launch, composite_battery->time_decal); launch_battery = composite_battery; } else { bat = battery_nth(0, FALSE); if (bat && bat->enabled) { gkrellm_setup_decal_launcher(bat->panel, &launch, bat->time_decal); launch_battery = bat; } } } spacer_visibility(); }static voidcb_estimate_model(GtkWidget *entry, gpointer data) { gint i = GPOINTER_TO_INT(data); estimate_model[i] = GTK_TOGGLE_BUTTON(estimate_model_button[i])->active; reset_estimate = TRUE; update_battery_panels(); }static voidcb_poll_interval(GtkWidget *entry, GtkSpinButton *spin) { poll_interval = gtk_spin_button_get_value_as_int(spin); }static void cb_launch_entry(GtkWidget *widget, gpointer data) { if (!launch_battery) return; gkrellm_apply_launcher(&launch_entry, &tooltip_entry, launch_battery->panel, &launch, gkrellm_launch_button_cb); }static gchar *battery_info_text[] ={N_("<h>Setup\n"),N_("<b>Display Estimated Time\n"),N_("If battery times are not reported by the BIOS or if the reported times\n""are inaccurate, select this option to display a battery time remaining or\n""time to charge which is calculated based on the current battery percentage\n""level, user supplied total battery times, and a linear extrapolation model.\n"),"\n",N_("<b>Total Battery Times\n"),N_("Enter the typical total run time and total charge time in hours for your\n""battery.\n"),"\n",N_("<b>Exponential Charge Model\n"), /* xgettext:no-c-format */N_("For some charging systems battery capacity rises exponentially, which\n""means the simple linear model will grossly underestimate the time to 100%.\n""Select the exponential model for more accuracy in this case.\n"),"\n","<b>",N_("Alerts"),"\n",N_("Substitution variables may be used in alert commands.\n"),N_("\t$p battery percent level.\n"),N_("\t$t battery time left.\n"),N_("\t$n battery number.\n"),N_("\t$o online state (boolean).\n"),N_("\t$c charging state (boolean).\n"),"\n",N_("<h>Mouse Button Actions:\n"),N_("<b>\tLeft "),N_(" click on the charging state decal to toggle the display mode\n""\t\tbetween a minutes, percentage, or charging rate display.\n"),N_("<b>\tMiddle "),N_(" clicking anywhere on the Battery panel also toggles the display mode.\n")};static voidcreate_battery_tab(GtkWidget *tab_vbox) { GtkWidget *tabs, *table, *vbox, *vbox1, *vbox2, *hbox, *hbox2, *text; Battery *bat; gint i; tabs = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab_vbox), tabs, TRUE, TRUE, 0);/* -- Setup tab */ vbox = gkrellm_gtk_notebook_page(tabs, _("Options")); vbox = gkrellm_gtk_framed_vbox(vbox, NULL, 2, TRUE, 10, 6); if (composite_battery && n_batteries > 0) { vbox1 = gkrellm_gtk_category_vbox(vbox, _("Enable"), 2, 2, TRUE); gkrellm_gtk_check_button_connected(vbox1, NULL, enable_composite, FALSE, FALSE, 0, cb_enable, GINT_TO_POINTER(2), _("Composite Battery")); gkrellm_gtk_check_button_connected(vbox1, NULL, enable_each, FALSE, FALSE, 0, cb_enable, GINT_TO_POINTER(1), _("Real Batteries")); } else gkrellm_gtk_check_button_connected(vbox, NULL, enable_each, FALSE, FALSE, 10, cb_enable, GINT_TO_POINTER(0), _("Enable Battery")); vbox2 = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0); vbox1 = gtk_vbox_new(FALSE, 0); gkrellm_gtk_check_button_connected(vbox2, NULL, enable_estimate, FALSE, FALSE, 2, cb_enable_estimate, vbox1, _("Display estimated time remaining and time to charge")); gtk_widget_set_sensitive(vbox1, enable_estimate ? TRUE : FALSE); gtk_box_pack_start(GTK_BOX(vbox2), vbox1, FALSE, FALSE, 0); vbox1 = gkrellm_gtk_category_vbox(vbox1, NULL, 0, 0, TRUE); gkrellm_gtk_spin_button(vbox1, &estimate_runtime_spin_button[0], estimate_runtime[0], 0.1, 24, 0.1, 1.0, 1, 55, cb_runtime, GINT_TO_POINTER(1), FALSE, _("Total battery run time in hours")); gkrellm_gtk_spin_button(vbox1, &estimate_runtime_spin_button[1], estimate_runtime[1], 0.1, 24, 0.1, 1.0, 1, 55, cb_runtime, GINT_TO_POINTER(2), FALSE, _("Total battery charge time in hours")); gkrellm_gtk_check_button_connected(vbox1, &estimate_model_button[1], estimate_model[1], FALSE, FALSE, 0, cb_estimate_model, GINT_TO_POINTER(1), _("Exponential charge model")); if (!_GK.client_mode) { hbox2 = gtk_hbox_new(FALSE, 0); gkrellm_gtk_spin_button(hbox2, NULL, (gfloat) poll_interval, 1, 3600, 1, 10, 0, 55, cb_poll_interval, NULL, FALSE, _("Seconds between updates")); gtk_box_pack_end(GTK_BOX(vbox), hbox2, FALSE, FALSE, 6); } vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Setup")); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 8); gkrellm_gtk_alert_button(hbox, NULL, FALSE, FALSE, 4, TRUE, cb_set_alert, NULL); if (battery_list) { bat = (Battery *) battery_list->data; if (bat && bat->time_left >= 0) /* No choice if no battery times */ gkrellm_gtk_check_button_connected(hbox, NULL, alert_units_percent, FALSE, FALSE, 16, alert_units_percent_cb, NULL, _("Alerts check for percent capacity remaining.")); } vbox1 = gkrellm_gtk_framed_vbox_end(vbox, _("Launch Commands"), 4, FALSE, 0, 2); table = gkrellm_gtk_launcher_table_new(vbox1, 1); gkrellm_gtk_config_launcher(table, 0, &launch_entry, &tooltip_entry, _("Battery"), &launch); g_signal_connect(G_OBJECT(launch_entry), "changed", G_CALLBACK(cb_launch_entry), NULL); g_signal_connect(G_OBJECT(tooltip_entry), "changed", G_CALLBACK(cb_launch_entry), NULL);/* --Info tab */ vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Info")); text = gkrellm_gtk_scrolled_text_view(vbox, NULL, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); for (i = 0; i < sizeof(battery_info_text)/sizeof(gchar *); ++i) gkrellm_gtk_text_view_append(text, _(battery_info_text[i])); }static GkrellmMonitor monitor_battery = { N_("Battery"), /* Name, for config tab. */ MON_BATTERY, /* Id, 0 if a plugin */ create_battery, /* The create function */ update_battery, /* The update function */ create_battery_tab, /* The config tab create function */ NULL, /* Apply the config function */ save_battery_config, /* Save user conifg */ load_battery_config, /* Load user config */ BAT_CONFIG_KEYWORD, /* config keyword */ NULL, /* Undef 2 */ NULL, /* Undef 1 */ NULL, /* Undef 0 */ 0, /* insert_before_id - place plugin before this mon */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ };GkrellmMonitor *gkrellm_init_battery_monitor(void) { estimate_runtime[0] = 1.5; /* 1.5 hour battery */ estimate_runtime[1] = 3.0; /* 3 hour recharge */ if (_GK.client_mode) poll_interval = 1; monitor_battery.name=_(monitor_battery.name); style_id = gkrellm_add_meter_style(&monitor_battery, BATTERY_STYLE_NAME); mon_battery = &monitor_battery; if (setup_battery_interface()) { (*read_battery_data)(); return &monitor_battery; } return NULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -