[mythtv] [PATCH] View log entries in System Status (Update2)
Kevin Kuphal
kuphal at dls.net
Sat Sep 4 01:40:49 EDT 2004
Kevin Kuphal wrote:
> Chris Pinkham wrote:
>
>> For displaying the log in the status screen. I have been sitting on
>> some
>> code which enables scrolling in this screen by basically keeping an
>> array (QMap<int,QString> really) of lines to be displayed. The various
>> do*Status() methods would simply fill in the QMap and the scrolling code
>> is generic and just keeps track of what portion of the QMap is actually
>> being displayed in the on-screen list. This works for things that
>> can't be created using a simple query like you have for the logs.
>> Do you think that something like this might be more flexible than the
>> current way you have the scrolling implemented? I wrote my patch
>> because
>> I needed to have a scrolling list for the Job Queue status to show what
>> jobs were currently running, pending, etc.. I haven't committed the
>> Job Queue patch to CVS yet, so the statusbox changes aren't there
>> either.
>> Attached is the diff to current CVS of my statusbox.h and statusbox.cpp
>> files. Can you take a look at how I implemented the scrolling and see
>> if it might be more flexible to adding new status lists in the future.
>> If so, you could merge in my scrolling changes to your tree and
>> resubmit the log patch and I can get that in CVS then I can take my
>> Job Queue status changes and merge them in when I commit the Job Queue
>> itself. I'm open to ideas, but want to see if we can make adding in
>> a new scrolling status list easy so we don't to recode large
>> portions of statusbox.cpp.
>>
>> I like the way you made the iconlist more dynamic rather than having all
>> those case statements hard-coded which made it harder to add any new
>> items
>> unless they were at the end.
>
> I like it alot. I'll see about getting the scrolling part working
> with my changes and resubmit. Thanks!
>
Chris,
Here is my updated patch incorporating your QMap changes. I also added
something so that there is a doScroll option that each content function
can set that will control whether the content scrolls as you had it or
highlights an entry and keeps the selection centered as I need to for
the logging. If you could check this over and make sure I didn't break
anything in that respect, I'd appreciate it. If you can give me the
heads up, I'll repost this in a new thread so Isaac can find it better.
Oh, and I also added so that the tuner detail is now show in the text
area like the log detail is rather than on multiple lines in the list.
Thanks again,
Kevin
-------------- next part --------------
Index: mythtv/libs/libmyth/uitypes.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/uitypes.h,v
retrieving revision 1.57
diff -n -u -r1.57 uitypes.h
--- mythtv/libs/libmyth/uitypes.h 19 Aug 2004 10:19:15 -0000 1.57
+++ mythtv/libs/libmyth/uitypes.h 4 Sep 2004 05:34:46 -0000
@@ -381,6 +381,7 @@
void Draw(QPainter *, int drawlayer, int);
bool ShowSelAlways() const { return m_showSelAlways; }
void ShowSelAlways(bool bnew) { m_showSelAlways = bnew; }
+ bool isActive() { return m_active; }
private:
//QString cutDown(QString, QFont *, int);
int m_selheight;
Index: mythtv/programs/mythfrontend/statusbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/statusbox.cpp,v
retrieving revision 1.1
diff -n -u -r1.1 statusbox.cpp
--- mythtv/programs/mythfrontend/statusbox.cpp 19 Aug 2004 01:23:04 -0000 1.1
+++ mythtv/programs/mythfrontend/statusbox.cpp 4 Sep 2004 05:34:47 -0000
@@ -21,17 +21,32 @@
{
// Set this value to the number of items in icon_list
// to prevent scrolling off the bottom
- max_icons = 3;
+ int item_count = 0;
+ dateFormat = gContext->GetSetting("ShortDateFormat", "M/d");
+ timeFormat = gContext->GetSetting("TimeFormat", "h:mm AP");
setNoErase();
LoadTheme();
- icon_list->SetItemText(0, "Listings Status");
- icon_list->SetItemText(1, "Tuner Status");
- icon_list->SetItemText(2, "DVB Status");
- // icon_list->SetItemText(3, "Log Entries");
+ icon_list->SetItemText(item_count++, QObject::tr("Listings Status"));
+ icon_list->SetItemText(item_count++, QObject::tr("Tuner Status"));
+#ifdef USING_DVB
+ if (gContext->GetNumSetting("DVBMonitorInterval", 0))
+ icon_list->SetItemText(item_count++, "DVB Status");
+#endif
+ icon_list->SetItemText(item_count++, QObject::tr("Log Entries"));
icon_list->SetItemCurrent(0);
icon_list->SetActive(true);
+
+ max_icons = item_count;
+ inContent = false;
+ contentPos = 0;
+ contentTotalLines = 0;
+ contentSize = 0;
+ contentMid = 0;
+ min_level = gContext->GetNumSetting("LogDefaultView",1);
+ my_parent = parent;
+ clicked();
}
void StatusBox::paintEvent(QPaintEvent *e)
@@ -53,10 +68,51 @@
pix.fill(this, pr.topLeft());
QPainter tmp(&pix);
QPainter p(this);
+
+ // In order to maintain a center scrolling highlight, we need to determine the point at which
+ // to start the content list so that the current item is in the center
+ int startPos = 0;
+ if (contentPos > contentMid)
+ startPos = contentPos - contentMid;
if (content == NULL) return;
LayerSet *container = content;
+ // If the content position is beyond the midpoint and before the end
+ // or if the content is first being displayed, write the content using
+ // the offset we determined above. If we are before the midpoint or
+ // close to the end, we stop moving the content up or down to let the
+ // hightlight move up and down with fixed content
+ if (((contentPos > contentMid) && (contentPos <= (contentTotalLines - contentMid))) || (contentPos == 0))
+ {
+ list_area->ResetList();
+ for (int x = startPos; (x - startPos) <= contentSize; x++)
+ if (contentLines.contains(x))
+ list_area->SetItemText(x - startPos, contentLines[x]);
+ }
+
+ // If we are scrolling, the determine the item to highlight
+ if (doScroll)
+ {
+ if (contentPos < contentMid)
+ list_area->SetItemCurrent(contentPos);
+
+ if (contentPos >= contentMid)
+ list_area->SetItemCurrent(contentMid);
+
+ if (contentPos > (contentTotalLines - contentMid))
+ list_area->SetItemCurrent(contentSize - (contentTotalLines - contentPos));
+
+ if ((contentDetail[contentPos] != "") || (contentPos > 0))
+ {
+ helptext->SetText(contentDetail[contentPos]);
+ update(TopRect);
+ }
+ }
+
+ list_area->SetUpArrow(contentPos > 0);
+ list_area->SetDownArrow((contentPos + contentSize) < contentTotalLines);
+
container->Draw(&tmp, 0, 0);
container->Draw(&tmp, 1, 0);
container->Draw(&tmp, 2, 0);
@@ -215,21 +271,158 @@
{
clicked();
}
+ else if (action == "MENU")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ int retval = MythPopupBox::show2ButtonPopup(my_parent, QString("AckLogEntry"),
+ QString("Acknowledge all log entries at this priority level or lower?"), QString("Yes"),
+ QString("No"), 0);
+ if (retval == 0)
+ {
+ QString query = QString("UPDATE mythlog SET acknowledged = 1 where priority <= %1").arg(min_level);
+ QSqlDatabase *db = QSqlDatabase::database();
+ db->exec(query);
+ doLogEntries();
+ }
+ }
+ }
else if (action == "UP")
{
- if (icon_list->GetCurrentItem() > 0)
- icon_list->SetItemCurrent(icon_list->GetCurrentItem()-1);
- setHelpText();
- update(SelectRect);
+ if (inContent)
+ {
+ if (contentPos > 0)
+ contentPos--;
+ update(ContentRect);
+ }
+ else
+ {
+ if (icon_list->GetCurrentItem() > 0)
+ icon_list->SetItemCurrent(icon_list->GetCurrentItem()-1);
+ clicked();
+ setHelpText();
+ update(SelectRect);
+ }
+
}
else if (action == "DOWN")
{
- if (icon_list->GetCurrentItem() < (max_icons - 1))
- icon_list->SetItemCurrent(icon_list->GetCurrentItem()+1);
- setHelpText();
+ if (inContent)
+ {
+ if (contentPos < (contentTotalLines - 1))
+ contentPos++;
+ update(ContentRect);
+ }
+ else
+ {
+ if (icon_list->GetCurrentItem() < (max_icons - 1))
+ icon_list->SetItemCurrent(icon_list->GetCurrentItem()+1);
+ clicked();
+ setHelpText();
+ update(SelectRect);
+ }
+ }
+ else if ((action == "RIGHT") &&
+ (!inContent) &&
+ ((contentTotalLines > contentSize) || (doScroll)))
+ {
+ clicked();
+ inContent = true;
+ contentPos = 0;
+ icon_list->SetActive(false);
+ list_area->SetActive(true);
update(SelectRect);
+ update(ContentRect);
}
- else
+ else if ((action == "LEFT") && (inContent))
+ {
+ inContent = false;
+ contentPos = 0;
+ list_area->SetActive(false);
+ icon_list->SetActive(true);
+ update(SelectRect);
+ update(ContentRect);
+ }
+ else if (action == "1")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 1;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "2")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 2;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "3")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 3;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "4")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 4;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "5")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 5;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "6")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 6;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "7")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 7;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ }
+ else if (action == "8")
+ {
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+ {
+ min_level = 8;
+ helptext->SetText(QObject::tr("Setting priority level to %1").arg(min_level));
+ update(TopRect);
+ doLogEntries();
+ }
+ } else
handled = false;
}
@@ -239,46 +432,69 @@
void StatusBox::setHelpText()
{
- topbar->ClearAllText();
- switch (icon_list->GetCurrentItem())
+ if (inContent)
{
- case 0:
- helptext->SetText("Listings Status shows the latest status information from mythfilldatabase");
- break;
- case 1:
- helptext->SetText("Tuner Status shows the current information about the state of backend tuner cards");
- break;
- case 2:
- helptext->SetText("DVB Status shows the quality statistics of all DVB cards, if present");
- break;
- case 3:
- helptext->SetText("Log Entries shows any unread log entries from the system if you have logging enabled");
- break;
+ helptext->SetText(contentDetail[contentPos]);
+ } else {
+ topbar->ClearAllText();
+ QString current_item = icon_list->GetItemText(icon_list->GetCurrentItem());
+
+ if (current_item == "Listings Status")
+ helptext->SetText(QObject::tr("Listings Status shows the latest status information from mythfilldatabase"));
+
+ if (current_item == "Tuner Status")
+ helptext->SetText(QObject::tr("Tuner Status shows the current information about the state of backend tuner cards"));
+
+#ifdef USING_DVB
+ if (current_item == "DVB Status")
+ helptext->SetText(QObject::tr("DVB Status shows the quality statistics of all DVB cards, if present"));
+#endif
+
+ if (current_item == "Log Entries")
+ helptext->SetText(QObject::tr("Log Entries shows any unread log entries from the system if you have logging enabled"));
}
update(TopRect);
}
void StatusBox::clicked()
{
- // Clear all visible content elements here
- // I'm sure there's a better way to do this but I can't find it
- content->ClearAllText();
- list_area->ResetList();
-
- switch (icon_list->GetCurrentItem())
+ if ((inContent) && (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
{
- case 0:
+ int retval = MythPopupBox::show2ButtonPopup(my_parent, QString("AckLogEntry"),
+ QString("Acknowledge this log entry?"), QString("Yes"),
+ QString("No"), 0);
+ if (retval == 0)
+ {
+ QString query = QString("UPDATE mythlog SET acknowledged = 1 where logid = %1")
+ .arg(logID[contentPos]);
+ QSqlDatabase *db = QSqlDatabase::database();
+ db->exec(query);
+ doLogEntries();
+ }
+ } else {
+ // Clear all visible content elements here
+ // I'm sure there's a better way to do this but I can't find it
+ content->ClearAllText();
+ list_area->ResetList();
+ contentLines.clear();
+ contentDetail.clear();
+ logID.clear();
+
+ QString current_item = icon_list->GetItemText(icon_list->GetCurrentItem());
+
+ if (current_item == "Listings Status")
doListingsStatus();
- break;
- case 1:
+
+ if (current_item == "Tuner Status")
doTunerStatus();
- break;
- case 2:
+
+#ifdef USING_DVB
+ if (current_item == "DVB Status")
doDVBStatus();
- break;
- case 3:
+#endif
+
+ if (current_item == "Log Entries")
doLogEntries();
- break;
}
}
@@ -366,19 +582,25 @@
}
text_area->SetText(Status);
+ contentSize = 0;
+ contentTotalLines = 0;
update(ContentRect);
}
void StatusBox::doTunerStatus()
{
int count = 0;
+ doScroll = true;
QString querytext = QString("SELECT cardid FROM capturecard;");
QSqlDatabase *db = QSqlDatabase::database();
QSqlQuery query = db->exec(querytext);
+
+ contentLines.clear();
+ contentDetail.clear();
+
if (query.isActive() && query.numRowsAffected())
{
- list_area->ResetList();
while(query.next())
{
int cardid = query.value(0).toInt();
@@ -398,8 +620,8 @@
else
Status += "is not recording";
- list_area->SetItemText(count, Status);
- count++;
+ contentLines[count] = Status;
+ contentDetail[count] = Status;
if (strlist[0].toInt()==kState_RecordingOnly)
{
@@ -409,26 +631,28 @@
ProgramInfo *proginfo = new ProgramInfo;
proginfo->FromStringList(strlist, 0);
- Status = " ";
- Status += proginfo->title;
- list_area->SetItemText(count++, Status);
-
- Status = " ";
+ Status = proginfo->title;
+ Status += "\n";
Status += proginfo->subtitle;
- if (Status != " ")
- list_area->SetItemText(count++, Status);
+ contentDetail[count] = Status;
}
+ count++;
}
}
+ contentTotalLines = count;
+ contentSize = list_area->GetItems();
+ if (contentSize > contentTotalLines)
+ contentSize = contentTotalLines;
+ contentMid = contentSize / 2;
update(ContentRect);
}
+#ifdef USING_DVB
void StatusBox::doDVBStatus(void)
{
QString querytext;
-
bool doneAnything = false;
-
+
QString Status = QString("Details of DVB error statistics for last 48 hours:\n");
QString outerqry =
@@ -472,7 +696,7 @@
while (query.next())
{
- Status += QString("Encoder %1 Min SNR: %2 Avg SNR: %3 Min BER %4 Avg BER %5 Cont Errs: %6 Overflows: %7\n")
+ Status += QString("Encoder %1 Min SNR: %2 Avg SNR: %3 Min BER %4 Avg BER %5 Cont Errs: %6 Overflows: %7\n")
.arg(query.value(0).toInt())
.arg(query.value(5).toInt())
.arg(query.value(6).toInt())
@@ -493,25 +717,75 @@
}
text_area->SetText(Status);
+ contentSize = 0;
+ contentTotalLines = 0;
update(ContentRect);
}
+#endif
void StatusBox::doLogEntries(void)
{
-/*
- // int minlevel = gContext->GetNumSetting("LogDefaultView",0);
- int minlevel = 8;
+ QString timeDateFormat;
+ QString line;
+ int count = 0;
+
+ doScroll = true;
+
+ timeDateFormat = gContext->GetSetting("TimeFormat", "h:mm AP") + " " +
+ gContext->GetSetting("ShortDateFormat", "M/d");
+
+ contentLines.clear();
+ contentDetail.clear();
+ logID.clear();
- log_list->clear();
QSqlDatabase *db = QSqlDatabase::database();
- QString thequery = QString("SELECT logid, module, priority, logdate, host, message, "
- "details FROM mythlog WHERE acknowledged = 0 and priority <= %1 "
- "order by logdate").arg(minlevel);
+ QString thequery;
+
+ thequery = QString("SELECT logid, module, priority, logdate, host, "
+ "message, details "
+ "FROM mythlog WHERE acknowledged = 0 AND priority <= %1 "
+ "ORDER BY logdate DESC;").arg(min_level);
QSqlQuery query = db->exec(thequery);
if (query.isActive())
+ {
while (query.next())
- log_list->insertItem(QString("%1 %2").arg(query.value(3).toString()).arg(query.value(5).toString()));
-*/
+ {
+ line = QString("%1").arg(query.value(5).toString());
+ contentLines[count] = line;
+
+ if (query.value(6).toString() != "")
+ line = QString("On %1 %2 from %3.%4\n%5\n%6")
+ .arg(query.value(3).toDateTime().toString(dateFormat))
+ .arg(query.value(3).toDateTime().toString(timeFormat))
+ .arg(query.value(4).toString())
+ .arg(query.value(1).toString())
+ .arg(query.value(5).toString())
+ .arg(query.value(6).toString());
+ else line = QString("On %1 %2 from %3.%4\n%5\nNo other details")
+ .arg(query.value(3).toDateTime().toString(dateFormat))
+ .arg(query.value(3).toDateTime().toString(timeFormat))
+ .arg(query.value(4).toString())
+ .arg(query.value(1).toString())
+ .arg(query.value(5).toString());
+ contentDetail[count] = line;
+ logID[count++] = query.value(0).toString();
+ }
+ }
+
+ if (!count)
+ {
+ contentLines[count++] = QObject::tr("No items found at this priority level or lower.");
+ contentLines[count++] = QObject::tr("Push RIGHT and then");
+ contentLines[count++] = QObject::tr("use 1-8 to change priority level.");
+ }
+
+
+ contentTotalLines = count;
+ contentSize = list_area->GetItems();
+ if (contentSize > contentTotalLines)
+ contentSize = contentTotalLines;
+ contentMid = contentSize / 2;
+ update(ContentRect);
}
StatusBox::~StatusBox(void)
Index: mythtv/programs/mythfrontend/statusbox.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/statusbox.h,v
retrieving revision 1.1
diff -n -u -r1.1 statusbox.h
--- mythtv/programs/mythfrontend/statusbox.h 19 Aug 2004 01:23:04 -0000 1.1
+++ mythtv/programs/mythfrontend/statusbox.h 4 Sep 2004 05:34:47 -0000
@@ -29,6 +29,7 @@
void doListingsStatus();
void doTunerStatus();
void doDVBStatus();
+ void doJobQueueStatus();
void doLogEntries();
void clicked();
void setHelpText();
@@ -41,6 +42,20 @@
LayerSet *selector, *topbar, *content;
int max_icons;
+
+ bool inContent, doScroll;
+ int contentTotalLines;
+ int contentSize;
+ int contentPos;
+ int contentMid;
+ int min_level;
+ QString dateFormat, timeFormat;
+
+ QMap<int, QString> contentLines;
+ QMap<int, QString> contentDetail;
+ QMap<int, QString> logID;
+
+ MythMainWindow *my_parent;
};
#endif
Index: mythtv/themes/default/status-ui.xml
===================================================================
RCS file: /var/lib/mythcvs/mythtv/themes/default/status-ui.xml,v
retrieving revision 1.1
diff -n -u -r1.1 status-ui.xml
--- mythtv/themes/default/status-ui.xml 19 Aug 2004 01:23:04 -0000 1.1
+++ mythtv/themes/default/status-ui.xml 4 Sep 2004 05:34:48 -0000
@@ -28,6 +28,12 @@
<bold>yes</bold>
</font>
+ <font name="status_selected" face="Arial">
+ <color>#ffff33</color>
+ <size>16</size>
+ <bold>yes</bold>
+ </font>
+
<container name="topbar">
<area>0,0,800,200</area>
<textarea name="heading" draworder="0">
@@ -36,7 +42,7 @@
<value>System Status - Select a category to view the status</value>
</textarea>
<textarea name="helptext" draworder="0">
- <area>30,60,760,80</area>
+ <area>30,60,760,120</area>
<font>title</font>
<value>This screen show the status of various system components</value>
<multiline>yes</multiline>
@@ -68,10 +74,10 @@
<container name="content">
<area>265,201,535,600</area>
<listarea name="list_area" draworder="2">
- <area>15,20,490,395</area>
+ <area>15,20,490,345</area>
<fcnfont name="status" function="active"></fcnfont>
<fcnfont name="status" function="inactive"></fcnfont>
- <fcnfont name="status" function="selected"></fcnfont>
+ <fcnfont name="status_selected" function="selected"></fcnfont>
<column number="1" width="490" context="-1"></column>
<items>12</items>
</listarea>
More information about the mythtv-dev
mailing list