-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarevimavatar.pas
More file actions
128 lines (103 loc) · 2.74 KB
/
barevimavatar.pas
File metadata and controls
128 lines (103 loc) · 2.74 KB
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
unit BarevIMAvatar;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Graphics, Barev;
type
TLogEvent = procedure(const Message: string) of object;
TAvatarChangedEvent = procedure(const BuddyJID: string) of object;
{ TAvatarManager - manages avatar operations }
TAvatarManager = class
private
FClient: TBarevClient;
FOnLog: TLogEvent;
FOnAvatarChanged: TAvatarChangedEvent;
procedure Log(const Message: string);
public
constructor Create(AClient: TBarevClient);
{ My avatar operations }
function SetMyAvatar(const FilePath: string): Boolean;
procedure ClearMyAvatar;
function GetMyAvatarHash: string;
function GetMyAvatarPath: string;
{ Buddy avatar operations }
function RequestBuddyAvatar(const BuddyJID: string): Boolean;
property Client: TBarevClient read FClient write FClient;
property OnLog: TLogEvent read FOnLog write FOnLog;
property OnAvatarChanged: TAvatarChangedEvent
read FOnAvatarChanged write FOnAvatarChanged;
end;
implementation
{ TAvatarManager }
constructor TAvatarManager.Create(AClient: TBarevClient);
begin
inherited Create;
FClient := AClient;
FOnLog := nil;
FOnAvatarChanged := nil;
end;
procedure TAvatarManager.Log(const Message: string);
begin
if Assigned(FOnLog) then
FOnLog(Message);
end;
function TAvatarManager.SetMyAvatar(const FilePath: string): Boolean;
begin
Result := False;
if not Assigned(FClient) then
begin
Log('Error: Client not connected');
Exit;
end;
if not FileExists(FilePath) then
begin
Log('Error: Avatar file not found: ' + FilePath);
Exit;
end;
Result := FClient.LoadMyAvatar(FilePath);
if Result then
begin
Log('Avatar set: ' + FilePath);
Log('Avatar hash: ' + FClient.GetMyAvatarHash);
FClient.SendPresence;
end
else
Log('Failed to set avatar');
end;
procedure TAvatarManager.ClearMyAvatar;
begin
if not Assigned(FClient) then
Exit;
FClient.ClearMyAvatar;
FClient.SendPresence;
Log('Avatar cleared');
end;
function TAvatarManager.GetMyAvatarHash: string;
begin
if Assigned(FClient) then
Result := FClient.GetMyAvatarHash
else
Result := '';
end;
function TAvatarManager.GetMyAvatarPath: string;
begin
if Assigned(FClient) and Assigned(FClient.AvatarManager) then
Result := FClient.AvatarManager.MyAvatarPath
else
Result := '';
end;
function TAvatarManager.RequestBuddyAvatar(const BuddyJID: string): Boolean;
begin
Result := False;
if not Assigned(FClient) then
begin
Log('Error: Client not connected');
Exit;
end;
Result := FClient.RequestBuddyAvatar(BuddyJID);
if Result then
Log('Avatar request sent to: ' + BuddyJID)
else
Log('Failed to request avatar from: ' + BuddyJID);
end;
end.