Login | ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/alarming/trunk/Delphi Client/DoorAlarmClientMain.pas
(Generate patch)

Comparing trunk/Delphi Client/DoorAlarmClientMain.pas (file contents):
Revision 6 by daniel-marschall, Mon May 6 20:45:31 2019 UTC vs.
Revision 7 by daniel-marschall, Mon Jun 10 21:58:29 2019 UTC

# Line 1 | Line 1
1   unit DoorAlarmClientMain;
2  
3 < // TODO: make configurable, which actions should be executed (e.g. run programs) when a motion was detected
3 > // TODO: make configurable, which actions should be executed (e.g. run programs) when a motion was detected, with different event sounds etc
4 > // TODO: ask server to subscribe/unsubscribe to events (doorbell, motion)
5  
6   interface
7  
# Line 11 | Line 12 | uses
12    JPEG, MJPEGDecoderUnit, IniFiles, Menus;
13  
14   type
15 +  TAlarmType = (atUnknown, atMotion, atDoorbell);
16 +
17    TForm1 = class(TForm)
18      Image1: TImage;
19      TrayIcon1: TTrayIcon;
# Line 26 | Line 29 | type
29      N2: TMenuItem;
30      Stopalarm1: TMenuItem;
31      Gotocontrolpanelwebsite1: TMenuItem;
32 +    doorbellPanel: TPanel;
33 +    N3: TMenuItem;
34 +    Ignoredoorbell1: TMenuItem;
35 +    Ignoremotionalert1: TMenuItem;
36 +    unknownAlarm: TPanel;
37      procedure FormDestroy(Sender: TObject);
38      procedure FormCreate(Sender: TObject);
39      procedure TrayIcon1Click(Sender: TObject);
# Line 52 | Line 60 | type
60      procedure WMQueryEndSession(var Message: TWMQueryEndSession); message WM_QUERYENDSESSION;
61      procedure StartStream;
62      procedure StopStream;
63 <    procedure DoShowForm;
63 >    procedure DoShowForm(AlarmType: TAlarmType);
64      procedure DoPosition;
65      procedure StopMusic;
66      function ControlServerUrl: string;
# Line 269 | Line 277 | begin
277  
278    DoPosition;
279  
280 +  // Question: Should these settings also be saved for the next program session?
281    Allowmutingsoundinterface1.Checked := ini.ReadBool('Client', 'AllowMute', false);
282 +  Ignoredoorbell1.Checked := ini.ReadBool('Client', 'IgnoreDoorbell', false);
283 +  Ignoremotionalert1.Checked := ini.ReadBool('Client', 'IgnoreMotion', false);
284  
285    UpdateIPTimerTimer(UpdateIPTimer);
286    UpdateIPTimer.Interval := ini.ReadInteger('Client', 'SubscribeInterval', 30*60) * 1000;
# Line 288 | Line 299 | end;
299  
300   procedure TForm1.FormHide(Sender: TObject);
301   begin
302 <  StopStream;
302 >  if Image2.Visible then
303 >    StopStream;
304   end;
305  
306   procedure TForm1.FormShow(Sender: TObject);
307   begin
308 <  StartStream;
308 >  if Image2.Visible then
309 >    StartStream;
310   end;
311  
312   procedure TForm1.Gotocontrolpanelwebsite1Click(Sender: TObject);
# Line 309 | Line 322 | end;
322   procedure TForm1.ServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
323   var
324    AutoCloseTimerInterval: integer;
325 +  AlarmType: TAlarmType;
326   begin
327    aResponseInfo.ResponseNo  := 200;
328    aResponseInfo.ContentType := 'text/html';
# Line 343 | Line 357 | begin
357          CloseTimer.Enabled := true;
358        end;
359  
360 <      DoShowForm;
360 >      if ARequestInfo.Params.IndexOf('targets=1.3.6.1.4.1.37476.2.4.2.1002' {camera, motion}) >= 0 then
361 >        AlarmType := atMotion
362 >      else if ARequestInfo.Params.IndexOf('targets=1.3.6.1.4.1.37476.2.4.2.2001' {sound, doorbell}) >= 0 then
363 >        AlarmType := atDoorbell
364 >      else
365 >      begin
366 >        // TODO: Make plugin DLLs ?
367 >        AlarmType := atUnknown;
368 >      end;
369 >
370 >      // Attention: Ignoring these events at the client does not prevent the server
371 >      // doing other actions (e.g. ask Spotify to stop the music on connected devices)
372 >      if Ignoredoorbell1.Checked and (AlarmType = atDoorbell) then Exit;
373 >      if Ignoremotionalert1.Checked and (AlarmType = atMotion) then Exit;
374 >
375 >      if AlarmType = atUnknown then
376 >      begin
377 >        unknownAlarm.ShowHint := true;
378 >        unknownAlarm.Hint := ARequestInfo.Params.Text;
379 >      end;
380 >      DoShowForm(AlarmType);
381  
382        if ini.ReadBool('Client', 'AutoPopup', true) then
383        begin
# Line 369 | Line 403 | begin
403    Application.Restore;
404    WindowState := wsNormal;
405    FormStyle := fsNormal;
406 <  DoShowForm;
406 >  DoShowForm(atMotion);
407   end;
408  
409   procedure TForm1.UpdateIPTimerTimer(Sender: TObject);
# Line 385 | Line 419 | begin
419        lParamList.Add('ttl='+IntToStr((UpdateIPTimer.Interval div 1000) * 2 + 10));
420        lParamList.Add('targets=1.3.6.1.4.1.37476.2.4.2.0');    // Any
421        lParamList.Add('targets=1.3.6.1.4.1.37476.2.4.2.1002'); // Motion, camera
422 +      lParamList.Add('targets=1.3.6.1.4.1.37476.2.4.2.2001'); // Sound, doorbell
423  
424        idhttp := TIdHTTP.Create(nil);
425        try
# Line 427 | Line 462 | begin
462    Self.Top := Screen.Height - Self.Height - _TaskBarHeight;
463   end;
464  
465 < procedure TForm1.DoShowForm;
465 > procedure TForm1.DoShowForm(AlarmType: TAlarmType);
466   begin
467 +  Image1.Visible := AlarmType = atMotion;
468 +  Image2.Visible := AlarmType = atMotion;
469 +
470 +  // BUGBUG! TODO: This does not work. The panels are not visible for some reason! I just get a white window!
471 +  doorbellPanel.Visible := AlarmType = atDoorbell;
472 +  unknownAlarm.Visible := AlarmType = atUnknown;
473 +
474    if ini.ReadBool('Client', 'AutoReposition', true) then
475    begin
476      DoPosition;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines