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 ) |
326 | 326 | long long iTotal = -1, iUsed = -1, iAvail = -1; |
327 | 327 | |
328 | 328 | BackendQueryDiskSpace(strlist, m_pEncoders, true, m_bIsMaster); |
| 329 | QDomElement total; |
329 | 330 | |
330 | 331 | QStringList::iterator sit = strlist.begin(); |
331 | 332 | while (sit != strlist.end()) |
… |
… |
void HttpStatus::FillStatusXML( QDomDocument *pDoc ) |
339 | 340 | iUsed = decodeLongLong(strlist, sit); |
340 | 341 | iAvail = iTotal - iUsed; |
341 | 342 | |
342 | | if (fsID == "-2") |
| 343 | if (fsID == "-2") { |
343 | 344 | fsID = "total"; |
| 345 | } |
344 | 346 | |
345 | | if (ids == "") |
346 | | ids = fsID; |
347 | | else |
348 | | ids = ids + "," + fsID; |
| 347 | QDomElement group = pDoc->createElement("Group"); |
349 | 348 | |
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 | } |
354 | 361 | } |
355 | | |
356 | | storage.setAttribute("fsids", ids); |
357 | 362 | |
| 363 | storage.appendChild(total); |
| 364 | |
358 | 365 | // load average --------------------- |
359 | 366 | |
360 | 367 | double rgdAverages[3]; |
… |
… |
int HttpStatus::PrintMachineInfo( QTextStream &os, QDomElement info ) |
1085 | 1092 | } |
1086 | 1093 | |
1087 | 1094 | // local drive space --------------------- |
1088 | | |
1089 | 1095 | node = info.namedItem( "Storage" ); |
| 1096 | QDomElement storage = node.toElement(); |
| 1097 | node = storage.firstChild(); |
1090 | 1098 | |
1091 | | if (!node.isNull()) |
1092 | | { |
1093 | | QDomElement e = node.toElement(); |
| 1099 | os << " Disk Usage:<br />\r\n"; |
| 1100 | os << " <ul>\r\n"; |
1094 | 1101 | |
1095 | | if (!e.isNull()) |
| 1102 | |
| 1103 | while (!node.isNull()) |
| 1104 | { |
| 1105 | QDomElement g = node.toElement(); |
| 1106 | |
| 1107 | if (!g.isNull() && g.tagName() == "Group") |
1096 | 1108 | { |
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" , "" ); |
1099 | 1114 | |
1100 | | os << " Disk Usage:<br />\r\n"; |
1101 | | os << " <ul>\r\n"; |
| 1115 | nDir.replace(QRegExp(","), ", "); |
1102 | 1116 | |
1103 | | for (unsigned int i = 0; i < tokens.size(); i++) |
| 1117 | |
| 1118 | if (id == "total") |
1104 | 1119 | { |
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: "; |
1127 | 1131 | else |
1128 | | { |
1129 | | os << " <li>MythTV Drive #" << tokens[i] << ":" |
1130 | | << "\r\n<br />\r\n"; |
| 1132 | os << " <li>Directory: "; |
1131 | 1133 | |
1132 | | if (nDirs.contains(",")) |
1133 | | os << " <ul><li>Directories: "; |
1134 | | else |
1135 | | os << " <ul><li>Directory: "; |
| 1134 | os << nDir << "</li>\r\n"; |
| 1135 | } |
1136 | 1136 | |
1137 | | os << nDirs << "</li>\r\n"; |
1138 | | } |
| 1137 | QLocale c(QLocale::C); |
1139 | 1138 | |
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"; |
1144 | 1142 | |
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"; |
1148 | 1146 | |
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"; |
1152 | 1153 | |
1153 | | os << " </ul>\r\n" |
1154 | | << " </li>\r\n"; |
1155 | | } |
1156 | | os << " </ul>\r\n"; |
1157 | 1154 | } |
| 1155 | |
| 1156 | node = node.nextSibling(); |
1158 | 1157 | } |
1159 | 1158 | |
| 1159 | os << " </ul>\r\n"; |
| 1160 | |
1160 | 1161 | // Guide Info --------------------- |
1161 | 1162 | |
1162 | 1163 | node = info.namedItem( "Guide" ); |