Skip to content

Commit df635a8

Browse files
committed
Improve the code
1 parent 3802582 commit df635a8

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

syncplay/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ def userInitiatedMarkWatched(self, fileSourcePath):
556556
watchedDirectoryFilepath = os.path.join(watchedDirectory, filename)
557557
watchedDirectoryName = os.path.basename(os.path.dirname(watchedDirectoryFilepath))
558558
if os.path.isfile(watchedDirectoryFilepath):
559-
self.ui.showErrorMessage("A file with the same name already exists in '{}' subfolder.".format(watchedDirectoryName)) # TODO: Move to Language
559+
self.ui.showErrorMessage(getMessage("cannot-move-file-due-to-name-conflict-error").format(watchedDirectoryName)) # TODO: Move to Language
560560
return
561561
utils.moveFile(fileSourcePath, watchedDirectoryFilepath)
562562
self.fileSwitch.updateInfo()
563-
self.ui.showMessage("Moved file '{}' to '\{}\\'".format(fileSourcePath, watchedDirectoryName))
563+
self.ui.showMessage(getMessage("moved-file-to-subfolder-notification").format(fileSourcePath, watchedDirectoryName))
564564
except Exception as e:
565565
self.ui.showErrorMessage("Could not mark as watched: {}".format(e)) # TODO: Move to language
566566

@@ -579,7 +579,7 @@ def userInitiatedMarkUnwatched(self, fileSourcePath):
579579
return
580580
utils.moveFile(fileSourcePath, unwatchedFilePath)
581581
self.fileSwitch.updateInfo()
582-
self.ui.showMessage("Moved file '{}' to '\{}\\'".format(fileSourcePath, unwatchedDirectoryPathName)) # TODO: Move to Language
582+
self.ui.showMessage(getMessage("moved-file-to-subfolder-notification").format(fileSourcePath, unwatchedDirectoryPathName))
583583
except Exception as e:
584584
self.ui.showErrorMessage("Could not mark as unwatched: {}".format(e)) # TODO: Move to Language
585585

@@ -610,7 +610,7 @@ def _tryMovePendingWatchedFiles(self):
610610
utils.moveFile(pendingWatchedMove, destFilepath)
611611
self.fileSwitch.updateInfo()
612612
try:
613-
self.ui.showMessage("Moved '{}' to '{}' sub-folder".format(pendingWatchedMove, constants.WATCHED_SUBFOLDER))
613+
self.ui.showMessage(getMessage("moved-file-to-subfolder-notification").format(pendingWatchedMove, constants.WATCHED_SUBFOLDER))
614614
self._pendingWatchedMoves.remove(pendingWatchedMove)
615615
except Exception:
616616
pass

syncplay/ui/gui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from syncplay.utils import resourcespath
1919
from syncplay.utils import isLinux, isWindows, isMacOS
2020
from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize, isURL
21-
from syncplay.utils import isWatchedFile, getWatchedSubfolder, getCorrectedDirectoryForFile, getCorrectedPathForFile, canMarkAsUnwatched
21+
from syncplay.utils import isWatchedFile, getCorrectedPathForFile, canMarkAsWatched
2222
from syncplay.vendor import Qt
2323
from syncplay.vendor.Qt import QtCore, QtWidgets, QtGui, __binding__, __binding_version__, __qt_version__, IsPySide, IsPySide2, IsPySide6
2424
from syncplay.vendor.Qt.QtCore import Qt, QSettings, QSize, QPoint, QUrl, QLine, QDateTime
@@ -754,10 +754,10 @@ def addSeenUnseenItems(pathFound, menu):
754754
filename = os.path.basename(pathFound)
755755
if len(constants.WATCHED_SUBFOLDER) > 0:
756756
pathFound = getCorrectedPathForFile(pathFound)
757-
if canMarkAsUnwatched(pathFound):
758-
menu.addAction(QtGui.QPixmap(resourcespath + "yes_eye.png"), getMessage("mark-as-watched-menu-label"), lambda p=pathFound: self._markFileWatchedViaContext(p)) # TODO: Move to language
759-
elif isWatchedFile(pathFound):
757+
if isWatchedFile(pathFound):
760758
menu.addAction(QtGui.QPixmap(resourcespath + "no_eye.png"), getMessage("mark-as-unwatched-menu-label"), lambda p=pathFound: self._markFileUnwatchedViaContext(p)) # TODO: Move to language
759+
elif canMarkAsWatched(pathFound):
760+
menu.addAction(QtGui.QPixmap(resourcespath + "yes_eye.png"), getMessage("mark-as-watched-menu-label"), lambda p=pathFound: self._markFileWatchedViaContext(p)) # TODO: Move to language
761761

762762
indexes = self.playlist.selectedIndexes()
763763
if len(indexes) > 0:

syncplay/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,19 @@ def getListOfPublicServers():
506506
raise IOError(getMessage("failed-to-load-server-list-error"))
507507

508508
def isWatchedFile(filePath):
509+
if len(constants.WATCHED_SUBFOLDER) == 0:
510+
return False
509511
directoryPath = getCorrectedDirectoryForFile(filePath)
510512
return isWatchedSubfolder(directoryPath) and os.path.exists(filePath)
511513

512-
def canMarkAsUnwatched(filePath):
514+
def canMarkAsWatched(filePath):
515+
if len(constants.WATCHED_SUBFOLDER) == 0:
516+
return False
513517
directory = getCorrectedDirectoryForFile(filePath)
514518
if isWatchedSubfolder(directory):
515519
return False
516520
watchedDirectory = getWatchedSubfolder(directory)
517-
return len(constants.WATCHED_SUBFOLDER) > 0 and ((watchedDirectory and os.path.isdir(watchedDirectory)) or constants.WATCHED_AUTOCREATESUBFOLDERS)
521+
return bool((watchedDirectory and os.path.isdir(watchedDirectory)) or constants.WATCHED_AUTOCREATESUBFOLDERS)
518522

519523
def getUnwatchedParentfolder(watchedDirectoryPath):
520524
if not watchedDirectoryPath:

0 commit comments

Comments
 (0)