Back to index

im-sdk  12.3.91
le_desktop.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "le_desktop.h"
00004 #include "imbean.h"
00005 
00006 #include <libxml/xmlmemory.h>
00007 #include <libxml/parser.h>
00008 
00009 extern LeInfoRec *le_info;
00010 
00011 /****************************************************************************/
00012 /*                         Ime Properties Utilities                         */
00013 /****************************************************************************/
00014 ImePropertyListRec* ime_property_list_duplicate(ImePropertyListRec* pl)
00015 {
00016     int i;
00017     ImePropertyListRec *pl_dup = NULL;
00018 
00019     if (pl == NULL ||
00020         pl->count <= 0 ||
00021         pl->properties == NULL)
00022        return (NULL);
00023 
00024     pl_dup = (ImePropertyListRec *)calloc(1, sizeof(ImePropertyListRec));
00025 
00026     pl_dup->count = pl->count;
00027     pl_dup->properties = (ImePropertyRec *)calloc(pl_dup->count,
00028                                             sizeof(ImePropertyRec));
00029 
00030     for (i = 0; i < pl_dup->count; i++) {
00031        ImePropertyRec *pi_dup = &(pl_dup->properties[i]);
00032        ImePropertyRec *pi = &(pl->properties[i]);
00033 
00034        pi_dup->id     = pi->id;
00035        pi_dup->encode = pi->encode;
00036        pi_dup->key    = pi->key;
00037        pi_dup->name   = pi->name;
00038        pi_dup->tip    = pi->tip;
00039        pi_dup->type   = pi->type;
00040        pi_dup->range  = pi->range;
00041        pi_dup->value  = pi->value;
00042     }
00043 
00044     return (pl_dup);
00045 }
00046 
00047 void ime_property_list_free_duplicated(ImePropertyListRec* pl)
00048 {
00049     if (pl == NULL)
00050        return;
00051 
00052     if (pl->properties)
00053        free ((char *)pl->properties);
00054 
00055     free ((char *)pl);
00056 
00057     return;
00058 }
00059 
00060 /****************************************************************************/
00061 /*                         LE Desktop Context                               */
00062 /****************************************************************************/
00063 LeDesktopContextRec *le_desktop_context_new()
00064 {
00065     int i, num_ime_modules;
00066     LeDesktopContextRec *le_desktop_context = NULL;
00067 
00068     le_desktop_context =
00069        (LeDesktopContextRec *) calloc(1, sizeof(LeDesktopContextRec));
00070     if (le_desktop_context == NULL)
00071        return (NULL);
00072 
00073     le_desktop_context->locale = NULL;
00074 
00075     le_desktop_context->default_ime_module = NULL;
00076     le_desktop_context->default_qjbj_status = QJBJ_HALFWIDTH;
00077     le_desktop_context->default_punct_status = PUNCT_CHINESE;
00078     le_desktop_context->default_conversion_status = 0;
00079 
00080     le_desktop_context->num_aux_modules = 0;
00081     le_desktop_context->aux_modules = NULL;
00082 
00083     le_desktop_context->current_session = NULL;
00084 
00085     le_desktop_context->num_ime_modules = 0;
00086     le_desktop_context->ime_modules = NULL;
00087 
00088     if (le_info == NULL ||
00089         le_info->ime_modules == NULL ||
00090         le_info->num_ime_modules <= 0)
00091        return (le_desktop_context);
00092 
00093     le_desktop_context->ime_modules =
00094         (ImeModuleContextRec **) calloc(le_info->num_ime_modules,
00095                                    sizeof(ImeModuleContextRec *));
00096     if (le_desktop_context->ime_modules == NULL)
00097        return (le_desktop_context);
00098 
00099     num_ime_modules = 0;
00100     for (i = 0; i < le_info->num_ime_modules; i++) {
00101        ImeModuleContextRec *ime_module_context;
00102 
00103        if (le_info->ime_modules[i] == NULL ||
00104             le_info->ime_modules[i]->ime_module == NULL)
00105             continue;
00106 
00107         ime_module_context =
00108            (ImeModuleContextRec *) calloc(1, sizeof(ImeModuleContextRec));
00109         if (ime_module_context == NULL)
00110             continue;
00111 
00112         ime_module_context->ime_module = le_info->ime_modules[i]->ime_module;
00113         ime_module_context->enabled = le_info->ime_modules[i]->enabled;
00114         ime_module_context->pl = (ImePropertyListRec *)
00115            ime_property_list_duplicate(ime_module_context->ime_module->info->pl);
00116        
00117         le_desktop_context->ime_modules[num_ime_modules] = ime_module_context;
00118         num_ime_modules ++;
00119     }
00120 
00121     le_desktop_context->num_ime_modules = num_ime_modules;
00122 
00123     if (num_ime_modules > 0) 
00124         le_desktop_context->default_ime_module =
00125             le_desktop_context->ime_modules[0]->ime_module;
00126 
00127     le_desktop_context->time_stamp = 0;
00128     le_desktop_context->shortcutkey_vkb = 'K';
00129 
00130     return (le_desktop_context);
00131 }
00132 
00133 LeResult le_desktop_context_destroy(LeDesktopContextRec *le_desktop_context)
00134 {
00135     int i;
00136 
00137     if (le_desktop_context == NULL)
00138        return (LE_FAIL);
00139 
00140     if (le_desktop_context->ime_modules != NULL) {
00141        for (i = 0; i < le_desktop_context->num_ime_modules; i ++) {
00142            ImeModuleContextRec *ime_module_context;
00143            ime_module_context = le_desktop_context->ime_modules[i];
00144            if (ime_module_context == NULL)
00145               continue;
00146 
00147            /* free property data */
00148            ime_property_list_free_duplicated(ime_module_context->pl);
00149 
00150            free((char *)ime_module_context);
00151        }       
00152        free((char *) le_desktop_context->ime_modules);
00153     }
00154 
00155     if (le_desktop_context->aux_modules)
00156        free((char *) le_desktop_context->aux_modules);
00157 
00158     if (le_desktop_context->locale)
00159        free((char *) le_desktop_context->locale);
00160 
00161     free((char *) le_desktop_context);
00162 
00163     return (LE_OK);
00164 }
00165 
00166 LeResult le_desktop_context_print(LeDesktopContextRec * le_desktop_context)
00167 {
00168     int i;
00169 
00170     DEBUG_printf("le_desktop_context_print ==========\n");
00171 
00172     if (le_desktop_context == NULL)
00173        return (LE_FAIL);
00174 
00175     if (le_desktop_context->ime_modules != NULL) {
00176        for (i = 0; i < le_desktop_context->num_ime_modules; i ++) {
00177            ImeModuleContextRec *ime_module_context;
00178            ime_module_context = le_desktop_context->ime_modules[i];
00179            if (ime_module_context == NULL)
00180               continue;
00181 
00182            ime_module_context_print(ime_module_context);
00183        }       
00184     }
00185 
00186     return (LE_OK);
00187 }
00188 
00189 LeResult le_desktop_context_set_current_session(LeDesktopContextRec *
00190                                           le_desktop_context,
00191                                           iml_session_t * s)
00192 {
00193     if (le_desktop_context == NULL)
00194        return (LE_FAIL);
00195 
00196     le_desktop_context->current_session = s;
00197     return (LE_OK);
00198 }
00199 
00200 iml_session_t *le_desktop_context_get_current_session(LeDesktopContextRec *
00201                                                 le_desktop_context)
00202 {
00203     if (le_desktop_context == NULL)
00204        return (NULL);
00205 
00206     return (le_desktop_context->current_session);
00207 }
00208 
00209 ImeModuleRec *le_desktop_context_get_default_ime_module(LeDesktopContextRec *
00210                                                  le_desktop_context)
00211 {
00212     if (le_desktop_context == NULL)
00213        return (NULL);
00214 
00215     return (le_desktop_context->default_ime_module);
00216 }
00217 
00218 LeResult le_desktop_context_set_default_qjbj_status(LeDesktopContextRec *
00219                                               le_desktop_context,
00220                                               QjBjStatus
00221                                               default_qjbj_status)
00222 {
00223     if (le_desktop_context == NULL)
00224        return (LE_FAIL);
00225 
00226     le_desktop_context->default_qjbj_status = default_qjbj_status;
00227     return (LE_OK);
00228 }
00229 
00230 QjBjStatus le_desktop_context_get_default_qjbj_status(LeDesktopContextRec *
00231                                                 le_desktop_context)
00232 {
00233     if (le_desktop_context == NULL)
00234        return (0);
00235 
00236     return (le_desktop_context->default_qjbj_status);
00237 }
00238 
00239 LeResult le_desktop_context_set_default_punct_status(LeDesktopContextRec *
00240                                                le_desktop_context,
00241                                                PunctStatus
00242                                                default_punct_status)
00243 {
00244     if (le_desktop_context == NULL)
00245        return (LE_FAIL);
00246 
00247     le_desktop_context->default_punct_status = default_punct_status;
00248     return (LE_OK);
00249 }
00250 
00251 PunctStatus le_desktop_context_get_default_punct_status(LeDesktopContextRec *
00252                                                  le_desktop_context)
00253 {
00254     if (le_desktop_context == NULL)
00255        return (0);
00256 
00257     return (le_desktop_context->default_punct_status);
00258 }
00259 
00260 LeResult
00261 le_desktop_context_set_default_conversion_status(LeDesktopContextRec *
00262                                            le_desktop_context,
00263                                            int
00264                                            default_conversion_status)
00265 {
00266     if (le_desktop_context == NULL)
00267        return (LE_FAIL);
00268 
00269     le_desktop_context->default_conversion_status =
00270        default_conversion_status;
00271     return (LE_OK);
00272 }
00273 
00274 PunctStatus
00275 le_desktop_context_get_default_conversion_status(LeDesktopContextRec *
00276                                            le_desktop_context)
00277 {
00278     if (le_desktop_context == NULL)
00279        return (0);
00280 
00281     return (le_desktop_context->default_conversion_status);
00282 }
00283 
00284 LeResult le_desktop_context_set_locale(LeDesktopContextRec *
00285                                    le_desktop_context, char *locale)
00286 {
00287     if (le_desktop_context == NULL || locale == NULL)
00288        return (LE_FAIL);
00289 
00290     if (le_desktop_context->locale)
00291        free ((char *)le_desktop_context->locale);
00292 
00293     le_desktop_context->locale = (char *) strdup(locale);
00294     return (LE_OK);
00295 }
00296 
00297 char *le_desktop_context_get_locale(LeDesktopContextRec *
00298                                 le_desktop_context)
00299 {
00300     if (le_desktop_context == NULL)
00301        return (NULL);
00302 
00303     return (le_desktop_context->locale);
00304 }
00305 
00306 /****************************************************************************/
00307 /*                         LE Desktop Profile                               */
00308 /****************************************************************************/
00309 int le_desktop_profile_new_le_properties_from_ibml_category(LeDesktopContextRec * dc,
00310                                                   IbmlCategory * ibml_category)
00311 {
00312     IbmlElement *ibml_element;
00313     IbmlProperty *ibml_property;
00314 
00315     int i, j;
00316 
00317     char *id, *scope;
00318     char *name, *value, *options;
00319 
00320     if (dc == NULL)
00321        return (LE_FAIL);
00322 
00323     if (ibml_category == NULL)
00324        return (LE_FAIL);
00325 
00326     if (ibml_category->num_elements <= 0)
00327        return (LE_FAIL);
00328 
00329     DEBUG_printf("Begin le_desktop_profile_new_le_properties_from_ibml_category()\n");
00330     for (i = 0; i < ibml_category->num_elements; i++) {
00331        ibml_element = ibml_category->elements[i];
00332        if (!ibml_element)
00333            continue;
00334 
00335        id = (char *) ibml_element->id;
00336        scope = (char *) ibml_element->scope;
00337        DEBUG_printf("id:%s, scope:%s\n", id ? id : "NULL",
00338                    scope ? scope : "NULL");
00339        if (!id || !*id)
00340            continue;
00341 
00342        if (strcasecmp(id, "iiim_properties"))
00343            continue;
00344 
00345        for (j = 0; j < ibml_element->num_properties; j++) {
00346            ibml_property = ibml_element->properties[j];
00347            if (!ibml_property)
00348               continue;
00349 
00350            name = (char *) ibml_property->name;
00351            if (!name || !*name)
00352               continue;
00353 
00354            value = (char *) ibml_property->value;
00355            if (!value || !*value)
00356               continue;
00357 
00358            if (!strcasecmp(name, "time_stamp")) {
00359               char *time_stamp_str = (char *) value;
00360               dc->time_stamp = atol(time_stamp_str);
00361            } else if (!strcasecmp(name, "shortcutkey_vkb")) {
00362               char *vkb_key_str = (char *) value;
00363               dc->shortcutkey_vkb = vkb_key_str[0];
00364            }
00365        }
00366     }
00367 
00368     return (LE_OK);
00369 }
00370 
00371 int le_desktop_profile_new_imeengines_from_ibml_category(LeDesktopContextRec * dc,
00372                                                   IbmlCategory * ibml_category,
00373                                                   int need_sort)
00374 {
00375     IbmlElement *ibml_element;
00376     IbmlProperty *ibml_property;
00377 
00378     int i, j, k;
00379     int current_ime_module_id;
00380     ImeModuleContextRec *current_ime_module_context;
00381     ImePropertyListRec *pl;
00382 
00383     char *id, *scope;
00384     char *name, *value, *options;
00385 
00386     if (dc == NULL || dc->ime_modules == NULL)
00387        return (LE_FAIL);
00388 
00389     if (ibml_category == NULL)
00390        return (LE_FAIL);
00391 
00392     if (ibml_category->num_elements <= 0)
00393        return (LE_FAIL);
00394 
00395     DEBUG_printf("Begin le_desktop_profile_new_imeengines_from_ibml_category()\n");
00396     current_ime_module_id = 0;
00397     for (i = 0; i < ibml_category->num_elements; i++) {
00398        char *uuid = NULL;
00399        char *enable_str = NULL;
00400        int enable_value;
00401 
00402        ibml_element = ibml_category->elements[i];
00403        if (!ibml_element)
00404            continue;
00405 
00406        id = (char *) ibml_element->id;
00407        scope = (char *) ibml_element->scope;
00408        DEBUG_printf("id:%s, scope:%s\n", id ? id : "NULL",
00409                    scope ? scope : "NULL");
00410        if (!id || !*id)
00411            continue;
00412 
00413        uuid = id;
00414 
00415        current_ime_module_context = NULL;
00416        for (j = current_ime_module_id; j < dc->num_ime_modules; j++) {
00417            ImeModuleContextRec *ime_module_context = dc->ime_modules[j];
00418 
00419            if (!ime_module_context || !ime_module_context->ime_module)
00420               continue;
00421 
00422            if (!strcasecmp
00423               (uuid, ime_module_context->ime_module->info->uuid)) {
00424               if (need_sort) {
00425                   for (k = j; k > current_ime_module_id; k--)
00426                       dc->ime_modules[k] = dc->ime_modules[k - 1];
00427 
00428                   dc->ime_modules[current_ime_module_id] =
00429                       ime_module_context;
00430                   current_ime_module_id++;
00431               }
00432               current_ime_module_context = ime_module_context;
00433               break;
00434            }
00435        }
00436 
00437        if (current_ime_module_context == NULL)
00438            continue;
00439 
00440        pl = current_ime_module_context->pl;
00441 
00442        for (j = 0; j < ibml_element->num_properties; j++) {
00443            ibml_property = ibml_element->properties[j];
00444            if (!ibml_property)
00445               continue;
00446 
00447            name = (char *) ibml_property->name;
00448            if (!name || !*name)
00449               continue;
00450 
00451            value = (char *) ibml_property->value;
00452            if (!value || !*value)
00453               continue;
00454 
00455            if (!strcasecmp(name, "enabled")) {
00456               enable_str = (char *) value;
00457 
00458               enable_value = 1;
00459               if (enable_str && *enable_str) {
00460                   if (!strcasecmp(enable_str, "0") ||
00461                      !strcasecmp(enable_str, "false"))
00462                      enable_value = 0;
00463               }
00464 
00465               current_ime_module_context->enabled = enable_value;
00466               continue;
00467            }
00468 
00469            if (pl != NULL) {
00470                for (k = 0; k < pl->count; k ++) {
00471                   ImePropertyRec *pi = &(pl->properties[k]);
00472                   if (pi == NULL || pi->key == NULL)
00473                       continue;
00474 
00475                   if (!strcmp(name, pi->key)) {
00476                       pi->value.int_value = atoi(value);
00477                   }
00478                }
00479            }
00480        }
00481     }
00482 
00483     return (LE_OK);
00484 }
00485 
00486 #define LE_PROPERTIES_CATAGORY            "le_settings"
00487 #define ENGINE_PROPERTIES_CATAGORY "engine_properties"
00488 #define ALL_ENGINE_CATAGORY        "all_engines"
00489 
00490 int le_desktop_profile_new_from_memory(LeDesktopContextRec * dc, char *buf,
00491                                 int size)
00492 {
00493     IbmlData *ibml_data;
00494     IbmlCategory *ibml_category;
00495     int i;
00496     int ret = LE_OK;
00497     int need_sort;
00498 
00499     if (dc == NULL)
00500        return (LE_FAIL);
00501     if (buf == NULL || size <= 0)
00502        return (LE_FAIL);
00503 
00504     ibml_data = (IbmlData *) imbean_config_new_from_memory(buf, size);
00505     if (ibml_data == NULL)
00506        return (LE_FAIL);
00507 
00508     for (i = 0; i < ibml_data->num_categories; i++) {
00509        ibml_category = ibml_data->categories[i];
00510 
00511        if (!ibml_category->scope || !*ibml_category->scope)
00512            continue;
00513 
00514        if (!strcasecmp(ibml_category->scope, ALL_ENGINE_CATAGORY)) {
00515            need_sort = 1;
00516            ret = le_desktop_profile_new_imeengines_from_ibml_category(dc, 
00517                                                  ibml_category, need_sort);
00518        } else if (!strcasecmp(ibml_category->scope, ENGINE_PROPERTIES_CATAGORY)) {
00519            need_sort = 0;
00520            ret = le_desktop_profile_new_imeengines_from_ibml_category(dc, 
00521                                                  ibml_category, need_sort);
00522        } else if (!strcasecmp(ibml_category->scope, LE_PROPERTIES_CATAGORY)) {
00523            ret = le_desktop_profile_new_le_properties_from_ibml_category(dc, 
00524                                                  ibml_category);
00525        }
00526     }
00527 
00528     ibml_data_free(ibml_data);
00529     return (ret);
00530 }
00531 
00532 #define BUF_LEN   4196
00533 char *le_desktop_profile_write_to_memory(LeDesktopContextRec * dc)
00534 {
00535     xmlDocPtr doc;
00536     xmlNodePtr root;
00537     xmlNodePtr im_node;
00538     xmlNodePtr imbean_node;
00539     xmlNodePtr property_node;
00540     xmlChar *xmlbuf = NULL;
00541     char utf8_buf[BUF_LEN];
00542     int size = 0;
00543     int i;
00544 
00545     if (dc == NULL || dc->ime_modules == NULL)
00546        return (NULL);
00547 
00548     doc = xmlNewDoc("1.0");
00549 
00550     root = xmlNewNode(NULL, IBML_ELEMENT_ROOT);
00551     xmlSetProp(root, IBML_ELEMENT_SCOPE, LE_NAME);
00552     xmlDocSetRootElement(doc, root);
00553 
00554     doc->children = root;
00555 
00556     im_node = xmlNewChild(root, NULL, IBML_ELEMENT_CATAGORY, NULL);
00557     xmlSetProp(im_node, IBML_ELEMENT_SCOPE, LE_PROPERTIES_CATAGORY);
00558 
00559     imbean_node = xmlNewChild(im_node, NULL, IBML_ELEMENT_IMBEAN, NULL);
00560     xmlSetProp(imbean_node, IBML_ELEMENT_IMBEAN_ID, "iiim_properties");
00561     property_node =
00562        xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00563     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "time_stamp");
00564     snprintf(utf8_buf, BUF_LEN, "%d", le_info->time_stamp);
00565     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, utf8_buf);
00566 
00567     property_node =
00568        xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00569     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "shortcutkey_vkb");
00570     snprintf(utf8_buf, BUF_LEN, "%c", dc->shortcutkey_vkb);
00571     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, utf8_buf);
00572 
00573     im_node = xmlNewChild(root, NULL, IBML_ELEMENT_CATAGORY, NULL);
00574     xmlSetProp(im_node, IBML_ELEMENT_SCOPE, ALL_ENGINE_CATAGORY);
00575 
00576     for (i = 0; i < dc->num_ime_modules; i++) {
00577        ImeModuleRec *ime_module;
00578        ImeInfoRec *ime_info;
00579        ImeModuleContextRec *ime_module_context = dc->ime_modules[i];
00580        ImePropertyListRec *pl;
00581 
00582        int encoding;
00583        int enabled_value;
00584        char *enabled_str;
00585 
00586        char *tmp_ptr, *name_str;
00587        int from_len, to_left, ret;
00588 
00589        if (ime_module_context == NULL)
00590            continue;
00591 
00592        ime_module = ime_module_context->ime_module;
00593        if (ime_module == NULL)
00594            continue;
00595 
00596        ime_info = ime_module->info;
00597        if (ime_info == NULL ||
00598            ime_info->uuid == NULL ||
00599            ime_info->name == NULL || ime_info->author == NULL)
00600            continue;
00601 
00602        encoding = ime_info->encoding;
00603        enabled_value = ime_module_context->enabled;
00604 
00605        imbean_node =
00606            xmlNewChild(im_node, NULL, IBML_ELEMENT_IMBEAN, NULL);
00607        xmlSetProp(imbean_node, IBML_ELEMENT_IMBEAN_ID,
00608                  (char *) ime_info->uuid);
00609 
00610        name_str = (char *) ime_info->name;
00611        from_len = strlen(name_str);
00612        to_left = BUF_LEN;
00613        tmp_ptr = utf8_buf;
00614        memset(utf8_buf, 0, BUF_LEN);
00615        ret = Convert_Native_To_UTF8(encoding,
00616                                  name_str,
00617                                  from_len,
00618                                  (char **) &tmp_ptr,
00619                                  (size_t *) & to_left);
00620 
00621        if (ret == -1)
00622            continue;
00623 
00624        property_node =
00625            xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00626        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "name");
00627        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, utf8_buf);
00628 
00629        name_str = (char *) ime_info->author;
00630        from_len = strlen(name_str);
00631        to_left = BUF_LEN;
00632        tmp_ptr = utf8_buf;
00633        memset(utf8_buf, 0, BUF_LEN);
00634        ret = Convert_Native_To_UTF8(encoding,
00635                                  name_str,
00636                                  from_len,
00637                                  (char **) &tmp_ptr,
00638                                  (size_t *) & to_left);
00639 
00640        if (ret == -1)
00641            continue;
00642 
00643        property_node =
00644            xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00645        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "author");
00646        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, utf8_buf);
00647 
00648        snprintf(utf8_buf, BUF_LEN, "%d", ime_info->version);
00649        property_node =
00650            xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00651        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "version");
00652        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, utf8_buf);
00653 
00654        if (ime_info->copyright) {
00655            name_str = (char *) ime_info->copyright;
00656            from_len = strlen(name_str);
00657            to_left = BUF_LEN;
00658            tmp_ptr = utf8_buf;
00659            memset(utf8_buf, 0, BUF_LEN);
00660            ret = Convert_Native_To_UTF8(encoding,
00661                                     name_str,
00662                                     from_len,
00663                                     (char **) &tmp_ptr,
00664                                     (size_t *) & to_left);
00665 
00666            if (ret == -1)
00667               continue;
00668 
00669            property_node =
00670               xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY,
00671                          NULL);
00672            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME,
00673                      "copyright");
00674            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE,
00675                      utf8_buf);
00676        }
00677 
00678        if (ime_info->hinting) {
00679            name_str = (char *) ime_info->hinting;
00680            from_len = strlen(name_str);
00681            to_left = BUF_LEN;
00682            tmp_ptr = utf8_buf;
00683            memset(utf8_buf, 0, BUF_LEN);
00684            ret = Convert_Native_To_UTF8(encoding,
00685                                     name_str,
00686                                     from_len,
00687                                     (char **) &tmp_ptr,
00688                                     (size_t *) & to_left);
00689 
00690            if (ret == -1)
00691               continue;
00692 
00693            property_node =
00694               xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY,
00695                          NULL);
00696            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME,
00697                      "hinting");
00698            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE,
00699                      utf8_buf);
00700        }
00701 
00702        if (ime_info->icon_file) {
00703            property_node =
00704               xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY,
00705                          NULL);
00706            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME,
00707                      "icon_file");
00708            xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE,
00709                      ime_info->icon_file);
00710        }
00711 
00712        property_node =
00713            xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
00714        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "enabled");
00715        enabled_str = "true";
00716        if (enabled_value == 0)
00717            enabled_str = "false";
00718        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE,
00719                  enabled_str);
00720 
00721        DEBUG_printf("ime_name: %s\n", ime_info->uuid);
00722        pl = ime_module_context->pl;
00723        if (pl == NULL)
00724            pl = ime_info->pl;
00725 
00726        if (pl != NULL) {
00727            int j;
00728            for (j = 0; j < pl->count; j++) {
00729               ImeProperty ime_property;
00730               char options_str[BUF_LEN];
00731               char options_type[56];
00732               char options_value[10];
00733 
00734               ime_property = &(pl->properties[j]);
00735               if (ime_property->name == NULL ||
00736                   ime_property->key == NULL)
00737                   continue;
00738 
00739               property_node =
00740                   xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY,
00741                             NULL);
00742               xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME,
00743                         ime_property->key);
00744 
00745               options_str[0] = 0;
00746               options_type[0] = 0;
00747               options_value[0] = '0';
00748               options_value[1] = 0;
00749               if (ime_property->type == ImeProperty_Selection) {
00750                   char **value_ptr;
00751                   int k;
00752                   strcat(options_str, ime_property->name);
00753                   value_ptr = ime_property->range.multiString_range;
00754                   if (value_ptr != NULL) {
00755                      for (k = 0; value_ptr[k] != NULL; k++) {
00756                          strcat(options_str, "/");
00757                          strcat(options_str, value_ptr[k]);
00758                      }
00759                   }
00760                   strcat(options_type, "ImeProperty_Selection");
00761               } else if (ime_property->type == ImeProperty_Toggle) {
00762                   strcat(options_str, ime_property->name);
00763                   strcat(options_type, "ImeProperty_Toggle");
00764               } else if (ime_property->type == ImeProperty_Int) {
00765                   char value[12];
00766                   strcat(options_str, ime_property->name);
00767                   strcat(options_str, "/");
00768                   snprintf(value, 12, "%d/%d",
00769                          ime_property->range.int_range.min,
00770                          ime_property->range.int_range.max);
00771                   strcat(options_str, value);
00772                   strcat(options_type, "ImeProperty_Int");
00773               }
00774 
00775               snprintf(options_value, 10, "%d", ime_property->value.int_value);
00776 
00777 #if DEBUG
00778               printf("options_str: %s, options_type: %s, options_value: %s\n",
00779                           options_str, options_type, options_value);
00780 #endif
00781               if (*options_str && *options_type) {
00782                   encoding = ime_property->encode;
00783                   name_str = (char *) options_str;
00784                   from_len = strlen(name_str);
00785                   to_left = BUF_LEN;
00786                   tmp_ptr = utf8_buf;
00787                   memset(utf8_buf, 0, BUF_LEN);
00788                   ret = Convert_Native_To_UTF8(encoding,
00789                                            name_str,
00790                                            from_len,
00791                                            (char **) &tmp_ptr,
00792                                            (size_t *) & to_left);
00793 
00794                   if (ret == -1)
00795                      continue;
00796 
00797                   xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_OPTIONS,
00798                             utf8_buf);
00799                   xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_TYPE,
00800                             options_type);
00801                   xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE,
00802                             options_value);
00803               }
00804            }
00805        }
00806     }
00807 
00808     xmlDocDumpFormatMemoryEnc(doc, &xmlbuf, &size, "UTF-8", 1);
00809 
00810     xmlFreeDoc(doc);
00811 
00812     return (xmlbuf);
00813 }
00814 
00815 /****************************************************************************/
00816 /*                         LE Desktop                                       */
00817 /****************************************************************************/
00818 LeDesktopContextRec *le_desktop_create(iml_desktop_t * desktop)
00819 {
00820     LeDesktopContextRec *le_desktop_context = NULL;
00821     int num_ime_modules, i;
00822 
00823     le_desktop_context = (LeDesktopContextRec *) le_desktop_context_new();
00824     DEBUG_printf("le_desktop_create ===== %p\n", le_desktop_context);
00825 
00826     le_desktop_context_print(le_desktop_context);
00827 
00828     desktop->specific_data = (void *) le_desktop_context;
00829 
00830     return (le_desktop_context);
00831 }
00832 
00833 LeResult le_desktop_destroy(iml_desktop_t * desktop)
00834 {
00835     LeDesktopContextRec *le_desktop_context =
00836        (LeDesktopContextRec *) desktop->specific_data;
00837 
00838     le_desktop_context_destroy(le_desktop_context);
00839 
00840     desktop->specific_data = NULL;
00841 
00842     return (LE_OK);
00843 }