Bugfix for new settings management

Do not create new internal_id, if the setting already have one.
Do not create new entries, if the setting is the last one in the array.
This commit is contained in:
2023-01-10 15:17:29 +01:00
parent 8790e508ad
commit 5488e7cc81
3 changed files with 35 additions and 29 deletions

View File

@@ -134,6 +134,7 @@ class RevPiSettings:
self._settings.beginWriteArray("connections") self._settings.beginWriteArray("connections")
self._settings.setArrayIndex(count_settings) self._settings.setArrayIndex(count_settings)
if not self.internal_id:
self.internal_id = uuid4().hex self.internal_id = uuid4().hex
if not self.internal_id: if not self.internal_id:
@@ -141,7 +142,7 @@ class RevPiSettings:
else: else:
# Always search setting in array, because connection manager could reorganize array indexes # Always search setting in array, because connection manager could reorganize array indexes
index = -1 new_setting = True
for index in range(count_settings): for index in range(count_settings):
self._settings.setArrayIndex(index) self._settings.setArrayIndex(index)
@@ -150,12 +151,14 @@ class RevPiSettings:
if self._settings.value("address") == self.address: if self._settings.value("address") == self.address:
# Set missing internal_id # Set missing internal_id
self.internal_id = uuid4().hex self.internal_id = uuid4().hex
new_setting = False
break break
else: else:
if self._settings.value("internal_id") == self.internal_id: if self._settings.value("internal_id") == self.internal_id:
new_setting = False
break break
if index == count_settings - 1: if new_setting:
# On this point, we iterate all settings and found none, so create new one # On this point, we iterate all settings and found none, so create new one
create_new_array_member() create_new_array_member()
@@ -665,17 +668,21 @@ def all_revpi_settings() -> [RevPiSettings]:
def import_old_settings(): def import_old_settings():
if not settings.value("revpicommander/imported_settings", False, type=bool): """Try to import saved connections from old storage to new setting object."""
if settings.value("revpicommander/imported_settings", False, type=bool):
return
settings.setValue("revpicommander/imported_settings", True) settings.setValue("revpicommander/imported_settings", True)
old_settings = QtCore.QSettings("revpipyplc", "revpipyload") old_settings = QtCore.QSettings("revpipyplc", "revpipyload")
count_settings = old_settings.beginReadArray("connections") count_settings = old_settings.beginReadArray("connections")
old_settings.endArray() old_settings.endArray()
lst_revpi_settings = [RevPiSettings(i, settings_storage=old_settings) for i in range(count_settings)] for i in range(count_settings):
for revpi_setting in lst_revpi_settings: try:
revpi_setting = RevPiSettings(i, settings_storage=old_settings)
revpi_setting._settings = settings revpi_setting._settings = settings
revpi_setting.save_settings() revpi_setting.save_settings()
except Exception as e:
pi.logger.warning("Could not import saved connection {0}".format(i))
import_old_settings() import_old_settings()

View File

@@ -101,62 +101,62 @@ Nicht gespeicherte Änderunen gehen verloren</translation>
<context> <context>
<name>ConnectionManager</name> <name>ConnectionManager</name>
<message> <message>
<location filename="../helper.py" line="511"/> <location filename="../helper.py" line="512"/>
<source>SIMULATING</source> <source>SIMULATING</source>
<translation>SIMULATION</translation> <translation>SIMULATION</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="514"/> <location filename="../helper.py" line="515"/>
<source>NOT CONNECTED</source> <source>NOT CONNECTED</source>
<translation>NICHT VERBUNDEN</translation> <translation>NICHT VERBUNDEN</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="531"/> <location filename="../helper.py" line="532"/>
<source>SERVER ERROR</source> <source>SERVER ERROR</source>
<translation>SERVER FEHLER</translation> <translation>SERVER FEHLER</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="556"/> <location filename="../helper.py" line="557"/>
<source>RUNNING</source> <source>RUNNING</source>
<translation>LÄUFT</translation> <translation>LÄUFT</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="558"/> <location filename="../helper.py" line="559"/>
<source>PLC FILE NOT FOUND</source> <source>PLC FILE NOT FOUND</source>
<translation>SPS PROGRAMM NICHT GEFUNDEN</translation> <translation>SPS PROGRAMM NICHT GEFUNDEN</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="560"/> <location filename="../helper.py" line="561"/>
<source>NOT RUNNING (NO STATUS)</source> <source>NOT RUNNING (NO STATUS)</source>
<translation>LÄUFT NICHT (KEIN STATUS)</translation> <translation>LÄUFT NICHT (KEIN STATUS)</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="562"/> <location filename="../helper.py" line="563"/>
<source>PROGRAM KILLED</source> <source>PROGRAM KILLED</source>
<translation>PROGRAMM GETÖTET</translation> <translation>PROGRAMM GETÖTET</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="564"/> <location filename="../helper.py" line="565"/>
<source>PROGRAM TERMED</source> <source>PROGRAM TERMED</source>
<translation>PROGRAMM BEENDET</translation> <translation>PROGRAMM BEENDET</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="566"/> <location filename="../helper.py" line="567"/>
<source>NOT RUNNING</source> <source>NOT RUNNING</source>
<translation>LÄUFT NICHT</translation> <translation>LÄUFT NICHT</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="568"/> <location filename="../helper.py" line="569"/>
<source>FINISHED WITH CODE {0}</source> <source>FINISHED WITH CODE {0}</source>
<translation>BEENDET MIT CODE {0}</translation> <translation>BEENDET MIT CODE {0}</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="383"/> <location filename="../helper.py" line="384"/>
<source>Error</source> <source>Error</source>
<translation>Fehler</translation> <translation>Fehler</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="351"/> <location filename="../helper.py" line="352"/>
<source>The combination of username and password was rejected from the SSH server. <source>The combination of username and password was rejected from the SSH server.
Try again.</source> Try again.</source>
@@ -165,7 +165,7 @@ Try again.</source>
Bitte erneut versuchen.</translation> Bitte erneut versuchen.</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="360"/> <location filename="../helper.py" line="361"/>
<source>Could not establish a SSH connection to server: <source>Could not establish a SSH connection to server:
{0}</source> {0}</source>
@@ -174,7 +174,7 @@ Bitte erneut versuchen.</translation>
{0}</translation> {0}</translation>
</message> </message>
<message> <message>
<location filename="../helper.py" line="383"/> <location filename="../helper.py" line="384"/>
<source>Can not connect to RevPi XML-RPC Service! <source>Can not connect to RevPi XML-RPC Service!
This could have the following reasons: The RevPi is not online, the XML-RPC service is not running / bind to localhost or the ACL permission is not set for your IP!!! This could have the following reasons: The RevPi is not online, the XML-RPC service is not running / bind to localhost or the ACL permission is not set for your IP!!!
@@ -665,15 +665,15 @@ Ungesicherte Änderungen gehen verloren.</translation>
<message> <message>
<location filename="../revpiplclist.py" line="28"/> <location filename="../revpiplclist.py" line="28"/>
<source>New connection</source> <source>New connection</source>
<translation>Neue Verbindung</translation> <translation type="obsolete">Neue Verbindung</translation>
</message> </message>
<message> <message>
<location filename="../revpiplclist.py" line="103"/> <location filename="../revpiplclist.py" line="102"/>
<source>Question</source> <source>Question</source>
<translation>Frage</translation> <translation>Frage</translation>
</message> </message>
<message> <message>
<location filename="../revpiplclist.py" line="103"/> <location filename="../revpiplclist.py" line="102"/>
<source>Do you really want to quit? <source>Do you really want to quit?
Unsaved changes will be lost.</source> Unsaved changes will be lost.</source>
<translation>Soll das Fenster wirklich geschlossen werden? <translation>Soll das Fenster wirklich geschlossen werden?

View File

@@ -25,7 +25,6 @@ class RevPiPlcList(QtWidgets.QDialog, Ui_diag_connections):
def __init__(self, parent=None): def __init__(self, parent=None):
super(RevPiPlcList, self).__init__(parent) super(RevPiPlcList, self).__init__(parent)
self.setupUi(self) self.setupUi(self)
self.__default_name = self.tr("New connection")
self.__default_port = 55123 self.__default_port = 55123
self.__current_item = QtWidgets.QTreeWidgetItem() # type: QtWidgets.QTreeWidgetItem self.__current_item = QtWidgets.QTreeWidgetItem() # type: QtWidgets.QTreeWidgetItem