1 | Unit MainFormUnit;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | Uses
|
---|
6 | Classes, Forms, Graphics, StdCtrls, Buttons, MultiColumnListBox, Dialogs, ACLLanguageUnit;
|
---|
7 |
|
---|
8 | const
|
---|
9 | AppVersion = 'V1.2.0'; // $SS_REQUIRE_NEW_VERSION$
|
---|
10 |
|
---|
11 | type
|
---|
12 | TProgramType =
|
---|
13 | (
|
---|
14 | idBrowser,
|
---|
15 | idMail,
|
---|
16 | idNews,
|
---|
17 | idFTP,
|
---|
18 | idIRC
|
---|
19 | );
|
---|
20 |
|
---|
21 | Type
|
---|
22 | TMainForm = Class (TForm)
|
---|
23 | PathEdit: TEdit;
|
---|
24 | BrowsePathButton: TButton;
|
---|
25 | SelectDirectoryButton: TButton;
|
---|
26 | WorkingDirectoryEdit: TEdit;
|
---|
27 | ItemsListbox: TMultiColumnListBox;
|
---|
28 | ApplyButton: TButton;
|
---|
29 | CloseButton: TButton;
|
---|
30 | PathLabel: TLabel;
|
---|
31 | WorkingDirectoryLabel: TLabel;
|
---|
32 | OpenDialog: TSystemOpenDialog;
|
---|
33 | ChangeDirDialog: TChangeDirDialog;
|
---|
34 | RestoreButton: TButton;
|
---|
35 | ParametersEdit: TEdit;
|
---|
36 | ParametersLabel: TLabel;
|
---|
37 | VersionLabel: TLabel;
|
---|
38 | LngItems: String;
|
---|
39 | LngPath: String;
|
---|
40 | LngWebBrowser: String;
|
---|
41 | LngEmail: String;
|
---|
42 | LngNewsgroups: String;
|
---|
43 | LngFtp: String;
|
---|
44 | LngIrc: String;
|
---|
45 | LngDiscardChanges: String;
|
---|
46 | LngExitAndDiscardChanges: String;
|
---|
47 | LngFileDoesNotExist: String;
|
---|
48 | LngProgramNotFoundInPath: String;
|
---|
49 | LngDirectoryDoesNotExist: String;
|
---|
50 | LngSaveAnyway: String;
|
---|
51 | Procedure ParametersEditOnChange (Sender: TObject);
|
---|
52 | Procedure RestoreButtonOnClick (Sender: TObject);
|
---|
53 | Procedure MainFormOnCloseQuery (Sender: TObject; Var CanClose: Boolean);
|
---|
54 | Procedure WorkingDirectoryEditOnChange (Sender: TObject);
|
---|
55 | Procedure ApplyButtonOnClick (Sender: TObject);
|
---|
56 | Procedure SelectDirectoryButtonOnClick (Sender: TObject);
|
---|
57 | Procedure BrowsePathButtonOnClick (Sender: TObject);
|
---|
58 | Procedure PathEditOnChange (Sender: TObject);
|
---|
59 | Procedure ItemsListboxOnItemFocus (Sender: TObject; Index: LongInt);
|
---|
60 | Procedure MainFormOnCreate (Sender: TObject);
|
---|
61 | Private
|
---|
62 | {Insert private declarations here}
|
---|
63 | FLastItem: TProgramType;
|
---|
64 | FLastItemSet: boolean;
|
---|
65 | Displaying: boolean;
|
---|
66 | Changed: boolean;
|
---|
67 | Protected
|
---|
68 | Procedure OnLanguageEvent( Language: TLanguageFile; const Apply: boolean );
|
---|
69 | Public
|
---|
70 | {Insert public declarations here}
|
---|
71 | Function SelectedType: TProgramType;
|
---|
72 | Procedure StoreEdits( P: TProgramType );
|
---|
73 | Procedure LoadCurrentSettings;
|
---|
74 | End;
|
---|
75 |
|
---|
76 | Var
|
---|
77 | MainForm: TMainForm;
|
---|
78 |
|
---|
79 | Implementation
|
---|
80 |
|
---|
81 | Uses
|
---|
82 | PMWin, PMSHL,
|
---|
83 | SysUtils,
|
---|
84 | ACLFileUtility, ACLUtility, ACLStringUtility,
|
---|
85 | ControlsUtility, ACLDialogs;
|
---|
86 |
|
---|
87 | {$R Images}
|
---|
88 |
|
---|
89 | type
|
---|
90 | TProgramSettings = record
|
---|
91 | ProgramType: TProgramType;
|
---|
92 | Name: string;
|
---|
93 | PathKey: string;
|
---|
94 | WorkingDirectoryKey: string;
|
---|
95 | ParametersKey: string;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | TCurrentSettings = record
|
---|
99 | Path: string;
|
---|
100 | WorkingDirectory: string;
|
---|
101 | Parameters: string;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | const
|
---|
105 | Programs: array[ Low( TProgramType ).. High( TProgramType ) ] of TProgramSettings =
|
---|
106 | (
|
---|
107 | ( ProgramType: idBrowser;
|
---|
108 | Name: 'Web Browser';
|
---|
109 | PathKey: 'DefaultBrowserExe';
|
---|
110 | WorkingDirectoryKey: 'DefaultWorkingDir';
|
---|
111 | ParametersKey: 'DefaultParameters' ),
|
---|
112 | ( ProgramType: idMail;
|
---|
113 | Name: 'Email';
|
---|
114 | PathKey: 'DefaultMailExe';
|
---|
115 | WorkingDirectoryKey: 'DefaultMailWorkingDir';
|
---|
116 | ParametersKey: 'DefaultMailParameters' ),
|
---|
117 | ( ProgramType: idNews;
|
---|
118 | Name: 'Newsgroups';
|
---|
119 | PathKey: 'DefaultNewsExe';
|
---|
120 | WorkingDirectoryKey: 'DefaultNewsWorkingDir';
|
---|
121 | ParametersKey: 'DefaultNewsParameters' ),
|
---|
122 | ( ProgramType: idFTP;
|
---|
123 | Name: 'FTP';
|
---|
124 | PathKey: 'DefaultFTPExe';
|
---|
125 | WorkingDirectoryKey: 'DefaultFTPWorkingDir';
|
---|
126 | ParametersKey: 'DefaultFTPParameters' ),
|
---|
127 | ( ProgramType: idIRC;
|
---|
128 | Name: 'IRC';
|
---|
129 | PathKey: 'DefaultIRCExe';
|
---|
130 | WorkingDirectoryKey: 'DefaultIRCWorkingDir';
|
---|
131 | ParametersKey: 'DefaultIRCParameters' )
|
---|
132 | );
|
---|
133 |
|
---|
134 | var
|
---|
135 | ProgramNames: array[ Low( TProgramType ).. High( TProgramType ) ] of String = (
|
---|
136 | 'Web Browser', 'Email', 'Newsgroups', 'FTP', 'IRC'
|
---|
137 | );
|
---|
138 |
|
---|
139 | CurrentSettings: array[ Low( TProgramType ).. High( TProgramType ) ] of TCurrentSettings;;
|
---|
140 |
|
---|
141 | Procedure SetProgramPath( P: TProgramSettings;
|
---|
142 | const V: string );
|
---|
143 | begin
|
---|
144 | SetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
145 | P.PathKey,
|
---|
146 | V );
|
---|
147 | end;
|
---|
148 |
|
---|
149 | Procedure SetWorkingDirectory( P: TProgramSettings;
|
---|
150 | const V: string );
|
---|
151 | begin
|
---|
152 | SetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
153 | P.WorkingDirectoryKey,
|
---|
154 | V );
|
---|
155 | end;
|
---|
156 |
|
---|
157 | Procedure SetParameters( P: TProgramSettings;
|
---|
158 | Const V: string );
|
---|
159 | begin
|
---|
160 | SetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
161 | P.ParametersKey,
|
---|
162 | V );
|
---|
163 | end;
|
---|
164 |
|
---|
165 | Function GetProgramPath( P: TProgramSettings ): string;
|
---|
166 | begin
|
---|
167 | Result := GetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
168 | P.PathKey,
|
---|
169 | '' );
|
---|
170 | end;
|
---|
171 |
|
---|
172 | Function GetWorkingDirectory( P: TProgramSettings ): string;
|
---|
173 | begin
|
---|
174 | Result := GetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
175 | P.WorkingDirectoryKey,
|
---|
176 | '' );
|
---|
177 | end;
|
---|
178 |
|
---|
179 | Function GetParameters( P: TProgramSettings ): string;
|
---|
180 | begin
|
---|
181 | Result := GetUserProfileString( 'WPURLDEFAULTSETTINGS',
|
---|
182 | P.ParametersKey,
|
---|
183 | '' );
|
---|
184 | end;
|
---|
185 |
|
---|
186 | Procedure TMainForm.ParametersEditOnChange (Sender: TObject);
|
---|
187 | Begin
|
---|
188 | if not Displaying then
|
---|
189 | Changed := true;
|
---|
190 | End;
|
---|
191 |
|
---|
192 | Procedure TMainForm.RestoreButtonOnClick (Sender: TObject);
|
---|
193 | Begin
|
---|
194 | LoadCurrentSettings;
|
---|
195 | End;
|
---|
196 |
|
---|
197 | Procedure TMainForm.MainFormOnCloseQuery (Sender: TObject;
|
---|
198 | Var CanClose: Boolean);
|
---|
199 | Begin
|
---|
200 | if Changed then
|
---|
201 | if not DoConfirmDlg( LngDiscardChanges,
|
---|
202 | LngExitAndDiscardChanges ) then
|
---|
203 | CanClose := false;
|
---|
204 |
|
---|
205 | End;
|
---|
206 |
|
---|
207 | Procedure TMainForm.WorkingDirectoryEditOnChange (Sender: TObject);
|
---|
208 | Begin
|
---|
209 | if not Displaying then
|
---|
210 | Changed := true;
|
---|
211 |
|
---|
212 | End;
|
---|
213 |
|
---|
214 | Procedure TMainForm.ApplyButtonOnClick (Sender: TObject);
|
---|
215 | var
|
---|
216 | ProgramType: TProgramType;
|
---|
217 | P: TProgramSettings;
|
---|
218 | FoundPath: string; // dummy
|
---|
219 | Begin
|
---|
220 | StoreEdits( SelectedType );
|
---|
221 | // validate.
|
---|
222 | for ProgramType := Low( TProgramType ) to High( TProgramType ) do
|
---|
223 | begin
|
---|
224 | p := Programs[ ProgramType ];
|
---|
225 |
|
---|
226 | with CurrentSettings[ ProgramType ] do
|
---|
227 | begin
|
---|
228 | if Trim( Path ) <> '' then
|
---|
229 | begin
|
---|
230 | if ExtractFilePath( Path ) <> '' then
|
---|
231 | begin
|
---|
232 | // they specified a path...
|
---|
233 | if not FileExists( Path ) then
|
---|
234 | if not DoConfirmDlg( ProgramNames[ ProgramType ],
|
---|
235 | LngFileDoesNotExist + EndLine
|
---|
236 | + Path + EndLine
|
---|
237 | + LngSaveAnyway ) then
|
---|
238 | exit;
|
---|
239 | end
|
---|
240 | else
|
---|
241 | begin
|
---|
242 | // no directory, search path
|
---|
243 | if not SearchPath( 'PATH',
|
---|
244 | Path,
|
---|
245 | FoundPath ) then
|
---|
246 | if not DoConfirmDlg( ProgramNames[ ProgramType ],
|
---|
247 | LngProgramNotFoundInPath + EndLine
|
---|
248 | + Path + EndLine
|
---|
249 | + LngSaveAnyway ) then
|
---|
250 | exit;
|
---|
251 | end;
|
---|
252 | if not DirectoryExists( WorkingDirectory ) then
|
---|
253 | if not DoConfirmDlg( ProgramNames[ ProgramType ],
|
---|
254 | LngDirectoryDoesNotExist + EndLine
|
---|
255 | + WorkingDirectory + EndLine
|
---|
256 | + LngSaveAnyway ) then
|
---|
257 | exit;
|
---|
258 | end;
|
---|
259 | end;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | for ProgramType := Low( TProgramType ) to High( TProgramType ) do
|
---|
263 | begin
|
---|
264 | p := Programs[ ProgramType ];
|
---|
265 |
|
---|
266 | SetProgramPath( P, CurrentSettings[ ProgramType ].Path );
|
---|
267 | SetWorkingDirectory( P, CurrentSettings[ ProgramType ].WorkingDirectory );
|
---|
268 | SetParameters( p, CurrentSettings[ ProgramType ].Parameters );
|
---|
269 | end;
|
---|
270 |
|
---|
271 | Changed := false;
|
---|
272 | End;
|
---|
273 |
|
---|
274 | Procedure TMainForm.SelectDirectoryButtonOnClick (Sender: TObject);
|
---|
275 | Begin
|
---|
276 | ChangeDirDialog.Directory := WorkingDirectoryEdit.Text;
|
---|
277 | if not ChangeDirDialog.Execute then
|
---|
278 | exit;
|
---|
279 | WorkingDirectoryEdit.Text := ChangeDirDialog.Directory;
|
---|
280 | End;
|
---|
281 |
|
---|
282 | Procedure TMainForm.BrowsePathButtonOnClick (Sender: TObject);
|
---|
283 | Begin
|
---|
284 | OpenDialog.Filename := ExtractFilePath( PathEdit.Text ) + '*.exe' ;
|
---|
285 | if not OpenDialog.Execute then
|
---|
286 | exit;
|
---|
287 |
|
---|
288 | PathEdit.Text := OpenDialog.FileName;
|
---|
289 | End;
|
---|
290 |
|
---|
291 | Procedure TMainForm.PathEditOnChange (Sender: TObject);
|
---|
292 | Begin
|
---|
293 | if not Displaying then
|
---|
294 | begin
|
---|
295 | StoreEdits( SelectedType );
|
---|
296 | Changed := true;
|
---|
297 | end;
|
---|
298 | End;
|
---|
299 |
|
---|
300 | Function TMainForm.SelectedType: TProgramType;
|
---|
301 | begin
|
---|
302 | Result := TProgramType( ItemsListBox.Items.Objects[ ItemsListBox.ItemIndex ] );
|
---|
303 | end;
|
---|
304 |
|
---|
305 | Procedure TMainForm.StoreEdits( P: TProgramType );
|
---|
306 | var
|
---|
307 | i: longint;
|
---|
308 | begin
|
---|
309 | CurrentSettings[ P ].Path := PathEdit.Text;
|
---|
310 | CurrentSettings[ P ].WorkingDirectory := WorkingDirectoryEdit.Text;
|
---|
311 | CurrentSettings[ P ].Parameters := ParametersEdit.Text;
|
---|
312 |
|
---|
313 | for i := 0 to ItemsListBox.Items.Count - 1 do
|
---|
314 | if TProgramType( ItemsListBox.Items.Objects[ i ] ) = p then
|
---|
315 | ItemsListBox.Items[ i ] := ProgramNames[ p ]
|
---|
316 | + #9
|
---|
317 | + PathEdit.Text;
|
---|
318 | end;
|
---|
319 |
|
---|
320 | Procedure TMainForm.ItemsListboxOnItemFocus (Sender: TObject; Index: LongInt);
|
---|
321 | Begin
|
---|
322 | if FLastItemSet then
|
---|
323 | begin
|
---|
324 | StoreEdits( FLastItem );
|
---|
325 | end;
|
---|
326 |
|
---|
327 | Displaying := true;
|
---|
328 | PathEdit.Text := CurrentSettings[ SelectedType ].Path;
|
---|
329 | WorkingDirectoryEdit.Text := CurrentSettings[ SelectedType ].WorkingDirectory;
|
---|
330 | ParametersEdit.Text := CurrentSettings[ SelectedType ].Parameters;
|
---|
331 |
|
---|
332 | Displaying := false;
|
---|
333 | FLastItem := SelectedType;
|
---|
334 | FLastItemSet := true;
|
---|
335 | End;
|
---|
336 |
|
---|
337 | Procedure TMainForm.MainFormOnCreate (Sender: TObject);
|
---|
338 | Begin
|
---|
339 | Font := GetNiceDefaultFont;
|
---|
340 |
|
---|
341 | Forms.FormIconResourceID := 1;
|
---|
342 |
|
---|
343 | RegisterForLanguages( OnLanguageEvent );
|
---|
344 |
|
---|
345 | VersionLabel.Caption := AppVersion;
|
---|
346 | LoadDefaultLanguage('cfgapps');
|
---|
347 | LoadCurrentSettings;
|
---|
348 |
|
---|
349 | if Width > Screen.Width then
|
---|
350 | Width := Screen.Width;
|
---|
351 | if Height > Screen.Height then
|
---|
352 | Height := Screen.Height;
|
---|
353 | Left := ( Screen.Width - Width ) div 2;
|
---|
354 | Bottom := ( Screen.Height - Height ) div 2;
|
---|
355 |
|
---|
356 | end;
|
---|
357 |
|
---|
358 | Procedure TMainForm.LoadCurrentSettings;
|
---|
359 | var
|
---|
360 | ProgramType: TProgramType;
|
---|
361 | P: TProgramSettings;
|
---|
362 | begin
|
---|
363 | ItemsListBox.Items.Clear;
|
---|
364 | for ProgramType := Low( TProgramType ) to High( TProgramType ) do
|
---|
365 | begin
|
---|
366 | p := Programs[ ProgramType ];
|
---|
367 | CurrentSettings[ ProgramType ].Path := GetProgramPath( p );
|
---|
368 | CurrentSettings[ ProgramType ].WorkingDirectory := GetWorkingDirectory( p );
|
---|
369 | CurrentSettings[ ProgramType ].Parameters := GetParameters( p );
|
---|
370 |
|
---|
371 | ItemsListBox.Items.AddObject( ProgramNames[ ProgramType ]
|
---|
372 | + #9
|
---|
373 | + CurrentSettings[ ProgramType ].Path,
|
---|
374 | TObject( P.ProgramType ) );
|
---|
375 | end;
|
---|
376 |
|
---|
377 | FLastItemSet := false;
|
---|
378 | Displaying := false;
|
---|
379 | Changed := false;
|
---|
380 | ItemsListBox.ItemIndex := 0;
|
---|
381 | End;
|
---|
382 |
|
---|
383 | Procedure TMainForm.OnLanguageEvent( Language: TLanguageFile;
|
---|
384 | const Apply: boolean );
|
---|
385 | Var
|
---|
386 | ProgramType: TProgramType;
|
---|
387 | P: TProgramSettings;
|
---|
388 | Begin
|
---|
389 | Language.LoadComponentLanguage( self, Apply );
|
---|
390 |
|
---|
391 | Language.LL( Apply, LngWebBrowser, 'ProgramWebBrowser', 'Web Browser' );
|
---|
392 | Language.LL( Apply, LngEmail, 'ProgramEmail', 'Email' );
|
---|
393 | Language.LL( Apply, LngNewsgroups, 'ProgramNewsgroups', 'Newsgroups' );
|
---|
394 | Language.LL( Apply, LngFtp, 'ProgramFTP', 'FTP' );
|
---|
395 | Language.LL( Apply, LngIrc, 'ProgramIRC', 'IRC' );
|
---|
396 | Language.LL( Apply, LngDiscardChanges, 'DiscardChanges', 'Discard changes?' );
|
---|
397 | Language.LL( Apply, LngExitAndDiscardChanges, 'ExitAndDiscardChanges', 'Exit and discard changes?' );
|
---|
398 | Language.LL( Apply, LngFileDoesNotExist, 'FileDoesNotExist', 'File does not exist: ' );
|
---|
399 | Language.LL( Apply, LngProgramNotFoundInPath, 'ProgramNotFoundInPath', 'Program not found in path: ' );
|
---|
400 | Language.LL( Apply, LngDirectoryDoesNotExist, 'DirectoryDoesNotExist', 'Directory does not exist: ' );
|
---|
401 | Language.LL( Apply, LngSaveAnyway, 'SaveAnyway', 'Save anyway?' );
|
---|
402 |
|
---|
403 | ProgramNames[ idBrowser ] := LngWebBrowser;
|
---|
404 | ProgramNames[ idMail ] := LngEmail;
|
---|
405 | ProgramNames[ idNews ] := LngNewsgroups;
|
---|
406 | ProgramNames[ idFTP ] := LngFtp;
|
---|
407 | ProgramNames[ idIRC ] := LngIrc;
|
---|
408 |
|
---|
409 | End;
|
---|
410 |
|
---|
411 | Initialization
|
---|
412 | RegisterClasses ([TMainForm, TEdit, TButton, TMultiColumnListBox, TLabel,
|
---|
413 | TSystemOpenDialog, TChangeDirDialog]);
|
---|
414 | End.
|
---|