From f891ecc9fbe159ec8a6cf321c43217d59f8cdf02 Mon Sep 17 00:00:00 2001 From: Holger Cremer Date: Sun, 16 Apr 2017 01:34:22 +0200 Subject: adds a new feature: a user can select it's sond theme in the web interface. If not selected, a random theme is used. --- src/web/Makefile | 2 +- src/web/main.vala | 8 +++++--- src/web/web.vala | 27 ++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src/web') diff --git a/src/web/Makefile b/src/web/Makefile index 17140c3..e6094f6 100644 --- a/src/web/Makefile +++ b/src/web/Makefile @@ -1,7 +1,7 @@ all: web @echo > /dev/null -web: main.vala web.vala websession.vala csv.vala template.vala ../database/db-interface.vala ../pgp/pgp-interface.vala ../price.vapi ../config/config-interface.vala +web: main.vala web.vala websession.vala csv.vala template.vala ../database/db-interface.vala ../pgp/pgp-interface.vala ../price.vapi ../config/config-interface.vala ../audio/audio-interface.vala valac -X -w -o $@ --vapidir=../../vapi --enable-experimental --pkg gee-0.8 --pkg gio-2.0 --pkg libsoup-2.4 --pkg posix $^ clean: diff --git a/src/web/main.vala b/src/web/main.vala index 86caea5..22c586b 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -17,6 +17,7 @@ Database db; public CSVMemberFile csvimport; public PGP pgp; public Config cfg; +public AudioPlayer audio; string templatedir; public static int main(string[] args) { @@ -26,9 +27,10 @@ public static int main(string[] args) { uint port = 8080; try { - db = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); - pgp = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); - cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + db = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); + pgp = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); + cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + audio = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); templatedir = cfg.get_string("WEB", "filepath"); port = cfg.get_integer("WEB", "port"); diff --git a/src/web/web.vala b/src/web/web.vala index fb03e4b..c63db73 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -359,19 +359,36 @@ public class WebServer { t.replace("ISADMIN2", "disabled=\"disabled\""); } + var userThemeList = audio.get_user_themes(); + var message = ""; var postdata = Soup.Form.decode_multipart(msg, null, null, null, null); if(postdata != null && postdata.contains("password1") && postdata.contains("password2")) { if(postdata["password1"] != postdata["password2"]) { - t.replace("MESSAGE", "
Error! Passwords do not match!
"); + message = "
Error! Passwords do not match!
"; } else if(postdata["password1"] == "") { - t.replace("MESSAGE", "
Error! Empty Password not allowed!
"); + message = "
Error! Empty Password not allowed!
"; } else { db.set_user_password(id, postdata["password1"]); - t.replace("MESSAGE", "
Password Changed!
"); + message = "
Password Changed!
"; } - } else { - t.replace("MESSAGE", ""); + } else if(postdata != null && postdata.contains("soundTheme")) { + if (postdata["soundTheme"] in userThemeList) { + userinfo.soundTheme = postdata["soundTheme"]; + db.set_userTheme(id, postdata["soundTheme"]); + } else { + userinfo.soundTheme = null; + db.set_userTheme(id, ""); + } + message = "
Sound theme changed.
"; + } + t.replace("MESSAGE", message); + + var soundThemes = ""; + foreach(var theme in userThemeList) { + var selected = userinfo.soundTheme == theme ? "selected" : ""; + soundThemes += @""; } + t.replace("SOUND_THEMES", soundThemes); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); -- cgit v1.2.3