Room history (#337)

* Add room history mechanism (Syncplay#336)

* new 'roomhistory' value in configuration
* change gui room input to combobox to display history
* update history upon startup using the configuration room

* Prevent room history from saving empty room name

* Add rooms editing ability
* add rooms dialog
* new button to open rooms dialog
This commit is contained in:
Gabriel Dolberg 2020-09-13 14:49:25 +03:00 committed by GitHub
parent 70382e1a78
commit 86bd299a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 4 deletions

View File

@ -29,6 +29,7 @@ class ConfigurationGetter(object):
"noGui": False,
"noStore": False,
"room": "",
"roomhistory": [],
"password": None,
"playerPath": None,
"perPlayerArguments": None,
@ -149,6 +150,7 @@ class ConfigurationGetter(object):
]
self._serialised = [
"roomhistory",
"perPlayerArguments",
"mediaSearchDirectories",
"trustedDomains",
@ -181,7 +183,7 @@ class ConfigurationGetter(object):
self._iniStructure = {
"server_data": ["host", "port", "password"],
"client_settings": [
"name", "room", "playerPath",
"name", "room", "roomhistory", "playerPath",
"perPlayerArguments", "slowdownThreshold",
"rewindThreshold", "fastforwardThreshold",
"slowOnDesync", "rewindOnDesync",

View File

@ -156,6 +156,28 @@ class ConfigDialog(QtWidgets.QDialog):
def openHelp(self):
self.QtGui.QDesktopServices.openUrl(QUrl("https://syncplay.pl/guide/client/"))
def openRoomsDialog(self):
RoomsDialog = QtWidgets.QDialog()
RoomsDialog.setWindowFlags(Qt.FramelessWindowHint)
RoomsLayout = QtWidgets.QGridLayout()
RoomsTextbox = QtWidgets.QPlainTextEdit()
RoomsTextbox.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
RoomsTextbox.setPlainText(utils.getListAsMultilineString(self.config['roomhistory']))
RoomsLayout.addWidget(RoomsTextbox, 0, 0, 1, 1)
RoomsButtonBox = QtWidgets.QDialogButtonBox()
RoomsButtonBox.setOrientation(Qt.Horizontal)
RoomsButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
RoomsButtonBox.accepted.connect(RoomsDialog.accept)
RoomsButtonBox.rejected.connect(RoomsDialog.reject)
RoomsLayout.addWidget(RoomsButtonBox, 1, 0, 1, 1)
RoomsDialog.setLayout(RoomsLayout)
RoomsDialog.setModal(True)
RoomsDialog.show()
result = RoomsDialog.exec_()
if result == QtWidgets.QDialog.Accepted:
newRooms = utils.convertMultilineStringToList(RoomsTextbox.toPlainText())
self.relistRoomHistory(newRooms)
def safenormcaseandpath(self, path):
if utils.isURL(path):
return path
@ -380,6 +402,27 @@ class ConfigDialog(QtWidgets.QDialog):
settings.setValue("publicServers", servers)
self.hostCombobox.setEditText(currentServer)
def fillRoomsCombobox(self):
self.roomsCombobox.clear()
for roomHistoryValue in self.config['roomhistory']:
self.roomsCombobox.addItem(roomHistoryValue)
def relistRoomHistory(self, newRooms):
filteredNewRooms = [room for room in newRooms if room and not room.isspace()]
self.config['roomhistory'] = filteredNewRooms
self.fillRoomsCombobox()
def addRoomToHistory(self, newRoom=None):
if newRoom is None:
newRoom = self.roomsCombobox.currentText()
if not newRoom:
return
roomHistory = self.config['roomhistory']
if newRoom in roomHistory:
roomHistory.remove(newRoom)
roomHistory.insert(0, newRoom)
self.config['roomhistory'] = roomHistory
def showErrorMessage(self, errorMessage):
QtWidgets.QMessageBox.warning(self, "Syncplay", errorMessage)
@ -447,6 +490,7 @@ class ConfigDialog(QtWidgets.QDialog):
else:
self.config['file'] = str(self.mediapathTextbox.text())
self.config['publicServers'] = self.publicServerAddresses
self.config['room'] = self.roomsCombobox.currentText()
self.pressedclosebutton = False
self.close()
@ -599,11 +643,17 @@ class ConfigDialog(QtWidgets.QDialog):
self.usernameTextbox.setObjectName("name")
self.serverpassLabel = QLabel(getMessage("password-label"), self)
self.defaultroomTextbox = QLineEdit(self)
self.roomsCombobox = QtWidgets.QComboBox(self)
self.roomsCombobox.setEditable(True)
self.addRoomToHistory(config['room'])
self.fillRoomsCombobox()
self.usernameLabel = QLabel(getMessage("name-label"), self)
self.serverpassTextbox = QLineEdit(self)
self.serverpassTextbox.setText(self.storedPassword)
self.defaultroomLabel = QLabel(getMessage("room-label"), self)
self.editRoomsButton = QtWidgets.QToolButton()
self.editRoomsButton.setIcon(QtGui.QIcon(resourcespath + 'eye.png'))
self.editRoomsButton.released.connect(self.openRoomsDialog)
self.hostLabel.setObjectName("host")
self.hostCombobox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "host")
@ -614,7 +664,7 @@ class ConfigDialog(QtWidgets.QDialog):
self.hostCombobox.editTextChanged.connect(self.updatePasswordVisibilty)
self.hostCombobox.currentIndexChanged.connect(self.updatePasswordVisibilty)
self.defaultroomLabel.setObjectName("room")
self.defaultroomTextbox.setObjectName("room")
self.roomsCombobox.setObjectName("room")
self.connectionSettingsLayout = QtWidgets.QGridLayout()
self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0)
@ -624,7 +674,8 @@ class ConfigDialog(QtWidgets.QDialog):
self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0)
self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1)
self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0)
self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1)
self.connectionSettingsLayout.addWidget(self.editRoomsButton, 3, 0, Qt.AlignRight)
self.connectionSettingsLayout.addWidget(self.roomsCombobox, 3, 1)
self.connectionSettingsLayout.setSpacing(10)
self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout)
if isMacOS():