Back to index

im-sdk  12.3.91
property_data.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <locale.h>
00003 #include <sys/stat.h>
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #include "config.h"
00007 #endif
00008 
00009 #include "property_data.h"
00010 
00011 #include "imbean.h"
00012 
00013 #include <libxml/xmlmemory.h>
00014 #include <libxml/parser.h>
00015 
00016 /*********************************************************************/
00017 /*                       ImePropertyRec utilities                    */
00018 /*********************************************************************/
00019 #define IME_PROPERTY_LIST_NUM_ALLOC 10
00020 
00021 static ImePropertyRec *ime_property_new()
00022 {
00023     ImePropertyRec *ime_property = NULL;
00024 
00025     ime_property = (ImePropertyRec *) calloc(1, sizeof(ImePropertyRec));
00026 
00027     return ime_property;
00028 }
00029 
00030 void ime_property_destroy(ImePropertyRec * ime_property)
00031 {
00032     if (ime_property == NULL)
00033        return;
00034 
00035     if (ime_property->key)
00036        free((char *) ime_property->key);
00037 
00038     if (ime_property->name)
00039        free((char *) ime_property->name);
00040 
00041     if (ime_property->tip)
00042        free((char *) ime_property->tip);
00043 
00044     if (ime_property->type == ImeProperty_Selection) {
00045        char **value_ptr;
00046        int i;
00047        value_ptr = ime_property->range.multiString_range;
00048        if (value_ptr != NULL) {
00049            for (i = 0; value_ptr[i]; i++) {
00050               free((char *) value_ptr[i]);
00051            }
00052            free((char *) value_ptr);
00053        }
00054     }
00055 }
00056 
00057 void ime_property_print(ImePropertyRec * ime_property)
00058 {
00059     if (ime_property == NULL)
00060        return;
00061 
00062     printf(" ime property: \n");
00063 
00064     if (ime_property->key)
00065        printf("  key: %s\n", (char *) ime_property->key);
00066 
00067     if (ime_property->name)
00068        printf("  name: %s\n", (char *) ime_property->name);
00069 
00070     if (ime_property->tip)
00071        printf("  tip: %s\n", (char *) ime_property->tip);
00072 
00073     if (ime_property->type)
00074        printf("  type: %d\n", (char *) ime_property->type);
00075 
00076     if (ime_property->type == ImeProperty_Selection) {
00077        char **value_ptr;
00078        int i;
00079        value_ptr = ime_property->range.multiString_range;
00080        if (value_ptr != NULL) {
00081            for (i = 0; value_ptr[i]; i++) {
00082               printf("  options[%d]: %s\n", i, (char *) value_ptr[i]);
00083            }
00084        }
00085     } else if (ime_property->type == ImeProperty_Int) {
00086        int min, max;
00087        printf("  min: %d\n", ime_property->range.int_range.min);
00088        printf("  max: %d\n", ime_property->range.int_range.max);
00089     }
00090 
00091     printf("\n");
00092 }
00093 
00094 ImePropertyListRec *ime_property_list_new()
00095 {
00096     ImePropertyListRec *ime_property_list = NULL;
00097 
00098     ime_property_list =
00099        (ImePropertyListRec *) calloc(1, sizeof(ImePropertyListRec));
00100 
00101     return ime_property_list;
00102 }
00103 
00104 void ime_property_list_destroy(ImePropertyListRec * ime_property_list)
00105 {
00106     int i;
00107 
00108     if (ime_property_list != NULL) {
00109         if (ime_property_list->properties != NULL) {
00110             for (i = 0; i < ime_property_list->count; i++) {
00111                 ImePropertyRec *p = &(ime_property_list->properties[i]);
00112                 ime_property_destroy(p);
00113             }
00114             free((char *) ime_property_list->properties);
00115         }
00116         free((char *) ime_property_list);
00117     }
00118 }
00119 
00120 void ime_property_list_print(ImePropertyListRec * ime_property_list)
00121 {
00122 #if DEBUG
00123     int i;
00124 
00125     if (ime_property_list != NULL) {
00126         if (ime_property_list->properties != NULL) {
00127             printf("ime_property_list: count: %d\n", ime_property_list->count);
00128             for (i = 0; i < ime_property_list->count; i++) {
00129                 ImePropertyRec *p = &(ime_property_list->properties[i]);
00130                 ime_property_print(p);
00131             }
00132         }
00133     }
00134 #endif
00135 }
00136 
00137 int ime_property_list_prepare_memory(ImePropertyListRec *ime_property_list)
00138 {
00139     int i, count;
00140 
00141     if (ime_property_list == NULL)
00142         return 0;
00143 
00144     if (ime_property_list->properties == NULL) {
00145         ime_property_list->properties =
00146             (ImePropertyRec *) calloc(IME_PROPERTY_LIST_NUM_ALLOC,
00147                                   sizeof(ImePropertyRec));
00148         if (ime_property_list->properties == NULL)
00149             return 0;
00150     }
00151 
00152     count = ime_property_list->count;
00153     if ((count + 1) % IME_PROPERTY_LIST_NUM_ALLOC == 0) {
00154         int num = count + 1 + IME_PROPERTY_LIST_NUM_ALLOC;
00155 
00156        ime_property_list->properties =
00157            (ImePropertyRec *) realloc(ime_property_list->properties,
00158                                        num * sizeof(ImePropertyRec));
00159         if (ime_property_list->properties == NULL)
00160             return 0;
00161 
00162         for (i = count; i < num; i++)
00163            memset(&(ime_property_list->properties[i]),
00164                    0, sizeof(ImePropertyRec));
00165     }
00166 
00167     return 1;
00168 }
00169 
00170 void ime_property_list_add_new_item(ImePropertyListRec * ime_property_list,
00171                                char *key, char *options, char *type,
00172                                char *value)
00173 {
00174     int i, ret;
00175     ImePropertyRec *ime_property;
00176 
00177     DEBUG_printf
00178        ("ime_property_list_add_new_item: key: %s, options: %s, type: %s, value: %s\n",
00179         key, options, type, value);
00180     if (ime_property_list == NULL)
00181        return;
00182 
00183     if (!key || !*key)
00184        return;
00185 
00186     if (!options || !*options)
00187        return;
00188 
00189     if (!type || !*type)
00190        return;
00191 
00192     if (!value || !*value)
00193        return;
00194 
00195     ret = ime_property_list_prepare_memory(ime_property_list);
00196     if (ret == 0)
00197         return;
00198 
00199     ime_property = &(ime_property_list->properties[ime_property_list->count]);
00200 
00201     ime_property->key = (char *) strdup(key);
00202 
00203     if (!strcasecmp(type, "ImeProperty_Toggle")) {
00204        ime_property->type = ImeProperty_Toggle;
00205     } else if (!strcasecmp(type, "ImeProperty_Int")) {
00206        ime_property->type = ImeProperty_Int;
00207     } else if (!strcasecmp(type, "ImeProperty_Selection")) {
00208        ime_property->type = ImeProperty_Selection;
00209     }
00210 
00211     if (ime_property->type == ImeProperty_Toggle) {
00212        ime_property->name = (char *) strdup(options);
00213     } else if (ime_property->type == ImeProperty_Int) {
00214        char *name, *min_str, *max_str;
00215 
00216        name = options;
00217        min_str = strchr(options, '/');
00218        max_str = NULL;
00219        if (min_str != NULL) {
00220            *min_str = 0;
00221            min_str++;
00222            max_str = strchr(min_str, '/');
00223            if (max_str != NULL) {
00224               *max_str = 0;
00225               max_str++;
00226            }
00227        }
00228 
00229        if (min_str != NULL && max_str != NULL) {
00230            ime_property->name = (char *) strdup(name);
00231            ime_property->range.int_range.min = atoi(min_str);
00232            ime_property->range.int_range.max = atoi(max_str);
00233        }
00234     } else if (ime_property->type == ImeProperty_Selection) {
00235        char *name, *option_ptr;
00236        char *ptr;
00237        char **multiString_range;
00238        int option_num = 0;
00239        int option_id;
00240 
00241        name = options;
00242        option_ptr = options;
00243        while (option_ptr) {
00244            option_ptr = strchr(option_ptr, '/');
00245            if (option_ptr) {
00246               option_num++;
00247               option_ptr++;
00248            }
00249        }
00250 
00251        DEBUG_printf("option_num: %d\n", option_num);
00252        if (option_num == 0)
00253            return;
00254 
00255        multiString_range =
00256            (char **) calloc(option_num + 1, sizeof(char *));
00257 
00258        name = options;
00259        option_ptr = strchr(options, '/');
00260        if (option_ptr != NULL) {
00261            *option_ptr = 0;
00262            option_ptr++;
00263            ime_property->name = (char *) strdup(name);
00264        }
00265 
00266        option_id = 0;
00267        do {
00268            ptr = strchr(option_ptr, '/');
00269            if (ptr)
00270               *ptr = 0;
00271 
00272            DEBUG_printf("option_ptr : %s, ptr: %p\n", option_ptr, ptr);
00273            multiString_range[option_id] = (char *) strdup(option_ptr);
00274            option_id++;
00275            option_ptr = ptr + 1;
00276        } while (ptr);
00277 
00278        ime_property->range.multiString_range = multiString_range;
00279     }
00280 
00281     ime_property->value.int_value = atoi(value);
00282     ime_property_list->count++;
00283 }
00284 
00285 /*********************************************************************/
00286 /*                       ime_module_t utilities                      */
00287 /*********************************************************************/
00288 static ime_module_t *ime_module_new()
00289 {
00290     ime_module_t *ime_module = NULL;
00291 
00292     ime_module = (ime_module_t *) calloc(1, sizeof(ime_module_t));
00293 
00294     return ime_module;
00295 }
00296 
00297 void ime_module_destroy(ime_module_t * ime_module)
00298 {
00299     if (ime_module == NULL)
00300        return;
00301 
00302     if (ime_module->uuid)
00303        free((char *) ime_module->uuid);
00304 
00305     if (ime_module->name)
00306        free((char *) ime_module->name);
00307 
00308     if (ime_module->author)
00309        free((char *) ime_module->author);
00310 
00311     if (ime_module->copyright)
00312        free((char *) ime_module->copyright);
00313 
00314     if (ime_module->hinting)
00315        free((char *) ime_module->hinting);
00316 
00317     if (ime_module->icon_file)
00318        free((char *) ime_module->icon_file);
00319 
00320     if (ime_module->icon_pixbuf)
00321        gdk_pixbuf_unref(ime_module->icon_pixbuf);
00322 
00323     if (ime_module->property_list)
00324        ime_property_list_destroy(ime_module->property_list);
00325 
00326     if (ime_module->vkbs) {
00327        int i;
00328        for (i = 0; i < ime_module->num_vkbs; i ++)
00329            vkb_layout_destroy (ime_module->vkbs[i]);
00330        free((char *)ime_module->vkbs);
00331     }
00332 
00333     free ((char *)ime_module);
00334 }
00335 
00336 void ime_module_print(ime_module_t * ime_module)
00337 {
00338 #if DEBUG
00339     if (ime_module == NULL)
00340        return;
00341 
00342     printf("ime: \n");
00343     printf("  version: %d\n", ime_module->version);
00344 
00345     if (ime_module->uuid)
00346        printf("  uuid: %s\n", (char *) ime_module->uuid);
00347 
00348     if (ime_module->name)
00349        printf("  name: %s\n", (char *) ime_module->name);
00350 
00351     if (ime_module->author)
00352        printf("  author: %s\n", (char *) ime_module->author);
00353 
00354     if (ime_module->copyright)
00355        printf("  copyright: %s\n", (char *) ime_module->copyright);
00356 
00357     if (ime_module->hinting)
00358        printf("  hinting: %s\n", (char *) ime_module->hinting);
00359 
00360     if (ime_module->icon_file)
00361        printf("  icon_file: %s\n", (char *) ime_module->icon_file);
00362 
00363     printf("  icon_pixbuf: %p.\n", ime_module->icon_pixbuf);
00364     printf("  enabled:  %d.\n", ime_module->enabled);
00365 
00366     printf("  property_list:  %p.\n", ime_module->property_list);
00367     if (ime_module->property_list)
00368        ime_property_list_print(ime_module->property_list);
00369 
00370     if (ime_module->vkbs) {
00371        int i;
00372        for (i = 0; i < ime_module->num_vkbs; i ++)
00373            vkb_layout_print (ime_module->vkbs[i]);
00374     }
00375 
00376     printf("\n");
00377 #endif
00378 }
00379 
00380 #define VKB_LAYOUT_NUM_ALLOC   6
00381 int ime_module_pushback_vkb(ime_module_t *ime_module, vkb_layout_t *vkb)
00382 {
00383     int i, num_vkbs;
00384 
00385     if (ime_module == NULL || vkb == NULL)
00386         return 0;
00387 
00388     if (ime_module->vkbs == NULL) {
00389         ime_module->vkbs = (vkb_layout_t **)calloc (VKB_LAYOUT_NUM_ALLOC,
00390                                                     sizeof(vkb_layout_t *));
00391         if (ime_module->vkbs == NULL)
00392             return 0;
00393     }
00394 
00395     num_vkbs = ime_module->num_vkbs;
00396     if ((num_vkbs + 1) % VKB_LAYOUT_NUM_ALLOC == 0) {
00397         int num = num_vkbs + 1 + VKB_LAYOUT_NUM_ALLOC;
00398 
00399         ime_module->vkbs = (vkb_layout_t **)realloc(ime_module->vkbs,
00400                                              num * sizeof(vkb_layout_t *));
00401         if (ime_module->vkbs == NULL)
00402             return 0;
00403 
00404         for (i = num_vkbs; i < num; i++)
00405             ime_module->vkbs[i] = NULL;
00406     }
00407 
00408     ime_module->vkbs[num_vkbs] = vkb;
00409     ime_module->num_vkbs ++;
00410 
00411     return 1;
00412 }
00413 
00414 /*********************************************************************/
00415 /*                    property_data_t utilities                      */
00416 /*********************************************************************/
00417 
00418 property_data_t *property_data_new()
00419 {
00420     property_data_t *property_data = NULL;
00421 
00422     property_data = (property_data_t *) calloc(1, sizeof(property_data_t));
00423     if (property_data == NULL)
00424        return NULL;
00425 
00426     property_data->time_stamp = 0;
00427     property_data->fkey_vkb = 'K';
00428 
00429     property_data->show_ime_button = 1;
00430     property_data->show_qjbj_button = 1;
00431     property_data->show_punct_button = 1;
00432     property_data->show_vkb_button = 1;
00433     property_data->show_utility_button = 1;
00434     property_data->show_with_vertical = 0;
00435 
00436     property_data->pos_x_palette = -1;
00437     property_data->pos_y_palette = -1;
00438     
00439     property_data->tooltips_enabled = 1;
00440     property_data->beep_enabled = 1;
00441 
00442     property_data->composite_style = 1;
00443 
00444     property_data->num_ime_modules = 0;
00445     property_data->ime_modules = NULL;
00446 
00447     return property_data;
00448 }
00449 
00450 void property_data_destroy(property_data_t * property_data)
00451 {
00452     int i;
00453 
00454     if (property_data == NULL)
00455        return;
00456 
00457     if (property_data->ime_modules)  {
00458        for (i = 0; i < property_data->num_ime_modules; i++) {
00459            ime_module_destroy(property_data->ime_modules[i]);
00460        }
00461        free ((char *)property_data->ime_modules);
00462     }
00463 
00464     free ((char *)property_data);
00465 }
00466 
00467 void property_data_print(property_data_t * property_data)
00468 {
00469 #if DEBUG
00470     int i;
00471 
00472     if (property_data == NULL)
00473        return;
00474 
00475     printf(" show_ime_button:      %d\n", property_data->show_ime_button);
00476     printf(" show_qjbj_button:     %d\n", property_data->show_qjbj_button);
00477     printf(" show_punct_button:    %d\n", property_data->show_punct_button);
00478     printf(" show_vkb_button:      %d\n", property_data->show_vkb_button);
00479     printf(" show_utility_button:  %d\n", property_data->show_utility_button);
00480     printf(" show_with_vertical:   %d\n", property_data->show_with_vertical);
00481 
00482     printf(" pos_x_palette:        %d\n", property_data->pos_x_palette);
00483     printf(" pos_y_palette:        %d\n", property_data->pos_y_palette);
00484 
00485     printf(" beep_enabled:         %d\n", property_data->beep_enabled);
00486 
00487     printf(" composite_style:      %d\n", property_data->composite_style);
00488 
00489     if (property_data->ime_modules)  {
00490        for (i = 0; i < property_data->num_ime_modules; i++) {
00491            ime_module_print(property_data->ime_modules[i]);
00492        }
00493     }
00494 #endif
00495 }
00496 
00497 void property_data_set_enabled_by_uuid(property_data_t *property_data,
00498                                    char *uuid, int enabled)
00499 {
00500     int i;
00501     ime_module_t *ime_module;
00502 
00503     if (property_data == NULL)
00504        return;
00505 
00506     for (i = 0; i < property_data->num_ime_modules; i++) {
00507        ime_module = property_data->ime_modules[i];
00508 
00509        if (ime_module == NULL || ime_module->uuid == NULL)
00510            continue;
00511 
00512        if (!strcmp(ime_module->uuid, uuid))
00513            ime_module->enabled = enabled;
00514     }
00515 
00516     return;
00517 }
00518 
00519 ime_module_t *property_data_get_ime_module_by_uuid(property_data_t *property_data,
00520                                              char *uuid)
00521 {
00522     int i;
00523     ime_module_t *ime_module;
00524 
00525     if (property_data == NULL)
00526        return NULL;
00527 
00528     for (i = 0; i < property_data->num_ime_modules; i++) {
00529        ime_module = property_data->ime_modules[i];
00530 
00531        if (ime_module == NULL || ime_module->uuid == NULL)
00532            continue;
00533 
00534        if (!strcmp(ime_module->uuid, uuid))
00535            return ime_module;
00536     }
00537 
00538     return NULL;
00539 }
00540 
00541 #define IME_MODULE_LIST_NUM_ALLOC 10
00542 int property_data_pushback_ime_module(property_data_t *property_data,
00543                                       ime_module_t *ime_module)
00544 {
00545     int i, num_ime_modules;
00546 
00547     if (property_data == NULL || ime_module == NULL)
00548         return 0;
00549 
00550     if (property_data->ime_modules == NULL) {
00551         property_data->ime_modules = (ime_module_t **)
00552                                           calloc (IME_MODULE_LIST_NUM_ALLOC,
00553                                                   sizeof(ime_module_t *));
00554         if (property_data->ime_modules == NULL)
00555             return 0;
00556     }
00557 
00558     num_ime_modules = property_data->num_ime_modules;
00559     if ((num_ime_modules + 1) % IME_MODULE_LIST_NUM_ALLOC == 0) {
00560         int num = num_ime_modules + 1 + IME_MODULE_LIST_NUM_ALLOC;
00561 
00562         property_data->ime_modules = (ime_module_t **)realloc(property_data->ime_modules,
00563                                                               num * sizeof(ime_module_t *));
00564         if (property_data->ime_modules == NULL)
00565             return 0;
00566 
00567         for (i = num_ime_modules; i < num; i++)
00568             property_data->ime_modules[i] = NULL;
00569     }
00570 
00571     property_data->ime_modules[num_ime_modules] = ime_module;
00572     property_data->num_ime_modules ++;
00573 
00574     return 1;
00575 }
00576 
00577 /*********************************************************************/
00578 /*      property_data_t utilities to save/get from user profile      */
00579 /*********************************************************************/
00580 
00581 #define USER_PROFILE_PATH              ".iiim"
00582 #define IME_CONFIG_PROFILE_NAME        "ime_config.xml"
00583 #define LOCAL_PERFERENCE_PROFILE_NAME  "local_perference.xml"
00584 
00585 #define ALL_ENGINE_CATAGORY            "all_engines"
00586 #define ENGINE_PROPERTIES_CATAGORY     "engine_properties"
00587 #define SYSTEM_PROPERTIES_CATAGORY     "le_settings"
00588 #define STATUSBAR_PROPERTIES_CATAGORY  "statusbar_properties"
00589 #define IIIMSERVER_PROPERTIES_CATAGORY "iiim_properties"
00590 
00591 char *property_data_parse_ime_vkb_info(ime_module_t *ime_module,
00592                                    char *options)
00593 {
00594     int i, ret;
00595     vkb_layout_t *vkb;
00596 
00597     char label_str[256];
00598     char key_value_pair[256];
00599     char keymapping_str[1024];
00600     char new_option_str[1024];
00601     char *p;
00602 
00603     if (ime_module == NULL)
00604         return NULL;
00605 
00606     if (!options || !*options)
00607         return NULL;
00608 
00609     /* make sure to clean the old vkb infos in ime_module */
00610     if (ime_module->vkbs != NULL) {
00611         for (i = 0; i < ime_module->num_vkbs; i++) {
00612             vkb_layout_destroy (ime_module->vkbs[i]);
00613         }
00614 
00615         free ((char *) ime_module->vkbs);
00616         ime_module->num_vkbs = 0;
00617     }
00618 
00619     /* begin parse option string      */
00620     /* two tasks:                     */
00621     /*    1. create vkb_layout list   */
00622     /*    2. recreate new options str */
00623     p = options;
00624 
00625     memset(new_option_str, 0, 1024);
00626 
00627     /* get label_str */
00628     i = 0;
00629     memset (label_str, 0, 256);
00630     while (*p) {
00631         if (i >= 256 || (*p == '/' && (i == 0 || *(p-1) != '\\')))
00632             break;
00633 
00634         label_str[i++] = *(p ++);
00635     }
00636     DEBUG_printf("lable_str:  %s\n", label_str);
00637     strncpy(new_option_str, label_str, 1024);
00638 
00639     if (!*p || *p != '/')
00640         return NULL;
00641 
00642     p ++;
00643     
00644     while (*p) {
00645         char *ptr;
00646         char vkb_name[256];
00647         char vkb_key_pair[256];
00648 
00649         /* try to get keymapping string, like:  vkb_name|aA|bB|... */
00650         i = 0;
00651        memset(keymapping_str, 0, 1024);
00652         while (*p) {
00653             if (i >= 1024 || (*p == '/' && (i == 0 || *(p-1) != '\\')))
00654                 break;
00655 
00656             keymapping_str[i++] = *(p ++);
00657         }
00658 
00659         /* process keymapping string */
00660         if (*keymapping_str) {
00661             DEBUG_printf("keymapping_str:  %s\n", keymapping_str);
00662 
00663             ptr = keymapping_str;
00664 
00665             /* try to get vkb name string, like:  vkb_name */
00666             i = 0;
00667            memset(vkb_name, 0, 256);
00668             while (*ptr) {
00669                 if (i >= 256 || (*ptr == '|' && (i == 0 || *(ptr-1) != '\\')))
00670                     break;
00671 
00672                 vkb_name[i++] = *(ptr ++);
00673             }
00674 
00675             if (*vkb_name) {
00676                 strncat(new_option_str, "/", 1024);
00677                 strncat(new_option_str, vkb_name, 1024);
00678 
00679                 /* create vkb_layout */
00680               if (*ptr == '|') {
00681                     DEBUG_printf("key_value_pair: %s\n", ptr);
00682                     vkb = (vkb_layout_t *) vkb_layout_new();
00683                     if (vkb == NULL)
00684                         break;
00685 
00686                     vkb->type = KEYBOARD_KEY_TYPE;
00687                     vkb_layout_set_keyboard_ename(vkb, "keymap");
00688                     vkb_layout_set_keyboard_label(vkb, vkb_name);
00689                     vkb_layout_set_ctrlkey_label(vkb);
00690 
00691                     ptr++;
00692                     while (*ptr) {
00693                         i = 0;
00694                         memset(key_value_pair, 0, 256);
00695 
00696                         if (*ptr == '\\' &&
00697                             (*(ptr+1) == '/' || *(ptr+1) == '|'))
00698                             ptr++;
00699 
00700                         key_value_pair[i++] = *ptr++;
00701                         key_value_pair[i++] = 0x20;
00702     
00703                         if (!*ptr) break;
00704 
00705                         while (*ptr) {
00706                             if (i >= 256 || (*ptr == '|' && (i == 0 || *(ptr-1) != '\\')))
00707                                 break;
00708 
00709                             key_value_pair[i++] = *(ptr ++);
00710                         }
00711 
00712                         DEBUG_printf(" key_value_pair: %s\n", key_value_pair);
00713                         vkb_layout_set_basekey_label(vkb, key_value_pair);
00714 
00715                         if (*ptr != '|')
00716                             break;
00717 
00718                         ptr ++;
00719                     }
00720 
00721                     vkb_layout_print(vkb);
00722                     ret = ime_module_pushback_vkb(ime_module, vkb);
00723                     if (ret == 0) {
00724                         vkb_layout_destroy(vkb);
00725                     }
00726                 }
00727             }
00728         }
00729 
00730         if (!*p || *p != '/')
00731             break;
00732 
00733         p ++;
00734     }
00735 
00736     if (ime_module->num_vkbs > 1) {
00737        int len = strlen (options) + 1;
00738         strncpy(options, new_option_str, len);
00739         return options;
00740     }
00741 
00742     return NULL;
00743 }
00744 
00745 void property_data_parse_ime_property(ime_module_t *ime_module,
00746                                   IbmlProperty *ibml_property)
00747 {
00748     char *name, *value, *type, *options;
00749 
00750     name = (char *) ibml_property->name;
00751     if (!name || !*name)
00752        return;
00753 
00754     value = (char *) ibml_property->value;
00755     if (!value || !*value)
00756        return;
00757 
00758     if (!strcasecmp(name, "name")) {
00759        if (ime_module->name)
00760            free ((char *)ime_module->name);
00761        ime_module->name = (char *) strdup(value);
00762        return;
00763     } else if (!strcasecmp(name, "version")) {
00764        if (ime_module->version)
00765            free ((char *)ime_module->version);
00766        ime_module->version = atoi (value);
00767        return;
00768     } else if (!strcasecmp(name, "copyright")) {
00769        if (ime_module->copyright)
00770            free ((char *)ime_module->copyright);
00771        ime_module->copyright = (char *) strdup(value);
00772        return;
00773     } else if (!strcasecmp(name, "author")) {
00774        if (ime_module->author)
00775            free ((char *)ime_module->author);
00776        ime_module->author = (char *) strdup(value);
00777        return;
00778     } else if (!strcasecmp(name, "hinting")) {
00779        if (ime_module->hinting)
00780            free ((char *)ime_module->hinting);
00781        ime_module->hinting = (char *) strdup(value);
00782        return;
00783     } else if (!strcasecmp(name, "icon_file")) {
00784        if (ime_module->icon_file)
00785            free ((char *)ime_module->icon_file);
00786        ime_module->icon_file = (char *) strdup(value);
00787        return;
00788     } else if (!strcasecmp(name, "enabled")) {
00789        char *enabled_str = (char *) value;
00790        ime_module->enabled = 1;
00791        if (enabled_str && (!strcasecmp(enabled_str, "false"))) {
00792            ime_module->enabled = 0;
00793        }
00794        return;
00795     }
00796 
00797     options = (char *) ibml_property->options;
00798     if (!options || !*options)
00799        return;
00800 
00801     type = (char *) ibml_property->type;
00802     if (!type || !*type)
00803        return;
00804 
00805     /* parse keymapping info */
00806     if (!strcasecmp(name, "/keymapping")) {
00807        options = property_data_parse_ime_vkb_info(ime_module, options);
00808     }
00809 
00810     if (!options || !*options)
00811        return;
00812 
00813     /* add IME property list */
00814     if (ime_module->property_list == NULL) {
00815        ime_module->property_list = (ImePropertyListRec *)ime_property_list_new();
00816     }
00817 
00818     ime_property_list_add_new_item(ime_module->property_list,
00819                                name, options, type, value);
00820 
00821     return;
00822 }
00823 
00824 void property_data_parse_iiimserver_properties(property_data_t *property_data,
00825                                           IbmlProperty *ibml_property)
00826 {
00827     char *name, *value;
00828 
00829     name = (char *) ibml_property->name;
00830     if (!name || !*name)
00831        return;
00832 
00833     value = (char *) ibml_property->value;
00834     if (!value || !*value)
00835        return;
00836 
00837     DEBUG_printf("property_data_parse_iiimserver_properties ===\n");
00838     if (!strcasecmp(name, "time_stamp")) {
00839        property_data->time_stamp = atol(value);
00840     } else if (!strcasecmp(name, "shortcutkey_vkb")) {
00841        property_data->fkey_vkb = value[0];
00842     }
00843 
00844     return;
00845 }
00846 
00847 void property_data_parse_statusbar_properties(property_data_t *property_data,
00848                                          IbmlProperty *ibml_property)
00849 {
00850     char *name, *value;
00851 
00852     name = (char *) ibml_property->name;
00853     if (!name || !*name)
00854        return;
00855 
00856     value = (char *) ibml_property->value;
00857     if (!value || !*value)
00858        return;
00859 
00860     DEBUG_printf("property_data_parse_statusbar_properties ===\n");
00861     if (!strcasecmp(name, "show_ime_button")) {
00862        property_data->show_ime_button = 1;
00863        if (!strcasecmp(value, "false")) {
00864            property_data->show_ime_button = 0;
00865        }
00866     } else if (!strcasecmp(name, "show_qjbj_button")) {
00867        property_data->show_qjbj_button = 1;
00868        if (!strcasecmp(value, "false")) {
00869            property_data->show_qjbj_button = 0;
00870        }
00871     } else if (!strcasecmp(name, "show_punct_button")) {
00872        property_data->show_punct_button = 1;
00873        if (!strcasecmp(value, "false")) {
00874            property_data->show_punct_button = 0;
00875        }
00876     } else if (!strcasecmp(name, "show_vkb_button")) {
00877        property_data->show_vkb_button = 1;
00878        if (!strcasecmp(value, "false")) {
00879            property_data->show_vkb_button = 0;
00880        }
00881     } else if (!strcasecmp(name, "show_utility_button")) {
00882        property_data->show_utility_button = 1;
00883        if (!strcasecmp(value, "false")) {
00884            property_data->show_utility_button = 0;
00885        }
00886     } else if (!strcasecmp(name, "show_with_vertical")) {
00887        property_data->show_with_vertical = 0;
00888        if (!strcasecmp(value, "true")) {
00889            property_data->show_with_vertical = 1;
00890        }
00891     } else if (!strcasecmp(name, "beep_enabled")) {
00892        property_data->beep_enabled = 1;
00893        if (!strcasecmp(value, "false")) {
00894            property_data->beep_enabled = 0;
00895        }
00896     } else if (!strcasecmp(name, "pos_x_palette")) {
00897        property_data->pos_x_palette = atoi(value);
00898     } else if (!strcasecmp(name, "pos_y_palette")) {
00899        property_data->pos_y_palette = atoi(value);
00900     }
00901 
00902     return;
00903 }
00904 
00905 void property_data_get_system_properties_info(property_data_t *property_data,
00906                                          IbmlCategory *ibml_category)
00907 {
00908     IbmlElement *ibml_element;
00909     IbmlProperty *ibml_property;
00910 
00911     int i, j;
00912 
00913     char *id, *scope;
00914 
00915     if (ibml_category == NULL)
00916        return;
00917     if (ibml_category->num_elements <= 0)
00918        return;
00919 
00920     for (i = 0; i < ibml_category->num_elements; i++) {
00921        ibml_element = ibml_category->elements[i];
00922        if (!ibml_element)
00923            continue;
00924        if (ibml_element->num_properties <= 0)
00925            continue;
00926 
00927        id = (char *) ibml_element->id;
00928        scope = (char *) ibml_element->scope;
00929        DEBUG_printf("id:%s, scope:%s\n", id ? id : "NULL",
00930               scope ? scope : "NULL");
00931        if (!id || !*id)
00932            continue;
00933   
00934        if (!strcasecmp(id, IIIMSERVER_PROPERTIES_CATAGORY)) {
00935            for (j = 0; j < ibml_element->num_properties; j++) {
00936                ibml_property = ibml_element->properties[j];
00937                if (!ibml_property)
00938                   continue;
00939 
00940                property_data_parse_iiimserver_properties(property_data,
00941                                                     ibml_property);
00942            }
00943        } else if (!strcasecmp(id, STATUSBAR_PROPERTIES_CATAGORY)) {
00944            for (j = 0; j < ibml_element->num_properties; j++) {
00945                ibml_property = ibml_element->properties[j];
00946                if (!ibml_property)
00947                   continue;
00948 
00949                property_data_parse_statusbar_properties(property_data,
00950                                                    ibml_property);
00951            }
00952        }
00953     }
00954 
00955     return;
00956 }
00957 
00958 void property_data_get_ime_modules_info(property_data_t *property_data,
00959                                    IbmlCategory *ibml_category)
00960 {
00961     ime_module_t *ime_module;
00962 
00963     IbmlElement *ibml_element;
00964     IbmlProperty *ibml_property;
00965 
00966     int i, j;
00967 
00968     char *id, *scope;
00969 
00970     if (property_data == NULL)
00971        return;
00972     if (ibml_category == NULL)
00973        return;
00974     if (ibml_category->num_elements <= 0)
00975        return;
00976 
00977     if (property_data->ime_modules)  {
00978        for (i = 0; i < property_data->num_ime_modules; i++) {
00979            ime_module_destroy(property_data->ime_modules[i]);
00980        }
00981        free ((char *)property_data->ime_modules);
00982 
00983         property_data->ime_modules = NULL;
00984         property_data->num_ime_modules = 0;
00985     }
00986 
00987     for (i = 0; i < ibml_category->num_elements; i++) {
00988        ibml_element = ibml_category->elements[i];
00989        if (!ibml_element)
00990            continue;
00991        if (ibml_element->num_properties <= 0)
00992            continue;
00993 
00994        id = (char *) ibml_element->id;
00995        scope = (char *) ibml_element->scope;
00996        DEBUG_printf("id:%s, scope:%s\n", id ? id : "NULL",
00997               scope ? scope : "NULL");
00998        if (!id || !*id)
00999            continue;
01000 
01001        ime_module = (ime_module_t *) ime_module_new();
01002        if (ime_module == NULL)
01003            continue;
01004 
01005        ime_module->uuid = (char *) strdup(id);
01006 
01007        for (j = 0; j < ibml_element->num_properties; j++) {
01008            ibml_property = ibml_element->properties[j];
01009            if (!ibml_property)
01010               continue;
01011 
01012            property_data_parse_ime_property(ime_module, ibml_property);
01013        }
01014 
01015        if (ime_module->uuid == NULL ||
01016            ime_module->name == NULL ||
01017            ! property_data_pushback_ime_module(property_data, ime_module)) {
01018            ime_module_destroy (ime_module);
01019            continue;
01020         }
01021     }
01022 
01023     return;
01024 }
01025 
01026 int property_data_parse_from_xmlstr(property_data_t *property_data, char *xml_str, int size)
01027 {
01028     IbmlData *ibml_data;
01029     IbmlCategory *ibml_category;
01030     int i;
01031 
01032     if (property_data == NULL)
01033        return 0;
01034 
01035     if (xml_str == NULL || size <= 0)
01036        return 0;
01037 
01038     ibml_data = (IbmlData *) imbean_config_new_from_memory(xml_str, size);
01039     if (ibml_data == NULL)
01040        return 0;
01041 
01042     for (i = 0; i < ibml_data->num_categories; i++) {
01043        ibml_category = ibml_data->categories[i];
01044 
01045        if (!ibml_category->scope || !*ibml_category->scope)
01046            continue;
01047 
01048        if (!strcasecmp(ibml_category->scope, ALL_ENGINE_CATAGORY)) {
01049            property_data_get_ime_modules_info(property_data, ibml_category);
01050        } else if (!strcasecmp(ibml_category->scope, SYSTEM_PROPERTIES_CATAGORY)) {
01051            property_data_get_system_properties_info(property_data, ibml_category);
01052        }
01053     }
01054 
01055     ibml_data_free(ibml_data);
01056     return 1;
01057 }
01058 
01059 char *property_data_composite_local_perference_to_xmlstr(property_data_t *property_data)
01060 {
01061     xmlDocPtr doc;
01062     xmlAttrPtr attr;
01063     xmlNodePtr root;
01064     xmlNodePtr im_node;
01065     xmlNodePtr imbean_node;
01066     xmlNodePtr property_node;
01067     xmlChar *xmlbuf;
01068 
01069     char *enabled_str;
01070     char tmp_str[256];
01071     int size;
01072 
01073     if (property_data == NULL)
01074        return NULL;
01075 
01076     doc = xmlNewDoc("1.0");
01077 
01078     attr = xmlNewDocProp(doc, "encoding", "UTF-8");
01079 
01080     root = xmlNewNode(NULL, IBML_ELEMENT_ROOT);
01081     xmlSetProp(root, IBML_ELEMENT_SCOPE, LE_NAME);
01082     xmlDocSetRootElement(doc, root);
01083 
01084     doc->children = root;
01085 
01086     /* For "local_perference" category */
01087     im_node = xmlNewChild(root, NULL, IBML_ELEMENT_CATAGORY, NULL);
01088     xmlSetProp(im_node, IBML_ELEMENT_SCOPE, SYSTEM_PROPERTIES_CATAGORY);
01089 
01090     imbean_node = xmlNewChild(im_node, NULL, IBML_ELEMENT_IMBEAN, NULL);
01091     xmlSetProp(imbean_node, IBML_ELEMENT_IMBEAN_ID, STATUSBAR_PROPERTIES_CATAGORY);
01092 
01093     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01094     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "pos_x_palette");
01095     snprintf(tmp_str, sizeof(tmp_str), "%d", property_data->pos_x_palette); 
01096     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, tmp_str);
01097 
01098     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01099     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "pos_y_palette");
01100     snprintf(tmp_str, sizeof(tmp_str), "%d", property_data->pos_y_palette); 
01101     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, tmp_str);
01102 
01103     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01104     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_ime_button");
01105     enabled_str = "true";
01106     if (property_data->show_ime_button == 0)
01107         enabled_str = "false";
01108     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01109 
01110     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01111     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_qjbj_button");
01112     enabled_str = "true";
01113     if (property_data->show_qjbj_button == 0)
01114         enabled_str = "false";
01115     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01116 
01117     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01118     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_punct_button");
01119     enabled_str = "true";
01120     if (property_data->show_punct_button == 0)
01121         enabled_str = "false";
01122     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01123 
01124     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01125     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_vkb_button");
01126     enabled_str = "true";
01127     if (property_data->show_vkb_button == 0)
01128         enabled_str = "false";
01129     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01130 
01131     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01132     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_utility_button");
01133     enabled_str = "true";
01134     if (property_data->show_utility_button == 0)
01135         enabled_str = "false";
01136     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01137 
01138     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01139     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "show_with_vertical");
01140     enabled_str = "true";
01141     if (property_data->show_with_vertical == 0)
01142         enabled_str = "false";
01143     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01144 
01145     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01146     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "beep_enabled");
01147     enabled_str = "true";
01148     if (property_data->beep_enabled == 0)
01149         enabled_str = "false";
01150     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01151 
01152     xmlDocDumpFormatMemoryEnc(doc, &xmlbuf, &size, "UTF-8", 1);
01153 
01154     xmlFreeDoc(doc);
01155 
01156     return xmlbuf;
01157 }
01158 
01159 /* mode: local or server */
01160 char *property_data_composite_le_settings_to_xmlstr(property_data_t *property_data, int mode)
01161 {
01162     xmlDocPtr doc;
01163     xmlAttrPtr attr;
01164     xmlNodePtr root;
01165     xmlNodePtr im_node;
01166     xmlNodePtr imbean_node;
01167     xmlNodePtr property_node;
01168     xmlChar *xmlbuf;
01169     int i, j, size;
01170     char *enabled_str;
01171     char tmp_buf[256];
01172 
01173     if (property_data == NULL)
01174        return NULL;
01175 
01176     doc = xmlNewDoc("1.0");
01177 
01178     attr = xmlNewDocProp(doc, "encoding", "UTF-8");
01179 
01180     root = xmlNewNode(NULL, IBML_ELEMENT_ROOT);
01181     xmlSetProp(root, IBML_ELEMENT_SCOPE, LE_NAME);
01182     xmlDocSetRootElement(doc, root);
01183 
01184     doc->children = root;
01185 
01186     /* For "le_setting" category */
01187     im_node = xmlNewChild(root, NULL, IBML_ELEMENT_CATAGORY, NULL);
01188     xmlSetProp(im_node, IBML_ELEMENT_SCOPE, SYSTEM_PROPERTIES_CATAGORY);
01189 
01190     imbean_node = xmlNewChild(im_node, NULL, IBML_ELEMENT_IMBEAN, NULL);
01191     xmlSetProp(imbean_node, IBML_ELEMENT_IMBEAN_ID, IIIMSERVER_PROPERTIES_CATAGORY);
01192 
01193     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01194     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "time_stamp");
01195     snprintf(tmp_buf, 256, "%d", property_data->time_stamp);
01196     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, tmp_buf);
01197 
01198     property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01199     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "shortcutkey_vkb");
01200     snprintf(tmp_buf, 256, "%c", property_data->fkey_vkb);
01201     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, tmp_buf);
01202 
01203     /* For "all_engines" category */
01204     im_node = xmlNewChild(root, NULL, IBML_ELEMENT_CATAGORY, NULL);
01205     if (mode == PROPERTY_DATA_FOR_LOCAL_PROFILE ||
01206         mode == PROPERTY_DATA_FOR_SERVER_NOTIFICATION) {
01207         xmlSetProp(im_node, IBML_ELEMENT_SCOPE, ALL_ENGINE_CATAGORY);
01208     } else {
01209         xmlSetProp(im_node, IBML_ELEMENT_SCOPE, ENGINE_PROPERTIES_CATAGORY);
01210     }
01211 
01212     for (i = 0; i < property_data->num_ime_modules; i++) {
01213        ime_module_t *ime_module;
01214        ImePropertyListRec *property_list;
01215 
01216        ime_module = (ime_module_t *) property_data->ime_modules[i];
01217 
01218        imbean_node = xmlNewChild(im_node, NULL, IBML_ELEMENT_IMBEAN, NULL);
01219        xmlSetProp(imbean_node, IBML_ELEMENT_IMBEAN_ID,
01220                  (char *) ime_module->uuid);
01221 
01222         if (mode == PROPERTY_DATA_FOR_LOCAL_PROFILE) {
01223             if (ime_module->name) {
01224                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01225                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "name");
01226                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, ime_module->name);
01227             }
01228 
01229             if (ime_module->author) {
01230                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01231                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "author");
01232                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, ime_module->author);
01233             }
01234 
01235             if (ime_module->copyright) {
01236                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01237                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "copyright");
01238                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, ime_module->copyright);
01239             }
01240 
01241             if (ime_module->version) {
01242                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01243                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "version");
01244                 snprintf(tmp_buf, 256, "%d", ime_module->version);
01245                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, tmp_buf);
01246             }
01247 
01248             if (ime_module->hinting) {
01249                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01250                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "hinting");
01251                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, ime_module->hinting);
01252             }
01253 
01254             if (ime_module->icon_file) {
01255                 property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01256                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "icon_file");
01257                 xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, ime_module->icon_file);
01258             }
01259         }
01260 
01261        property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01262        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, "enabled");
01263        enabled_str = "true";
01264        if (ime_module->enabled == 0)
01265            enabled_str = "false";
01266        xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, enabled_str);
01267 
01268        property_list = ime_module->property_list;
01269        if (property_list) {
01270            for (j = 0; j < property_list->count; j++) {
01271               char buf[10];
01272 
01273               ImePropertyRec *ime_property = &(property_list->properties[j]);
01274               if (ime_property == NULL)
01275                   continue;
01276 
01277               property_node = xmlNewChild(imbean_node, NULL, IBML_ELEMENT_PROPERTY, NULL);
01278               xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_NAME, ime_property->key);
01279 
01280                 if (mode == PROPERTY_DATA_FOR_LOCAL_PROFILE) {
01281                     char options_str[1024];
01282                     char *options_type = "ImeProperty_Toggle";
01283 
01284                     options_str[0] = 0;
01285                     if (ime_property->type == ImeProperty_Toggle) {
01286                         options_type = "ImeProperty_Toggle";
01287                         strncat(options_str, ime_property->name, 1024);
01288                     } else if (ime_property->type == ImeProperty_Selection) {
01289                         char **value_ptr;
01290                         int k;
01291 
01292                         options_type = "ImeProperty_Selection";
01293 
01294                         strncat(options_str, ime_property->name, 1024);
01295                         value_ptr = ime_property->range.multiString_range;
01296                         if (value_ptr != NULL) {
01297                             for (k = 0; value_ptr[k] != NULL; k++) {
01298                                 strncat(options_str, "/", 1024);
01299                                 strncat(options_str, value_ptr[k], 1024);
01300                             }
01301                         }
01302                     } else if (ime_property->type == ImeProperty_Int) {
01303                         char value[12];
01304 
01305                         options_type = "ImeProperty_Int";
01306 
01307                         strncat(options_str, ime_property->name, 1024);
01308                         strncat(options_str, "/", 1024);
01309                         snprintf(value, 12, "%d/%d",
01310                                  ime_property->range.int_range.min,
01311                                  ime_property->range.int_range.max);
01312                         strncat(options_str, value, 1024);
01313                     }
01314 
01315                     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_OPTIONS,
01316                                options_str);
01317                     xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_TYPE,
01318                                options_type);
01319                 }
01320 
01321               snprintf(buf, 10, "%d", ime_property->value.int_value);
01322               xmlSetProp(property_node, IBML_ELEMENT_PROPERTY_VALUE, buf);
01323            }
01324        }
01325     }
01326 
01327     xmlDocDumpFormatMemoryEnc(doc, &xmlbuf, &size, "UTF-8", 1);
01328 
01329     xmlFreeDoc(doc);
01330 
01331     return xmlbuf;
01332 }
01333 
01334 char *property_data_get_local_profile_path(int create_flag)
01335 {
01336     int ret;
01337     struct stat file_stat;
01338     char path_name[256], tmp_name[256];
01339     char *locale_name;
01340     char *local_profile_path;
01341 
01342     /* get Path $(HOME)/.iiim/<locale>/$LE_NAME */
01343     locale_name = setlocale(LC_CTYPE, NULL);
01344     snprintf(path_name, 256, "%s/%s/%s/%s", getenv("HOME"),
01345            USER_PROFILE_PATH, locale_name, LE_NAME);
01346     DEBUG_printf("path name :%s\n", path_name);
01347 
01348     local_profile_path = (char *)strdup(path_name);
01349 
01350     if (create_flag == 0)
01351         return local_profile_path;
01352 
01353     ret = stat(path_name, &file_stat);
01354     if (ret == 0)
01355         return local_profile_path;
01356 
01357     /* Create Path $(HOME)/.iiim */
01358     snprintf(path_name, 256, "%s/%s", (char *) getenv("HOME"),
01359            USER_PROFILE_PATH);
01360     DEBUG_printf("path_name: %s\n", path_name);
01361 
01362     ret = stat(path_name, &file_stat);
01363     if (ret == -1) {
01364        DEBUG_printf("%s not exist\n", path_name);
01365        ret = mkdir(path_name, 0777);
01366        if (ret == -1) {
01367            DEBUG_printf("can not create path %s\n", path_name);
01368            if (local_profile_path)
01369                 free ((char *)local_profile_path);
01370            return NULL;
01371        }
01372     }
01373 
01374     /* Create Path $(HOME)/.iiim/<locale> */
01375     locale_name = setlocale(LC_CTYPE, NULL);
01376     snprintf(tmp_name, 256, "%s/%s", path_name, locale_name);
01377     strncpy(path_name, tmp_name, 256);
01378 
01379     ret = stat(path_name, &file_stat);
01380     if (ret == -1) {
01381        DEBUG_printf("%s not exist\n", path_name);
01382        ret = mkdir(path_name, 0777);
01383        if (ret == -1) {
01384            DEBUG_printf("can not create path %s\n", path_name);
01385            if (local_profile_path)
01386                 free ((char *)local_profile_path);
01387            return NULL;
01388        }
01389     }
01390 
01391     /* Create Path $(HOME)/.iiim/<locale>/$LE_NAME */
01392     snprintf(tmp_name, 256, "%s/%s", path_name, LE_NAME);
01393     strncpy(path_name, tmp_name, 256);
01394     DEBUG_printf("path_name: %s\n", path_name);
01395 
01396     ret = stat(path_name, &file_stat);
01397     if (ret == -1) {
01398        DEBUG_printf("%s not exist\n", path_name);
01399        ret = mkdir(path_name, 0777);
01400        if (ret == -1) {
01401            DEBUG_printf("can not create path %s\n", path_name);
01402            if (local_profile_path)
01403                 free ((char *)local_profile_path);
01404            return NULL;
01405        }
01406     }
01407 
01408     return local_profile_path;
01409 }
01410 
01411 int property_data_read_file_to_memory(char *file_name, char **ptr, int *len)
01412 {
01413     char full_file_name[256];
01414     struct stat file_stat;
01415     int ret, file_size;
01416 
01417     FILE *fd;
01418     char *file_buf = NULL;
01419     char *local_profile_path;
01420 
01421     if (file_name == NULL)
01422         return 0;
01423 
01424     *ptr = NULL;
01425     *len = 0;
01426 
01427     /* read profile from file to memory buffer  */
01428     local_profile_path = (char *)property_data_get_local_profile_path(0);
01429     if (local_profile_path == NULL)
01430         return 0;
01431 
01432     snprintf(full_file_name, sizeof(full_file_name), "%s/%s",
01433              local_profile_path, file_name);
01434     DEBUG_printf("file name: %s\n", full_file_name);
01435 
01436     ret = stat(full_file_name, &file_stat);
01437     if (ret == -1) {
01438         free((char *) local_profile_path);
01439        return 0;
01440     }
01441 
01442     file_size = file_stat.st_size;
01443     if (file_size == 0) {
01444         free((char *) local_profile_path);
01445        return 0;
01446     }
01447 
01448     file_buf = (char *) calloc(1, file_size + 1);
01449     if (file_buf == NULL) {
01450         free((char *) local_profile_path);
01451        return 0;
01452     }
01453 
01454     fd = fopen(full_file_name, "r");
01455     if (!fd) {
01456         free((char *) local_profile_path);
01457        free((char *) file_buf);
01458        return 0;
01459     }
01460 
01461     fread((char *) file_buf, file_size, 1, fd);
01462     file_buf[file_size] = 0;
01463 
01464     free((char *) local_profile_path);
01465     fclose(fd);
01466 
01467     *ptr = file_buf;
01468     *len = file_size + 1;
01469 
01470     return 1;
01471 }
01472 
01473 int property_data_write_memory_to_file(char *file_name, char *ptr, int len)
01474 {
01475     char full_file_name[256];
01476     char *local_profile_path;
01477 
01478     FILE *fd;
01479 
01480     if (file_name == NULL || ptr == NULL || len == 0)
01481         return 0;
01482 
01483     /* read profile from file to memory buffer  */
01484     local_profile_path = (char *)property_data_get_local_profile_path(1);
01485     if (local_profile_path == NULL)
01486         return 0;
01487 
01488     snprintf(full_file_name, sizeof(full_file_name), "%s/%s",
01489              local_profile_path, file_name);
01490     DEBUG_printf("file name: %s\n", full_file_name);
01491 
01492     fd = fopen(full_file_name, "wb");
01493     if (!fd) {
01494        DEBUG_printf("unable open the file: %s\n", full_file_name);
01495         free((char *) local_profile_path);
01496        return 0;
01497     }
01498 
01499     fprintf(fd, "%s\n", ptr);
01500     fclose(fd);
01501 
01502     free((char *) local_profile_path);
01503     return 1;
01504 }
01505 
01506 int property_data_read_from_profile(property_data_t *property_data, int save_mode)
01507 {
01508     char *str = NULL;
01509     int  len;
01510 
01511     if (property_data == NULL)
01512         return 0;
01513 
01514     if (save_mode == PROPERTY_DATA_FOR_LOCAL_PROFILE ||
01515         save_mode == PROPERTY_DATA_FOR_ALL) {
01516         property_data_read_file_to_memory(LOCAL_PERFERENCE_PROFILE_NAME, &str, &len);
01517         if (str != NULL) {
01518             property_data_parse_from_xmlstr(property_data, str, len);
01519             free ((char *)str);
01520             str = NULL;
01521         }
01522     }
01523 
01524     if (save_mode == PROPERTY_DATA_FOR_IME_CONFIG ||
01525         save_mode == PROPERTY_DATA_FOR_ALL) {
01526         property_data_read_file_to_memory(IME_CONFIG_PROFILE_NAME, &str, &len);
01527         if (str != NULL) {
01528             property_data_parse_from_xmlstr(property_data, str, len);
01529             free ((char *)str);
01530             str = NULL;
01531         }
01532     }
01533 
01534     return 1;
01535 }
01536 
01537 int property_data_save_to_profile(property_data_t *property_data, int save_mode)
01538 {
01539     char *property_info_str = NULL;
01540 
01541     if (property_data == NULL)
01542         return 0;
01543 
01544     if (save_mode == PROPERTY_DATA_FOR_LOCAL_PROFILE ||
01545         save_mode == PROPERTY_DATA_FOR_ALL) {
01546         property_info_str = (char *) property_data_composite_local_perference_to_xmlstr(property_data);
01547         if (property_info_str != NULL) {
01548             property_data_write_memory_to_file(LOCAL_PERFERENCE_PROFILE_NAME,
01549                                                property_info_str,
01550                                                strlen(property_info_str));
01551         }
01552     }
01553 
01554     if (save_mode == PROPERTY_DATA_FOR_IME_CONFIG ||
01555         save_mode == PROPERTY_DATA_FOR_ALL) {
01556         property_info_str = (char *) property_data_composite_le_settings_to_xmlstr(property_data,
01557            PROPERTY_DATA_FOR_LOCAL_PROFILE);
01558         if (property_info_str != NULL) {
01559             property_data_write_memory_to_file(IME_CONFIG_PROFILE_NAME,
01560                                                property_info_str,
01561                                                strlen(property_info_str));
01562         }
01563     }
01564 
01565     return 1;
01566 }