diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-11-26 23:19:40 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-11-26 23:19:40 +0100 |
| commit | 97390d565eca8004edb1d262c282aaf9e47c3b7b (patch) | |
| tree | 7590e094e17a9e8732fc48b76b8f38c4ba866e9b /src/main.cpp | |
| parent | bae92cea3bcbacd7883499da61a0e54f13da6d23 (diff) | |
| download | wanda-97390d565eca8004edb1d262c282aaf9e47c3b7b.tar.xz wanda-97390d565eca8004edb1d262c282aaf9e47c3b7b.zip | |
fs: implement filesystem access
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp index 38fdf7f..6d1353d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,28 +1,50 @@ +#include "filesystem.hpp" #include "setting.hpp" #include "optional.hpp" #include <iostream> +#include <set> #include <string> -#include <typeinfo> +namespace +{ -int main() +void set_wallpaper(std::filesystem::path wallpaper) { using namespace wanda::literals; using namespace wanda::std_ext; using namespace std::string_literals; - with("org.gnome.desktop.background"_setting, [](auto &setting) { - with(setting["picture-uri"_key], [](auto &value) { - std::visit([](auto &&value) { - using ValueType = std::decay_t<decltype(value)>; - if constexpr (std::is_same_v<ValueType, std::string>) - { - std::cout << value << '\n'; - } - }, - *value); - std::cout << (value = "file:///"s) << '\n'; + with("org.gnome.desktop.background"_setting, [&](auto &setting) { + with(setting["picture-uri"_key], [&](auto &value) { + value = "file://" + wallpaper.native(); }) || [] { std::cerr << "No such key!\n"; }; }) || [] { std::cerr << "No such setting!\n"; }; } + +constexpr auto image_filter = [](auto const &path) { + static auto const extensions = std::set<std::filesystem::path>{ + std::filesystem::path{".jpg"}, + std::filesystem::path{".png"}, + }; + + if (!std::filesystem::is_regular_file(path)) + { + return false; + } + + return extensions.find(path.extension()) != extensions.cend(); +}; + +} // namespace + +int main() +{ + using namespace wanda::std_ext; + + with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [](auto const &list) { + auto wallpaper = wanda::random_pick(list); + std::cout << "changing wallpaper to " << wallpaper << '\n'; + set_wallpaper(wallpaper); + }) || [] { std::cerr << "Directory does not exist\n"; }; +} |
