source: tags/1.3.1/UCore.pas

Last change on this file was 114, checked in by chronos, 8 years ago
  • Fixed: Disable images scaling under linux as it is not working correctly.
File size: 5.6 KB
Line 
1unit UCore;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, UAcronym, UCoolTranslator, UPersistentForm,
9 UJobProgressView, UScaleDPI, Forms, Controls, ExtCtrls, Menus, LazFileUtils,
10 URegistry, Registry;
11
12type
13
14 { TCore }
15
16 TCore = class(TDataModule)
17 CoolTranslator1: TCoolTranslator;
18 ImageList1: TImageList;
19 ImageListLarge: TImageList;
20 JobProgressView1: TJobProgressView;
21 MenuItem1: TMenuItem;
22 MenuItem19: TMenuItem;
23 MenuItem2: TMenuItem;
24 MenuItem26: TMenuItem;
25 MenuItem27: TMenuItem;
26 MenuItem28: TMenuItem;
27 MenuItem3: TMenuItem;
28 PersistentForm1: TPersistentForm;
29 PopupMenuTrayIcon: TPopupMenu;
30 ScaleDPI1: TScaleDPI;
31 TrayIcon1: TTrayIcon;
32 procedure CoolTranslator1Translate(Sender: TObject);
33 procedure DataModuleCreate(Sender: TObject);
34 procedure DataModuleDestroy(Sender: TObject);
35 procedure TrayIcon1Click(Sender: TObject);
36 private
37 FAlwaysOnTop: Boolean;
38 StoredDimension: TControlDimension;
39 procedure SetAlwaysOnTop(AValue: Boolean);
40 function FindFirstNonOption: string;
41 public
42 AcronymDb: TAcronymDb;
43 StartOnLogon: Boolean;
44 StartMinimizedToTray: Boolean;
45 InitializeStarted: Boolean;
46 InitializeFinished: Boolean;
47 procedure Initialize;
48 procedure LoadConfig;
49 procedure SaveConfig;
50 procedure ScaleDPI;
51 property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
52 end;
53
54var
55 Core: TCore;
56
57const
58 DefaultRegKey = '\Software\Chronosoft\Acronym Decoder';
59
60
61implementation
62
63uses
64 UFormMain;
65
66const
67 ExampleFile = 'Example acronyms.adp';
68
69
70{$R *.lfm}
71
72procedure TCore.DataModuleCreate(Sender: TObject);
73begin
74 AcronymDb := TAcronymDb.Create;
75 InitializeStarted := False;
76 InitializeFinished := False;
77 StoredDimension := TControlDimension.Create;
78end;
79
80procedure TCore.DataModuleDestroy(Sender: TObject);
81begin
82 FreeAndNil(StoredDimension);
83 FreeAndNil(AcronymDb);
84end;
85
86procedure TCore.TrayIcon1Click(Sender: TObject);
87begin
88 if not FormMain.Visible then FormMain.AShow.Execute
89 else FormMain.Hide;
90end;
91
92procedure TCore.CoolTranslator1Translate(Sender: TObject);
93begin
94 UAcronym.Translate;
95end;
96
97procedure TCore.SetAlwaysOnTop(AValue: Boolean);
98begin
99 if FAlwaysOnTop = AValue then Exit;
100 FAlwaysOnTop := AValue;
101 if FAlwaysOnTop then FormMain.FormStyle := fsSystemStayOnTop
102 else FormMain.FormStyle := fsNormal;
103end;
104
105procedure TCore.Initialize;
106var
107 FileNameOption: string;
108begin
109 if not InitializeStarted then begin
110 InitializeStarted := True;
111 LoadConfig;
112
113 {$IFDEF 0}
114 if Application.HasOption('h', 'help') then begin
115 WriteLn('AcronymDecoder <project file>');
116 WriteLn(' -t --tray Start minimized in system tray');
117 WriteLn(' -h --help Show this help');
118 Application.Terminate;
119 Exit;
120 end;
121 {$ENDIF}
122
123 if Application.HasOption('t', 'tray') then begin
124 FormMain.Visible := False;
125 end;
126
127 FileNameOption := FindFirstNonOption;
128 if FileNameOption <> '' then begin
129 // Open file specified as command line parameter
130 AcronymDB.LoadFromFile(FileNameOption);
131 FormMain.LastOpenedList1.AddItem(FileNameOption);
132 end else
133 if (FormMain.LastOpenedList1.Items.Count > 0) and FileExists(FormMain.LastOpenedList1.Items[0]) then begin
134 // Open last opened file
135 AcronymDB.LoadFromFile(FormMain.LastOpenedList1.Items[0])
136 end else begin
137 // Open default database with examples if no item is in recent openned history
138 FileNameOption := ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile;
139 {$IFDEF Linux}
140 // If installed in Linux system then use installation directory for po files
141 if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
142 FileNameOption := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/Examples/' + ExampleFile;
143 {$ENDIF}
144 FormMain.ProjectOpen(FileNameOption);
145 end;
146
147 //ImageList1.Assign(ImageListLarge);
148
149 ScaleDPI;
150 FormMain.UpdateAcronymsList;
151 FormMain.ListViewFilter1.UpdateFromListView(FormMain.ListViewAcronyms);
152 InitializeFinished := True;
153 end;
154end;
155
156procedure TCore.LoadConfig;
157begin
158 FormMain.LoadConfig;
159
160 with TRegistryEx.Create do
161 try
162 RootKey := HKEY_CURRENT_USER;
163 OpenKey(DefaultRegKey, True);
164 ScaleDPI1.DPI := Point(ReadIntegerWithDefault('DPIX', 96), ReadIntegerWithDefault('DPIY', 96));
165 ScaleDPI1.AutoDetect := ReadBoolWithDefault('DPIAuto', True);
166 finally
167 Free;
168 end;
169end;
170
171procedure TCore.SaveConfig;
172begin
173 FormMain.SaveConfig;
174
175 with TRegistryEx.Create do
176 try
177 RootKey := HKEY_CURRENT_USER;
178 OpenKey(DefaultRegKey, True);
179 WriteInteger('DPIX', ScaleDPI1.DPI.X);
180 WriteInteger('DPIY', ScaleDPI1.DPI.Y);
181 WriteBool('DPIAuto', ScaleDPI1.AutoDetect);
182 finally
183 Free;
184 end;
185end;
186
187procedure TCore.ScaleDPI;
188begin
189 // TODO: Transparent image scaling not working properly under linux Gtk2
190 // Also screen DPI is not correctly detected under linux Gtk2
191 {$IFDEF WINDOWS}
192 Core.ScaleDPI1.ScaleImageList(ImageList1, Core.ScaleDPI1.DesignDPI);
193 Core.ScaleDPI1.ScaleControl(FormMain.ToolBar1, Core.ScaleDPI1.DesignDPI);
194 {$ENDIF}
195end;
196
197function TCore.FindFirstNonOption: string;
198var
199 S: string;
200 I: Integer;
201begin
202 Result := '';
203 for I := 1 to Application.ParamCount do begin
204 S := Application.Params[I];
205 if S[1] = Application.OptionChar then Continue;
206 Result := S;
207 Break;
208 end;
209end;
210
211
212
213end.
214
Note: See TracBrowser for help on using the repository browser.