From b39b36d54589fa432b56989fa27fef1b8f2a3742 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sat, 19 Mar 2022 03:24:19 -0700 Subject: [PATCH] loading xml screensaver files into a list --- src/application.vala | 2 +- src/candy/base.vala | 2 +- src/candy/{mpv.vala => video.vala} | 8 +++---- src/candy/xscreensaver.vala | 35 +++++++++++++++++++++++------- src/candy/xscreensaver_config.vala | 30 +++++++++++++++++++++++++ src/meson.build | 4 +++- 6 files changed, 66 insertions(+), 15 deletions(-) rename src/candy/{mpv.vala => video.vala} (62%) create mode 100644 src/candy/xscreensaver_config.vala diff --git a/src/application.vala b/src/application.vala index 8d4801a..e8c9e40 100644 --- a/src/application.vala +++ b/src/application.vala @@ -18,7 +18,7 @@ namespace Deskcandy { this.add_action(toggle_enabled); this.set_up_actions(); - this._candies = { new XScreensaver(), new Mpv() }; + this._candies = { new XScreensaver(), new Video() }; } private async void initialize_async() { diff --git a/src/candy/base.vala b/src/candy/base.vala index c532fc5..37335c6 100644 --- a/src/candy/base.vala +++ b/src/candy/base.vala @@ -3,7 +3,7 @@ namespace Deskcandy.Candy { protected BaseCandy() { } - public abstract async void initialize(); + public abstract async void initialize() throws Error; public abstract Subprocess launch(uint socket_id) throws Error; } diff --git a/src/candy/mpv.vala b/src/candy/video.vala similarity index 62% rename from src/candy/mpv.vala rename to src/candy/video.vala index 4d3c79b..28335f1 100644 --- a/src/candy/mpv.vala +++ b/src/candy/video.vala @@ -1,14 +1,14 @@ namespace Deskcandy.Candy { - class Mpv : BaseCandy { - public Mpv() { + class Video : BaseCandy { + public Video() { } - public override async void initialize() { + public override async void initialize() throws Error { } public override Subprocess launch(uint socket_id) throws Error { message("Launching mpv video..."); - return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", "/home/vv/Videos/Sprite_Fright_-_Open_Movie_by_Blender_Studio.webm"); + return new Subprocess(SubprocessFlags.NONE, "mpv", @"--wid=$socket_id", "--no-audio", "--video-unscaled=downscale-big", "--video-zoom=20", "/home/vv/Videos/Spring_-_Blender_Open_Movie.webm"); } } } diff --git a/src/candy/xscreensaver.vala b/src/candy/xscreensaver.vala index 588e1d1..3491ee1 100644 --- a/src/candy/xscreensaver.vala +++ b/src/candy/xscreensaver.vala @@ -1,21 +1,40 @@ namespace Deskcandy.Candy { class XScreensaver : BaseCandy { - public string config_dir { get; private set; } - public string path_dir { get; private set; } + public string config_path { get; private set; } + public string saver_path { get; private set; } + + public List configs; public XScreensaver() { + this.configs = new List(); } - public override async void initialize() { + public override async void initialize() throws Error { yield this.hacky_determine_directories(); + + var config_dir = File.new_for_path(this.config_path); + var enumerator = yield config_dir.enumerate_children_async("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS); + FileInfo info; + message(@"Parsing configs in $(this.config_path)"); + while ((info = enumerator.next_file()) != null) { + if (!info.get_name().has_suffix(".xml")) { + continue; + } + + var name = info.get_name(); + var config = new XScreensaverConfig(config_dir.resolve_relative_path(info.get_name())); + this.configs.append(config); + } + message(@"Found $(this.configs.length()) screensavers."); } public override Subprocess launch(uint socket_id) throws Error { message("Launching XScreensaver..."); - return new Subprocess(SubprocessFlags.NONE, @"$(this.path_dir)/abstractile", "-window-id", socket_id.to_string()); + return new Subprocess(SubprocessFlags.NONE, @"$(this.saver_path)/abstractile", "-window-id", socket_id.to_string()); } private async void hacky_determine_directories() { + // TODO: Make this a first-time thing and save to config warning("HACK: launching xscreensaver-settings to figure out the configuration"); try { SourceFunc callback = this.hacky_determine_directories.callback; @@ -49,11 +68,11 @@ namespace Deskcandy.Candy { while ((line = dis.read_line_utf8()) != null) { MatchInfo info; if (config_dir_regex.match(line, 0, out info)) { - this.config_dir = info.fetch(1); - message(@"Found xscreensaver config dir: $(this.config_dir)"); + this.config_path = info.fetch(1); + message(@"Found xscreensaver config dir: $(this.config_path)"); } else if (path_dir_regex.match(line, 0, out info)) { - this.path_dir = info.fetch(1); - message(@"Found xscreensaver path dir: $(this.path_dir)"); + this.saver_path = info.fetch(1); + message(@"Found xscreensaver path dir: $(this.saver_path)"); } } } catch (IOError e) { diff --git a/src/candy/xscreensaver_config.vala b/src/candy/xscreensaver_config.vala new file mode 100644 index 0000000..39fe3ad --- /dev/null +++ b/src/candy/xscreensaver_config.vala @@ -0,0 +1,30 @@ +namespace Deskcandy.Candy { + public class XScreensaverConfig : GXml.Element { + [Description(nick="::name")] + public string name { get; set; } + + [Description(nick="::_label")] + public string label { get; set; } + + [Description(nick="::gl")] + public string gl { get; set; } + + public string arg { get; set;} + + [Description(nick="::_description")] + public string description { get; set; } + + public XScreensaverConfig(File file) throws Error { + this.initialize("screensaver"); + this.read_from_file(file); + + var tag = this.get_child("command"); + this.arg = tag.get_attribute("arg"); + debug(@"Loaded $this"); + } + + public string to_string() { + return @"Screensaver: $(this.label) [$(this.name) $(this.arg)]"; + } + } +} diff --git a/src/meson.build b/src/meson.build index 226f352..fe679da 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,13 +5,15 @@ deskcandy_sources = [ 'application.vala', 'candy/base.vala', 'candy/xscreensaver.vala', - 'candy/mpv.vala' + 'candy/xscreensaver_config.vala', + 'candy/video.vala' ] deskcandy_deps = [ dependency('gio-2.0', version: '>= 2.50'), dependency('gtk+-3.0', version: '>= 3.22'), + dependency('gxml-0.20', version: '>= 0.20'), ] gnome = import('gnome')