void
Ut_ProfileValueTests::profilevalueNotifyValue()
{
#ifdef HAVE_LIBPROFILE
      cnt = 0;
      QProfileValue  pv("ringing.alert.volume");
      QObject::connect(&pv, SIGNAL(changed()), this, SLOT( catchsignal() ));
      QStringList list;
      list << "general" << "silent";
      QString profile = profile_get_profile();

      QProfileValue::notifyValue( profile.toAscii(), "ringing.alert.volume", 0, 0, &pv);
      QVERIFY( cnt );

      cnt = 0;
      QProfileValue::notifyValue( profile.toAscii(), "system.sound.level", 0, 0, &pv);

      QVERIFY( !cnt );

      if (profile == list.at(0))
            profile = list.at(1);
      else
            profile = list.at(0);

      QProfileValue::notifyValue( profile.toAscii(), "system.sound.level", 0, 0, &pv);
      QVERIFY( !cnt );
#endif
}
QString ProfileControl::profile()
{
    if (m_profile.isEmpty()) {
        m_profile = QString::fromUtf8(profile_get_profile());
    }

    return m_profile;
}
Exemplo n.º 3
0
static void
query_current_profile (NCore *core)
{
    NContext   *context = n_core_get_context (core);
    NValue     *value   = NULL;
    char       *profile = NULL;

    profile = profile_get_profile ();

    /* store the current profile to the context */

    value = n_value_new ();
    n_value_set_string (value, profile);
    n_context_set_value (context, "profile.current_profile", value);
    N_DEBUG (LOG_CAT "current profile set to '%s'", profile);

    free (profile);
}
Exemplo n.º 4
0
profile_plugin * init_profile()
{
    profile_plugin *plugin = g_new0(profile_plugin, 1);
    char *profile = NULL;
    profileval_t *values = NULL;

    if (!plugin) {
        return NULL;
    }

    
    /* let libprofile know the correct bus connection */
    profile_connection_set(bus_conn);
    
    /* get current profile */
    profile = profile_get_profile();

    /* start tracking profile changes */
    if (profile && subscribe_to_service()) {
        values = profile_get_values(profile);
    }
    else {
        g_free(plugin);
        plugin = NULL;
        goto end;
    }

    if (!profile_create_fact(profile, values)) {
        g_free(plugin);
        plugin = NULL;
        goto end;
    }

end:

    free(profile);
    profile_free_values(values);

    return plugin;
}
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.º 6
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;
}