My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes  
Changes to /trunk/source/connections.pas
r4108 vs. r4118 Compare: vs.  Format:
Revision r4118
Go to: 
/trunk/source/connections.pas   r4108 /trunk/source/connections.pas   r4118
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, Contnrs, Generics.Collections, 13 VirtualTrees, Menus, Graphics, Contnrs, Generics.Collections,
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 Save1: TMenuItem; 25 Save1: TMenuItem;
26 Delete1: TMenuItem; 26 Delete1: TMenuItem;
27 Saveas1: TMenuItem; 27 Saveas1: 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;
86 timerSettingsImport: TTimer;
85 procedure FormCreate(Sender: TObject); 87 procedure FormCreate(Sender: TObject);
86 procedure btnOpenClick(Sender: TObject); 88 procedure btnOpenClick(Sender: TObject);
87 procedure FormShow(Sender: TObject); 89 procedure FormShow(Sender: TObject);
88 procedure btnSaveClick(Sender: TObject); 90 procedure btnSaveClick(Sender: TObject);
89 procedure btnSaveAsClick(Sender: TObject); 91 procedure btnSaveAsClick(Sender: TObject);
90 procedure btnNewClick(Sender: TObject); 92 procedure btnNewClick(Sender: TObject);
91 procedure btnDeleteClick(Sender: TObject); 93 procedure btnDeleteClick(Sender: TObject);
92 procedure Modification(Sender: TObject); 94 procedure Modification(Sender: TObject);
93 procedure ListSessionsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 95 procedure ListSessionsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
94 Column: TColumnIndex; TextType: TVSTTextType; var CellText: String); 96 Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
95 procedure ListSessionsFocusChanged(Sender: TBaseVirtualTree; 97 procedure ListSessionsFocusChanged(Sender: TBaseVirtualTree;
96 Node: PVirtualNode; Column: TColumnIndex); 98 Node: PVirtualNode; Column: TColumnIndex);
97 procedure ListSessionsGetImageIndex(Sender: TBaseVirtualTree; 99 procedure ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
98 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; 100 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
99 var Ghosted: Boolean; var ImageIndex: Integer); 101 var Ghosted: Boolean; var ImageIndex: Integer);
100 procedure ListSessionsNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; 102 procedure ListSessionsNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
101 Column: TColumnIndex; NewText: String); 103 Column: TColumnIndex; NewText: String);
102 procedure ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode, 104 procedure ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode,
103 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; 105 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
104 var Allowed: Boolean); 106 var Allowed: Boolean);
105 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 107 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
106 procedure FormDestroy(Sender: TObject); 108 procedure FormDestroy(Sender: TObject);
107 procedure TimerStatisticsTimer(Sender: TObject); 109 procedure TimerStatisticsTimer(Sender: TObject);
108 procedure FormClose(Sender: TObject; var Action: TCloseAction); 110 procedure FormClose(Sender: TObject; var Action: TCloseAction);
109 procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; 111 procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
110 out EditLink: IVTEditLink); 112 out EditLink: IVTEditLink);
111 procedure PickFile(Sender: TObject); 113 procedure PickFile(Sender: TObject);
112 procedure editSSHPlinkExeChange(Sender: TObject); 114 procedure editSSHPlinkExeChange(Sender: TObject);
113 procedure editHostChange(Sender: TObject); 115 procedure editHostChange(Sender: TObject);
114 procedure lblDownloadPlinkClick(Sender: TObject); 116 procedure lblDownloadPlinkClick(Sender: TObject);
115 procedure comboDatabasesDropDown(Sender: TObject); 117 procedure comboDatabasesDropDown(Sender: TObject);
116 procedure chkLoginPromptClick(Sender: TObject); 118 procedure chkLoginPromptClick(Sender: TObject);
117 procedure ListSessionsInitNode(Sender: TBaseVirtualTree; ParentNode, 119 procedure ListSessionsInitNode(Sender: TBaseVirtualTree; ParentNode,
118 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); 120 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
119 procedure ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree; 121 procedure ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
120 var NodeDataSize: Integer); 122 var NodeDataSize: Integer);
121 procedure comboNetTypeChange(Sender: TObject); 123 procedure comboNetTypeChange(Sender: TObject);
122 procedure splitterMainMoved(Sender: TObject); 124 procedure splitterMainMoved(Sender: TObject);
125 procedure btnImportSettingsClick(Sender: TObject);
126 procedure timerSettingsImportTimer(Sender: TObject);
123 private 127 private
124 { Private declarations } 128 { Private declarations }
125 FLoaded: Boolean; 129 FLoaded: Boolean;
126 FSessions: TObjectList<TConnectionParameters>; 130 FSessions: TObjectList<TConnectionParameters>;
127 FSessionModified, FOnlyPasswordModified, FSessionAdded: Boolean; 131 FSessionModified, FOnlyPasswordModified, FSessionAdded: Boolean;
128 FServerVersion: String; 132 FServerVersion: String;
133 FSettingsImportWaitTime: Cardinal;
134 procedure SetSessions;
129 function SelectedSession: String; 135 function SelectedSession: String;
130 function CurrentParams: TConnectionParameters; 136 function CurrentParams: TConnectionParameters;
131 procedure FinalizeModifications(var CanProceed: Boolean); 137 procedure FinalizeModifications(var CanProceed: Boolean);
132 procedure SaveCurrentValues(Session: String; IsNew: Boolean); 138 procedure SaveCurrentValues(Session: String; IsNew: Boolean);
133 procedure ValidateControls; 139 procedure ValidateControls;
134 public 140 public
135 { Public declarations } 141 { Public declarations }
136 end; 142 end;
137 143
138 144
139 implementation 145 implementation
140 146
141 uses Main, helpers, grideditlinks; 147 uses Main, helpers, grideditlinks;
142 148
143 {$I const.inc} 149 {$I const.inc}
144 150
145 {$R *.DFM} 151 {$R *.DFM}
146 152
147 153
148 procedure Tconnform.FormCreate(Sender: TObject); 154 procedure Tconnform.FormCreate(Sender: TObject);
149 var 155 var
150 LastActiveSession: String; 156 LastActiveSession: String;
151 SessionNames, LastSessions: TStringList; 157 LastSessions: TStringList;
152 Sess: TConnectionParameters;
153 PSess: PConnectionParameters; 158 PSess: PConnectionParameters;
154 hSysMenu: THandle; 159 hSysMenu: THandle;
155 i: Integer;
156 nt: TNetType; 160 nt: TNetType;
157 Node: PVirtualNode; 161 Node: PVirtualNode;
158 Params: TConnectionParameters; 162 Params: TConnectionParameters;
159 begin 163 begin
160 // Fix GUI stuff 164 // Fix GUI stuff
161 InheritFont(Font); 165 InheritFont(Font);
162 SetWindowSizeGrip(Handle, True); 166 SetWindowSizeGrip(Handle, True);
163 Width := GetRegValue(REGNAME_SESSMNGR_WINWIDTH, Width); 167 Width := GetRegValue(REGNAME_SESSMNGR_WINWIDTH, Width);
164 Height := GetRegValue(REGNAME_SESSMNGR_WINHEIGHT, Height); 168 Height := GetRegValue(REGNAME_SESSMNGR_WINHEIGHT, Height);
165 ListSessions.Width := GetRegValue(REGNAME_SESSMNGR_LISTWIDTH, ListSessions.Width); 169 ListSessions.Width := GetRegValue(REGNAME_SESSMNGR_LISTWIDTH, ListSessions.Width);
166 splitterMain.OnMoved(Sender); 170 splitterMain.OnMoved(Sender);
167 FixVT(ListSessions); 171 FixVT(ListSessions);
168 MainForm.RestoreListSetup(ListSessions); 172 MainForm.RestoreListSetup(ListSessions);
169 ListSessions.OnCompareNodes := MainForm.AnyGridCompareNodes; 173 ListSessions.OnCompareNodes := MainForm.AnyGridCompareNodes;
170 ListSessions.OnHeaderClick := MainForm.AnyGridHeaderClick; 174 ListSessions.OnHeaderClick := MainForm.AnyGridHeaderClick;
171 ListSessions.OnHeaderDraggedOut := MainForm.AnyGridHeaderDraggedOut; 175 ListSessions.OnHeaderDraggedOut := MainForm.AnyGridHeaderDraggedOut;
176 btnImportSettings.Caption := MainForm.actImportSettings.Caption;
172 FLoaded := False; 177 FLoaded := False;
173 178
174 comboNetType.Clear; 179 comboNetType.Clear;
175 Params := TConnectionParameters.Create; 180 Params := TConnectionParameters.Create;
176 for nt:=Low(nt) to High(nt) do 181 for nt:=Low(nt) to High(nt) do
177 comboNetType.Items.Add(Params.NetTypeName(nt, True)); 182 comboNetType.Items.Add(Params.NetTypeName(nt, True));
178 Params.Free; 183 Params.Free;
179 184
180 FSessions := TObjectList<TConnectionParameters>.Create; 185 FSessions := TObjectList<TConnectionParameters>.Create;
181 SessionNames := TStringList.Create; 186 SetSessions;
182 MainReg.OpenKey(RegPath + REGKEY_SESSIONS, True);
183 MainReg.GetKeyNames(SessionNames);
184 for i:=0 to SessionNames.Count-1 do begin
185 Sess := TConnectionParameters.ReadFromRegistry(SessionNames[i]);
186 FSessions.Add(Sess);
187 end;
188 ListSessions.RootNodeCount := FSessions.Count;
189 187
190 // Focus last session 188 // Focus last session
191 SelectNode(ListSessions, nil); 189 SelectNode(ListSessions, nil);
192 LastSessions := Explode(DELIM, GetRegValue(REGNAME_LASTSESSIONS, '')); 190 LastSessions := Explode(DELIM, GetRegValue(REGNAME_LASTSESSIONS, ''));
193 LastActiveSession := GetRegValue(REGNAME_LASTACTIVESESSION, ''); 191 LastActiveSession := GetRegValue(REGNAME_LASTACTIVESESSION, '');
194 if (LastActiveSession = '') and (LastSessions.Count > 0) then 192 if (LastActiveSession = '') and (LastSessions.Count > 0) then
195 LastActiveSession := LastSessions[0]; 193 LastActiveSession := LastSessions[0];
196 Node := ListSessions.GetFirst; 194 Node := ListSessions.GetFirst;
197 while Assigned(Node) do begin 195 while Assigned(Node) do begin
198 PSess := ListSessions.GetNodeData(Node); 196 PSess := ListSessions.GetNodeData(Node);
199 if PSess.SessionName = LastActiveSession then 197 if PSess.SessionName = LastActiveSession then
200 SelectNode(ListSessions, Node); 198 SelectNode(ListSessions, Node);
201 Node := ListSessions.GetNextSibling(Node); 199 Node := ListSessions.GetNextSibling(Node);
202 end; 200 end;
203 201
204 // Add own menu items to system menu 202 // Add own menu items to system menu
205 hSysMenu := GetSystemMenu(Handle, False); 203 hSysMenu := GetSystemMenu(Handle, False);
206 AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0); 204 AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0);
207 AppendMenu(hSysMenu, MF_STRING, MSG_UPDATECHECK, PChar(Mainform.actUpdateCheck.Caption)); 205 AppendMenu(hSysMenu, MF_STRING, MSG_UPDATECHECK, PChar(Mainform.actUpdateCheck.Caption));
208 AppendMenu(hSysMenu, MF_STRING, MSG_PREFERENCES, PChar(Mainform.actPreferences.Caption)); 206 AppendMenu(hSysMenu, MF_STRING, MSG_PREFERENCES, PChar(Mainform.actPreferences.Caption));
209 AppendMenu(hSysMenu, MF_STRING, MSG_ABOUT, PChar(Mainform.actAboutBox.Caption)); 207 AppendMenu(hSysMenu, MF_STRING, MSG_ABOUT, PChar(Mainform.actAboutBox.Caption));
210 end; 208 end;
211 209
212 210
211 procedure Tconnform.SetSessions;
212 var
213 SessionNames: TStringList;
214 i: Integer;
215 Sess: TConnectionParameters;
216 begin
217 // Initialize session tree
218 SessionNames := TStringList.Create;
219 MainReg.OpenKey(RegPath + REGKEY_SESSIONS, True);
220 MainReg.GetKeyNames(SessionNames);
221 for i:=0 to SessionNames.Count-1 do begin
222 Sess := TConnectionParameters.ReadFromRegistry(SessionNames[i]);
223 FSessions.Add(Sess);
224 end;
225 ListSessions.RootNodeCount := FSessions.Count;
226 end;
227
228
213 procedure Tconnform.FormDestroy(Sender: TObject); 229 procedure Tconnform.FormDestroy(Sender: TObject);
214 begin 230 begin
215 // Save GUI stuff 231 // Save GUI stuff
216 OpenRegistry; 232 OpenRegistry;
217 MainReg.WriteInteger(REGNAME_SESSMNGR_LISTWIDTH, ListSessions.Width); 233 MainReg.WriteInteger(REGNAME_SESSMNGR_LISTWIDTH, ListSessions.Width);
218 MainReg.WriteInteger(REGNAME_SESSMNGR_WINWIDTH, Width); 234 MainReg.WriteInteger(REGNAME_SESSMNGR_WINWIDTH, Width);
219 MainReg.WriteInteger(REGNAME_SESSMNGR_WINHEIGHT, Height); 235 MainReg.WriteInteger(REGNAME_SESSMNGR_WINHEIGHT, Height);
220 MainForm.SaveListSetup(ListSessions); 236 MainForm.SaveListSetup(ListSessions);
221 end; 237 end;
222 238
223 239
224 procedure Tconnform.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 240 procedure Tconnform.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
225 begin 241 begin
226 // Modifications? Ask if they should be saved. 242 // Modifications? Ask if they should be saved.
227 FinalizeModifications(CanClose); 243 FinalizeModifications(CanClose);
228 end; 244 end;
229 245
230 246
231 procedure Tconnform.FormClose(Sender: TObject; var Action: TCloseAction); 247 procedure Tconnform.FormClose(Sender: TObject; var Action: TCloseAction);
232 begin 248 begin
233 // Suspend calculating statistics as long as they're not visible 249 // Suspend calculating statistics as long as they're not visible
234 TimerStatistics.Enabled := False; 250 TimerStatistics.Enabled := False;
235 Action := caFree; 251 Action := caFree;
236 end; 252 end;
237 253
238 254
239 procedure Tconnform.FormShow(Sender: TObject); 255 procedure Tconnform.FormShow(Sender: TObject);
240 begin 256 begin
241 ListSessions.SetFocus; 257 ListSessions.SetFocus;
242 // Reactivate statistics 258 // Reactivate statistics
243 TimerStatistics.Enabled := True; 259 TimerStatistics.Enabled := True;
244 TimerStatistics.OnTimer(Sender); 260 TimerStatistics.OnTimer(Sender);
245 FLoaded := True; 261 FLoaded := True;
246 end; 262 end;
247 263
248 264
249 procedure Tconnform.btnOpenClick(Sender: TObject); 265 procedure Tconnform.btnOpenClick(Sender: TObject);
250 var 266 var
251 Connection: TDBConnection; 267 Connection: TDBConnection;
252 begin 268 begin
253 // Connect to selected session 269 // Connect to selected session
254 Screen.Cursor := crHourglass; 270 Screen.Cursor := crHourglass;
255 if Mainform.InitConnection(CurrentParams, True, Connection) then 271 if Mainform.InitConnection(CurrentParams, True, Connection) then
256 ModalResult := mrOK 272 ModalResult := mrOK
257 else begin 273 else begin
258 TimerStatistics.OnTimer(Sender); 274 TimerStatistics.OnTimer(Sender);
259 ModalResult := mrNone; 275 ModalResult := mrNone;
260 end; 276 end;
261 Screen.Cursor := crDefault; 277 Screen.Cursor := crDefault;
262 end; 278 end;
263 279
264 280
265 procedure Tconnform.SaveCurrentValues(Session: String; IsNew: Boolean); 281 procedure Tconnform.SaveCurrentValues(Session: String; IsNew: Boolean);
266 var 282 var
267 Sess: PConnectionParameters; 283 Sess: PConnectionParameters;
268 begin 284 begin
269 OpenRegistry(Session); 285 OpenRegistry(Session);
270 MainReg.WriteString(REGNAME_HOST, editHost.Text); 286 MainReg.WriteString(REGNAME_HOST, editHost.Text);
271 MainReg.WriteBool(REGNAME_WINDOWSAUTH, chkWindowsAuth.Checked); 287 MainReg.WriteBool(REGNAME_WINDOWSAUTH, chkWindowsAuth.Checked);
272 MainReg.WriteString(REGNAME_USER, editUsername.Text); 288 MainReg.WriteString(REGNAME_USER, editUsername.Text);
273 MainReg.WriteString(REGNAME_PASSWORD, encrypt(editPassword.Text)); 289 MainReg.WriteString(REGNAME_PASSWORD, encrypt(editPassword.Text));
274 MainReg.WriteBool(REGNAME_LOGINPROMPT, chkLoginPrompt.Checked); 290 MainReg.WriteBool(REGNAME_LOGINPROMPT, chkLoginPrompt.Checked);
275 MainReg.WriteString(REGNAME_PORT, IntToStr(updownPort.Position)); 291 MainReg.WriteString(REGNAME_PORT, IntToStr(updownPort.Position));
276 MainReg.WriteInteger(REGNAME_NETTYPE, comboNetType.ItemIndex); 292 MainReg.WriteInteger(REGNAME_NETTYPE, comboNetType.ItemIndex);
277 MainReg.WriteBool(REGNAME_COMPRESSED, chkCompressed.Checked); 293 MainReg.WriteBool(REGNAME_COMPRESSED, chkCompressed.Checked);
278 MainReg.WriteString(REGNAME_DATABASES, comboDatabases.Text); 294 MainReg.WriteString(REGNAME_DATABASES, comboDatabases.Text);
279 MainReg.WriteString(REGNAME_STARTUPSCRIPT, editStartupScript.Text); 295 MainReg.WriteString(REGNAME_STARTUPSCRIPT, editStartupScript.Text);
280 MainReg.WriteString(REGNAME_SSHHOST, editSSHHost.Text); 296 MainReg.WriteString(REGNAME_SSHHOST, editSSHHost.Text);
281 MainReg.WriteInteger(REGNAME_SSHPORT, MakeInt(editSSHport.Text)); 297 MainReg.WriteInteger(REGNAME_SSHPORT, MakeInt(editSSHport.Text));
282 MainReg.WriteString(REGNAME_SSHUSER, editSSHUser.Text); 298 MainReg.WriteString(REGNAME_SSHUSER, editSSHUser.Text);
283 MainReg.WriteString(REGNAME_SSHPASSWORD, encrypt(editSSHPassword.Text)); 299 MainReg.WriteString(REGNAME_SSHPASSWORD, encrypt(editSSHPassword.Text));
284 MainReg.WriteInteger(REGNAME_SSHTIMEOUT, updownSSHTimeout.Position); 300 MainReg.WriteInteger(REGNAME_SSHTIMEOUT, updownSSHTimeout.Position);
285 MainReg.WriteString(REGNAME_SSHKEY, editSSHPrivateKey.Text); 301 MainReg.WriteString(REGNAME_SSHKEY, editSSHPrivateKey.Text);
286 MainReg.WriteInteger(REGNAME_SSHLOCALPORT, MakeInt(editSSHlocalport.Text)); 302 MainReg.WriteInteger(REGNAME_SSHLOCALPORT, MakeInt(editSSHlocalport.Text));
287 MainReg.WriteBool(REGNAME_SSL_ACTIVE, chkWantSSL.Checked); 303 MainReg.WriteBool(REGNAME_SSL_ACTIVE, chkWantSSL.Checked);
288 MainReg.WriteString(REGNAME_SSL_KEY, editSSLPrivateKey.Text); 304 MainReg.WriteString(REGNAME_SSL_KEY, editSSLPrivateKey.Text);
289 MainReg.WriteString(REGNAME_SSL_CERT, editSSLCertificate.Text); 305 MainReg.WriteString(REGNAME_SSL_CERT, editSSLCertificate.Text);
290 MainReg.WriteString(REGNAME_SSL_CA, editSSLCACertificate.Text); 306 MainReg.WriteString(REGNAME_SSL_CA, editSSLCACertificate.Text);
291 if IsNew then 307 if IsNew then
292 MainReg.WriteString(REGNAME_SESSIONCREATED, DateTimeToStr(Now)); 308 MainReg.WriteString(REGNAME_SESSIONCREATED, DateTimeToStr(Now));
293 OpenRegistry; 309 OpenRegistry;
294 MainReg.WriteString(REGNAME_PLINKEXE, editSSHPlinkExe.Text); 310 MainReg.WriteString(REGNAME_PLINKEXE, editSSHPlinkExe.Text);
295 311
296 // Overtake edited values for in-memory parameter object 312 // Overtake edited values for in-memory parameter object
297 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 313 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
298 Sess.Hostname := editHost.Text; 314 Sess.Hostname := editHost.Text;
299 Sess.Username := editUsername.Text; 315 Sess.Username := editUsername.Text;
300 Sess.Password := editPassword.Text; 316 Sess.Password := editPassword.Text;
301 Sess.LoginPrompt := chkLoginPrompt.Checked; 317 Sess.LoginPrompt := chkLoginPrompt.Checked;
302 Sess.WindowsAuth := chkWindowsAuth.Checked; 318 Sess.WindowsAuth := chkWindowsAuth.Checked;
303 Sess.Port := updownPort.Position; 319 Sess.Port := updownPort.Position;
304 Sess.NetType := TNetType(comboNetType.ItemIndex); 320 Sess.NetType := TNetType(comboNetType.ItemIndex);
305 Sess.Compressed := chkCompressed.Checked; 321 Sess.Compressed := chkCompressed.Checked;
306 Sess.AllDatabasesStr := comboDatabases.Text; 322 Sess.AllDatabasesStr := comboDatabases.Text;
307 Sess.StartupScriptFilename := editStartupScript.Text; 323 Sess.StartupScriptFilename := editStartupScript.Text;
308 Sess.SSHHost := editSSHhost.Text; 324 Sess.SSHHost := editSSHhost.Text;
309 Sess.SSHPort := MakeInt(editSSHport.Text); 325 Sess.SSHPort := MakeInt(editSSHport.Text);
310 Sess.SSHUser := editSSHUser.Text; 326 Sess.SSHUser := editSSHUser.Text;
311 Sess.SSHPassword := editSSHPassword.Text; 327 Sess.SSHPassword := editSSHPassword.Text;
312 Sess.SSHTimeout := updownSSHTimeout.Position; 328 Sess.SSHTimeout := updownSSHTimeout.Position;
313 Sess.SSHPrivateKey := editSSHPrivateKey.Text; 329 Sess.SSHPrivateKey := editSSHPrivateKey.Text;
314 Sess.SSHLocalPort := MakeInt(editSSHlocalport.Text); 330 Sess.SSHLocalPort := MakeInt(editSSHlocalport.Text);
315 Sess.WantSSL := chkWantSSL.Checked; 331 Sess.WantSSL := chkWantSSL.Checked;
316 Sess.SSLPrivateKey := editSSLPrivateKey.Text; 332 Sess.SSLPrivateKey := editSSLPrivateKey.Text;
317 Sess.SSLCertificate := editSSLCertificate.Text; 333 Sess.SSLCertificate := editSSLCertificate.Text;
318 Sess.SSLCACertificate := editSSLCACertificate.Text; 334 Sess.SSLCACertificate := editSSLCACertificate.Text;
319 335
320 FSessionModified := False; 336 FSessionModified := False;
321 FSessionAdded := False; 337 FSessionAdded := False;
322 ListSessions.Invalidate; 338 ListSessions.Invalidate;
323 ValidateControls; 339 ValidateControls;
324 end; 340 end;
325 341
326 342
327 procedure Tconnform.btnSaveClick(Sender: TObject); 343 procedure Tconnform.btnSaveClick(Sender: TObject);
328 begin 344 begin
329 // Save session settings 345 // Save session settings
330 SaveCurrentValues(SelectedSession, FSessionAdded); 346 SaveCurrentValues(SelectedSession, FSessionAdded);
331 end; 347 end;
332 348
333 349
334 procedure Tconnform.btnSaveAsClick(Sender: TObject); 350 procedure Tconnform.btnSaveAsClick(Sender: TObject);
335 var 351 var
336 newName: String; 352 newName: String;
337 NameOK: Boolean; 353 NameOK: Boolean;
338 NewSess: TConnectionParameters; 354 NewSess: TConnectionParameters;
339 Node: PVirtualNode; 355 Node: PVirtualNode;
340 begin 356 begin
341 // Save session as ... 357 // Save session as ...
342 newName := 'Enter new session name ...'; 358 newName := 'Enter new session name ...';
343 NameOK := False; 359 NameOK := False;
344 OpenRegistry; 360 OpenRegistry;
345 while not NameOK do begin 361 while not NameOK do begin
346 if not InputQuery('Clone session ...', 'New session name:', newName) then 362 if not InputQuery('Clone session ...', 'New session name:', newName) then
347 Exit; // Cancelled 363 Exit; // Cancelled
348 NameOK := not MainReg.KeyExists(REGKEY_SESSIONS + newName); 364 NameOK := not MainReg.KeyExists(REGKEY_SESSIONS + newName);
349 if not NameOK then 365 if not NameOK then
350 ErrorDialog('Session name '''+newName+''' already in use.') 366 ErrorDialog('Session name '''+newName+''' already in use.')
351 else begin 367 else begin
352 // Create the key and save its values 368 // Create the key and save its values
353 OpenRegistry(newName); 369 OpenRegistry(newName);
354 SaveCurrentValues(newName, True); 370 SaveCurrentValues(newName, True);
355 NewSess := TConnectionParameters.ReadFromRegistry(newName); 371 NewSess := TConnectionParameters.ReadFromRegistry(newName);
356 FSessions.Add(NewSess); 372 FSessions.Add(NewSess);
357 Node := ListSessions.AddChild(nil, @NewSess); 373 Node := ListSessions.AddChild(nil, @NewSess);
358 SelectNode(ListSessions, Node); 374 SelectNode(ListSessions, Node);
359 end; 375 end;
360 end; 376 end;
361 end; 377 end;
362 378
363 379
380 procedure Tconnform.btnImportSettingsClick(Sender: TObject);
381 begin
382 MainForm.actImportSettings.Execute;
383 FSettingsImportWaitTime := 0;
384 timerSettingsImport.Enabled := True;
385 end;
386
387
388 procedure Tconnform.timerSettingsImportTimer(Sender: TObject);
389 begin
390 Inc(FSettingsImportWaitTime, timerSettingsImport.Interval);
391 SetSessions;
392 if FSessions.Count > 0 then
393 timerSettingsImport.Enabled := False;
394 if FSettingsImportWaitTime >= 10000 then begin
395 timerSettingsImport.Enabled := False;
396 MessageDialog('Imported sessions could not be detected. Restarting HeidiSQL may solve that.', mtWarning, [mbOK]);
397 end;
398 end;
399
400
364 procedure Tconnform.btnNewClick(Sender: TObject); 401 procedure Tconnform.btnNewClick(Sender: TObject);
365 var 402 var
366 i: Integer; 403 i: Integer;
367 CanProceed: Boolean; 404 CanProceed: Boolean;
368 NewSess: TConnectionParameters; 405 NewSess: TConnectionParameters;
369 Node: PVirtualNode; 406 Node: PVirtualNode;
370 begin 407 begin
371 // Create new session 408 // Create new session
372 FinalizeModifications(CanProceed); 409 FinalizeModifications(CanProceed);
373 if not CanProceed then 410 if not CanProceed then
374 Exit; 411 Exit;
375 412
376 i := 0; 413 i := 0;
377 NewSess := TConnectionParameters.Create; 414 NewSess := TConnectionParameters.Create;
378 NewSess.SessionName := 'Unnamed'; 415 NewSess.SessionName := 'Unnamed';
379 while MainReg.KeyExists(RegPath + REGKEY_SESSIONS + NewSess.SessionName) do begin 416 while MainReg.KeyExists(RegPath + REGKEY_SESSIONS + NewSess.SessionName) do begin
380 inc(i); 417 inc(i);
381 NewSess.SessionName := 'Unnamed-' + IntToStr(i); 418 NewSess.SessionName := 'Unnamed-' + IntToStr(i);
382 end; 419 end;
383 FSessions.Add(NewSess); 420 FSessions.Add(NewSess);
384 Node := ListSessions.AddChild(nil, @NewSess); 421 Node := ListSessions.AddChild(nil, @NewSess);
385 // Select it 422 // Select it
386 SelectNode(ListSessions, Node); 423 SelectNode(ListSessions, Node);
387 FSessionAdded := True; 424 FSessionAdded := True;
388 ValidateControls; 425 ValidateControls;
389 ListSessions.EditNode(Node, 0); 426 ListSessions.EditNode(Node, 0);
390 end; 427 end;
391 428
392 429
393 procedure Tconnform.btnDeleteClick(Sender: TObject); 430 procedure Tconnform.btnDeleteClick(Sender: TObject);
394 var 431 var
395 SessionKey: String; 432 SessionKey: String;
396 Sess: PConnectionParameters; 433 Sess: PConnectionParameters;
397 begin 434 begin
398 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 435 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
399 if MessageDialog('Delete session "' + Sess.SessionName + '" ?', mtConfirmation, [mbYes, mbCancel]) = mrYes then 436 if MessageDialog('Delete session "' + Sess.SessionName + '" ?', mtConfirmation, [mbYes, mbCancel]) = mrYes then
400 begin 437 begin
401 SessionKey := RegPath + REGKEY_SESSIONS + Sess.SessionName; 438 SessionKey := RegPath + REGKEY_SESSIONS + Sess.SessionName;
402 if MainReg.KeyExists(SessionKey) then 439 if MainReg.KeyExists(SessionKey) then
403 MainReg.DeleteKey(SessionKey); 440 MainReg.DeleteKey(SessionKey);
404 ListSessions.DeleteSelectedNodes; 441 ListSessions.DeleteSelectedNodes;
405 FSessions.Remove(Sess^); 442 FSessions.Remove(Sess^);
406 if (not Assigned(ListSessions.FocusedNode)) and (ListSessions.RootNodeCount > 0) then 443 if (not Assigned(ListSessions.FocusedNode)) and (ListSessions.RootNodeCount > 0) then
407 SelectNode(ListSessions, ListSessions.RootNodeCount-1) 444 SelectNode(ListSessions, ListSessions.RootNodeCount-1)
408 else 445 else
409 SelectNode(ListSessions, nil); 446 SelectNode(ListSessions, nil);
410 end; 447 end;
411 end; 448 end;
412 449
413 450
414 function Tconnform.SelectedSession: String; 451 function Tconnform.SelectedSession: String;
415 var 452 var
416 Sess: PConnectionParameters; 453 Sess: PConnectionParameters;
417 begin 454 begin
418 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 455 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
419 Result := Sess.SessionName; 456 Result := Sess.SessionName;
420 end; 457 end;
421 458
422 459
423 function Tconnform.CurrentParams: TConnectionParameters; 460 function Tconnform.CurrentParams: TConnectionParameters;
424 begin 461 begin
425 // Return non-stored parameters 462 // Return non-stored parameters
426 Result := TConnectionParameters.Create; 463 Result := TConnectionParameters.Create;
427 Result.SessionName := SelectedSession; 464 Result.SessionName := SelectedSession;
428 Result.NetType := TNetType(comboNetType.ItemIndex); 465 Result.NetType := TNetType(comboNetType.ItemIndex);
429 Result.ServerVersion := FServerVersion; 466 Result.ServerVersion := FServerVersion;
430 Result.Hostname := editHost.Text; 467 Result.Hostname := editHost.Text;
431 Result.Username := editUsername.Text; 468 Result.Username := editUsername.Text;
432 Result.Password := editPassword.Text; 469 Result.Password := editPassword.Text;
433 Result.LoginPrompt := chkLoginPrompt.Checked; 470 Result.LoginPrompt := chkLoginPrompt.Checked;
434 Result.WindowsAuth := chkWindowsAuth.Checked; 471 Result.WindowsAuth := chkWindowsAuth.Checked;
435 if updownPort.Enabled then 472 if updownPort.Enabled then
436 Result.Port := updownPort.Position 473 Result.Port := updownPort.Position
437 else 474 else
438 Result.Port := 0; 475 Result.Port := 0;
439 Result.AllDatabasesStr := comboDatabases.Text; 476 Result.AllDatabasesStr := comboDatabases.Text;
440 Result.SSHHost := editSSHHost.Text; 477 Result.SSHHost := editSSHHost.Text;
441 Result.SSHPort := MakeInt(editSSHPort.Text); 478 Result.SSHPort := MakeInt(editSSHPort.Text);
442 Result.SSHUser := editSSHuser.Text; 479 Result.SSHUser := editSSHuser.Text;
443 Result.SSHPassword := editSSHpassword.Text; 480 Result.SSHPassword := editSSHpassword.Text;
444 Result.SSHTimeout := updownSSHTimeout.Position; 481 Result.SSHTimeout := updownSSHTimeout.Position;
445 Result.SSHPrivateKey := editSSHPrivateKey.Text; 482 Result.SSHPrivateKey := editSSHPrivateKey.Text;
446 Result.SSHLocalPort := MakeInt(editSSHlocalport.Text); 483 Result.SSHLocalPort := MakeInt(editSSHlocalport.Text);
447 Result.SSHPlinkExe := editSSHplinkexe.Text; 484 Result.SSHPlinkExe := editSSHplinkexe.Text;
448 Result.WantSSL := chkWantSSL.Checked; 485 Result.WantSSL := chkWantSSL.Checked;
449 Result.SSLPrivateKey := editSSLPrivateKey.Text; 486 Result.SSLPrivateKey := editSSLPrivateKey.Text;
450 Result.SSLCertificate := editSSLCertificate.Text; 487 Result.SSLCertificate := editSSLCertificate.Text;
451 Result.SSLCACertificate := editSSLCACertificate.Text; 488 Result.SSLCACertificate := editSSLCACertificate.Text;
452 Result.StartupScriptFilename := editStartupScript.Text; 489 Result.StartupScriptFilename := editStartupScript.Text;
453 Result.Compressed := chkCompressed.Checked; 490 Result.Compressed := chkCompressed.Checked;
454 end; 491 end;
455 492
456 493
457 procedure Tconnform.ListSessionsGetImageIndex(Sender: TBaseVirtualTree; 494 procedure Tconnform.ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
458 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; 495 Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
459 var Ghosted: Boolean; var ImageIndex: Integer); 496 var Ghosted: Boolean; var ImageIndex: Integer);
460 var 497 var
461 Sess: PConnectionParameters; 498 Sess: PConnectionParameters;
462 begin 499 begin
463 // A new session gets an additional plus symbol, editing gets a pencil 500 // A new session gets an additional plus symbol, editing gets a pencil
464 if Column > 0 then 501 if Column > 0 then
465 ImageIndex := -1 502 ImageIndex := -1
466 else case Kind of 503 else case Kind of
467 ikNormal, ikSelected: begin 504 ikNormal, ikSelected: begin
468 Sess := Sender.GetNodeData(Node); 505 Sess := Sender.GetNodeData(Node);
469 ImageIndex := Sess.ImageIndex; 506 ImageIndex := Sess.ImageIndex;
470 end; 507 end;
471 508
472 ikOverlay: if Node = Sender.FocusedNode then begin 509 ikOverlay: if Node = Sender.FocusedNode then begin
473 if FSessionAdded then 510 if FSessionAdded then
474 ImageIndex := 163 511 ImageIndex := 163
475 else if FSessionModified then 512 else if FSessionModified then
476 ImageIndex := 162; 513 ImageIndex := 162;
477 end; 514 end;
478 515
479 end; 516 end;
480 end; 517 end;
481 518
482 519
483 procedure Tconnform.ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree; 520 procedure Tconnform.ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
484 var NodeDataSize: Integer); 521 var NodeDataSize: Integer);
485 begin 522 begin
486 NodeDataSize := SizeOf(TConnectionParameters); 523 NodeDataSize := SizeOf(TConnectionParameters);
487 end; 524 end;
488 525
489 526
490 procedure Tconnform.ListSessionsGetText(Sender: TBaseVirtualTree; 527 procedure Tconnform.ListSessionsGetText(Sender: TBaseVirtualTree;
491 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; 528 Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
492 var CellText: String); 529 var CellText: String);
493 var 530 var
494 Sess: PConnectionParameters; 531 Sess: PConnectionParameters;
495 begin 532 begin
496 // Display session name cell 533 // Display session name cell
497 Sess := Sender.GetNodeData(Node); 534 Sess := Sender.GetNodeData(Node);
498 case Column of 535 case Column of
499 0: begin 536 0: begin
500 CellText := Sess.SessionName; 537 CellText := Sess.SessionName;
501 if (FSessionModified or FSessionAdded) and (Node = Sender.FocusedNode) and (not Sender.IsEditing) then 538 if (FSessionModified or FSessionAdded) and (Node = Sender.FocusedNode) and (not Sender.IsEditing) then
502 CellText := CellText + ' *'; 539 CellText := CellText + ' *';
503 end; 540 end;
504 1: CellText := Sess.Hostname; 541 1: CellText := Sess.Hostname;
505 2: CellText := Sess.Username; 542 2: CellText := Sess.Username;
506 3: CellText := Sess.ServerVersion; 543 3: CellText := Sess.ServerVersion;
507 end; 544 end;
508 end; 545 end;
509 546
510 547
511 procedure Tconnform.ListSessionsInitNode(Sender: TBaseVirtualTree; ParentNode, 548 procedure Tconnform.ListSessionsInitNode(Sender: TBaseVirtualTree; ParentNode,
512 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); 549 Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
513 var 550 var
514 Sess: PConnectionParameters; 551 Sess: PConnectionParameters;
515 begin 552 begin
516 Sess := Sender.GetNodeData(Node); 553 Sess := Sender.GetNodeData(Node);
517 Sess^ := FSessions[Node.Index]; 554 Sess^ := FSessions[Node.Index];
518 end; 555 end;
519 556
520 557
521 procedure Tconnform.ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; 558 procedure Tconnform.ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode;
522 Column: TColumnIndex; out EditLink: IVTEditLink); 559 Column: TColumnIndex; out EditLink: IVTEditLink);
523 begin 560 begin
524 // Use our own text editor to rename a session 561 // Use our own text editor to rename a session
525 EditLink := TInplaceEditorLink.Create(Sender as TVirtualStringTree); 562 EditLink := TInplaceEditorLink.Create(Sender as TVirtualStringTree);
526 end; 563 end;
527 564
528 565
529 procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree; 566 procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
530 Node: PVirtualNode; Column: TColumnIndex); 567 Node: PVirtualNode; Column: TColumnIndex);
531 var 568 var
532 SessionFocused: Boolean; 569 SessionFocused: Boolean;
533 Sess: PConnectionParameters; 570 Sess: PConnectionParameters;
534 begin 571 begin
535 // select one connection! 572 // select one connection!
536 Screen.Cursor := crHourglass; 573 Screen.Cursor := crHourglass;
537 TimerStatistics.Enabled := False; 574 TimerStatistics.Enabled := False;
538 SessionFocused := Assigned(Node); 575 SessionFocused := Assigned(Node);
539 FLoaded := False; 576 FLoaded := False;
540 tabStart.TabVisible := not SessionFocused; 577 tabStart.TabVisible := not SessionFocused;
541 tabSettings.TabVisible := SessionFocused; 578 tabSettings.TabVisible := SessionFocused;
542 tabSSHtunnel.TabVisible := SessionFocused; 579 tabSSHtunnel.TabVisible := SessionFocused;
543 tabSSLoptions.TabVisible := SessionFocused; 580 tabSSLoptions.TabVisible := SessionFocused;
544 tabStatistics.TabVisible := SessionFocused; 581 tabStatistics.TabVisible := SessionFocused;
545 582
546 if not SessionFocused then begin 583 if not SessionFocused then begin
547 PageControlDetails.ActivePage := tabStart; 584 PageControlDetails.ActivePage := tabStart;
548 if FSessions.Count = 0 then 585 if FSessions.Count = 0 then
549 lblHelp.Caption := 'New here? In order to connect to a server, you have to create a so called '+ 586 lblHelp.Caption := 'New here? In order to connect to a server, you have to create a so called '+
550 '"session" at first. Just click the "New" button on the bottom left to create your first session.'+CRLF+CRLF+ 587 '"session" at first. Just click the "New" button on the bottom left to create your first session.'+CRLF+CRLF+
551 'Give it a friendly name (e.g. "Local DB server") so you''ll recall it the next time you start '+APPNAME+'.' 588 'Give it a friendly name (e.g. "Local DB server") so you''ll recall it the next time you start '+APPNAME+'.'
552 else 589 else
553 lblHelp.Caption := 'Please click a session on the left list to edit parameters, doubleclick to open it.'; 590 lblHelp.Caption := 'Please click a session on the left list to edit parameters, doubleclick to open it.';
554 end else begin 591 end else begin
555 PageControlDetails.ActivePage := tabSettings; 592 PageControlDetails.ActivePage := tabSettings;
556 Sess := Sender.GetNodeData(Node); 593 Sess := Sender.GetNodeData(Node);
557 594
558 comboNetType.ItemIndex := Integer(Sess.NetType); 595 comboNetType.ItemIndex := Integer(Sess.NetType);
559 editHost.Text := Sess.Hostname; 596 editHost.Text := Sess.Hostname;
560 editUsername.Text := Sess.Username; 597 editUsername.Text := Sess.Username;
561 editPassword.Text := Sess.Password; 598 editPassword.Text := Sess.Password;
562 chkLoginPrompt.Checked := Sess.LoginPrompt; 599 chkLoginPrompt.Checked := Sess.LoginPrompt;
563 chkWindowsAuth.Checked := Sess.WindowsAuth; 600 chkWindowsAuth.Checked := Sess.WindowsAuth;
564 updownPort.Position := Sess.Port; 601 updownPort.Position := Sess.Port;
565 chkCompressed.Checked := Sess.Compressed; 602 chkCompressed.Checked := Sess.Compressed;
566 comboDatabases.Text := Sess.AllDatabasesStr; 603 comboDatabases.Text := Sess.AllDatabasesStr;
567 editStartupScript.Text := Sess.StartupScriptFilename; 604 editStartupScript.Text := Sess.StartupScriptFilename;
568 editSSHPlinkExe.Text := Sess.SSHPlinkExe; 605 editSSHPlinkExe.Text := Sess.SSHPlinkExe;
569 editSSHHost.Text := Sess.SSHHost; 606 editSSHHost.Text := Sess.SSHHost;
570 editSSHport.Text := IntToStr(Sess.SSHPort); 607 editSSHport.Text := IntToStr(Sess.SSHPort);
571 editSSHUser.Text := Sess.SSHUser; 608 editSSHUser.Text := Sess.SSHUser;
572 editSSHPassword.Text := Sess.SSHPassword; 609 editSSHPassword.Text := Sess.SSHPassword;
573 updownSSHTimeout.Position := Sess.SSHTimeout; 610 updownSSHTimeout.Position := Sess.SSHTimeout;
574 editSSHPrivateKey.Text := Sess.SSHPrivateKey; 611 editSSHPrivateKey.Text := Sess.SSHPrivateKey;
575 editSSHlocalport.Text := IntToStr(Sess.SSHLocalPort); 612 editSSHlocalport.Text := IntToStr(Sess.SSHLocalPort);
576 chkWantSSL.Checked := Sess.WantSSL; 613 chkWantSSL.Checked := Sess.WantSSL;
577 editSSLPrivateKey.Text := Sess.SSLPrivateKey; 614 editSSLPrivateKey.Text := Sess.SSLPrivateKey;
578 editSSLCertificate.Text := Sess.SSLCertificate; 615 editSSLCertificate.Text := Sess.SSLCertificate;
579 editSSLCACertificate.Text := Sess.SSLCACertificate; 616 editSSLCACertificate.Text := Sess.SSLCACertificate;
580 FServerVersion := Sess.ServerVersion; 617 FServerVersion := Sess.ServerVersion;
581 end; 618 end;
582 619
583 FLoaded := True; 620 FLoaded := True;
584 FSessionModified := False; 621 FSessionModified := False;
585 FSessionAdded := False; 622 FSessionAdded := False;
586 ListSessions.Repaint; 623 ListSessions.Repaint;
587 ValidateControls; 624 ValidateControls;
588 TimerStatistics.Enabled := True; 625 TimerStatistics.Enabled := True;
589 TimerStatistics.OnTimer(Sender); 626 TimerStatistics.OnTimer(Sender);
590 627
591 Screen.Cursor := crDefault; 628 Screen.Cursor := crDefault;
592 end; 629 end;
593 630
594 631
595 procedure Tconnform.TimerStatisticsTimer(Sender: TObject); 632 procedure Tconnform.TimerStatisticsTimer(Sender: TObject);
596 var 633 var
597 LastConnect, Created, DummyDate: TDateTime; 634 LastConnect, Created, DummyDate: TDateTime;
598 Connects, Refused: Integer; 635 Connects, Refused: Integer;
599 begin 636 begin
600 // Continuously update statistics labels 637 // Continuously update statistics labels
601 lblLastConnectRight.Caption := 'unknown or never'; 638 lblLastConnectRight.Caption := 'unknown or never';
602 lblLastConnectRight.Hint := ''; 639 lblLastConnectRight.Hint := '';
603 lblLastConnectRight.Enabled := False; 640 lblLastConnectRight.Enabled := False;
604 lblCreatedRight.Caption := 'unknown'; 641 lblCreatedRight.Caption := 'unknown';
605 lblCreatedRight.Hint := ''; 642 lblCreatedRight.Hint := '';
606 lblCreatedRight.Enabled := False; 643 lblCreatedRight.Enabled := False;
607 lblCounterRight.Caption := 'not available'; 644 lblCounterRight.Caption := 'not available';
608 lblCounterRight.Enabled := False; 645 lblCounterRight.Enabled := False;
609 646
610 if (not Assigned(ListSessions.FocusedNode)) 647 if (not Assigned(ListSessions.FocusedNode))
611 or (not MainReg.KeyExists(RegPath + REGKEY_SESSIONS + SelectedSession)) then 648 or (not MainReg.KeyExists(RegPath + REGKEY_SESSIONS + SelectedSession)) then
612 Exit; 649 Exit;
613 650
614 DummyDate := StrToDateTime('2000-01-01'); 651 DummyDate := StrToDateTime('2000-01-01');
615 LastConnect := StrToDateTimeDef(GetRegValue(REGNAME_LASTCONNECT, '', SelectedSession), DummyDate); 652 LastConnect := StrToDateTimeDef(GetRegValue(REGNAME_LASTCONNECT, '', SelectedSession), DummyDate);
616 if LastConnect <> DummyDate then begin 653 if LastConnect <> DummyDate then begin
617 lblLastConnectRight.Hint := DateTimeToStr(LastConnect); 654 lblLastConnectRight.Hint := DateTimeToStr(LastConnect);
618 lblLastConnectRight.Caption := DateBackFriendlyCaption(LastConnect); 655 lblLastConnectRight.Caption := DateBackFriendlyCaption(LastConnect);
619 lblLastConnectRight.Enabled := True; 656 lblLastConnectRight.Enabled := True;
620 end; 657 end;
621 Created := StrToDateTimeDef(GetRegValue(REGNAME_SESSIONCREATED, '', SelectedSession), DummyDate); 658 Created := StrToDateTimeDef(GetRegValue(REGNAME_SESSIONCREATED, '', SelectedSession), DummyDate);
622 if Created <> DummyDate then begin 659 if Created <> DummyDate then begin
623 lblCreatedRight.Hint := DateTimeToStr(Created); 660 lblCreatedRight.Hint := DateTimeToStr(Created);
624 lblCreatedRight.Caption := DateBackFriendlyCaption(Created); 661 lblCreatedRight.Caption := DateBackFriendlyCaption(Created);
625 lblCreatedRight.Enabled := True; 662 lblCreatedRight.Enabled := True;
626 end; 663 end;
627 Connects := GetRegValue(REGNAME_CONNECTCOUNT, 0, SelectedSession); 664 Connects := GetRegValue(REGNAME_CONNECTCOUNT, 0, SelectedSession);
628 Refused := GetRegValue(REGNAME_REFUSEDCOUNT, 0, SelectedSession); 665 Refused := GetRegValue(REGNAME_REFUSEDCOUNT, 0, SelectedSession);
629 lblCounterRight.Enabled := Connects + Refused > 0; 666 lblCounterRight.Enabled := Connects + Refused > 0;
630 if Connects > 0 then begin 667 if Connects > 0 then begin
631 lblCounterRight.Caption := 'Successful connects: '+IntToStr(Connects); 668 lblCounterRight.Caption := 'Successful connects: '+IntToStr(Connects);
632 if Refused > 0 then 669 if Refused > 0 then
633 lblCounterRight.Caption := lblCounterRight.Caption + ', unsuccessful: '+IntToStr(Refused); 670 lblCounterRight.Caption := lblCounterRight.Caption + ', unsuccessful: '+IntToStr(Refused);
634 end else if Refused > 0 then 671 end else if Refused > 0 then
635 lblCounterRight.Caption := 'Unsuccessful connects: '+IntToStr(Refused); 672 lblCounterRight.Caption := 'Unsuccessful connects: '+IntToStr(Refused);
636 Invalidate; 673 Invalidate;
637 end; 674 end;
638 675
639 676
640 procedure Tconnform.ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode, 677 procedure Tconnform.ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode,
641 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; 678 NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
642 var Allowed: Boolean); 679 var Allowed: Boolean);
643 begin 680 begin
644 if NewNode <> OldNode then 681 if NewNode <> OldNode then
645 FinalizeModifications(Allowed) 682 FinalizeModifications(Allowed)
646 else 683 else
647 Allowed := False; 684 Allowed := False;
648 end; 685 end;
649 686
650 687
651 procedure Tconnform.ListSessionsNewText(Sender: TBaseVirtualTree; 688 procedure Tconnform.ListSessionsNewText(Sender: TBaseVirtualTree;
652 Node: PVirtualNode; Column: TColumnIndex; NewText: String); 689 Node: PVirtualNode; Column: TColumnIndex; NewText: String);
653 var 690 var
654 SessionKey: String; 691 SessionKey: String;
655 Connection: TDBConnection; 692 Connection: TDBConnection;
656 Sess: PConnectionParameters; 693 Sess: PConnectionParameters;
657 Names: TStringList; 694 Names: TStringList;
658 idx: Integer; 695 idx: Integer;
659 begin 696 begin
660 // Rename session 697 // Rename session
661 Sess := Sender.GetNodeData(Node); 698 Sess := Sender.GetNodeData(Node);
662 OpenRegistry; 699 OpenRegistry;
663 Names := TStringList.Create; 700 Names := TStringList.Create;
664 MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, true); 701 MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, true);
665 MainReg.GetKeyNames(Names); 702 MainReg.GetKeyNames(Names);
666 idx := Names.IndexOf(Sess.SessionName); 703 idx := Names.IndexOf(Sess.SessionName);
667 if idx > -1 then 704 if idx > -1 then
668 Names.Delete(idx); 705 Names.Delete(idx);
669 if Names.IndexOf(NewText) > -1 then begin 706 if Names.IndexOf(NewText) > -1 then begin
670 ErrorDialog('Session "'+NewText+'" already exists!'); 707 ErrorDialog('Session "'+NewText+'" already exists!');
671 NewText := Sess.SessionName; 708 NewText := Sess.SessionName;
672 end else begin 709 end else begin
673 SessionKey := RegPath + REGKEY_SESSIONS + Sess.SessionName; 710 SessionKey := RegPath + REGKEY_SESSIONS + Sess.SessionName;
674 if MainReg.KeyExists(SessionKey) then 711 if MainReg.KeyExists(SessionKey) then
675 MainReg.MoveKey(SessionKey, RegPath + REGKEY_SESSIONS + NewText, true); 712 MainReg.MoveKey(SessionKey, RegPath + REGKEY_SESSIONS + NewText, true);
676 // Also fix internal session names in main form, which gets used to store e.g. "lastuseddb" later 713 // Also fix internal session names in main form, which gets used to store e.g. "lastuseddb" later
677 for Connection in MainForm.Connections do begin 714 for Connection in MainForm.Connections do begin
678 if Connection.Parameters.SessionName = Sess.SessionName then 715 if Connection.Parameters.SessionName = Sess.SessionName then
679 Connection.Parameters.SessionName := NewText; 716 Connection.Parameters.SessionName := NewText;
680 end; 717 end;
681 MainForm.SetWindowCaption; 718 MainForm.SetWindowCaption;
682 Sess.SessionName := NewText; 719 Sess.SessionName := NewText;
683 end; 720 end;
684 end; 721 end;
685 722
686 723
687 procedure Tconnform.editHostChange(Sender: TObject); 724 procedure Tconnform.editHostChange(Sender: TObject);
688 begin 725 begin
689 editSSHhost.TextHint := TEdit(Sender).Text; 726 editSSHhost.TextHint := TEdit(Sender).Text;
690 Modification(Sender); 727 Modification(Sender);
691 end; 728 end;
692 729
693 730
694 procedure Tconnform.chkLoginPromptClick(Sender: TObject); 731 procedure Tconnform.chkLoginPromptClick(Sender: TObject);
695 var 732 var
696 Checked: Boolean; 733 Checked: Boolean;
697 begin 734 begin
698 // Login prompt and SQL Server integrated Windows Auth are mutually exclusive 735 // Login prompt and SQL Server integrated Windows Auth are mutually exclusive
699 Checked := TCheckBox(Sender).Checked; 736 Checked := TCheckBox(Sender).Checked;
700 if Checked and (Sender = chkWindowsAuth) then 737 if Checked and (Sender = chkWindowsAuth) then
701 chkLoginPrompt.Checked := False; 738 chkLoginPrompt.Checked := False;
702 if Checked and (Sender = chkLoginPrompt) then 739 if Checked and (Sender = chkLoginPrompt) then
703 chkWindowsAuth.Checked := False; 740 chkWindowsAuth.Checked := False;
704 Modification(Sender); 741 Modification(Sender);
705 end; 742 end;
706 743
707 744
708 procedure Tconnform.comboDatabasesDropDown(Sender: TObject); 745 procedure Tconnform.comboDatabasesDropDown(Sender: TObject);
709 var 746 var
710 Connection: TDBConnection; 747 Connection: TDBConnection;
711 Params: TConnectionParameters; 748 Params: TConnectionParameters;
712 begin 749 begin
713 // Try to connect and lookup database names 750 // Try to connect and lookup database names
714 Params := CurrentParams; 751 Params := CurrentParams;
715 Connection := Params.CreateConnection(Self); 752 Connection := Params.CreateConnection(Self);
716 Connection.Parameters.AllDatabasesStr := ''; 753 Connection.Parameters.AllDatabasesStr := '';
717 Connection.LogPrefix := SelectedSession; 754 Connection.LogPrefix := SelectedSession;
718 Connection.OnLog := Mainform.LogSQL; 755 Connection.OnLog := Mainform.LogSQL;
719 comboDatabases.Items.Clear; 756 comboDatabases.Items.Clear;
720 Screen.Cursor := crHourglass; 757 Screen.Cursor := crHourglass;
721 try 758 try
722 Connection.Active := True; 759 Connection.Active := True;
723 comboDatabases.Items := Connection.AllDatabases; 760 comboDatabases.Items := Connection.AllDatabases;
724 except 761 except
725 // Silence connection errors here - should be sufficient to log them 762 // Silence connection errors here - should be sufficient to log them
726 end; 763 end;
727 FreeAndNil(Connection); 764 FreeAndNil(Connection);
728 Screen.Cursor := crDefault; 765 Screen.Cursor := crDefault;
729 end; 766 end;
730 767
731 768
732 procedure Tconnform.comboNetTypeChange(Sender: TObject); 769 procedure Tconnform.comboNetTypeChange(Sender: TObject);
733 var 770 var
734 Params: TConnectionParameters; 771 Params: TConnectionParameters;
735 begin 772 begin
736 // Autoset default port number as long as that was not modified by user 773 // Autoset default port number as long as that was not modified by user
737 if (not editPort.Modified) and (FLoaded) then begin 774 if (not editPort.Modified) and (FLoaded) then begin
738 Params := CurrentParams; 775 Params := CurrentParams;
739 case Params.NetTypeGroup of 776 case Params.NetTypeGroup of
740 ngMySQL: 777 ngMySQL:
741 updownPort.Position := DEFAULT_PORT; 778 updownPort.Position := DEFAULT_PORT;
742 ngMSSQL: 779 ngMSSQL:
743 updownPort.Position := 1433; 780 updownPort.Position := 1433;
744 end; 781 end;
745 FreeAndNil(Params); 782 FreeAndNil(Params);
746 end; 783 end;
747 Modification(Sender); 784 Modification(Sender);
748 end; 785 end;
749 786
750 787
751 procedure Tconnform.Modification(Sender: TObject); 788 procedure Tconnform.Modification(Sender: TObject);
752 var 789 var
753 PasswordModified: Boolean; 790 PasswordModified: Boolean;
754 Sess: PConnectionParameters; 791 Sess: PConnectionParameters;
755 begin 792 begin
756 // Some modification - 793 // Some modification -
757 if FLoaded then begin 794 if FLoaded then begin
758 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode); 795 Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
759 FSessionModified := (Sess.Hostname <> editHost.Text) 796 FSessionModified := (Sess.Hostname <> editHost.Text)
760 or (Sess.Username <> editUsername.Text) 797 or (Sess.Username <> editUsername.Text)
761 or (Sess.LoginPrompt <> chkLoginPrompt.Checked) 798 or (Sess.LoginPrompt <> chkLoginPrompt.Checked)
762 or (Sess.WindowsAuth <> chkWindowsAuth.Checked) 799 or (Sess.WindowsAuth <> chkWindowsAuth.Checked)
763 or (Sess.Port <> updownPort.Position) 800 or (Sess.Port <> updownPort.Position)
764 or (Sess.Compressed <> chkCompressed.Checked) 801 or (Sess.Compressed <> chkCompressed.Checked)
765 or (Sess.NetType <> TNetType(comboNetType.ItemIndex)) 802 or (Sess.NetType <> TNetType(comboNetType.ItemIndex))
766 or (Sess.StartupScriptFilename <> editStartupScript.Text) 803 or (Sess.StartupScriptFilename <> editStartupScript.Text)
767 or (Sess.AllDatabasesStr <> comboDatabases.Text) 804 or (Sess.AllDatabasesStr <> comboDatabases.Text)
768 or (Sess.SSHHost <> editSSHHost.Text) 805 or (Sess.SSHHost <> editSSHHost.Text)
769 or (IntToStr(Sess.SSHPort) <> editSSHPort.Text) 806 or (IntToStr(Sess.SSHPort) <> editSSHPort.Text)
770 or (Sess.SSHPlinkExe <> editSSHPlinkExe.Text) 807 or (Sess.SSHPlinkExe <> editSSHPlinkExe.Text)
771 or (IntToStr(Sess.SSHLocalPort) <> editSSHlocalport.Text) 808 or (IntToStr(Sess.SSHLocalPort) <> editSSHlocalport.Text)
772 or (Sess.SSHUser <> editSSHUser.Text) 809 or (Sess.SSHUser <> editSSHUser.Text)
773 or (Sess.SSHPassword <> editSSHPassword.Text) 810 or (Sess.SSHPassword <> editSSHPassword.Text)
774 or (Sess.SSHTimeout <> updownSSHTimeout.Position) 811 or (Sess.SSHTimeout <> updownSSHTimeout.Position)
775 or (Sess.SSHPrivateKey <> editSSHPrivateKey.Text) 812 or (Sess.SSHPrivateKey <> editSSHPrivateKey.Text)
776 or (Sess.WantSSL <> chkWantSSL.Checked) 813 or (Sess.WantSSL <> chkWantSSL.Checked)
777 or (Sess.SSLPrivateKey <> editSSLPrivateKey.Text) 814 or (Sess.SSLPrivateKey <> editSSLPrivateKey.Text)
778 or (Sess.SSLCertificate <> editSSLCertificate.Text) 815 or (Sess.SSLCertificate <> editSSLCertificate.Text)
779 or (Sess.SSLCACertificate <> editSSLCACertificate.Text); 816 or (Sess.SSLCACertificate <> editSSLCACertificate.Text);
780 PasswordModified := Sess.Password <> editPassword.Text; 817 PasswordModified := Sess.Password <> editPassword.Text;
781 FOnlyPasswordModified := PasswordModified and (not FSessionModified); 818 FOnlyPasswordModified := PasswordModified and (not FSessionModified);
782 FSessionModified := FSessionModified or PasswordModified; 819 FSessionModified := FSessionModified or PasswordModified;
783 820
784 ListSessions.Repaint; 821 ListSessions.Repaint;
785 ValidateControls; 822 ValidateControls;
786 end; 823 end;
787 end; 824 end;
788 825
789 826
790 procedure Tconnform.FinalizeModifications(var CanProceed: Boolean); 827 procedure Tconnform.FinalizeModifications(var CanProceed: Boolean);
791 begin 828 begin
792 if (FSessionModified and (not FOnlyPasswordModified)) or FSessionAdded then begin 829 if (FSessionModified and (not FOnlyPasswordModified)) or FSessionAdded then begin
793 case MessageDialog('Save modifications?', 'Settings for "'+SelectedSession+'" were changed.', mtConfirmation, [mbYes, mbNo, mbCancel]) of 830 case MessageDialog('Save modifications?', 'Settings for "'+SelectedSession+'" were changed.', mtConfirmation, [mbYes, mbNo, mbCancel]) of
794 mrYes: begin 831 mrYes: begin
795 btnSave.OnClick(Self); 832 btnSave.OnClick(Self);
796 CanProceed := True; 833 CanProceed := True;
797 end; 834 end;
798 mrNo: begin 835 mrNo: begin
799 CanProceed := True; 836 CanProceed := True;
800 end; 837 end;
801 mrCancel: CanProceed := False; 838 mrCancel: CanProceed := False;
802 end; 839 end;
803 end else 840 end else
804 CanProceed := True; 841 CanProceed := True;
805 end; 842 end;
806 843
807 844
808 procedure Tconnform.ValidateControls; 845 procedure Tconnform.ValidateControls;
809 var 846 var
810 SessionFocused: Boolean; 847 SessionFocused: Boolean;
811 Params: TConnectionParameters; 848 Params: TConnectionParameters;
812 begin 849 begin
813 SessionFocused := Assigned(ListSessions.FocusedNode); 850 SessionFocused := Assigned(ListSessions.FocusedNode);
814 851
815 btnOpen.Enabled := SessionFocused; 852 btnOpen.Enabled := SessionFocused;
816 btnNew.Enabled := not FSessionAdded; 853 btnNew.Enabled := not FSessionAdded;
817 btnSave.Enabled := FSessionModified or FSessionAdded; 854 btnSave.Enabled := FSessionModified or FSessionAdded;
818 btnDelete.Enabled := SessionFocused; 855 btnDelete.Enabled := SessionFocused;
819 btnOpen.Enabled := SessionFocused; 856 btnOpen.Enabled := SessionFocused;
820 857
821 if SessionFocused then begin 858 if SessionFocused then begin
822 // Validate session GUI stuff 859 // Validate session GUI stuff
823 Params := CurrentParams; 860 Params := CurrentParams;
824 if Params.NetType = ntMySQL_NamedPipe then 861 if Params.NetType = ntMySQL_NamedPipe then
825 lblHost.Caption := 'Socket name:' 862 lblHost.Caption := 'Socket name:'
826 else 863 else
827 lblHost.Caption := 'Hostname / IP:'; 864 lblHost.Caption := 'Hostname / IP:';
828 chkWindowsAuth.Enabled := Params.NetTypeGroup = ngMSSQL; 865 chkWindowsAuth.Enabled := Params.NetTypeGroup = ngMSSQL;
829 lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled)) 866 lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled))
830 and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled)); 867 and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled));
831 editUsername.Enabled := lblUsername.Enabled; 868 editUsername.Enabled := lblUsername.Enabled;
832 lblPassword.Enabled := lblUsername.Enabled; 869 lblPassword.Enabled := lblUsername.Enabled;
833 editPassword.Enabled := lblUsername.Enabled; 870 editPassword.Enabled := lblUsername.Enabled;
834 lblPort.Enabled := Params.NetType in [ntMySQL_TCPIP, ntMySQL_SSHtunnel, ntMSSQL_TCPIP]; 871 lblPort.Enabled := Params.NetType in [ntMySQL_TCPIP, ntMySQL_SSHtunnel, ntMSSQL_TCPIP];
835 if (Params.NetType = ntMSSQL_TCPIP) and (Pos('\', editHost.Text) > 0) then 872 if (Params.NetType = ntMSSQL_TCPIP) and (Pos('\', editHost.Text) > 0) then
836 lblPort.Enabled := False; // Named instance without port 873 lblPort.Enabled := False; // Named instance without port
837 editPort.Enabled := lblPort.Enabled; 874 editPort.Enabled := lblPort.Enabled;
838 updownPort.Enabled := lblPort.Enabled; 875 updownPort.Enabled := lblPort.Enabled;
839 tabSSLoptions.TabVisible := Params.NetType = ntMySQL_TCPIP; 876 tabSSLoptions.TabVisible := Params.NetType = ntMySQL_TCPIP;
840 lblSSLPrivateKey.Enabled := Params.WantSSL; 877 lblSSLPrivateKey.Enabled := Params.WantSSL;
841 editSSLPrivateKey.Enabled := Params.WantSSL; 878 editSSLPrivateKey.Enabled := Params.WantSSL;
842 lblSSLCACertificate.Enabled := Params.WantSSL; 879 lblSSLCACertificate.Enabled := Params.WantSSL;
843 editSSLCACertificate.Enabled := Params.WantSSL; 880 editSSLCACertificate.Enabled := Params.WantSSL;
844 lblSSLCertificate.Enabled := Params.WantSSL; 881 lblSSLCertificate.Enabled := Params.WantSSL;
845 editSSLCertificate.Enabled := Params.WantSSL; 882 editSSLCertificate.Enabled := Params.WantSSL;
846 tabSSHtunnel.TabVisible := Params.NetType = ntMySQL_SSHtunnel; 883 tabSSHtunnel.TabVisible := Params.NetType = ntMySQL_SSHtunnel;
847 FreeAndNil(Params); 884 FreeAndNil(Params);
848 end; 885 end;
849 end; 886 end;
850 887
851 888
852 procedure Tconnform.splitterMainMoved(Sender: TObject); 889 procedure Tconnform.splitterMainMoved(Sender: TObject);
853 var 890 var
854 ButtonWidth: Integer; 891 ButtonWidth: Integer;
855 begin 892 begin
856 // Splitter resized - adjust width of buttons 893 // Splitter resized - adjust width of buttons
857 ButtonWidth := Round((ListSessions.Width - 2 * ListSessions.Margins.Left) / 3); 894 ButtonWidth := Round((ListSessions.Width - 2 * ListSessions.Margins.Left) / 3);
858 btnNew.Width := ButtonWidth; 895 btnNew.Width := ButtonWidth;
859 btnSave.Width := ButtonWidth; 896 btnSave.Width := ButtonWidth;
860 btnDelete.Width := ButtonWidth; 897 btnDelete.Width := ButtonWidth;
861 btnNew.Left := ListSessions.Left; 898 btnNew.Left := ListSessions.Left;
862 btnSave.Left := btnNew.Left + btnNew.Width + ListSessions.Margins.Left; 899 btnSave.Left := btnNew.Left + btnNew.Width + ListSessions.Margins.Left;
863 btnDelete.Left := btnSave.Left + btnSave.Width + ListSessions.Margins.Left; 900 btnDelete.Left := btnSave.Left + btnSave.Width + ListSessions.Margins.Left;
864 end; 901 end;
865 902
866 903
867 procedure Tconnform.PickFile(Sender: TObject); 904 procedure Tconnform.PickFile(Sender: TObject);
868 var 905 var
869 Selector: TOpenDialog; 906 Selector: TOpenDialog;
870 Edit: TButtonedEdit; 907 Edit: TButtonedEdit;
871 i: Integer; 908 i: Integer;
872 Control: TControl; 909 Control: TControl;
873 begin 910 begin
874 // Select startup SQL file, SSL file or whatever button clicked 911 // Select startup SQL file, SSL file or whatever button clicked
875 Edit := Sender as TButtonedEdit; 912 Edit := Sender as TButtonedEdit;
876 Selector := TOpenDialog.Create(Self); 913 Selector := TOpenDialog.Create(Self);
877 Selector.FileName := editStartupScript.Text; 914 Selector.FileName := editStartupScript.Text;
878 if Edit = editStartupScript then 915 if Edit = editStartupScript then
879 Selector.Filter := 'SQL-files (*.sql)|*.sql|All files (*.*)|*.*' 916 Selector.Filter := 'SQL-files (*.sql)|*.sql|All files (*.*)|*.*'
880 else if Edit = editSSHPlinkExe then 917 else if Edit = editSSHPlinkExe then
881 Selector.Filter := 'Executables (*.exe)|*.exe|All files (*.*)|*.*' 918 Selector.Filter := 'Executables (*.exe)|*.exe|All files (*.*)|*.*'
882 else if Edit = editSSHPrivateKey then 919 else if Edit = editSSHPrivateKey then
883 Selector.Filter := 'PuTTY private key (*.ppk)|*.ppk|All files (*.*)|*.*' 920 Selector.Filter := 'PuTTY private key (*.ppk)|*.ppk|All files (*.*)|*.*'
884 else 921 else
885 Selector.Filter := 'Privacy Enhanced Mail certificates (*.pem)|*.pem|Certificates (*.crt)|*.crt|All files (*.*)|*.*'; 922 Selector.Filter := 'Privacy Enhanced Mail certificates (*.pem)|*.pem|Certificates (*.crt)|*.crt|All files (*.*)|*.*';
886 // Find relevant label and set open dialog's title 923 // Find relevant label and set open dialog's title
887 for i:=0 to Edit.Parent.ControlCount - 1 do begin 924 for i:=0 to Edit.Parent.ControlCount - 1 do begin
888 Control := Edit.Parent.Controls[i]; 925 Control := Edit.Parent.Controls[i];
889 if (Control is TLabel) and ((Control as TLabel).FocusControl = Edit) then begin 926 if (Control is TLabel) and ((Control as TLabel).FocusControl = Edit) then begin
890 Selector.Title := 'Select ' + (Control as TLabel).Caption; 927 Selector.Title := 'Select ' + (Control as TLabel).Caption;
891 break; 928 break;
892 end; 929 end;
893 end; 930 end;
894 931
895 if Selector.Execute then begin 932 if Selector.Execute then begin
896 Edit.Text := Selector.FileName; 933 Edit.Text := Selector.FileName;
897 Modification(Selector); 934 Modification(Selector);
898 end; 935 end;
899 Selector.Free; 936 Selector.Free;
900 end; 937 end;
901 938
902 939
903 procedure Tconnform.editSSHPlinkExeChange(Sender: TObject); 940 procedure Tconnform.editSSHPlinkExeChange(Sender: TObject);
904 begin 941 begin
905 if not FileExists(editSSHPlinkExe.Text) then 942 if not FileExists(editSSHPlinkExe.Text) then
906 editSSHPlinkExe.Font.Color := clRed 943 editSSHPlinkExe.Font.Color := clRed
907 else 944 else
908 editSSHPlinkExe.Font.Color := clWindowText; 945 editSSHPlinkExe.Font.Color := clWindowText;
909 Modification(Sender); 946 Modification(Sender);
910 end; 947 end;
911 948
912 949
913 procedure Tconnform.lblDownloadPlinkClick(Sender: TObject); 950 procedure Tconnform.lblDownloadPlinkClick(Sender: TObject);
914 begin 951 begin
915 ShellExec(TLabel(Sender).Hint); 952 ShellExec(TLabel(Sender).Hint);
916 end; 953 end;
917 954
918 955
919 end. 956 end.
Powered by Google Project Hosting