Skip to content

Commit

Permalink
Merge pull request #3463 from keymanapp/feat/windows/rework-download-…
Browse files Browse the repository at this point in the history
…keyboard-dialog-style

feat(windows): rework download keyboard dialog style
  • Loading branch information
mcdurdin authored Aug 17, 2020
2 parents 0eeef1b + 0fbbf41 commit 9846da9
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 35 deletions.
76 changes: 50 additions & 26 deletions windows/src/desktop/kmshell/install/UfrmInstallKeyboardFromWeb.pas
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ interface
type
TfrmInstallKeyboardFromWeb = class(TfrmWebContainer)
dlgSaveFile: TSaveDialog;
procedure TntFormShow(Sender: TObject);
procedure TntFormCreate(Sender: TObject);
private
FDownloadFilename: string;
FDownloadURL: string;
frmDownloadProgress: TfrmDownloadProgress;
FDownloadStatusText: string;
FDownloadStatusCode: Integer;
procedure DoDownload(AOwner: TfrmDownloadProgress; var Result: Boolean);
procedure cefBeforeBrowse(Sender: TObject; const Url: string;
wasHandled: Boolean);
procedure cefBeforeBrowseSync(Sender: TObject; const Url: string;
out Handled: Boolean);
procedure cefLoadingStateChange(Sender: TObject; isLoading, canGoBack, canGoForward: Boolean);
procedure DownloadAndInstallPackage(const PackageID, BCP47: string);
procedure HttpReceiveData(const Sender: TObject; AContentLength,
AReadCount: Int64; var Abort: Boolean);
Expand All @@ -77,6 +80,9 @@ implementation
httpuploader,
GlobalProxySettings,
Keyman.Configuration.UI.InstallFile,
Keyman.System.LocaleStrings,
kmint,
MessageIdentifierConsts,
Upload_Settings,
utilfiletypes,
utildir,
Expand All @@ -95,31 +101,44 @@ procedure TfrmInstallKeyboardFromWeb.FireCommand(const command: WideString;
inherited;
end;

procedure TfrmInstallKeyboardFromWeb.TntFormShow(Sender: TObject);
procedure TfrmInstallKeyboardFromWeb.TntFormCreate(Sender: TObject);
begin
inherited;
// Ensures keyman.com hosted site opens locally
cef.ShouldOpenRemoteUrlsInBrowser := False;
cef.OnBeforeBrowse := cefBeforeBrowse;
cef.OnBeforeBrowseSync := cefBeforeBrowseSync;
cef.OnLoadingStateChange := cefLoadingStateChange;

FRenderPage := 'downloadkeyboard';

Content_Render;
inherited;
end;

procedure TfrmInstallKeyboardFromWeb.cefBeforeBrowseSync(Sender: TObject; const Url: string; out Handled: Boolean);
begin
Handled := TRegEx.IsMatch(Url, UrlPath_RegEx_MatchKeyboardsInstall);
end;

procedure TfrmInstallKeyboardFromWeb.cefLoadingStateChange(Sender: TObject;
isLoading, canGoBack, canGoForward: Boolean);
begin
if not isLoading then
begin
if canGoBack
then cef.cef.ExecuteJavaScript('updateBackButtonState(true)', cef.cef.Browser.MainFrame.Url)
else cef.cef.ExecuteJavaScript('updateBackButtonState(false)', cef.cef.Browser.MainFrame.Url);
end;
end;

procedure TfrmInstallKeyboardFromWeb.cefBeforeBrowse(Sender: TObject; const Url: string; wasHandled: Boolean);
var
m: TMatch;
uri: TURI;
BCP47: string;
PackageID: string;
begin

m := TRegEx.Match(Url, UrlPath_RegEx_MatchKeyboardsInstall);
if m.Success then
begin
Expand Down Expand Up @@ -151,7 +170,10 @@ procedure TfrmInstallKeyboardFromWeb.DownloadAndInstallPackage(const PackageID,
try
frmDownloadProgress.Callback := DoDownload;
if frmDownloadProgress.ShowModal <> mrOk then
begin
ShowMessage(TLocaleStrings.MsgFromIdFormat(kmcom, S_DownloadKeyboard_DownloadError, [FDownloadStatusText, FDownloadStatusCode]));
Exit;
end;
finally
frmDownloadProgress.Free;
end;
Expand Down Expand Up @@ -181,33 +203,35 @@ procedure TfrmInstallKeyboardFromWeb.DoDownload(AOwner: TfrmDownloadProgress; va
FTempFilename: string;
begin
Result := False;
FTempFilename := FDownloadFilename + '.download';
Client := THTTPClient.Create;
FTempFilename := FDownloadFilename + '.download';
Client := THTTPClient.Create;
try
Client.OnReceiveData := HttpReceiveData;

Stream := TFileStream.Create(FTempFilename, fmCreate);
try
Client.OnReceiveData := HttpReceiveData;

Stream := TFileStream.Create(FTempFilename, fmCreate);
try
Response := Client.Get(FDownloadURL, Stream);
Result := Response.StatusCode = 200;
finally
Stream.Free;
end;
Response := Client.Get(FDownloadURL, Stream);
Result := Response.StatusCode = 200;
FDownloadStatusText := Response.StatusText;
FDownloadStatusCode := Response.StatusCode;
finally
Stream.Free;
end;

if FileExists(FTempFilename) then
if FileExists(FTempFilename) then
begin
if Result then
begin
if Result then
begin
if FileExists(FDownloadFilename) then
System.SysUtils.DeleteFile(FDownloadFilename);
RenameFile(FTempFilename, FDownloadFilename);
end
else
System.SysUtils.DeleteFile(FTempFilename);
end;
finally
Client.Free;
if FileExists(FDownloadFilename) then
System.SysUtils.DeleteFile(FDownloadFilename);
RenameFile(FTempFilename, FDownloadFilename);
end
else
System.SysUtils.DeleteFile(FTempFilename);
end;
finally
Client.Free;
end;
end;


Expand Down
10 changes: 5 additions & 5 deletions windows/src/desktop/kmshell/kmshell.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<VerInfo_Keys>CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<BT_BuildType>Debug</BT_BuildType>
<Debugger_RunParams>-splash</Debugger_RunParams>
<Debugger_RunParams>-c</Debugger_RunParams>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
Expand Down Expand Up @@ -413,15 +413,15 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Profiling\AQtimeModule1.aqt" Configuration="Debug" Class="ProjectFile">
<DeployFile LocalName="kmshell.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteDir>.\</RemoteDir>
<RemoteName>kmshell.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="kmshell.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="Profiling\AQtimeModule1.aqt" Configuration="Debug" Class="ProjectFile">
<Platform Name="Win32">
<RemoteName>kmshell.exe</RemoteName>
<RemoteDir>.\</RemoteDir>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand Down
Binary file modified windows/src/desktop/kmshell/kmshell.res
Binary file not shown.
6 changes: 6 additions & 0 deletions windows/src/desktop/kmshell/xml/config.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ input[type='submit'], input[type='button'], button
border: none;
}

input[type='submit']:disabled, input[type='button']:disabled, button:disabled
{
color: #c0c0cf;
background: #80808f;
}

a.hotkey:link, a.hotkey:visited
{
color: blue;
Expand Down
25 changes: 21 additions & 4 deletions windows/src/desktop/kmshell/xml/downloadkeyboard.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<script src="/app/sentry.bundle.min.js"></script>
<script src="/app/sentry.init.js"></script>
<script src="/app/jquery.min.js"></script>
<title><xsl:value-of select="$locale/string[@name='S_DownloadKeyboard_Title']"/></title>
<link rel="stylesheet" type="text/css" href="/app/config.css" />
<style type="text/css">
Expand Down Expand Up @@ -57,18 +58,34 @@
else return;
event.cancelBubble = true; event.returnValue = false;
}
// This function is called by the Delphi code when browse events
// happen, because we cannot determine the state of history adequately
// from within the browser context.
function updateBackButtonState(shouldEnable) {
document.getElementById('button_back').disabled = !shouldEnable;
}
function goBack() {
history.back();
}
]]></script>

</head>
<body>
<div id="size"></div>
<iframe id="contentframe" frameborder="0">
<xsl:attribute name="src"><xsl:value-of select='/Keyman/keyman-com' />/go/windows/<xsl:value-of select="/Keyman/version-info/@versionRelease" />/download-keyboards?version=<xsl:value-of select="/Keyman/Version" /></xsl:attribute>&#160;
</iframe>
<div id="footerframe">
<!--<div style="float:left; font-size: 13.3px;">
<input type="checkbox" id="chkDownloadOnly" /> <label for="chkDownloadOnly"><xsl:value-of select="$locale/string[@name='S_DownloadKeyboard_DownloadOnlyCheckbox']"/></label>
</div>-->
<div style="float:left; padding-left: 8px">
<xsl:call-template name="button">
<xsl:with-param name="id">back</xsl:with-param>
<xsl:with-param name="disabled">1</xsl:with-param>
<xsl:with-param name="caption"><xsl:value-of select="$locale/string[@name='S_Button_Back']"/></xsl:with-param>
<xsl:with-param name="command">javascript:goBack()</xsl:with-param>
<xsl:with-param name="width">70px</xsl:with-param>
</xsl:call-template>
</div>
<div style="float:right; padding-right: 8px">
<xsl:call-template name="button">
<xsl:with-param name="caption"><xsl:value-of select="$locale/string[@name='S_Button_Cancel']"/></xsl:with-param>
Expand Down
3 changes: 3 additions & 0 deletions windows/src/desktop/kmshell/xml/elements.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<xsl:param name="default" />
<xsl:param name="width" />
<xsl:param name="id" />
<xsl:param name="disabled" />
<xsl:param name="tabid" />
<xsl:param name="shield" />

Expand All @@ -74,6 +75,7 @@
<xsl:otherwise>button</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$disabled = 1"><xsl:attribute name="disabled">disabled</xsl:attribute></xsl:if>
<xsl:attribute name="id">button_<xsl:value-of select="$id"/></xsl:attribute>
<xsl:attribute name="onclick"><xsl:choose><xsl:when test="$onclick != ''"><xsl:value-of select="$onclick"/></xsl:when><xsl:otherwise>location.href="<xsl:value-of select="$command"/>";</xsl:otherwise></xsl:choose></xsl:attribute>
<xsl:attribute name="tabindex"><xsl:value-of select="$tabid"/></xsl:attribute>
Expand All @@ -98,6 +100,7 @@
<xsl:otherwise>button</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$disabled = 1"><xsl:attribute name="disabled">disabled</xsl:attribute></xsl:if>
<xsl:attribute name="ID">button_<xsl:value-of select="$id"/></xsl:attribute>
<xsl:attribute name="onclick"><xsl:choose><xsl:when test="$onclick != ''"><xsl:value-of select="$onclick"/></xsl:when><xsl:otherwise>location.href="<xsl:value-of select="$command"/>";</xsl:otherwise></xsl:choose></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="$caption" /></xsl:attribute>
Expand Down
10 changes: 10 additions & 0 deletions windows/src/desktop/kmshell/xml/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@
<!-- Introduced: 7.0.230.0 -->
<string name="S_DownloadKeyboard_DownloadOnlyCheckbox" comment="Download only option checkbox">Don't install, just download</string>

<!-- Parameters: %0:s = Error Message, %1:d Error Code -->
<!-- Context: Download Keyboard Dialog -->
<!-- String Type: FormatString -->
<!-- Introduced: 14.0 -->
<string name="S_DownloadKeyboard_DownloadError" comment="Message shown when there is an error downloading the keyboard package">Unable to download keyboard, error %1:d: %0:s</string>

<!-- Context: Download Keyboard Dialog -->
<!-- String Type: PlainText -->
<!-- Introduced: 14.0 -->
<string name="S_Button_Back" comment="Back button">&lt; Back</string>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ object frameCEFHost: TframeCEFHost
OnWidgetCompMsg = cefWidgetCompMsg
OnProcessMessageReceived = cefProcessMessageReceived
OnLoadEnd = cefLoadEnd
OnLoadingStateChange = cefLoadingStateChange
OnSetFocus = cefSetFocus
OnRunContextMenu = cefRunContextMenu
OnPreKeyEvent = cefPreKeyEvent
Expand Down
Loading

0 comments on commit 9846da9

Please sign in to comment.