source: trunk/UMainWindow.pas

Last change on this file was 15, checked in by george, 16 years ago

Přepracováno: Změna síťových komponent z fundamentals sockets na Indy. Prozatím ne dostatečně funkční.
Typografikcé úpravy.

  • Property svn:executable set to *
File size: 64.8 KB
Line 
1unit UMainWindow;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, cTCPClient, cTCPServer, cWindows, cSockets, cUtils,
8 cSocketsUDP, ImgList, Menus, CoolTrayIcon, ToolWin,
9 ActnMan, ActnCtrls, ActnMenus, ActnList, XPStyleActnCtrls, ComCtrls,
10 ExtCtrls, cWinSock, UAutoRegistry, Registry, CustomizeDlg, MPlayer,
11 StdActns, ULogExceptions, RVScroll, RichView, RVStyle, UTextFileStream,
12 ShellAPI, SunriseChatCoreUnit, SunriseChatNetworkCoreUnit, IdBaseComponent,
13 IdComponent, IdUDPBase, IdUDPServer, XPMan, IdUDPClient, IdCustomTCPServer,
14 IdTCPServer, IdTCPConnection, IdTCPClient, IdAntiFreezeBase, IdAntiFreeze;
15
16const
17 ApplicationName = 'SunriseChat';
18 Author = 'Jiří Hajda';
19 HomePage = 'http://www.zdechov.net/sunrisechat/';
20 Email = 'robie@centrum.cz';
21 ClientVersion = '3.0';
22 ClientReleaseDate = '11.2.2008';
23 OfflineTimeout = 13/24/3600; // 13 seconds
24 Creator = 'Chronosoft';
25 RegistryPath = '\Software\' + Creator + '\SunriseChat';
26 ChangeLogFile = 'Novinky.txt';
27 Licence = 'Copyleft';
28 HttpHeader = 'http://';
29 ShareHeader = '\\';
30
31type
32 TAppEventTextColor = record
33 Color: Integer;
34 Charset: Integer;
35 Style: string;
36 Size: Integer;
37 Name: string;
38 end;
39
40 TAppEvent = record
41 // Actions
42 EventName: string;
43 ShowWindow: Boolean;
44 ShowBalloonHint: Boolean;
45 PlaySound: Boolean;
46 ShowAlertIcon: Boolean;
47 IconFile: string;
48 PlayBeep: Boolean;
49 SoundFile: string;
50 ExecuteApplication: Boolean;
51 ApplicationFile: string;
52 ShowMessage: Boolean;
53 MessageText: string;
54 MessageFont: TFont;
55 MessageFontTemp: TAppEventTextColor;
56 end;
57
58 TAppUserEvent = record
59 // Conditions
60 ConditionTextEnable: Boolean;
61 ConditionText: string;
62 ConditionUserEnable: Boolean;
63 ConditionUser: string;
64 ConditionAppEventEnable: Boolean;
65 ConditionAppEvent: Integer;
66
67 // Actions
68 EventName: string;
69 ShowWindow: Boolean;
70 ShowBalloonHint: Boolean;
71 PlaySound: Boolean;
72 ShowAlertIcon: Boolean;
73 IconFile: string;
74 PlayBeep: Boolean;
75 SoundFile: string;
76 ExecuteApplication: Boolean;
77 ApplicationFile: string;
78 ShowImage: Boolean;
79 ImageFile: string;
80 Image: TImage;
81 end;
82
83 TEventOption = (eoShowWindow, eoShowBalloonHint, eoShowAlertIcon, eoPlayBeep,
84 eoShowMessage);
85 TEventOptions = set of TEventOption;
86
87 TMainWindow = class(TForm)
88 Panel3: TPanel;
89 Panel4: TPanel;
90 Button1: TButton;
91 ActionManager1: TActionManager;
92 ActionOptions: TAction;
93 ActionInfo: TAction;
94 ActionAbout: TAction;
95 ActionStatus: TAction;
96 ActionClose: TAction;
97 ActionRestore: TAction;
98 ActionOnline: TAction;
99 ActionAway: TAction;
100 ActionInvisible: TAction;
101 ActionTestResponse: TAction;
102 ActionBlockIP: TAction;
103 ActionCallUp: TAction;
104 CoolTrayIcon1: TCoolTrayIcon;
105 PopupMenu2: TPopupMenu;
106 Blokovatadresu1: TMenuItem;
107 estodezvy1: TMenuItem;
108 Vzva1: TMenuItem;
109 PopupMenu1: TPopupMenu;
110 Obnovit1: TMenuItem;
111 Informace1: TMenuItem;
112 Nastaven2: TMenuItem;
113 Oprogramu2: TMenuItem;
114 Ukonit1: TMenuItem;
115 ImageList1: TImageList;
116 Timer1: TTimer;
117 ActionUserRoom: TAction;
118 ActionLogCommand: TAction;
119 PopupMenu3: TPopupMenu;
120 Odejtzmstnosti1: TMenuItem;
121 CustomizeDlg1: TCustomizeDlg;
122 ActionCustomizeDlg: TAction;
123 PopupMenu4: TPopupMenu;
124 Pedchozzprva1: TMenuItem;
125 Doplnitjmno1: TMenuItem;
126 MainMenu1: TMainMenu;
127 Status1: TMenuItem;
128 Online1: TMenuItem;
129 Pry1: TMenuItem;
130 Neviditeln1: TMenuItem;
131 Nastaven1: TMenuItem;
132 Informace2: TMenuItem;
133 Status2: TMenuItem;
134 Online2: TMenuItem;
135 Pry2: TMenuItem;
136 Neviditeln2: TMenuItem;
137 ActionNetworkTest: TAction;
138 estst1: TMenuItem;
139 Panel5: TPanel;
140 ToolBar1: TToolBar;
141 ToolButton1: TToolButton;
142 ToolButton2: TToolButton;
143 ToolButton3: TToolButton;
144 ToolButton4: TToolButton;
145 ToolButton5: TToolButton;
146 ToolButton7: TToolButton;
147 Panel2: TPanel;
148 Label1: TLabel;
149 ListView1: TListView;
150 Splitter3: TSplitter;
151 Panel1: TPanel;
152 Label2: TLabel;
153 MediaPlayer1: TMediaPlayer;
154 Vytvoitmstnost1: TMenuItem;
155 ActionCreateRoom: TAction;
156 Vytvoitmstnost2: TMenuItem;
157 SearchFind1: TSearchFind;
158 PopupMenu5: TPopupMenu;
159 Find1: TMenuItem;
160 Vymazatve1: TMenuItem;
161 ActionClearMessageList: TAction;
162 ComboBox1: TComboBox;
163 N1: TMenuItem;
164 Novinky1: TMenuItem;
165 ActionChangeLog: TAction;
166 Oprogramu1: TMenuItem;
167 RVStyle1: TRVStyle;
168 Panel6: TPanel;
169 RichView1: TRichView;
170 PageControl1: TPageControl;
171 TabSheet1: TTabSheet;
172 Pozvatuivateledomstnosti1: TMenuItem;
173 ActionUserEventsList: TAction;
174 Nabdkauivatelskchudlost1: TMenuItem;
175 ToolButton6: TToolButton;
176 ListView2: TListView;
177 Koprovar1: TMenuItem;
178 Vloit1: TMenuItem;
179 Vloitsovodkaz1: TMenuItem;
180 OpenDialog1: TOpenDialog;
181 XPManifest1: TXPManifest;
182 Log1: TMenuItem;
183 procedure FormCreate(Sender: TObject);
184 procedure FormShow(Sender: TObject);
185 procedure Vloitsovodkaz1Click(Sender: TObject);
186 procedure RichView1Jump(Sender: TObject; id: Integer);
187 procedure Vloit1Click(Sender: TObject);
188 procedure Koprovar1Click(Sender: TObject);
189 procedure Button1Click(Sender: TObject);
190 procedure Timer1Timer(Sender: TObject);
191 procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
192 procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
193 Shift: TShiftState);
194 procedure ActionInfoExecute(Sender: TObject);
195 procedure ActionAwayExecute(Sender: TObject);
196 procedure ActionOnlineExecute(Sender: TObject);
197 procedure ActionCloseExecute(Sender: TObject);
198 procedure ListView1Click(Sender: TObject);
199 procedure ActionTestResponseExecute(Sender: TObject);
200 procedure ActionRestoreExecute(Sender: TObject);
201 procedure ActionInvisibleExecute(Sender: TObject);
202 procedure ActionAboutExecute(Sender: TObject);
203 procedure ActionOptionsExecute(Sender: TObject);
204 procedure ActionCallUpExecute(Sender: TObject);
205 procedure TabControl1Change(Sender: TObject);
206 procedure ActionBlockIPExecute(Sender: TObject);
207 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
208 procedure ActionUserRoomExecute(Sender: TObject);
209 procedure Odejtzmstnosti1Click(Sender: TObject);
210 procedure ActionCustomizeDlgExecute(Sender: TObject);
211 procedure PopupMenu2Popup(Sender: TObject);
212 procedure Pedchozzprva1Click(Sender: TObject);
213// procedure Doplnitjmno1Click(Sender: TObject);
214 procedure ActionNetworkTestExecute(Sender: TObject);
215 procedure ToolButton7Click(Sender: TObject);
216 procedure CoolTrayIcon1Click(Sender: TObject);
217 procedure ToolButton1Click(Sender: TObject);
218 procedure ToolButton3Click(Sender: TObject);
219 procedure ToolButton2Click(Sender: TObject);
220 procedure ToolButton5Click(Sender: TObject);
221 procedure ToolButton4Click(Sender: TObject);
222 procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
223 Shift: TShiftState; X, Y: Integer);
224 procedure ListView1InfoTip(Sender: TObject; Item: TListItem;
225 var InfoTip: String);
226 procedure ActionCreateRoomExecute(Sender: TObject);
227 procedure Doplnitjmno1Click(Sender: TObject);
228 procedure SearchFind1FindDialogFind(Sender: TObject);
229 procedure SearchFind1BeforeExecute(Sender: TObject);
230 procedure ActionClearMessageListExecute(Sender: TObject);
231 procedure ComboBox1Change(Sender: TObject);
232 procedure ActionChangeLogExecute(Sender: TObject);
233 procedure ComboBox1DropDown(Sender: TObject);
234 procedure ComboBox1CloseUp(Sender: TObject);
235 procedure FormResize(Sender: TObject);
236 procedure ActionUserEventsListExecute(Sender: TObject);
237 procedure ToolButton6Click(Sender: TObject);
238 procedure Panel6Resize(Sender: TObject);
239 procedure SunriseChatNetworkCore1RoomListChanged;
240 procedure SunriseChatNetworkCore1UserListUpdate;
241 procedure SunriseChatNetworkCore1AddMessage(EventType: TAppEventType;
242 Room: TRoom; const Args: array of TVarRec; RoomLine: TRoomLine);
243 procedure FormDestroy(Sender: TObject);
244 procedure FormClose(Sender: TObject; var Action: TCloseAction);
245 procedure Log1Click(Sender: TObject);
246 private
247 CloseEnabled: Boolean;
248 UserLastText: string;
249 procedure WMQueryEndSession(var Message: TMessage); message WM_QUERYENDSESSION;
250 procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
251 procedure ChangeNetworkState;
252 procedure CallUp;
253 procedure lComboBox1Change(Sender: TObject);
254 { Private declarations }
255 public
256 SunriseChatNetworkCore1: TSunriseChatNetworkCore;
257 UserEventsImagesEnabled: Boolean;
258 FirstStart: Boolean;
259 LastRichViewStyle: Integer;
260 MaxNumberOfRoomLines: Integer;
261 AppEvents: array of TAppEvent;
262 AppUserEvents: array of TAppUserEvent;
263 AppEventsInit: array of TAppEvent;
264 Options: TAutoRegistry;
265 AppEventsOptions: array of TAutoRegistry;
266 AppUserEventsOptions: array of TAutoRegistry;
267 NetworkPort: Integer;
268 NetworkInterface: string;
269 PingTimeout: Integer;
270 MinimizeToTray: Boolean;
271 StartInTray: Boolean;
272 RunOnLogon: Boolean;
273 LastText: string;
274 OnTop: Boolean;
275 ShowOnMessage: Boolean;
276 PositionX, PositionY, SizeX, SizeY: Integer;
277 LastWindowState: Integer;
278 AlphaBlendWindow: Integer;
279 UserListWidth: Integer;
280 ShowMessageTime: Boolean;
281 ShowMainMenu: Boolean;
282 InstanceIndex: Integer;
283 ShowBallonHint: Boolean;
284 NoResloveHostName: Boolean;
285 MinimalizeOnCloseWindow: Boolean;
286 DefaultReason: string;
287 ServiceFunction: Boolean;
288 ShowRightToolBar: Boolean;
289 PauseScrollText: Boolean;
290 OneAppInstance: Boolean;
291 WM_SunriseChatStart: Cardinal;
292 WM_SunriseChatClose: Cardinal;
293 NoSaveToRegistry: Boolean;
294 SoundDisable: Boolean;
295 StopProgram: Boolean;
296 SnapWindow: Boolean;
297 InvisibledOnStart: Boolean;
298 AutoChangeWindowHeight: Boolean;
299 AutoChangeWindowHeightDirectionDown: Boolean;
300 MinimumVisibleUsersCount: Integer;
301 SoundVolume: Integer;
302 LanguageIndex: Integer;
303 SettingsName: string;
304 AutoChangeInfoWindowHeight: Boolean;
305 AppUserEventsCount: Integer;
306 HyperLinks: array of string;
307 BroadcastTypeI: Integer;
308 UserNick: string;
309 UsersAutoAwayDelay: Integer;
310 procedure RoomListChanged;
311 procedure InitTrayIcon;
312 procedure ChangeRunOnLogon;
313 procedure ScrollDownRichEdit1;
314 procedure DoplnitJmeno;
315 procedure AddEvent(Name, Text: string; Options: TEventOptions);
316 procedure SaveAppEventsToRegistry;
317 procedure LoadAppEventsFromRegistry;
318 procedure SaveAppUserEventsToRegistry;
319 procedure LoadAppUserEventsFromRegistry(UpdateOnly: Boolean = False);
320 procedure RefreshAppTitle;
321 procedure InitSettings;
322 procedure FillComboBox;
323 procedure ShowUserList;
324 procedure ReloadImages;
325 end;
326
327procedure MPSetVolume(MP: TMediaPlayer; Volume: Integer) ;
328function MPGetVolume(MP: TMediaPlayer): Integer;
329
330var
331 MainWindow: TMainWindow;
332
333implementation
334
335uses UInfoWindow, UAboutWindow, UOptionsWindow, UNetworkTest, UNewRoom,
336 DateUtils, ULocalization, UJobProgressView, MMSystem, UProtocolMessageLog;
337
338{$R *.dfm}
339
340const
341 MCI_SETAUDIO = $0873;
342 MCI_DGV_SETAUDIO_VOLUME = $4002;
343 MCI_DGV_SETAUDIO_ITEM = $00800000;
344 MCI_DGV_SETAUDIO_VALUE = $01000000;
345 MCI_DGV_STATUS_VOLUME = $4019;
346type
347 MCI_DGV_SETAUDIO_PARMS = record
348 dwCallback: DWORD;
349 dwItem: DWORD;
350 dwValue: DWORD;
351 dwOver: DWORD;
352 lpstrAlgorithm: PChar;
353 lpstrQuality: PChar;
354 end;
355type
356 MCI_STATUS_PARMS = record
357 dwCallback: DWORD;
358 dwReturn: DWORD;
359 dwItem: DWORD;
360 dwTrack: DWORD;
361 end;
362
363{Set Volume, range 0 - 1000}
364procedure MPSetVolume(MP: TMediaPlayer; Volume: Integer) ;
365var
366 p: MCI_DGV_SETAUDIO_PARMS;
367begin
368 p.dwCallback := 0;
369 p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
370 p.dwValue := Volume;
371 p.dwOver := 0;
372 p.lpstrAlgorithm := nil;
373 p.lpstrQuality := nil;
374 mciSendCommand(MP.DeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p)) ;
375end;
376
377{Get Volume, range 0 - 1000}
378function MPGetVolume(MP: TMediaPlayer): Integer;
379var
380 p: MCI_STATUS_PARMS;
381begin
382 p.dwCallback := 0;
383 p.dwItem := MCI_DGV_STATUS_VOLUME;
384 mciSendCommand(MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p)) ;
385 Result := p.dwReturn;
386end;
387
388procedure SwitchToThisWindow(h1: hWnd; x: bool); stdcall; external user32 Name 'SwitchToThisWindow';
389
390procedure TMainWindow.FormCreate(Sender: TObject);
391const
392 Separator = '|';
393var
394 Row: string;
395 FileName: string;
396 I: Integer;
397begin
398 SunriseChatNetworkCore1 := TSunriseChatNetworkCore.Create(Self);
399 with SunriseChatNetworkCore1 do begin
400 UdpPort := 55557;
401 UseDefaultEventsText := True;
402 AutoAwayDelay := 5;
403 AutoReconnect := True;
404 BroadcastType := btLocal;
405 MaxRoomLines := 100;
406 end;
407
408
409 SettingsName := '';
410 // Process application parameters
411 for I := 0 to ParamCount do begin
412 //ShowMessage(ParamStr(I));
413 if Copy(ParamStr(I), 1, 3) = '/s:' then SettingsName := Copy(ParamStr(I), 4, 255);
414 end;
415 if SettingsName = '' then SettingsName := 'Default';
416
417 with SunriseChatNetworkCore1 do begin
418 OnChangeNetworkState := ChangeNetworkState;
419 OnAddMessage := SunriseChatNetworkCore1AddMessage;
420 OnUserListUpdate := ShowUserList;
421 OnRoomListChanged := RoomListChanged;
422 end;
423
424 Options := TAutoRegistry.Create(RegistryPath + '\' + SettingsName);
425 with Options, SunriseChatNetworkCore1 do begin
426 InitSettings;
427 if FirstStart then begin
428 FileName := ExtractFileDir(Application.ExeName) + '\' + SmileysDefFile;
429 if FileExists(FileName) then begin
430 with TTextFileStream.Create(FileName, fmOpenRead) do try
431 repeat
432 Row := Trim(ReadLn);
433 if Row <> '' then begin
434 SetLength(AppUserEvents, Length(AppUserEvents)+1);
435 with AppUserEvents[High(AppUserEvents)] do begin
436 EventName := Copy(Row, 1, Pos(Separator, Row)-1);
437 ConditionTextEnable := True;
438 ConditionText := EventName;
439 ShowImage := True;
440 ImageFile := ExtractFileDir(FileName) + '\' + Copy(Row, Pos(Separator, Row)+1, Length(Row));
441 end;
442 end;
443 until Position = Size;
444 finally
445 Free;
446 end;
447 SetLength(AppUserEventsOptions,Length(AppUserEvents));
448 AppUserEventsCount:= Length(AppUserEvents);
449 LoadAppUserEventsFromRegistry(True);
450 SaveAppUserEventsToRegistry;
451 ReloadImages;
452 end;
453 end;
454
455 // Check multiple application instance
456 WM_SunriseChatStart := RegisterWindowMessage('SunriseChatStart');
457 WM_SunriseChatClose := RegisterWindowMessage('SunriseChatClose');
458 Application.OnMessage := AppMessage;
459 PostMessage(HWND_BROADCAST, WM_SunriseChatStart, Application.Handle, 0);
460 for I := 0 to 10 do begin
461 Sleep(1);
462 Application.ProcessMessages;
463 if StopProgram then Break;
464 end;
465 if StopProgram then begin
466 Application.Terminate;
467 Exit;
468 end;
469 end;
470
471 // Local user initialization
472 with SunriseChatNetworkCore1.LocalUser do begin
473 Client := ApplicationName;
474 Application.Title := ApplicationName;
475 end;
476 SunriseChatNetworkCore1.LocalUser.ClientVersion := ClientVersion;
477 SunriseChatNetworkCore1.UDPPort := NetworkPort;
478 SunriseChatNetworkCore1.SelectNetworkInterfaceByGUID(NetworkInterface);
479// SunriseChatCore.Init;
480 RoomListChanged;
481// if FileExists(CustomizeFile) then ActionManager1.LoadFromFile(CustomizeFile);
482 RefreshAppTitle;
483 SunriseChatNetworkCore1.Active := True;
484 SunriseChatNetworkCore1.AutoReconnect := True;
485end;
486
487procedure TMainWindow.InitTrayIcon;
488begin
489 CoolTrayIcon1.MinimizeToTray:= MinimizeToTray;
490 CoolTrayIcon1.IconIndex:= 5;
491 CoolTrayIcon1.IconVisible:= True; //MinimizeToTray;
492 if OnTop then FormStyle:= fsStayOnTop else FormStyle:= fsNormal;
493
494 if MinimizeToTray then CoolTrayIcon1.HideTaskbarIcon
495 else CoolTrayIcon1.ShowTaskbarIcon;
496
497 // Hide MainForm at startup.
498 if StartInTray then Application.ShowMainForm:= False;
499end;
500
501procedure TMainWindow.Koprovar1Click(Sender: TObject);
502begin
503 RichView1.CopyText;
504 //SendMessage(RichView1.Handle, WM_COPY, 0, 0);
505end;
506
507procedure TMainWindow.SunriseChatNetworkCore1AddMessage(
508 EventType: TAppEventType; Room: TRoom; const Args: array of TVarRec;
509 RoomLine: TRoomLine);
510var
511 ForUser, ForUser2, MessageTime: string;
512 Icon: TIcon;
513 RichViewStyle: Integer;
514 I, II: Integer;
515 MessageTextTemp: string;
516 TextStart, TextEnd: Integer;
517 TemporaryText: string;
518 UserNick: string;
519begin
520 case EventType of
521 aeUserChangeNick: RefreshAppTitle;
522 aeCommonMessage, aeOneUserMessage: UserNick := string(Args[1].VPChar);
523 end;
524
525 // Format text line
526 try
527 RoomLine.Text := Format(AppEvents[Integer(EventType)].MessageText, Args);
528 except
529 ShowMessage('Chyba ve zprávě pro událost '+AppEvents[Integer(EventType)].EventName+'!');
530 end;
531
532 with AppEvents[Integer(EventType)] do begin
533 if ShowWindow then CallUp; //CoolTrayIcon1.ShowMainForm;
534 if not SoundDisable then begin
535 if PlayBeep then Beep;
536 if PlaySound then
537 try
538 MediaPlayer1.FileName := SoundFile;
539 MediaPlayer1.Open;
540 MediaPlayer1.Play;
541 MPSetVolume(MediaPlayer1, SoundVolume);
542 except
543 Dialogs.ShowMessage('Zadaný zvukový soubor pro událost '+AppEvents[Integer(EventType)].EventName+' není audio soubor nebo nebyl nalezen!');
544 end;
545 end;
546
547 try
548 if ExecuteApplication then ShellLaunch(ApplicationFile);
549 except
550 Dialogs.ShowMessage('Zadaný program ke spuštění pro událost '+AppEvents[Integer(EventType)].EventName+' nebyl nalezen!');
551 end;
552
553 with SunriseChatNetworkCore1 do
554 if (not Visible) and ShowBalloonHint then
555 CoolTrayIcon1.ShowBalloonHint(ApplicationName+' - Zpráva', RoomLine.Text, bitInfo, 10);
556
557 // Change tray icon
558 if ShowAlertIcon and MinimizeToTray and (not Visible) and FileExists(IconFile) then begin
559 Icon:= TIcon.Create;
560 try
561 Icon.LoadFromFile(IconFile);
562 CoolTrayIcon1.IconList.ReplaceIcon(6,Icon);
563 CoolTrayIcon1.IconIndex:= 6;
564 finally
565 Icon.Free;
566 end;
567 end;
568
569 if ShowMessage then with SunriseChatNetworkCore1 do begin
570 // Set text font
571 RoomLine.Font.Charset := MessageFont.Charset;
572 RoomLine.Font.Name := MessageFont.Name;
573 RoomLine.Font.Size := MessageFont.Size;
574 RoomLine.Font.Style := MessageFont.Style;
575 if EventType = aeOneUserMessage then begin
576 RoomLine.Font.Color := MessageFont.Color;
577 RoomLine.Font.Style := RoomLine.Font.Style + [fsBold];
578 end;
579
580 if (Room = nil) or (RoomList.IndexOf(ActiveRoom) = RoomList.IndexOf(Room)) then
581 begin
582 with RVStyle1.TextStyles do begin
583 AddFontEx(RoomLine.Font.Name, RoomLine.Font.Size, RoomLine.Font.Color, RoomLine.Font.Style, RoomLine.Font.Charset);
584
585 if ShowMessageTime then MessageTime := '['+TimeToStr(Now)+'] ' else MessageTime := '';
586 RichView1.AddNamedCheckPoint('a');
587 RichView1.AddFromNewLine(MessageTime, Count-1);
588
589 // Process user defined events
590 MessageTextTemp := RoomLine.Text;
591 TextStart := 1;
592 TextEnd := 1;
593 while TextEnd <= Length(MessageTextTemp) do begin
594 if (HttpHeader = Copy(MessageTextTemp, TextEnd, Length(HttpHeader))) or
595 (ShareHeader = Copy(MessageTextTemp, TextEnd, Length(ShareHeader))) or
596 (('"' + ShareHeader) = Copy(MessageTextTemp, TextEnd, Length(ShareHeader)+1)) then begin
597 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
598 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
599 TemporaryText := Copy(MessageTextTemp, TextEnd, High(Integer));
600 if TemporaryText[1] = '"' then begin
601 if Pos('"', Copy(TemporaryText, 2, High(Integer))) > 0 then
602 TemporaryText := Copy(TemporaryText, 1, Pos('"', Copy(TemporaryText, 2, High(Integer)))+1)
603 end else if(Pos(' ', TemporaryText)>0) then TemporaryText := Copy(TemporaryText, 1, Pos(' ', TemporaryText)-1);
604 RichView1.Add(TemporaryText, rvsJump1);
605 TextStart := TextEnd + Length(TemporaryText);
606 TextEnd := TextStart-1;
607 SetLength(HyperLinks, Length(HyperLinks) + 1);
608 HyperLinks[High(HyperLinks)] := TemporaryText;
609 end else
610 for I := 0 to High(AppUserEvents) do
611 with AppUserEvents[I] do begin
612 if (((not ConditionUserEnable) or (ConditionUserEnable and (ConditionUser = UserNick))) and
613 ((not ConditionTextEnable) or (ConditionTextEnable and (Length(ConditionText)>0)and (ConditionText = Copy(MessageTextTemp,TextEnd,Length(ConditionText))))) and
614 ((not ConditionAppEventEnable) or (ConditionAppEventEnable and (ConditionAppEvent = Integer(EventType))))) and
615 (ConditionAppEventEnable or ConditionTextEnable or ConditionUserEnable) then begin
616 // Show image instead text
617 if ShowImage and UserEventsImagesEnabled then begin
618 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
619 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
620
621 if not Assigned(Image) then begin
622 Image:= TImage.Create(Self);
623 if FileExists(ImageFile) then
624 Image.Picture.LoadFromFile(ImageFile);
625 end;
626 if Assigned(Image.Picture.Graphic) then RichView1.AddImage(Image, False)
627 else RichView1.AddText(ConditionText+'"Obrázek nenalezen!"',Count-1);
628
629 TextStart:= TextEnd + Length(ConditionText);
630 TextEnd:= TextStart-1;
631 end;
632
633 // Show call up
634 if ShowWindow then CallUp; //CoolTrayIcon1.ShowMainForm;
635
636 // Play sound
637 if not SoundDisable then begin
638 if PlayBeep then Beep;
639 if PlaySound then
640 try
641 MediaPlayer1.FileName:= SoundFile;
642 MediaPlayer1.Open;
643 MediaPlayer1.Play;
644 except
645 Dialogs.ShowMessage('Zadaný zvukový soubor pro uživatelskou událost '+EventName+' není audio soubor nebo nebyl nalezen!');
646 end;
647 end;
648 // Execute application
649 try
650 if ExecuteApplication then ShellLaunch(ApplicationFile);
651 except
652 Dialogs.ShowMessage('Zadaný program ke spuštění pro událost '+AppEvents[Integer(EventType)].EventName+' nebyl nalezen!');
653 end;
654
655 // Show balloon hint
656 with SunriseChatNetworkCore1 do
657 if (not Visible) and ShowBalloonHint then with SunriseChatNetworkCore1 do
658 CoolTrayIcon1.ShowBalloonHint(ApplicationName+' - Zpráva', RoomLine.Text, bitInfo,10);
659
660 // Change tray icon
661 if ShowAlertIcon and MinimizeToTray and (not Visible) and FileExists(IconFile) then begin
662 Icon:= TIcon.Create;
663 try
664 Icon.LoadFromFile(IconFile);
665 CoolTrayIcon1.IconList.ReplaceIcon(6,Icon);
666 CoolTrayIcon1.IconIndex:= 6;
667 finally
668 Icon.Free;
669 end;
670 end;
671 Break;
672 end;
673 end;
674 TextEnd:= TextEnd + 1;
675 end;
676 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
677 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
678 //Dialogs.ShowMessage(IntToStr(RichView1.CheckPointsCount));
679 if RichView1.CheckPointsCount > SunriseChatNetworkCore1.MaxRoomLines then
680 RichView1.DeleteSection('a');
681 RichView1.Format;
682 ScrollDownRichEdit1;
683 RichView1.Paint;
684 end;
685 end else begin
686 if RoomList.IndexOf(Room) < PageControl1.PageCount then
687 with PageControl1.Pages[RoomList.IndexOf(Room)] do begin
688 if ImageIndex = 25 then ImageIndex := 27;
689 if ImageIndex = 26 then ImageIndex := 28;
690 end;
691 end;
692 end else RoomLine.Text := '';;
693 end;
694end;
695
696procedure TMainWindow.Button1Click(Sender: TObject);
697var
698 TargetUser: string;
699 I: Integer;
700begin
701 //raise Exception.Create('Test');
702 if ComboBox1.Text <> '' then with SunriseChatNetworkCore1, ComboBox1 do begin
703 TRoom(RoomList[PageControl1.TabIndex]).Select;
704 LocalUser.Status := usOnline;
705 if Pos(':', Text) > 0 then TargetUser := Copy(Text, 1, Pos(':', Text)-1)
706 else TargetUser := '';
707
708 I := 0;
709 while (I < UserList.Count) and (TUser(UserList[I]).Nick <> TargetUser) do
710 I := I + 1;
711 if I < UserList.Count then begin
712 SunriseChatNetworkCore1.SendCommand(scMessage, ComboBox1.Text,
713 TUser(UserList[I]).Id.Machine, TUser(UserList[I]).Id.User);
714 end else SendCommand(scMessage, ComboBox1.Text);
715 end;
716 ComboBox1.Text := '';
717 ComboBox1.SetFocus;
718 lComboBox1Change(Self);
719end;
720
721procedure TMainWindow.FormShow(Sender: TObject);
722begin
723 FirstStart := False;
724 Options.SaveToRegistry;
725
726 LogExceptions.NazevAplikace := ApplicationName + ' ' +ClientVersion;
727 if MinimizeToTray then CoolTrayIcon1.HideTaskbarIcon
728 else CoolTrayIcon1.ShowTaskbarIcon;
729 CoolTrayIcon1.IconIndex := 5;
730 // Localization section
731 with Localization do begin
732 ActionAbout.Caption := Item('AboutProgram');
733 ActionAway.Caption := Item('AwayMode');
734 ActionBlockIP.Caption := Item('BlockUser');
735 ActionCallUp.Caption := Item('CallUp');
736 ActionClearMessageList.Caption := Item('ClearMessageList');
737 ActionClose.Caption := Item('Close');
738 ActionCreateRoom.Caption := Item('CreateRoom');
739 ActionInfo.Caption := Item('Information');
740 ActionInvisible.Caption := Item('Invisible');
741 ActionNetworkTest.Caption := Item('NetworkTest');
742 ActionOnline.Caption := Item('Online');
743 ActionOptions.Caption := Item('Options');
744 ActionRestore.Caption := Item('Restore');
745 ActionStatus.Caption := Item('Status');
746 ActionTestResponse.Caption := Item('ResponseTest');
747 ActionUserRoom.Caption := Item('InviteUserToRoom');
748 ActionChangeLog.Caption := Item('ChangeLog');
749
750 SearchFind1.Caption := Item('SearchText');
751 Label1.Caption := Item('UserList')+':';
752 Label2.Caption := Item('MessageList')+':';
753 Pedchozzprva1.Caption := Item('PreviousMessage');
754 Doplnitjmno1.Caption := Item('CompleteUserName');
755 Odejtzmstnosti1.Caption := Item('LeaveRoom');
756 Button1.Caption := Item('Send');
757 end;
758end;
759
760procedure TMainWindow.CallUp;
761begin
762 CoolTrayIcon1.ShowMainForm;
763 FormStyle := fsStayOnTop;
764// ShowMessage('Výzva');
765// CallUpWindow.Show;
766 BringWindowToTop(Handle);
767 //Timer1.Tag := 0;
768 //Timer1.Enabled := True;
769
770 //Windows.SetForegroundWindow(Handle);
771 //BringToFront;
772 //windows.SetFocus(Handle);
773 //FormStyle := fsStayOnTop;
774 // ShellLaunch('calc.exe');
775 if not OnTop then FormStyle := fsNormal;
776 //SwitchToThisWindow(Handle,True);
777 //TabControl1Change(Self);
778// RichEdit1.Repaint;
779end;
780
781procedure TMainWindow.Timer1Timer(Sender: TObject);
782begin
783 with SunriseChatNetworkCore1, LocalUser do begin
784 Repaint;
785 Beep;
786 Timer1.Tag := Timer1.Tag + 1;
787 if Timer1.Tag > 50 then Timer1.Enabled := False;
788// if SunriseChatCore.Connected then NewCaption:= '' else NewCaption:= '(offline)';
789// Caption:= 'SunriseChat'+NewCaption+' - '+SunriseChatCore.LocalUser.Nick;
790// Label1.Caption:= BoolToStr(CoolTrayIcon1.MinimizeToTray);
791// Label3.Caption:= BoolToStr(SunriseChatCore.fndTCPServer1.Active);
792// Label4.Caption:= IntToStr(SunriseChatCore.fndTCPServer1.ClientCount);
793 end;
794end;
795
796procedure TMainWindow.ChangeRunOnLogon;
797begin
798 // Check run on startup
799 with TRegistry.Create do
800 try
801 RootKey := HKEY_CURRENT_USER;
802 OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True);
803 if RunOnLogon then WriteString(ApplicationName+'-'+SettingsName,'"'+Application.ExeName+'" "/s:'+SettingsName+'"')
804 else DeleteValue(ApplicationName+'-'+SettingsName);
805 finally
806 Free;
807 end;
808end;
809
810procedure TMainWindow.ChangeNetworkState;
811begin
812 RefreshAppTitle;
813end;
814
815procedure TMainWindow.ShowUserList;
816var
817 I: Integer;
818 Node: TListItem;
819 Index: Integer;
820 LastCount: Integer;
821 NewImageIndex: Integer;
822
823function StatusToImageIndex(Status: TUserStatusMode): Integer;
824begin
825 if Status = usAway then Result:= 2
826 else if Status = usWriting then Result:= 4
827 else if Status = usInvisible then Result:= 7
828 else if Status = usOffline then Result:= 7
829 else Result:= 0;
830end;
831
832begin
833 with SunriseChatNetworkCore1, ListView1 do begin
834 if Assigned(ListView1.Selected) then Index := ListView1.Selected.Index
835 else Index := 0;
836 LastCount := ListView1.Items.Count;
837 //ListView1.Items.BeginUpdate;
838 //ListView1.Items.Clear;
839
840 // Add missing items to list
841 for I := 1 to UserList.Count - Items.Count do begin
842 Node := ListView1.Items.Add;
843 with Node do begin
844 Node.Caption := '';
845 ImageIndex:= 0;
846 end;
847 end;
848
849 // Delete excessive items from list
850 for I := 1 to Items.Count - UserList.Count do Items.Delete(Items.Count-1);
851
852 // Update all items
853 for I := 0 to UserList.Count-1 do with TUser(UserList[I]), Items.Item[I] do begin
854 if Caption <> Nick then Caption:= Nick;
855 if (Now - LastTime)>OfflineTimeout then NewImageIndex:= 7 else begin
856 if (IdleTime>(AutoAwayDelay * 60)) and (Status <> usAway) then NewImageIndex:= 1 else
857 NewImageIndex:= StatusToImageIndex(Status);
858 if BlockMessages then NewImageIndex:= 17;
859 end;
860 if NewImageIndex <> ImageIndex then ImageIndex:= NewImageIndex;
861 end;
862
863 //ListView1.Items.EndUpdate;
864
865 // Select previous selected item
866 try
867 with ListView1 do
868 if Items.Count>0 then
869 if Index < Items.Count then Selected:= Items.Item[Index] else
870 Selected:= Items.Item[Items.Count-1];
871 except
872 end;
873
874 // Automatically change window height according to user list count
875 if AutoChangeWindowHeight then
876 if LastCount <> ListView1.Items.Count then begin
877 LastCount:= ListView1.Items.Count;
878 if LastCount < MinimumVisibleUsersCount then LastCount:= MinimumVisibleUsersCount;
879 with MainWindow do begin
880 if not AutoChangeWindowHeightDirectionDown then
881 Top := Top - (LastCount * 17 - ListView1.Height + 10);
882 Height := Height + (LastCount * 17 - ListView1.Height + 10);
883 ListView1.Update;
884 end;
885 end;
886 end;
887end;
888
889procedure TMainWindow.ComboBox1KeyPress(Sender: TObject; var Key: Char);
890begin
891 if Key = #13 then begin
892 with ComboBox1 do
893 if DroppedDown and (Style <> csSimple) then begin
894 DroppedDown:= False;
895 Items.Clear;
896 SelStart:= Length(ComboBox1.Text);
897 ComboBox1.Style:= csSimple;
898 end else Button1Click(Self);
899 Key:= #0;
900 end;
901end;
902
903procedure TMainWindow.ComboBox1KeyDown(Sender: TObject; var Key: Word;
904 Shift: TShiftState);
905begin
906// ShowMessage(IntToStr(Key));
907 if Key = 38 then ComboBox1.Text := UserLastText;
908 if Key = 39 then with SunriseChatNetworkCore1 do DoplnitJmeno;
909end;
910
911procedure TMainWindow.ActionInfoExecute(Sender: TObject);
912begin
913 InfoWindow.ShowModal;
914end;
915
916procedure TMainWindow.ActionAwayExecute(Sender: TObject);
917begin
918 with SunriseChatNetworkCore1, LocalUser do
919 if Status <> usAway then begin
920 Reason := DefaultReason;
921 if ComboBox1.Text <> '' then begin
922 Reason := ComboBox1.Text;
923 ComboBox1.Text := '';
924 end else
925 if not InputQuery('Odchod pryč', 'Zadejte důvod nepřítomnosti', Reason) then Exit;
926 ActionAway.Checked := True;
927 Status := usAway;
928 SendCommand(scUserInfo);
929 ShowUserList;
930 ComboBox1.Enabled := False;
931 Button1.Enabled := False;
932 end;
933 //ShowUserList;
934end;
935
936procedure TMainWindow.ActionOnlineExecute(Sender: TObject);
937begin
938 ActionOnline.Checked := True;
939 with SunriseChatNetworkCore1, LocalUser do begin
940 if Status = usAway then begin
941 Status := usOnline;
942 SendCommand(scUserInfo);
943 end;
944 ShowUserList;
945 end;
946 ComboBox1.Enabled:= True;
947 Button1.Enabled:= True;
948 ShowUserList;
949end;
950
951procedure TMainWindow.ActionCloseExecute(Sender: TObject);
952begin
953 CloseEnabled:= True;
954 Close;
955end;
956
957procedure TMainWindow.ListView1Click(Sender: TObject);
958begin
959 with SunriseChatNetworkCore1 do
960 if Assigned(ListView1.Selected) then with ListView1.Selected do begin
961 if TUser(UserList[Index]).Status = usAway then
962 AddMessage(aeUserGoAway, ActiveRoom, [TUser(UserList[Index]).Nick, TUser(UserList[Index]).Reason]);
963 end;
964end;
965
966procedure TMainWindow.ActionTestResponseExecute(Sender: TObject);
967begin
968 with SunriseChatNetworkCore1 do
969 if Assigned(ListView1.Selected) then with ListView1.Selected do begin
970 SendCommand(scPing, TimeToStr(Now), TUser(UserList[Index]).Id.Machine, TUser(UserList[Index]).Id.User);
971 AddMessage(aeSendPing, ActiveRoom, [TUser(UserList[Index]).Nick]);
972 end;
973end;
974
975procedure TMainWindow.ActionRestoreExecute(Sender: TObject);
976begin
977 CoolTrayIcon1.ShowMainForm;
978end;
979
980procedure TMainWindow.ActionInvisibleExecute(Sender: TObject);
981begin
982 ActionInvisible.Checked := True;
983 SunriseChatNetworkCore1.LocalUser.Status := usInvisible;
984 ComboBox1.Enabled := False;
985 Button1.Enabled := False;
986 ShowUserList;
987end;
988
989procedure TMainWindow.ActionAboutExecute(Sender: TObject);
990begin
991 AboutWindow.ShowModal;
992end;
993
994procedure TMainWindow.ActionOptionsExecute(Sender: TObject);
995begin
996 OptionsWindow.ShowModal;
997end;
998
999procedure TMainWindow.ActionCallUpExecute(Sender: TObject);
1000begin
1001 with SunriseChatNetworkCore1 do
1002 if Assigned(ListView1.Selected) then with ListView1.Selected, TUser(UserList[Index]) do begin
1003 AddMessage(aeSendCallUp, nil, [Nick]);
1004 SendCommand(scCallUp, '', Id.Machine, Id.User);
1005 end;
1006end;
1007
1008
1009procedure TMainWindow.TabControl1Change(Sender: TObject);
1010var
1011 I, II: Integer;
1012 ForUser: string;
1013 MessageTime: string;
1014 MessageTextTemp: string;
1015 TextStart, TextEnd: Integer;
1016 TemporaryText: string;
1017begin
1018 SetLength(HyperLinks, 0);
1019 SunriseChatNetworkCore1.ActiveRoom := SunriseChatNetworkCore1.RoomList[PageControl1.TabIndex];
1020 with SunriseChatNetworkCore1, TRoom(RoomList[PageControl1.TabIndex]) do begin
1021 with PageControl1 do
1022 if ActiveRoom.Typ = rtPublic then Pages[TabIndex].ImageIndex:= 25
1023 else Pages[TabIndex].ImageIndex := 26;
1024 RichView1.Clear;
1025 ForUser := SunriseChatNetworkCore1.LocalUser.Nick+': ';
1026 for II := 0 to Count-1 do
1027 with SunriseChatNetworkCore1, RVStyle1.TextStyles, TRoomLine(Lines[(StartLine+II) mod MaxRoomLines]) do begin
1028
1029 AddFontEx(Font.Name, Font.Size, Font.Color, Font.Style, Font.Charset);
1030 if ShowMessageTime then MessageTime := '['+TimeToStr(Time)+'] ' else MessageTime:= '';
1031 RichView1.AddNamedCheckPoint('a');
1032 RichView1.AddFromNewLine(MessageTime, Count-1);
1033
1034 // Process user defined events
1035 MessageTextTemp:= Text;
1036 TextStart:= 1;
1037 TextEnd:= 1;
1038 while TextEnd <= Length(MessageTextTemp) do begin
1039 if (HttpHeader = Copy(MessageTextTemp, TextEnd, Length(HttpHeader))) or
1040 (ShareHeader = Copy(MessageTextTemp, TextEnd, Length(ShareHeader))) or
1041 (('"' + ShareHeader) = Copy(MessageTextTemp, TextEnd, Length(ShareHeader)+1)) then begin
1042 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
1043 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
1044 TemporaryText := Copy(MessageTextTemp, TextEnd, High(Integer));
1045 if TemporaryText[1] = '"' then begin
1046 if Pos('"', Copy(TemporaryText, 2, High(Integer))) > 0 then
1047 TemporaryText := Copy(TemporaryText, 1, Pos('"', Copy(TemporaryText, 2, High(Integer)))+1)
1048 end else if(Pos(' ', TemporaryText)>0) then TemporaryText := Copy(TemporaryText, 1, Pos(' ', TemporaryText)-1);
1049 RichView1.Add(TemporaryText, rvsJump1);
1050 TextStart := TextEnd + Length(TemporaryText);
1051 TextEnd := TextStart-1;
1052 SetLength(HyperLinks, Length(HyperLinks)+1);
1053 HyperLinks[High(HyperLinks)] := TemporaryText;
1054 end else
1055 for I:= 0 to High(AppUserEvents) do
1056 with AppUserEvents[I] do begin
1057 if (((not ConditionUserEnable) or (ConditionUserEnable and (ConditionUser = Nick))) and
1058 ((not ConditionTextEnable) or (ConditionTextEnable and (ConditionText = Copy(MessageTextTemp,TextEnd,Length(ConditionText))))) and
1059 (ConditionText <> '') and
1060 ((not ConditionAppEventEnable) or (ConditionAppEventEnable and (ConditionAppEvent = Integer(EventType))))) and
1061 (ConditionAppEventEnable or ConditionTextEnable or ConditionUserEnable) then begin
1062 // Show image instead text
1063 if ShowImage and UserEventsImagesEnabled then begin
1064 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
1065 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
1066 if not Assigned(Image) then begin
1067 Image:= TImage.Create(Self);
1068 if FileExists(ImageFile) then
1069 Image.Picture.LoadFromFile(ImageFile);
1070 end;
1071 if Assigned(Image.Picture.Graphic) then RichView1.AddImage(Image, False)
1072 else RichView1.AddText(ConditionText+'"Obrázek nenalezen!"',Count-1);
1073 TextStart:= TextEnd + Length(ConditionText);
1074 TextEnd:= TextStart-1;
1075 Break;
1076 end;
1077 end;
1078 end;
1079 TextEnd:= TextEnd + 1;
1080 end;
1081 if (MessageTime = '') and (TextStart = 1) then RichView1.AddTextFromNewLine(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1)
1082 else RichView1.AddText(Copy(MessageTextTemp,TextStart,TextEnd-TextStart),Count-1);
1083 end;
1084 RichView1.Format;
1085 ScrollDownRichEdit1;
1086 RichView1.Paint;
1087 end;
1088end;
1089
1090procedure TMainWindow.ActionBlockIPExecute(Sender: TObject);
1091begin
1092 with SunriseChatNetworkCore1 do
1093 if Assigned(ListView1.Selected) then
1094 with ListView1.Selected, TUser(UserList[Index]) do begin
1095 BlockMessages:= not BlockMessages;
1096 ShowUserList;
1097 end;
1098end;
1099
1100procedure TMainWindow.FormCloseQuery(Sender: TObject;
1101 var CanClose: Boolean);
1102begin
1103 CanClose:= CloseEnabled;
1104 if MinimalizeOnCloseWindow then begin
1105 CoolTrayIcon1.HideMainForm;
1106 end else CanClose:= True;
1107end;
1108
1109procedure TMainWindow.ActionUserRoomExecute(Sender: TObject);
1110begin
1111 if Assigned(ListView1.Selected) then
1112 with ListView1.Selected, SunriseChatNetworkCore1, TUser(UserList[Index]) do begin
1113 if ActiveRoom.Typ = rtPublic then ShowMessage('Nelze pozvat uživatele do veřejné místnosti!')
1114 else begin
1115 SendCommand(scCreateRoom, '', Id.Machine, Id.User);
1116 AddMessage(aeUserInvited, ActiveRoom, [Nick]);
1117 //if (IP<>LocalUser.IP) or (ID<>LocalUser.ID) then SendCommand('CreateRoom','',LocalUser.IP,LocalUser.ID);
1118 end;
1119 end;
1120end;
1121
1122procedure TMainWindow.RoomListChanged;
1123var
1124 I: Integer;
1125// T: TListBox;
1126 NewTabSheet: TTabSheet;
1127begin
1128 with SunriseChatNetworkCore1 do with PageControl1 do begin
1129 while PageCount>0 do Pages[0].Free;
1130 for I:= 0 to RoomList.Count-1 do begin
1131 NewTabSheet := TTabSheet.Create(PageControl1);
1132 NewTabSheet.PageControl := PageControl1;
1133 NewTabSheet.Caption := TRoom(RoomList[I]).Name;
1134 if TRoom(RoomList[I]).Typ = rtPublic then NewTabSheet.ImageIndex:= 25
1135 else NewTabSheet.ImageIndex:= 26;
1136 end;
1137 Visible := PageCount > 1;
1138 if RoomList.IndexOf(ActiveRoom) = -1 then ActiveRoom := RoomList[0];
1139 ActivePageIndex := RoomList.IndexOf(ActiveRoom);
1140 PageControl1.TabIndex := ActivePageIndex;
1141 TabControl1Change(Self);
1142 end;
1143end;
1144
1145procedure TMainWindow.Odejtzmstnosti1Click(Sender: TObject);
1146begin
1147 with SunriseChatNetworkCore1 do
1148 if PageControl1.ActivePageIndex = 0 then ShowMessage('Tuto místnost nelze zrušit')
1149 else begin
1150 SendCommand(scLeaveRoom);
1151 DeleteRoom(PageControl1.ActivePageIndex);
1152 TabControl1Change(Self);
1153 end;
1154end;
1155
1156procedure TMainWindow.ActionCustomizeDlgExecute(Sender: TObject);
1157begin
1158 FormStyle:= fsNormal;
1159 CustomizeDlg1.Show;
1160// if OnTop then FormStyle:= fsStayOnTop;
1161end;
1162
1163procedure TMainWindow.PopupMenu2Popup(Sender: TObject);
1164begin
1165 with SunriseChatNetworkCore1 do
1166 if Assigned(ListView1.Selected) then
1167 with ListView1.Selected, SunriseChatNetworkCore1, TUser(UserList[Index]) do
1168 BlokovatAdresu1.Checked:= BlockMessages;
1169end;
1170
1171procedure TMainWindow.WMQueryEndSession(var Message: TMessage);
1172{ This method is a hack. It intercepts the WM_QUERYENDSESSION message.
1173 This way we can decide if we want to ignore the "Close to tray" option.
1174 Otherwise, when selected, the option would make Windows unable to shut down. }
1175begin
1176 CloseEnabled:= True;
1177 Message.Result:= 1;
1178end;
1179
1180procedure TMainWindow.Pedchozzprva1Click(Sender: TObject);
1181var
1182 I: Integer;
1183begin
1184 ComboBox1.Style:= csDropDown;
1185 with SunriseChatNetworkCore1, ComboBox1.Items do begin
1186 BeginUpdate;
1187 Clear;
1188 for I := ActiveRoom.Count-1 downto 0 do with ActiveRoom, TRoomLine(Lines[(I + StartLine) mod MaxRoomLines]) do begin
1189 Add(Text);
1190 end;
1191 Update;
1192 EndUpdate;
1193 if ComboBox1.Items.Count>0 then ComboBox1.DroppedDown:= True;
1194 end;
1195end;
1196
1197
1198procedure TMainWindow.DoplnitJmeno;
1199var
1200 I: Integer;
1201 UserIndex: Integer;
1202 NickCount: Integer;
1203begin
1204 UserIndex := -1;
1205 NickCOunt := 0;
1206 with SunriseChatNetworkCore1 do begin
1207 for I := 0 to UserList.Count-1 do begin
1208 if Length(ComboBox1.Text) <= Length(TUser(UserList[I]).Nick) then
1209 if ComboBox1.Text = Copy(TUser(UserList[I]).Nick, 1, Length(ComboBox1.Text)) then begin
1210 UserIndex := I;
1211 NickCount := NickCount + 1;
1212 end;
1213 end;
1214 if NickCount = 1 then begin
1215 ComboBox1.Text:= TUser(UserList[UserIndex]).Nick + ': ';
1216 ComboBox1.SelStart:= Length(ComboBox1.Text);
1217 end else
1218 if NickCount > 1 then FillComboBox;
1219 end;
1220end;
1221
1222procedure TMainWindow.ActionNetworkTestExecute(Sender: TObject);
1223begin
1224 NetworkTest.ShowModal;
1225end;
1226
1227procedure TMainWindow.ToolButton7Click(Sender: TObject);
1228begin
1229 Application.Minimize;
1230end;
1231
1232procedure TMainWindow.Vloit1Click(Sender: TObject);
1233begin
1234 SendMessage(ComboBox1.Handle, WM_PASTE, 0, 0);
1235end;
1236
1237procedure TMainWindow.Vloitsovodkaz1Click(Sender: TObject);
1238begin
1239 if OpenDialog1.Execute then begin
1240 if Pos(' ', OpenDialog1.FileName) > 0 then
1241 ComboBox1.Text := ComboBox1.Text + '"' + OpenDialog1.FileName + '"'
1242 else
1243 ComboBox1.Text := ComboBox1.Text + OpenDialog1.FileName;
1244 end;
1245end;
1246
1247procedure TMainWindow.CoolTrayIcon1Click(Sender: TObject);
1248begin
1249// RichEdit1.Lines.Add(IntToStr(GetForegroundWindow)+' '+IntToStr(MainWindow.Handle)+' '+IntToStr(Application.Handle));
1250// if GetForegroundWindow = Application.Handle then CoolTrayIcon1.HideMainForm else
1251 if MainWindow.Visible then CoolTrayIcon1.HideMainForm else
1252 CoolTrayIcon1.ShowMainForm;
1253end;
1254
1255procedure TMainWindow.ToolButton1Click(Sender: TObject);
1256begin
1257// ToolButton1.Marked := not ToolButton1.Marked;
1258 PauseScrollText := ToolButton1.Down;
1259end;
1260
1261procedure TMainWindow.ToolButton3Click(Sender: TObject);
1262begin
1263 ActionOptionsExecute(Self);
1264end;
1265
1266procedure TMainWindow.ToolButton2Click(Sender: TObject);
1267begin
1268 ActionInfoExecute(Self);
1269end;
1270
1271procedure TMainWindow.ToolButton5Click(Sender: TObject);
1272begin
1273// ToolButton5.Marked:= not ToolButton5.Marked;
1274 OnTop:= ToolButton5.Down;
1275 InitTrayIcon;
1276end;
1277
1278procedure TMainWindow.ToolButton4Click(Sender: TObject);
1279begin
1280// ToolButton4.Marked:= not ToolButton4.Marked;
1281 SoundDisable:= ToolButton4.Down;
1282end;
1283
1284procedure TMainWindow.ScrollDownRichEdit1;
1285begin
1286 if not PauseScrollText then begin
1287 RichView1.ScrollTo(High(Integer));
1288 RichView1.Paint;
1289 (*
1290 // Scroll down Richedit
1291 ScrollMessage.Msg:= WM_VScroll;
1292
1293 ScrollMessage.ScrollCode:= sb_Bottom;
1294 ScrollMessage.Pos:= 0;
1295 RichEdit1.Dispatch(ScrollMessage);
1296 if Win32Platform = 1 then begin
1297 ScrollMessage.Msg:= WM_VScroll;
1298 begin
1299 ScrollMessage.ScrollCode:= SB_PAGEUP;
1300 ScrollMessage.Pos:= 0;
1301 RichEdit1.Dispatch(ScrollMessage);
1302 end;
1303 end;
1304 *)
1305 end;
1306end;
1307
1308
1309procedure TMainWindow.AppMessage(var Msg: TMsg; var Handled: Boolean);
1310begin
1311 if Msg.Message = WM_SunriseChatStart then begin
1312 if HWND(Msg.wParam) <> Application.Handle then begin
1313 if OneAppInstance then begin
1314 Application.Restore;
1315 CoolTrayIcon1.ShowMainForm;
1316 SetForeGroundWindow(Application.MainForm.Handle);
1317 PostMessage(HWND_BROADCAST, WM_SunriseChatClose, Application.Handle, 0);
1318 end;
1319 end;
1320 Handled := true;
1321 end;
1322 if Msg.Message = WM_SunriseChatClose then begin
1323 if HWND(Msg.wParam) <> Application.Handle then begin
1324 if OneAppInstance then begin
1325 NoSaveToRegistry:= True;
1326 StopProgram:= True;
1327 end;
1328 end;
1329 Handled := true;
1330 end;
1331end;
1332
1333procedure TMainWindow.RichEdit1MouseDown(Sender: TObject;
1334 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1335begin
1336 SendMessage(HWND_BROADCAST,WM_SunriseChatStart,0,0);
1337end;
1338
1339procedure TMainWindow.RichView1Jump(Sender: TObject; id: Integer);
1340var
1341 Url: string;
1342begin
1343 Url := HyperLinks[id];
1344 if Url[1] = '"' then Delete(Url, 1, 1);
1345 if Pos('"', Url) > 0 then Delete(Url, Length(Url), 1);
1346 ShellExecute(Handle, 'open', PChar(Url), nil, nil, SW_SHOWNORMAL);
1347end;
1348
1349procedure TMainWindow.lComboBox1Change(Sender: TObject);
1350begin
1351 with SunriseChatNetworkCore1 do begin
1352 if (ComboBox1.Text = '') and (Length(LastText) > 0) then begin
1353 LocalUser.Status := usOnline;
1354 SendCommand(scUserInfo);
1355 end;
1356 if (Length(ComboBox1.Text) > 0) and (Length(LastText) = 0) then begin
1357 LocalUser.Status := usWriting;
1358 SendCommand(scUserInfo);
1359 end;
1360 LastText := ComboBox1.Text;
1361 end;
1362// if Edit1.Text='' then SunriseChatCore.LocalUser.Status:= usOnline;
1363end;
1364
1365procedure TMainWindow.AddEvent(Name, Text: string; Options: TEventOptions);
1366begin
1367 SetLength(AppEventsInit, Length(AppEventsInit) + 1);
1368 with AppEventsInit[High(AppEventsInit)] do begin
1369 EventName := Name;
1370 ShowMessage := eoShowMessage in Options;
1371 MessageText := Text;
1372 MessageFont := TFont.Create;
1373 ShowBalloonHint := eoShowBalloonHint in Options;
1374 ShowAlertIcon := eoShowAlertIcon in Options;
1375 ShowWindow := eoShowWindow in Options;
1376 PlayBeep := eoPlayBeep in Options;
1377 end;
1378end;
1379
1380procedure TMainWindow.SaveAppEventsToRegistry;
1381var
1382 I: Integer;
1383begin
1384 for I:= 0 to High(AppEventsOptions) do with AppEvents[I] do begin
1385 MessageFontTemp.Color := MessageFont.Color;
1386 MessageFontTemp.Style:= '';
1387 if fsBold in MessageFont.Style then MessageFontTemp.Style := MessageFontTemp.Style + 'Bold,';
1388 if fsItalic in MessageFont.Style then MessageFontTemp.Style := MessageFontTemp.Style + 'Italic,';
1389 if fsUnderline in MessageFont.Style then MessageFontTemp.Style := MessageFontTemp.Style + 'Underline,';
1390 if fsStrikeOut in MessageFont.Style then MessageFontTemp.Style := MessageFontTemp.Style + 'StrikeOut,';
1391 MessageFontTemp.Charset := MessageFont.Charset;
1392 MessageFontTemp.Size := MessageFont.Size;
1393 MessageFontTemp.Name := MessageFont.Name;
1394
1395 AppEventsOptions[I].SaveToRegistry;
1396 AppEventsOptions[I].Free;
1397 end;
1398 SetLength(AppEventsOptions,0);
1399 LoadAppEventsFromRegistry;
1400end;
1401
1402procedure TMainWindow.SaveAppUserEventsToRegistry;
1403var
1404 I: Integer;
1405 Max: Integer;
1406begin
1407 AppUserEventsCount := Length(AppUserEvents);
1408 Max := High(AppUserEventsOptions);
1409 for I := 0 to Max do begin
1410 if I<Length(AppUserEvents) then AppUserEventsOptions[I].SaveToRegistry;
1411 //AppUserEventsOptions[I].Free;
1412 if Assigned(JobProgressView) then JobProgressView.Progress := I/Max;
1413 end;
1414 //SetLength(AppUserEventsOptions,0);
1415 //LoadAppUserEventsFromRegistry;
1416end;
1417
1418procedure TMainWindow.LoadAppEventsFromRegistry;
1419var
1420 I: Integer;
1421 Text: string;
1422begin
1423 SetLength(AppEventsOptions, Length(AppEvents));
1424 for I := 0 to High(AppEventsOptions) do begin
1425 //if not Assigned(AppEventsOptions[I]) then
1426 AppEventsOptions[I] := TAutoRegistry.Create(RegistryPath + '\' + SettingsName +
1427 '\AppEvents\' + IntToStr(I));
1428 with AppEventsOptions[I], AppEvents[I] do begin
1429 Include('ShowWindow', ShowWindow, ShowWindow);
1430 Include('ShowAlertIcon', ShowAlertIcon, ShowAlertIcon);
1431 Include('ShowBaloonHint', ShowBalloonHint, ShowBalloonHint);
1432 Include('PlayBeep', PlayBeep, PlayBeep);
1433 Include('PlaySound' ,PlaySound, PlaySound);
1434 Include('SoundFile', SoundFile, '');
1435 Include('ExecuteApplication', ExecuteApplication, False);
1436 Include('ApplicationFile', ApplicationFile, '');
1437 Include('ShowMessage', ShowMessage, ShowMessage);
1438 Include('MessageText', MessageText, MessageText);
1439 Include('IconFile', IconFile, 'Envelope.ico');
1440 // Font
1441 Include('FontColor', MessageFontTemp.Color, Integer(clBlack));
1442 Include('FontStyle', MessageFontTemp.Style, '');
1443 Include('FontCharset', MessageFontTemp.Charset, 1);
1444 Include('FontSize', MessageFontTemp.Size, 8);
1445 Include('FontName', MessageFontTemp.Name, 'MS Sans Serif');
1446 LoadFromRegistry;
1447 MessageFont.Color := MessageFontTemp.Color;
1448 while Pos(',', MessageFontTemp.Style) > 0 do begin
1449 Text := Copy(MessageFontTemp.Style, 1, Pos(',', MessageFontTemp.Style) - 1);
1450 System.Delete(MessageFontTemp.Style, 1, Length(Text) + 1);
1451 if Text = 'Bold' then MessageFont.Style := MessageFont.Style + [fsBold];
1452 if Text = 'Italic' then MessageFont.Style := MessageFont.Style + [fsItalic];
1453 if Text = 'Underline' then MessageFont.Style := MessageFont.Style + [fsUnderline];
1454 if Text = 'StrikeOut' then MessageFont.Style := MessageFont.Style + [fsStrikeOut];
1455 end;
1456 MessageFont.Charset := MessageFontTemp.Charset;
1457 MessageFont.Size := MessageFontTemp.Size;
1458 MessageFont.Name := MessageFontTemp.Name;
1459 end;
1460 end;
1461end;
1462
1463procedure TMainWindow.LoadAppUserEventsFromRegistry(UpdateOnly: Boolean = False);
1464var
1465 I: Integer;
1466begin
1467 SetLength(AppUserEventsOptions, AppUserEventsCount);
1468 SetLength(AppUserEvents, AppUserEventsCount);
1469 for I := 0 to AppUserEventsCount - 1 do begin
1470 //if not Assigned(AppEventsOptions[I]) then
1471 AppUserEventsOptions[I] := TAutoRegistry.Create(RegistryPath + '\' +
1472 SettingsName + '\AppUserEvents\' + IntToStr(I));
1473 with AppUserEventsOptions[I], AppUserEvents[I] do begin
1474 Update := UpdateOnly;
1475 Include('ConditionTextEnable', ConditionTextEnable, ConditionTextEnable);
1476 Include('ConditionText', ConditionText, ConditionText);
1477 Include('ConditionUserEnable', ConditionUserEnable, ConditionUserEnable);
1478 Include('ConditionUser', ConditionUser, ConditionUser);
1479 Include('ConditionAppEventEnable', ConditionAppEventEnable, ConditionAppEventEnable);
1480 Include('ConditionAppEvent', ConditionAppEvent, ConditionAppEvent);
1481 Include('ShowWindow', ShowWindow, ShowWindow);
1482 Include('ShowAlertIcon', ShowAlertIcon, ShowAlertIcon);
1483 Include('IconFile', IconFile, 'Envelope.ico');
1484 Include('ShowBaloonHint', ShowBalloonHint, ShowBalloonHint);
1485 Include('PlayBeep', PlayBeep, PlayBeep);
1486 Include('PlaySound', PlaySound, PlaySound);
1487 Include('SoundFile', SoundFile, '');
1488 Include('ExecuteApplication', ExecuteApplication, False);
1489 Include('ApplicationFile', ApplicationFile, '');
1490 Include('ShowImage', ShowImage, ShowImage);
1491 Include('ImageFile', ImageFile, ImageFile);
1492 Include('EventName', EventName, EventName);
1493 LoadFromRegistry;
1494 end;
1495 if Assigned(JobProgressView) then JobProgressView.Progress := I / AppUserEventsCount;
1496 end;
1497end;
1498
1499procedure TMainWindow.Log1Click(Sender: TObject);
1500begin
1501 ProtocolMessageLogForm.Show;
1502end;
1503
1504procedure TMainWindow.RefreshAppTitle;
1505var
1506 NewCaption: string;
1507 Settings: string;
1508begin
1509 if SettingsName = 'Default' then Settings:= '' else Settings:= '(' + SettingsName + ')';
1510 if SunriseChatNetworkCore1.Connected then NewCaption := ''
1511 else NewCaption := ' (Offline)';
1512 Caption := ApplicationName + Settings + ' - ' +
1513 SunriseChatNetworkCore1.LocalUser.Nick + NewCaption;
1514end;
1515
1516procedure TMainWindow.ListView1InfoTip(Sender: TObject; Item: TListItem;
1517 var InfoTip: String);
1518begin
1519 InfoTip := TUser(SunriseChatNetworkCore1.UserList[Item.Index]).DetailInfo;
1520end;
1521
1522procedure TMainWindow.ActionCreateRoomExecute(Sender: TObject);
1523begin
1524 NewRoom.ShowModal;
1525end;
1526
1527procedure TMainWindow.Doplnitjmno1Click(Sender: TObject);
1528begin
1529 //if Pos(':',ComboBox1.Text) = 0 then
1530 DoplnitJmeno;
1531 ComboBox1.SelStart := ComboBox1.SelStart + 1;
1532end;
1533
1534procedure TMainWindow.SearchFind1FindDialogFind(Sender: TObject);
1535//var
1536// FoundAt: LongInt;
1537// StartPos, ToEnd: Integer;
1538// STypes: TSearchTypes;
1539begin
1540(*
1541 with SearchFind1, RichEdit1 do begin
1542 if frWholeWord in Dialog.Options then STypes := STypes + [stWholeWord];
1543 if frMatchCase in Dialog.Options then STypes := STypes + [stMatchCase];
1544 if SelLength <> 0 then StartPos := SelStart + SelLength
1545 else StartPos := 0;
1546 ToEnd := Length(Text) - StartPos;
1547 FoundAt := FindText(Dialog.FindText, StartPos, ToEnd, Stypes);
1548 if FoundAt <> -1 then begin
1549 SetFocus;
1550 SelStart := FoundAt;
1551 SelLength := Length(Dialog.FindText);
1552 end else ShowMessage(Dialog.FindText+' nelze najít');
1553 end;
1554*)
1555end;
1556
1557procedure TMainWindow.SearchFind1BeforeExecute(Sender: TObject);
1558begin
1559 SearchFind1.Dialog.Options := [frHideUpDown];
1560end;
1561
1562procedure TMainWindow.ActionClearMessageListExecute(Sender: TObject);
1563var
1564 I: Integer;
1565begin
1566 with SunriseChatNetworkCore1 do begin
1567 for I := 0 to ActiveRoom.Count - 1 do
1568 TRoomLine(ActiveRoom.Lines[I]).Font.Free;
1569 ActiveRoom.Count := 0;
1570 TabControl1Change(Self);
1571 end;
1572end;
1573
1574procedure TMainWindow.InitSettings;
1575var
1576 I: Integer;
1577begin
1578 with Options, SunriseChatNetworkCore1 do begin
1579 Include('UserEventsImagesEnabled', UserEventsImagesEnabled, True);
1580 Include('ShowRightToolBar', ShowRightToolBar, True);
1581 Include('MinimalizeOnCloseWindow', MinimalizeOnCloseWindow, False);
1582 Include('DefaultReason', DefaultReason, 'Jsem pryč');
1583 Include('NoResloveHostName', NoResloveHostName, False);
1584 Include('ShowMainMenu', ShowMainMenu, True);
1585 MainMenu1.Items.Visible := ShowMainMenu;
1586 Include('ShowMessageTime', ShowMessageTime, False);
1587 Include('AlphaBlend', AlphaBlendWindow, 255);
1588 Include('UserListWidth', UserListWidth, 100);
1589 Include('ShowOnMessage', ShowOnMessage, False);
1590 Include('ShowBallonHint', ShowBallonHint, False);
1591 Include('OnTop', OnTop, False);
1592 Include('RunOnLogon', RunOnLogon, True);
1593 Include('StartInTray', StartInTray, False);
1594 Include('MinimizeToTray', MinimizeToTray, True);
1595 Include('ServiceFunction', ServiceFunction, False);
1596 Include('Nick', UserNick, 'Host');
1597 Include('DetailInfo', LocalUser.DetailInfo, '');
1598 LocalUser.NickTime := Now;
1599 Include('Color', LocalUser.Color, 0);
1600 Include('SnapWindow', SnapWindow, True);
1601 Include('Port', NetworkPort, 55557);
1602 Include('NetworkInterfaceGUID', NetworkInterface, '');
1603 Include('PositionX',PositionX, Left);
1604 if (PositionX < 0) or (PositionX > Screen.Width) then PositionX := 0;
1605 Include('PositionY',PositionY,Top);
1606 if (PositionY < 0) or (PositionY > Screen.Height) then PositionY := 0;
1607 Include('SizeX', SizeX, Width);
1608 Include('SizeY', SizeY, Height);
1609 Include('WindowState', LastWindowState, Integer(fsNormal));
1610 Include('AutoAwayIdleTime', UsersAutoAwayDelay, 5);
1611 Include('PauseScrollText', PauseScrollText, False);
1612 Include('SoundDisable', SoundDisable, False);
1613 Include('OneAppInstance', OneAppInstance, True);
1614 Include('MaxNumberOfRoomLines', MaxNumberOfRoomLines, 100);
1615 Include('AutoChangeWindowHeight', AutoChangeWindowHeight, False);
1616 Include('AutoChangeWindowHeightDirectionDown', AutoChangeWindowHeightDirectionDown, False);
1617 Include('MinimumVisibleUsersCount', MinimumVisibleUsersCount, 8);
1618 Include('PingTimeout', PingTimeout, 200);
1619 Include('LanguageIndex', LanguageIndex, 0);
1620 Include('InvisibledOnStart', InvisibledOnStart, False);
1621 Include('AutoChangeInfoWindowHeight', AutoChangeInfoWindowHeight, True);
1622 Include('AppUserEventsCount', AppUserEventsCount, 0);
1623 Include('FirstStart', FirstStart, True);
1624 Include('BroadcastType', BroadcastTypeI, 0);
1625 Include('SoundVolume', SoundVolume, 1000);
1626 LoadFromRegistry;
1627 AutoAwayDelay := UsersAutoAwayDelay;
1628 LocalUser.Nick := UserNick;
1629 MPSetVolume(MediaPlayer1, SoundVolume);
1630 SunriseChatNetworkCore1.BroadcastType := TBroadcastType(BroadcastTypeI);
1631 if InvisibledOnStart then ActionInvisibleExecute(Self) else ActionOnlineExecute(Self);
1632 Localization.Activate(LanguageIndex);
1633 SunriseChatNetworkCore1.MaxRoomLines := MaxNumberOfRoomLines;
1634 MainWindow.ScreenSnap := SnapWindow;
1635 ToolButton1.Down := PauseScrollText;
1636 ToolButton4.Down := SoundDisable;
1637 ToolButton5.Down := OnTop;
1638 Left := PositionX;
1639 Top := PositionY;
1640 Width := SizeX;
1641 Height := SizeY;
1642 WindowState := TWindowState(LastWindowState);
1643 Panel2.Width := UserListWidth;
1644 AlphaBlendValue := AlphaBlendWindow;
1645 AlphaBlend := AlphaBlendValue < 255;
1646
1647 // Initialisation of Events
1648 AddEvent('Běžná zpráva', '<%0:s> %1:s', [eoShowMessage, eoPlayBeep, eoShowAlertIcon]);
1649 AddEvent('Osobní zpráva', '<%0:s> %1:s', [eoShowMessage, eoPlayBeep, eoShowAlertIcon, eoShowBalloonHint]);
1650 AddEvent('Uživatel se připojil', 'Uživatel %0:s se připojil z počítače %1:s', [eoShowMessage]);
1651 AddEvent('Uživatel se odpojil', 'Uživatel %s se odpojil', [eoShowMessage]);
1652 AddEvent('Uživatel obnoven', 'Uživatel %s obnoven', []);
1653 AddEvent('Uživatel zmizel', 'Uživatel %s zmizel', []);
1654 AddEvent('Uživatel odešel', 'Uživatel %0:s odešel: %1:s', [eoShowMessage]);
1655 AddEvent('Uživatel se vrátil', 'Uživatel %s se vrátil', []);
1656 AddEvent('Odeslání výzvy', 'Výzva uživateli %s byla odeslána', [eoShowMessage]);
1657 AddEvent('Přijetí výzvy', 'Uživatel %s vás vyzval', [eoShowMessage, eoShowWindow, eoPlayBeep]);
1658 AddEvent('Test odezvy', 'Odezva uživateli %s byla odeslána', [eoShowMessage]);
1659 AddEvent('Přijetí odezvy', 'Odezva od uživatele %0:s přijata za %1:s sekund', [eoShowMessage]);
1660 AddEvent('Změna jména uživatele', 'Uživatel %0:s se přejmenoval na %1:s', [eoShowMessage]);
1661 AddEvent('Změna jména při konfliktu', 'Došlo ke konfliktu jmen. Měním vaše jméno na %s', [eoShowMessage]);
1662 AddEvent('Vytvoření místnosti', 'Uživatel %0:s vytvořil místnost %1:s', [eoShowMessage]);
1663 AddEvent('Opuštění místnosti', 'Uživatel %0:s opustil místnosti %1:s', [eoShowMessage]);
1664 AddEvent('Uživatel automaticky odešel', 'Uživatel %0:s automaticky odešel po %1:s minutách nečinnosti', []);
1665 AddEvent('Uživatel se automaticky vrátil', 'Uživatel %0:s se automaticky vrátil po %1:s minutách', []);
1666 AddEvent('Celé hodiny', 'Je %0:d hodin', []);
1667 AddEvent('Start aplikace', 'Vítá tě '+ApplicationName+'!', [eoShowMessage]);
1668 AddEvent('Ukončení aplikace', 'Loučí se s tebou '+ApplicationName+'!', [eoShowMessage]);
1669 AddEvent('Pozvání do soukromé místnosti', 'Uživatel %0:s pozván do místnosti', [eoShowMessage]);
1670 AddEvent('Volitelná událost', 'Volitelná událost', []);
1671 SetLength(AppEvents, Length(AppEventsInit));
1672 for I := 0 to High(AppEventsInit) do
1673 AppEvents[I] := AppEventsInit[I];
1674 SetLength(AppEventsInit, 0);
1675 LoadAppEventsFromRegistry;
1676
1677 LoadAppUserEventsFromRegistry;
1678 ReloadImages;
1679
1680 CoolTrayIcon1.Hint := ApplicationName;
1681 if OnTop then FormStyle := fsStayOnTop else FormStyle := fsNormal;
1682 InitTrayIcon;
1683 ChangeRunOnLogon;
1684 Panel5.Visible := ShowRightToolBar;
1685 Panel2.Visible := False;
1686 Panel2.Visible := True;
1687 end;
1688end;
1689
1690procedure TMainWindow.ComboBox1Change(Sender: TObject);
1691begin
1692 lComboBox1Change(Self);
1693end;
1694
1695procedure TMainWindow.FillComboBox;
1696var
1697 I: Integer;
1698begin
1699 ComboBox1.Style := csDropDown;
1700 with SunriseChatNetworkCore1, ComboBox1.Items do begin
1701 BeginUpdate;
1702 Clear;
1703 for I := 0 to UserList.Count - 1 do with TUser(UserList[I]) do begin
1704 if Copy(Nick, 1, Length(ComboBox1.Text)) = ComboBox1.Text then Add(Nick + ': ');
1705 end;
1706 Update;
1707 EndUpdate;
1708 if ComboBox1.Items.Count > 0 then ComboBox1.DroppedDown:= True;
1709 end;
1710end;
1711
1712procedure TMainWindow.ActionChangeLogExecute(Sender: TObject);
1713begin
1714 ShellLaunch(ChangeLogFile);
1715end;
1716
1717procedure TMainWindow.ComboBox1DropDown(Sender: TObject);
1718begin
1719 ComboBox1.Style := csSimple;
1720end;
1721
1722procedure TMainWindow.ComboBox1CloseUp(Sender: TObject);
1723begin
1724 ComboBox1.Style := csSimple;
1725 ComboBox1.SelStart := -1;
1726end;
1727
1728procedure TMainWindow.FormResize(Sender: TObject);
1729begin
1730 ScrollDownRichEdit1;
1731end;
1732
1733procedure TMainWindow.ReloadImages;
1734var
1735 I: Integer;
1736begin
1737 RichView1.Clear;
1738 for I := 0 to High(AppUserEvents) do
1739 if Assigned(AppUserEvents[I].Image) then FreeAndNil(AppUserEvents[I].Image);
1740 TabControl1Change(Self);
1741(*
1742 for I:= 0 to High(AppUserEvents) do
1743with AppUserEvents[I] do begin
1744 if not Assigned(Image) then Image:= TImage.Create(Self);
1745 if FileExists(ImageFile) then
1746 Image.Picture.LoadFromFile(ImageFile);
1747 end;
1748 RichView1.Paint;
1749*)
1750end;
1751
1752procedure TMainWindow.ActionUserEventsListExecute(Sender: TObject);
1753var
1754 I: Integer;
1755 StringList: TStringList;
1756begin
1757 ComboBox1.Style := csDropDown;
1758 StringList := TStringList.Create;
1759 try
1760 with SunriseChatNetworkCore1, StringList do begin
1761 BeginUpdate;
1762 for I := 0 to High(AppUserEvents) do with AppUserEvents[I] do begin
1763 Add(ComboBox1.Text+EventName);
1764 end;
1765 Sort;
1766 EndUpdate;
1767 end;
1768 with SunriseChatNetworkCore1, ComboBox1, Items do begin
1769 BeginUpdate;
1770 Clear;
1771 AddStrings(StringList);
1772 if Count > 0 then DroppedDown:= True;
1773 Update;
1774 EndUpdate;
1775 end;
1776 finally
1777 StringList.Free;
1778 end;
1779end;
1780
1781procedure TMainWindow.ToolButton6Click(Sender: TObject);
1782begin
1783// ToolButton6.Marked := not ToolButton6.Marked;
1784 ToolButton6.Repaint;
1785 UserEventsImagesEnabled := not ToolButton6.Down;
1786 TabControl1Change(Self);
1787end;
1788
1789procedure TMainWindow.Panel6Resize(Sender: TObject);
1790begin
1791 RichView1.Width := Panel6.Width - 2;
1792 RichView1.Height := Panel6.Height - 2;
1793end;
1794
1795procedure TMainWindow.SunriseChatNetworkCore1RoomListChanged;
1796begin
1797 RoomListChanged;
1798end;
1799
1800procedure TMainWindow.SunriseChatNetworkCore1UserListUpdate;
1801begin
1802 ShowUserList;
1803end;
1804
1805procedure TMainWindow.FormDestroy(Sender: TObject);
1806var
1807 I: Integer;
1808begin
1809 UsersAutoAwayDelay := SunriseChatNetworkCore1.AutoAwayDelay;
1810 UserNick := SunriseChatNetworkCore1.LocalUser.Nick;
1811// IdleTrackerTerm;
1812 //Timer1.Enabled:= False;
1813 BroadcastTypeI := Integer(SunriseChatNetworkCore1.BroadcastType);
1814 PositionX := Left;
1815 PositionY := Top;
1816 SizeX := Width;
1817 SizeY := Height;
1818 LastWindowState := Integer(WindowState);
1819 UserListWidth := Panel2.Width;
1820 if not NoSaveToRegistry then Options.SaveToRegistry;
1821 ShowBallonHint := False;
1822 SoundDisable := True;
1823 SunriseChatNetworkCore1.SendCommand(scDisconnect);
1824 SunriseChatNetworkCore1.Free;
1825 Options.Free;
1826 for I := 0 to High(AppEvents) do
1827 AppEvents[I].MessageFont.Free;
1828 for I := 0 to High(AppEventsOptions) do
1829 AppEventsOptions[I].Free;
1830 for I := 0 to High(AppUserEventsOptions) do
1831 AppUserEventsOptions[I].Free;
1832end;
1833
1834procedure TMainWindow.FormClose(Sender: TObject; var Action: TCloseAction);
1835//var
1836// I: Integer;
1837begin
1838 SunriseChatNetworkCore1.SendCommand(scDisconnect);
1839 Application.ProcessMessages;
1840 Sleep(500);
1841 SaveAppEventsToRegistry;
1842 SaveAppUserEventsToRegistry;
1843end;
1844
1845end.
1846
Note: See TracBrowser for help on using the repository browser.