2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-01-27 17:25:36 +00:00
|
|
|
#include <AK/String.h>
|
2019-02-08 15:19:16 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
|
|
|
#include <AK/Vector.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-06-07 09:49:31 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.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()) {
|
2020-03-06 22:37:51 +00:00
|
|
|
fprintf(stderr, "DirIterator: %s\n", 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();
|
|
|
|
printf("%s\n", name.characters());
|
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
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
printf("%s\n", GUI::Desktop::the().wallpaper().characters());
|
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)) {
|
2019-03-21 14:54:19 +00:00
|
|
|
fprintf(stderr, "pape: Failed to set wallpaper %s\n", path.characters());
|
|
|
|
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
|
|
|
}
|