-
Notifications
You must be signed in to change notification settings - Fork 0
/
UPreferences.pas
161 lines (141 loc) · 4.49 KB
/
UPreferences.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{* Copyright (C) 2009-2011 Karl-Michael Schindler
*
* This file is part of Heat Wizard.
*
* Heat Wizard 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 3
* of the License, or (at your option) any later version.
*
* Heat Wizard 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 Heat Wizard; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/> or write to the
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA
*
* $URL$
* $Id$
*}
unit UPreferences;
{$mode objfpc}
{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls, Menus;
type
{ TPreferencesForm }
TPreferencesForm = class(TForm)
LanguageComboBox: TComboBox;
DoneButton: TButton;
LanguageLabel: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure LanguageComboBoxSelect(Sender: TObject);
procedure DoneButtonClick(Sender: TObject);
procedure TranslateTexts(const locale: string);
private
{ private declarations }
public
{ public declarations }
end;
var
PreferencesForm: TPreferencesForm;
implementation
{ TPreferencesForm }
uses
gettext,
HeatWizardPanel,
UAbout,
UFormPainter,
ULog,
UPlatform,
UPreferenceData;
procedure TPreferencesForm.FormCreate(Sender: TObject);
var
index: integer;
begin
Logger.Output('TPreferencesForm.FormCreate','Language: ' + LanguageShortString[Language]);
LanguageComboBox.Items.Clear;
for index := ord(low(Tlanguage)) to ord(high(Tlanguage)) do
begin
LanguageComboBox.Items.Add(LanguageLongString[TLanguage(index)]);
end;
LanguageComboBox.ItemIndex := ord(Language);
TranslateTexts(LanguageShortString[Language]);
DoneButton.Height := PF_ButtonHeight;
Logger.Output('UPreferences', 'started with: ' + LanguageShortString[Language]);
Visible := false;
end;
procedure TPreferencesForm.FormPaint(Sender: TObject);
begin
PaintBackground(Self)
end;
procedure TPreferencesForm.FormResize(Sender: TObject);
begin
PreferenceData.FormsPosition.Top := Top;
PreferenceData.FormsPosition.Left := Left;
PreferenceData.Save;
end;
procedure TPreferencesForm.LanguageComboBoxSelect(Sender: TObject);
begin
Language := TLanguage(LanguageComboBox.ItemIndex);
TranslateTexts(LanguageShortString[Language]);
AboutForm.TranslateTexts(LanguageShortString[Language]);
MainForm.TranslateTexts(LanguageShortString[Language]);
Logger.Output('UPreferences', 'Language changed to: ' + LanguageShortString[Language]);
end;
procedure TPreferencesForm.DoneButtonClick(Sender: TObject);
begin
PreferenceData.Language := LanguageShortString[Language];
PreferenceData.Save;
MainForm.Left := PreferencesForm.Left;
MainForm.Top := PreferencesForm.Top;
MainForm.Visible := true;
PreferencesForm.Visible := false;
end;
procedure TPreferencesForm.TranslateTexts(const locale: string);
var
LanguageFilePath: string;
MOFile: TMOFile;
index: integer;
begin
LanguageFilePath := getLanguageFilePath(locale);
if not FileExists(LanguageFilePath) then
begin
Logger.Output ('PreferencesForm', 'File ' + LanguageFilePath + ' not found!');
Logger.Output ('PreferencesForm', 'Continuing with default language, i.e. English!');
end
else
begin
try
MOFile := TMOFile.Create(LanguageFilePath);
except
on EMOFileError do
Logger.Output ('PreferencesForm', 'Invalid .mo file header');
end;
if assigned(MOFile) then
begin
LanguageLabel.Caption := MOFile.translate('Language:');
for index := ord(low(Tlanguage)) to ord(high(Tlanguage)) do
begin
LanguageComboBox.Items.Strings[index] := MOFile.translate(LanguageLongString[TLanguage(index)]);
end;
DoneButton.Caption := MOFile.translate('Done');
{$IF Defined(DARWIN)}
MainForm.AboutMenu.Caption := MOFile.translate('About ') + Application.Title;
MainForm.PreferencesMenu.Caption := MOFile.translate('Preferences ...');
{$IFEND}
MOFile.Destroy;
end;
end;
end;
{$R *.lfm}
end.