[cosmetics] update date in GPL header
[vuplus_xbmc] / tools / Translator / Translator / ChooseLanguageForm.cs
1 /*
2  *      Copyright (C) 2006-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 using System;
23 using System.Drawing;
24 using System.Collections;
25 using System.ComponentModel;
26 using System.Windows.Forms;
27 using TeamXBMC.TranslatorCore;
28
29 namespace TeamXBMC.Translator
30 {
31         /// <summary>
32         /// Shows all available languages. The user can choose 
33         /// the language to be translated.
34         /// </summary>
35         public sealed class ChooseLanguageForm : System.Windows.Forms.Form
36         {
37                 private System.Windows.Forms.ListBox listBox1;
38                 private System.Windows.Forms.Button buttonOK;
39                 private System.Windows.Forms.Button buttonCancel;
40                 private System.Windows.Forms.Label label1;
41                 /// <summary>
42                 /// Required designer variable.
43                 /// </summary>
44                 private System.ComponentModel.Container components = null;
45
46                 public ChooseLanguageForm()
47                 {
48                         //
49                         // Required for Windows Form Designer support
50                         //
51                         InitializeComponent();
52
53                         //
54                         // TODO: Add any constructor code after InitializeComponent call
55                         //
56                 }
57
58                 /// <summary>
59                 /// Clean up any resources being used.
60                 /// </summary>
61                 protected override void Dispose( bool disposing )
62                 {
63                         if( disposing )
64                         {
65                                 if(components != null)
66                                 {
67                                         components.Dispose();
68                                 }
69                         }
70                         base.Dispose( disposing );
71                 }
72
73                 #region Windows Form Designer generated code
74                 /// <summary>
75                 /// Required method for Designer support - do not modify
76                 /// the contents of this method with the code editor.
77                 /// </summary>
78                 private void InitializeComponent()
79                 {
80                         this.buttonOK = new System.Windows.Forms.Button();
81                         this.buttonCancel = new System.Windows.Forms.Button();
82                         this.listBox1 = new System.Windows.Forms.ListBox();
83                         this.label1 = new System.Windows.Forms.Label();
84                         this.SuspendLayout();
85                         // 
86                         // buttonOK
87                         // 
88                         this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
89                         this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
90                         this.buttonOK.Location = new System.Drawing.Point(80, 200);
91                         this.buttonOK.Name = "buttonOK";
92                         this.buttonOK.TabIndex = 3;
93                         this.buttonOK.Text = "OK";
94                         this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
95                         // 
96                         // buttonCancel
97                         // 
98                         this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
99                         this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
100                         this.buttonCancel.Location = new System.Drawing.Point(168, 200);
101                         this.buttonCancel.Name = "buttonCancel";
102                         this.buttonCancel.TabIndex = 4;
103                         this.buttonCancel.Text = "Cancel";
104                         // 
105                         // listBox1
106                         // 
107                         this.listBox1.Location = new System.Drawing.Point(8, 32);
108                         this.listBox1.Name = "listBox1";
109                         this.listBox1.Size = new System.Drawing.Size(232, 160);
110                         this.listBox1.Sorted = true;
111                         this.listBox1.TabIndex = 2;
112                         this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
113                         this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
114                         // 
115                         // label1
116                         // 
117                         this.label1.Location = new System.Drawing.Point(8, 8);
118                         this.label1.Name = "label1";
119                         this.label1.Size = new System.Drawing.Size(240, 23);
120                         this.label1.TabIndex = 1;
121                         this.label1.Text = "Select the language to be translated";
122                         // 
123                         // ChooseLanguageForm
124                         // 
125                         this.AcceptButton = this.buttonOK;
126                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
127                         this.CancelButton = this.buttonCancel;
128                         this.ClientSize = new System.Drawing.Size(250, 232);
129                         this.Controls.Add(this.label1);
130                         this.Controls.Add(this.listBox1);
131                         this.Controls.Add(this.buttonCancel);
132                         this.Controls.Add(this.buttonOK);
133                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
134                         this.MaximizeBox = false;
135                         this.MinimizeBox = false;
136                         this.Name = "ChooseLanguageForm";
137                         this.ShowInTaskbar = false;
138                         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
139                         this.Text = "Choose Language";
140                         this.Load += new System.EventHandler(this.ChooseLanguageForm_Load);
141                         this.ResumeLayout(false);
142
143                 }
144                 #endregion
145
146                 #region Form initialization
147
148                 /// <summary>
149                 /// Fills the listbox with all available languages and selects the one currently edited
150                 /// </summary>
151                 private void ChooseLanguageForm_Load(object sender, System.EventArgs e)
152                 {
153                         string root=Settings.Instance.LanguageFolder;
154                         string[] languages=TranslationManager.Instance.Languages;
155
156                         foreach (string language in languages)
157                         {
158                                 listBox1.Items.Add(language);
159
160                                 if (Settings.Instance.Language==language)
161                                 {
162                                         listBox1.SelectedItem=language;
163                                 }
164                         }
165
166                         if (Settings.Instance.Language=="")
167                         { // No language selected yet, disable ok button
168                                 buttonOK.Enabled=false;
169                         }
170                 }
171
172
173                 #endregion
174
175                 #region Control Events
176
177                 /// <summary>
178                 /// The double clicked language in the listbox is selected as the current one
179                 /// and afterwards the dialog is closed
180                 /// </summary>
181                 private void listBox1_DoubleClick(object sender, System.EventArgs e)
182                 {
183                         Settings.Instance.Language=(string)listBox1.SelectedItem;
184
185                         DialogResult=DialogResult.OK;
186                         Close();
187                 }
188
189                 /// <summary>
190                 /// Sets the language selected in the listbox as the current one.
191                 /// </summary>
192                 private void buttonOK_Click(object sender, System.EventArgs e)
193                 {
194                         Settings.Instance.Language=(string)listBox1.SelectedItem;
195                 }
196
197                 private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
198                 {
199                         buttonOK.Enabled=true;
200                 }
201
202                 #endregion
203         }
204 }