Repository navigation
Expand file tree
/
Copy pathtool.h
More file actions
60 lines (48 loc) · 1.47 KB
/
Copy pathtool.h
File metadata and controls
60 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <QString>
#include <QStringList>
#include <pwd.h>
#include <filesystem>
#include <iostream>
#include <format>
#include <vector>
#include <string>
#include <ranges>
namespace fs = std::filesystem;
class QWidget;
class tool {
public:
static inline QString const ORGANIZATION{"Piotr Pszczółkowski"};
static inline QString const DOMAIN{"beesoft.org"};
static inline QString const VERSION{"0.1.0"};
static inline QString const PROGRAM{"Amadeus"};
static inline QString const SUBNAME{"music for you"};
static void resize(QWidget*, int width, int height);
static QString app_complete_name() {
return PROGRAM + " - " + SUBNAME;
}
static std::string home_dir() {
if (struct passwd* pw = getpwuid(getuid()))
return pw->pw_dir;
return {};
}
static bool create_dirs(std::string const& path) noexcept {
if (fs::exists(path))
return true;
std::error_code ec{};
if (fs::create_directories(path, ec))
return true;
std::cerr << std::format("{}\n", ec.message());
return {};
}
static inline QStringList to_qstringlist(std::vector<std::string> data) noexcept {
if (data.empty())
return {};
QStringList lista;
lista.reserve(data.size());
std::ranges::for_each(data, [&lista] (auto&& item) {
lista << QString::fromStdString(std::move(item));
});
return lista;
}
};