[mythtv] [PATCH] OSD regexp substitution

David Engel dlengel at attbi.com
Tue Oct 21 21:29:00 EDT 2003


For awhile now, I've been wanting the program subtitle to be displayed
in quotes before the program description in the OSD.  I finally got
around to digging into that code and the available OSD themes and
found that it can already be done with th %FIELD% style substitution.

Unfortunately, using a line like the one below results in the quotes
and a space showing up before the description when the subtitle is
null.

    <value>"%SUBTITLE%" %DESCRIPTION% (%LENMINS% minutes)</value>

I didn't like this so I added another substitution style.  The syntax
is "%FIELD|prefix|suffix|ifnull%".  If the field is not null, the
prefix and suffix text will be prepended and appended, respectively,
to the field value.  If the field is null, the ifnull text will be
used instead.

With this substitution style, using the line below results in a nice
OSD description field.

    <value>%SUBTITLE|"|"  |%%DESCRIPTION|||No description available.%  (%LENMI
NS% minutes)</value>

The included patch implements this feature.  Comments, especially on a
better syntax, are welcome.  The patch also fixes an issue where
ProgramInfo::ToStringList modifies it's own data when it probably
shouldn't.

David
-- 
David Engel
dlengel at attbi.com

Index: libs/libmythtv/osdtypes.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/osdtypes.cpp,v
retrieving revision 1.34
diff -u -r1.34 osdtypes.cpp
--- libs/libmythtv/osdtypes.cpp	18 Oct 2003 23:40:36 -0000	1.34
+++ libs/libmythtv/osdtypes.cpp	22 Oct 2003 00:57:51 -0000
@@ -244,6 +244,13 @@
                 {
                     full_regex = "%" + riter.key().upper() + "%";
                     new_text.replace(QRegExp(full_regex), riter.data());
+		    full_regex = "%" + riter.key().upper() + 
+		      "\\|([^%|]*)" + "\\|([^%|]*)" + "\\|([^%]*)%";
+		    if (riter.data() != "")
+			new_text.replace(QRegExp(full_regex), 
+					 "\\1" + riter.data() + "\\2");
+		    else
+			new_text.replace(QRegExp(full_regex), "\\3");
                 }
 
             if (new_text != "")
Index: libs/libmythtv/programinfo.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/programinfo.cpp,v
retrieving revision 1.69
diff -u -r1.69 programinfo.cpp
--- libs/libmythtv/programinfo.cpp	13 Aug 2003 15:28:51 -0000	1.69
+++ libs/libmythtv/programinfo.cpp	22 Oct 2003 00:57:51 -0000
@@ -88,56 +88,29 @@
 
 void ProgramInfo::ToStringList(QStringList &list)
 {
-    if (title == "")
-        title = " ";
-    if (subtitle == "")
-        subtitle = " ";
-    if (description == "")
-        description = " ";
-    if (category == "")
-        category = " ";
-    if (pathname == "")
-        pathname = " ";
-    if (hostname == "")
-        hostname = " ";
-    if (chanid == "")
-        chanid = " ";
-    if (chanstr == "")
-        chanstr = " ";
-    if (chansign == "")
-        chansign = " ";
-    if (channame == "")
-        channame = " ";
-    if (pathname == "")
-        pathname = " ";
-    if (rank == "")
-        rank = " ";
-    if (reasonsuppressed == "")
-        reasonsuppressed = " ";
-
-    list << title;
-    list << subtitle;
-    list << description;
-    list << category;
-    list << chanid;
-    list << chanstr;
-    list << chansign;
-    list << channame;
-    list << pathname;
+    list << ((title != "") ? title : " ");
+    list << ((subtitle != "") ? subtitle : " ");
+    list << ((description != "") ? description : " ");
+    list << ((category != "") ? category : " ");
+    list << ((chanid != "") ? chanid : " ");
+    list << ((chanstr != "") ? chanstr : " ");
+    list << ((chansign != "") ? chansign : " ");
+    list << ((channame != "") ? channame : " ");
+    list << ((pathname != "") ? pathname : " ");
     encodeLongLong(list, filesize);
     list << startts.toString(Qt::ISODate);
     list << endts.toString(Qt::ISODate);
     list << QString::number(conflicting);
     list << QString::number(recording);
     list << QString::number(duplicate);
-    list << hostname;
+    list << ((hostname != "") ? hostname : " ");
     list << QString::number(sourceid);
     list << QString::number(cardid);
     list << QString::number(inputid);
-    list << rank;
+    list << ((rank != "") ? rank : " ");
     list << QString::number(suppressed);
-    list << reasonsuppressed;
+    list << ((reasonsuppressed != "") ? reasonsuppressed : " ");
 }
 
 void ProgramInfo::FromStringList(QStringList &list, int offset)


More information about the mythtv-dev mailing list