<?xml version="1.0"?>
<!--
 * this file is a part of Check4Change 
 *
 * Copyright 2010 Ronen Zilberman
 * See license.txt for details.
 *-->

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<dialog id="c4c_options" title="Set Default Values" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="loadParams();" ondialogaccept="return doOK();">
    <script type="application/x-javascript" src="chrome://c4c/content/c4cUti.js" />
    <script type="application/x-javascript" src="chrome://c4c/content/c4cMenu.js" />
    <script type="application/x-javascript" src="chrome://c4c/content/c4cSystem.js" />
    <popupset>
        <tooltip id="c4c_timesTooltip" orient="vertical">
            <description value="These are the direct options found in the C4C menu. They run using the default" />
            <description value=" parameters defined below. To remove an option just clear it's duration text." />
        </tooltip>
    </popupset>
    <vbox>
        <vbox align="center" id="c4c_vipbox" style="display:none;">
            <hbox align="center">
                <image src="vip.png" />
                <vbox align="center">
                    <label id="c4c_vipname" value="%NAME% is C4C VIP :)" />
                    <label value="Thank you for your support!" />
                </vbox>
                <image src="vip.png" />
            </hbox>
            <label class="text-link" value="Open VIP Profile.." onclick="openProfile();" />
            <label value="" />
        </vbox>
        <tabbox>
            <tabs>
                <tab label="Menu Items" />
                <tab label="Notifications" />				
                <tab label="Settings" />
            </tabs>
            <tabpanels>
                <tabpanel id="menuItems">
                    <groupbox flex="1">
                        <caption label="Context Menu Options" tooltip="c4c_timesTooltip" />
						<label value=""/>
                        <hbox>
                            <hbox align="center">
                                <checkbox class="option" id="timeE0" oncommand="updateTimes();" label="Check every" tooltip="c4c_timesTooltip" />
                            </hbox>
                            <textbox class="option number" id="timeD0" tooltip="c4c_timesTooltip" size="3" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value='';" />
                            <menulist class="option" id="timeU0" tooltip="c4c_timesTooltip">
                                <menupopup>
                                    <menuitem label="seconds" />
                                    <menuitem label="minutes" />
                                    <menuitem label="hours" />
                                </menupopup>
                            </menulist>
                        </hbox>
                        <hbox>
                            <hbox align="center">
                                <checkbox class="option" id="timeE1" oncommand="updateTimes();" label="Check every" tooltip="c4c_timesTooltip" />
                            </hbox>
                            <textbox class="option number" id="timeD1" tooltip="c4c_timesTooltip" size="3" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
                            <menulist class="option" id="timeU1" tooltip="c4c_timesTooltip">
                                <menupopup>
                                    <menuitem label="seconds" />
                                    <menuitem label="minutes" />
                                    <menuitem label="hours" />
                                </menupopup>
                            </menulist>
                        </hbox>
                        <hbox>
                            <hbox align="center">
                                <checkbox class="option" id="timeE2" oncommand="updateTimes();" label="Check every" tooltip="c4c_timesTooltip" />
                            </hbox>
                            <textbox class="option number" id="timeD2" size="3" tooltip="c4c_timesTooltip" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
                            <menulist class="option" id="timeU2" tooltip="c4c_timesTooltip">
                                <menupopup>
                                    <menuitem label="seconds" />
                                    <menuitem label="minutes" />
                                    <menuitem label="hours" />
                                </menupopup>
                            </menulist>
                        </hbox>
                        <hbox>
                            <hbox align="center">
                                <checkbox class="option" id="timeE3" oncommand="updateTimes();" label="Check every" tooltip="c4c_timesTooltip" />
                            </hbox>
                            <textbox class="option number" id="timeD3" size="3" tooltip="c4c_timesTooltip" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
                            <menulist class="option" id="timeU3" tooltip="c4c_timesTooltip">
                                <menupopup>
                                    <menuitem label="seconds" />
                                    <menuitem label="minutes" />
                                    <menuitem label="hours" />
                                </menupopup>
                            </menulist>
                        </hbox>
                        <hbox>
                            <hbox align="center">
                                <checkbox class="option" id="timeE4" oncommand="updateTimes();" label="Check every" tooltip="c4c_timesTooltip" />
                            </hbox>
                            <textbox class="option number" id="timeD4" size="3" tooltip="c4c_timesTooltip" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
                            <menulist class="option" id="timeU4" tooltip="c4c_timesTooltip">
                                <menupopup>
                                    <menuitem label="seconds" />
                                    <menuitem label="minutes" />
                                    <menuitem label="hours" />
                                </menupopup>
                            </menulist>
                        </hbox>
                    </groupbox>
                </tabpanel>
                <tabpanel id="notifications">
                    <vbox flex="1">
                        <groupbox>
                            <caption label="Default Notifications" />
                            <vbox>
                                <checkbox class="option" id="notifyAnim" label="Tab animation" tooltiptext="Dancing C4C letters in the tab." />
                                <checkbox class="option" id="notifyTaskBar" label="Flash Task Bar button" tooltiptext="OS dependant behavior. In Windows, it flashes the browser's button in the taskbar." />
                                <checkbox class="option" id="notifyPopup" label="Pop-up alert" tooltiptext="Like the one used to indicate 'Download Complete'. Clicking it will bring up the page." />
                                <checkbox class="option" id="notifyFocus" label="Focus tab" tooltiptext="Bring tab to the foreground and restore window if it is minimized." />
                                <hbox align="center">
                                    <checkbox class="option" id="notifySound" oncommand="updateSound();" label="Play sound" tooltiptext="Play a sound notification." />
                                    <checkbox class="option" id="notifySoundContinuous" label="Continuously" tooltiptext="Replay sound notification until tab is clicked." />
                                </hbox>
                                <checkbox class="option" id="notifyLog" label="Log changes to file" tooltiptext="Log changes to a log file." />
                                <hbox align="center">
                                    <checkbox class="option" id="notifyEmail" label="Send Email Notification" tooltiptext="Send an email when a change is found." disabled="true" />
                                    <label id="notifyEmailActivate" class="text-link" value="Activate..." onclick="becomeVIP(1);" />
                                    <label id="notifyEmailConfigure" class="text-link" value="" onclick="openProfile();" />
                                </hbox>
                            </vbox>
                        </groupbox>
						<label value=""/>
                        <groupbox>
                            <caption label="Notification Sound" />
                            <hbox>
                                <menulist class="option" id="soundFile" flex="1" editable="true">
                                    <menupopup>
                                    </menupopup>
                                </menulist>
                                <button label="Choose File.." id="SoundFilePicker" oncommand="doPickSoundFile();" />
                            </hbox>
                            <hbox align="center">
                                <button id="SoundFileTest" label="Test" oncommand="doTestSoundFile();" />
							
                                <caption label="Volume:" />
                                <scale class="option" id="soundVolume" min="1" max="100"  />
                            </hbox>
							<label id="groovySounds" class="text-link" value="Get 5 new groovy sounds..." onclick="becomeVIP(2);" />							
                        </groupbox>
                    </vbox>
                </tabpanel>
				
                <tabpanel id="settings">
                    <vbox>
                        <groupbox>
                            <caption label="Default Settings" />
                            <vbox>
                                <checkbox class="option" id="doContinue" label="Continue monitoring after first change" tooltiptext="When checked, the tab will remain c4c-enabled after the first change has been detected. Subsequent reloads will be tested against the new content and changes will continue to be notified." />
                                <checkbox class="option" id="doStopWhenViewing" label="Pause reloading while tab in view" tooltiptext="When checked, c4c will not reload the tab while it is in focus." />
                            </vbox>
                        </groupbox>
						
						
                        <groupbox>
                            <caption label="General Options" />
                            <hbox align="center">
                                <tooltip id="delayDur" orient="vertical">
                                    <description value="Time to wait after page has loaded and before it is checked for changes." />
                                    <description value="Some pages are modified after loading with javascript/ajax so this delay lets them &quot;settle down&quot;. Lowering this value will increase response time, but might cause false alarms." />
                                </tooltip>
                                <label value="Wait" tooltip="delayDur" />
                                <textbox class="option number" id="delayDuration" size="1" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
                                <label value="seconds before checking page." tooltip="delayDur" />
                            </hbox>
                            <popupset>
                                <tooltip id="allowNavToolTip" orient="vertical">
                                    <description value="If enabled, you can naviagate away from the monitored page, but when the timer expires," />
                                    <description value="the original page will be reloaded. This shouldn't be used normally." />
                                </tooltip>
                            </popupset>
                            <checkbox class="option" id="doAllowNav" label="Allow navigating away from a monitored page" tooltip="allowNavToolTip" />
							<hbox align="center">
								<checkbox class="option" id="doRandom" label="Randomize reloading time by " oncommand="updateRandom();" tooltiptext="Change the refresh rate randomly within this percentage. For example: A refresh duration of 10 minutes with a 20% randomization will result in each duration being between 8-12 minutes." />
								<textbox class="option number" id="randomPercentage" size="3" oninput="this.value=parseInt(this.value);if (this.value=='NaN') this.value=''; " />
								<label value="percent"/>
							</hbox>
							
                            <checkbox class="option" id="doCountDown" label="Show countdown in tab" tooltiptext="Show time left to next reload in tab." />							
                            <checkbox class="option" id="doReselect" label="Reselect text after each reload" tooltiptext="When checked the monitored text is reselected after each reload." />															
                            <popupset>
                                <tooltip id="c4c_debugTooltip" orient="vertical">
                                    <description value="In case of a bug, this option might show an alert message with useful information." />
                                    <description value="If you find a bug, however small, I would really like to hear about it." />
                                    <description value="Please try to recreate it with this option set, and contact me via the Feedback." />
                                </tooltip>
                            </popupset>
                            <hbox>
                                <checkbox class="option" id="doDebug" label="Debug Mode" tooltip="c4c_debugTooltip" />
                            </hbox>
                        </groupbox>
						<label value=""/>
                        <groupbox>
							<caption label="Logging Files Folder" />						
							<vbox>
								<hbox>
									<textbox class="option" id="logDir" flex="1" />
									<button label="Choose Dir.." id="LogDirPicker" oncommand="doPickLogDir();" />
								</hbox>
								<hbox>
								<button flex="0" id="LogDirOpen" label="Open" oncommand="doOpenLogDir();" />							
								</hbox>
							</vbox>	
                        </groupbox>
						
                    </vbox>
                </tabpanel>
            </tabpanels>
        </tabbox>
        <vbox></vbox>
        <label value="" />
    </vbox>
    <vbox align="center">
        <hbox>
            <button dlgtype="accept" />
            <button dlgtype="cancel" />
        </hbox>
    </vbox>
    <label value="" />
    <label value="For Help, hold the mouse over desired option." tooltiptext="Yes. Just like that..." />


<script>
<![CDATA[

function becomeVIP(code) {
    var win = c4cUti_getRecentBrowser();	
	win.c4cSystem_goBecomeVIP(code);
}

function openProfile() {
    var win = c4cUti_getRecentBrowser();	
	win.c4cSystem_goVIPProfile();
}

function updateSound() {
  var state = document.getElementById("notifySound").checked;
  document.getElementById("notifySoundContinuous").disabled = !state;
}

function updateTimes() {
	for (var i=0;i<5;i++) {
		var s = document.getElementById("timeE"+i).checked;
		document.getElementById("timeU"+i).disabled = !s;
		document.getElementById("timeD"+i).disabled = !s;
		
	}
}

function updateRandom() {
  var state = document.getElementById("doRandom").checked;
  document.getElementById("randomPercentage").disabled = !state;
}


function loadParams() {

	//vip
	if (c4cVIP_isVIP()) {
		document.getElementById("notifyEmail").disabled = false;	
		document.getElementById("notifyEmailActivate").value = '';
		document.getElementById("groovySounds").style.display="none";
		document.getElementById("notifyEmailConfigure").value = 'Configure..';				
		document.getElementById("c4c_vipbox").style.display = "";
		document.getElementById("c4c_vipname").value = document.getElementById("c4c_vipname").value.replace('%NAME%', c4cVIP_getName());
	}

	//create sounds
	var popup = document.getElementById("soundFile").childNodes[0];
	var arr = c4cSystem_getSystemSoundArray();
	for (var f in arr) {
		var e = document.createElement("menuitem");
		e.setAttribute("label", f);
		popup.insertBefore(e,null);
	}

  c4cParams_setupDialog(null);
  
  updateSound();
  updateTimes();
  updateRandom();  
}

function doOK() {
/*
  for (var i=0;i<c4cMenu_TIMES_COUNT;i++) {
    c4cUti_setPrefInt("timeD"+i, document.getElementById("duration"+i).value);
    c4cUti_setPrefString("timeU"+i, document.getElementById("units"+i).selectedItem.label);
  }
*/
  c4cParams_saveFromDialog();
  return true;
}



function doPickSoundFile() {
try {
    var nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
    fp.init(window, "Choose Sound File", nsIFilePicker.modeOpen);
    fp.appendFilter("WAV files","*.wav");	
    fp.appendFilter("OGG files","*.ogg");	

    var res = fp.show();
    if (res == nsIFilePicker.returnOK || res == nsIFilePicker.returnReplace) {
      var path = fp.file.path;
      document.getElementById("soundFile").value = path;
    }  

} catch (e) {c4cUti_assert(false,e); return null;}
}

function doPickLogDir() {
try {
    var nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
    fp.init(window, "Choose Log Files Directory", nsIFilePicker.modeGetFolder);
  
    // try to get current directory and set it as the default location.
    // if we get an error, no problem. Dialog will just use system default.
    try {
      var dirname = document.getElementById("logDir").value;
      var nsiDir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
      nsiDir.initWithPath(dirname);
      fp.displayDirectory = nsiDir;
    } catch (e) {} 
    
    var res = fp.show();
    if (res == nsIFilePicker.returnOK) {
      var path = fp.file.path;
      // fix trailing // bug : https://bugzilla.mozilla.org/show_bug.cgi?id=660666
      if (path.substring(0,2) == '//') {
	path = path.substring(2);
      }
      document.getElementById("logDir").value = path;
    }  
    
} catch (e) {c4cUti_assert(false,e); return null;}
}

function doTestSoundFile() {

	var soundfile = document.getElementById("soundFile").value;
	var vol = document.getElementById("soundVolume").value;
	c4cUti_stopSound();
	var res = c4cUti_playSound(c4cSystem_translateSoundFile(soundfile), vol, function(){alert("xxx");});
	if (res == false) {
		c4cUti_alert(window, "Error Playing Sound File", "There was an error playing the sound file.");
	}
	
	
}


function doOpenLogDir() {
    var win = c4cUti_getRecentBrowser();	
	win.c4cUti_addTabLocal(document.getElementById("logDir").value, true);
}




]]>

</script>


</dialog>
