00001
00002 #include "mythuiclock.h"
00003
00004 #include <QCoreApplication>
00005 #include <QDomDocument>
00006
00007 #include "mythpainter.h"
00008 #include "mythmainwindow.h"
00009 #include "mythfontproperties.h"
00010
00011 #include "mythcorecontext.h"
00012 #include "mythlogging.h"
00013 #include "mythdb.h"
00014
00015 MythUIClock::MythUIClock(MythUIType *parent, const QString &name)
00016 : MythUIText(parent, name)
00017 {
00018 m_DateFormat = GetMythDB()->GetSetting("DateFormat", "ddd d MMMM");
00019 m_ShortDateFormat = GetMythDB()->GetSetting("ShortDateFormat", "ddd d");
00020 m_TimeFormat = GetMythDB()->GetSetting("TimeFormat", "hh:mm");
00021
00022 m_Format = QString("%1, %2").arg(m_DateFormat).arg(m_TimeFormat);
00023
00024 m_Flash = false;
00025 }
00026
00027 MythUIClock::~MythUIClock()
00028 {
00029 delete m_Font;
00030 m_Font = NULL;
00031 }
00032
00036 void MythUIClock::Pulse(void)
00037 {
00038 m_Time = QDateTime::currentDateTime();
00039
00040 if (m_nextUpdate.isNull() || (m_Time >= m_nextUpdate))
00041 MythUIText::SetText(GetTimeText());
00042
00043 MythUIText::Pulse();
00044 }
00045
00053 QString MythUIClock::GetTimeText(void)
00054 {
00055 QString newMsg = gCoreContext->GetQLocale().toString(m_Time, m_Format);
00056
00057 m_nextUpdate = m_Time.addSecs(1);
00058 m_nextUpdate = QDateTime(
00059 m_Time.date(), m_Time.time().addMSecs(m_Time.time().msec()));
00060
00061 return newMsg;
00062 }
00063
00067 void MythUIClock::SetText(const QString &text)
00068 {
00069 QString txt = text;
00070
00071 if (txt.isEmpty())
00072 {
00073 m_Time = QDateTime::currentDateTime();
00074 txt = GetTimeText();
00075 }
00076
00077 MythUIText::SetText(txt);
00078 }
00079
00083 bool MythUIClock::ParseElement(
00084 const QString &filename, QDomElement &element, bool showWarnings)
00085 {
00086 if (element.tagName() == "format" ||
00087 element.tagName() == "template")
00088 {
00089 QString format = parseText(element);
00090 format = qApp->translate("ThemeUI", format.toUtf8(), NULL,
00091 QCoreApplication::UnicodeUTF8);
00092 format.replace("%TIME%", m_TimeFormat, Qt::CaseInsensitive);
00093 format.replace("%DATE%", m_DateFormat, Qt::CaseInsensitive);
00094 format.replace("%SHORTDATE%", m_ShortDateFormat, Qt::CaseInsensitive);
00095 m_Format = format;
00096 m_Message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_Format);
00097 }
00098 else
00099 {
00100 m_Message = gCoreContext->GetQLocale().toString(QDateTime::currentDateTime(), m_Format);
00101 return MythUIText::ParseElement(filename, element, showWarnings);
00102 }
00103
00104 return true;
00105 }
00106
00110 void MythUIClock::CopyFrom(MythUIType *base)
00111 {
00112 MythUIClock *clock = dynamic_cast<MythUIClock *>(base);
00113
00114 if (!clock)
00115 {
00116 LOG(VB_GENERAL, LOG_ERR, "ERROR, bad parsing");
00117 return;
00118 }
00119
00120 m_Time = clock->m_Time;
00121 m_nextUpdate = clock->m_nextUpdate;
00122
00123 m_Format = clock->m_Format;
00124 m_TimeFormat = clock->m_TimeFormat;
00125 m_DateFormat = clock->m_DateFormat;
00126 m_ShortDateFormat = clock->m_ShortDateFormat;
00127
00128 m_Flash = clock->m_Flash;
00129
00130 MythUIText::CopyFrom(base);
00131 }
00132
00136 void MythUIClock::CreateCopy(MythUIType *parent)
00137 {
00138 MythUIClock *clock = new MythUIClock(parent, objectName());
00139 clock->CopyFrom(this);
00140 }
00141