Opened 17 years ago

Closed 16 years ago

#3957 closed defect (fixed)

Missing comma in disk space sizes greater than 1000 MB

Reported by: anonymous Owned by: Isaac Richards
Priority: trivial Milestone: unknown
Component: mythtv Version: head
Severity: low Keywords:
Cc: Ticket locked: no

Description

Mythweb is missing a comma when you have more 1000 MB of total disk space:

Total Disk Space:

  • Total Space: 1054,294 MB

Should read 1,054,294 MB.

Attachments (1)

3957_diff.patch (2.1 KB) - added by Joe Ripley <vitaminjoe@…> 17 years ago.
Patch mythbackend to properly add commas to numbers > 1000 for mythweb status page

Download all attachments as: .zip

Change History (7)

comment:1 Changed 17 years ago by xris

Component: mythwebmythtv
Owner: changed from xris to Isaac Richards

Mythweb should show sizes in GB.. The only place that it does, is on the recordings page. If you're looking at the "backend status" page, that's a direct passthrough from the backend.

comment:2 Changed 17 years ago by Nigel

Following code in programs/mythbackend/httpstatus.cpp is the culprit:

                os << "            <li>Total Space: ";
                sRep.sprintf( "%d,%03d MB ", (nTotal) / 1000, (nTotal) % 1000);
                os << sRep << "</li>\r\n";

                os << "            <li>Space Used: ";
                sRep.sprintf( "%d,%03d MB ", (nUsed) / 1000, (nUsed) % 1000);
                os << sRep << "</li>\r\n";

                os << "            <li>Space Free: ";
                sRep.sprintf( "%d,%03d MB ", (nFree) / 1000, (nFree) % 1000);

Note that the code currently will output bad strings like 0,123MB for small numbers. If there isn't an easy way to do this in Qt, we should probably add a nice formatter in libs/libmyth/util.cpp ?

comment:3 Changed 17 years ago by Joe Ripley <vitaminjoe@…>

This patch fixes it for me. I doubt that this is where you guys would like the formatting code to end up, but, I thought I'd throw it in anyway.

-- Joe Ripley vitaminjoe@…

Changed 17 years ago by Joe Ripley <vitaminjoe@…>

Attachment: 3957_diff.patch added

Patch mythbackend to properly add commas to numbers > 1000 for mythweb status page

comment:4 Changed 17 years ago by Nigel

Thanks for the patch, Joe.
1) Here is an even simpler one:

Index: httpstatus.cpp
===================================================================
--- httpstatus.cpp      (revision 14490)
+++ httpstatus.cpp      (working copy)
@@ -21,6 +21,7 @@
 #include <qfile.h>
 #include <qregexp.h>
 #include <qbuffer.h>
+#include <qlocale.h>
 #include <math.h>
 
 #include "../../config.h"
@@ -1132,16 +1133,17 @@
                     os << nDirs << "</li>\r\n";
                 }
 
+               QLocale c(QLocale::C);
                 os << "            <li>Total Space: ";
-                sRep.sprintf( "%d,%03d MB ", (nTotal) / 1000, (nTotal) % 1000);
+               sRep = c.toString(nTotal) + " MB ";
                 os << sRep << "</li>\r\n";
 
                 os << "            <li>Space Used: ";
-                sRep.sprintf( "%d,%03d MB ", (nUsed) / 1000, (nUsed) % 1000);
+               sRep = c.toString(nUsed) + " MB ";
                 os << sRep << "</li>\r\n";
 
                 os << "            <li>Space Free: ";
-                sRep.sprintf( "%d,%03d MB ", (nFree) / 1000, (nFree) % 1000);
+               sRep = c.toString(nFree) + " MB ";
                 os << sRep << "</li>\r\n";
 
                 os << "          </ul>\r\n"

2) I suspect we shouldn't be anchoring this in MB. It won't be long before most users have Terabytes, and I think a signed long long can represent 1.3 Petabytes. Maybe a generic SI prefix routine?

comment:5 Changed 17 years ago by Joe Ripley <vitaminjoe@…>

Much cleaner! I think I need to review the Qt API. Thanks nigel!

-- Joe Ripley vitaminjoe@…

comment:6 Changed 16 years ago by Nigel

Resolution: fixed
Status: newclosed

(In [15013]) Format disk usage sizes correctly. Closes #3957

Note: See TracTickets for help on using tickets.