Skip to content

Commit

Permalink
url format changed
Browse files Browse the repository at this point in the history
From now on url will be build using url and token
  • Loading branch information
SergeyRock committed Aug 18, 2023
1 parent 44ff4b5 commit b50d013
Show file tree
Hide file tree
Showing 14 changed files with 916 additions and 1,936 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project
tmp/
.ignore/
AutomaticConversion.log
*.bat

Expand Down
2 changes: 2 additions & 0 deletions NightscoutWatcher.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ program NightscoutWatcher;
uses
Interfaces,
Forms,
{$IFDEF ExplSSL}, sslsockets, fpopenssl,{$ENDIF}
opensslsockets,
ufMain in 'forms\ufMain.pas' {fMain},
ufSettings in 'forms\ufSettings.pas' {fSettings},
uNightscout in 'units\uNightscout.pas',
Expand Down
18 changes: 13 additions & 5 deletions NightscoutWatcher.lpi
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasUsesSectionForAllUnits Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="Nightscout Watcher"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
Expand All @@ -25,7 +25,7 @@
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="2"/>
<MinorVersionNr Value="14"/>
<BuildNr Value="126"/>
<BuildNr Value="135"/>
<StringTable CompanyName="Sergey Oleynikov" LegalCopyright="Sergey Oleynikov" ProductName="Nightscout Watcher"/>
</VersionInfo>
<BuildModes Count="3">
Expand Down Expand Up @@ -95,6 +95,7 @@
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
<DebugInfoType Value="dsDwarf2Set"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
Expand All @@ -116,7 +117,6 @@
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<Item1>
Expand All @@ -126,7 +126,7 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="6">
<Units Count="7">
<Unit0>
<Filename Value="NightscoutWatcher.dpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -161,6 +161,14 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="ufTimerDialog"/>
</Unit5>
<Unit6>
<Filename Value="forms\ufnightscoutsite.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="fNightscoutSite"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="ufNightscoutSite"/>
</Unit6>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2,570 changes: 682 additions & 1,888 deletions forms/ufMain.lfm

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions forms/ufMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ TfMain = class(TForm)
procedure DrawTextInCenter(const AText: string);
procedure DoDraw(Sender: TObject);
procedure DoUpdateCallerFormWithSettings;
function SetNightscoutUrl(Url: string): Boolean;
function SetNightscoutUrl(Url: string; Token: string): Boolean;
function SetCheckIntervalByString(Value: string): Boolean;
function SetMaximumDrawStageSizeToCanvas(DrawStage: TDrawStage; const AText: string): Byte;
procedure SetAlphaBlendValue(Value: Integer);
Expand Down Expand Up @@ -259,7 +259,7 @@ TfMain = class(TForm)
implementation

uses
ufSettings, ufTimerDialog, Math, StrUtils, Types, graphtype,
ufNightscoutSite, ufSettings, ufTimerDialog, Math, StrUtils, Types, graphtype,
intfgraphics, fpimage, process, ButtonPanel, fphttpclient, fpopenssl, openssl
{$IFDEF WINDOWS}
, mmsystem
Expand Down Expand Up @@ -582,7 +582,7 @@ procedure TfMain.actSetHoursToReceiveExecute(Sender: TObject);

procedure TfMain.actSetNightscoutSiteExecute(Sender: TObject);
var
Url, Msg: string;
NightscoutUrl, NightscoutToken, Msg: string;
DialogResult: TModalResult;
WasConnected: Boolean;
TimerIntervalSecs: Integer;
Expand All @@ -591,16 +591,13 @@ procedure TfMain.actSetNightscoutSiteExecute(Sender: TObject);
try
WasConnected := Connected;
Connected := False;
Url := Settings.NightscoutUrl;
TimerIntervalSecs := -1;
if WasConnected then
TimerIntervalSecs := 20;
Msg := 'Type in URL of Nightscout site.' + LineEnding +
'If an error occurs try to change protocol to HTTP instead of HTTPS in URL.';
DialogResult := TfTimerDialog.Execute(Self, 'Nighscout site', Msg, Url, [pbOK, pbCancel], TimerIntervalSecs);
NightscoutUrl := Settings.NightscoutUrl;
NightscoutToken := Settings.NightscoutToken;

DialogResult := TfNightscoutSite.Execute(Self, NightscoutUrl, NightscoutToken);
if DialogResult = mrOK then
begin
if (Url <> '') and (SetNightscoutUrl(Url)) then
if SetNightscoutUrl(NightscoutUrl, NightscoutToken) then
tmrTimer(tmr)
else
begin
Expand Down Expand Up @@ -1180,6 +1177,7 @@ function TfMain.LoadEntriesData: Boolean;
Url: string;
begin
Url := Settings.GetEntriesUrlByHours();

Result := TFPHttpClient.SimpleGet(Url);
end;

Expand Down Expand Up @@ -1285,13 +1283,14 @@ procedure TfMain.HardInvalidate();
OnResize := FormResize;
end;

function TfMain.SetNightscoutUrl(Url: string): Boolean;
function TfMain.SetNightscoutUrl(Url: string; Token: string): Boolean;
begin
Result := False;
if Trim(Url) = '' then
Exit;

Settings.NightscoutUrl := ExcludeTrailingBackslash(Url);
Settings.NightscoutUrl := ExcludeTrailingBackslash(Trim(Url));
Settings.NightscoutToken := ExcludeTrailingBackslash(Trim(Token));
Result := True;
end;

Expand Down
54 changes: 39 additions & 15 deletions forms/ufSettings.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object fSettings: TfSettings
Left = 1997
Left = 1155
Height = 500
Top = 312
Top = 179
Width = 600
Caption = 'Settings'
ClientHeight = 500
Expand All @@ -16,7 +16,7 @@ object fSettings: TfSettings
OnDestroy = FormDestroy
OnKeyDown = FormKeyDown
Position = poScreenCenter
LCLVersion = '2.0.6.0'
LCLVersion = '2.2.6.0'
object btnOK: TButton
Left = 120
Height = 36
Expand Down Expand Up @@ -44,10 +44,10 @@ object fSettings: TfSettings
Height = 432
Top = 0
Width = 600
ActivePage = tsVisual
ActivePage = tsMain
Align = alTop
Anchors = [akTop, akLeft, akRight, akBottom]
TabIndex = 1
TabIndex = 0
TabOrder = 2
OnChange = pcChange
object tsMain: TTabSheet
Expand All @@ -57,7 +57,7 @@ object fSettings: TfSettings
object lblCheckInterval: TLabel
Left = 13
Height = 19
Top = 133
Top = 198
Width = 178
AutoSize = False
Caption = 'Check interval in seconds'
Expand All @@ -71,7 +71,7 @@ object fSettings: TfSettings
object lblHoursToReceive: TLabel
Left = 13
Height = 19
Top = 174
Top = 239
Width = 186
AutoSize = False
Caption = 'Hours to receive data'
Expand All @@ -97,7 +97,7 @@ object fSettings: TfSettings
object lblTimeZoneCorrection: TLabel
Left = 13
Height = 35
Top = 212
Top = 277
Width = 157
AutoSize = False
Caption = 'Time-zone correction in hours'
Expand All @@ -111,7 +111,7 @@ object fSettings: TfSettings
object cbIsMmolL: TCheckBox
Left = 13
Height = 23
Top = 88
Top = 153
Width = 233
Caption = 'Set unit of measure to mmol/l'
Font.Color = clWindowText
Expand All @@ -123,7 +123,7 @@ object fSettings: TfSettings
object seCheckInterval: TSpinEdit
Left = 224
Height = 27
Top = 128
Top = 193
Width = 60
Font.Color = clWindowText
Font.Height = -16
Expand All @@ -137,7 +137,7 @@ object fSettings: TfSettings
object seHoursToReceive: TSpinEdit
Left = 224
Height = 27
Top = 170
Top = 235
Width = 60
Font.Color = clWindowText
Font.Height = -16
Expand All @@ -163,7 +163,7 @@ object fSettings: TfSettings
object seTimeZoneCorrection: TSpinEdit
Left = 224
Height = 27
Top = 213
Top = 278
Width = 60
Font.Color = clWindowText
Font.Height = -16
Expand All @@ -174,6 +174,30 @@ object fSettings: TfSettings
TabOrder = 4
Value = 3
end
object lblNightscoutToken: TLabel
Left = 13
Height = 19
Top = 79
Width = 119
Caption = 'Nightscout token'
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Tahoma'
ParentColor = False
ParentFont = False
end
object eNightscoutToken: TEdit
Left = 13
Height = 27
Top = 102
Width = 566
Anchors = [akTop, akLeft, akRight]
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Tahoma'
ParentFont = False
TabOrder = 5
end
end
object tsVisual: TTabSheet
Caption = 'Diagram'
Expand Down Expand Up @@ -444,7 +468,7 @@ object fSettings: TfSettings
ParentFont = False
TabOrder = 13
end
object cbShowIconOnTaskbar: TCheckBox
object cbShowIconInTaskbar: TCheckBox
Left = 277
Height = 23
Top = 88
Expand Down Expand Up @@ -2039,7 +2063,7 @@ object fSettings: TfSettings
object odWallpaper: TOpenDialog
Filter = '*.jp*g|*.jp*g'
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail, ofAutoPreview]
left = 528
top = 40
Left = 528
Top = 40
end
end
8 changes: 6 additions & 2 deletions forms/ufSettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ TfSettings = class(TForm)
cbDrawHoursToReceiveData: TCheckBox;
cbEnableAudioAlarms: TCheckBox;
cbShowIconInTray: TCheckBox;
cbShowIconInTaskbar: TCheckBox;
cbStayOnTop: TCheckBox;
cbDrawGlucoseLevelDelta: TCheckBox;
cbDrawGlucoseAvg: TCheckBox;
cbEnableGlucoseLevelAlarms: TCheckBox;
cbEnableStaleDataAlarms: TCheckBox;
cbDrawWallpaper: TCheckBox;
cbShowIconInTaskbar: TCheckBox;
eNightscoutToken: TEdit;
eWallpaper: TEdit;
gbGlucoseLevelAlarms: TGroupBox;
Image1: TImage;
lblDeveloper: TLabel;
lblNightscoutToken: TLabel;
lblVersion: TLabel;
lblGitHubLink: TLabel;
lblHighGlucoseAlarm: TLabel;
Expand Down Expand Up @@ -152,7 +154,7 @@ procedure TfSettings.btnOKClick(Sender: TObject);
AssignComponentsToSettings();
SourceSettings.Assign(NewSettings);

if (NewSettings.NightscoutUrl <> SourceSettings.NightscoutUrl) and
if ((NewSettings.NightscoutUrl <> SourceSettings.NightscoutUrl) or (NewSettings.NightscoutToken <> SourceSettings.NightscoutToken)) and
Assigned(OnTryLoadEntriesData) and not OnTryLoadEntriesData then
begin
ModalResult := mrNone;
Expand Down Expand Up @@ -333,6 +335,7 @@ procedure TfSettings.AssignSettingsToComponents();
seUrgentStaleDataAlarm.Value := NewSettings.UrgentStaleDataAlarm;
seTimeZoneCorrection.Value := NewSettings.TimeZoneCorrection;
eNightscoutSite.Text := NewSettings.NightscoutUrl;
eNightscoutToken.Text := NewSettings.NightscoutToken;

AssignGlucoseAlertInMmolL(seUrgentHighGlucoseAlarm);
AssignGlucoseAlertInMmolL(seHighGlucoseAlarm);
Expand Down Expand Up @@ -380,6 +383,7 @@ procedure TfSettings.AssignComponentsToSettings;
NewSettings.ShowIconInTaskBar := cbShowIconInTaskbar.Checked;
NewSettings.ShowIconInTray := cbShowIconInTray.Checked;
NewSettings.NightscoutUrl := eNightscoutSite.Text;
NewSettings.NightscoutToken := eNightscoutToken.Text;

NewSettings.ScaleIndex := sbScale.Position;
NewSettings.AlphaBlendValue := sbAlphaBlend.Position;
Expand Down
Loading

0 comments on commit b50d013

Please sign in to comment.