Exemplo n.º 1
0
static void
query_current_values (NCore *core)
{
    NContext      *context     = n_core_get_context (core);
    char         **profiles    = NULL;
    char         **p           = NULL;
    const char    *current     = NULL;
    profileval_t  *values      = NULL;
    profileval_t  *v           = NULL;
    gboolean       is_current  = FALSE;

    profiles = profile_get_profiles ();
    current  = n_value_get_string ((NValue*) n_context_get_value (context,
        "profile.current_profile"));

    for (p = profiles; *p; ++p) {
        is_current = current && g_str_equal (current, *p);
        values = profile_get_values (*p);
        for (v = values; v->pv_key; ++v) {
            update_context_value (context, *p, v->pv_key, v->pv_val);
            if (is_current)
                update_context_value (context, NULL, v->pv_key, v->pv_val);
        }
        profile_free_values (values);
    }

    /* fallbacks */

    /* This is in a way a bug, since profiled doesn't expose fallback settings ever,
     * but, when requesting non-existing profile, profile_get_values() returns
     * fallback profile contents. */
    values = profile_get_values ("fallback");
    for (v = values; v->pv_key; ++v)
        update_context_value (context, "fallback", v->pv_key, v->pv_val);
    profile_free_values (values);

    profile_free_profiles (profiles);
}
void
ProfileBackend::initialize ()
{
    // initialization should be done only once...
    if (m_initialized)
        return;

    m_initialized = true;

#ifdef HAVE_LIBPROFILE
    // get the current profile name
    m_activeProfile = profile_get_profile ();

    char **profiles = NULL;

    // get the list of available profiles
    profiles = profile_get_profiles ();

    if (profiles != NULL)
    {
        for (int i = 0; profiles[i] != NULL; i++)
        {
            char *profile = profiles[i];

            int  volumeLevel = profile_get_value_as_int (profile, keyVolume);
            bool vibration = profile_get_value_as_bool (profile, keyVibration);

            SYS_DEBUG ("*** PROFILE : \"%s\" ***", profile);

            // fill the hash tables...
            m_profileVibrations[QString (profile)] = vibration;
            m_profileVolumes[QString (profile)]    = volumeLevel;
        }

        profile_free_profiles (profiles);
    }
    else
    {
        SYS_WARNING ("There are no available profiles on the system!");
    }

    // callback to track current profile changes...
    profile_track_add_profile_cb (
        (profile_track_profile_fn_data) &ProfileBackend::currentProfileChanged,
        this, NULL);

    // callback to track profile value changes...
    profile_track_add_change_cb (
        (profile_track_value_fn_data) &ProfileBackend::profileValueChanged,
        this, NULL);

    // callback to track current profile value changes...
    // XXX: is this call really necessary? FIXME
    profile_track_add_active_cb (
        (profile_track_value_fn_data) &ProfileBackend::profileValueChanged,
        this, NULL);

    // start the tracking of changes...
    profile_connection_enable_autoconnect ();
    profile_tracker_init ();
#endif // HAVE_LIBPROFILE
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  int opt;

  char *p,*k,*v,**w;

  while( (opt = getopt(argc, argv, "hp:s:d:g:t:TlkvV:B:I:D:G:rR:")) != -1 )
  {
    switch (opt)
    {
    case 'h':
      write(STDOUT_FILENO, usage, sizeof usage - 1);
      exit(0);

    case 'p':
      profile_set_profile(optarg);
      break;

    case 'l':
      p = profile_get_profile();
      w = profile_get_profiles();
      for( size_t i = 0; w && w[i]; ++i )
      {
        printf("%s%s\n", w[i], strcmp(w[i],p) ? "" : "*");
      }
      profile_free_profiles(w);
      free(p);
      break;

    case 'k':
      w = profile_get_keys();
      for( size_t i = 0; w && w[i]; ++i )
      {
        printf("%s\n", w[i]);
      }
      profile_free_keys(w);
      break;

    case 'r':
      w = profile_get_keys();
      for( size_t i = 0; w && w[i]; ++i )
      {
        profile_set_value(0, w[i], "");
      }
      profile_free_keys(w);
      break;

    case 'R':
      w = profile_get_keys();
      for( size_t i = 0; w && w[i]; ++i )
      {
        profile_set_value(optarg, w[i], "");
      }
      profile_free_keys(w);
      break;

    case 'v':
    case 'V':
      {
        p = (opt == 'v') ? 0 : optarg;
        profileval_t *t = profile_get_values(p);

        for( size_t i = 0; t && t[i].pv_key; ++i )
        {
          printf("%s = %s (%s)\n", t[i].pv_key, t[i].pv_val, t[i].pv_type);
        }
        profile_free_values(t);
      }
      break;

    case 'T':
      exit(track());

    case 's':
      parse(optarg, &p,&k,&v);
      profile_set_value(p, k, v);
      break;

    case 'd':
      parse(optarg, &p,&k,&v);
      profile_set_value(p, k, "");
      break;

    case 'g':
      parse(optarg, &p,&k,&v);
      v = profile_get_value(p,k);
      printf("%s\n", v);
      free(v);
      break;

    case 'G':
      {
        parse(optarg, &p,&k,&v);

        char *s = profile_get_value(p,k);
        printf("STRING: '%s'\n", s);
        free(s);

        int b = profile_get_value_as_bool(p,k);
        printf("BOOL: %s (%d)\n", b ? "On" : "Off", b);

        int i = profile_get_value_as_int(p,k);
        printf("INT: %d\n", i);

        double d = profile_get_value_as_double(p,k);
        printf("DOUBLE:%g\n", d);
      }
      break;

    case 'B':
      {
        parse(optarg, &p,&k,&v);
        int v = profile_get_value_as_bool(p,k);
        printf("BOOL:%s (%d)\n", v ? "On" : "Off", v);
      }
      break;

    case 'I':
      {
        parse(optarg, &p,&k,&v);
        int v = profile_get_value_as_int(p,k);
        printf("INT:%d\n", v);
      }
      break;

    case 'D':
      {
        parse(optarg, &p,&k,&v);
        double v = profile_get_value_as_double(p,k);
        printf("DOUBLE:%g\n", v);
      }
      break;

    case 't':
      v = profile_get_type(optarg);
      printf("%s\n", v);
      free(v);
      break;

    default: /* '?' */
      fprintf(stderr, "(use -h for usage info)\n");
      exit(EXIT_FAILURE);
    }
  }

  return 0;
}