[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 02/13: Implement compact format_value for most monitors

noreply at xfce.org noreply at xfce.org
Wed Aug 12 18:39:06 CEST 2015


This is an automated email from the git hooks/post-receive script.

omegaphil pushed a commit to branch master
in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit 8a07aa9a3d9dd0c2a4d1787d9652573ae5ed447b
Author: OmegaPhil <OmegaPhil at startmail.com>
Date:   Tue Jul 28 19:54:52 2015 +0100

    Implement compact format_value for most monitors
---
 src/monitor-impls.cpp |   54 ++++++++++++++++++++++++++++++++-----------------
 src/monitor-impls.hpp |   16 +++++++--------
 src/monitor.hpp       |    2 +-
 3 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index a285591..92b5275 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -338,7 +338,7 @@ bool CpuUsageMonitor::fixed_max()
   return true;
 }
 
-Glib::ustring CpuUsageMonitor::format_value(double val)
+Glib::ustring CpuUsageMonitor::format_value(double val, bool compact)
 {
   return String::ucompose(_("%1%%"), precision(1), 100 * val);
 }
@@ -411,11 +411,13 @@ bool SwapUsageMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring SwapUsageMonitor::format_value(double val)
+Glib::ustring SwapUsageMonitor::format_value(double val, bool compact)
 {
+  Glib::ustring format = compact ? _("%1M"): _("%1 MB");
+
   val /= 1000000;
 
-  return String::ucompose(_("%1 Mb"), decimal_digits(val, 3), val);
+  return String::ucompose(format, decimal_digits(val, 3), val);
 }
 
 Glib::ustring SwapUsageMonitor::get_name()
@@ -486,7 +488,7 @@ bool LoadAverageMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring LoadAverageMonitor::format_value(double val)
+Glib::ustring LoadAverageMonitor::format_value(double val, bool compact)
 {
   return String::ucompose("%1", precision(1), val);
 }
@@ -568,11 +570,13 @@ bool MemoryUsageMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring MemoryUsageMonitor::format_value(double val)
+Glib::ustring MemoryUsageMonitor::format_value(double val, bool compact)
 {
+  Glib::ustring format = compact ? _("%1M") : _("%1 MB");
+
   val /= 1000000;
 
-  return String::ucompose(_("%1 Mb"), decimal_digits(val, 3), val);
+  return String::ucompose(format, decimal_digits(val, 3), val);
 }
 
 Glib::ustring MemoryUsageMonitor::get_name()
@@ -643,22 +647,28 @@ bool DiskUsageMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring DiskUsageMonitor::format_value(double val)
+Glib::ustring DiskUsageMonitor::format_value(double val, bool compact)
 {
+  Glib::ustring format;
+
   if (val >= 1000 * 1000 * 1000) {
     val /= 1000 * 1000 * 1000;
-    return String::ucompose(_("%1 GB"), decimal_digits(val, 3), val);
+    format = compact ? _("%1G") : _("%1 GB");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else if (val >= 1000 * 1000) {
     val /= 1000 * 1000;
-    return String::ucompose(_("%1 MB"), decimal_digits(val, 3), val);
+    format = compact ? _("%1M") : _("%1 MB");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else if (val >= 1000) {
     val /= 1000;
-    return String::ucompose(_("%1 kB"), decimal_digits(val, 3), val);
+    format = compact ? _("%1K"): _("%1 KB");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else
-    return String::ucompose(_("%1 B"), decimal_digits(val, 3), val);
+    format = compact ? _("%1B") : _("%1 B");
+    return String::ucompose(format, decimal_digits(val, 3), val);
 }
 
 Glib::ustring DiskUsageMonitor::get_name()
@@ -781,8 +791,10 @@ bool NetworkLoadMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring NetworkLoadMonitor::format_value(double val)
+Glib::ustring NetworkLoadMonitor::format_value(double val, bool compact)
 {
+  Glib::ustring format;
+
   // 1000 ms = 1 s
   val = val / time_difference * 1000;
 
@@ -791,18 +803,24 @@ Glib::ustring NetworkLoadMonitor::format_value(double val)
 
   if (val >= 1000 * 1000 * 1000) {
     val /= 1000 * 1000 * 1000;
-    return String::ucompose(_("%1 GB/s"), decimal_digits(val, 3), val);
+    format = compact ? _("%1G") : _("%1 GB/s");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else if (val >= 1000 * 1000) {
     val /= 1000 * 1000;
-    return String::ucompose(_("%1 MB/s"), decimal_digits(val, 3), val);
+    format = compact ? _("%1M") : _("%1 MB/s");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else if (val >= 1000) {
     val /= 1000;
-    return String::ucompose(_("%1 kB/s"), decimal_digits(val, 3), val);
+    format = compact ? _("%1K") : _("%1 KB/s");
+    return String::ucompose(format, decimal_digits(val, 3), val);
   }
   else
-    return String::ucompose(_("%1 B/s"), decimal_digits(val, 3), val);
+  {
+    format = compact ? _("%1B") : _("%1 B/s");
+    return String::ucompose(format, decimal_digits(val, 3), val);
+  }
 }
 
 Glib::ustring NetworkLoadMonitor::get_name()
@@ -1446,7 +1464,7 @@ bool TemperatureMonitor::fixed_max()
 }
 
 
-Glib::ustring TemperatureMonitor::format_value(double val)
+Glib::ustring TemperatureMonitor::format_value(double val, bool compact)
 {
   // %2 contains the degree sign (the following 'C' stands for Celsius)
   return String::ucompose(_("%1%2C"), decimal_digits(val, 3), val, "\xc2\xb0");
@@ -1543,7 +1561,7 @@ bool FanSpeedMonitor::fixed_max()
   return false;
 }
 
-Glib::ustring FanSpeedMonitor::format_value(double val)
+Glib::ustring FanSpeedMonitor::format_value(double val, bool compact)
 {
   // rpm is rotations per minute
   return String::ucompose(_("%1 rpm"), val, val);
diff --git a/src/monitor-impls.hpp b/src/monitor-impls.hpp
index 5a4dbb9..48a9523 100644
--- a/src/monitor-impls.hpp
+++ b/src/monitor-impls.hpp
@@ -53,7 +53,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -80,7 +80,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -100,7 +100,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -121,7 +121,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -141,7 +141,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact= false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -185,7 +185,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -251,7 +251,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
@@ -274,7 +274,7 @@ public:
 
   virtual double max();
   virtual bool fixed_max();
-  virtual Glib::ustring format_value(double val);
+  virtual Glib::ustring format_value(double val, bool compact = false);
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual int update_interval();
diff --git a/src/monitor.hpp b/src/monitor.hpp
index 5d74d8b..893879e 100644
--- a/src/monitor.hpp
+++ b/src/monitor.hpp
@@ -77,7 +77,7 @@ public:
 
   /* Convert float to string which represents an actual number with the
    * appropriate unit */
-  virtual Glib::ustring format_value(double val) = 0;
+  virtual Glib::ustring format_value(double val, bool compact = false) = 0;
 
   // Return a descriptive name
   virtual Glib::ustring get_name() = 0;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list