Back to index

im-sdk  12.3.91
Functions
hotkey_config.c File Reference
#include "unit_input.h"

Go to the source code of this file.

Functions

IMKeyEventStructparseKey (xmlDocPtr, xmlNodePtr)
IMHotkeyStructparseHotkey (xmlDocPtr, xmlNodePtr)
IMHotkeyProfileStructparseHotkeyProfile (xmlDocPtr, xmlNodePtr)
IMHotkeyManagerStructparse_hotkey_config_file (IMLEName *, char *)
void printHotkeyManager (IMHotkeyManagerStruct *)
int get_key_value (char *)

Function Documentation

int get_key_value ( char *  )

Definition at line 1093 of file unit_input.c.

                                {
    int i;
    for (i = 0; kvp[i].key_name != 0; i++) {
        if(!strcmp(kvp[i].key_name, key_str)){
            return kvp[i].value;
        }
    }
    return 0;
}
IMHotkeyManagerStruct * parse_hotkey_config_file ( IMLEName le_name,
char *  filename 
)

Definition at line 230 of file hotkey_config.c.

{
   IMHotkeyManagerStruct *hkm;
   IMHotkeyProfileStruct *hkp;
   xmlDocPtr doc;
   xmlNodePtr cur;
   int i;

   LIBXML_TEST_VERSION

   xmlKeepBlanksDefault(0);

   /*
    * build an XML tree from the configuration file
    */

   doc = xmlParseFile(filename);
   if (doc == NULL) return(NULL);

   /*
    * Check if the document is of the right kind
    */
   
   cur = xmlDocGetRootElement(doc);
   if (cur == NULL) {
     printf("Empty document ..\n");
     xmlFreeDoc(doc);
     return(NULL);
   }

   /*
    * Allocate the structure to be returned.
    */

   hkm = (IMHotkeyManagerStruct *) calloc(1, sizeof(IMHotkeyManagerStruct));
   if (hkm == NULL) {
     printf("parse_hotkey_config_file: calloc error \n");
     xmlFreeDoc(doc);
     return(NULL);
   }

   /*
    * Now, walk the tree.
    */

   /* First level we expect just le */
   if (!xmlStrcmp(cur->name, (const xmlChar *)"le")) {
     cur = cur->xmlChildrenNode;
   } else {
     printf("Invalid configuration file ..\n");
     xmlFreeDoc(doc);
     return(NULL);
   }
   
   while (cur != NULL) {
     if (!xmlStrcmp(cur->name, (const xmlChar *)"name")) {
       char *le_name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"text") || !xmlStrcmp(cur->name, (const xmlChar *)"comment")) {
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"num_hotkey_profiles")) {
       hkm->num_hotkey_profiles = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       hkm->hkps = (IMHotkeyProfileStruct *)calloc(hkm->num_hotkey_profiles, sizeof(IMHotkeyProfileStruct));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"hotkey_profile")) {
       for (i=0; i<hkm->num_hotkey_profiles; i++) {
         /*
         hkm->hkps[i] = (IMHotkeyProfileStruct *)parseHotkeyProfile(doc, cur);
         */
         hkp = parseHotkeyProfile(doc, cur);
         hkm->hkps[i].profile_id = hkp->profile_id;
         hkm->hkps[i].scope = hkp->scope;
         hkm->hkps[i].name = le_name;
         hkm->hkps[i].num_hotkeys = hkp->num_hotkeys;
         hkm->hkps[i].hks = hkp->hks;
         if (cur)
           cur = cur->next;
       }
     }
   }
  
   return hkm;
}

Here is the call graph for this function:

Here is the caller graph for this function:

IMHotkeyStruct * parseHotkey ( xmlDocPtr  doc,
xmlNodePtr  cur 
)

Definition at line 113 of file hotkey_config.c.

{
   IMHotkeyStruct *hk = NULL;
   IMKeyEventStruct *keys = NULL;
   int i;

   hk = (IMHotkeyStruct *) calloc (1, sizeof(IMHotkeyStruct));
   if (hk == NULL) {
     printf("parseHotkey: calloc error \n");
     return (NULL);
   }

   cur = cur->xmlChildrenNode;
   while (cur != NULL) {
     if (!xmlStrcmp(cur->name, (const xmlChar *)"text") || 
                   !xmlStrcmp(cur->name, (const xmlChar *)"comment")) {
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"id")) {
       /*
       int hk_id = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       */
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"state_flag")) {
       hk->state_flag = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"action_flag")) {
       hk->action_flag = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"label")) {
       hk->label = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"num_keys")) {
       hk->nkeys = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       hk->keys = (IMKeyEventStruct *) calloc(hk->nkeys, sizeof(IMKeyEventStruct));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"key")) {
       for (i=0; i<hk->nkeys; i++) {
         keys = parseKey(doc, cur);
         hk->keys[i].keyCode = keys->keyCode;
         hk->keys[i].modifier = keys->modifier;
         if (cur)
           cur = cur->next;
       }
     }
   }
   return hk;
}

Here is the call graph for this function:

Here is the caller graph for this function:

IMHotkeyProfileStruct * parseHotkeyProfile ( xmlDocPtr  doc,
xmlNodePtr  cur 
)

Definition at line 171 of file hotkey_config.c.

{
   IMHotkeyProfileStruct *hkp = NULL;
   IMHotkeyStruct *hk = NULL;
   int i;

   hkp = (IMHotkeyProfileStruct *) calloc (1, sizeof(IMHotkeyProfileStruct));
   if (hkp == NULL) {
     printf("parseHotkeyProfile: calloc error \n");
     return (NULL);
   }

   cur = cur->xmlChildrenNode;

   while (cur != NULL) {
     if (!xmlStrcmp(cur->name, (const xmlChar *)"id")) {
       hkp->profile_id = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"text") || 
                   !xmlStrcmp(cur->name, (const xmlChar *)"comment")) {
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"scope")) {
       char *scope = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
       if (scope && strstr(scope, "SESSION_SPECIFIC_HOTKEY")) {
         hkp->scope = 1;
       } else if (scope && strstr(scope, "GLOBAL_HOTKEY")) {
         hkp->scope = 0;
       } else
          hkp->scope  = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       free(scope);
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"num_hotkeys")) {
       hkp->num_hotkeys = atoi(xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
       hkp->hks = (IMHotkeyStruct *) calloc(hkp->num_hotkeys, sizeof(IMHotkeyStruct));
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"hotkey")) {
       for (i=0; i<hkp->num_hotkeys; i++) {
         hk = parseHotkey(doc, cur);
         hkp->hks[i].label = hk->label;
         hkp->hks[i].state_flag = hk->state_flag;
         hkp->hks[i].action_flag = hk->action_flag;
         hkp->hks[i].nkeys = hk->nkeys;
         hkp->hks[i].keys = hk->keys;
         if (cur)
           cur = cur->next;
       }
     }
   }
   return hkp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

IMKeyEventStruct * parseKey ( xmlDocPtr  doc,
xmlNodePtr  cur 
)

Definition at line 53 of file hotkey_config.c.

{
   IMKeyEventStruct *key;

   key = (IMKeyEventStruct *) calloc (1, sizeof(IMKeyEventStruct));
   if (key == NULL) {
     printf("parseKey: calloc error \n");
     return (NULL);
   }

   cur = cur->xmlChildrenNode;
   while (cur != NULL) {
     if (!xmlStrcmp(cur->name, (const xmlChar *)"text") || 
                   !xmlStrcmp(cur->name, (const xmlChar *)"comment")) {
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"keycode")) {
       char *kc = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
       if (kc && strstr(kc, "IM_")) {
         key->keyCode  = get_key_value(kc);
       } else {
         key->keyCode  = atoi(kc);
       }
       free(kc);
       cur = cur->next;
     }
     if (!xmlStrcmp(cur->name, (const xmlChar *)"modifier")) {
       char *mo = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
       int modifier = 0;
       if (mo && strstr(mo, "IM_")) {
         if (strstr(mo, "IM_SHIFT_MASK")) {
           modifier += 1;
         } 
         if (strstr(mo, "IM_CTRL_MASK")) {
           modifier += 2;
         }  
         if (strstr(mo, "IM_META_MASK")) {
           modifier += 4;
         } 
         if (strstr(mo, "IM_ALT_MASK")) {
           modifier += 8;
         }
         if (strstr(mo, "IM_ALT_GRAPH_MASK")) {
           modifier += 32;
         }
         key->modifier = modifier;
       } else { 
          key->modifier = atoi(mo);
       }
       free(mo); 
       cur = cur->next;
     }
   }
   return key;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 321 of file hotkey_config.c.

{
   int i, j, k;

   printf("\nprintHotkeyManager: num_hotkey_profiles [%d]\n", hkm->num_hotkey_profiles);
   for (i=0; i<hkm->num_hotkey_profiles; i++) {
     printf("\n++++ HOTKEY PROFILE: id [%d]\n", hkm->hkps[i].profile_id);
     printf("++++ scope [%d]\n", hkm->hkps[i].scope);
     printf("++++ num_hotkeys [%d]\n", hkm->hkps[i].num_hotkeys);
     for (j=0; j<hkm->hkps[i].num_hotkeys; j++) {
       printf("\n++++++ HOTKEY: state_flag [%d]\n", hkm->hkps[i].hks[j].state_flag);
       printf("++++++ HOTKEY: action_flag [%d]\n", hkm->hkps[i].hks[j].action_flag);
       printf("++++++ HOTKEY: label [%s]\n", hkm->hkps[i].hks[j].label);
       printf("++++++ HOTKEY: nkeys [%d]\n", hkm->hkps[i].hks[j].nkeys);
       for (k=0; k<hkm->hkps[i].hks[j].nkeys; k++) {
         printf("\n++++++++ KEYS: keyCode [%d]\n", hkm->hkps[i].hks[j].keys[k].keyCode);
         printf("++++++++ KEYS: modifier [%d]\n", hkm->hkps[i].hks[j].keys[k].modifier);
       }
     }
   }
}