00001 #include <qfile.h>
00002 #include <qdir.h>
00003
00004 #include "themeinfo.h"
00005 #include "mythcontext.h"
00006
00007 ThemeInfo::ThemeInfo(QString theme)
00008 {
00009
00010 m_theme = new QFileInfo (theme);
00011 m_name = m_aspect = m_previewpath = m_description = m_errata = "";
00012 m_type = THEME_UNKN;
00013 m_baseres = QSize(800, 600);
00014 m_majorver = m_minorver = 0;
00015
00016 if (!parseThemeInfo())
00017 {
00018
00019
00020
00021
00022 VERBOSE(VB_GENERAL, QString("The theme (%1) is missing a themeinfo.xml file")
00023 .arg(m_theme->fileName()));
00024
00025 m_name = m_theme->fileName();
00026
00027 if (m_name.contains("-wide"))
00028 m_aspect = "16:9";
00029 else
00030 m_aspect = "4:3";
00031
00032 if (QFile::exists(m_theme->absFilePath() + "/theme.xml"))
00033 {
00034 m_type |= THEME_UI;
00035
00036 if (IsWide())
00037 {
00038 m_baseres = QSize(1280, 720);
00039 }
00040 else
00041 {
00042 m_baseres = QSize(800, 600);
00043 }
00044 }
00045
00046 if (QFile::exists(m_theme->absFilePath() + "/osd.xml"))
00047 {
00048 m_type |= THEME_OSD;
00049 m_baseres = QSize(640, 480);
00050 }
00051
00052 if (QFile::exists(m_theme->absFilePath() + "/mainmenu.xml"))
00053 m_type |= THEME_MENU;
00054
00055 m_previewpath = m_theme->absFilePath() + "/preview.jpg";
00056 }
00057 }
00058
00059 ThemeInfo::~ThemeInfo()
00060 {
00061
00062 if (m_theme)
00063 delete m_theme;
00064
00065 }
00066
00067 bool ThemeInfo::parseThemeInfo()
00068 {
00069
00070 QDomDocument doc;
00071
00072 QFile f(m_theme->absFilePath() + "/themeinfo.xml");
00073
00074 if (!f.open(IO_ReadOnly))
00075 {
00076 VERBOSE(VB_FILE, QString("Unable to open themeinfo.xml "
00077 "for %1").arg(m_theme->absFilePath()));
00078 return false;
00079 }
00080
00081 if ( !doc.setContent( &f ) ) {
00082 VERBOSE(VB_IMPORTANT, QString("Unable to parse themeinfo.xml "
00083 "for %1").arg(m_theme->fileName()));
00084 f.close();
00085 return false;
00086 }
00087 f.close();
00088
00089 QDomElement docElem = doc.documentElement();
00090
00091 for (QDomNode n = docElem.firstChild(); !n.isNull();
00092 n = n.nextSibling())
00093 {
00094 QDomElement e = n.toElement();
00095 if (!e.isNull())
00096 {
00097 if (e.tagName() == "name")
00098 {
00099 m_name = e.firstChild().toText().data();
00100 }
00101 else if (e.tagName() == "aspect")
00102 {
00103 m_aspect = e.firstChild().toText().data();
00104 }
00105 else if (e.tagName() == "baseres")
00106 {
00107 QString size = e.firstChild().toText().data();
00108 m_baseres = QSize(size.section('x', 0, 0).toInt(),
00109 size.section('x', 1, 1).toInt());
00110 }
00111 else if (e.tagName() == "types")
00112 {
00113 for (QDomNode child = e.firstChild(); !child.isNull();
00114 child = child.nextSibling())
00115 {
00116 QDomElement ce = child.toElement();
00117 if (!ce.isNull())
00118 {
00119 if (ce.tagName() == "type")
00120 {
00121 QString type = ce.firstChild().toText().data();
00122
00123 if (type == "UI")
00124 {
00125 m_type |= THEME_UI;
00126 }
00127 else if (type == "OSD")
00128 {
00129 m_type |= THEME_OSD;
00130 }
00131 else if (type == "Menu")
00132 {
00133 m_type |= THEME_MENU;
00134 }
00135 else
00136 {
00137 VERBOSE(VB_IMPORTANT, QString("Invalid theme "
00138 "type seen when parsing "
00139 "%2")
00140 .arg(m_theme->fileName()));
00141 }
00142 }
00143 }
00144 }
00145 }
00146 else if (e.tagName() == "version")
00147 {
00148 for (QDomNode child = e.firstChild(); !child.isNull();
00149 child = child.nextSibling())
00150 {
00151 QDomElement ce = child.toElement();
00152 if (!ce.isNull())
00153 {
00154 if (ce.tagName() == "major")
00155 {
00156 m_majorver = ce.firstChild().toText()
00157 .data().toInt();
00158 }
00159 else if (ce.tagName() == "minor")
00160 {
00161 m_minorver = ce.firstChild().toText()
00162 .data().toInt();
00163 }
00164 }
00165 }
00166 }
00167 else if (e.tagName() == "detail")
00168 {
00169 for (QDomNode child = e.firstChild(); !child.isNull();
00170 child = child.nextSibling())
00171 {
00172 QDomElement ce = child.toElement();
00173 if (!ce.isNull())
00174 {
00175 if (ce.tagName() == "thumbnail")
00176 {
00177 if (ce.attribute("name") == "preview")
00178 {
00179 QString thumbnail = ce.firstChild().toText()
00180 .data();
00181 m_previewpath = m_theme->absFilePath() + "/"
00182 + thumbnail;
00183 }
00184 }
00185 else if (ce.tagName() == "description")
00186 {
00187 m_description = ce.firstChild().toText().data();
00188 }
00189 else if (ce.tagName() == "errata")
00190 {
00191 m_errata = ce.firstChild().toText().data();
00192 }
00193 }
00194 }
00195 }
00196 }
00197 }
00198
00199 return true;
00200 }
00201
00202 bool ThemeInfo::IsWide()
00203 {
00204
00205 if (m_aspect == "16:9" || m_aspect == "16:10")
00206 return true;
00207
00208 return false;
00209 }