Shuffle order of items in status bar; change behavior per oofus on irc.
[ardour.git] / gtk2_ardour / disk_space_gauge.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include "ardour_ui.h"
20 #include "dsp_load_gauge.h"
21
22 #include "pbd/i18n.h"
23
24 #define PADDING 3
25
26 DiskSpaceGauge::DiskSpaceGauge ()
27         : ArdourGauge (">24h")
28         , _sec (-1)
29 {
30 }
31
32 void
33 DiskSpaceGauge::set_available_disk_sec (float sec)
34 {
35         if (_sec == sec) {
36                 return;
37         }
38         _sec = sec;
39
40         if (sec < 0) {
41                 update (_("N/A"));
42                 return;
43         }
44
45         char buf[64];
46         if (_sec > 86400) {
47                 update (_("Rec: >24h"));
48                 return;
49         } else if (_sec > 32400 /* 9 hours */) {
50                 snprintf (buf, sizeof (buf), "Rec: %.0fh", _sec / 3600.f);
51         } else if (_sec > 5940 /* 99 mins */) {
52                 snprintf (buf, sizeof (buf), "Rec: %.1fh", _sec / 3600.f);
53         } else {
54                 snprintf (buf, sizeof (buf), "Rec: %.0fm", _sec / 60.f);
55         }
56         update (std::string (buf));
57 }
58
59 float
60 DiskSpaceGauge::level () const {
61         static const float six_hours = 6.f * 3600.f;
62         if (_sec < 0) return 1.0;
63         if (_sec > six_hours) return 0.0;
64         return (1.0 - (_sec / six_hours));
65 }
66
67 bool
68 DiskSpaceGauge::alert () const
69 {
70         return _sec >=0 && _sec < 60.f * 10.f;
71 }
72
73 ArdourGauge::Status
74 DiskSpaceGauge::indicator () const
75 {
76         if (_sec > 3600.f) {
77                 return ArdourGauge::Level_OK;
78         } else if (_sec > 1800.f) {
79                 return ArdourGauge::Level_WARN;
80         }
81         return ArdourGauge::Level_CRIT;
82 }
83
84 std::string
85 DiskSpaceGauge::tooltip_text ()
86 {
87         if (_sec < 0) {
88                 return _("Unkown");
89         }
90
91         int sec = floor (_sec);
92         char buf[64];
93         int hrs  = sec / 3600;
94         int mins = (sec / 60) % 60;
95         int secs = sec % 60;
96
97         snprintf (buf, sizeof(buf), _("%02dh:%02dm:%02ds"), hrs, mins, secs);
98         return _("Available capture disk-space: ") + std::string (buf);
99 }