diff options
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/.gitignore | 1 | ||||
-rw-r--r-- | src/audio/Makefile | 10 | ||||
-rw-r--r-- | src/audio/audio-interface.vala | 16 | ||||
-rw-r--r-- | src/audio/audio.vala | 36 | ||||
-rw-r--r-- | src/audio/main.vala | 20 |
5 files changed, 47 insertions, 36 deletions
diff --git a/src/audio/.gitignore b/src/audio/.gitignore deleted file mode 100644 index d5cc284..0000000 --- a/src/audio/.gitignore +++ /dev/null @@ -1 +0,0 @@ -audio diff --git a/src/audio/Makefile b/src/audio/Makefile deleted file mode 100644 index 950287a..0000000 --- a/src/audio/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: audio - @echo > /dev/null - -audio: main.vala audio.vala audio-interface.vala ../config/config-interface.vala - valac -X -w -o $@ --pkg gstreamer-1.0 --pkg gio-2.0 $^ - -clean: - rm -rf audio - -.PHONY: all clean diff --git a/src/audio/audio-interface.vala b/src/audio/audio-interface.vala index fe13af5..721a484 100644 --- a/src/audio/audio-interface.vala +++ b/src/audio/audio-interface.vala @@ -17,8 +17,16 @@ public interface AudioPlayer : Object { public abstract signal void end_of_stream(); - public abstract void play_system(string file) throws IOError; - public abstract string get_random_user_theme() throws IOError; - public abstract string[] get_user_themes() throws IOError; - public abstract void play_user(string theme, string type) throws IOError; + public abstract void play_system(string file) throws DBusError, IOError; + public abstract string get_random_user_theme() throws DBusError, IOError; + public abstract string[] get_user_themes() throws DBusError, IOError; + public abstract void play_user(string theme, string type) throws DBusError, IOError; +} + +public enum AudioType { + ERROR, + LOGIN, + LOGOUT, + PURCHASE, + INFO } diff --git a/src/audio/audio.vala b/src/audio/audio.vala index 9afb840..0d969e2 100644 --- a/src/audio/audio.vala +++ b/src/audio/audio.vala @@ -30,24 +30,31 @@ public class AudioPlayerImplementation { return true; } - public AudioPlayerImplementation(string path) throws IOError { + public AudioPlayerImplementation(string path) throws IOError, DBusError { this.path = path; var alsa = Gst.ElementFactory.make("alsasink", "alsa"); - if (alsa == null) - throw new GLib.IOError.FAILED("Cannot find alsa GStreamer plugin"); + if (alsa == null) { + var msg = _("Cannot find alsa GStreamer plugin"); + stderr.printf(msg); + throw new GLib.IOError.FAILED(msg); + } p = Gst.ElementFactory.make("playbin", "player"); - if (p == null) - throw new GLib.IOError.FAILED("Cannot find playbin2 GStreamer plugin"); + if (p == null) { + var msg = _("Cannot find playbin2 GStreamer plugin"); + stderr.printf(msg); + throw new GLib.IOError.FAILED(msg); + } p.set("audio-sink", alsa); p.get_bus().add_watch(Priority.DEFAULT, bus_callback); } - public void play_system(string file) { + public void play_system(string file) throws IOError, DBusError { p.set_state(Gst.State.NULL); - p.uri = "file://" + path + "system/" + file; + p.uri = "file://" + Path.build_filename(path, "system", file); + stdout.printf("Play: %s\n", p.uri); p.set_state(Gst.State.PLAYING); } @@ -76,18 +83,19 @@ public class AudioPlayerImplementation { return files[index]; } - public string get_random_user_theme() { - return get_random_file(path + "user/"); + public string get_random_user_theme() throws IOError, DBusError { + return get_random_file(Path.build_filename(path, "user")); } - public string[] get_user_themes() { - return get_files(path + "user/"); + public string[] get_user_themes() throws IOError, DBusError { + return get_files(Path.build_filename(path, "user")); } - public void play_user(string theme, string type) { + public void play_user(string theme, string type) throws IOError, DBusError { p.set_state(Gst.State.NULL); - var file = get_random_file(path + "user/" + theme+ "/" + type); - p.uri = "file://" + path + "user/" + theme+ "/" + type + "/" + file; + var file = get_random_file(Path.build_filename(path, "user", theme, type)); + p.uri = "file://" + Path.build_filename(path, "user", theme, type, file); + stdout.printf("Play: %s\n", p.uri); p.set_state(Gst.State.PLAYING); } } diff --git a/src/audio/main.vala b/src/audio/main.vala index ac64f52..2fdaf61 100644 --- a/src/audio/main.vala +++ b/src/audio/main.vala @@ -18,22 +18,28 @@ AudioPlayerImplementation player; public static int main(string[] args) { Gst.init(ref args); + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + Bus.own_name( BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", BusNameOwnerFlags.NONE, - on_bus_aquired, + on_bus_acquired, () => {}, - () => stderr.printf("Could not aquire name\n")); + () => stderr.printf(_("Could not acquire name\n"))); try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - var path = cfg.get_string("AUDIO", "path"); + var datapath = cfg.get_string("GENERAL", "datapath"); + var path = Path.build_filename(datapath, "sounds"); player = new AudioPlayerImplementation(path); } catch(IOError e) { - error("IOError: %s\n", e.message); + error(_("IO Error: %s\n"), e.message); } catch(KeyFileError e) { - error("Config Error: %s\n", e.message); + error(_("Config Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); } new MainLoop().run(); @@ -41,10 +47,10 @@ public static int main(string[] args) { return 0; } -void on_bus_aquired(DBusConnection con) { +void on_bus_acquired(DBusConnection con) { try { con.register_object("/io/mainframe/shopsystem/audio", player); } catch(IOError e) { - stderr.printf("Could not register service\n"); + stderr.printf(_("Could not register service\n")); } } |