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

View File

@@ -101,62 +101,62 @@ Nicht gespeicherte Änderunen gehen verloren</translation>
<context>
<name>ConnectionManager</name>
<message>
<location filename="../helper.py" line="511"/>
<location filename="../helper.py" line="512"/>
<source>SIMULATING</source>
<translation>SIMULATION</translation>
</message>
<message>
<location filename="../helper.py" line="514"/>
<location filename="../helper.py" line="515"/>
<source>NOT CONNECTED</source>
<translation>NICHT VERBUNDEN</translation>
</message>
<message>
<location filename="../helper.py" line="531"/>
<location filename="../helper.py" line="532"/>
<source>SERVER ERROR</source>
<translation>SERVER FEHLER</translation>
</message>
<message>
<location filename="../helper.py" line="556"/>
<location filename="../helper.py" line="557"/>
<source>RUNNING</source>
<translation>LÄUFT</translation>
</message>
<message>
<location filename="../helper.py" line="558"/>
<location filename="../helper.py" line="559"/>
<source>PLC FILE NOT FOUND</source>
<translation>SPS PROGRAMM NICHT GEFUNDEN</translation>
</message>
<message>
<location filename="../helper.py" line="560"/>
<location filename="../helper.py" line="561"/>
<source>NOT RUNNING (NO STATUS)</source>
<translation>LÄUFT NICHT (KEIN STATUS)</translation>
</message>
<message>
<location filename="../helper.py" line="562"/>
<location filename="../helper.py" line="563"/>
<source>PROGRAM KILLED</source>
<translation>PROGRAMM GETÖTET</translation>
</message>
<message>
<location filename="../helper.py" line="564"/>
<location filename="../helper.py" line="565"/>
<source>PROGRAM TERMED</source>
<translation>PROGRAMM BEENDET</translation>
</message>
<message>
<location filename="../helper.py" line="566"/>
<location filename="../helper.py" line="567"/>
<source>NOT RUNNING</source>
<translation>LÄUFT NICHT</translation>
</message>
<message>
<location filename="../helper.py" line="568"/>
<location filename="../helper.py" line="569"/>
<source>FINISHED WITH CODE {0}</source>
<translation>BEENDET MIT CODE {0}</translation>
</message>
<message>
<location filename="../helper.py" line="383"/>
<location filename="../helper.py" line="384"/>
<source>Error</source>
<translation>Fehler</translation>
</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.
Try again.</source>
@@ -165,7 +165,7 @@ Try again.</source>
Bitte erneut versuchen.</translation>
</message>
<message>
<location filename="../helper.py" line="360"/>
<location filename="../helper.py" line="361"/>
<source>Could not establish a SSH connection to server:
{0}</source>
@@ -174,7 +174,7 @@ Bitte erneut versuchen.</translation>
{0}</translation>
</message>
<message>
<location filename="../helper.py" line="383"/>
<location filename="../helper.py" line="384"/>
<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!!!
@@ -665,15 +665,15 @@ Ungesicherte Änderungen gehen verloren.</translation>
<message>
<location filename="../revpiplclist.py" line="28"/>
<source>New connection</source>
<translation>Neue Verbindung</translation>
<translation type="obsolete">Neue Verbindung</translation>
</message>
<message>
<location filename="../revpiplclist.py" line="103"/>
<location filename="../revpiplclist.py" line="102"/>
<source>Question</source>
<translation>Frage</translation>
</message>
<message>
<location filename="../revpiplclist.py" line="103"/>
<location filename="../revpiplclist.py" line="102"/>
<source>Do you really want to quit?
Unsaved changes will be lost.</source>
<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):
super(RevPiPlcList, self).__init__(parent)
self.setupUi(self)
self.__default_name = self.tr("New connection")
self.__default_port = 55123
self.__current_item = QtWidgets.QTreeWidgetItem() # type: QtWidgets.QTreeWidgetItem