// frmOptions.cs
// Copyright (C) 2008 Karel Jordaan karel_jordaan@yahoo.com.au
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.ComponentModel;
using System.Windows.Forms;
using GUIControlLogic;
using GUIControlLogic.Persistence;
using FileScope;

namespace ZANZIClient
{
    /// <summary>
    /// Summary description for frmOptions.
    /// </summary>
    /// <remarks>None</remarks>
    public class frmOptions : Form
    {
        #region Variable declaration

        /// <summary>
        /// settings object
        /// </summary>
        /// <remarks>None</remarks>
        private readonly clsSettings thisSettings;

        /// <summary>
        /// cancel btn
        /// </summary>
        /// <remarks>None</remarks>
        private Button btnCancel;

        /// <summary>
        /// Ok btn
        /// </summary>
        /// <remarks>None</remarks>
        private Button btnOK;

        /// <summary>
        /// validation class variable
        /// </summary>
        /// <remarks>None</remarks>
        private clsValidation cls = new clsValidation();

        /// <summary>
        /// compontents
        /// </summary>
        /// <remarks>None</remarks>
        private IContainer components;

        /// <summary>
        /// chat ctrl
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionChat ctrlChat = new ctrlOptionChat();


        /// <summary>
        /// Shares ctrl
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionShares ctrlShares = new ctrlOptionShares();

        /// <summary>
        /// connection
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionConnection ctrlCnn = new ctrlOptionConnection();

        /// <summary>
        /// option interface
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionInterface ctrlInterface = new ctrlOptionInterface();

        /// <summary>
        /// network ctrl
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionNetwork ctrlNetwork = new ctrlOptionNetwork();

        /// <summary>
        /// options transfer ctrl
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionTransfer ctrlTransfer = new ctrlOptionTransfer();

        /// <summary>
        /// option user ctrl
        /// </summary>
        /// <remarks>None</remarks>
        public ctrlOptionUser ctrlUser = new ctrlOptionUser();

        /// <summary>
        /// imagelist
        /// </summary>
        /// <remarks>None</remarks>
        private ImageList imageList1;

        /// <summary>
        /// panel
        /// </summary>
        /// <remarks>None</remarks>
        private Panel panel1;

        /// <summary>
        /// tooltip
        /// </summary>
        /// <remarks>None</remarks>
        private ToolTip toolTip1;

        /// <summary>
        /// treeview
        /// </summary>
        /// <remarks>None</remarks>
        private TreeView treeView1;

        #endregion

        #region Structures

        #endregion

        #region Functions

        /// <summary>Main entry for frmOptions</summary>
        /// <returns>Returns nothing</returns>
        /// <param name="frm">Used to pass the MDIParent as reference</param>
        /// <remarks>frmOptions is the constructor for the frmOptions class.  
        /// The <paramref name="frm"/> parameter takes a reference to frmMain.
        /// The <paramref name="cls"/> parameter takes a reference to frmMain.
        /// The <paramref name="trv"/> parameter takes a reference to frmMain's Treeview.
        /// <c>public frmOptions(clsMain cls, clsTreeView trv)</c>
        /// <c>public frmOptions(frmOptions frm)</c>
        /// 
        /// <summary>Main entry for frmOptions</summary>
        /// <returns>Takes no variables and returns nothing</returns>
        ///<c>public frmOptions()</c>
        public frmOptions(clsMain frm)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            //this.Parent = frm;
            frm.clss.LoadOptionsSetting(this);
            thisSettings = frm.clss;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <remarks>None</remarks>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #endregion

        #region Menu handlers

        #endregion

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        /// <remarks>None</remarks>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmOptions));
            this.btnOK = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.panel1 = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            // 
            // btnOK
            // 
            this.btnOK.AccessibleDescription = null;
            this.btnOK.AccessibleName = null;
            resources.ApplyResources(this.btnOK, "btnOK");
            this.btnOK.BackgroundImage = null;
            this.btnOK.Font = null;
            this.btnOK.Name = "btnOK";
            this.toolTip1.SetToolTip(this.btnOK, resources.GetString("btnOK.ToolTip"));
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.AccessibleDescription = null;
            this.btnCancel.AccessibleName = null;
            resources.ApplyResources(this.btnCancel, "btnCancel");
            this.btnCancel.BackgroundImage = null;
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = null;
            this.btnCancel.Name = "btnCancel";
            this.toolTip1.SetToolTip(this.btnCancel, resources.GetString("btnCancel.ToolTip"));
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // treeView1
            // 
            this.treeView1.AccessibleDescription = null;
            this.treeView1.AccessibleName = null;
            resources.ApplyResources(this.treeView1, "treeView1");
            this.treeView1.BackgroundImage = null;
            this.treeView1.Font = null;
            this.treeView1.ImageList = this.imageList1;
            this.treeView1.ItemHeight = 16;
            this.treeView1.Name = "treeView1";
            this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes1"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes2"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes3"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes4"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes5"))),
            ((System.Windows.Forms.TreeNode)(resources.GetObject("treeView1.Nodes6")))});
            this.treeView1.Scrollable = false;
            this.toolTip1.SetToolTip(this.treeView1, resources.GetString("treeView1.ToolTip"));
            this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "");
            this.imageList1.Images.SetKeyName(1, "");
            this.imageList1.Images.SetKeyName(2, "");
            this.imageList1.Images.SetKeyName(3, "");
            this.imageList1.Images.SetKeyName(4, "");
            this.imageList1.Images.SetKeyName(5, "");
            this.imageList1.Images.SetKeyName(6, "");
            // 
            // panel1
            // 
            this.panel1.AccessibleDescription = null;
            this.panel1.AccessibleName = null;
            resources.ApplyResources(this.panel1, "panel1");
            this.panel1.BackgroundImage = null;
            this.panel1.Font = null;
            this.panel1.Name = "panel1";
            this.toolTip1.SetToolTip(this.panel1, resources.GetString("panel1.ToolTip"));
            // 
            // frmOptions
            // 
            this.AcceptButton = this.btnOK;
            this.AccessibleDescription = null;
            this.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            this.BackgroundImage = null;
            this.CancelButton = this.btnCancel;
            this.Controls.Add(this.treeView1);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.panel1);
            this.Font = null;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Icon = null;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmOptions";
            this.ShowInTaskbar = false;
            this.toolTip1.SetToolTip(this, resources.GetString("$this.ToolTip"));
            this.TopMost = true;
            this.Load += new System.EventHandler(this.frmOptions_Load);
            this.ResumeLayout(false);

        }

        #endregion

        #region Events

        private void frmOptions_Load(object sender, EventArgs e)
        {
            //Load values
            //zzoi 10 june  2008 load the first treeview itme by generating a treeitem click event
            treeView1.SelectedNode = treeView1.Nodes[0];
        }

        private void txtAlias_Validating(object sender, CancelEventArgs e)
        {
            //Required


//			if (!cls.ValidateRequired(txtAlias.Text))
//			{	
//				errorProvider1.SetError (txtAlias,"Please enter an alias.");
//				//txtAlias.e
//				e.Cancel = true;
//			}
//			else
//			{
//				errorProvider1.SetError (txtAlias,"");
//				//txtAlias.e
//				e.Cancel = false;
//			}

            //e.Cancel = cls.DoValidation (this,txtAlias.Text,txtAlias,GUIControlLogic.clsValidation.TypeValidation.Required );
        }

        private void txtCity_Validating(object sender, CancelEventArgs e)
        {
            //Required
            //		GUIControlLogic.clsValidation cls = new GUIControlLogic.clsValidation();

//			if (!cls.ValidateRequired(txtCity.Text))
//			{	
//				errorProvider1.SetError (txtCity,"Please enter a City.");
//				//txtAlias.e
//				e.Cancel = true;
//			}
//			else
//			{
//				errorProvider1.SetError (txtCity,"");
//				//txtAlias.e
//				e.Cancel = false;
//			}

            //e.Cancel = cls.DoValidation (this,txtCity.Text,txtCity,GUIControlLogic.clsValidation.TypeValidation.Required );
        }

        private void cboCountry_Validating(object sender, CancelEventArgs e)
        {
            //Required
            //GUIControlLogic.clsValidation cls = new GUIControlLogic.clsValidation();

//			if (!cls.ValidateRequired(cboCountry.Text))
//			{	
//				errorProvider1.SetError (cboCountry,"Please select a Country.");
//				//txtAlias.e
//				e.Cancel = true;
//			}
//			else
//			{
//				errorProvider1.SetError (cboCountry,"");
//				//txtAlias.e
//				e.Cancel = false;
//			}

            //	e.Cancel = cls.DoValidation (this,cboCountry.Text,cboCountry,GUIControlLogic.clsValidation.TypeValidation.Required );
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            thisSettings.SaveOptionsSetting();
            Close();
        }

        #endregion

        /// <summary>
        /// cancel btn
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">parm</param>
        /// <remarks>None</remarks>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// afterselect event on the treeview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>None</remarks>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

            //zzoi 28 Feb 2009
            //when another language is selected eg. af
            //this code will not switch due to the string comparison
            //the strings should not be hardcoded
            panel1.Controls.Clear();
            switch (e.Node.Text)
            {
                //zzoi 28 Feb 2009
                //added the shares ctrl
                case "Shares":
                    panel1.Controls.Add(ctrlShares);
                    panel1.Invalidate();
                    break;
                case "Interface":
                    panel1.Controls.Add(ctrlInterface);
                    panel1.Invalidate();
                    break;
                case "Network":
                    panel1.Controls.Add(ctrlNetwork);
                    panel1.Invalidate();
                    break;
                case "Connection":
                    panel1.Controls.Add(ctrlCnn);
                    panel1.Invalidate();
                    break;
                case "Transfers":
                    panel1.Controls.Add(ctrlTransfer);
                    panel1.Invalidate();
                    break;
                case "Chat":
                    panel1.Controls.Add(ctrlChat);
                    panel1.Invalidate();
                    break;
                case "Profile":
                    panel1.Controls.Add(ctrlUser);
                    panel1.Invalidate();
                    break;
            }
            Show();
        }
    }
}