[mythtv] [PATCH] View log entries in System Status (Update1)

Chris Pinkham cpinkham at bc2va.org
Thu Sep 2 01:20:56 EDT 2004


> Attached patch should address these issues
> 
> Kevin

Couple questions/comments about the logs and status screen.

I think that the LogEnabled setting in globalsettings.cpp should probably
inherit from BackendSetting instead of GlobalSetting.   GlobalSetting
isn't really Global, it applies only to the frontend that you set it on.
If you don't run the frontend setup on a backend then that backend
won't log even if you turned logging on on the frontend.  Making this
a BackendSetting would truly make it global between all frontends and
backends and all event logging would be turned ON/OFF by the one
setting.

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.

-- 

Chris

-------------- next part --------------
Index: statusbox.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/statusbox.h,v
retrieving revision 1.1
diff -u -r1.1 statusbox.h
--- statusbox.h	19 Aug 2004 01:23:04 -0000	1.1
+++ statusbox.h	2 Sep 2004 05:06:58 -0000
@@ -29,6 +29,7 @@
     void doListingsStatus();
     void doTunerStatus();
     void doDVBStatus();
+    void doJobQueueStatus();
     void doLogEntries();
     void clicked();
     void setHelpText();
@@ -41,6 +42,12 @@
     LayerSet *selector, *topbar, *content;
 
     int max_icons;
+
+    bool inContent;
+    int contentTotalLines;
+    int contentSize;
+    int contentPos;
+    QMap<int, QString> contentLines;
 };
 
 #endif
Index: statusbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/statusbox.cpp,v
retrieving revision 1.1
diff -u -r1.1 statusbox.cpp
--- statusbox.cpp	19 Aug 2004 01:23:04 -0000	1.1
+++ statusbox.cpp	2 Sep 2004 05:06:58 -0000
@@ -14,6 +14,7 @@
 #include "mythcontext.h"
 #include "remoteutil.h"
 #include "programinfo.h"
+#include "jobqueue.h"
 #include "tv.h"
 
 StatusBox::StatusBox(MythMainWindow *parent, const char *name)
@@ -21,17 +22,24 @@
 {
     // Set this value to the number of items in icon_list
     // to prevent scrolling off the bottom
-    max_icons = 3;
+    max_icons = 5;
 
     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(0, QObject::tr("Listings Status"));
+    icon_list->SetItemText(1, QObject::tr("Tuner Status"));
+    icon_list->SetItemText(2, QObject::tr("DVB Status"));
+    icon_list->SetItemText(3, QObject::tr("Job Queue"));
+    icon_list->SetItemText(4, QObject::tr("Log Entries"));
     icon_list->SetItemCurrent(0);
     icon_list->SetActive(true);
+
+    inContent = false;
+    contentPos = 0;
+    contentTotalLines = 0;
+    contentSize = 0;
+    clicked();
 }
 
 void StatusBox::paintEvent(QPaintEvent *e)
@@ -57,6 +65,14 @@
     if (content  == NULL) return;
     LayerSet *container = content;
 
+    list_area->ResetList();
+    for (int x = contentPos; (x - contentPos) <= contentSize; x++)
+        if (contentLines.contains(x))
+            list_area->SetItemText(x - contentPos, contentLines[x]);
+
+    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);
@@ -213,21 +229,64 @@
 
         if (action == "SELECT")
         {
-            clicked();
+            if (!inContent)
+                clicked();
         }
         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 - contentSize))
+                    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))
+        {
+            clicked();
+            inContent = true;
+            contentPos = 0;
+            icon_list->SetActive(false);
+            list_area->SetActive(true);
             update(SelectRect);
+            update(ContentRect);
+        }
+        else if ((action == "LEFT") && (inContent))
+        {
+            inContent = false;
+            contentPos = 0;
+            list_area->SetActive(false);
+            icon_list->SetActive(true);
+            update(SelectRect);
+            update(ContentRect);
         }
         else
             handled = false;
@@ -243,16 +302,19 @@
     switch (icon_list->GetCurrentItem())
     {
         case 0:
-            helptext->SetText("Listings Status shows the latest status information from mythfilldatabase");
+            helptext->SetText(QObject::tr("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");
+            helptext->SetText(QObject::tr("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");
+            helptext->SetText(QObject::tr("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");
+            helptext->SetText(QObject::tr("The Job Queue is used by Myth for things such as Transcoding and Commercial Flagging"));
+            break;
+        case 4:
+            helptext->SetText(QObject::tr("Log Entries shows any unread log entries from the system if you have logging enabled"));
             break;
     }
     update(TopRect);
@@ -264,6 +326,7 @@
     // I'm sure there's a better way to do this but I can't find it
     content->ClearAllText();
     list_area->ResetList();
+    contentLines.clear();
 
     switch (icon_list->GetCurrentItem())
     {
@@ -277,6 +340,9 @@
             doDVBStatus();
             break;
         case 3:
+            doJobQueueStatus();
+            break;
+        case 4:
             doLogEntries();
             break;
     }
@@ -366,6 +432,8 @@
     }
    
     text_area->SetText(Status);
+    contentSize = 0;
+    contentTotalLines = 0;
     update(ContentRect);
 }
 
@@ -376,9 +444,11 @@
     QString querytext = QString("SELECT cardid FROM capturecard;");
     QSqlDatabase *db = QSqlDatabase::database();
     QSqlQuery query = db->exec(querytext);
+
+    contentLines.clear();
+
     if (query.isActive() && query.numRowsAffected())
     {
-        list_area->ResetList();
         while(query.next())
         {
             int cardid = query.value(0).toInt();
@@ -398,8 +468,7 @@
             else 
                 Status += "is not recording";
 
-            list_area->SetItemText(count, Status);
-            count++;
+            contentLines[count++] = Status;
 
             if (strlist[0].toInt()==kState_RecordingOnly)
             {
@@ -411,15 +480,17 @@
    
                 Status = "   ";
                 Status += proginfo->title;
-                list_area->SetItemText(count++, Status);
+                contentLines[count++] = Status;
 
                 Status = "   ";
                 Status += proginfo->subtitle;
                 if (Status != "   ")
-                    list_area->SetItemText(count++, Status);
+                    contentLines[count++] = Status;
             }
         }
     }
+    contentTotalLines = count;
+    contentSize = list_area->GetItems();
     update(ContentRect);
 }
 
@@ -472,7 +543,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 +564,135 @@
     }
 
     text_area->SetText(Status);
+    contentSize = 0;
+    contentTotalLines = 0;
+    update(ContentRect);
+}
+
+void StatusBox::doJobQueueStatus()
+{
+    QMap<int, JobQueueEntry> jobs;
+    QMap<int, JobQueueEntry>::Iterator it;
+    QString lastchanid = "";
+    QDateTime laststarttime = QDateTime::currentDateTime();
+    int count = 0;
+
+    QString timeDateFormat;
+    QString line;
+    QSqlDatabase *db = QSqlDatabase::database();
+
+    timeDateFormat = gContext->GetSetting("TimeFormat", "h:mm AP") + " " +
+                     gContext->GetSetting("ShortDateFormat", "M/d");
+
+    JobQueue::GetJobsInQueue(db, jobs);
+
+    contentLines.clear();
+
+    if (jobs.size())
+    {
+        contentLines[count++] = QObject::tr("Current Jobs In Queue") + ":";
+        contentLines[count++] = QString("------------------------------------");
+
+        for (it = jobs.begin(); it != jobs.end(); ++it)
+        {
+            QString chanid = it.data().chanid;
+            QDateTime starttime = it.data().starttime;
+            ProgramInfo *pginfo;
+
+            pginfo = ProgramInfo::GetProgramFromRecorded(db, chanid, starttime);
+
+            if (!pginfo)
+                continue;
+
+            if ((lastchanid != chanid) ||
+                (laststarttime != starttime))
+            {
+                line = pginfo->title;
+                contentLines[count++] = line;
+
+                line = "      " + pginfo->channame + " " + pginfo->chanstr +
+                               " @ " + starttime.toString(timeDateFormat);
+                contentLines[count++] = line;
+            }
+
+            line = "      " + JobQueue::JobText(db, it.data().type) + " -> " +
+                   JobQueue::StatusText(it.data().status);
+            contentLines[count++] = line;
+
+            if (it.data().status != JOB_QUEUED)
+            {
+                line = "      ";
+                if (it.data().hostname == "")
+                    line += QObject::tr("master");
+                else
+                    line += it.data().hostname;
+                line += ":";
+                contentLines[count++] = line;
+            }
+
+			if (it.data().comment != "")
+            {
+                line = "          " + it.data().comment;
+                contentLines[count++] = line;
+            }
+
+            lastchanid = chanid;
+            laststarttime = starttime;
+
+            delete pginfo;
+        }
+    }
+    else
+    {
+        contentLines[count++] = QObject::tr("Job Queue is currently empty.");
+    }
+
+    contentTotalLines = count;
+    contentSize = list_area->GetItems();
     update(ContentRect);
 }
 
 void StatusBox::doLogEntries(void)
 {
-/*
-    // int minlevel = gContext->GetNumSetting("LogDefaultView",0);
+    // minlevel = gContext->GetNumSetting("LogDefaultView",0);
     int minlevel = 8;
+    QString timeDateFormat;
+    QString line;
+    int count = 0;
+
+    // minlevel = gContext->GetNumSetting("LogDefaultView",0);
+    timeDateFormat = gContext->GetSetting("TimeFormat", "h:mm AP") + " " +
+                     gContext->GetSetting("ShortDateFormat", "M/d");
+
+    contentLines.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(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()));
-*/
+        {
+            line = query.value(3).toDateTime().toString(timeDateFormat) + 
+                   " on " + query.value(4).toString();
+            contentLines[count++] = line;
+
+            line = "    " + query.value(5).toString();
+            contentLines[count++] = line;
+        }
+    }
+
+	if (!count)
+        contentLines[count++] = QObject::tr("Log is currently empty.");
+
+    contentTotalLines = count;
+    contentSize = list_area->GetItems();
+    update(ContentRect);
 }
 
 StatusBox::~StatusBox(void)


More information about the mythtv-dev mailing list