loading xml screensaver files into a list

This commit is contained in:
Vivianne 2022-03-19 03:24:19 -07:00
parent d4c219bff6
commit b39b36d545
6 changed files with 66 additions and 15 deletions

View file

@ -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() {

View file

@ -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;
}

View file

@ -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");
}
}
}

View file

@ -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<XScreensaverConfig> configs;
public XScreensaver() {
this.configs = new List<XScreensaverConfig>();
}
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) {

View file

@ -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)]";
}
}
}

View file

@ -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')