예제 #1
0
파일: plugin.c 프로젝트: kvahlman/ngfd
static void
update_context_value (NContext *context, const char *profile, const char *key,
                      const char *value)
{
    gchar  *context_key = NULL;
    NValue *context_val = NULL;
    gint    level       = 0;
    gchar  *new_val     = NULL;

    context_key = construct_context_key (profile, key);
    context_val = n_value_new ();

    if (g_str_has_suffix (key, TONE_SUFFIX) ||
        g_str_has_suffix (key, PATTERN_SUFFIX)) {
        new_val = get_absolute_tone_path (value);
        new_val = new_val != NULL ? new_val : g_strdup (value);
        n_value_set_string (context_val, new_val);
        g_free (new_val);
    }
    else if (g_str_has_suffix (key, VOLUME_SUFFIX)) {
        n_value_set_int (context_val, profile_parse_int (value));
    }
    else if (g_str_has_suffix (key, SYSTEM_SUFFIX)) {
        level = profile_parse_int (value);
        level = CLAMP_VALUE (level, 0, (gint) num_system_sound_levels-1);
        n_value_set_int (context_val, system_sound_levels[level]);
    }
    else if (g_str_equal (key, KEY_VIBRATION_ENABLED)) {
        n_value_set_bool (context_val, profile_parse_bool (value));
    } else if (g_str_equal (key, KEY_TOUCH_VIBRA_LEVEL)) {
        n_value_set_int (context_val, profile_parse_int (value));
    } else {
        n_value_set_string (context_val, value);
    }

    n_context_set_value (context, context_key, context_val);
    g_free (context_key);
}
void
ProfileBackend::changeProfileValue (
    const char      *profile,
    const char      *key,
    const char      *value)
{
#ifdef HAVE_LIBPROFILE
    QString profileName = profile;

    if (m_profileVolumes.value (profileName, -1) < 0)
    {
        SYS_WARNING ("Invalid profile: %s, ignoring...", profile);
        return;
    }

    if (qstrcmp (keyVolume, key) == 0)
    {
        int volume = profile_parse_int (value);

        m_profileVolumes[profileName] = volume;

        emit volumeSettingChanged (profileName, volume);
    }
    else if (qstrcmp (keyVibration, key) == 0)
    {
        bool vibration = profile_parse_bool (value);

        m_profileVibrations[profileName] = vibration;

        emit vibrationSettingChanged (profileName, vibration);
    }
    else
    {
        SYS_WARNING ("Error, invalid key: %s", key);
    }
#endif
}