source: branches/3 fndSockets/UMainWindow.pas

Last change on this file was 13, checked in by george, 17 years ago

Opraveno: Načítání seznamu síťových adaptérů na Linuxu.
Přidáno: Úpravy pro potřeby ladění problému s nepřijímáním UDP paketů.

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