1 /*
2  * AboutDialogContents.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.studio.client.application.ui;
16 
17 import com.google.gwt.aria.client.Id;
18 import com.google.gwt.aria.client.Roles;
19 import com.google.gwt.dom.client.Element;
20 import com.google.gwt.user.client.ui.Anchor;
21 import org.rstudio.core.client.Debug;
22 import org.rstudio.core.client.StringUtil;
23 import org.rstudio.core.client.widget.HyperlinkLabel;
24 import org.rstudio.studio.client.RStudioGinjector;
25 import org.rstudio.studio.client.application.Desktop;
26 import org.rstudio.studio.client.application.model.ProductEditionInfo;
27 import org.rstudio.studio.client.application.model.ProductInfo;
28 
29 import com.google.gwt.core.client.GWT;
30 import com.google.gwt.uibinder.client.UiBinder;
31 import com.google.gwt.uibinder.client.UiField;
32 import com.google.gwt.user.client.Window;
33 import com.google.gwt.user.client.ui.Composite;
34 import com.google.gwt.user.client.ui.HTMLPanel;
35 import com.google.gwt.user.client.ui.InlineLabel;
36 import com.google.gwt.user.client.ui.Label;
37 import com.google.gwt.user.client.ui.TextArea;
38 import com.google.gwt.user.client.ui.Widget;
39 import org.rstudio.studio.client.application.model.ProductNotice;
40 import org.rstudio.studio.client.server.ServerError;
41 import org.rstudio.studio.client.server.ServerRequestCallback;
42 
43 public class AboutDialogContents extends Composite
44 {
ensureStylesInjected()45    public static void ensureStylesInjected()
46    {
47       new AboutDialogContents();
48    }
49 
50    private static AboutDialogContentsUiBinder uiBinder = GWT
51          .create(AboutDialogContentsUiBinder.class);
52 
53    interface AboutDialogContentsUiBinder extends
54          UiBinder<Widget, AboutDialogContents>
55    {
56    }
57 
AboutDialogContents()58    private AboutDialogContents()
59    {
60       uiBinder.createAndBindUi(this);
61    }
62 
AboutDialogContents(ProductInfo info, ProductEditionInfo editionInfo)63    public AboutDialogContents(ProductInfo info, ProductEditionInfo editionInfo)
64    {
65       initWidget(uiBinder.createAndBindUi(this));
66       versionMajorLabel.setText(info.version_major + "." + info.version_minor + "." + info.version_patch);
67       versionBuildLabel.setText("Build " + info.version_suffix.split("\\+")[1]);
68 
69       // a11y
70       productInfo.getElement().setId("productinfo");
71       gplLinkLabel.getElement().setId("gplLinkLabel");
72       Roles.getLinkRole().setAriaDescribedbyProperty(gplLink.getElement(), Id.of(gplLinkLabel.getElement()));
73 
74       userAgentLabel.setText(
75             Window.Navigator.getUserAgent());
76       buildLabel.setText(
77            "\"" + info.release_name + "\" " + info.build_type + " (" + info.commit.substring(0, 8) + ", " +
78            info.date + ") for " + info.os);
79       productName.setText(editionInfo.editionName());
80       copyrightYearLabel.setText("2009-" + info.copyright_year);
81 
82       // Warn that dailies and previews aren't supported
83       if (!info.build_type.equals("Release")) {
84          supportNotice.setText(
85             "This " +
86             info.build_type +
87             " build of " +
88             editionInfo.editionName() +
89             " is provided by RStudio, PBC for testing purposes only and is not an officially supported release."
90          );
91       }
92       else
93       {
94          preReleaseRibbon.setVisible(false);
95       }
96 
97 
98       showNoticelink_.setClickHandler(() ->
99       {
100          RStudioGinjector.INSTANCE.getServer().getProductNotice(new ServerRequestCallback<ProductNotice>()
101          {
102             @Override
103             public void onResponseReceived(ProductNotice notice)
104             {
105                AboutOpenSourceDialog about = new AboutOpenSourceDialog(notice);
106                about.showModal();
107             }
108             @Override
109             public void onError(ServerError error)
110             {
111                Debug.logError(error);
112             }
113          });
114       });
115 
116       if (editionInfo.proLicense())
117       {
118          // no need to show GPL notice in pro edition
119          gplNotice.setVisible(false);
120 
121          if (Desktop.hasDesktopFrame())
122          {
123             // load license status in desktop mode
124             licenseBox.setVisibleLines(3);
125             licenseLabel.setVisible(true);
126             licenseBox.setVisible(true);
127             licenseBox.setText("Loading...");
128             Desktop.getFrame().getLicenseStatusMessage(licenseStatus ->
129             {
130                licenseBox.setText(licenseStatus);
131             });
132          }
133       }
134    }
135 
getDescriptionElement()136    public Element getDescriptionElement()
137    {
138       return productInfo.getElement();
139    }
140 
141    @UiField InlineLabel versionMajorLabel;
142    @UiField InlineLabel versionBuildLabel;
143    @UiField InlineLabel userAgentLabel;
144    @UiField InlineLabel buildLabel;
145    @UiField InlineLabel copyrightYearLabel;
146    @UiField HyperlinkLabel showNoticelink_;
147    @UiField HTMLPanel gplNotice;
148    @UiField HTMLPanel licenseLabel;
149    @UiField HTMLPanel preReleaseRibbon;
150    @UiField TextArea licenseBox;
151    @UiField Label productName;
152    @UiField HTMLPanel productInfo;
153    @UiField InlineLabel supportNotice;
154    @UiField Anchor gplLink;
155    @UiField Label gplLinkLabel;
156 }
157