static void profile_name_change(const char *profile, void *dummy) { /* Active profile has changed */ /* get values for the new profile */ (void)dummy; profileval_t *values = NULL; #if 0 OHM_INFO("profile: active profile has changed: '%s'", profile); #endif if (!profile) return; values = profile_get_values(profile); /* empty 'values' means that the profile is empty */ /* change profile data */ profile_create_fact(profile, values); profile_free_values(values); }
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); }
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; }
/*! * A method for getting AlertTone objects for all * available settings (ringing, voip, email, sms, im) * * \return AlertTone instances... */ QList<AlertTone *> AlertTone::alertTones () { QList<AlertTone *> v; #ifdef HAVE_LIBPROFILE #ifdef WANT_PROFILED_CHECKS QList<QString> keys; profileval_t *vals = profile_get_values(NULL); if (vals) { for (int profile = 0 ; vals[profile].pv_key != NULL ; profile++) { QStringList split_key = QString (vals[profile].pv_key).split ('.'); if (split_key.size() == 3) { if (split_key[0] != "clock" && split_key[1] == "alert" && split_key[2] == "tone") keys.push_back (vals[profile].pv_key); } } profile_free_values (vals); } QVector<QString> toneKeys (0); toneKeys << "ringing.alert.tone" << "voip.alert.tone" << "email.alert.tone" << "sms.alert.tone" << "im.alert.tone" << "calendar.alert.tone"; for (int i = 0 ; i < toneKeys.size() ; i++) { if (keys.contains (toneKeys.at (i))) { keys.removeOne (toneKeys.at (i)); v << new AlertTone (QString (toneKeys.at (i)) + "@general"); } } #else // do not WANT_PROFILED_CHECKS QVector<QString> toneKeys (0); toneKeys << "ringing.alert.tone@general" << "voip.alert.tone@general" << "email.alert.tone@general" << "sms.alert.tone@general" << "im.alert.tone@general" << "calendar.alert.tone@general"; for (int i = 0; i < toneKeys.size (); i++) { v << new AlertTone (toneKeys.at (i)); } #endif #endif // HAVE_LIBPROFILE return v; }
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; }