diff options
Diffstat (limited to 'src/gpm-common.c')
-rw-r--r-- | src/gpm-common.c | 108 |
1 files changed, 35 insertions, 73 deletions
diff --git a/src/gpm-common.c b/src/gpm-common.c index 0d0e536..e7d1d66 100644 --- a/src/gpm-common.c +++ b/src/gpm-common.c @@ -79,88 +79,50 @@ gpm_get_timestring (guint time_secs) } /** - * gpm_icon_policy_from_string: - **/ -GpmIconPolicy -gpm_icon_policy_from_string (const gchar *policy) -{ - if (policy == NULL) - return GPM_ICON_POLICY_NEVER; - if (g_strcmp0 (policy, "always") == 0) - return GPM_ICON_POLICY_ALWAYS; - if (g_strcmp0 (policy, "present") == 0) - return GPM_ICON_POLICY_PRESENT; - if (g_strcmp0 (policy, "charge") == 0) - return GPM_ICON_POLICY_CHARGE; - if (g_strcmp0 (policy, "low") == 0) - return GPM_ICON_POLICY_LOW; - if (g_strcmp0 (policy, "critical") == 0) - return GPM_ICON_POLICY_CRITICAL; - if (g_strcmp0 (policy, "never") == 0) - return GPM_ICON_POLICY_NEVER; - return GPM_ICON_POLICY_NEVER; -} - -/** - * gpm_icon_policy_to_string: + * gpm_discrete_from_percent: + * @percentage: The percentage to convert + * @levels: The number of discrete levels + * + * We have to be carefull when converting from %->discrete as precision is very + * important if we want the highest value. + * + * Return value: The discrete value for this percentage. **/ -const gchar * -gpm_icon_policy_to_string (GpmIconPolicy policy) +guint +gpm_discrete_from_percent (guint percentage, guint levels) { - if (policy == GPM_ICON_POLICY_ALWAYS) - return "always"; - if (policy == GPM_ICON_POLICY_PRESENT) - return "present"; - if (policy == GPM_ICON_POLICY_CHARGE) - return "charge"; - if (policy == GPM_ICON_POLICY_LOW) - return "low"; - if (policy == GPM_ICON_POLICY_CRITICAL) - return "critical"; - if (policy == GPM_ICON_POLICY_NEVER) - return "never"; - return "never"; + /* check we are in range */ + if (percentage > 100) + return levels; + if (levels == 0) { + g_warning ("levels is 0!"); + return 0; + } + return (guint) ((((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f) + 0.5f); } /** - * gpm_action_policy_from_string: + * gpm_discrete_to_percent: + * @hw: The discrete level + * @levels: The number of discrete levels + * + * We have to be carefull when converting from discrete->%. + * + * Return value: The percentage for this discrete value. **/ -GpmActionPolicy -gpm_action_policy_from_string (const gchar *policy) +guint +gpm_discrete_to_percent (guint discrete, guint levels) { - if (policy == NULL) - return GPM_ACTION_POLICY_NOTHING; - if (g_strcmp0 (policy, "blank") == 0) - return GPM_ACTION_POLICY_BLANK; - if (g_strcmp0 (policy, "shutdown") == 0) - return GPM_ACTION_POLICY_SHUTDOWN; - if (g_strcmp0 (policy, "suspend") == 0) - return GPM_ACTION_POLICY_SUSPEND; - if (g_strcmp0 (policy, "hibernate") == 0) - return GPM_ACTION_POLICY_HIBERNATE; - if (g_strcmp0 (policy, "interactive") == 0) - return GPM_ACTION_POLICY_INTERACTIVE; - return GPM_ACTION_POLICY_NOTHING; + /* check we are in range */ + if (discrete > levels) + return 100; + if (levels == 0) { + g_warning ("levels is 0!"); + return 0; + } + return (guint) (((gfloat) discrete * (100.0f / (gfloat) (levels - 1))) + 0.5f); } -/** - * gpm_action_policy_to_string: - **/ -const gchar * -gpm_action_policy_to_string (GpmActionPolicy policy) -{ - if (policy == GPM_ACTION_POLICY_BLANK) - return "blank"; - if (policy == GPM_ACTION_POLICY_SHUTDOWN) - return "shutdown"; - if (policy == GPM_ACTION_POLICY_SUSPEND) - return "suspend"; - if (policy == GPM_ACTION_POLICY_HIBERNATE) - return "hibernate"; - if (policy == GPM_ACTION_POLICY_INTERACTIVE) - return "interactive"; - return "nothing"; -} /** * gpm_help_display: |