Check-in [5b7709bef6]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Default start and stop time can now be specified in the .ini file. Renamed the sample .ini file. The form is now always invalidated after a refresh; even when an exception occurs.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5b7709bef6d3fec141f11c16bc1c46f3a1fe3302
User & Date: tinus 2014-12-03 08:22:41
Context
2014-12-04
09:04
Added feature to manually adjust work and lunch times. check-in: c2c21599e3 user: tinus tags: trunk
2014-12-03
08:22
Default start and stop time can now be specified in the .ini file. Renamed the sample .ini file. The form is now always invalidated after a refresh; even when an exception occurs. check-in: 5b7709bef6 user: tinus tags: trunk
2014-12-02
12:27
Specify default times (in case no calendar info could be loaded). Handle calendar loading errors more gracefully (i.e. refresh the bar anyway). Updated project to Delphi XE7. Includes new executable. check-in: ebd6f87c86 user: tinus tags: trunk
Changes

Changes to out/TempusFugit.exe.

cannot compute difference between binary files

Name change from out/TempusFugit.ini.sample to out/TempusFugit.sample.ini.

1
2
3




4
5
6
7
8
9
10
[General]
Opacity=100





[Gradient]
StartColor=$7F0000
StartCurve=4

CloseColor=$007F00
CloseCurve=2




>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
[General]
Opacity=100

[Defaults]
StartTime=8:00:00
StopTime=17:00:00

[Gradient]
StartColor=$7F0000
StartCurve=4

CloseColor=$007F00
CloseCurve=2

Changes to src/F_Main.pas.

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
402
403
404
405
406
407
408

409



410
411
412
413
414
415
416
...
485
486
487
488
489
490
491

492
493
494
495
496
497
498
...
510
511
512
513
514
515
516

517


518
519
520
521
522
523
524
...
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
  Percentage: integer;
begin
  FSettings := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  FErrorFetchesAgo := -1;

  Application.HintHidePause := FSettings.ReadInteger('General', 'HintTimeout', 5000);

  FStartTime := Date + EncodeTime(8, 0, 0, 0);
  FStopTime := Date + EncodeTime(17, 0, 0, 0);

  SetLength(FWaypoints, 4);
  FWaypoints[0].RGB.Color := StringToColor(FSettings.ReadString('Gradient', 'StartColor', 'clHighlight'));
  FWaypoints[0].Position := 0;
  FWaypoints[0].MapArg := FSettings.ReadInteger('Gradient', 'StartCurve', 4);

  FWaypoints[1].RGB.Color := StringToColor(FSettings.ReadString('Gradient', 'CloseColor', '$007F00'));
................................................................................
begin
  Application.Terminate;
end;

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.miRefreshClick(Sender: TObject);
begin

  FetchHoursOnline;



end;

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.mnuOpacityClick(Sender: TObject);
var
  MenuItem: TMenuItem;
  i: Integer;
................................................................................

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.FetchHoursOnline();
var
  URL: string;
  DateOffset: integer;
  QueryDate: TDate;

  HourQuery, LunchQuery: string;
  Start, Stop: string;
  Exc: Exception;
  { -------------------------------------------------------------------------------------------- }
  function FetchHours(Query: string; out Start, Stop: string): boolean;
  var
    Content: TMemoryStream;
................................................................................
      if httpClient.ResponseCode = 200 then begin
        Content.Position := 0;
        SA := TStreamAdapter.Create(Content, soReference);

        // Parse the XML stream
        xmlDoc := CreateOLEObject('MSXML2.DOMDocument.6.0');
        if not xmlDoc.load(SA as IStream) then begin

          raise Exception.Create('Unable to parse!'#13#10 + xmlDoc.parseError.reason);


        end;
        xmlDoc.setProperty('SelectionNamespaces', 'xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005"');

        // Extract the hours
        xmlEntry := xmlDoc.selectSingleNode('/atom:feed/atom:entry[atom:title="' + Query + '"]');
        if not (VarIsClear(xmlEntry) or VarIsNull(xmlEntry)) then begin
          Result := True;
................................................................................
  // Determine the events to look for
  HourQuery := FSettings.ReadString('Google Calendar', 'WorkingHours', '');
  LunchQuery := FSettings.ReadString('Google Calendar', 'LunchHours', '');

  // Determine the date
  DateOffset := FSettings.ReadInteger('Debug', 'DateOffset', 0);
  QueryDate := IncDay(Date, DateOffset);



  // Assemble the URL
  URL := Format('%s?singleevents=true&orderby=starttime&start-min=%s&start-max=%s',
              [FSettings.ReadString('Google Calendar', 'URL', ''),
               FormatDateTime('yyyy-MM-dd', QueryDate, XMLFS),
               FormatDateTime('yyyy-MM-dd', IncDay(QueryDate), XMLFS)]);

  // Get the work hours
  if FetchHours(HourQuery, Start, Stop) then begin
    FStartTime := DateTimeFromXML(Start);
    FStopTime := DateTimeFromXML(Stop);
  end else begin
    FStartTime := QueryDate;
    FStopTime := QueryDate + 1;
  end;
  if DateOffset <> 0 then begin
    FStartTime := IncDay(FStartTime, -DateOffset);
    FStopTime := IncDay(FStopTime, -DateOffset);
  end;

  // Get the lunch hours







|
|







 







>
|
>
>
>







 







>







 







>
|
>
>







 







>
>












|
|







106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
...
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
...
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
  Percentage: integer;
begin
  FSettings := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  FErrorFetchesAgo := -1;

  Application.HintHidePause := FSettings.ReadInteger('General', 'HintTimeout', 5000);

  FStartTime := Date + FSettings.ReadTime('Defaults', 'StartTime', 0);
  FStopTime := Date + FSettings.ReadTime('Defaults', 'StopTime', 1);

  SetLength(FWaypoints, 4);
  FWaypoints[0].RGB.Color := StringToColor(FSettings.ReadString('Gradient', 'StartColor', 'clHighlight'));
  FWaypoints[0].Position := 0;
  FWaypoints[0].MapArg := FSettings.ReadInteger('Gradient', 'StartCurve', 4);

  FWaypoints[1].RGB.Color := StringToColor(FSettings.ReadString('Gradient', 'CloseColor', '$007F00'));
................................................................................
begin
  Application.Terminate;
end;

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.miRefreshClick(Sender: TObject);
begin
  try
    FetchHoursOnline;
  finally
    Self.Invalidate;
  end;
end;

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.mnuOpacityClick(Sender: TObject);
var
  MenuItem: TMenuItem;
  i: Integer;
................................................................................

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmMain.FetchHoursOnline();
var
  URL: string;
  DateOffset: integer;
  QueryDate: TDate;
  DefStart, DefStop: TTime;
  HourQuery, LunchQuery: string;
  Start, Stop: string;
  Exc: Exception;
  { -------------------------------------------------------------------------------------------- }
  function FetchHours(Query: string; out Start, Stop: string): boolean;
  var
    Content: TMemoryStream;
................................................................................
      if httpClient.ResponseCode = 200 then begin
        Content.Position := 0;
        SA := TStreamAdapter.Create(Content, soReference);

        // Parse the XML stream
        xmlDoc := CreateOLEObject('MSXML2.DOMDocument.6.0');
        if not xmlDoc.load(SA as IStream) then begin
          if not Assigned(Exc) then begin
            Exc := Exception.Create('Unable to parse!'#13#10 + xmlDoc.parseError.reason);
          end;
          Exit;
        end;
        xmlDoc.setProperty('SelectionNamespaces', 'xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005"');

        // Extract the hours
        xmlEntry := xmlDoc.selectSingleNode('/atom:feed/atom:entry[atom:title="' + Query + '"]');
        if not (VarIsClear(xmlEntry) or VarIsNull(xmlEntry)) then begin
          Result := True;
................................................................................
  // Determine the events to look for
  HourQuery := FSettings.ReadString('Google Calendar', 'WorkingHours', '');
  LunchQuery := FSettings.ReadString('Google Calendar', 'LunchHours', '');

  // Determine the date
  DateOffset := FSettings.ReadInteger('Debug', 'DateOffset', 0);
  QueryDate := IncDay(Date, DateOffset);
  DefStart := FSettings.ReadTime('Defaults', 'StartTime', 0);
  DefStop  := FSettings.ReadTime('Defaults', 'StopTime',  1);

  // Assemble the URL
  URL := Format('%s?singleevents=true&orderby=starttime&start-min=%s&start-max=%s',
              [FSettings.ReadString('Google Calendar', 'URL', ''),
               FormatDateTime('yyyy-MM-dd', QueryDate, XMLFS),
               FormatDateTime('yyyy-MM-dd', IncDay(QueryDate), XMLFS)]);

  // Get the work hours
  if FetchHours(HourQuery, Start, Stop) then begin
    FStartTime := DateTimeFromXML(Start);
    FStopTime := DateTimeFromXML(Stop);
  end else begin
    FStartTime := QueryDate + DefStart;
    FStopTime := QueryDate + DefStop;
  end;
  if DateOffset <> 0 then begin
    FStartTime := IncDay(FStartTime, -DateOffset);
    FStopTime := IncDay(FStopTime, -DateOffset);
  end;

  // Get the lunch hours