My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes  
Changes to /trunk/source/connections.pas
r4171 vs. r4172 Compare: vs.  Format:
Revision r4172
Go to: 
/trunk/source/connections.pas   r4171 /trunk/source/connections.pas   r4172
1 unit connections; 1 unit connections;
2 2
3 3
4 // ------------------------------------- 4 // -------------------------------------
5 // Connections (start-window) 5 // Connections (start-window)
6 // ------------------------------------- 6 // -------------------------------------
7 7
8 8
9 interface 9 interface
10 10
11 uses 11 uses
12 Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, 12 Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
13 VirtualTrees, Menus, Graphics, Generics.Collections, ActiveX, 13 VirtualTrees, Menus, Graphics, Generics.Collections, ActiveX,
14 dbconnection; 14 dbconnection;
15 15
16 type 16 type
17 Tconnform = class(TForm) 17 Tconnform = class(TForm)
18 btnCancel: TButton; 18 btnCancel: TButton;
19 btnOpen: TButton; 19 btnOpen: TButton;
20 btnSave: TButton; 20 btnSave: TButton;
21 ListSessions: TVirtualStringTree; 21 ListSessions: TVirtualStringTree;
22 btnNew: TButton; 22 btnNew: TButton;
23 btnDelete: TButton; 23 btnDelete: TButton;
24 popupSessions: TPopupMenu; 24 popupSessions: TPopupMenu;
25 menuSave: TMenuItem; 25 menuSave: TMenuItem;
26 menuDelete: TMenuItem; 26 menuDelete: TMenuItem;
27 menuSaveAs: TMenuItem; 27 menuSaveAs: TMenuItem;
28 TimerStatistics: TTimer; 28 TimerStatistics: TTimer;
29 PageControlDetails: TPageControl; 29 PageControlDetails: TPageControl;
30 tabSettings: TTabSheet; 30 tabSettings: TTabSheet;
31 lblStartupScript: TLabel; 31 lblStartupScript: TLabel;
32 lblPort: TLabel; 32 lblPort: TLabel;
33 lblPassword: TLabel; 33 lblPassword: TLabel;
34 lblHost: TLabel; 34 lblHost: TLabel;
35 lblUsername: TLabel; 35 lblUsername: TLabel;
36 lblNetworkType: TLabel; 36 lblNetworkType: TLabel;
37 editStartupScript: TButtonedEdit; 37 editStartupScript: TButtonedEdit;
38 chkCompressed: TCheckBox; 38 chkCompressed: TCheckBox;
39 editPort: TEdit; 39 editPort: TEdit;
40 updownPort: TUpDown; 40 updownPort: TUpDown;
41 editPassword: TEdit; 41 editPassword: TEdit;
42 editUsername: TEdit; 42 editUsername: TEdit;
43 editHost: TEdit; 43 editHost: TEdit;
44 tabSSLOptions: TTabSheet; 44 tabSSLOptions: TTabSheet;
45 lblSSLPrivateKey: TLabel; 45 lblSSLPrivateKey: TLabel;
46 lblSSLCACertificate: TLabel; 46 lblSSLCACertificate: TLabel;
47 lblSSLCertificate: TLabel; 47 lblSSLCertificate: TLabel;
48 editSSLPrivateKey: TButtonedEdit; 48 editSSLPrivateKey: TButtonedEdit;
49 editSSLCACertificate: TButtonedEdit; 49 editSSLCACertificate: TButtonedEdit;
50 editSSLCertificate: TButtonedEdit; 50 editSSLCertificate: TButtonedEdit;
51 tabStatistics: TTabSheet; 51 tabStatistics: TTabSheet;
52 lblLastConnectLeft: TLabel; 52 lblLastConnectLeft: TLabel;
53 lblCounterLeft: TLabel; 53 lblCounterLeft: TLabel;
54 lblCreatedLeft: TLabel; 54 lblCreatedLeft: TLabel;
55 lblCreatedRight: TLabel; 55 lblCreatedRight: TLabel;
56 lblCounterRight: TLabel; 56 lblCounterRight: TLabel;
57 lblLastConnectRight: TLabel; 57 lblLastConnectRight: TLabel;
58 tabSSHtunnel: TTabSheet; 58 tabSSHtunnel: TTabSheet;
59 editSSHlocalport: TEdit; 59 editSSHlocalport: TEdit;
60 editSSHUser: TEdit; 60 editSSHUser: TEdit;
61 editSSHPassword: TEdit; 61 editSSHPassword: TEdit;
62 lblSSHLocalPort: TLabel; 62 lblSSHLocalPort: TLabel;
63 lblSSHUser: TLabel; 63 lblSSHUser: TLabel;
64 lblSSHPassword: TLabel; 64 lblSSHPassword: TLabel;
65 editSSHPlinkExe: TButtonedEdit; 65 editSSHPlinkExe: TButtonedEdit;
66 lblSSHPlinkExe: TLabel; 66 lblSSHPlinkExe: TLabel;
67 comboNetType: TComboBox; 67 comboNetType: TComboBox;
68 lblSSHhost: TLabel; 68 lblSSHhost: TLabel;
69 editSSHhost: TEdit; 69 editSSHhost: TEdit;
70 editSSHport: TEdit; 70 editSSHport: TEdit;
71 editSSHPrivateKey: TButtonedEdit; 71 editSSHPrivateKey: TButtonedEdit;
72 lblSSHkeyfile: TLabel; 72 lblSSHkeyfile: TLabel;
73 lblDownloadPlink: TLabel; 73 lblDownloadPlink: TLabel;
74 comboDatabases: TComboBox; 74 comboDatabases: TComboBox;
75 lblDatabase: TLabel; 75 lblDatabase: TLabel;
76 chkLoginPrompt: TCheckBox; 76 chkLoginPrompt: TCheckBox;
77 lblPlinkTimeout: TLabel; 77 lblPlinkTimeout: TLabel;
78 editSSHTimeout: TEdit; 78 editSSHTimeout: TEdit;
79 updownSSHTimeout: TUpDown; 79 updownSSHTimeout: TUpDown;
80 chkWindowsAuth: TCheckBox; 80 chkWindowsAuth: TCheckBox;
81 splitterMain: TSplitter; 81 splitterMain: TSplitter;
82 tabStart: TTabSheet; 82 tabStart: TTabSheet;
83 lblHelp: TLabel; 83 lblHelp: TLabel;
84 chkWantSSL: TCheckBox; 84 chkWantSSL: TCheckBox;
85 btnImportSettings: TButton; 85 btnImportSettings: TButton;
86 timerSettingsImport: TTimer; 86 timerSettingsImport: TTimer;
87 chkLocalTimeZone: TCheckBox; 87 chkLocalTimeZone: TCheckBox;
88 popupNew: TPopupMenu; 88 popupNew: TPopupMenu;
89 menuNewSession: TMenuItem; 89 menuNewSession: TMenuItem;
90 menuNewFolder: TMenuItem; 90 menuNewFolder: TMenuItem;
91 menuNewFolder2: TMenuItem; 91 menuNewFolder2: TMenuItem;
92 menuNewSession2: TMenuItem; 92 menuNewSession2: TMenuItem;
93 procedure FormCreate(Sender: TObject); 93 procedure FormCreate(Sender: TObject);
94 procedure btnOpenClick(Sender: TObject); 94 procedure btnOpenClick(Sender: TObject);
95 procedure FormShow(Sender: TObject); 95 procedure FormShow(Sender: TObject);
96 procedure btnSaveClick(Sender: TObject); 96 procedure btnSaveClick(Sender: TObject);
97 procedure btnSaveAsClick(Sender: TObject); 97 procedure btnSaveAsClick(Sender: TObject);
98 procedure btnNewClick(Sender: TObject); 98 procedure btnNewClick(Sender: TObject);
99 procedure btnDeleteClick(Sender: TObject); 99 procedure btnDeleteClick(Sender: TObject);
100 procedure Modification(Sender: TObject); 100 procedure Modification(Sender: TObject);
101 procedure ListSessionsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 101 procedure ListSessionsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
102 Column: TColumnIndex; TextType: TVSTTextType; var CellText: String); 102 Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
103 procedure ListSessionsFocusChanged(Sender: TBaseVirtualTree; 103 procedure ListSessionsFocusChanged(Sender: TBaseVirtualTree;
104 Node: PVirtualNode; Column: TColumnIndex); 104 Node: PVirtualNode; Column: TColumnIndex);
105 procedure ListSessionsGetImageIndex(Sender: TBaseVirtualTree; 105 procedure ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
106 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; 106 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
107 var Ghosted: Boolean; var ImageIndex: Integer); 107 var Ghosted: Boolean; var ImageIndex: Integer);
108 procedure ListSessionsNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; 108 procedure ListSessionsNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
109 Column: TColumnIndex; NewText: String); 109 Column: TColumnIndex; NewText: String);
110 procedure ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode, 110 procedure ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode,
111 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; 111 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
112 var Allowed: Boolean); 112 var Allowed: Boolean);
113 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 113 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
114 procedure FormDestroy(Sender: TObject); 114 procedure FormDestroy(Sender: TObject);
115 procedure TimerStatisticsTimer(Sender: TObject); 115 procedure TimerStatisticsTimer(Sender: TObject);
116 procedure FormClose(Sender: TObject; var Action: TCloseAction); 116 procedure FormClose(Sender: TObject; var Action: TCloseAction);
117 procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; 117 procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
118 out EditLink: IVTEditLink); 118 out EditLink: IVTEditLink);
119 procedure PickFile(Sender: TObject); 119 procedure PickFile(Sender: TObject);
120 procedure editSSHPlinkExeChange(Sender: TObject); 120 procedure editSSHPlinkExeChange(Sender: TObject);
121 procedure editHostChange(Sender: TObject); 121 procedure editHostChange(Sender: TObject);
122 procedure lblDownloadPlinkClick(Sender: TObject); 122 procedure lblDownloadPlinkClick(Sender: TObject);
123 procedure comboDatabasesDropDown(Sender: TObject); 123 procedure comboDatabasesDropDown(Sender: TObject);
124 procedure chkLoginPromptClick(Sender: TObject); 124 procedure chkLoginPromptClick(Sender: TObject);
125 procedure ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree; 125 procedure ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
126 var NodeDataSize: Integer); 126 var NodeDataSize: Integer);
127 procedure comboNetTypeChange(Sender: TObject); 127 procedure comboNetTypeChange(Sender: TObject);
128 procedure splitterMainMoved(Sender: TObject); 128 procedure splitterMainMoved(Sender: TObject);
129 procedure btnImportSettingsClick(Sender: TObject); 129 procedure btnImportSettingsClick(Sender: TObject);
130 procedure timerSettingsImportTimer(Sender: TObject); 130 procedure timerSettingsImportTimer(Sender: TObject);
131 procedure ListSessionsStructureChange(Sender: TBaseVirtualTree; 131 procedure ListSessionsStructureChange(Sender: TBaseVirtualTree;
132 Node: PVirtualNode; Reason: TChangeReason); 132 Node: PVirtualNode; Reason: TChangeReason);
133 procedure ListSessionsDragOver(Sender: TBaseVirtualTree; Source: TObject; 133 procedure ListSessionsDragOver(Sender: TBaseVirtualTree; Source: TObject;
134 Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode; 134 Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode;
135 var Effect: Integer; var Accept: Boolean); 135 var Effect: Integer; var Accept: Boolean);
136 procedure ListSessionsDragDrop(Sender: TBaseVirtualTree; Source: TObject; 136 procedure ListSessionsDragDrop(Sender: TBaseVirtualTree; Source: TObject;
137 DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState; 137 DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState;
138 Pt: TPoint; var Effect: Integer; Mode: TDropMode); 138 Pt: TPoint; var Effect: Integer; Mode: TDropMode);
139 private 139 private
140 { Private declarations } 140 { Private declarations }
141 FLoaded: Boolean; 141 FLoaded: Boolean;
142 FSessionModified, FOnlyPasswordModified: Boolean; 142 FSessionModified, FOnlyPasswordModified: Boolean;
143 FServerVersion: String; 143 FServerVersion: String;
144 FSessionColor: TColor; 144 FSessionColor: TColor;
145 FSettingsImportWaitTime: Cardinal; 145 FSettingsImportWaitTime: Cardinal;
146 procedure RefreshSessions(ParentNode: PVirtualNode); 146 procedure RefreshSessions(ParentNode: PVirtualNode);
147 function SelectedSessionPath: String; 147 function SelectedSessionPath: String;
148 function CurrentParams: TConnectionParameters; 148 function CurrentParams: TConnectionParameters;
149 procedure FinalizeModifications(var CanProceed: Boolean); 149 procedure FinalizeModifications(var CanProceed: Boolean);
150 procedure ValidateControls; 150 procedure ValidateControls;
151 function NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList; 151 function NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList;
152 public 152 public
153 { Public declarations } 153 { Public declarations }
154 end; 154 end;
155 155
156 156
157 implementation 157 implementation
158 158
159 uses Main, helpers, grideditlinks; 159 uses Main, helpers, grideditlinks;
160 160
161 {$I const.inc} 161 {$I const.inc}
162 162
163 {$R *.DFM} 163 {$R *.DFM}
164 164
165 165
166 procedure Tconnform.FormCreate(Sender: TObject); 166 procedure Tconnform.FormCreate(Sender: TObject);
167 var 167 var
168 LastActiveSession: String; 168 LastActiveSession: String;
169 LastSessions: TStringList; 169 LastSessions: TStringList;
170 PSess: PConnectionParameters; 170 PSess: PConnectionParameters;
171 hSysMenu: THandle; 171 hSysMenu: THandle;
172 nt: TNetType; 172 nt: TNetType;
173 Node: PVirtualNode; 173 Node: PVirtualNode;
174 Params: TConnectionParameters; 174 Params: TConnectionParameters;
175 begin 175 begin
176 // Fix GUI stuff 176 // Fix GUI stuff
177 InheritFont(Font); 177 InheritFont(Font);
178 SetWindowSizeGrip(Handle, True); 178 SetWindowSizeGrip(Handle, True);
179 Width := AppSettings.ReadInt(asSessionManagerWindowWidth); 179 Width := AppSettings.ReadInt(asSessionManagerWindowWidth);
180 Height := AppSettings.ReadInt(asSessionManagerWindowHeight); 180 Height := AppSettings.ReadInt(asSessionManagerWindowHeight);
181 ListSessions.Width := AppSettings.ReadInt(asSessionManagerListWidth); 181 ListSessions.Width := AppSettings.ReadInt(asSessionManagerListWidth);
182 splitterMain.OnMoved(Sender); 182 splitterMain.OnMoved(Sender);
183 FixVT(ListSessions); 183 FixVT(ListSessions);
184 MainForm.RestoreListSetup(ListSessions); 184 MainForm.RestoreListSetup(ListSessions);
185 ListSessions.OnCompareNodes := MainForm.AnyGridCompareNodes; 185 ListSessions.OnCompareNodes := MainForm.AnyGridCompareNodes;
186 ListSessions.OnHeaderClick := MainForm.AnyGridHeaderClick; 186 ListSessions.OnHeaderClick := MainForm.AnyGridHeaderClick;
187 ListSessions.OnHeaderDraggedOut := MainForm.AnyGridHeaderDraggedOut; 187 ListSessions.OnHeaderDraggedOut := MainForm.AnyGridHeaderDraggedOut;
188 btnImportSettings.Caption := MainForm.actImportSettings.Caption; 188 btnImportSettings.Caption := MainForm.actImportSettings.Caption;
189 FLoaded := False; 189 FLoaded := False;
190 190
191 comboNetType.Clear; 191 comboNetType.Clear;
192 Params := TConnectionParameters.Create; 192 Params := TConnectionParameters.Create;
193 for nt:=Low(nt) to High(nt) do 193 for nt:=Low(nt) to High(nt) do
194 comboNetType.Items.Add(Params.NetTypeName(nt, True)); 194 comboNetType.Items.Add(Params.NetTypeName(nt, True));
195 Params.Free; 195 Params.Free;
196 196
197 // Init sessions tree 197 // Init sessions tree
198 RefreshSessions(nil); 198 RefreshSessions(nil);
199 199
200 // Focus last session 200 // Focus last session
201 SelectNode(ListSessions, nil); 201 SelectNode(ListSessions, nil);
202 LastSessions := Explode(DELIM, AppSettings.ReadString(asLastSessions)); 202 LastSessions := Explode(DELIM, AppSettings.ReadString(asLastSessions));
203 LastActiveSession := AppSettings.ReadString(asLastActiveSession); 203 LastActiveSession := AppSettings.ReadString(asLastActiveSession);
204 if (LastActiveSession = '') and (LastSessions.Count > 0) then 204 if (LastActiveSession = '') and (LastSessions.Count > 0) then
205 LastActiveSession := LastSessions[0]; 205 LastActiveSession := LastSessions[0];
206 Node := ListSessions.GetFirst; 206 Node := ListSessions.GetFirst;
207 while Assigned(Node) do begin 207 while Assigned(Node) do begin
208 PSess := ListSessions.GetNodeData(Node); 208 PSess := ListSessions.GetNodeData(Node);
209 if PSess.SessionPath = LastActiveSession then 209 if PSess.SessionPath = LastActiveSession then
210 SelectNode(ListSessions, Node); 210 SelectNode(ListSessions, Node);
211 Node := ListSessions.GetNext(Node); 211 Node := ListSessions.GetNext(Node);
212 end; 212 end;
213 213
214 // Add own menu items to system menu 214 // Add own menu items to system menu
215 hSysMenu := GetSystemMenu(Handle, False); 215 hSysMenu := GetSystemMenu(Handle, False);
216 AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0); 216 AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0);
217 AppendMenu(hSysMenu, MF_STRING, MSG_UPDATECHECK, PChar(Mainform.actUpdateCheck.Caption)); 217 AppendMenu(hSysMenu, MF_STRING, MSG_UPDATECHECK, PChar(Mainform.actUpdateCheck.Caption));
218 AppendMenu(hSysMenu, MF_STRING, MSG_PREFERENCES, PChar(Mainform.actPreferences.Caption)); 218 AppendMenu(hSysMenu, MF_STRING, MSG_PREFERENCES, PChar(Mainform.actPreferences.Caption));
219 AppendMenu(hSysMenu, MF_STRING, MSG_ABOUT, PChar(Mainform.actAboutBox.Caption)); 219 AppendMenu(hSysMenu, MF_STRING, MSG_ABOUT, PChar(Mainform.actAboutBox.Caption));
220 end; 220 end;
221 221
222 222
223 procedure Tconnform.RefreshSessions(ParentNode: PVirtualNode); 223 procedure Tconnform.RefreshSessions(ParentNode: PVirtualNode);
224 var 224 var
225 SessionNames: TStringList; 225 SessionNames: TStringList;
226 RegKey: String; 226 RegKey: String;
227 i: Integer; 227 i: Integer;
228 Params: TConnectionParameters; 228 Params: TConnectionParameters;
229 SessNode: PVirtualNode; 229 SessNode: PVirtualNode;
230 begin 230 begin
231 // Initialize session tree 231 // Initialize session tree
232 if ParentNode=nil then 232 if ParentNode=nil then
233 ListSessions.Clear 233 ListSessions.Clear
234 else 234 else
235 ListSessions.DeleteChildren(ParentNode, True); 235 ListSessions.DeleteChildren(ParentNode, True);
236 SessionNames := NodeSessionNames(ParentNode, RegKey); 236 SessionNames := NodeSessionNames(ParentNode, RegKey);
237 for i:=0 to SessionNames.Count-1 do begin 237 for i:=0 to SessionNames.Count-1 do begin
238 Params := TConnectionParameters.Create(RegKey+SessionNames[i]); 238 Params := TConnectionParameters.Create(RegKey+SessionNames[i]);
239 SessNode := ListSessions.AddChild(ParentNode, PConnectionParameters(Params)); 239 SessNode := ListSessions.AddChild(ParentNode, PConnectionParameters(Params));
240 if Params.IsFolder then 240 if Params.IsFolder then
241 RefreshSessions(SessNode); 241 RefreshSessions(SessNode);
242 end; 242 end;
243 end; 243 end;
244 244
245 245
246 procedure Tconnform.FormDestroy(Sender: TObject); 246 procedure Tconnform.FormDestroy(Sender: TObject);
247 begin 247 begin
248 // Save GUI stuff 248 // Save GUI stuff
249 AppSettings.WriteInt(asSessionManagerListWidth, ListSessions.Width); 249 AppSettings.WriteInt(asSessionManagerListWidth, ListSessions.Width);
250 AppSettings.WriteInt(asSessionManagerWindowWidth, Width); 250 AppSettings.WriteInt(asSessionManagerWindowWidth, Width);
251 AppSettings.WriteInt(asSessionManagerWindowHeight, Height); 251 AppSettings.WriteInt(asSessionManagerWindowHeight, Height);
252 MainForm.SaveListSetup(ListSessions); 252 MainForm.SaveListSetup(ListSessions);
253 end; 253 end;
254 254
255 255
256 procedure Tconnform.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 256 procedure Tconnform.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
257 begin 257 begin
258 // Modifications? Ask if they should be saved. 258 // Modifications? Ask if they should be saved.
259 FinalizeModifications(CanClose); 259 FinalizeModifications(CanClose);
260 end; 260 end;
261 261
262 262
263 procedure Tconnform.FormClose(Sender: TObject; var Action: TCloseAction); 263 procedure Tconnform.FormClose(Sender: TObject; var Action: TCloseAction);
264 begin 264 begin
265 // Suspend calculating statistics as long as they're not visible 265 // Suspend calculating statistics as long as they're not visible
266 TimerStatistics.Enabled := False; 266 TimerStatistics.Enabled := False;
267 Action := caFree; 267 Action := caFree;
268 end; 268 end;
269 269
270 270
271 procedure Tconnform.FormShow(Sender: TObject); 271 procedure Tconnform.FormShow(Sender: TObject);
272 begin 272 begin
273 ListSessions.SetFocus; 273 ListSessions.SetFocus;
274 // Reactivate statistics 274 // Reactivate statistics
275 TimerStatistics.Enabled := True; 275 TimerStatistics.Enabled := True;
276 TimerStatistics.OnTimer(Sender); 276 TimerStatistics.OnTimer(Sender);
277 FLoaded := True; 277 FLoaded := True;
278 end; 278 end;
279 279
280 280
281 procedure Tconnform.btnOpenClick(Sender: TObject); 281 procedure Tconnform.btnOpenClick(Sender: TObject);
282 var 282 var
283 Connection: TDBConnection; 283 Connection: TDBConnection;
284 begin 284 begin
285 // Connect to selected session 285 // Connect to selected session
286 if not btnOpen.Enabled then 286 if not btnOpen.Enabled then
287 Exit; 287 Exit;
288 Screen.Cursor := crHourglass; 288 Screen.Cursor := crHourglass;
289 if Mainform.InitConnection(CurrentParams, True, Connection) then 289 if Mainform.InitConnection(CurrentParams, True, Connection) then
290 ModalResult := mrOK 290 ModalResult := mrOK
291 else begin 291 else begin
292 TimerStatistics.OnTimer(Sender); 292 TimerStatistics.OnTimer(Sender);
293 ModalResult := mrNone; 293 ModalResult := mrNone;
294 end; 294 end;
295 Screen.Cursor := crDefault; 295 Screen.Cursor := crDefault;
296 end; 296 end;
297 297
298 298
299 procedure Tconnform.btnSaveClick(Sender: TObject); 299 procedure Tconnform.btnSaveClick(Sender: TObject);
300 var 300 var
301 Sess: PConnectionParameters; 301 Sess: PConnectionParameters;
302 begin 302 begin
303 // Overtake edited values for current parameter object and save to registry 303 // Overtake edited values for current parameter object and save to registry
304 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 304 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
305 Sess.Hostname := editHost.Text; 305 Sess.Hostname := editHost.Text;
306 Sess.Username := editUsername.Text; 306 Sess.Username := editUsername.Text;
307 Sess.Password := editPassword.Text; 307 Sess.Password := editPassword.Text;
308 Sess.LoginPrompt := chkLoginPrompt.Checked; 308 Sess.LoginPrompt := chkLoginPrompt.Checked;
309 Sess.WindowsAuth := chkWindowsAuth.Checked; 309 Sess.WindowsAuth := chkWindowsAuth.Checked;
310 Sess.Port := updownPort.Position; 310 Sess.Port := updownPort.Position;
311 Sess.NetType := TNetType(comboNetType.ItemIndex); 311 Sess.NetType := TNetType(comboNetType.ItemIndex);
312 Sess.Compressed := chkCompressed.Checked; 312 Sess.Compressed := chkCompressed.Checked;
313 Sess.LocalTimeZone := chkLocalTimeZone.Checked; 313 Sess.LocalTimeZone := chkLocalTimeZone.Checked;
314 Sess.AllDatabasesStr := comboDatabases.Text; 314 Sess.AllDatabasesStr := comboDatabases.Text;
315 Sess.StartupScriptFilename := editStartupScript.Text; 315 Sess.StartupScriptFilename := editStartupScript.Text;
316 Sess.SSHPlinkExe := editSSHPlinkExe.Text;
316 Sess.SSHHost := editSSHhost.Text; 317 Sess.SSHHost := editSSHhost.Text;
317 Sess.SSHPort := MakeInt(editSSHport.Text); 318 Sess.SSHPort := MakeInt(editSSHport.Text);
318 Sess.SSHUser := editSSHUser.Text; 319 Sess.SSHUser := editSSHUser.Text;
319 Sess.SSHPassword := editSSHPassword.Text; 320 Sess.SSHPassword := editSSHPassword.Text;
320 Sess.SSHTimeout := updownSSHTimeout.Position; 321 Sess.SSHTimeout := updownSSHTimeout.Position;
321 Sess.SSHPrivateKey := editSSHPrivateKey.Text; 322 Sess.SSHPrivateKey := editSSHPrivateKey.Text;
322 Sess.SSHLocalPort := MakeInt(editSSHlocalport.Text); 323 Sess.SSHLocalPort := MakeInt(editSSHlocalport.Text);
323 Sess.WantSSL := chkWantSSL.Checked; 324 Sess.WantSSL := chkWantSSL.Checked;
324 Sess.SSLPrivateKey := editSSLPrivateKey.Text; 325 Sess.SSLPrivateKey := editSSLPrivateKey.Text;
325 Sess.SSLCertificate := editSSLCertificate.Text; 326 Sess.SSLCertificate := editSSLCertificate.Text;
326 Sess.SSLCACertificate := editSSLCACertificate.Text; 327 Sess.SSLCACertificate := editSSLCACertificate.Text;
327 Sess.SaveToRegistry; 328 Sess.SaveToRegistry;
328 329
329 FSessionModified := False; 330 FSessionModified := False;
330 ListSessions.Invalidate; 331 ListSessions.Invalidate;
331 ValidateControls; 332 ValidateControls;
332 end; 333 end;
333 334
334 335
335 procedure Tconnform.btnSaveAsClick(Sender: TObject); 336 procedure Tconnform.btnSaveAsClick(Sender: TObject);
336 var 337 var
337 newName, ParentKey: String; 338 newName, ParentKey: String;
338 NameOK: Boolean; 339 NameOK: Boolean;
339 NewSess: TConnectionParameters; 340 NewSess: TConnectionParameters;
340 Node: PVirtualNode; 341 Node: PVirtualNode;
341 SessionNames: TStringList; 342 SessionNames: TStringList;
342 begin 343 begin
343 // Save session as ... 344 // Save session as ...
344 newName := 'Enter new session name ...'; 345 newName := 'Enter new session name ...';
345 NameOK := False; 346 NameOK := False;
346 SessionNames := NodeSessionNames(ListSessions.FocusedNode.Parent, ParentKey); 347 SessionNames := NodeSessionNames(ListSessions.FocusedNode.Parent, ParentKey);
347 while not NameOK do begin 348 while not NameOK do begin
348 if not InputQuery('Clone session ...', 'New session name:', newName) then 349 if not InputQuery('Clone session ...', 'New session name:', newName) then
349 Exit; // Cancelled 350 Exit; // Cancelled
350 NameOK := SessionNames.IndexOf(newName) = -1; 351 NameOK := SessionNames.IndexOf(newName) = -1;
351 if not NameOK then 352 if not NameOK then
352 ErrorDialog('Session name '''+ParentKey+newName+''' already in use.') 353 ErrorDialog('Session name '''+ParentKey+newName+''' already in use.')
353 else begin 354 else begin
354 // Create the key and save its values 355 // Create the key and save its values
355 NewSess := CurrentParams; 356 NewSess := CurrentParams;
356 NewSess.SessionPath := ParentKey+newName; 357 NewSess.SessionPath := ParentKey+newName;
357 NewSess.SaveToRegistry; 358 NewSess.SaveToRegistry;
358 Node := ListSessions.InsertNode(ListSessions.FocusedNode, amInsertAfter, PConnectionParameters(NewSess)); 359 Node := ListSessions.InsertNode(ListSessions.FocusedNode, amInsertAfter, PConnectionParameters(NewSess));
359 FSessionModified := False; 360 FSessionModified := False;
360 SelectNode(ListSessions, Node); 361 SelectNode(ListSessions, Node);
361 end; 362 end;
362 end; 363 end;
363 SessionNames.Free; 364 SessionNames.Free;
364 end; 365 end;
365 366
366 367
367 procedure Tconnform.btnImportSettingsClick(Sender: TObject); 368 procedure Tconnform.btnImportSettingsClick(Sender: TObject);
368 begin 369 begin
369 MainForm.actImportSettings.Execute; 370 MainForm.actImportSettings.Execute;
370 FSettingsImportWaitTime := 0; 371 FSettingsImportWaitTime := 0;
371 timerSettingsImport.Enabled := MainForm.ImportSettingsDone; 372 timerSettingsImport.Enabled := MainForm.ImportSettingsDone;
372 end; 373 end;
373 374
374 375
375 procedure Tconnform.timerSettingsImportTimer(Sender: TObject); 376 procedure Tconnform.timerSettingsImportTimer(Sender: TObject);
376 begin 377 begin
377 Inc(FSettingsImportWaitTime, timerSettingsImport.Interval); 378 Inc(FSettingsImportWaitTime, timerSettingsImport.Interval);
378 RefreshSessions(nil); 379 RefreshSessions(nil);
379 if ListSessions.RootNodeCount > 0 then 380 if ListSessions.RootNodeCount > 0 then
380 timerSettingsImport.Enabled := False; 381 timerSettingsImport.Enabled := False;
381 if FSettingsImportWaitTime >= 10000 then begin 382 if FSettingsImportWaitTime >= 10000 then begin
382 timerSettingsImport.Enabled := False; 383 timerSettingsImport.Enabled := False;
383 MessageDialog('Imported sessions could not be detected. Restarting HeidiSQL may solve that.', mtWarning, [mbOK]); 384 MessageDialog('Imported sessions could not be detected. Restarting HeidiSQL may solve that.', mtWarning, [mbOK]);
384 end; 385 end;
385 end; 386 end;
386 387
387 388
388 procedure Tconnform.btnNewClick(Sender: TObject); 389 procedure Tconnform.btnNewClick(Sender: TObject);
389 var 390 var
390 i: Integer; 391 i: Integer;
391 CanProceed: Boolean; 392 CanProceed: Boolean;
392 NewSess: TConnectionParameters; 393 NewSess: TConnectionParameters;
393 ParentSess: PConnectionParameters; 394 ParentSess: PConnectionParameters;
394 ParentNode, NewNode: PVirtualNode; 395 ParentNode, NewNode: PVirtualNode;
395 ParentPath: String; 396 ParentPath: String;
396 SiblingSessionNames: TStringList; 397 SiblingSessionNames: TStringList;
397 begin 398 begin
398 // Create new session or folder 399 // Create new session or folder
399 FinalizeModifications(CanProceed); 400 FinalizeModifications(CanProceed);
400 if not CanProceed then 401 if not CanProceed then
401 Exit; 402 Exit;
402 403
403 ParentSess := ListSessions.GetNodeData(ListSessions.FocusedNode); 404 ParentSess := ListSessions.GetNodeData(ListSessions.FocusedNode);
404 if ParentSess = nil then 405 if ParentSess = nil then
405 ParentNode := nil 406 ParentNode := nil
406 else if ParentSess.IsFolder then 407 else if ParentSess.IsFolder then
407 ParentNode := ListSessions.FocusedNode 408 ParentNode := ListSessions.FocusedNode
408 else 409 else
409 ParentNode := ListSessions.FocusedNode.Parent; 410 ParentNode := ListSessions.FocusedNode.Parent;
410 SiblingSessionNames := NodeSessionNames(ParentNode, ParentPath); 411 SiblingSessionNames := NodeSessionNames(ParentNode, ParentPath);
411 412
412 NewSess := TConnectionParameters.Create; 413 NewSess := TConnectionParameters.Create;
413 NewSess.IsFolder := (Sender = menuNewFolder) or (Sender = menuNewFolder2); 414 NewSess.IsFolder := (Sender = menuNewFolder) or (Sender = menuNewFolder2);
414 NewSess.SessionPath := ParentPath + 'Unnamed'; 415 NewSess.SessionPath := ParentPath + 'Unnamed';
415 i := 0; 416 i := 0;
416 while SiblingSessionNames.IndexOf(NewSess.SessionName) > -1 do begin 417 while SiblingSessionNames.IndexOf(NewSess.SessionName) > -1 do begin
417 inc(i); 418 inc(i);
418 NewSess.SessionPath := ParentPath + 'Unnamed-' + IntToStr(i); 419 NewSess.SessionPath := ParentPath + 'Unnamed-' + IntToStr(i);
419 end; 420 end;
420 NewSess.SaveToRegistry; 421 NewSess.SaveToRegistry;
421 SiblingSessionNames.Free; 422 SiblingSessionNames.Free;
422 NewNode := ListSessions.AddChild(ParentNode, PConnectionParameters(NewSess)); 423 NewNode := ListSessions.AddChild(ParentNode, PConnectionParameters(NewSess));
423 // Select it 424 // Select it
424 SelectNode(ListSessions, NewNode); 425 SelectNode(ListSessions, NewNode);
425 ValidateControls; 426 ValidateControls;
426 ListSessions.EditNode(NewNode, 0); 427 ListSessions.EditNode(NewNode, 0);
427 end; 428 end;
428 429
429 430
430 procedure Tconnform.btnDeleteClick(Sender: TObject); 431 procedure Tconnform.btnDeleteClick(Sender: TObject);
431 var 432 var
432 Sess: PConnectionParameters; 433 Sess: PConnectionParameters;
433 Node, FocusNode: PVirtualNode; 434 Node, FocusNode: PVirtualNode;
434 begin 435 begin
435 Node := ListSessions.FocusedNode; 436 Node := ListSessions.FocusedNode;
436 Sess := ListSessions.GetNodeData(Node); 437 Sess := ListSessions.GetNodeData(Node);
437 if MessageDialog('Delete session "' + Sess.SessionName + '" ?', mtConfirmation, [mbYes, mbCancel]) = mrYes then 438 if MessageDialog('Delete session "' + Sess.SessionName + '" ?', mtConfirmation, [mbYes, mbCancel]) = mrYes then
438 begin 439 begin
439 AppSettings.SessionPath := Sess.SessionPath; 440 AppSettings.SessionPath := Sess.SessionPath;
440 AppSettings.DeleteCurrentKey; 441 AppSettings.DeleteCurrentKey;
441 if Assigned(Node.NextSibling) then 442 if Assigned(Node.NextSibling) then
442 FocusNode := Node.NextSibling 443 FocusNode := Node.NextSibling
443 else if Assigned(Node.PrevSibling) then 444 else if Assigned(Node.PrevSibling) then
444 FocusNode := Node.PrevSibling 445 FocusNode := Node.PrevSibling
445 else 446 else
446 FocusNode := Node.Parent; 447 FocusNode := Node.Parent;
447 ListSessions.DeleteNode(Node); 448 ListSessions.DeleteNode(Node);
448 SelectNode(ListSessions, FocusNode); 449 SelectNode(ListSessions, FocusNode);
449 ListSessions.SetFocus; 450 ListSessions.SetFocus;
450 end; 451 end;
451 end; 452 end;
452 453
453 454
454 function Tconnform.SelectedSessionPath: String; 455 function Tconnform.SelectedSessionPath: String;
455 var 456 var
456 Sess: PConnectionParameters; 457 Sess: PConnectionParameters;
457 begin 458 begin
458 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 459 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
459 Result := Sess.SessionPath; 460 Result := Sess.SessionPath;
460 end; 461 end;
461 462
462 463
463 function Tconnform.CurrentParams: TConnectionParameters; 464 function Tconnform.CurrentParams: TConnectionParameters;
464 var 465 var
465 FromReg: PConnectionParameters; 466 FromReg: PConnectionParameters;
466 begin 467 begin
467 // Return non-stored parameters 468 // Return non-stored parameters
468 FromReg := ListSessions.GetNodeData(ListSessions.FocusedNode); 469 FromReg := ListSessions.GetNodeData(ListSessions.FocusedNode);
469 if FromReg.IsFolder then begin 470 if FromReg.IsFolder then begin
470 Result := FromReg^; 471 Result := FromReg^;
471 end else begin 472 end else begin
472 Result := TConnectionParameters.Create; 473 Result := TConnectionParameters.Create;
473 Result.SessionPath := SelectedSessionPath; 474 Result.SessionPath := SelectedSessionPath;
474 Result.SessionColor := FSessionColor; 475 Result.SessionColor := FSessionColor;
475 Result.NetType := TNetType(comboNetType.ItemIndex); 476 Result.NetType := TNetType(comboNetType.ItemIndex);
476 Result.ServerVersion := FServerVersion; 477 Result.ServerVersion := FServerVersion;
477 Result.Hostname := editHost.Text; 478 Result.Hostname := editHost.Text;
478 Result.Username := editUsername.Text; 479 Result.Username := editUsername.Text;
479 Result.Password := editPassword.Text; 480 Result.Password := editPassword.Text;
480 Result.LoginPrompt := chkLoginPrompt.Checked; 481 Result.LoginPrompt := chkLoginPrompt.Checked;
481 Result.WindowsAuth := chkWindowsAuth.Checked; 482 Result.WindowsAuth := chkWindowsAuth.Checked;
482 if updownPort.Enabled then 483 if updownPort.Enabled then
483 Result.Port := updownPort.Position 484 Result.Port := updownPort.Position
484 else 485 else
485 Result.Port := 0; 486 Result.Port := 0;
486 Result.AllDatabasesStr := comboDatabases.Text; 487 Result.AllDatabasesStr := comboDatabases.Text;
487 Result.SSHHost := editSSHHost.Text; 488 Result.SSHHost := editSSHHost.Text;
488 Result.SSHPort := MakeInt(editSSHPort.Text); 489 Result.SSHPort := MakeInt(editSSHPort.Text);
489 Result.SSHUser := editSSHuser.Text; 490 Result.SSHUser := editSSHuser.Text;
490 Result.SSHPassword := editSSHpassword.Text; 491 Result.SSHPassword := editSSHpassword.Text;
491 Result.SSHTimeout := updownSSHTimeout.Position; 492 Result.SSHTimeout := updownSSHTimeout.Position;
492 Result.SSHPrivateKey := editSSHPrivateKey.Text; 493 Result.SSHPrivateKey := editSSHPrivateKey.Text;
493 Result.SSHLocalPort := MakeInt(editSSHlocalport.Text); 494 Result.SSHLocalPort := MakeInt(editSSHlocalport.Text);
494 Result.SSHPlinkExe := editSSHplinkexe.Text; 495 Result.SSHPlinkExe := editSSHplinkexe.Text;
495 Result.WantSSL := chkWantSSL.Checked; 496 Result.WantSSL := chkWantSSL.Checked;
496 Result.SSLPrivateKey := editSSLPrivateKey.Text; 497 Result.SSLPrivateKey := editSSLPrivateKey.Text;
497 Result.SSLCertificate := editSSLCertificate.Text; 498 Result.SSLCertificate := editSSLCertificate.Text;
498 Result.SSLCACertificate := editSSLCACertificate.Text; 499 Result.SSLCACertificate := editSSLCACertificate.Text;
499 Result.StartupScriptFilename := editStartupScript.Text; 500 Result.StartupScriptFilename := editStartupScript.Text;
500 Result.Compressed := chkCompressed.Checked; 501 Result.Compressed := chkCompressed.Checked;
501 Result.LocalTimeZone := chkLocalTimeZone.Checked; 502 Result.LocalTimeZone := chkLocalTimeZone.Checked;
502 end; 503 end;
503 end; 504 end;
504 505
505 506
506 procedure Tconnform.ListSessionsGetImageIndex(Sender: TBaseVirtualTree; 507 procedure Tconnform.ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
507 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; 508 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
508 var Ghosted: Boolean; var ImageIndex: Integer); 509 var Ghosted: Boolean; var ImageIndex: Integer);
509 var 510 var
510 Sess: PConnectionParameters; 511 Sess: PConnectionParameters;
511 begin 512 begin
512 // An edited session gets an additional pencil symbol 513 // An edited session gets an additional pencil symbol
513 if Column > 0 then 514 if Column > 0 then
514 ImageIndex := -1 515 ImageIndex := -1
515 else case Kind of 516 else case Kind of
516 ikNormal, ikSelected: begin 517 ikNormal, ikSelected: begin
517 Sess := Sender.GetNodeData(Node); 518 Sess := Sender.GetNodeData(Node);
518 ImageIndex := Sess.ImageIndex; 519 ImageIndex := Sess.ImageIndex;
519 end; 520 end;
520 521
521 ikOverlay: 522 ikOverlay:
522 if (Node = Sender.FocusedNode) and FSessionModified then 523 if (Node = Sender.FocusedNode) and FSessionModified then
523 ImageIndex := 162; 524 ImageIndex := 162;
524 525
525 end; 526 end;
526 end; 527 end;
527 528
528 529
529 procedure Tconnform.ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree; 530 procedure Tconnform.ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
530 var NodeDataSize: Integer); 531 var NodeDataSize: Integer);
531 begin 532 begin
532 NodeDataSize := SizeOf(TConnectionParameters); 533 NodeDataSize := SizeOf(TConnectionParameters);
533 end; 534 end;
534 535
535 536
536 procedure Tconnform.ListSessionsGetText(Sender: TBaseVirtualTree; 537 procedure Tconnform.ListSessionsGetText(Sender: TBaseVirtualTree;
537 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; 538 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
538 var CellText: String); 539 var CellText: String);
539 var 540 var
540 Sess: PConnectionParameters; 541 Sess: PConnectionParameters;
541 begin 542 begin
542 // Display session name cell 543 // Display session name cell
543 Sess := Sender.GetNodeData(Node); 544 Sess := Sender.GetNodeData(Node);
544 if Sess.IsFolder then begin 545 if Sess.IsFolder then begin
545 case Column of 546 case Column of
546 0: CellText := Sess.SessionName; 547 0: CellText := Sess.SessionName;
547 else CellText := ''; 548 else CellText := '';
548 end; 549 end;
549 end else begin 550 end else begin
550 case Column of 551 case Column of
551 0: begin 552 0: begin
552 CellText := Sess.SessionName; 553 CellText := Sess.SessionName;
553 if FSessionModified and (Node = Sender.FocusedNode) and (not Sender.IsEditing) then 554 if FSessionModified and (Node = Sender.FocusedNode) and (not Sender.IsEditing) then
554 CellText := CellText + ' *'; 555 CellText := CellText + ' *';
555 end; 556 end;
556 1: CellText := Sess.Hostname; 557 1: CellText := Sess.Hostname;
557 2: CellText := Sess.Username; 558 2: CellText := Sess.Username;
558 3: CellText := Sess.ServerVersion; 559 3: CellText := Sess.ServerVersion;
559 4: if Sess.LastConnect>0 then 560 4: if Sess.LastConnect>0 then
560 CellText := DateTimeToStr(Sess.LastConnect) 561 CellText := DateTimeToStr(Sess.LastConnect)
561 else 562 else
562 CellText := ''; 563 CellText := '';
563 5: CellText := FormatNumber(Sess.Counter); 564 5: CellText := FormatNumber(Sess.Counter);
564 end; 565 end;
565 end; 566 end;
566 end; 567 end;
567 568
568 569
569 function Tconnform.NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList; 570 function Tconnform.NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList;
570 var 571 var
571 Sess: PConnectionParameters; 572 Sess: PConnectionParameters;
572 Folders: TStringList; 573 Folders: TStringList;
573 begin 574 begin
574 // Find sibling session names in a folder node 575 // Find sibling session names in a folder node
575 576
576 if Node = nil then 577 if Node = nil then
577 Node := ListSessions.RootNode; 578 Node := ListSessions.RootNode;
578 579
579 // Find registry sub path for given node 580 // Find registry sub path for given node
580 RegKey := ''; 581 RegKey := '';
581 if Node <> ListSessions.RootNode then begin 582 if Node <> ListSessions.RootNode then begin
582 Sess := ListSessions.GetNodeData(Node); 583 Sess := ListSessions.GetNodeData(Node);
583 RegKey := Sess.SessionPath + '\'; 584 RegKey := Sess.SessionPath + '\';
584 end; 585 end;
585 586
586 // Fetch from registry 587 // Fetch from registry
587 Folders := TStringList.Create; 588 Folders := TStringList.Create;
588 Result := AppSettings.GetSessionNames(RegKey, Folders); 589 Result := AppSettings.GetSessionNames(RegKey, Folders);
589 Result.AddStrings(Folders); 590 Result.AddStrings(Folders);
590 Folders.Free; 591 Folders.Free;
591 end; 592 end;
592 593
593 594
594 procedure Tconnform.ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; 595 procedure Tconnform.ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode;
595 Column: TColumnIndex; out EditLink: IVTEditLink); 596 Column: TColumnIndex; out EditLink: IVTEditLink);
596 begin 597 begin
597 // Use our own text editor to rename a session 598 // Use our own text editor to rename a session
598 EditLink := TInplaceEditorLink.Create(Sender as TVirtualStringTree); 599 EditLink := TInplaceEditorLink.Create(Sender as TVirtualStringTree);
599 end; 600 end;
600 601
601 602
602 procedure Tconnform.ListSessionsDragDrop(Sender: TBaseVirtualTree; 603 procedure Tconnform.ListSessionsDragDrop(Sender: TBaseVirtualTree;
603 Source: TObject; DataObject: IDataObject; Formats: TFormatArray; 604 Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
604 Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode); 605 Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
605 var 606 var
606 TargetNode, ParentNode: PVirtualNode; 607 TargetNode, ParentNode: PVirtualNode;
607 AttachMode: TVTNodeAttachMode; 608 AttachMode: TVTNodeAttachMode;
608 TargetSess, FocusedSess: PConnectionParameters; 609 TargetSess, FocusedSess: PConnectionParameters;
609 ParentKey: String; 610 ParentKey: String;
610 SiblingSessions: TStringList; 611 SiblingSessions: TStringList;
611 begin 612 begin
612 TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y); 613 TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y);
613 if not Assigned(TargetNode) then begin 614 if not Assigned(TargetNode) then begin
614 MessageBeep(MB_ICONEXCLAMATION); 615 MessageBeep(MB_ICONEXCLAMATION);
615 Exit; 616 Exit;
616 end; 617 end;
617 TargetSess := Sender.GetNodeData(TargetNode); 618 TargetSess := Sender.GetNodeData(TargetNode);
618 FocusedSess := Sender.GetNodeData(ListSessions.FocusedNode); 619 FocusedSess := Sender.GetNodeData(ListSessions.FocusedNode);
619 case Mode of 620 case Mode of
620 dmAbove: 621 dmAbove:
621 AttachMode := amInsertBefore; 622 AttachMode := amInsertBefore;
622 dmOnNode: 623 dmOnNode:
623 if TargetSess.IsFolder then 624 if TargetSess.IsFolder then
624 AttachMode := amAddChildFirst 625 AttachMode := amAddChildFirst
625 else 626 else
626 AttachMode := amInsertBefore; 627 AttachMode := amInsertBefore;
627 dmBelow: 628 dmBelow:
628 AttachMode := amInsertAfter; 629 AttachMode := amInsertAfter;
629 else 630 else
630 AttachMode := amInsertAfter; 631 AttachMode := amInsertAfter;
631 end; 632 end;
632 if AttachMode in [amInsertBefore, amInsertAfter] then 633 if AttachMode in [amInsertBefore, amInsertAfter] then
633 ParentNode := TargetNode.Parent 634 ParentNode := TargetNode.Parent
634 else 635 else
635 ParentNode := TargetNode; 636 ParentNode := TargetNode;
636 637
637 SiblingSessions := NodeSessionNames(ParentNode, ParentKey); 638 SiblingSessions := NodeSessionNames(ParentNode, ParentKey);
638 // Test if target folder has an equal named node 639 // Test if target folder has an equal named node
639 if SiblingSessions.IndexOf(FocusedSess.SessionName) > -1 then 640 if SiblingSessions.IndexOf(FocusedSess.SessionName) > -1 then
640 ErrorDialog('Session "'+ParentKey+FocusedSess.SessionName+'" already exists!') 641 ErrorDialog('Session "'+ParentKey+FocusedSess.SessionName+'" already exists!')
641 else begin 642 else begin
642 try 643 try
643 AppSettings.SessionPath := FocusedSess.SessionPath; 644 AppSettings.SessionPath := FocusedSess.SessionPath;
644 AppSettings.MoveCurrentKey(REGKEY_SESSIONS+'\'+ParentKey+FocusedSess.SessionName); 645 AppSettings.MoveCurrentKey(REGKEY_SESSIONS+'\'+ParentKey+FocusedSess.SessionName);
645 ListSessions.MoveTo(ListSessions.FocusedNode, TargetNode, AttachMode, False); 646 ListSessions.MoveTo(ListSessions.FocusedNode, TargetNode, AttachMode, False);
646 FocusedSess.SessionPath := ParentKey+FocusedSess.SessionName; 647 FocusedSess.SessionPath := ParentKey+FocusedSess.SessionName;
647 except 648 except
648 on E:Exception do 649 on E:Exception do
649 ErrorDialog('Error while moving registry key: '+E.Message); 650 ErrorDialog('Error while moving registry key: '+E.Message);
650 end; 651 end;
651 end; 652 end;
652 SiblingSessions.Free; 653 SiblingSessions.Free;
653 end; 654 end;
654 655
655 656
656 procedure Tconnform.ListSessionsDragOver(Sender: TBaseVirtualTree; 657 procedure Tconnform.ListSessionsDragOver(Sender: TBaseVirtualTree;
657 Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint; 658 Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint;
658 Mode: TDropMode; var Effect: Integer; var Accept: Boolean); 659 Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
659 var 660 var
660 TargetNode: PVirtualNode; 661 TargetNode: PVirtualNode;
661 TargetSess: PConnectionParameters; 662 TargetSess: PConnectionParameters;
662 begin 663 begin
663 // Allow node dragging everywhere except within the current folder 664 // Allow node dragging everywhere except within the current folder
664 TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y); 665 TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y);
665 TargetSess := Sender.GetNodeData(TargetNode); 666 TargetSess := Sender.GetNodeData(TargetNode);
666 Accept := (Source = Sender) 667 Accept := (Source = Sender)
667 and ((TargetNode.Parent <> ListSessions.FocusedNode.Parent) or TargetSess.IsFolder) 668 and ((TargetNode.Parent <> ListSessions.FocusedNode.Parent) or TargetSess.IsFolder)
668 and (TargetNode <> ListSessions.FocusedNode.Parent) 669 and (TargetNode <> ListSessions.FocusedNode.Parent)
669 and (Mode <> dmNowhere); 670 and (Mode <> dmNowhere);
670 end; 671 end;
671 672
672 673
673 procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree; 674 procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
674 Node: PVirtualNode; Column: TColumnIndex); 675 Node: PVirtualNode; Column: TColumnIndex);
675 var 676 var
676 SessionFocused: Boolean; 677 SessionFocused: Boolean;
677 Sess: PConnectionParameters; 678 Sess: PConnectionParameters;
678 begin 679 begin
679 // select one connection! 680 // select one connection!
680 Screen.Cursor := crHourglass; 681 Screen.Cursor := crHourglass;
681 TimerStatistics.Enabled := False; 682 TimerStatistics.Enabled := False;
682 SessionFocused := False; 683 SessionFocused := False;
683 Sess := nil; 684 Sess := nil;
684 if Assigned(Node) then begin 685 if Assigned(Node) then begin
685 Sess := Sender.GetNodeData(Node); 686 Sess := Sender.GetNodeData(Node);
686 SessionFocused := not Sess.IsFolder; 687 SessionFocused := not Sess.IsFolder;
687 end; 688 end;
688 FLoaded := False; 689 FLoaded := False;
689 tabStart.TabVisible := not SessionFocused; 690 tabStart.TabVisible := not SessionFocused;
690 tabSettings.TabVisible := SessionFocused; 691 tabSettings.TabVisible := SessionFocused;
691 tabSSHtunnel.TabVisible := SessionFocused; 692 tabSSHtunnel.TabVisible := SessionFocused;
692 tabSSLoptions.TabVisible := SessionFocused; 693 tabSSLoptions.TabVisible := SessionFocused;
693 tabStatistics.TabVisible := SessionFocused; 694 tabStatistics.TabVisible := SessionFocused;
694 695
695 if not SessionFocused then begin 696 if not SessionFocused then begin
696 PageControlDetails.ActivePage := tabStart; 697 PageControlDetails.ActivePage := tabStart;
697 if ListSessions.RootNodeCount = 0 then 698 if ListSessions.RootNodeCount = 0 then
698 lblHelp.Caption := 'New here? In order to connect to a server, you have to create a so called '+ 699 lblHelp.Caption := 'New here? In order to connect to a server, you have to create a so called '+
699 '"session" at first. Just click the "New" button on the bottom left to create your first session.'+CRLF+CRLF+ 700 '"session" at first. Just click the "New" button on the bottom left to create your first session.'+CRLF+CRLF+
700 'Give it a friendly name (e.g. "Local DB server") so you''ll recall it the next time you start '+APPNAME+'.' 701 'Give it a friendly name (e.g. "Local DB server") so you''ll recall it the next time you start '+APPNAME+'.'
701 else 702 else
702 lblHelp.Caption := 'Please click a session on the left list to edit parameters, doubleclick to open it.'; 703 lblHelp.Caption := 'Please click a session on the left list to edit parameters, doubleclick to open it.';
703 end else begin 704 end else begin
704 PageControlDetails.ActivePage := tabSettings; 705 PageControlDetails.ActivePage := tabSettings;
705 706
706 comboNetType.ItemIndex := Integer(Sess.NetType); 707 comboNetType.ItemIndex := Integer(Sess.NetType);
707 editHost.Text := Sess.Hostname; 708 editHost.Text := Sess.Hostname;
708 editUsername.Text := Sess.Username; 709 editUsername.Text := Sess.Username;
709 editPassword.Text := Sess.Password; 710 editPassword.Text := Sess.Password;
710 chkLoginPrompt.Checked := Sess.LoginPrompt; 711 chkLoginPrompt.Checked := Sess.LoginPrompt;
711 chkWindowsAuth.Checked := Sess.WindowsAuth; 712 chkWindowsAuth.Checked := Sess.WindowsAuth;
712 updownPort.Position := Sess.Port; 713 updownPort.Position := Sess.Port;
713 chkCompressed.Checked := Sess.Compressed; 714 chkCompressed.Checked := Sess.Compressed;
714 chkLocalTimeZone.Checked := Sess.LocalTimeZone; 715 chkLocalTimeZone.Checked := Sess.LocalTimeZone;
715 comboDatabases.Text := Sess.AllDatabasesStr; 716 comboDatabases.Text := Sess.AllDatabasesStr;
716 editStartupScript.Text := Sess.StartupScriptFilename; 717 editStartupScript.Text := Sess.StartupScriptFilename;
717 editSSHPlinkExe.Text := Sess.SSHPlinkExe; 718 editSSHPlinkExe.Text := Sess.SSHPlinkExe;
718 editSSHHost.Text := Sess.SSHHost; 719 editSSHHost.Text := Sess.SSHHost;
719 editSSHport.Text := IntToStr(Sess.SSHPort); 720 editSSHport.Text := IntToStr(Sess.SSHPort);
720 editSSHUser.Text := Sess.SSHUser; 721 editSSHUser.Text := Sess.SSHUser;
721 editSSHPassword.Text := Sess.SSHPassword; 722 editSSHPassword.Text := Sess.SSHPassword;
722 updownSSHTimeout.Position := Sess.SSHTimeout; 723 updownSSHTimeout.Position := Sess.SSHTimeout;
723 editSSHPrivateKey.Text := Sess.SSHPrivateKey; 724 editSSHPrivateKey.Text := Sess.SSHPrivateKey;
724 editSSHlocalport.Text := IntToStr(Sess.SSHLocalPort); 725 editSSHlocalport.Text := IntToStr(Sess.SSHLocalPort);
725 chkWantSSL.Checked := Sess.WantSSL; 726 chkWantSSL.Checked := Sess.WantSSL;
726 editSSLPrivateKey.Text := Sess.SSLPrivateKey; 727 editSSLPrivateKey.Text := Sess.SSLPrivateKey;
727 editSSLCertificate.Text := Sess.SSLCertificate; 728 editSSLCertificate.Text := Sess.SSLCertificate;
728 editSSLCACertificate.Text := Sess.SSLCACertificate; 729 editSSLCACertificate.Text := Sess.SSLCACertificate;
729 FServerVersion := Sess.ServerVersion; 730 FServerVersion := Sess.ServerVersion;
730 FSessionColor := Sess.SessionColor; 731 FSessionColor := Sess.SessionColor;
731 end; 732 end;
732 733
733 FLoaded := True; 734 FLoaded := True;
734 FSessionModified := False; 735 FSessionModified := False;
735 ListSessions.Repaint; 736 ListSessions.Repaint;
736 ValidateControls; 737 ValidateControls;
737 TimerStatistics.Enabled := True; 738 TimerStatistics.Enabled := True;
738 TimerStatistics.OnTimer(Sender); 739 TimerStatistics.OnTimer(Sender);
739 740
740 Screen.Cursor := crDefault; 741 Screen.Cursor := crDefault;
741 end; 742 end;
742 743
743 744
744 procedure Tconnform.TimerStatisticsTimer(Sender: TObject); 745 procedure Tconnform.TimerStatisticsTimer(Sender: TObject);
745 var 746 var
746 LastConnect, Created, DummyDate: TDateTime; 747 LastConnect, Created, DummyDate: TDateTime;
747 Connects, Refused: Integer; 748 Connects, Refused: Integer;
748 begin 749 begin
749 // Continuously update statistics labels 750 // Continuously update statistics labels
750 lblLastConnectRight.Caption := 'unknown or never'; 751 lblLastConnectRight.Caption := 'unknown or never';
751 lblLastConnectRight.Hint := ''; 752 lblLastConnectRight.Hint := '';
752 lblLastConnectRight.Enabled := False; 753 lblLastConnectRight.Enabled := False;
753 lblCreatedRight.Caption := 'unknown'; 754 lblCreatedRight.Caption := 'unknown';
754 lblCreatedRight.Hint := ''; 755 lblCreatedRight.Hint := '';
755 lblCreatedRight.Enabled := False; 756 lblCreatedRight.Enabled := False;
756 lblCounterRight.Caption := 'not available'; 757 lblCounterRight.Caption := 'not available';
757 lblCounterRight.Enabled := False; 758 lblCounterRight.Enabled := False;
758 759
759 if not Assigned(ListSessions.FocusedNode) then 760 if not Assigned(ListSessions.FocusedNode) then
760 Exit; 761 Exit;
761 762
762 AppSettings.SessionPath := SelectedSessionPath; 763 AppSettings.SessionPath := SelectedSessionPath;
763 DummyDate := StrToDateTime('2000-01-01'); 764 DummyDate := StrToDateTime('2000-01-01');
764 LastConnect := StrToDateTimeDef(AppSettings.ReadString(asLastConnect), DummyDate); 765 LastConnect := StrToDateTimeDef(AppSettings.ReadString(asLastConnect), DummyDate);
765 if LastConnect <> DummyDate then begin 766 if LastConnect <> DummyDate then begin
766 lblLastConnectRight.Hint := DateTimeToStr(LastConnect); 767 lblLastConnectRight.Hint := DateTimeToStr(LastConnect);
767 lblLastConnectRight.Caption := DateBackFriendlyCaption(LastConnect); 768 lblLastConnectRight.Caption := DateBackFriendlyCaption(LastConnect);
768 lblLastConnectRight.Enabled := True; 769 lblLastConnectRight.Enabled := True;
769 end; 770 end;
770 Created := StrToDateTimeDef(AppSettings.ReadString(asSessionCreated), DummyDate); 771 Created := StrToDateTimeDef(AppSettings.ReadString(asSessionCreated), DummyDate);
771 if Created <> DummyDate then begin 772 if Created <> DummyDate then begin
772 lblCreatedRight.Hint := DateTimeToStr(Created); 773 lblCreatedRight.Hint := DateTimeToStr(Created);
773 lblCreatedRight.Caption := DateBackFriendlyCaption(Created); 774 lblCreatedRight.Caption := DateBackFriendlyCaption(Created);
774 lblCreatedRight.Enabled := True; 775 lblCreatedRight.Enabled := True;
775 end; 776 end;
776 Connects := AppSettings.ReadInt(asConnectCount); 777 Connects := AppSettings.ReadInt(asConnectCount);
777 Refused := AppSettings.ReadInt(asRefusedCount); 778 Refused := AppSettings.ReadInt(asRefusedCount);
778 lblCounterRight.Enabled := Connects + Refused > 0; 779 lblCounterRight.Enabled := Connects + Refused > 0;
779 if Connects > 0 then begin 780 if Connects > 0 then begin
780 lblCounterRight.Caption := 'Successful connects: '+IntToStr(Connects); 781 lblCounterRight.Caption := 'Successful connects: '+IntToStr(Connects);
781 if Refused > 0 then 782 if Refused > 0 then
782 lblCounterRight.Caption := lblCounterRight.Caption + ', unsuccessful: '+IntToStr(Refused); 783 lblCounterRight.Caption := lblCounterRight.Caption + ', unsuccessful: '+IntToStr(Refused);
783 end else if Refused > 0 then 784 end else if Refused > 0 then
784 lblCounterRight.Caption := 'Unsuccessful connects: '+IntToStr(Refused); 785 lblCounterRight.Caption := 'Unsuccessful connects: '+IntToStr(Refused);
785 Invalidate; 786 Invalidate;
786 end; 787 end;
787 788
788 789
789 procedure Tconnform.ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode, 790 procedure Tconnform.ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode,
790 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; 791 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
791 var Allowed: Boolean); 792 var Allowed: Boolean);
792 begin 793 begin
793 if NewNode <> OldNode then 794 if NewNode <> OldNode then
794 FinalizeModifications(Allowed) 795 FinalizeModifications(Allowed)
795 else 796 else
796 Allowed := False; 797 Allowed := False;
797 end; 798 end;
798 799
799 800
800 procedure Tconnform.ListSessionsNewText(Sender: TBaseVirtualTree; 801 procedure Tconnform.ListSessionsNewText(Sender: TBaseVirtualTree;
801 Node: PVirtualNode; Column: TColumnIndex; NewText: String); 802 Node: PVirtualNode; Column: TColumnIndex; NewText: String);
802 var 803 var
803 ParentKey: String; 804 ParentKey: String;
804 Connection: TDBConnection; 805 Connection: TDBConnection;
805 Sess: PConnectionParameters; 806 Sess: PConnectionParameters;
806 SiblingSessions: TStringList; 807 SiblingSessions: TStringList;
807 begin 808 begin
808 // Rename session 809 // Rename session
809 Sess := Sender.GetNodeData(Node); 810 Sess := Sender.GetNodeData(Node);
810 SiblingSessions := NodeSessionNames(Node.Parent, ParentKey); 811 SiblingSessions := NodeSessionNames(Node.Parent, ParentKey);
811 if SiblingSessions.IndexOf(NewText) > -1 then begin 812 if SiblingSessions.IndexOf(NewText) > -1 then begin
812 ErrorDialog('Session "'+ParentKey+NewText+'" already exists!'); 813 ErrorDialog('Session "'+ParentKey+NewText+'" already exists!');
813 NewText := Sess.SessionName; 814 NewText := Sess.SessionName;
814 end else begin 815 end else begin
815 AppSettings.SessionPath := Sess.SessionPath; 816 AppSettings.SessionPath := Sess.SessionPath;
816 AppSettings.MoveCurrentKey(REGKEY_SESSIONS+'\'+ParentKey+NewText); 817 AppSettings.MoveCurrentKey(REGKEY_SESSIONS+'\'+ParentKey+NewText);
817 // Also fix internal session names in main form, which gets used to store e.g. "lastuseddb" later 818 // Also fix internal session names in main form, which gets used to store e.g. "lastuseddb" later
818 for Connection in MainForm.Connections do begin 819 for Connection in MainForm.Connections do begin
819 if Connection.Parameters.SessionPath = Sess.SessionPath then 820 if Connection.Parameters.SessionPath = Sess.SessionPath then
820 Connection.Parameters.SessionPath := ParentKey+NewText; 821 Connection.Parameters.SessionPath := ParentKey+NewText;
821 end; 822 end;
822 MainForm.SetWindowCaption; 823 MainForm.SetWindowCaption;
823 Sess.SessionPath := ParentKey+NewText; 824 Sess.SessionPath := ParentKey+NewText;
824 end; 825 end;
825 SiblingSessions.Free; 826 SiblingSessions.Free;
826 end; 827 end;
827 828
828 829
829 procedure Tconnform.ListSessionsStructureChange(Sender: TBaseVirtualTree; 830 procedure Tconnform.ListSessionsStructureChange(Sender: TBaseVirtualTree;
830 Node: PVirtualNode; Reason: TChangeReason); 831 Node: PVirtualNode; Reason: TChangeReason);
831 begin 832 begin
832 // Node added or removed. Tree needs a repaint in some cases. 833 // Node added or removed. Tree needs a repaint in some cases.
833 // TODO: does not work 834 // TODO: does not work
834 Sender.Repaint; 835 Sender.Repaint;
835 end; 836 end;
836 837
837 838
838 procedure Tconnform.editHostChange(Sender: TObject); 839 procedure Tconnform.editHostChange(Sender: TObject);
839 begin 840 begin
840 editSSHhost.TextHint := TEdit(Sender).Text; 841 editSSHhost.TextHint := TEdit(Sender).Text;
841 Modification(Sender); 842 Modification(Sender);
842 end; 843 end;
843 844
844 845
845 procedure Tconnform.chkLoginPromptClick(Sender: TObject); 846 procedure Tconnform.chkLoginPromptClick(Sender: TObject);
846 var 847 var
847 Checked: Boolean; 848 Checked: Boolean;
848 begin 849 begin
849 // Login prompt and SQL Server integrated Windows Auth are mutually exclusive 850 // Login prompt and SQL Server integrated Windows Auth are mutually exclusive
850 Checked := TCheckBox(Sender).Checked; 851 Checked := TCheckBox(Sender).Checked;
851 if Checked and (Sender = chkWindowsAuth) then 852 if Checked and (Sender = chkWindowsAuth) then
852 chkLoginPrompt.Checked := False; 853 chkLoginPrompt.Checked := False;
853 if Checked and (Sender = chkLoginPrompt) then 854 if Checked and (Sender = chkLoginPrompt) then
854 chkWindowsAuth.Checked := False; 855 chkWindowsAuth.Checked := False;
855 Modification(Sender); 856 Modification(Sender);
856 end; 857 end;
857 858
858 859
859 procedure Tconnform.comboDatabasesDropDown(Sender: TObject); 860 procedure Tconnform.comboDatabasesDropDown(Sender: TObject);
860 var 861 var
861 Connection: TDBConnection; 862 Connection: TDBConnection;
862 Params: TConnectionParameters; 863 Params: TConnectionParameters;
863 begin 864 begin
864 // Try to connect and lookup database names 865 // Try to connect and lookup database names
865 Params := CurrentParams; 866 Params := CurrentParams;
866 Connection := Params.CreateConnection(Self); 867 Connection := Params.CreateConnection(Self);
867 Connection.Parameters.AllDatabasesStr := ''; 868 Connection.Parameters.AllDatabasesStr := '';
868 Connection.LogPrefix := SelectedSessionPath; 869 Connection.LogPrefix := SelectedSessionPath;
869 Connection.OnLog := Mainform.LogSQL; 870 Connection.OnLog := Mainform.LogSQL;
870 comboDatabases.Items.Clear; 871 comboDatabases.Items.Clear;
871 Screen.Cursor := crHourglass; 872 Screen.Cursor := crHourglass;
872 try 873 try
873 Connection.Active := True; 874 Connection.Active := True;
874 comboDatabases.Items := Connection.AllDatabases; 875 comboDatabases.Items := Connection.AllDatabases;
875 except 876 except
876 // Silence connection errors here - should be sufficient to log them 877 // Silence connection errors here - should be sufficient to log them
877 end; 878 end;
878 FreeAndNil(Connection); 879 FreeAndNil(Connection);
879 Screen.Cursor := crDefault; 880 Screen.Cursor := crDefault;
880 end; 881 end;
881 882
882 883
883 procedure Tconnform.comboNetTypeChange(Sender: TObject); 884 procedure Tconnform.comboNetTypeChange(Sender: TObject);
884 var 885 var
885 Params: TConnectionParameters; 886 Params: TConnectionParameters;
886 begin 887 begin
887 // Autoset default port number as long as that was not modified by user 888 // Autoset default port number as long as that was not modified by user
888 if (not editPort.Modified) and (FLoaded) then begin 889 if (not editPort.Modified) and (FLoaded) then begin
889 Params := CurrentParams; 890 Params := CurrentParams;
890 case Params.NetTypeGroup of 891 case Params.NetTypeGroup of
891 ngMySQL: 892 ngMySQL:
892 updownPort.Position := MakeInt(AppSettings.GetDefaultString(asPort)); 893 updownPort.Position := MakeInt(AppSettings.GetDefaultString(asPort));
893 ngMSSQL: 894 ngMSSQL:
894 updownPort.Position := 1433; 895 updownPort.Position := 1433;
895 end; 896 end;
896 FreeAndNil(Params); 897 FreeAndNil(Params);
897 end; 898 end;
898 Modification(Sender); 899 Modification(Sender);
899 end; 900 end;
900 901
901 902
902 procedure Tconnform.Modification(Sender: TObject); 903 procedure Tconnform.Modification(Sender: TObject);
903 var 904 var
904 PasswordModified: Boolean; 905 PasswordModified: Boolean;
905 Sess: PConnectionParameters; 906 Sess: PConnectionParameters;
906 begin 907 begin
907 // Some modification - 908 // Some modification -
908 if FLoaded then begin 909 if FLoaded then begin
909 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 910 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
910 FSessionModified := (Sess.Hostname <> editHost.Text) 911 FSessionModified := (Sess.Hostname <> editHost.Text)
911 or (Sess.Username <> editUsername.Text) 912 or (Sess.Username <> editUsername.Text)
912 or (Sess.LoginPrompt <> chkLoginPrompt.Checked) 913 or (Sess.LoginPrompt <> chkLoginPrompt.Checked)
913 or (Sess.WindowsAuth <> chkWindowsAuth.Checked) 914 or (Sess.WindowsAuth <> chkWindowsAuth.Checked)
914 or (Sess.Port <> updownPort.Position) 915 or (Sess.Port <> updownPort.Position)
915 or (Sess.Compressed <> chkCompressed.Checked) 916 or (Sess.Compressed <> chkCompressed.Checked)
916 or (Sess.LocalTimeZone <> chkLocalTimeZone.Checked) 917 or (Sess.LocalTimeZone <> chkLocalTimeZone.Checked)
917 or (Sess.NetType <> TNetType(comboNetType.ItemIndex)) 918 or (Sess.NetType <> TNetType(comboNetType.ItemIndex))
918 or (Sess.StartupScriptFilename <> editStartupScript.Text) 919 or (Sess.StartupScriptFilename <> editStartupScript.Text)
919 or (Sess.AllDatabasesStr <> comboDatabases.Text) 920 or (Sess.AllDatabasesStr <> comboDatabases.Text)
920 or (Sess.SSHHost <> editSSHHost.Text) 921 or (Sess.SSHHost <> editSSHHost.Text)
921 or (IntToStr(Sess.SSHPort) <> editSSHPort.Text) 922 or (IntToStr(Sess.SSHPort) <> editSSHPort.Text)
922 or (Sess.SSHPlinkExe <> editSSHPlinkExe.Text) 923 or (Sess.SSHPlinkExe <> editSSHPlinkExe.Text)
923 or (IntToStr(Sess.SSHLocalPort) <> editSSHlocalport.Text) 924 or (IntToStr(Sess.SSHLocalPort) <> editSSHlocalport.Text)
924 or (Sess.SSHUser <> editSSHUser.Text) 925 or (Sess.SSHUser <> editSSHUser.Text)
925 or (Sess.SSHPassword <> editSSHPassword.Text) 926 or (Sess.SSHPassword <> editSSHPassword.Text)
926 or (Sess.SSHTimeout <> updownSSHTimeout.Position) 927 or (Sess.SSHTimeout <> updownSSHTimeout.Position)
927 or (Sess.SSHPrivateKey <> editSSHPrivateKey.Text) 928 or (Sess.SSHPrivateKey <> editSSHPrivateKey.Text)
928 or (Sess.WantSSL <> chkWantSSL.Checked) 929 or (Sess.WantSSL <> chkWantSSL.Checked)
929 or (Sess.SSLPrivateKey <> editSSLPrivateKey.Text) 930 or (Sess.SSLPrivateKey <> editSSLPrivateKey.Text)
930 or (Sess.SSLCertificate <> editSSLCertificate.Text) 931 or (Sess.SSLCertificate <> editSSLCertificate.Text)
931 or (Sess.SSLCACertificate <> editSSLCACertificate.Text); 932 or (Sess.SSLCACertificate <> editSSLCACertificate.Text);
932 PasswordModified := Sess.Password <> editPassword.Text; 933 PasswordModified := Sess.Password <> editPassword.Text;
933 FOnlyPasswordModified := PasswordModified and (not FSessionModified); 934 FOnlyPasswordModified := PasswordModified and (not FSessionModified);
934 FSessionModified := FSessionModified or PasswordModified; 935 FSessionModified := FSessionModified or PasswordModified;
935 936
936 ListSessions.Repaint; 937 ListSessions.Repaint;
937 ValidateControls; 938 ValidateControls;
938 end; 939 end;
939 end; 940 end;
940 941
941 942
942 procedure Tconnform.FinalizeModifications(var CanProceed: Boolean); 943 procedure Tconnform.FinalizeModifications(var CanProceed: Boolean);
943 begin 944 begin
944 if FSessionModified and (not FOnlyPasswordModified) then begin 945 if FSessionModified and (not FOnlyPasswordModified) then begin
945 case MessageDialog('Save modifications?', 'Settings for "'+SelectedSessionPath+'" were changed.', mtConfirmation, [mbYes, mbNo, mbCancel]) of 946 case MessageDialog('Save modifications?', 'Settings for "'+SelectedSessionPath+'" were changed.', mtConfirmation, [mbYes, mbNo, mbCancel]) of
946 mrYes: begin 947 mrYes: begin
947 btnSave.OnClick(Self); 948 btnSave.OnClick(Self);
948 CanProceed := True; 949 CanProceed := True;
949 end; 950 end;
950 mrNo: begin 951 mrNo: begin
951 CanProceed := True; 952 CanProceed := True;
952 end; 953 end;
953 mrCancel: CanProceed := False; 954 mrCancel: CanProceed := False;
954 end; 955 end;
955 end else 956 end else
956 CanProceed := True; 957 CanProceed := True;
957 end; 958 end;
958 959
959 960
960 procedure Tconnform.ValidateControls; 961 procedure Tconnform.ValidateControls;
961 var 962 var
962 SessionFocused, FolderFocused: Boolean; 963 SessionFocused, FolderFocused: Boolean;
963 Params: TConnectionParameters; 964 Params: TConnectionParameters;
964 begin 965 begin
965 SessionFocused := False; 966 SessionFocused := False;
966 FolderFocused := False; 967 FolderFocused := False;
967 if Assigned(ListSessions.FocusedNode) then begin 968 if Assigned(ListSessions.FocusedNode) then begin
968 Params := CurrentParams; 969 Params := CurrentParams;
969 SessionFocused := not Params.IsFolder; 970 SessionFocused := not Params.IsFolder;
970 FolderFocused := Params.IsFolder; 971 FolderFocused := Params.IsFolder;
971 972
972 if SessionFocused then begin 973 if SessionFocused then begin
973 // Validate session GUI stuff 974 // Validate session GUI stuff
974 if Params.NetType = ntMySQL_NamedPipe then 975 if Params.NetType = ntMySQL_NamedPipe then
975 lblHost.Caption := 'Socket name:' 976 lblHost.Caption := 'Socket name:'
976 else 977 else
977 lblHost.Caption := 'Hostname / IP:'; 978 lblHost.Caption := 'Hostname / IP:';
978 chkWindowsAuth.Enabled := Params.NetTypeGroup = ngMSSQL; 979 chkWindowsAuth.Enabled := Params.NetTypeGroup = ngMSSQL;
979 lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled)) 980 lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled))
980 and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled)); 981 and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled));
981 editUsername.Enabled := lblUsername.Enabled; 982 editUsername.Enabled := lblUsername.Enabled;
982 lblPassword.Enabled := lblUsername.Enabled; 983 lblPassword.Enabled := lblUsername.Enabled;
983 editPassword.Enabled := lblUsername.Enabled; 984 editPassword.Enabled := lblUsername.Enabled;
984 lblPort.Enabled := Params.NetType in [ntMySQL_TCPIP, ntMySQL_SSHtunnel, ntMSSQL_TCPIP]; 985 lblPort.Enabled := Params.NetType in [ntMySQL_TCPIP, ntMySQL_SSHtunnel, ntMSSQL_TCPIP];
985 if (Params.NetType = ntMSSQL_TCPIP) and (Pos('\', editHost.Text) > 0) then 986 if (Params.NetType = ntMSSQL_TCPIP) and (Pos('\', editHost.Text) > 0) then
986 lblPort.Enabled := False; // Named instance without port 987 lblPort.Enabled := False; // Named instance without port
987 editPort.Enabled := lblPort.Enabled; 988 editPort.Enabled := lblPort.Enabled;
988 updownPort.Enabled := lblPort.Enabled; 989 updownPort.Enabled := lblPort.Enabled;
989 tabSSLoptions.TabVisible := Params.NetType = ntMySQL_TCPIP; 990 tabSSLoptions.TabVisible := Params.NetType = ntMySQL_TCPIP;
990 lblSSLPrivateKey.Enabled := Params.WantSSL; 991 lblSSLPrivateKey.Enabled := Params.WantSSL;
991 editSSLPrivateKey.Enabled := Params.WantSSL; 992 editSSLPrivateKey.Enabled := Params.WantSSL;
992 lblSSLCACertificate.Enabled := Params.WantSSL; 993 lblSSLCACertificate.Enabled := Params.WantSSL;
993 editSSLCACertificate.Enabled := Params.WantSSL; 994 editSSLCACertificate.Enabled := Params.WantSSL;
994 lblSSLCertificate.Enabled := Params.WantSSL; 995 lblSSLCertificate.Enabled := Params.WantSSL;
995 editSSLCertificate.Enabled := Params.WantSSL; 996 editSSLCertificate.Enabled := Params.WantSSL;
996 tabSSHtunnel.TabVisible := Params.NetType = ntMySQL_SSHtunnel; 997 tabSSHtunnel.TabVisible := Params.NetType = ntMySQL_SSHtunnel;
997 Params.Free; 998 Params.Free;
998 end; 999 end;
999 end; 1000 end;
1000 1001
1001 // Main buttons 1002 // Main buttons
1002 btnOpen.Enabled := SessionFocused; 1003 btnOpen.Enabled := SessionFocused;
1003 btnSave.Enabled := SessionFocused and FSessionModified; 1004 btnSave.Enabled := SessionFocused and FSessionModified;
1004 btnDelete.Enabled := SessionFocused or FolderFocused; 1005 btnDelete.Enabled := SessionFocused or FolderFocused;
1005 menuSave.Enabled := btnSave.Enabled; 1006 menuSave.Enabled := btnSave.Enabled;
1006 menuSaveAs.Enabled := SessionFocused; 1007 menuSaveAs.Enabled := SessionFocused;
1007 menuDelete.Enabled := btnDelete.Enabled; 1008 menuDelete.Enabled := btnDelete.Enabled;
1008 end; 1009 end;
1009 1010
1010 1011
1011 procedure Tconnform.splitterMainMoved(Sender: TObject); 1012 procedure Tconnform.splitterMainMoved(Sender: TObject);
1012 var 1013 var
1013 ButtonWidth: Integer; 1014 ButtonWidth: Integer;
1014 begin 1015 begin
1015 // Splitter resized - adjust width of buttons 1016 // Splitter resized - adjust width of buttons
1016 ButtonWidth := Round((ListSessions.Width - 2 * ListSessions.Margins.Left) / 3); 1017 ButtonWidth := Round((ListSessions.Width - 2 * ListSessions.Margins.Left) / 3);
1017 btnNew.Width := ButtonWidth; 1018 btnNew.Width := ButtonWidth;
1018 btnSave.Width := ButtonWidth; 1019 btnSave.Width := ButtonWidth;
1019 btnDelete.Width := ButtonWidth; 1020 btnDelete.Width := ButtonWidth;
1020 btnNew.Left := ListSessions.Left; 1021 btnNew.Left := ListSessions.Left;
1021 btnSave.Left := btnNew.Left + btnNew.Width + ListSessions.Margins.Left; 1022 btnSave.Left := btnNew.Left + btnNew.Width + ListSessions.Margins.Left;
1022 btnDelete.Left := btnSave.Left + btnSave.Width + ListSessions.Margins.Left; 1023 btnDelete.Left := btnSave.Left + btnSave.Width + ListSessions.Margins.Left;
1023 end; 1024 end;
1024 1025
1025 1026
1026 procedure Tconnform.PickFile(Sender: TObject); 1027 procedure Tconnform.PickFile(Sender: TObject);
1027 var 1028 var
1028 Selector: TOpenDialog; 1029 Selector: TOpenDialog;
1029 Edit: TButtonedEdit; 1030 Edit: TButtonedEdit;
1030 i: Integer; 1031 i: Integer;
1031 Control: TControl; 1032 Control: TControl;
1032 begin 1033 begin
1033 // Select startup SQL file, SSL file or whatever button clicked 1034 // Select startup SQL file, SSL file or whatever button clicked
1034 Edit := Sender as TButtonedEdit; 1035 Edit := Sender as TButtonedEdit;
1035 Selector := TOpenDialog.Create(Self); 1036 Selector := TOpenDialog.Create(Self);
1036 Selector.FileName := editStartupScript.Text; 1037 Selector.FileName := editStartupScript.Text;
1037 if Edit = editStartupScript then 1038 if Edit = editStartupScript then
1038 Selector.Filter := 'SQL-files (*.sql)|*.sql|All files (*.*)|*.*' 1039 Selector.Filter := 'SQL-files (*.sql)|*.sql|All files (*.*)|*.*'
1039 else if Edit = editSSHPlinkExe then 1040 else if Edit = editSSHPlinkExe then
1040 Selector.Filter := 'Executables (*.exe)|*.exe|All files (*.*)|*.*' 1041 Selector.Filter := 'Executables (*.exe)|*.exe|All files (*.*)|*.*'
1041 else if Edit = editSSHPrivateKey then 1042 else if Edit = editSSHPrivateKey then
1042 Selector.Filter := 'PuTTY private key (*.ppk)|*.ppk|All files (*.*)|*.*' 1043 Selector.Filter := 'PuTTY private key (*.ppk)|*.ppk|All files (*.*)|*.*'
1043 else 1044 else
1044 Selector.Filter := 'Privacy Enhanced Mail certificates (*.pem)|*.pem|Certificates (*.crt)|*.crt|All files (*.*)|*.*'; 1045 Selector.Filter := 'Privacy Enhanced Mail certificates (*.pem)|*.pem|Certificates (*.crt)|*.crt|All files (*.*)|*.*';
1045 // Find relevant label and set open dialog's title 1046 // Find relevant label and set open dialog's title
1046 for i:=0 to Edit.Parent.ControlCount - 1 do begin 1047 for i:=0 to Edit.Parent.ControlCount - 1 do begin
1047 Control := Edit.Parent.Controls[i]; 1048 Control := Edit.Parent.Controls[i];
1048 if (Control is TLabel) and ((Control as TLabel).FocusControl = Edit) then begin 1049 if (Control is TLabel) and ((Control as TLabel).FocusControl = Edit) then begin
1049 Selector.Title := 'Select ' + (Control as TLabel).Caption; 1050 Selector.Title := 'Select ' + (Control as TLabel).Caption;
1050 break; 1051 break;
1051 end; 1052 end;
1052 end; 1053 end;
1053 1054
1054 if Selector.Execute then begin 1055 if Selector.Execute then begin
1055 Edit.Text := Selector.FileName; 1056 Edit.Text := Selector.FileName;
1056 Modification(Selector); 1057 Modification(Selector);
1057 end; 1058 end;
1058 Selector.Free; 1059 Selector.Free;
1059 end; 1060 end;
1060 1061
1061 1062
1062 procedure Tconnform.editSSHPlinkExeChange(Sender: TObject); 1063 procedure Tconnform.editSSHPlinkExeChange(Sender: TObject);
1063 begin 1064 begin
1064 if not FileExists(editSSHPlinkExe.Text) then 1065 if not FileExists(editSSHPlinkExe.Text) then
1065 editSSHPlinkExe.Font.Color := clRed 1066 editSSHPlinkExe.Font.Color := clRed
1066 else 1067 else
1067 editSSHPlinkExe.Font.Color := clWindowText; 1068 editSSHPlinkExe.Font.Color := clWindowText;
1068 Modification(Sender); 1069 Modification(Sender);
1069 end; 1070 end;
1070 1071
1071 1072
1072 procedure Tconnform.lblDownloadPlinkClick(Sender: TObject); 1073 procedure Tconnform.lblDownloadPlinkClick(Sender: TObject);
1073 begin 1074 begin
1074 ShellExec(TLabel(Sender).Hint); 1075 ShellExec(TLabel(Sender).Hint);
1075 end; 1076 end;
1076 1077
1077 1078
1078 end. 1079 end.
Powered by Google Project Hosting