diff --git a/LogarithmPlotter/helper.py b/LogarithmPlotter/helper.py
new file mode 100644
index 0000000..31fcebb
--- /dev/null
+++ b/LogarithmPlotter/helper.py
@@ -0,0 +1,150 @@
+"""
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+"""
+
+from PySide2.QtWidgets import QMessageBox, QApplication
+from PySide2.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, Slot, QCoreApplication
+from PySide2.QtQml import QQmlApplicationEngine
+from PySide2.QtGui import QImage
+from PySide2 import __version__ as PySide2_version
+
+from os import chdir, path
+from json import loads
+from webbrowser import open as openWeb
+from sys import version as sys_version
+from urllib.request import urlopen
+from urllib.error import HTTPError, URLError
+
+
+from LogarithmPlotter import config, __VERSION__
+
+class ChangelogFetcher(QRunnable):
+ def __init__(self, helper):
+ QRunnable.__init__(self)
+ self.helper = helper
+
+ def run(self):
+ msg_text = "Unknown changelog error."
+ try:
+ # Fetching version
+ r = urlopen("https://api.ad5001.eu/changelog/logarithmplotter/")
+ lines = r.readlines()
+ r.close()
+ msg_text = "".join(map(lambda x: x.decode('utf-8'), lines)).strip()
+ except HTTPError as e:
+ msg_text = QCoreApplication.translate("changelog","Could not fetch changelog: Server error {}.").format(str(e.code))
+ except URLError as e:
+ msg_text = QCoreApplication.translate("changelog","Could not fetch update: {}.").format(str(e.reason))
+ self.helper.gotChangelog.emit(msg_text)
+
+class Helper(QObject):
+ changelogFetched = Signal(str)
+ gotChangelog = Signal(str)
+
+ def __init__(self, cwd: str, tmpfile: str):
+ QObject.__init__(self)
+ self.cwd = cwd
+ self.tmpfile = tmpfile
+ self.gotChangelog.connect(self.fetched)
+
+ def fetched(self, changelog: str):
+ self.changelogFetched.emit(changelog)
+
+ @Slot(str, str)
+ def write(self, filename, filedata):
+ chdir(self.cwd)
+ if path.exists(path.dirname(path.realpath(filename))):
+ if filename.split(".")[-1] == "lpf":
+ # Add header to file
+ filedata = "LPFv1" + filedata
+ f = open(path.realpath(filename), 'w', -1, 'utf8')
+ f.write(filedata)
+ f.close()
+ chdir(path.dirname(path.realpath(__file__)))
+
+ @Slot(str, result=str)
+ def load(self, filename):
+ chdir(self.cwd)
+ data = '{}'
+ if path.exists(path.realpath(filename)):
+ f = open(path.realpath(filename), 'r', -1, 'utf8')
+ data = f.read()
+ f.close()
+ try:
+ if data[:5] == "LPFv1":
+ # V1 version of the file
+ data = data[5:]
+ elif data[0] == "{" and "type" in loads(data) and loads(data)["type"] == "logplotv1":
+ pass
+ else:
+ raise Exception("Invalid LogarithmPlotter file.")
+ except Exception as e: # If file can't be loaded
+ QMessageBox.warning(None, 'LogarithmPlotter', QCoreApplication.translate('main','Could not open file "{}":\n{}').format(filename, e), QMessageBox.Ok) # Cannot parse file
+ else:
+ QMessageBox.warning(None, 'LogarithmPlotter', QCoreApplication.translate('main','Could not open file: "{}"\nFile does not exist.').format(filename), QMessageBox.Ok) # Cannot parse file
+ chdir(path.dirname(path.realpath(__file__)))
+ return data
+
+ @Slot(result=str)
+ def gettmpfile(self):
+ return self.tmpfile
+
+ @Slot()
+ def copyImageToClipboard(self):
+ clipboard = QApplication.clipboard()
+ clipboard.setImage(QImage(self.tmpfile))
+
+ @Slot(result=str)
+ def getVersion(self):
+ return __VERSION__
+
+ @Slot(str, result=str)
+ def getSetting(self, namespace):
+ return config.getSetting(namespace)
+
+ @Slot(str, result=bool)
+ def getSettingBool(self, namespace):
+ return config.getSetting(namespace)
+
+ @Slot(str, str)
+ def setSetting(self, namespace, value):
+ return config.setSetting(namespace, value)
+
+ @Slot(str, bool)
+ def setSettingBool(self, namespace, value):
+ return config.setSetting(namespace, value)
+
+ @Slot(str)
+ def setLanguage(self, new_lang):
+ config.setSetting("language", new_lang)
+
+ @Slot(result=str)
+ def getDebugInfos(self):
+ """
+ Returns the version info about Qt, PySide2 & Python
+ """
+ return QCoreApplication.translate('main',"Built with PySide2 (Qt) v{} and python v{}").format(PySide2_version, sys_version.split("\n")[0])
+
+ @Slot(str)
+ def openUrl(self, url):
+ openWeb(url)
+
+ @Slot()
+ def fetchChangelog(self):
+ runnable = ChangelogFetcher(self)
+ QThreadPool.globalInstance().start(runnable)
+
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml
index eb2d6c7..cae793b 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml
@@ -48,6 +48,8 @@ ApplicationWindow {
Popup.GreetScreen {}
+ Popup.Changelog {id: changelog}
+
Popup.About {id: about}
Popup.Alert {
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Changelog.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Changelog.qml
new file mode 100644
index 0000000..9ba77ee
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Changelog.qml
@@ -0,0 +1,73 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+
+Popup {
+ id: changelogPopup
+ x: (parent.width-width)/2
+ y: Math.max(20, (parent.height-height)/2)
+ width: changelog.width+40
+ height: Math.min(parent.height-40, 500)
+ modal: true
+ focus: true
+ closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
+
+ property bool changelogNeedsFetching: true
+
+ onAboutToShow: if(changelogNeedsFetching) Helper.fetchChangelog()
+
+ Connections {
+ target: Helper
+ function onChangelogFetched(chl) {
+ changelogNeedsFetching = false;
+ changelog.text = chl
+ }
+ }
+
+ ScrollView {
+ anchors.top: parent.top
+ anchors.topMargin: 10
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.bottom: doneBtn.top
+ anchors.bottomMargin: 10
+ clip: true
+
+ Label {
+ id: changelog
+ color: sysPalette.windowText
+ textFormat: TextEdit.MarkdownText
+
+ text: qsTr("Fetching changelog...")
+ onLinkActivated: Helper.openUrl(link)
+
+ }
+ }
+
+ Button {
+ id: doneBtn
+ text: qsTr("Done")
+ font.pixelSize: 18
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 10
+ anchors.horizontalCenter: parent.horizontalCenter
+ onClicked: changelogPopup.close()
+ }
+}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml
index 016250c..d2eb9c4 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml
@@ -108,13 +108,24 @@ Popup {
}
}
- Button {
- text: qsTr("Done")
- font.pixelSize: 20
+ Row {
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
- onClicked: greetingPopup.close()
+
+ Button {
+ id: changelogBtn
+ text: qsTr("Changelog")
+ font.pixelSize: 18
+ onClicked: changelog.open()
+ }
+
+ Button {
+ id: doneBtn
+ text: qsTr("Done")
+ font.pixelSize: 18
+ onClicked: greetingPopup.close()
+ }
}
Timer {
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/qmldir b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/qmldir
index 3e5a408..a37ae7c 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/qmldir
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/qmldir
@@ -4,5 +4,5 @@ About 1.0 About.qml
Alert 1.0 Alert.qml
FileDialog 1.0 FileDialog.qml
GreetScreen 1.0 GreetScreen.qml
-
+Changelog 1.0 Changelog.qml