/*
 * Copyright (c) 2014-2015 s1mpl3x <jan[at]over9000.eu>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package eu.over9000.skadi.ui.dialogs;

import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

import eu.over9000.skadi.model.StateContainer;

public class SettingsDialog extends Dialog<StateContainer> {

	public SettingsDialog() {
		final StateContainer state = StateContainer.getInstance();

		setTitle("Skadi settings");
		setHeaderText(null);
		setGraphic(null);

		final ButtonType saveButtonType = new ButtonType("Save", ButtonData.OK_DONE);
		getDialogPane().getButtonTypes().addAll(saveButtonType, ButtonType.CANCEL);

		final Label lbLivestreamer = new Label("Livestreamer executable");
		final TextField tfLivestreamer = new TextField(state.getExecutableLivestreamer());
		tfLivestreamer.setPrefColumnCount(25);


		final Label lbChrome = new Label("Chrome executable");
		final TextField tfChrome = new TextField(state.getExecutableChrome());
		tfChrome.setPrefColumnCount(25);

		final GridPane grid = new GridPane();
		grid.setHgap(10);
		grid.setVgap(10);

		grid.add(lbLivestreamer, 0, 0);
		grid.add(tfLivestreamer, 1, 0);
		grid.add(lbChrome, 0, 1);
		grid.add(tfChrome, 1, 1);

		final CheckBox cbShowNotifications = new CheckBox("Show notifications");
		cbShowNotifications.setSelected(state.isDisplayNotifications());
		final CheckBox cbMinimizeToTray = new CheckBox("Minimize to tray");
		cbMinimizeToTray.setSelected(state.isMinimizeToTray());
		final CheckBox cbDarkTheme = new CheckBox("Use dark Theme");
		cbDarkTheme.setSelected(state.isUseDarkTheme());

		final VBox boxCheckboxes = new VBox(10, cbShowNotifications, cbMinimizeToTray, cbDarkTheme);

		final VBox boxContent = new VBox(10, grid, new Separator(), boxCheckboxes);

		getDialogPane().setContent(boxContent);

		setResultConverter(btn -> {
			if (btn == saveButtonType) {
				state.setExecutableLivestreamer(tfLivestreamer.getText());
				state.setExecutableChrome(tfChrome.getText());

				state.setDisplayNotifications(cbShowNotifications.isSelected());
				state.setMinimizeToTray(cbMinimizeToTray.isSelected());
				state.setUseDarkTheme(cbDarkTheme.isSelected());
				return state;
			}
			return null;
		});
	}
}

@@ -1171,16 +1171,99 @@
 alogs;%0A%0A
+import eu.over9000.skadi.model.StateContainer;%0Aimport javafx.scene.control.Button;%0A
 import j
@@ -1335,16 +1335,126 @@
 trol.*;%0A
+import javafx.scene.control.Dialog;%0Aimport javafx.scene.control.Label;%0Aimport javafx.scene.control.TextField;%0A
 import j
@@ -1519,117 +1519,432 @@
 ox;%0A
-%0A
 import 
-eu.over9000.skadi.model.StateContainer;%0A%0Apublic class SettingsDialog extends Dialog%3CStateContainer%3E %7B
+org.apache.commons.lang3.SystemUtils;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.awt.*;%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Apublic class SettingsDialog extends Dialog%3CStateContainer%3E %7B%0A%0A%09public static final String LIVESTREAMER_CONFIG_PATH_WIN = System.getenv(%22APPDATA%22) + %22%5C%5Clivestreamer%5C%5C%22;%0A%09private static final Logger LOGGER = LoggerFactory.getLogger(SettingsDialog.class);
 %0A%0A%09p
@@ -2459,16 +2459,331 @@
 t(25);%0A%0A
+%09%09final Button btLivestreamerCfg = new Button(%22Open configuration folder%22);%0A%09%09btLivestreamerCfg.setOnAction(event -%3E %7B%0A%09%09%09try %7B%0A%09%09%09%09Desktop.getDesktop().open(new File(LIVESTREAMER_CONFIG_PATH_WIN));%0A%09%09%09%7D catch (final IOException e) %7B%0A%09%09%09%09LOGGER.error(%22settings dialog: open config folder failed: %22, e);%0A%09%09%09%7D%0A%09%09%7D);%0A%0A
 %0A%09%09final
@@ -3086,24 +3086,101 @@
 mer, 1, 0);%0A
+%09%09if (SystemUtils.IS_OS_WINDOWS) %7B%0A%09%09%09grid.add(btLivestreamerCfg, 2, 0);%0A%09%09%7D%0A
 %09%09grid.add(l

fix #21