diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2014-02-03 15:29:43 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2014-02-03 15:29:43 +0000 |
commit | afb1fa29ae33467c62d4927fa0b58d339cbdd6e7 (patch) | |
tree | 43e21af23e31bab0004697b095358a1e1e154d13 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow | |
parent | 521431920bb0079a618ffe5d72bd6280608fc13f (diff) | |
download | mocca-afb1fa29ae33467c62d4927fa0b58d339cbdd6e7.tar.gz mocca-afb1fa29ae33467c62d4927fa0b58d339cbdd6e7.tar.bz2 mocca-afb1fa29ae33467c62d4927fa0b58d339cbdd6e7.zip |
Check for updates on startup (configurable)
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@506 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
7 files changed, 128 insertions, 15 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java index 68b48242..d04d59c1 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java @@ -112,6 +112,12 @@ public interface ConfigManipulator { public void setSignLocale(Locale locale); /** + * Sets whether to automatically check for application updates + * @param checkUpdate whether to automatically check for application updates + */ + public void setUpdateCheck(boolean checkUpdate); + + /** * Sets the default main window size * @param size a Point describing the size */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java index 91bd5ecf..0e3bda77 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java @@ -151,6 +151,12 @@ public interface ConfigProvider { public Locale getSignLocale(); /** + * Gets whether to automatically check for application updates + * @return whether to automatically check for application updates + */ + public boolean getUpdateCheck(); + + /** * Gets the configured MainWindow size * @return the configured MainWindow size */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java index 3010868b..0d860ea0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java @@ -86,45 +86,45 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, config.load(configSource); // Set Emblem - this.setDefaultEmblem(config + setDefaultEmblem(config .getProperty(Constants.CFG_EMBLEM)); // Set Mobile Phone Number - this.setDefaultMobileNumber(config + setDefaultMobileNumber(config .getProperty(Constants.CFG_MOBILE_NUMBER)); // Set signature note - this.setSignatureNote(config + setSignatureNote(config .getProperty(Constants.CFG_SIGNATURE_NOTE)); // Set Proxy Host - this.setProxyHost(config + setProxyHost(config .getProperty(Constants.CFG_PROXY_HOST)); // Set Proxy User - this.setProxyUser(config + setProxyUser(config .getProperty(Constants.CFG_PROXY_USER)); // Set Proxy Password - this.setProxyPass(config + setProxyPass(config .getProperty(Constants.CFG_PROXY_PASS)); // Set Output Folder - this.setDefaultOutputFolder(config + setDefaultOutputFolder(config .getProperty(Constants.CFG_OUTPUT_FOLDER)); String localeString = config.getProperty(Constants.CFG_LOCALE); Locale targetLocale = LocaleSerializer.parseFromString(localeString); if (targetLocale != null) { - this.setLocale(targetLocale); + setLocale(targetLocale); } String signlocalString = config.getProperty(Constants.CFG_SIGN_LOCALE); Locale signtargetLocale = LocaleSerializer.parseFromString(signlocalString); if (signtargetLocale != null) { - this.setSignLocale(signtargetLocale); + setSignLocale(signtargetLocale); } String bkuUrl = config @@ -155,7 +155,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, int port = Integer.parseInt(proxyPortString); if (port > 0 && port <= 0xFFFF) { - this.setProxyPort(port); + setProxyPort(port); } else { log.warn("Proxy port is out of range!: " + port); //$NON-NLS-1$ } @@ -175,7 +175,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, defaultBKU = BKUs.NONE; } } - this.setDefaultBKU(defaultBKU); + setDefaultBKU(defaultBKU); // Set Signature placeholder transparency int transparency = Constants.DEFAULT_SIGNATURE_PLACEHOLDER_TRANSPARENCY; @@ -188,7 +188,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, // ignore parsing exception } } - this.setPlaceholderTransparency(transparency); + setPlaceholderTransparency(transparency); // Set MainWindow size int width = Constants.DEFAULT_MAINWINDOW_WIDTH; @@ -264,7 +264,12 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, log.error("Signature Position read from config failed: not matching string"); //$NON-NLS-1$ } } - this.setDefaultSignaturePosition(position); + setDefaultSignaturePosition(position); + + // Set update check + String updateCheck = config.getProperty(Constants.CFG_UPDATE_CHECK); + if (updateCheck != null) + setUpdateCheck(!updateCheck.equalsIgnoreCase(Constants.FALSE)); } /* @@ -332,6 +337,9 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, if (Constants.THEME != Constants.Themes.DEFAULT) props.setProperty(Constants.CFG_THEME, Constants.THEME.name()); + if (!getUpdateCheck()) + props.setProperty(Constants.CFG_UPDATE_CHECK, Constants.FALSE); + FileOutputStream outputstream = new FileOutputStream(configFile, false); props.store(outputstream, "Configuration file was generated!"); //$NON-NLS-1$ @@ -1014,6 +1022,22 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, } /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigManipulator#setUpdateCheck(boolean) + */ + @Override + public void setUpdateCheck(boolean checkUpdate) { + this.configuration.setUpdateCheck(checkUpdate); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigProvider#getUpdateCheck() + */ + @Override + public boolean getUpdateCheck() { + return this.configuration.getUpdateCheck(); + } + + /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.ConfigManipulator#setMainWindowSize(org.eclipse.swt.graphics.Point) */ @Override diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java index 486647cc..46ae32c6 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java @@ -232,6 +232,18 @@ public interface ConfigurationContainer { public void setDefaultSignaturePosition(SignaturePosition signaturePosition); /** + * Gets whether to automatically check for application updates + * @return whether to automatically check for application updates + */ + public boolean getUpdateCheck(); + + /** + * Sets whether to automatically check for application updates + * @param checkUpdate whether to automatically check for application updates + */ + public void setUpdateCheck(boolean checkUpdate); + + /** * Gets the main window size * @return the main window size */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java index ec79b403..630b22e9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java @@ -103,6 +103,9 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /** Holds the default signature position */ protected SignaturePosition defaultSignaturePosition = null; + /** Whether to automatically check for updates */ + protected boolean updateCheck = true; + /** Whether to skip the output state */ protected boolean skipFinish = false; @@ -429,6 +432,23 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#getUpdateCheck() + */ + @Override + public boolean getUpdateCheck() { + return this.updateCheck; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#setUpdateCheck(boolean) + */ + @Override + public void setUpdateCheck(boolean checkUpdate) { + this.updateCheck = checkUpdate; + } + + + /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.ConfigurationContainer#getMainWindowSize() */ @Override diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java index fe4fceb3..9dcb38e5 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java @@ -128,6 +128,12 @@ public interface PersistentConfigProvider { public Locale getSignLocale(); /** + * Gets whether to automatically check for application updates + * @return whether to automatically check for application updates + */ + public boolean getUpdateCheck(); + + /** * Gets the configured MainWindow size * @return the configured MainWindow size */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index bb715712..63c54c71 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -16,14 +16,20 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.awt.Desktop; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; import org.apache.log4j.PropertyConfigurator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.program.Program; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,12 +49,16 @@ import at.asit.pdfover.gui.cliarguments.ProxyPassArgument; import at.asit.pdfover.gui.cliarguments.ProxyPortArgument; import at.asit.pdfover.gui.cliarguments.ProxyUserArgument; import at.asit.pdfover.gui.cliarguments.SkipFinishArgument; -import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.Dialog.ICON; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.utils.Unzipper; +import at.asit.pdfover.gui.utils.VersionComparator; import at.asit.pdfover.gui.workflow.StateMachine; +import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; import at.asit.pdfover.signator.Signator; /** @@ -104,7 +114,6 @@ public class PrepareConfigurationState extends State { getStateMachine().getConfigProvider().getConfigurationDirectory() + FILE_SEPARATOR + filename)); log.info("Loaded config from file : " + filename); //$NON-NLS-1$ - } catch (FileNotFoundException ex) { if (filename.equals(Constants.DEFAULT_CONFIG_FILENAME)) { // we only check for resource config file if it is the @@ -329,6 +338,36 @@ public class PrepareConfigurationState extends State { getStateMachine().exit(); } + // Check for updates + if (getStateMachine().getConfigProvider().getUpdateCheck() && Constants.APP_VERSION != null) { + HttpClient client = MobileBKUHelper.getHttpClient(); + GetMethod method = new GetMethod(Constants.CURRENT_RELEASE_URL); + try { + client.executeMethod(method); + String version = method.getResponseBodyAsString().trim(); + + if (VersionComparator.before(Constants.APP_VERSION, version)) { + Dialog info = new Dialog(getStateMachine() + .getGUIProvider().getMainShell(), + Messages.getString("version_check.UpdateTitle"), //$NON-NLS-1$ + String.format(Messages.getString("version_check.UpdateText"), //$NON-NLS-1$ + version), + BUTTONS.OK_CANCEL, ICON.INFORMATION); + if (info.open() == SWT.OK) + { + if (Desktop.isDesktopSupported()) { + Desktop.getDesktop().browse(new URI(Constants.UPDATE_URL)); + } else { + log.info("SWT Desktop is not supported on this platform"); //$NON-NLS-1$ + Program.launch(Constants.UPDATE_URL); + } + } + } + } catch (Exception e) { + log.error("Error downloading update information: ", e); //$NON-NLS-1$ + } + } + // Set usedSignerLib ... getStateMachine().getPDFSigner().setUsedPDFSignerLibrary( Signator.Signers.PDFAS); |