| 1371 | |
| 1372 | |
| 1373 | class SyncplayUserlist(object): |
| 1374 | def __init__(self, ui, client): |
| 1375 | self.currentUser = SyncplayUser() |
| 1376 | self._users = {} |
| 1377 | self.ui = ui |
| 1378 | self._client = client |
| 1379 | self._roomUsersChanged = True |
| 1380 | |
| 1381 | def isReadinessSupported(self, requiresOtherUsers=True): |
| 1382 | if not utils.meetsMinVersion(self._client.serverVersion, constants.USER_READY_MIN_VERSION): |
| 1383 | return False |
| 1384 | elif self.onlyUserInRoomWhoSupportsReadiness() and requiresOtherUsers: |
| 1385 | return False |
| 1386 | else: |
| 1387 | return self._client.serverFeatures["readiness"] |
| 1388 | |
| 1389 | def isRoomSame(self, room): |
| 1390 | if room and self.currentUser.room and self.currentUser.room == room: |
| 1391 | return True |
| 1392 | else: |
| 1393 | return False |
| 1394 | |
| 1395 | def __showUserChangeMessage(self, username, room, file_, oldRoom=None): |
| 1396 | if room: |
| 1397 | if self.isRoomSame(room) or self.isRoomSame(oldRoom): |
| 1398 | showOnOSD = constants.SHOW_OSD_WARNINGS |
| 1399 | else: |
| 1400 | showOnOSD = constants.SHOW_DIFFERENT_ROOM_OSD |
| 1401 | if constants.SHOW_NONCONTROLLER_OSD == False and self.canControl(username) == False: |
| 1402 | showOnOSD = False |
| 1403 | hideFromOSD = not showOnOSD |
| 1404 | if not file_: |
| 1405 | message = getMessage("room-join-notification").format(username, room) |
| 1406 | self.ui.showMessage(message, hideFromOSD) |
| 1407 | else: |
| 1408 | duration = utils.formatTime(file_['duration']) |
| 1409 | message = getMessage("playing-notification").format(username, file_['name'], duration) |
| 1410 | if self.currentUser.room != room or self.currentUser.username == username: |
| 1411 | message += getMessage("playing-notification/room-addendum").format(room) |
| 1412 | self.ui.showMessage(message, hideFromOSD) |
| 1413 | if self.currentUser.file and not self.currentUser.isFileSame(file_) and self.currentUser.room == room: |
| 1414 | fileDifferences = self.getFileDifferencesForUser(self.currentUser.file, file_) |
| 1415 | if fileDifferences is not None: |
| 1416 | message = getMessage("file-differences-notification").format(fileDifferences) |
| 1417 | self.ui.showMessage(message, True) |
| 1418 | |
| 1419 | def getFileDifferencesForUser(self, currentUserFile, otherUserFile): |
| 1420 | if not currentUserFile or not otherUserFile: |
| 1421 | return None |
| 1422 | differences = [] |
| 1423 | differentName = not utils.sameFilename(currentUserFile['name'], otherUserFile['name']) |
| 1424 | differentSize = not utils.sameFilesize(currentUserFile['size'], otherUserFile['size']) |
| 1425 | differentDuration = not utils.sameFileduration(currentUserFile['duration'], otherUserFile['duration']) |
| 1426 | if differentName: differences.append(getMessage("file-difference-filename")) |
| 1427 | if differentSize: differences.append(getMessage("file-difference-filesize")) |
| 1428 | if differentDuration: differences.append(getMessage("file-difference-duration")) |
| 1429 | return ", ".join(differences) |
| 1430 | |