ProfileControl::ProfileControl(QObject *parent)
    : QObject(parent),
      m_systemSoundLevel(-1),
      m_touchscreenToneLevel(-1),
      m_touchscreenVibrationLevel(-1),
      m_ringerToneEnabled(-1),
      m_messageToneEnabled(-1),
      m_chatToneEnabled(-1),
      m_mailToneEnabled(-1),
      m_internetCallToneEnabled(-1),
      m_calendarToneEnabled(-1),
      m_clockAlarmToneEnabled(-1)
{
    profile_track_add_profile_cb((profile_track_profile_fn_data) currentProfileChangedCallback, this, NULL);

    // track changes in active and inactive profile(s)
    profile_track_add_active_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this, NULL);
    profile_track_add_change_cb((profile_track_value_fn_data) &updateStateCallBackTrampoline, this, NULL);

    profile_connection_enable_autoconnect();

    if (s_instanceCounter == 0) {
        profile_tracker_init();
    }
    s_instanceCounter++;

    m_ringerVolume = profile_get_value_as_int(GeneralProfile, VolumeKey);
    m_vibraInGeneral = profile_get_value_as_bool(GeneralProfile, VibraKey);
    m_vibraInSilent = profile_get_value_as_bool(SilentProfile, VibraKey);
}
bool ProfileControl::clockAlarmToneEnabled()
{
    if (m_clockAlarmToneEnabled == -1) {
        m_clockAlarmToneEnabled = profile_get_value_as_bool(GeneralProfile, ClockAlarmToneEnabledKey);
    }
    return m_clockAlarmToneEnabled;
}
bool ProfileControl::calendarToneEnabled()
{
    if (m_calendarToneEnabled == -1) {
        m_calendarToneEnabled = profile_get_value_as_bool(GeneralProfile, CalendarToneEnabledKey);
    }
    return m_calendarToneEnabled;
}
bool ProfileControl::internetCallToneEnabled()
{
    if (m_internetCallToneEnabled == -1) {
        m_internetCallToneEnabled = profile_get_value_as_bool(GeneralProfile, InternetCallToneEnabledKey);
    }
    return m_internetCallToneEnabled;
}
bool ProfileControl::mailToneEnabled()
{
    if (m_mailToneEnabled == -1) {
        m_mailToneEnabled = profile_get_value_as_bool(GeneralProfile, MailToneEnabledKey);
    }
    return m_mailToneEnabled;
}
bool ProfileControl::ringerToneEnabled()
{
    if (m_ringerToneEnabled == -1) {
        m_ringerToneEnabled = profile_get_value_as_bool(GeneralProfile, RingerToneEnabledKey);
    }
    return m_ringerToneEnabled;
}
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
}
Esempio n. 8
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;
}