summaryrefslogtreecommitdiff
path: root/plugins/mRadio/i_myservice.inc
blob: d55ab469e9b117dc2e1a36fbf48a96feafe6c3c6 (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
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
{My services}

function Service_RadioPlayStop(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
  p:PAnsiChar;
  tmpw, res:PWideChar;
  lnew:bool;
  hContact:TMCONTACT;
  i:integer;
begin
  result:=0;
  if lParam=0 then
  begin
    if wParam=0 then
      wParam:=GetCListSelContact;
    p:=Proto_GetBaseAccountName(wParam);
    if (p=nil) or (StrCmp(p,PluginName)<>0) then
      exit;
    hContact:=wParam;
  end
  // wParam = station name
  else
  begin
    AnsiToWide(pAnsiChar(wParam), tmpw);
    hContact:=db_find_first(PluginName);
    while hContact<>0 do
    begin
      res:=Contact_GetInfo(CNF_DISPLAY,hContact,PluginName);
      if res <> nil then
      begin
        i:=StrCmpW(tmpw, res);
        mir_free(res);
        if i=0 then
          break;
      end;
      hContact:=db_find_next(hContact,PluginName);
    end;
    mFreeMem(tmpw);
  end;

  if hContact<>0 then
  begin
    result:=1;
    if PluginStatus=ID_STATUS_OFFLINE then
      Service_SetStatus(ID_STATUS_ONLINE,0);

    case CallService(MS_RADIO_COMMAND,MRC_STATUS,RD_STATUS_GET) of
      RD_STATUS_CONNECT: begin //break while connect
        CallService(MS_RADIO_COMMAND,MRC_STATUS,RD_STATUS_ABORT);
        exit;
      end;
      RD_STATUS_ABORT: exit;
    end;

    lnew:=ActiveContact<>hContact;

    if ActiveContact<>0 then
      CallService(MS_RADIO_COMMAND,MRC_STOP,1);

    if lnew then
      CallService(MS_RADIO_COMMAND,MRC_PLAY,hContact);
  end;
end;

function Service_RadioSettings(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
  ood:TOPENOPTIONSDIALOG;
begin
  result:=0;
  ood.cbSize:=SizeOf(ood);
  ood.pszGroup:='Network';
  ood.pszPage :=PluginName;
  ood.pszTab  :=Translate('Advanced');
  CallService(MS_OPT_OPENOPTIONS,0,tlparam(@ood));
end;

function Service_RadioRecord(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  if lParam<>0 then lParam:=TLPARAM(-1) else lParam:=0;

  result:=CallService(MS_RADIO_COMMAND,MRC_RECORD,lParam);
end;

function Service_RadioGetVolume(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  result:=gVolume;
end;

function Service_RadioSetVolume(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  result:=Service_RadioGetVolume(0,0);
  SetSndVol(wParam);

  DBWriteByte(0,PluginName,optVolume,ABS(wParam));
  if lParam<>2 then // not from Frame
    if hVolFrmCtrl<>0 then
      SendMessage(hVolFrmCtrl,TBM_SETPOS,1,ABS(wParam));

  if lParam<>1 then // not from Settings
    if hVolCtrl<>0 then
      SendMessage(hVolCtrl,TBM_SETPOS,1,ABS(wParam));

end;

function Service_RadioMute(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  if gVolume=0 then
    gVolume:=-1
  else
    gVolume:=-gVolume;
  Result:=Service_RadioSetVolume(gVolume,0);
  if hVolFrmMute<>0 then
  begin
    InvalidateRect(hVolFrmMute,nil,true);
    RedrawWindow(hVolFrmMute,nil,0,RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_ERASE);
  end;
  if hVolFrmCtrl<>0 then
    EnableWindow(hVolFrmCtrl,gVolume>=0);
end;

function Service_EqOnOff(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  result:=ord(isEQ_OFF=BST_UNCHECKED);
  case wParam of
    0: begin
      if isEQ_OFF=BST_UNCHECKED then
        EQ_OFF
      else
        EQ_ON;
    end;
    1: EQ_ON;
  else
    EQ_OFF;
  end;
  if eq[0].wnd<>0 then // if options opened (can use hVolCtrl)
  begin
    CheckDlgButton(GetParent(eq[0].wnd),IDC_EQOFF,isEQ_OFF);
  end;
end;

//----- Import-export -----

function ImportOneStation(group:PAnsiChar;section:pointer):TMCONTACT;
var
  p:pWideChar;
  pc:pAnsiChar;
begin
  result:=0;
  pc:=GetParamSectionStr(section,'URL');
  if pc<>nil then
  begin
    result:=CallService(MS_DB_CONTACT_ADD,0,0);
    if result<>0 then
    begin
      Proto_AddToContact(result,PluginName);
      DBWriteString(result,PluginName,optStationURL,pc);
      DBWriteString(result,PluginName,optFirstName ,pc);

      pc:=GetParamSectionStr(section,optBitrate,'0');
      DBWriteString(result,PluginName,optBitrate,pc);
      DBWriteWord  (result,PluginName,optAge    ,StrToInt(pc));

      pc:=GetParamSectionStr(section,'Name',GetSectionName(section));
      DBWriteString(result,strCList  ,optMyHandle,pc);
      DBWriteString(result,PluginName,optNick    ,pc);

      pc:=GetParamSectionStr(section,optGenre,'unknown');
      DBWriteString(result,PluginName,optGenre   ,pc);
      DBWriteString(result,PluginName,optLastName,pc);

      SetStatus(result,ID_STATUS_OFFLINE);

      if group=nil then
        group:=GetParamSectionStr(section,optGroup);

      AnsiToWide(group,p,MirandaCP);
      CreateGroupW(p,result);
      mFreeMem(p);
      CallService(MS_IGNORE_IGNORE,result,IGNOREEVENT_ALL);
    end;
  end;
end;

function ImportAll(wParam:WPARAM;lParam:LPARAM):int; cdecl;
var
  dst:array [0..MAX_PATH-1] of AnsiChar;
  pc:pAnsiChar;
  lstorage,section,list:pointer;
begin
  result:=0;
  if lParam<>0 then
    StrCopy(dst,PAnsiChar(lParam));
  if (lParam<>0) or ShowDlg(dst,'radio.ini',nil,true) then
  begin
    lstorage:=OpenStorage(dst);
    if lstorage<>nil then
    begin
      list:=GetSectionList(lstorage);

      pc:=list;
      while pc^<>#0 do
      begin
        section:=SearchSection(lstorage,pc);
        if ImportOneStation(pAnsiChar(wParam),section)<>0 then inc(result);
        while pc^<>#0 do inc(pc);
        inc(pc);
      end;

      FreeSectionList(list);

      CloseStorage(lstorage);
    end;
  end;
end;

procedure ExportRadioContact(num:integer;fname:PAnsiChar;hContact:TMCONTACT);
var
  pc:pAnsiChar;
  section:array [0..15] of AnsiChar;
begin
  IntToStr(section,num);
  pc:=DBReadString(hContact,strCList,optMyHandle);
  WritePrivateProfileStringA(section,'Name',pc,fname);
  mFreeMem(pc);

  pc:=DBReadString(hContact,PluginName,optStationURL);
  WritePrivateProfileStringA(section,'URL',pc,fname);
  mFreeMem(pc);

  pc:=DBReadString(hContact,PluginName,optGenre);
  if pc<>nil then
  begin
    WritePrivateProfileStringA(section,optGenre,pc,fname);
    mFreeMem(pc);
  end;

  pc:=DBReadString(hContact,PluginName,optBitrate);
  if pc<>nil then
  begin
    WritePrivateProfileStringA(section,optBitrate,pc,fname);
    mFreeMem(pc);
  end;

  pc:=DBReadString(hContact,strCList,optGroup);
  if pc<>nil then
  begin
    WritePrivateProfileStringA(section,optGroup,pc,fname);
    mFreeMem(pc);
  end;
end;

function ExportAll(wParam:WPARAM;lParam:LPARAM):int; cdecl;
var
  dst:array [0..MAX_PATH-1] of AnsiChar;
  hContact:TMCONTACT;
begin
  result:=0;
  if lParam<>0 then
    StrCopy(dst,PAnsiChar(lParam));
  if (lParam<>0) or ShowDlg(dst,'radio.ini',nil,false) then
  begin
    if (wParam<>0) and (CallService(MS_DB_CONTACT_IS,wParam,0)<>0) then
    begin
      result:=1;
      ExportRadioContact(result,dst,wParam)
    end
    else
    begin
      hContact:=db_find_first(PluginName);
      while hContact<>0 do
      begin
        inc(result);
        ExportRadioContact(result,dst,hContact);
        hContact:=db_find_next(hContact,PluginName);
      end;
    end;
  end;
end;

function QuickOpen(wParam:WPARAM;lParam:LPARAM):int; cdecl;
var
  filter:pWideChar;
  buf:array [0..MAX_PATH-1] of WideChar;
begin
  filter:=ConstructFilter;
  if ShowDlgW(@buf,nil,filter) then
  begin
    result:=CallService(MS_DB_CONTACT_ADD,0,0);
    if result<>0 then
    begin
      Proto_AddToContact(result,PluginName);
      //
//      DBWriteByte(result,strCList,'Hidden'   ,0);
      DBWriteByte(result,strCList,'NotOnList',1);
      // URL
      DBWriteUnicode(result,PluginName,optStationURL,@buf);
      DBWriteUnicode(result,PluginName,optFirstName ,@buf);
      // Name
      DBWriteUnicode(result,strCList  ,optMyHandle,@buf);
      DBWriteUnicode(result,PluginName,optNick    ,@buf);

      SetStatus(result,ID_STATUS_OFFLINE);

      CallService(MS_IGNORE_IGNORE,result,IGNOREEVENT_USERONLINE{IGNOREEVENT_ALL});

      CallService(MS_RADIO_COMMAND,MRC_PLAY,result);
    end;
  end
  else
  begin
    result:=0;
  end;
  mFreeMem(filter);
end;