Parse control info tag
#61
another thing to keep in mind is that this has to be performed every frame, for every label control or fadelabel control, so any solution that is finalized must be as optimal as possible.

i agree that less complexity is better, and can't really think of any useful scenarios in which the more complicated one is necessary that can't be overcome with using 2 or more label controls.

cheers,
jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#62
(kraqh3d @ may 19 2005,14:40 Wrote:i'll check out why the localized strings arent added to the output string. an append is probably missing someplace Smile

i dont understand why cant you have both.  the $if is a new control type.  anything without an $if should be subjected to the old rules.  

anyway, i think this is overkill and unwarranted.

no, it's not a missing append, the code just sucks a littleSmile
i'll see if i can find a way to incoorporate both rules.

d.

-edit-
oh well .. nm.. see if u can fix the localize.. i hate to swap solutions back nd forth.. nd i don't use conditional stuff myself nyway.. since i just have everything tagged properlySmile
Image
Reply
#63
i _think_ this should fix the localize issue:

Quote:cstdstring cguicontrol::parselabel(cstdstring &strlabel)
{
 cstdstring tostring = l"";
 cstdstring queuestring = l"";
 int lastpos = 0;
 bool lastvalid = true;

 //look for parsable item
 int t = strlabel.find('$');
 //while a parsable item is found
 while ( t>=0 )
 {

   int skip = 0;
   cstdstring checkescape = l"";
   //read next char
   if (t+1 < (int)strlabel.length())
   {
     checkescape = strlabel.substr(t+1,1);
   }

   bool emptyinfo = false;
   //check if it's not a $, if it is then escape
   if (!checkescape.equals("$"))
   {
     //write all text since the last parsable item till this one to the literal text queue
     if (t > lastpos)
     {
       cstdstring tempstring = strlabel.substr(lastpos,t-lastpos);
       //replace escaped char
       tempstring.replace("$$","$");
       queuestring.append(tempstring.c_str());
     }
     cstdstring replacestring = l"";

     int startdata = strlabel.find('(',t);
     int enddata = strlabel.find(')',t);
     //look for value delimiters
     if (startdata > t && enddata > startdata)
     {

       cstdstring strtype = strlabel.substr(t+1,(startdata - t)-1);
       cstdstring strvalue = strlabel.substr(startdata+1,(enddata - startdata)-1);

       //if valid delimiters are found try to parse them
       strtype = strtype.tolower();
       if (strtype.equals("info"))
       {
         int info = g_infomanager.translatestring(strvalue);
         if (info)
         {
           replacestring = g_infomanager.getlabel(info);
           emptyinfo = (replacestring.length() == 0);
         }
         lastpos = enddata +1;
         skip = (enddata - t);
       }
       else if (strtype.equals("localize"))
       {
         //check if it's a valid number
         if (cutil::isnaturalnumber(strvalue))
         {
           int localize = atoi(strvalue);
           if (localize)
           {
             //if a localized string is found add it to the literal text queue
             cstdstring localizestring = g_localizestrings.get(localize);
             queuestring.append(localizestring.c_str());
           }
           lastpos = enddata +1;
           skip = (enddata - t);
         }
       }
     }
     // we have a valid infoitem
     if (replacestring.length() > 0)
     {
       //if there is text in the queue write it
       if (queuestring.length() > 0)
       {
         tostring.append(queuestring.c_str());
       }
       //empty literal text queue string
       queuestring = l"";

       //now write info string
       tostring.append(replacestring.c_str());
       lastvalid = true;
     }
     else if (emptyinfo)
     {
       //clear the queue
       queuestring = l"";
       lastvalid = false;
     }

   }
   else
   {
     skip = 1;
   }
   if (t+skip < (int)strlabel.length())
   {
     //try to find the next one
     t = strlabel.find('$',t+skip + 1);
   }
   else
   {
     //past end of line, stop searching
     t = -1;
   }
 }
 //if any text was leftover after the last parsable tag, add it to the literal text queue
 if (lastpos < (int)strlabel.length())
 {
   cstdstring tempstring = strlabel.substr(lastpos,(int)strlabel.length()-lastpos);
   tempstring.replace("$$","$");
   queuestring.append(tempstring.c_str());
 }
 //if the last info item was valid, append the literal text queue to the result string
 if (lastvalid && queuestring.length() > 0)
 {
   tostring.append(queuestring.c_str());
 }
 return tostring;
}
Image
Reply
#64
does you code allow for prefix and suffix text to be conditionally shown?

i redid the parselabel so it works like this.

you must have everything you want parsed in curly brackets. if there is not a matching pair of brackets, it doesn't parse it. if there is a least one pair, it will ignore anything outside of a pair. i did this to streamline the code. it forces more strict skinning, but it's probably better.

example: {it is }{$info(weather.conditions)outside and }{$info(weather.temperature)}

if weather.conditions was blank for example, it would return:
it is 55f (with the degree sign)

the conditional values control everything in there block. i just need to clean it up and do some more testing. if you think you might use this then i'll finish it. i could see a real benefit for the fadelabel.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#65
but if weather.temperature would be blank it would still write 'outside and ' at the end... which would be rather meaningless.
for a perfect solution you _will_ have to incorporate conditional expressions... but as the devs consider it getting too complex and i don't use it myelf i will not continue on that path.
Image
Reply
#66
you're right.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#67
ok, i have it working like the following:

all info must be enclosed in {}. any text in with an $info() tag, will be dependent on there being info.

<label>{album: $info(musicplayer.album)}{ by }{$info(musicplayer.artist)}</label>

you notice the { by }, if there are no $info() tags then that block relies on both sides having info.

i'll clean it up and test more with $localize().
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#68
if you would have:

<label>{album: $info(musicplayer.album)}{, by }{$info(musicplayer.artist)}{, in the year }{$info(musicplayer.year)}</label>

and artist is not available, it will concat album and year info without delimiters
Image
Reply
#69
thanks. that fix worked. the localized strings now are visible when appropiate.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#70
:nuts: why can't people tag things correctly.

well it isn't perfect, but it does give some control to the skinner and would work for simple strings. probablt isn't worth it though.

oh well.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#71
(nuka1195 @ may 20 2005,13:51 Wrote::nuts:  why can't people tag things correctly.

well it isn't perfect, but it does give some control to the skinner and would work for simple strings. probablt isn't worth it though.

oh well.
it's not always a matter of tagging... if you play shoutcast streams or for example a wav file a lot of info is missing. i usually only play fully tagged mp3's so for me there is no need for conditionality at all.
Image
Reply
#72
was this ever finalized Huh

if so, could a dev tell me what we got in cvs at the moment and how it works ? this whole thread is very confusing
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#73
sorry, ive been away for a few weeks. this has been in cvs for a while without the fancy conditionals. to concatentate infotags and localized strings you need to use control words which are parsed by the label control -- $localize() and $info(). anything else is assumed to be text.

the example from the changelog is:

<label>$localize(171) $info(musicplayer.artist)</label>

this will produce (in english):

artist: u2

missing fields in the middle will result in text seperators getting removed similar to how the tag formatting works in my music.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#74
just squashed another bug in this, and have just realized this is being called for every label, every frame.

this seems a little wasteful.

perhaps a way around it would be to have it setup in the <info> tag, and if the <info> tag is not parsed (in guicontrolfactory::create()) to a number, have it as an additional string variable.

the label control then just needs to check this variable at render time, and only processes the parselabel() code (which mayaswell go in the infomanager) when it needs it.

thoughts?

edit: not really wasteful at all, as only labels with $ in them actually get parsed!

cheers,
jonathan



Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#75
so you've fixed it so that only labels using the special tags are parsed? i can add this information to the new skinning page about label controls:

http://manual.xboxmediacenter.de/wakka.p....&v=13st
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply

Logout Mark Read Team Forum Stats Members Help
Parse control info tag0