CheckForUpdates.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/WidgetFactory.js");
  20. include("scripts/Help/Help.js");
  21. function CheckForUpdates(guiAction) {
  22. Help.call(this, guiAction);
  23. }
  24. CheckForUpdates.prototype = new Help();
  25. CheckForUpdates.includeBasePath = includeBasePath;
  26. CheckForUpdates.prototype.getUrl = function() {
  27. return CheckForUpdates.getUrl();
  28. };
  29. CheckForUpdates.getBaseName = function() {
  30. var fileName = "";
  31. fileName += RSettings.getMajorVersion() + "_";
  32. fileName += RSettings.getMinorVersion() + "_";
  33. fileName += RSettings.getRevisionVersion() + "_";
  34. fileName += RSettings.getBuildVersion();
  35. return fileName;
  36. };
  37. CheckForUpdates.getUrl = function() {
  38. // compile update info URL:
  39. if (RSettings.isQt(6)) {
  40. // TODO: use https:
  41. return "http://www.qcad.org/qcad/version/" + CheckForUpdates.getBaseName() + ".html";
  42. }
  43. else {
  44. return "https://www.qcad.org/qcad/version/" + CheckForUpdates.getBaseName() + ".html";
  45. }
  46. };
  47. CheckForUpdates.prototype.beginEvent = function() {
  48. Help.prototype.beginEvent.call(this);
  49. // compile update info URL:
  50. var url = this.getUrl();
  51. // set up dialog:
  52. var appWin = EAction.getMainWindow();
  53. var dialog = WidgetFactory.createDialog(CheckForUpdates.includeBasePath, "CheckForUpdatesDialog.ui", appWin);
  54. var textBrowser = dialog.findChild("TextBrowser");
  55. WidgetFactory.initTextBrowser(textBrowser, QDesktopServices.openUrl);
  56. // load version info from qcad.org:
  57. textBrowser.setHtml("<p>" + qsTr("Checking for Updates...") + "</p>");
  58. if (downloadToFile(url, RSettings.getDataLocation(), "updates.html", 10000)) {
  59. var fn = RSettings.getDataLocation() + "/updates.html";
  60. if (new QFileInfo(fn).exists()) {
  61. textBrowser.setSource(QUrl.fromLocalFile(fn));
  62. }
  63. else {
  64. textBrowser.setHtml("<p>" + qsTr("Version information not found.") + "</p>");
  65. }
  66. }
  67. else {
  68. textBrowser.setHtml("<p>" + qsTr("No connection to server or file not found. Please try again later.") + "</p>");
  69. }
  70. WidgetFactory.restoreState(dialog);
  71. // show dialog:
  72. dialog.exec();
  73. WidgetFactory.saveState(dialog);
  74. destr(dialog);
  75. EAction.activateMainWindow();
  76. };