summaryrefslogtreecommitdiff
path: root/plugins/mRadio/i_service.inc
blob: c129046170ca8ab369933be86e69047e68d73e6a (plain)
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
{services}

function Service_GetCaps(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
begin
  case wParam of
    PFLAGNUM_1:
      result:=PF1_EXTSEARCH or PF1_MODEMSGRECV or PF1_ADDSEARCHRES or PF1_BASICSEARCH;
    PFLAGNUM_2:
      result:=PF2_ONLINE or PF2_INVISIBLE or PF2_SHORTAWAY;
    PFLAGNUM_3:
      result:=PF2_ONLINE;// or PF2_INVISIBLE or PF2_SHORTAWAY;
    PFLAGNUM_4:
      result:=PF4_NOCUSTOMAUTH or PF4_AVATARS;
    PFLAG_UNIQUEIDTEXT:
      result:=int_ptr(TranslateW('Radio station URL'));
    else
      result:=0;
  end
end;

function Service_GetName(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
begin
  if lParam<>0 then
    StrCopy(PAnsiChar(lParam),Translate(PluginName),wParam);
  result:=0;
end;

procedure GetAwayMsgProc(hContact:TMCONTACT); cdecl;
var
  buf,p:PWideChar;
begin
  if isVarsInstalled then
  begin
    buf:=ParseVarString(StatusTmpl,ActiveContact);
  end
  else
  begin
    mGetMem(buf,1024);
    StrCopyW(buf,StatusTmpl);
    if StrPosW(buf,'%radio_name%')<>nil then
    begin
      p:=DBReadUnicode(ActiveContact,strCList,optMyHandle);
      StrReplaceW(buf,'%radio_name%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_url%')<>nil then
    begin
      p:=DBReadUnicode(ActiveContact,PluginName,optStationURL);
      StrReplaceW(buf,'%radio_url%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_active%')<>nil then
    begin
      StrReplaceW(buf,'%radio_active%',ActiveURL);
    end;
    if StrPosW(buf,'%radio_genre%')<>nil then // saved as String
    begin
      p:=DBReadUnicode(ActiveContact,PluginName,optGenre);
      StrReplaceW(buf,'%radio_genre%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_bitrate%')<>nil then // saved as String
    begin
      p:=DBReadUnicode(ActiveContact,PluginName,optBitrate);
      StrReplaceW(buf,'%radio_bitrate%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_title%')<>nil then
    begin
      p:=MakeMessage;
      StrReplaceW(buf,'%radio_title%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_codec%')<>nil then
    begin
      p:=DBReadUnicode(ActiveContact,PluginName,optActiveCodec);
      StrReplaceW(buf,'%radio_codec%',p);
      mFreeMem(p);
    end;
    if StrPosW(buf,'%radio_status%')<>nil then
    begin
      StrReplaceW(buf,'%radio_status%',
         TranslateW(GetStatusText(
             CallService(MS_RADIO_COMMAND,MRC_STATUS,RD_STATUS_GET))));
    end;
  end;

  ProtoBroadcastAck(PluginName,hContact,ACKTYPE_AWAYMSG,ACKRESULT_SUCCESS,AckHandle,lParam(buf));
  mFreeMem(buf);
end;

function Service_GetAwayMsg(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
var
  ccs:PCCSDATA;
begin
  ccs:=PCCSDATA(lParam);
  if (ccs^.hContact<>0) and (PluginStatus=ID_STATUS_ONLINE) and
     (DBReadWord(ccs^.hContact,PluginName,optStatus,ID_STATUS_OFFLINE)=ID_STATUS_ONLINE) then
  begin
    {CloseHandle}(mir_forkthread(@GetAwayMsgProc,pointer(uint_ptr(ccs^.hContact))));
    result:=AckHandle;
  end
  else
    result:=0;
end;

function Service_GetStatus(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
begin
  result:=PluginStatus;
end;

function Service_LoadIcon(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
begin
  case loword(wParam) of
    PLI_PROTOCOL: result:=LoadImage(hInstance,MAKEINTRESOURCE(IDI_MAIN),IMAGE_ICON,16,16,LR_SHARED);
  else
    result:=0;
  end;
end;

function Service_SetStatus(wParam:WPARAM;lParam:LPARAM):int_ptr;cdecl;
var
  OldStatus:integer;
begin
  result:=0;
  OldStatus:=PluginStatus;
  if wParam<>ID_STATUS_OFFLINE then
    wParam:=ID_STATUS_ONLINE;

  if wParam=TWPARAM(PluginStatus) then
    exit;

  PluginStatus:=ID_STATUS_OFFLINE;

  if wParam<>ID_STATUS_OFFLINE then
  begin
//    if MyInitBASS then
    begin
      PluginStatus:=ID_STATUS_ONLINE;

      if (ActiveContact<>0) and (AuConnect<>0) then
        CallService(MS_RADIO_COMMAND,MRC_PLAY,ActiveContact);
    end;
  end
  else //offline
  begin
    CallService(MS_RADIO_COMMAND,MRC_STOP,0);
  end;
  SetStatus(0,ID_STATUS_OFFLINE);

  ProtoBroadcastAck(PluginName,0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,OldStatus,PluginStatus);
end;

// really, can be replaced by helper function. this one more effective
function CreateProtoService(serviceName:PAnsiChar;pFunc:pointer):THANDLE;
var
  temp:array [0..MAXMODULELABELLENGTH-1] of AnsiChar;
begin
  StrCopy(StrCopyE(temp,PluginName),serviceName);
  result:=CreateServiceFunction(temp,pFunc);
end;

var
  prh0,prh1,prh2,prh3,prh4,prh5,prh6,prh7,prh8,prh9:THANDLE;

procedure DestroyProtoServices;
begin
  DestroyServiceFunction(prh0);
  DestroyServiceFunction(prh1);
  DestroyServiceFunction(prh2);
  DestroyServiceFunction(prh3);
  DestroyServiceFunction(prh4);
  DestroyServiceFunction(prh5);
  DestroyServiceFunction(prh6);
  DestroyServiceFunction(prh7);
  DestroyServiceFunction(prh8);
  DestroyServiceFunction(prh9);
end;

procedure CreateProtoServices;
begin
  prh0:=CreateProtoService(PS_GETCAPS,           @Service_GetCaps);
  prh1:=CreateProtoService(PS_ADDTOLIST,         @Service_AddToList);
  prh2:=CreateProtoService(PS_CREATEADVSEARCHUI, @Service_ExtSearchUI);
  prh3:=CreateProtoService(PS_SEARCHBYADVANCED,  @Service_SearchByAdvanced);
  prh4:=CreateProtoService(PS_BASICSEARCH,       @Service_SearchBasic);
  prh5:=CreateProtoService(PS_GETNAME,           @Service_GetName);
  prh6:=CreateProtoService(PS_LOADICON,          @Service_LoadIcon);
  prh7:=CreateProtoService(PS_GETSTATUS,         @Service_GetStatus);
  prh8:=CreateProtoService(PS_SETSTATUS,         @Service_SetStatus);
  prh9:=CreateProtoService(PSS_GETAWAYMSG,       @Service_GetAwayMsg);
end;