Ticket #4278: 0001-Return-the-storage-group-data-using-a-more-sensible-.patch

File 0001-Return-the-storage-group-data-using-a-more-sensible-.patch, 6.7 KB (added by Andrew Ruthven <andrew@…>, 16 years ago)
  • mythtv/programs/mythbackend/httpstatus.cpp

    From 0691ebad9ca7d834170894b2a6c01cc22b73d54d Mon Sep 17 00:00:00 2001
    From: Andrew Ruthven <puck@catalyst.net.nz>
    Date: Thu, 6 Dec 2007 09:34:35 +1300
    Subject: [PATCH] Return the storage group data using a more sensible XML approach.
    
    ---
     mythtv/programs/mythbackend/httpstatus.cpp |  133 ++++++++++++++--------------
     1 files changed, 67 insertions(+), 66 deletions(-)
    
    diff --git a/mythtv/programs/mythbackend/httpstatus.cpp b/mythtv/programs/mythbackend/httpstatus.cpp
    index 06e2f39..4938aa9 100644
    a b void HttpStatus::FillStatusXML( QDomDocument *pDoc ) 
    326326    long long iTotal = -1, iUsed = -1, iAvail = -1;
    327327
    328328    BackendQueryDiskSpace(strlist, m_pEncoders, true, m_bIsMaster);
     329    QDomElement total;
    329330
    330331    QStringList::iterator sit = strlist.begin();
    331332    while (sit != strlist.end())
    void HttpStatus::FillStatusXML( QDomDocument *pDoc ) 
    339340        iUsed      = decodeLongLong(strlist, sit);
    340341        iAvail     = iTotal - iUsed;
    341342
    342         if (fsID == "-2")
     343        if (fsID == "-2") {
    343344            fsID = "total";
     345        }
    344346
    345         if (ids == "")
    346             ids = fsID;
    347         else
    348             ids = ids + "," + fsID;
     347        QDomElement group = pDoc->createElement("Group");
    349348
    350         storage.setAttribute("drive_" + fsID + "_total", (int)(iTotal>>10));
    351         storage.setAttribute("drive_" + fsID + "_used" , (int)(iUsed>>10));
    352         storage.setAttribute("drive_" + fsID + "_free" , (int)(iAvail>>10));
    353         storage.setAttribute("drive_" + fsID + "_dirs" , directory);
     349        group.setAttribute("id"   , fsID );
     350        group.setAttribute("total", (int)(iTotal>>10) );
     351        group.setAttribute("used" , (int)(iUsed>>10)  );
     352        group.setAttribute("free" , (int)(iAvail>>10) );
     353        group.setAttribute("dir"  , directory );
     354
     355        // Make sure that the total is always the last element.
     356        if (fsID == "total") {
     357            total = group;
     358        } else {
     359            storage.appendChild(group);
     360        }
    354361    }
    355  
    356     storage.setAttribute("fsids", ids);
    357362
     363    storage.appendChild(total);
     364 
    358365    // load average ---------------------
    359366
    360367    double rgdAverages[3];
    int HttpStatus::PrintMachineInfo( QTextStream &os, QDomElement info ) 
    10851092    }
    10861093
    10871094    // local drive space   ---------------------
    1088    
    10891095    node = info.namedItem( "Storage" );
     1096    QDomElement storage = node.toElement();
     1097    node = storage.firstChild();
    10901098
    1091     if (!node.isNull())
    1092     {   
    1093         QDomElement e = node.toElement();
     1099    os << "      Disk Usage:<br />\r\n";
     1100    os << "      <ul>\r\n";
    10941101
    1095         if (!e.isNull())
     1102
     1103    while (!node.isNull())
     1104    {
     1105        QDomElement g = node.toElement();
     1106
     1107        if (!g.isNull() && g.tagName() == "Group")
    10961108        {
    1097             QString ids = e.attribute("fsids", "");
    1098             QStringList tokens = QStringList::split(",", ids);
     1109            int nFree    = g.attribute("free" , "0" ).toInt();
     1110            int nTotal   = g.attribute("total", "0" ).toInt();
     1111            int nUsed    = g.attribute("used" , "0" ).toInt();
     1112            QString nDir = g.attribute("dir"  , "" );
     1113            QString id   = g.attribute("id"   , "" );
    10991114
    1100             os << "      Disk Usage:<br />\r\n";
    1101             os << "      <ul>\r\n";
     1115            nDir.replace(QRegExp(","), ", ");
    11021116
    1103             for (unsigned int i = 0; i < tokens.size(); i++)
     1117
     1118            if (id == "total")
    11041119            {
    1105                 // For a single-directory installation just display the totals
    1106                 if ((tokens.size() == 2) && (i == 0) &&
    1107                     (tokens[i] != "total") &&
    1108                     (tokens[i+1] == "total"))
    1109                     i++;
    1110 
    1111                 int nFree =
    1112                     e.attribute("drive_" + tokens[i] + "_free" , "0" ).toInt();
    1113                 int nTotal =
    1114                     e.attribute("drive_" + tokens[i] + "_total", "0" ).toInt();
    1115                 int nUsed =
    1116                     e.attribute("drive_" + tokens[i] + "_used" , "0" ).toInt();
    1117                 QString nDirs =
    1118                     e.attribute("drive_" + tokens[i] + "_dirs" , "" );
    1119 
    1120                 nDirs.replace(QRegExp(","), ", ");
    1121 
    1122                 if (tokens[i] == "total")
    1123                 {
    1124                     os << "        <li>Total Disk Space:\r\n"
    1125                        << "          <ul>\r\n";
    1126                 }
     1120                os << "        <li>Total Disk Space:</li>\r\n"
     1121                << "          <ul>\r\n";
     1122            }
     1123            else
     1124            {
     1125                os << "        <li>MythTV Drive #" << id << ":"
     1126                << "</li>\r\n"
     1127                << "          <ul>\r\n";
     1128
     1129                if (nDir.contains(","))
     1130                    os << "            <li>Directories: ";
    11271131                else
    1128                 {
    1129                     os << "        <li>MythTV Drive #" << tokens[i] << ":"
    1130                        << "\r\n<br />\r\n";
     1132                    os << "            <li>Directory: ";
    11311133
    1132                     if (nDirs.contains(","))
    1133                         os << "          <ul><li>Directories: ";
    1134                     else
    1135                         os << "          <ul><li>Directory: ";
     1134                os << nDir << "</li>\r\n";
     1135            }
    11361136
    1137                     os << nDirs << "</li>\r\n";
    1138                 }
     1137            QLocale c(QLocale::C);
    11391138
    1140                 QLocale c(QLocale::C);
    1141                 os << "            <li>Total Space: ";
    1142                 sRep = c.toString(nTotal) + " MB ";
    1143                 os << sRep << "</li>\r\n";
     1139            os << "            <li>Total Space: ";
     1140            sRep = c.toString(nTotal) + " MB";
     1141            os << sRep << "</li>\r\n";
    11441142
    1145                 os << "            <li>Space Used: ";
    1146                 sRep = c.toString(nUsed) + " MB ";
    1147                 os << sRep << "</li>\r\n";
     1143            os << "            <li>Space Used: ";
     1144            sRep = c.toString(nUsed) + " MB";
     1145            os << sRep << "</li>\r\n";
    11481146
    1149                 os << "            <li>Space Free: ";
    1150                 sRep = c.toString(nFree) + " MB ";
    1151                 os << sRep << "</li>\r\n";
     1147            os << "            <li>Space Free: ";
     1148            sRep = c.toString(nFree) + " MB";
     1149            os << sRep << "</li>\r\n";
     1150
     1151            os << "          </ul>\r\n"
     1152            << "        </li>\r\n";
    11521153
    1153                 os << "          </ul>\r\n"
    1154                    << "        </li>\r\n";
    1155             }
    1156             os << "      </ul>\r\n";
    11571154        }
     1155
     1156        node = node.nextSibling();
    11581157    }
    11591158
     1159    os << "      </ul>\r\n";
     1160
    11601161    // Guide Info ---------------------
    11611162
    11621163    node = info.namedItem( "Guide" );