2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-27 17:25:36 +00:00
|
|
|
#include <AK/String.h>
|
2019-02-08 15:19:16 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/ArgsParser.h>
|
|
|
|
#include <LibCore/DirIterator.h>
|
2020-02-06 19:33:02 +00:00
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
#include <LibGUI/Desktop.h>
|
2019-02-08 15:19:16 +00:00
|
|
|
|
2019-05-17 13:06:06 +00:00
|
|
|
static int handle_show_all()
|
2019-02-08 15:19:16 +00:00
|
|
|
{
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::DirIterator di("/res/wallpapers", Core::DirIterator::SkipDots);
|
2019-05-27 07:26:54 +00:00
|
|
|
if (di.has_error()) {
|
2021-05-31 14:43:25 +00:00
|
|
|
warnln("DirIterator: {}", di.error_string());
|
2019-02-08 15:19:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2019-05-27 07:26:54 +00:00
|
|
|
|
|
|
|
while (di.has_next()) {
|
|
|
|
String name = di.next_path();
|
2021-05-31 14:43:25 +00:00
|
|
|
outln("{}", name);
|
2019-02-08 15:19:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:06:06 +00:00
|
|
|
static int handle_show_current()
|
2019-02-08 15:19:16 +00:00
|
|
|
{
|
2021-05-31 14:43:25 +00:00
|
|
|
outln("{}", GUI::Desktop::the().wallpaper());
|
2019-02-08 15:19:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:06:06 +00:00
|
|
|
static int handle_set_pape(const String& name)
|
2019-02-08 15:19:16 +00:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("/res/wallpapers/");
|
|
|
|
builder.append(name);
|
2019-03-21 14:54:19 +00:00
|
|
|
String path = builder.to_string();
|
2020-02-02 14:07:41 +00:00
|
|
|
if (!GUI::Desktop::the().set_wallpaper(path)) {
|
2021-05-31 14:43:25 +00:00
|
|
|
warnln("pape: Failed to set wallpaper {}", path);
|
2019-03-21 14:54:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2019-02-08 15:19:16 +00:00
|
|
|
return 0;
|
2019-05-17 13:06:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2020-01-27 17:25:36 +00:00
|
|
|
bool show_all = false;
|
|
|
|
bool show_current = false;
|
|
|
|
const char* name = nullptr;
|
2019-05-17 13:06:06 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::ArgsParser args_parser;
|
2020-01-27 17:25:36 +00:00
|
|
|
args_parser.add_option(show_all, "Show all wallpapers", "show-all", 'a');
|
|
|
|
args_parser.add_option(show_current, "Show current wallpaper", "show-current", 'c');
|
2020-02-02 11:34:39 +00:00
|
|
|
args_parser.add_positional_argument(name, "Wallpaper to set", "name", Core::ArgsParser::Required::No);
|
2020-01-27 17:25:36 +00:00
|
|
|
args_parser.parse(argc, argv);
|
2019-05-17 13:06:06 +00:00
|
|
|
|
2020-07-04 12:05:19 +00:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2019-05-17 13:06:06 +00:00
|
|
|
|
2020-01-27 17:25:36 +00:00
|
|
|
if (show_all)
|
2019-05-17 13:06:06 +00:00
|
|
|
return handle_show_all();
|
2020-01-27 17:25:36 +00:00
|
|
|
else if (show_current)
|
2019-05-17 13:06:06 +00:00
|
|
|
return handle_show_current();
|
|
|
|
|
2020-01-27 17:25:36 +00:00
|
|
|
return handle_set_pape(name);
|
2019-02-08 15:19:16 +00:00
|
|
|
}
|