Skip to content

Commit

Permalink
disk: clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Jul 22, 2024
1 parent 8333fd4 commit 7175184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
7 changes: 2 additions & 5 deletions include/modules/disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
#include <fmt/format.h>
#include <sys/statvfs.h>

#include <fstream>

#include "ALabel.hpp"
#include "util/format.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar::modules {

class Disk : public ALabel {
public:
Disk(const std::string&, const Json::Value&);
virtual ~Disk() = default;
~Disk() override = default;
auto update() -> void override;

private:
util::SleeperThread thread_;
std::string path_;
std::string unit_;

float calc_specific_divisor(const std::string divisor);
static float calc_specific_divisor(const std::string& divisor);
};

} // namespace waybar::modules
37 changes: 24 additions & 13 deletions src/modules/disk.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "modules/disk.hpp"

#include "util/format.hpp"

using namespace waybar::util;

waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config)
Expand Down Expand Up @@ -46,7 +48,10 @@ auto waybar::modules::Disk::update() -> void {
return;
}

float specific_free, specific_used, specific_total, divisor;
float specific_free;
float specific_used;
float specific_total;
float divisor;

divisor = calc_specific_divisor(unit_);
specific_free = (stats.f_bavail * stats.f_frsize) / divisor;
Expand Down Expand Up @@ -92,24 +97,30 @@ auto waybar::modules::Disk::update() -> void {
ALabel::update();
}

float waybar::modules::Disk::calc_specific_divisor(std::string divisor) {
float waybar::modules::Disk::calc_specific_divisor(const std::string& divisor) {
if (divisor == "kB") {
return 1000.0;
} else if (divisor == "kiB") {
}
if (divisor == "kiB") {
return 1024.0;
} else if (divisor == "MB") {
}
if (divisor == "MB") {
return 1000.0 * 1000.0;
} else if (divisor == "MiB") {
}
if (divisor == "MiB") {
return 1024.0 * 1024.0;
} else if (divisor == "GB") {
}
if (divisor == "GB") {
return 1000.0 * 1000.0 * 1000.0;
} else if (divisor == "GiB") {
}
if (divisor == "GiB") {
return 1024.0 * 1024.0 * 1024.0;
} else if (divisor == "TB") {
}
if (divisor == "TB") {
return 1000.0 * 1000.0 * 1000.0 * 1000.0;
} else if (divisor == "TiB") {
return 1024.0 * 1024.0 * 1024.0 * 1024.0;
} else { // default to Bytes if it is anything that we don't recongnise
return 1.0;
}
}
if (divisor == "TiB") {
return 1024.0 * 1024.0 * 1024.0 * 1024.0;
} // default to Bytes if it is anything that we don't recongnise
return 1.0;
}

0 comments on commit 7175184

Please sign in to comment.