/** * write_gconf_schemas_file: * @filename: Filename for output. * * Output the parameters as GSettings schemes file. */ gboolean write_schemas_file(const gchar * filename) { mkdg_log(INFO, "write_schemes_file(%s,)", filename); FILE *outF = fopen(filename, "w"); if (outF == NULL) { mkdg_log(DEBUG, "write_gconf_schemas_file(%s) file %s cannot be written!", filename, filename); return FALSE; } gboolean result = mkdg_g_settings_write_schema_from_spec_array(QUOTE_ME (PROJECT_SCHEMA_ID), QUOTE_ME (PROJECT_SCHEMA_PATH), outF, propSpecs, QUOTE_ME (PROJECT_NAME)); if (fclose(outF)) return FALSE; mkdg_log(DEBUG, "write_gconf_schemas_file(%s) ... done.", filename); return result; }
PropertyContext *property_context_new(MkdgPropertySpec * spec, MkdgBackend * backend, gpointer parent, gpointer auxData) { if (spec == NULL) { return NULL; } mkdg_log(INFO, "property_context_new(%s,-,-,-)", spec->key); PropertyContext *ctx = g_new0(PropertyContext, 1); ctx->spec = spec; ctx->backend = backend; ctx->parent = parent; ctx->auxData = auxData; g_value_init(&(ctx->value), ctx->spec->valueType); if (ctx->backend != NULL) { GValue *value = property_context_read(ctx, NULL); if (value == NULL) { property_context_default(ctx); } } else { property_context_default(ctx); } mkdg_log(DEBUG, "property_context_new(%s):Done", ctx->spec->key); return ctx; }
GValue *gconf2_backend_read_value(MkdgBackend * backend, GValue * value, const gchar * section, const gchar * key, gpointer userData) { mkdg_log(DEBUG, "gconf2_backend_read_value(-,-,%s,%s,-):", section, key); GConfClient *config = (GConfClient *) backend->config; GError *err = NULL; gchar confKey[KEY_BUFFER_SIZE]; to_real_key(confKey, backend, section, key); GConfValue *confValue = gconf_client_get(config, confKey, &err); if (confValue == NULL) { mkdg_log(ERROR, "gconf2_backend_read_value(-,-,%s,%s,-): Failed to retrieve confValue", section, key); return NULL; } if (err != NULL) { mkdg_log(ERROR, "gconf2_backend_read_value(-,-,%s,%s,-): %s", section, key, err->message); return NULL; } return gconf_value_to_g_value(confValue, value); }
gboolean ibus_config_backend_write_value(MkdgBackend * backend, GValue * value, const gchar * section, const gchar * key, gpointer userData) { gboolean result = FALSE; IBusConfig *config = (IBusConfig *) backend->config; gchar confSection[KEY_BUFFER_SIZE]; to_real_section(confSection, backend, section); #if IBUS_CHECK_VERSION(1, 4, 0) GVariant *gVar = g_variant_ref_sink(mkdg_g_value_to_g_variant(value)); if (gVar != NULL) { result = ibus_config_set_value(config, confSection, key, gVar); } #else result = ibus_config_set_value(config, confSection, key, value); #endif if (result == FALSE) { mkdg_log(WARN, "ibus_config_backend_write_value(-, %s, -) %s %s", key, "Failed to set variable", key); return FALSE; } if (!config) { mkdg_log(WARN, "ibus_config_backend_write_value(-, %s, -) %s", key, "Failed to connect to IBusService"); return FALSE; } return TRUE; }
GValue *property_context_get(PropertyContext * ctx) { if (ctx == NULL) { mkdg_log(WARN, "property_context_get(-): ctx is NULL"); return NULL; } mkdg_log(DEBUG, "property_context_get(%s): value=%s", ctx->spec->key, mkdg_g_value_to_string(&(ctx->value))); return &(ctx->value); }
gboolean property_context_use(PropertyContext * ctx, gpointer userData) { mkdg_log(DEBUG, "property_context_use(%s,-)", ctx->spec->key); GValue *ret = property_context_load(ctx, userData); if (ret == NULL) { mkdg_log(WARN, "property_context_use(%s): property_context_load return NULL", ctx->spec->key); return FALSE; } return property_context_apply(ctx, userData); }
void property_context_default(PropertyContext * ctx) { if (ctx->spec->defaultValue == NULL) return; mkdg_log(DEBUG, "property_context_default(%s)", ctx->spec->key); gboolean ret = property_context_from_string(ctx, ctx->spec->defaultValue); if (!ret) { mkdg_log(WARN, "property_context_default(%s): failed to convert string %s, return NULL", ctx->spec->key, ctx->spec->defaultValue); } }
/** * write_gconf_schemas_file: * @filename: Filename for output. * @owner: Owner of the schemas. * @schemasHome: The "home direcory" of schemas. * @localeStr: Supported localeStr, use ';' as delimiter. * @returns: TRUE if succeed; FALSE otherwise. * * Output the parameters as GConf schemes file. */ gboolean write_gconf_schemas_file(const gchar * filename, const gchar * owner, const gchar * schemasHome, const gchar * localeStr) { mkdg_log(INFO, "write_gconf_schemes_file(%s,%s,%s,%s)", filename, owner, schemasHome, localeStr); FILE *outF = fopen(filename, "w"); if (outF == NULL) { mkdg_log(DEBUG, "write_gconf_schemas_file(%s) file %s cannot be written!", filename, filename); return FALSE; } localeArray = g_strsplit_set(localeStr, ":;", -1); gchar **loc; for (loc = localeArray; *loc != NULL; loc++) { mkdg_log(DEBUG, "write_gconf_schemas_file() locale=%s", *loc); } /* Header */ mkdg_xml_tags_write(outF, "gconfschemafile", MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, NULL); mkdg_xml_tags_write(outF, "schemalist", MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, NULL); /* Body */ /* Backend is not needed for schema generation */ IBusChewingProperties *iProperties = ibus_chewing_properties_new(NULL, NULL, NULL); gsize i; for (i = 0; i < mkdg_properties_size(iProperties->properties); i++) { PropertyContext *ctx = mkdg_properties_index(iProperties->properties, i); ctx_write(ctx, schemasHome, owner, outF); } /* Footer */ mkdg_xml_tags_write(outF, "schemalist", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); mkdg_xml_tags_write(outF, "gconfschemafile", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); if (fclose(outF)) return FALSE; mkdg_log(DEBUG, "write_gconf_schemas_file(%s) ... done.", filename); return TRUE; }
gboolean property_context_set(PropertyContext * ctx, GValue * value) { if (ctx == NULL) { mkdg_log(WARN, "property_context_set(-): ctx is NULL"); return FALSE; } if (!G_IS_VALUE(value)) { mkdg_log(WARN, "property_context_set(%s): value is not GValue", ctx->spec->key); return FALSE; } mkdg_log(DEBUG, "property_context_set(%s,%s)", ctx->spec->key, mkdg_g_value_to_string(value)); g_value_copy(value, &(ctx->value)); return TRUE; }
gboolean property_context_apply(PropertyContext * ctx, gpointer userData) { if (ctx == NULL || ctx->parent == NULL) { mkdg_log(WARN, "property_context_apply(%s): either ctx or ctx->parent is NULL", ctx->spec->key); return FALSE; } if (ctx->spec->applyFunc == NULL) { mkdg_log(DEBUG, "property_context_apply(%s,-): No apply function, skip", ctx->spec->key); return TRUE; } mkdg_log(DEBUG, "property_context_apply(%s,-): value %s", ctx->spec->key, mkdg_g_value_to_string(&(ctx->value))); return ctx->spec->applyFunc(ctx, userData); }
gboolean property_context_save(PropertyContext * ctx, GValue * value, gpointer userData) { mkdg_log(DEBUG, "property_context_save(%s,-)", ctx->spec->key); if (!property_context_set(ctx, value)) { return FALSE; } return property_context_write(ctx, userData); }
gchar *command_run_obtain_output(const gchar * cmd) { mkdg_log(DEBUG, "command_run_obtain_output(%s)\n", cmd); static gchar readBuffer[FILE_BUFFER_SIZE]; FILE *stream = popen(cmd, "r"); if (stream == NULL) { g_error("Cannot pipe from command %s", cmd); exit(3); } gchar *line = fgets(readBuffer, FILE_BUFFER_SIZE, stream); pclose(stream); if (line == NULL) { mkdg_log(DEBUG, "line=NULL\n"); } else { line[strlen(line) - 1] = '\0'; mkdg_log(DEBUG, "line=%s\n", line); } return line; }
/* assign: save then apply */ GValue *property_context_read(PropertyContext * ctx, gpointer userData) { if (ctx == NULL) { return NULL; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { return NULL; } if (ctx->backend == NULL) { return NULL; } GValue *result = mkdg_backend_read(ctx->backend, &(ctx->value), ctx->spec->subSection, ctx->spec->key, userData); if (result == NULL) { mkdg_log(WARN, "property_context_read(%s): failed to read key", ctx->spec->key); } return result; }
gboolean property_context_write(PropertyContext * ctx, gpointer userData) { if (ctx == NULL) { return FALSE; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { return FALSE; } if (ctx->backend == NULL) { return FALSE; } return ctx->backend->writeFunc(ctx->backend, &(ctx->value), ctx->spec->subSection, ctx->spec->key, userData); }
static void ctx_write_locale(PropertyContext * ctx, FILE * outF, const gchar * locale) { gchar buf[XML_BUFFER_SIZE]; mkdg_log(DEBUG, "ctx_write_locale(%s,-,%s)", ctx->spec->key, locale); setlocale(LC_ALL, "locale"); g_snprintf(buf, 50, "name=\"%s\"", locale); setlocale(LC_MESSAGES, locale); mkdg_xml_tags_write(outF, "locale", MKDG_XML_TAG_TYPE_BEGIN_ONLY, buf, NULL); mkdg_xml_tags_write(outF, "short", MKDG_XML_TAG_TYPE_SHORT, NULL, gettext(ctx->spec->label)); mkdg_xml_tags_write(outF, "long", MKDG_XML_TAG_TYPE_LONG, NULL, gettext(ctx->spec->tooltip)); mkdg_xml_tags_write(outF, "locale", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); }
gboolean gconf2_backend_write_value(MkdgBackend * backend, GValue * value, const gchar * section, const gchar * key, gpointer userData) { GConfClient *config = (GConfClient *) backend->config; GError *err = NULL; gchar confKey[KEY_BUFFER_SIZE]; to_real_key(confKey, backend, section, key); GConfValue *confValue = gconf_value_new_g_value(value); gconf_client_set(config, confKey, confValue, &err); gconf_value_free(confValue); if (err != NULL) { mkdg_log(ERROR, "gconf2_backend_write_value(-,-,%s,%s,-): %s", section, key, err->message); return FALSE; } return TRUE; }
void property_context_free(PropertyContext * ctx) { mkdg_log(INFO, "property_context_free(%s,-)", ctx->spec->key); g_value_unset(&(ctx->value)); g_free(ctx); }
GValue *property_context_load(PropertyContext * ctx, gpointer userData) { mkdg_log(DEBUG, "property_context_load(%s,-)", ctx->spec->key); property_context_read(ctx, userData); return property_context_get(ctx); }