static void
config_handle_key_tag(MBKeyboardConfigState *state, const char **attr)
{
  const char *val;
  DBG("got key");

  state->current_key = mb_kbd_key_new(state->keyboard);

  if ((val = attr_get_val("obey-caps", attr)) != NULL)
    {
      if (strcaseeq(val, "true"))
	mb_kbd_key_set_obey_caps(state->current_key, True);
    }

  if ((val = attr_get_val("extended", attr)) != NULL)
    {
      if (strcaseeq(val, "true"))
	mb_kbd_key_set_extended(state->current_key, True);
    }

  if ((val = attr_get_val("width", attr)) != NULL)
    {
      if (atoi(val) > 0)
	mb_kbd_key_set_req_uwidth(state->current_key, atoi(val));
    }

  if ((val = attr_get_val("fill", attr)) != NULL)
    {
      if (strcaseeq(val, "true"))
	mb_kbd_key_set_fill(state->current_key, True);
    }

  mb_kbd_row_append_key(state->current_row, state->current_key);
}
Example #2
0
static int plain_write_attrs(const char *filename, const attrs_type&attributes)
{
    FILE       *  accountfile;
    t_hlist    *  curr;
    t_attr     *  attr;
    char const *  key;
    char const *  val;

    if (!(accountfile = fopen(filename,"w"))) {
        eventlog(eventlog_level_error, __FUNCTION__, "unable to open file \"%s\" for writing (fopen: %s)",filename,pstrerror(errno));
        return -1;
    }

    BEGIN(_attr,attributes)
    {
        attr=*_attr;
//   hlist_for_each(curr, attributes) {
//		attr = hlist_entry(curr, t_attr, link);


        if (attr_get_key(attr))
            key = escape_chars(attr_get_key(attr),strlen(attr_get_key(attr)));
        else {
            eventlog(eventlog_level_error, __FUNCTION__, "attribute with NULL key in list");
            key = NULL;
        }

        if (attr_get_val(attr))
            val = escape_chars(attr_get_val(attr),strlen(attr_get_val(attr)));
        else {
            eventlog(eventlog_level_error, __FUNCTION__, "attribute with NULL val in list");
            val = NULL;
        }

        if (key && val) {
            if (strncmp("BNET\\CharacterDefault\\", key, 20) == 0) {
                eventlog(eventlog_level_debug, __FUNCTION__, "skipping attribute key=\"%s\"",attr->key.c_str());
            } else {
                eventlog(eventlog_level_debug, __FUNCTION__, "saving attribute key=\"%s\" val=\"%s\"",attr->key.c_str(),attr->val.c_str());
                fprintf(accountfile,"\"%s\"=\"%s\"\n",key,val);
            }
        } else eventlog(eventlog_level_error, __FUNCTION__,"could not save attribute key=\"%s\"",attr->key.c_str());

        if (key) xfree((void *)key); /* avoid warning */
        if (val) xfree((void *)val); /* avoid warning */

        attr_clear_dirty(attr);
    }
Example #3
0
static int cdb_write_attrs(const char *filename, const attrs_type&attributes)
{
    FILE           *cdbfile;
    t_hlist	   *curr;
    t_attr         *attr;
    struct cdb_make cdbm;

    if ((cdbfile = fopen(filename, "w+b")) == NULL) {
	eventlog(eventlog_level_error, __FUNCTION__, "unable to open file \"%s\" for writing ",filename);
	return -1;
    }

    cdb_make_start(&cdbm, cdbfile);

	BEGIN(_attr,attributes)
	{
		attr=*_attr;
//    hlist_for_each(curr,attributes) {
//	attr = hlist_entry(curr, t_attr, link);

	if (attr_get_key(attr) && attr_get_val(attr)) {
	    if (strncmp("BNET\\CharacterDefault\\", attr_get_key(attr), 20) == 0) {
		eventlog(eventlog_level_debug, __FUNCTION__, "skipping attribute key=\"%s\"",attr_get_key(attr));
	    } else {
		eventlog(eventlog_level_debug, __FUNCTION__, "saving attribute key=\"%s\" val=\"%s\"",attr_get_key(attr),attr_get_val(attr));
		if (cdb_make_add(&cdbm, attr_get_key(attr), strlen(attr_get_key(attr)), attr_get_val(attr), strlen(attr_get_val(attr)))<0)
		{
		    eventlog(eventlog_level_error, __FUNCTION__, "got error on cdb_make_add ('%s' = '%s')", attr_get_key(attr), attr_get_val(attr));
		    cdb_make_finish(&cdbm); /* try to bail out nicely */
		    fclose(cdbfile);
		    return -1;
		}
	    }
	} else eventlog(eventlog_level_error, __FUNCTION__,"could not save attribute key=\"%s\"",attr_get_key(attr));

	attr_clear_dirty(attr);
    }
static void
config_handle_layout_tag(MBKeyboardConfigState *state, const char **attr)
{
  const char            *val;

  if ((val = attr_get_val("id", attr)) == NULL)
    {
      set_error(state, "Attribute 'id' is required");
      return;
    }

  state->current_layout = mb_kbd_layout_new(state->keyboard, val);

  mb_kbd_add_layout(state->keyboard, state->current_layout);
}
static void
config_handle_key_subtag(MBKeyboardConfigState *state,
			 const char            *tag,
			 const char           **attr)
{
  MBKeyboardKeyStateType keystate;
  const char            *val;
  KeySym                 found_keysym;

  /* TODO: Fix below with a lookup table 
   */
  if (streq(tag, "normal") || streq(tag, "default"))
    {
      keystate = MBKeyboardKeyStateNormal;
    }
  else if (streq(tag, "shifted"))
    {
      keystate = MBKeyboardKeyStateShifted;
    }
  else if (streq(tag, "mod1"))
    {
      keystate = MBKeyboardKeyStateMod1;
    }
  else if (streq(tag, "mod2"))
    {
      keystate = MBKeyboardKeyStateMod2;
    }
  else if (streq(tag, "mod3"))
    {
      keystate = MBKeyboardKeyStateMod3;
    }
  else
    {
      set_error(state, "Unknown key subtag");
      return;
    }

  if ((val = attr_get_val("display", attr)) == NULL)
    {
      set_error(state, "Attribute 'display' is required");
      return;
    }

  if (!strncmp(val, "image:", 6))
    {
      MBKeyboardImage *img;


      if (val[6] != '/')
	{
	  /* Relative, rather than absolute path, try pkddatadir and home */
	  char buf[512];
	  snprintf(buf, 512, "%s/%s", PKGDATADIR, &val[6]);

	  if (!util_file_readable(buf))
	    snprintf(buf, 512, "%s/.matchbox/%s", getenv("HOME"), &val[6]);

	  img = mb_kbd_image_new (state->keyboard, buf);
	}
      else
	img = mb_kbd_image_new (state->keyboard, &val[6]);

      if (!img)
	{
	  fprintf(stderr, "matchbox-keyboard: Failed to load '%s'\n", &val[6]);
	  state->error = True;
	  return;
	}
      mb_kbd_key_set_image_face(state->current_key, keystate, img);
    }
  else
    {
      mb_kbd_key_set_glyph_face(state->current_key, keystate, 
				attr_get_val("display", attr));
    }

  if ((val = attr_get_val("action", attr)) != NULL)
    {
      /*
	     action="utf8char"     // optional, action defulats to this    
	     action="modifier:Shift|Alt|ctrl|mod1|mod2|mod3|caps"
	     action="xkeysym:XK_BLAH"
	     action="control:">    // return etc - not needed use lookup 
      */

      if (!strncmp(val, "modifier:", 9))
	{
	  MBKeyboardKeyModType found_type;

	  DBG("checking '%s'", &val[9]);

	  found_type = config_str_to_modtype(&val[9]);

	  if (found_type)
	    {
	      mb_kbd_key_set_modifer_action(state->current_key,
					    keystate,
					    found_type);
	    }
	  else
	    {
              set_error(state, "Unknown modifier");
	      return;
	    }
	  
	}
      else if (!strncmp(val, "xkeysym:", 8))
	{
	  DBG("Checking %s\n", &val[8]);

	  found_keysym = XStringToKeysym(&val[8]);

	  if (found_keysym)
	    {
	      mb_kbd_key_set_keysym_action(state->current_key, 
					   keystate,
					   found_keysym);
	    }
	  else 
	    {
	      /* Should this error really be terminal */
              set_error(state, "Unknown keysym");
	      return;
	    }
	}
      else
	{
	  /* Its just 'regular' key  */

	  if (strlen(val) > 1  	/* match backspace, return etc */
	      && ((found_keysym  = config_str_to_keysym(val)) != 0))
	    {
	      mb_kbd_key_set_keysym_action(state->current_key, 
					   keystate,
					   found_keysym);
	    }
	  else
	    {
	      /* XXX We should actually check its a single UTF8 Char here */
	      mb_kbd_key_set_char_action(state->current_key, 
					 keystate, val);
	    }
	}
    }
  else /* fallback to reusing whats displayed  */
    {

      /* display could be an image in which case we should throw an error 
       * or summin.
      */

      mb_kbd_key_set_char_action(state->current_key, 
				 keystate, 
				 attr_get_val("display", attr));
    }

}
static void
config_xml_start_cb(void *data, const char *tag, const char **attr)
{
  MBKeyboardConfigState *state = (MBKeyboardConfigState *)data;

  if (streq(tag, "layout"))
    {
      config_handle_layout_tag(state, attr);
    }
  else if (streq(tag, "row"))
    {
      config_handle_row_tag(state, attr);
    }
  else if (streq(tag, "key"))
    {
      config_handle_key_tag(state, attr);
    }
  else  if (streq(tag, "space"))
    {
      config_handle_key_tag(state, attr);
      mb_kbd_key_set_blank(state->current_key, True);
    }
  else if (streq(tag, "normal")
	   || streq(tag, "default")
	   || streq(tag, "shifted")
	   || streq(tag, "caps")
	   || streq(tag, "mod1")
	   || streq(tag, "mod2")
	   || streq(tag, "mod3"))
    {
      config_handle_key_subtag(state, tag, attr);
    }
  else  if (streq(tag, "include"))
    {
      const char *val;
      const char *loc;
      char       *inc;
      int         autoloc = 1;

      if (!(val = attr_get_val("file", attr)))
        return;
      else
        {
          char *p;

          inc = strdup (val);
          if ((p = strstr (inc, ".xml")))
            *p = 0;
        }

      if ((loc = attr_get_val("auto-locale", attr)) &&
          streq(loc, "no"))
        autoloc = 0;

      load_include (state, inc, autoloc);
    }
  else  if (streq(tag, "fragment"))
    {
      /* Do nothing; the fragment element is needed so that the fragments
         are a valid xml */
    }

  if (state->error)
    {
      fprintf(stderr, "matchbox-keyboard:%s:%d: %s\n", state->keyboard->config_file,
                                              state->error_lineno, state->error_msg);
      util_fatal_error("Error parsing\n");
    }
}