-
Notifications
You must be signed in to change notification settings - Fork 6
/
IM.Main.pas
1402 lines (1280 loc) · 41.5 KB
/
IM.Main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit IM.Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Types, System.UITypes, System.Classes, Vcl.Graphics, Vcl.Forms,
Vcl.Dialogs, Vcl.ActnList, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtDlgs,
Winapi.MMSystem, System.ImageList, System.Actions, Vcl.Menus, Vcl.ComCtrls,
Vcl.ExtCtrls, Vcl.ImgList, Vcl.Controls, Vcl.Imaging.jpeg, Jabber.Types,
Jabber, GmXml, MD5Hash, System.Generics.Collections, HGM.Controls.VirtualTable,
HGM.Button, Vcl.WinXCtrls, Vcl.Imaging.pngimage, IM.ChatRoom, Direct2D,
IM.Classes, IM.Conference, Vcl.Grids;
type
TFormMain = class(TForm)
ImageListStatuses: TImageList;
TrayIcon: TTrayIcon;
PopupMenuSys: TPopupMenu;
MenuItemAccount: TMenuItem;
MenuItemSettings: TMenuItem;
MenuItemQuit: TMenuItem;
MenuItemAbout: TMenuItem;
MenuItemSound: TMenuItem;
MenuItemConsole: TMenuItem;
MenuItemBookmarks: TMenuItem;
PopupMenuContacts: TPopupMenu;
MenuItemContactVCard: TMenuItem;
MenuItemContactRename: TMenuItem;
MenuItemContactDelete: TMenuItem;
MenuItemContactAuth: TMenuItem;
MenuItemContactAuthAccept: TMenuItem;
MenuItemContactAuthRemove: TMenuItem;
MenuItemContactAuthRequest: TMenuItem;
MenuItemStatuses: TMenuItem;
MenuItemStOnline: TMenuItem;
MenuItemStChat: TMenuItem;
MenuItemStAway: TMenuItem;
MenuItemStXA: TMenuItem;
MenuItemStDND: TMenuItem;
MenuItemStInvisible: TMenuItem;
MenuItemStOffline: TMenuItem;
MenuItemConfList: TMenuItem;
MenuItemUserVCard: TMenuItem;
MenuItemAddContactSys: TMenuItem;
MenuItemGetVersion: TMenuItem;
MenuItemContactGroup: TMenuItem;
MenuItemContactGroupAdd: TMenuItem;
MenuItemAddToGroup: TMenuItem;
PanelMenu: TPanel;
PanelContacts: TPanel;
PanelClient: TPanel;
PanelLeft: TPanel;
TableExRoster: TTableEx;
ButtonFlatMenu: TButtonFlat;
ImageListNormal: TImageList;
ImageListOver: TImageList;
MenuItemRemoveGroup: TMenuItem;
PanelAccountInfo: TPanel;
ImageAvatar: TImage;
LabelNick: TLabel;
LabelStatusText: TLabel;
ImageShowType: TImage;
N2: TMenuItem;
MenuItemSendAttontion: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
Button1: TButtonFlat;
Button2: TButtonFlat;
PanelSearch: TPanel;
EditSearch: TEdit;
ButtonFlatSearchClear: TButtonFlat;
ActivityIndicatorWork: TActivityIndicator;
ImageList16: TImageList;
Splitter1: TSplitter;
N1: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
procedure MenuItemQuitClick(Sender: TObject);
procedure MenuItemAccountClick(Sender: TObject);
procedure MenuItemSettingsClick(Sender: TObject);
procedure OnAddToGroupClick(Sender: TObject);
procedure MenuItemAboutClick(Sender: TObject);
procedure MenuItemConsoleClick(Sender: TObject);
procedure JabberClientConnect(Sender: TObject);
procedure JabberClientConnectError(Sender: TObject);
procedure JabberClientDisconnect(Sender: TObject);
procedure JabberClientGetBookMarks(Sender: TObject; QueryNode: TGmXmlNode);
procedure JabberClientGetRoster(Sender: TObject; QueryNode: TGmXmlNode);
procedure JabberClientIQ(Sender: TObject; QueryNode: TGmXmlNode);
procedure JabberClientJabberOnline(Sender: TObject);
procedure JabberClientLoginError(Sender: TObject; Error: string);
procedure JabberClientSubscribe(Sender: TObject; From, Nick: string);
procedure JabberClientRosterSet(Sender: TObject; Item: TRosterItem);
procedure JabberClientWorkState(Sender: TObject; State: Boolean);
procedure JabberClientMessage(Sender: TObject; Item: TJabberMessage);
procedure JabberClientPresence(Sender: TObject; QueryNode: TGmXmlNode);
procedure JabberClientReceiveData(Sender: TObject; SendStr: string; Handled: Boolean);
procedure JabberClientSendData(Sender: TObject; SendStr: string);
procedure TrayIconClick(Sender: TObject);
procedure MenuItemStChatClick(Sender: TObject);
procedure MenuItemStAwayClick(Sender: TObject);
procedure MenuItemStXAClick(Sender: TObject);
procedure MenuItemStDNDClick(Sender: TObject);
procedure MenuItemStInvisibleClick(Sender: TObject);
procedure MenuItemStOfflineClick(Sender: TObject);
procedure MenuItemConfListClick(Sender: TObject);
procedure OnIviteToConfClick(Sender: TObject);
procedure OnBookmarkClick(Sender: TObject);
procedure MenuItemContactRenameClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure MenuItemUserVCardClick(Sender: TObject);
procedure MenuItemSoundClick(Sender: TObject);
procedure MenuItemContactDeleteClick(Sender: TObject);
procedure MenuItemContactAuthRequestClick(Sender: TObject);
procedure MenuItemContactAuthAcceptClick(Sender: TObject);
procedure MenuItemContactAuthRemoveClick(Sender: TObject);
procedure MenuItemContactVCardClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MenuItemAddContactSysClick(Sender: TObject);
procedure MenuItemGetVersionClick(Sender: TObject);
procedure PopupMenuContactsPopup(Sender: TObject);
procedure MenuItemContactGroupAddClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure JabberClientConnecting(Sender: TObject);
procedure TableExRosterItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
procedure TableExRosterEdit(Sender: TObject; var Data: TTableEditStruct; ACol, ARow: Integer; var Allow: Boolean);
procedure TableExRosterEditOk(Sender: TObject; Value: string; ItemValue, ACol, ARow: Integer);
procedure TableExRosterMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ButtonFlatMenuClick(Sender: TObject);
procedure PopupMenuSysPopup(Sender: TObject);
procedure OnRemoveFromGroupClick(Sender: TObject);
procedure TableExRosterDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure MenuItemSendAttontionClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ButtonFlatSearchClearClick(Sender: TObject);
procedure LabelStatusTextClick(Sender: TObject);
procedure EditSearchChange(Sender: TObject);
procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
procedure MenuItemStOnlineClick(Sender: TObject);
private
FActiveChatForm: TForm;
FRosterList: TRosterList;
FGroupList: TGroupList;
FBookmarkList: TBookmarkList;
BytesSend, BytesReceive: integer;
procedure SetImageStatus(Status: TShowType; Picture: TPicture);
function GetChatByJID(AJID: string; var Form: TFormChatRoom): Boolean;
function GetGroupChatByJID(AJID: string; var Form: TFormConference): Boolean;
procedure UpdateUserInfo(Card: TVCard);
procedure OnAttention(Item: TJabberMessage);
procedure EnterToGroupchat(ConfJID, Nick: string);
procedure Load;
public
JabberClient: TJabberClient;
FStatusMask: TPNGImage;
FFullMask: TPNGImage;
procedure PlaySounds(Sound: TSoundType); overload;
function CheckAccount: Boolean;
function CheckConnect: Boolean;
procedure Start;
procedure Open;
procedure Save;
function SetAccount: Boolean;
property RosterList: TRosterList read FRosterList;
end;
var
FormMain: TFormMain;
implementation
uses
IM.Account, IM.Config, IM.About, IM.Tool.Console, IM.Conference.Invite,
IM.Contact.Add, IM.Account.Card, IM.Tool.Captcha, HGM.Common.Utils,
System.NetEncoding, D2D1, System.DateUtils, IM.Core, HGM.Common.Settings,
System.Math;
{$R *.dfm}
procedure TFormMain.OnAttention(Item: TJabberMessage);
begin
ShowMessage('Âàñ îêëèêíóëè ' + Item.From + #13#10 + Item.Body);
end;
procedure TFormMain.OnAddToGroupClick(Sender: TObject);
var
MenuItem: TMenuItem absolute Sender;
Item: TRosterItem;
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
if FGroupList.IndexIn(MenuItem.Tag) then
begin
Item := FRosterList[TableExRoster.ItemIndex];
Item.Groups.Add(FGroupList[MenuItem.Tag].Name);
JabberClient.RenameContact(Item);
end;
end;
end;
procedure TFormMain.OnRemoveFromGroupClick(Sender: TObject);
var
MenuItem: TMenuItem absolute Sender;
Item: TRosterItem;
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
Item := FRosterList[TableExRoster.ItemIndex];
if MenuItem.Tag < Item.Groups.Count then
begin
Item.Groups.Delete(MenuItem.Tag);
JabberClient.RenameContact(Item);
end;
end;
end;
procedure TFormMain.Open;
begin
ShowWindow(Application.Handle, SW_SHOW);
FormMain.Show;
FormMain.BringToFront;
end;
procedure TFormMain.OnBookmarkClick(Sender: TObject);
var
MenuItem: TMenuItem absolute Sender;
begin
ShowMessage(FBookmarkList[MenuItem.Tag].Name + ' ' + FBookmarkList[MenuItem.Tag].JID);
end;
procedure TFormMain.OnIviteToConfClick(Sender: TObject);
var
MenuItem: TMenuItem absolute Sender;
begin
if FBookmarkList.IndexIn(MenuItem.Tag) then
begin
EnterToGroupchat(FBookmarkList[MenuItem.Tag].JID, FBookmarkList[MenuItem.Tag].nick);
end;
end;
procedure TFormMain.PlaySounds(Sound: TSoundType);
var
SoundFile: string;
begin
if not MenuItemSound.Checked then
Exit;
SoundFile := ExtractFilePath(Application.ExeName) + 'sounds\' + Core.Settings.GetStr('System', 'Sounds', 'icq');
case Sound of
sndError:
SoundFile := SoundFile + '\warning.wav';
sndOnline:
SoundFile := SoundFile + '\online.wav';
sndOffline:
begin
//À çäåñü âîñïðîèçâåä¸ì íå àñèíõðîííî
SoundFile := SoundFile + '\disconnect.wav';
if FileExists(SoundFile) then
PlaySound(PChar(SoundFile), 0, SND_FILENAME);
Exit;
end;
sndSubscribe:
SoundFile := SoundFile + '\subscr.wav';
sndWelcome:
SoundFile := SoundFile + '\welcome.wav';
sndMessage:
SoundFile := SoundFile + '\msg.wav';
sndGroup:
SoundFile := SoundFile + '\group.wav';
end;
if FileExists(SoundFile) then
PlaySound(PChar(SoundFile), 0, SND_FILENAME or SND_ASYNC);
end;
function TFormMain.GetChatByJID(AJID: string; var Form: TFormChatRoom): Boolean;
var
i: Integer;
begin
Result := False;
AJID := AnsiLowerCase(AJID);
for i := 0 to ComponentCount - 1 do
begin
if (Components[i] is TFormChatRoom) then
if AnsiLowerCase((Components[i] as TFormChatRoom).JID) = AJID then
begin
Form := Components[i] as TFormChatRoom;
Exit(True);
end;
end;
end;
function TFormMain.GetGroupChatByJID(AJID: string; var Form: TFormConference): Boolean;
var
i: Integer;
begin
Result := False;
AJID := AnsiLowerCase(AJID);
for i := 0 to ComponentCount - 1 do
begin
if (Components[i] is TFormConference) then
if AnsiLowerCase((Components[i] as TFormConference).JID) = AJID then
begin
Form := Components[i] as TFormConference;
Exit(True);
end;
end;
end;
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
Hide;
end;
procedure TFormMain.FormCreate(Sender: TObject);
var
i: integer;
begin
FRosterList := TRosterList.Create(TableExRoster);
FGroupList := TGroupList.Create;
FBookmarkList := TBookmarkList.Create;
FStatusMask := TPngImage.Create;
FStatusMask.LoadFromResourceName(HInstance, 'statusmask');
FFullMask := TPngImage.Create;
FFullMask.LoadFromResourceName(HInstance, 'fullmask');
ImageListOver.AddImages(ImageListNormal);
for i := 0 to ImageListOver.Count - 1 do
ColorImages(ImageListOver, i, clWhite);
ColorImages(ImageList16, 0, $00C18852);
ColorImages(ImageList16, 1, $00C18852);
ColorImages(ImageList16, 2, $00C18852);
LabelNick.Caption := '';
LabelStatusText.Caption := 'Çàãðóçêà...';
JabberClient := TJabberClient.Create(nil);
JabberClient.Name := 'JabberClient';
JabberClient.OnConnect := JabberClientConnect;
JabberClient.OnConnecting := JabberClientConnecting;
JabberClient.OnDisconnect := JabberClientDisconnect;
JabberClient.OnConnectError := JabberClientConnectError;
JabberClient.OnReceiveData := JabberClientReceiveData;
JabberClient.OnSendData := JabberClientSendData;
JabberClient.OnJabberOnline := JabberClientJabberOnline;
JabberClient.OnGetRoster := JabberClientGetRoster;
JabberClient.OnGetBookMarks := JabberClientGetBookMarks;
JabberClient.OnMessage := JabberClientMessage;
JabberClient.OnPresence := JabberClientPresence;
JabberClient.OnIQ := JabberClientIQ;
JabberClient.OnLoginError := JabberClientLoginError;
JabberClient.OnSubscribe := JabberClientSubscribe;
JabberClient.OnRosterSet := JabberClientRosterSet;
JabberClient.OnWorkState := JabberClientWorkState;
JabberClient.JabberPort := 5222;
JabberClient.UserServer := 'jabber.ru';
JabberClient.Resource := 'jabbrel';
Load;
//Çâóê çàïóñêà
PlaySounds(sndWelcome);
end;
procedure TFormMain.FormDestroy(Sender: TObject);
begin
Save;
FStatusMask.Free;
FFullMask.Free;
FBookmarkList.Free;
FGroupList.Free;
FRosterList.Free;
JabberClient.Free;
end;
procedure TFormMain.JabberClientConnect(Sender: TObject);
begin
FormConsole.AddLog('JabberClientConnect: Connected to server!' + #10#13, $00FEB043);
TFormChatRoom.SwowPopupWnd('Ïîäêëþ÷åíî!');
end;
procedure TFormMain.JabberClientConnecting(Sender: TObject);
begin
FormConsole.AddLog('JabberClientConnecting: Connecting' + #10#13, $00FEB043);
ActivityIndicatorWork.Animate := True;
end;
procedure TFormMain.JabberClientConnectError(Sender: TObject);
begin
ActivityIndicatorWork.Animate := False;
PlaySounds(sndError);
FormConsole.AddLog('JabberClientConnectError: Connect error!' + #10#13, $00FEB043);
TFormChatRoom.SwowPopupWnd('Îøèáêà ïîäêëþ÷åíèÿ!');
end;
procedure TFormMain.JabberClientDisconnect(Sender: TObject);
var
i: Integer;
begin
FormConsole.AddLog('JabberClientDisconnect: Disconnected!' + #10#13, $00FEB043);
ActivityIndicatorWork.Animate := False;
BytesSend := 0;
BytesReceive := 0;
PlaySounds(sndOffline);
FRosterList.Clear;
MenuItemAddContactSys.Enabled := False;
MenuItemUserVCard.Enabled := False;
for i := 0 to ComponentCount - 1 do
if Components[i] is TFormConference then
begin
(Components[i] as TFormConference).OnDisconnect;
end;
TFormChatRoom.SwowPopupWnd('Îòêëþ÷åí(à)!');
end;
procedure TFormMain.JabberClientGetBookMarks(Sender: TObject; QueryNode: TGmXmlNode);
var
ItemStorage, ItemBookmarker: TGmXmlNode;
i: integer;
Item: TBookmarkItem;
begin
ItemStorage := QueryNode.Children.NodeByName['storage'];
if Assigned(ItemStorage) then
begin
FBookmarkList.BeginUpdate;
FBookmarkList.Clear;
for i := 0 to ItemStorage.Children.Count - 1 do
begin
ItemBookmarker := ItemStorage.Children.Node[i];
if ItemBookmarker.Name = 'conference' then
begin
Item.BookmarkType := btConference;
Item.Name := ItemBookmarker.Params.Values['name'];
Item.JID := ItemBookmarker.Params.Values['jid'];
Item.Autojoin := ItemBookmarker.Params.Values['autojoin'] = 'true';
Item.Password := ItemBookmarker.Params.Values['password'];
Item.Nick := ItemBookmarker.Children.NodeByName['nick'].AsString;
FBookmarkList.Add(Item);
Continue;
end;
if ItemBookmarker.Name = 'url' then
begin
Item.BookmarkType := btUrl;
Item.Name := ItemBookmarker.Params.Values['name'];
Item.URL := ItemBookmarker.Params.Values['url'];
FBookmarkList.Add(Item);
Continue;
end;
end;
FBookmarkList.EndUpdate;
end;
FormConsole.AddLog('JabberClientGetBookMarks: BookMarks loaded!' + #10#13 + QueryNode.AsString, $005656FE);
TFormChatRoom.SwowPopupWnd('Çàêëàäêè çàãðóæåíû');
end;
procedure TFormMain.JabberClientGetRoster(Sender: TObject; QueryNode: TGmXmlNode);
var
RosterItem: TGmXmlNode;
Item: TRosterItem;
Group: TGroupItem;
i, j: integer;
begin
FRosterList.BeginUpdate;
FRosterList.Clear;
FGroupList.BeginUpdate;
FGroupList.Clear;
for i := 0 to QueryNode.Children.Count - 1 do
begin
RosterItem := QueryNode.Children.Node[i];
if RosterItem.Name = 'item' then
begin
//Ñåêöèÿ ãðóïïà
Item := TRosterItem.Create;
Item.JID := RosterItem.Params.Values['jid'];
Item.Name := RosterItem.Params.Values['name'];
if Item.Name.IsEmpty then
Item.Name := NickFromJID(Item.JID);
Item.Status := stOffline;
SetDefaultAvatar(Item, FStatusMask);
for j := 0 to RosterItem.Children.Count - 1 do
begin
Group.Name := RosterItem.Children.Node[j].AsString;
Item.Groups.Add(Group.Name);
if Group.Name <> '' then
FGroupList.Add(Group);
end;
FRosterList.Add(Item);
end;
end;
FRosterList.EndUpdate;
FGroupList.EndUpdate;
FormConsole.AddLog('JabberClientGetRoster: Roster loaded!' + #10#13, $005656FE);
end;
procedure TFormMain.JabberClientIQ(Sender: TObject; QueryNode: TGmXmlNode);
begin
FormConsole.AddLog('JabberClientIQ ', $005656FE);
end;
procedure TFormMain.JabberClientJabberOnline(Sender: TObject);
var
i: Integer;
begin
ActivityIndicatorWork.Animate := False;
FormConsole.AddLog('JabberClientJabberOnline: Now Online!' + #10#13, $00FEB043);
MenuItemUserVCard.Enabled := True;
MenuItemAddContactSys.Enabled := True;
UpdateUserInfo(JabberClient.VCard);
SetImageStatus(JabberClient.UserStatus, ImageShowType.Picture);
LabelNick.Caption := JabberClient.UserNick;
LabelStatusText.Caption := JabberClient.UserStatusText;
PlaySounds(sndOnline);
for i := 0 to ComponentCount - 1 do
if Components[i] is TFormConference then
begin
(Components[i] as TFormConference).OnConnect;
end;
TFormChatRoom.SwowPopupWnd('Îíëàéí!');
end;
procedure TFormMain.JabberClientLoginError(Sender: TObject; Error: string);
begin
ActivityIndicatorWork.Animate := False;
PlaySounds(sndError);
FormConsole.AddLog('JabberClientLoginError: Login error!' + #10#13, $00FEB043);
TFormChatRoom.SwowPopupWnd('Îøèáêà àâòîðèçàöèè!! Ïðîâåðüòå âàø ëîãèí/ïàðîëü...');
end;
procedure TFormMain.JabberClientMessage(Sender: TObject; Item: TJabberMessage);
var
JID: string;
ChatRoom: TFormChatRoom;
GroupChatRoom: TFormConference;
Roster: TRosterItem;
begin
FormConsole.AddLog('JabberClientMessage: ' + Item.From + ' ' + Item.Body, $005656FE);
JID := LoginFromJID(Item.From);
if Item.MessageType = 'headline' then
begin
OnAttention(Item);
Exit;
end;
//×àò ñîîáùåíèå
if Item.MessageType = 'chat' then
begin
if Assigned(FRosterList.Find(JID)) then
begin
Roster := FRosterList.Find(JID);
with Roster do
begin
if not Item.Body.IsEmpty then
begin
LastMessage.ID := Item.ID;
LastMessage.Body := Item.Body;
end;
Item.Nick := Name;
end;
end
else
begin
Roster := TRosterItem.Create;
Roster.JID := LoginFromJID(Item.From);
Roster.Name := JID;
SetDefaultAvatar(Roster, FStatusMask);
FRosterList.Add(Roster);
Item.Nick := JID;
end;
if not GetChatByJID(JID, ChatRoom) then
begin
ChatRoom := TFormChatRoom.Create(Self);
ChatRoom.Parent := PanelClient;
ChatRoom.SetItem(Roster);
end;
if not Item.Body.IsEmpty then
begin
ChatRoom.NewMessage(Item);
if (not Active) or (not ChatRoom.Visible) then
begin
TFormChatRoom.SwowPopupWnd(Item.Nick + ':' + Item.Body);
if Assigned(Roster) then
Roster.LastMessage.Unread := True;
end
else
begin
JabberClient.SendReadMessage(JID, Item.ID);
if Assigned(Roster) then
Roster.LastMessage.Unread := False;
end;
end
else
ChatRoom.MessageMarkers(Item);
FRosterList.UpdateTable;
end;
//MSG from conference
if (Item.MessageType = 'groupchat') then
begin
if GetGroupChatByJID(LoginFromJID(Item.From), GroupChatRoom) then
begin
Item.Nick := NickFromConfJID(Item.From);
GroupChatRoom.NewMessage(Item);
Exit;
end;
end;
//MSG error
if (Item.MessageType = 'error') then
begin
if GetGroupChatByJID(LoginFromJID(Item.From), GroupChatRoom) then
begin
GroupChatRoom.NewMessage(Item);
Exit;
end
else
ShowMessage(Item.From + #13#13 + Item.Error.Text);
end;
//Çàïðîñ ïðîâåðêè êàïò÷è
if (Item.MessageType = '') or (Item.MessageType = 'normal') then
begin
//CAPTCHA
if Item.XMLNS_XOOB.URL <> '' then
begin
TFormCaptcha.Execute(Item.XMLNS_XOOB.URL);
Exit;
end;
end;
end;
procedure TFormMain.UpdateUserInfo(Card: TVCard);
var
Pic: TPicture;
PNG: TPngImage;
begin
with Card do
begin
if Photo.PhotoType <> '' then
begin
Pic := TPicture.Create;
if SetImageFromBinVal(Photo.BinVal, Photo.PhotoType, Pic) then
begin
PNG := CreateAvatar(Pic.Graphic, FStatusMask);
ImageAvatar.Picture.Assign(PNG);
PNG.Free;
end;
Pic.Free;
end
else
begin
PNG := CreateDefaultAvatar(JabberClient.JID, JabberClient.UserNick, FStatusMask, CreateColorFromJID(JabberClient.JID));
ImageAvatar.Picture.Assign(PNG);
PNG.Free;
end;
end;
end;
procedure TFormMain.JabberClientPresence(Sender: TObject; QueryNode: TGmXmlNode);
var
FormChat: TFormChatRoom;
FormGroupChat: TFormConference;
Item: TRosterItem;
Pic: TPicture;
PNG: TPngImage;
begin
FormConsole.AddLog('JabberClientPresence ' + #10#13, $006A6AB4);
{
XMLItem := QueryNode;
fromJID := XMLItem.Params.Values['from'];
fromTYPE := LowerCase(XMLItem.Params.Values['type']);
xmlItem2 := XMLItem.Children.NodeByName['error'];
if Assigned(xmlItem2) then
ErrorCode := xmlItem2.Params.Values['code'];
if fromTYPE = 'error' then
begin
if ErrorCode = '409' then
Application.MessageBox('Èñïîëüçîâàíûé âàìè íèê óæå èñïîëüçóåòñÿ êåì-òî äðóãèì.', 'Îøèáêà');
if ErrorCode = '403' then
Application.MessageBox(pchar('Âàì çàïðåòèëè âõîäèòü â êîìíàòó ' + fromJID2), 'Îøèáêà');
if ErrorCode = '404' then
begin
FormConsole.AddLog('Ñåðâåð êîíòàêòà - ' + fromJID2 + ' íåäîñòóïåí, óäàëèòå åãî!' + #10#13, $00FEB043);
end;
if ErrorCode = '407' then
begin
confONLY := LoginFromJID(fromJID);
Application.MessageBox(pchar('Äëÿ âõîäà â êîìíàòó ' + confONLY + ' íóæíî èìåòü ÷ëåíñòâî.'), 'Îøèáêà');
FormConference.ConfClose2(confONLY);
end;
Exit;
end; }
if GetGroupChatByJID(LoginFromJID(QueryNode.Params.Values['from']), FormGroupChat) then
begin
FormGroupChat.OnPresence(Sender, QueryNode);
end
else
begin
//Ñâîé ñòàòóñ
if QueryNode.Params.Values['from'] = JabberClient.JID + '/' + JabberClient.Resource then
begin
if QueryNode.Children.NodeExists('show') then
SetImageStatus(StrToShowType(QueryNode.Children.NodeByName['show'].AsString), ImageShowType.Picture)
else
SetImageStatus(stNormal, ImageShowType.Picture);
if QueryNode.Children.NodeExists('status') then
LabelStatusText.Caption := QueryNode.Children.NodeByName['status'].AsString
else
LabelStatusText.Caption := '';
if QueryNode.Children.NodeExists('x') then
if QueryNode.Children.NodeByName['x'].Children.NodeExists('photo') then
if JabberClient.PhotoHash <> QueryNode.Children.NodeByName['x'].Children.NodeByName['photo'].AsString then
begin
JabberClient.PhotoHash := QueryNode.Children.NodeByName['x'].Children.NodeByName['photo'].AsString;
UpdateUserInfo(JabberClient.GetVCard(JabberClient.JID));
end;
end
else //×åé-òî ñòàòóñ
begin
Item := FRosterList.Find(LoginFromJID(QueryNode.Params.Values['from']));
if Assigned(Item) then
begin
if QueryNode.Params.Values['type'] = 'unavailable' then
Item.Status := stOffline
else
begin
if QueryNode.Children.NodeExists('show') then
Item.Status := StrToShowType(QueryNode.Children.NodeByName['show'].AsString)
else
Item.Status := stNormal;
if QueryNode.Children.NodeExists('status') then
Item.StatusText := QueryNode.Children.NodeByName['status'].AsString;
if QueryNode.Children.NodeExists('x') then
if QueryNode.Children.NodeByName['x'].Children.NodeExists('photo') then
if Item.Photo <> QueryNode.Children.NodeByName['x'].Children.NodeByName['photo'].AsString then
begin
Item.Photo := QueryNode.Children.NodeByName['x'].Children.NodeByName['photo'].AsString;
with JabberClient.GetVCard(Item.JID) do
begin
if Photo.PhotoType <> '' then
begin
Pic := TPicture.Create;
if SetImageFromBinVal(Photo.BinVal, Photo.PhotoType, Pic) then
begin
PNG := CreateAvatar(Pic.Graphic, FStatusMask);
Item.Avatar.Assign(PNG);
PNG.Free;
end;
Pic.Free;
end
else
Item.Photo := '';
end;
end;
//JabberClient.SendPresence(QueryNode.Params.Values['from']);
end;
if GetChatByJID(Item.JID, FormChat) then
begin
FormChat.SetItem(Item);
end;
FRosterList.UpdateTable;
end;
end;
end;
FormConsole.AddLog('JabberClientPresence END' + #10#13, $006A6AB4);
end;
procedure TFormMain.JabberClientReceiveData(Sender: TObject; SendStr: string; Handled: Boolean);
begin
BytesReceive := BytesReceive + Length(SendStr);
FormConsole.AddLog('JabberClientReceiveData: ' + SendStr + #10#13, $005656FE);
end;
procedure TFormMain.JabberClientRosterSet(Sender: TObject; Item: TRosterItem);
begin
if Item.Subscription = 'remove' then
begin
FRosterList.Delete(Item.JID);
Exit;
end;
if not Assigned(Item.Avatar) then
SetDefaultAvatar(Item, FStatusMask);
FRosterList.Update(Item);
FGroupList.Add(Item.Groups);
FormConsole.AddLog('JabberClientRosterSet: ' + Item.JID + #10#13, $005656FE);
end;
procedure TFormMain.JabberClientSendData(Sender: TObject; SendStr: string);
begin
BytesSend := BytesSend + Length(SendStr);
FormConsole.AddLog('JabberClientSendData: ' + SendStr + #10#13, $0085C285);
end;
procedure TFormMain.JabberClientSubscribe(Sender: TObject; From, Nick: string);
var
JIDExists: Boolean;
i: Integer;
begin
PlaySounds(sndSubscribe);
if MessageDlg('Ïîäòâåðäèòü àâòîðèçàöèþ ' + From + '? ', mtConfirmation, mbYesNo, 1) = mrYes then
begin
JIDExists := False;
for i := 0 to FRosterList.Count - 1 do
begin
if LowerCase(LoginFromJID(FRosterList[i].JID)) = LowerCase(From) then
begin
JIDExists := True;
Break;
end;
end;
if JIDExists then
begin
JabberClient.SendSubscribeAccept(From);
TFormChatRoom.SwowPopupWnd('Àâòîðèçàöèÿ îäîáðåíà!');
end
else
begin
if InputQuery('Äîáàâëåíèå íîâîãî êîíòàêòà', 'Ââåäèòå íèê: ', Nick) then
begin
if Nick = '' then
Nick := LoginFromJID(From);
JabberClient.AddContact(From, Nick);
Sleep(1000);
JabberClient.SendSubscribeAccept(From);
TFormChatRoom.SwowPopupWnd('Àâòîðèçàöèÿ îäîáðåíà!');
end;
end;
end
else
begin
JabberClient.SendSubscribeCancel(From);
TFormChatRoom.SwowPopupWnd('Àâòîðèçàöèÿ îòìåíåíà!');
end;
end;
procedure TFormMain.JabberClientWorkState(Sender: TObject; State: Boolean);
begin
if ActivityIndicatorWork.Animate <> State then
ActivityIndicatorWork.Animate := State;
Application.ProcessMessages;
end;
procedure TFormMain.MenuItemAccountClick(Sender: TObject);
begin
if SetAccount then
begin
if JabberClient.Online then
JabberClient.Disconnect;
JabberClient.Connect;
end;
end;
procedure TFormMain.MenuItemContactRenameClick(Sender: TObject);
begin
TableExRoster.Edit(TableExRoster.ItemIndex, 1);
end;
procedure TFormMain.MenuItemContactDeleteClick(Sender: TObject);
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
JabberClient.DeleteContact(FRosterList[TableExRoster.ItemIndex].JID);
FRosterList.Delete(TableExRoster.ItemIndex);
end;
end;
procedure TFormMain.MenuItemContactAuthAcceptClick(Sender: TObject);
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
JabberClient.SendSubscribeAccept(FRosterList[TableExRoster.ItemIndex].JID);
end;
end;
procedure TFormMain.MenuItemContactAuthRemoveClick(Sender: TObject);
var
JID: string;
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
JID := FRosterList[TableExRoster.ItemIndex].JID;
JabberClient.SendSubscribeCancel(JID);
JabberClient.SendUnsubscribe(JID);
JabberClient.SendAuthRemove(JID);
end;
end;
procedure TFormMain.MenuItemContactAuthRequestClick(Sender: TObject);
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
JabberClient.SendAuthRequest(FRosterList[TableExRoster.ItemIndex].JID);
end;
end;
procedure TFormMain.MenuItemSendAttontionClick(Sender: TObject);
begin
if FRosterList.IndexIn(TableExRoster.ItemIndex) then
begin
JabberClient.SendAttention(FRosterList[TableExRoster.ItemIndex].JID);
end;
end;
procedure TFormMain.MenuItemSettingsClick(Sender: TObject);
begin
TFormConfig.Execute;
end;
procedure TFormMain.MenuItemStOnlineClick(Sender: TObject);
begin
JabberClient.UserStatus := stNormal;
CheckConnect;
end;
procedure TFormMain.MenuItemStChatClick(Sender: TObject);
begin
JabberClient.UserStatus := stChat;
CheckConnect;
end;
procedure TFormMain.MenuItemStAwayClick(Sender: TObject);
begin
JabberClient.UserStatus := stAway;
CheckConnect;
end;
procedure TFormMain.MenuItemStXAClick(Sender: TObject);
begin
JabberClient.UserStatus := stXa;
CheckConnect;
end;
procedure TFormMain.MenuItemStDNDClick(Sender: TObject);
begin
JabberClient.UserStatus := stDnd;
CheckConnect;
end;
procedure TFormMain.MenuItemStInvisibleClick(Sender: TObject);
begin
JabberClient.UserStatus := stInvisible;
CheckConnect;
end;
procedure TFormMain.MenuItemStOfflineClick(Sender: TObject);
begin
JabberClient.Disconnect;
end;
procedure TFormMain.MenuItemConfListClick(Sender: TObject);
var
AConf, ANick: string;
begin
if JabberClient.Online then
begin
if TFormConfInvite.Execute(JabberClient, AConf, ANick) then
begin
EnterToGroupchat(AConf, ANick);
end;
end;
end;
procedure TFormMain.MenuItemQuitClick(Sender: TObject);
begin
JabberClient.Disconnect;
Application.Terminate;
end;
procedure TFormMain.MenuItemAddContactSysClick(Sender: TObject);
var
AJID, ANick: string;
Item: TRosterItem;
begin
if TFormContactAdd.Execute(AJID, ANick, FGroupList) then
begin
Item := TRosterItem.Create;
Item.JID := AJID;
Item.Name := ANick;