[mythtv] [PATCH] View log entries in System Status

Kevin Kuphal kuphal at dls.net
Mon Aug 23 02:48:15 EDT 2004


This patch adds the ability to view entries logged to the database 
(MythLog) in the System Status Window.  It also provides this functionality:

- Adds isActive() to UIListType to return if a list is active
- Shows DVB Status only when DVB support is compiled
- Detailed status show now without explicit SELECT when moving up and 
down the category list.  SELECT here will still update the content on 
the right.
- LEFT/RIGHT moves between category list and logged items list when 
appropriate
- 1-8 selects the priority of the log viewing when in the log category
- MENU key will prompt to acknowledge all items at this or lower 
priority when in the log category
- SELECT on an individual item will prompt to acknoweldge it and reset 
the list if acknowledged
- Minor improvements to the UI XML to support these features

I hope my early morning coding didn't leave any bugs outstanding in this 
and hopefully some kind souls might look to add more log entries in the 
system so there is more to view here.

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	23 Aug 2004 06:42:16 -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	23 Aug 2004 06:42:17 -0000
@@ -19,19 +19,27 @@
 StatusBox::StatusBox(MythMainWindow *parent, const char *name)
          : MythDialog(parent, name)
 {
-    // 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++, "Listings Status");
+    icon_list->SetItemText(item_count++, "Tuner Status");
+#ifdef USING_DVB
+    icon_list->SetItemText(item_count++, "DVB Status");
+#endif
+    icon_list->SetItemText(item_count++, "Log Entries");
     icon_list->SetItemCurrent(0);
     icon_list->SetActive(true);
+
+    max_icons = item_count;
+    log_offset = 0;
+    log_query = NULL;
+    min_level = gContext->GetNumSetting("LogDefaultView",1);
+    my_parent = parent;
 }
 
 void StatusBox::paintEvent(QPaintEvent *e)
@@ -200,6 +208,85 @@
     }
 }
 
+void StatusBox::cursorUp()
+{
+    int i = 0;
+
+    if (icon_list->isActive())
+    {
+        if (icon_list->GetCurrentItem() > 0)
+            icon_list->SetItemCurrent(icon_list->GetCurrentItem()-1);
+        setHelpText();
+        update(SelectRect);
+        clicked();
+    }
+    if (list_area->isActive())
+    {
+        if (log_query->at() > 0)
+            log_query->prev();
+        int current_pos = log_query->at();
+                
+        if (current_pos > 5)
+        {
+            if (log_offset > 6)
+            {
+                log_offset--;
+            } else {
+                log_query->seek(current_pos - log_offset - 1);
+                while(log_query->next())
+                    list_area->SetItemText(i++,
+                        QString("%1").arg(log_query->value(5).toString()));
+                log_query->seek(current_pos);
+            }
+        } else {
+            if (log_offset > 0)
+                log_offset--;
+        }
+
+        list_area->SetItemCurrent(log_offset);
+        setHelpText();
+        update(ContentRect);
+    }
+}
+
+void StatusBox::cursorDown()
+{
+    if (icon_list->isActive())
+    {
+        if (icon_list->GetCurrentItem() < (max_icons - 1))
+            icon_list->SetItemCurrent(icon_list->GetCurrentItem()+1);
+        setHelpText();
+        update(SelectRect);
+        clicked();
+    }
+    if (list_area->isActive())
+    {
+        if (log_query->at() < (log_query->size() - 1))
+        {
+            if ((log_offset < 6) || (log_query->size() - log_query->at() < 7))
+                log_offset++;
+
+            log_query->next();
+
+            int current_pos = log_query->at();
+            int i = 0;
+
+            if (current_pos > 6)
+            {
+                log_query->seek(current_pos - log_offset - 1);
+                while(log_query->next())
+                    list_area->SetItemText(i++,
+                        QString("%1").arg(log_query->value(5).toString()));
+            }
+            log_query->seek(current_pos); 
+            list_area->SetItemCurrent(log_offset);
+        }
+
+        setHelpText();
+        update(ContentRect); 
+    }
+}
+
 void StatusBox::keyPressEvent(QKeyEvent *e)
 {
     bool handled = false;
@@ -215,21 +302,116 @@
         {
             clicked();
         }
-        else if (action == "UP")
+        else if (action == "MENU")
         {
-            if (icon_list->GetCurrentItem() > 0)
-                icon_list->SetItemCurrent(icon_list->GetCurrentItem()-1);
-            setHelpText();
-            update(SelectRect);
+            if (list_area->isActive())
+            {
+                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 == "DOWN")
+        else if (action == "LEFT")
         {
-            if (icon_list->GetCurrentItem() < (max_icons - 1))
-                icon_list->SetItemCurrent(icon_list->GetCurrentItem()+1);
-            setHelpText();
+            icon_list->SetActive(true);
+            list_area->SetActive(false);
+            doLogEntries();
             update(SelectRect);
+            update(ContentRect);
         }
-        else
+        else if (action == "RIGHT")
+        {
+            QString current_item = icon_list->GetItemText(icon_list->GetCurrentItem());
+
+            if ((current_item == "Log Entries") && (log_query->isActive() && log_query->isValid()))
+            {
+                icon_list->SetActive(false);
+                list_area->SetActive(true);
+                list_area->SetItemCurrent(0);
+                setHelpText();
+                update(ContentRect);
+                update(SelectRect);
+            }
+        }
+        else if (action == "UP")
+        {
+            cursorUp();
+        }
+        else if (action == "DOWN")
+        {
+            cursorDown();
+        } 
+        else if (action == "1")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 1;
+                doLogEntries();
+            }
+        } 
+        else if (action == "2")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 2;
+                doLogEntries();
+            }
+        } 
+        else if (action == "3")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 3;
+                doLogEntries();
+            }
+        } 
+        else if (action == "4")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 4;
+                doLogEntries();
+            }
+        } 
+        else if (action == "5")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 5;
+                doLogEntries();
+            }
+        } 
+        else if (action == "6")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 6;
+                doLogEntries();
+            }
+        } 
+        else if (action == "7")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 7;
+                doLogEntries();
+            }
+        } 
+        else if (action == "8")
+        {
+            if ((list_area->isActive()) || (icon_list->GetItemText(icon_list->GetCurrentItem()) == "Log Entries"))
+            {
+                min_level = 8;
+                doLogEntries();
+            }
+        } else
             handled = false;
     }
 
@@ -239,46 +421,88 @@
 
 void StatusBox::setHelpText()
 {
-    topbar->ClearAllText();
-    switch (icon_list->GetCurrentItem())
+    if (icon_list->isActive())
     {
-        case 0:
+        topbar->ClearAllText();
+        QString current_item = icon_list->GetItemText(icon_list->GetCurrentItem());
+
+        if (current_item == "Listings Status")
             helptext->SetText("Listings Status shows the latest status information from mythfilldatabase");
-            break;
-        case 1:
+
+        if (current_item == "Tuner Status")
             helptext->SetText("Tuner Status shows the current information about the state of backend tuner cards");
-            break;
-        case 2:
+
+#ifdef USING_DVB
+        if (current_item == "DVB Status")
             helptext->SetText("DVB Status shows the quality statistics of all DVB cards, if present");
-            break;
-        case 3:
+#endif
+
+        if (current_item == "Log Entries")
             helptext->SetText("Log Entries shows any unread log entries from the system if you have logging enabled");
-            break;
     }
+
+    if (list_area->isActive())
+    {
+        if (log_query->value(6).toString() != "")
+            helptext->SetText(QString("On %1 %2 from %3.%4\n%5\n%6")
+                              .arg(log_query->value(3).toDateTime().toString(dateFormat))
+                              .arg(log_query->value(3).toDateTime().toString(timeFormat))
+                              .arg(log_query->value(4).toString())
+                              .arg(log_query->value(1).toString())
+                              .arg(log_query->value(5).toString())
+                              .arg(log_query->value(6).toString()));
+        else helptext->SetText(QString("On %1 %2 from %3.%4\n%5\nNo other details")
+                               .arg(log_query->value(3).toDateTime().toString(dateFormat))
+                               .arg(log_query->value(3).toDateTime().toString(timeFormat))
+                               .arg(log_query->value(4).toString())
+                               .arg(log_query->value(1).toString())
+                               .arg(log_query->value(5).toString()));
+    }
+
     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 (icon_list->isActive())
     {
-        case 0:
+        // Clear all visible content elements here
+        content->ClearAllText();
+        list_area->ResetList();
+
+        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;
+    }
+ 
+    if (list_area->isActive())
+    {
+        int retval = MythPopupBox::show2ButtonPopup(my_parent, QString("AckLogEntry"),
+                                   QString("Acknowledge this log entry?"), QString("Yes"),
+                                   QString("No"), 0);
+        if (retval == 0)
+        {
+            if (log_query->isValid())
+            { 
+                QString query = QString("UPDATE mythlog SET acknowledged = 1 where logid = %1")
+                                .arg(log_query->value(0).toString());
+                QSqlDatabase *db = QSqlDatabase::database();
+                db->exec(query);
+                doLogEntries();
+            }
+        }
     }
 }
 
@@ -423,6 +647,7 @@
     update(ContentRect);
 }
 
+#ifdef USING_DVB
 void StatusBox::doDVBStatus(void)
 {
     QString querytext;
@@ -495,23 +720,30 @@
     text_area->SetText(Status);
     update(ContentRect);
 }
+#endif
 
 void StatusBox::doLogEntries(void)
 {
-/*
-    // int minlevel = gContext->GetNumSetting("LogDefaultView",0);
-    int minlevel = 8;
+    list_area->ResetList();
+    log_offset = 0;
 
-    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);
-    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()));
-*/
+                               "order by logdate").arg(min_level);
+    log_query = new QSqlQuery(db->exec(thequery));
+
+    if (log_query->isActive())
+        while (log_query->next())
+            list_area->SetItemText(log_query->at(),
+                    QString("%1").arg(log_query->value(5).toString()));
+
+    list_area->SetItemCurrent(0);
+    if (log_query->first() == false)
+        list_area->SetItemText(0,"No items found at this priority level or lower");
+    helptext->SetText(QString("Listing priority %1 items").arg(min_level));
+    update(TopRect);
+    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	23 Aug 2004 06:42:17 -0000
@@ -32,6 +32,8 @@
     void doLogEntries();
     void clicked();
     void setHelpText();
+    void cursorUp();
+    void cursorDown();
 
     XMLParse *theme;
     QDomElement xmldata;
@@ -39,8 +41,12 @@
     UITextType *heading, *helptext, *text_area;
     UIListType *icon_list, *list_area;
     LayerSet *selector, *topbar, *content;
+    QSqlQuery *log_query;
 
-    int max_icons;
+    int max_icons, log_offset, min_level;
+    QString dateFormat, timeFormat;
+
+    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	23 Aug 2004 06:42:17 -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