コード例 #1
0
ファイル: plugin.c プロジェクト: plundstr/ngfd
static void
transform_properties_cb (NHook *hook, void *data, void *userdata)
{
    (void) hook;
    (void) data;
    (void) userdata;

    NCore        *core        = (NCore*) userdata;
    NContext     *context     = n_core_get_context (core);
    NProplist    *new_props   = NULL;
    NProplist    *props       = NULL;
    GList        *iter        = NULL;
    const char   *match_str   = NULL;
    ProfileEntry *entry       = NULL;
    NValue       *value       = NULL;
    gchar        *context_key = NULL;

    NCoreHookTransformPropertiesData *transform = (NCoreHookTransformPropertiesData*) data;

    N_DEBUG (LOG_CAT "transforming profile values for request '%s'",
        n_request_get_name (transform->request));

    new_props = n_proplist_new ();
    props = (NProplist*) n_request_get_properties (transform->request);
    for (iter = g_list_first (request_keys); iter; iter = g_list_next (iter)) {
        match_str = n_proplist_get_string (props, (gchar*) iter->data);
        if (!match_str)
            continue;

        entry = g_hash_table_lookup (profile_entries, match_str);
        if (!entry)
            continue;

        /* if this a fallback request, we don't care if there is existing
           target. otherwise check if the target exists. */

        if (!n_request_is_fallback (transform->request) &&
             n_proplist_has_key (props, entry->target))
            continue;

        context_key = construct_context_key (entry->profile, entry->key);
        value = (NValue*) n_context_get_value (context, context_key);

        if (value) {
            N_DEBUG (LOG_CAT "+ transforming profile key '%s' to target '%s'",
                entry->key, entry->target);
            n_proplist_set (new_props, entry->target, n_value_copy (value));
        }

        g_free (context_key);
    }

    n_proplist_merge (props, new_props);
    n_proplist_free (new_props);

    N_DEBUG (LOG_CAT "new properties:")
    n_proplist_dump (props);
}
コード例 #2
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);
}