diff --git a/syncplay/constants.py b/syncplay/constants.py index cba53af..507e24e 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -224,4 +224,10 @@ SYNCPLAY_PUBLIC_SERVER_LIST_URL = u"http://syncplay.pl/listpublicservers?{}" # P DEFAULT_TRUSTED_DOMAINS = [u"youtube.com",u"youtu.be"] TRUSTABLE_WEB_PROTOCOLS = [u"http://www.",u"https://www.",u"http://",u"https://"] -PRIVATE_FILE_FIELDS = ["path"] \ No newline at end of file +PRIVATE_FILE_FIELDS = ["path"] + +OS_WINDOWS = "win" +OS_LINUX = "linux" +OS_OSX = "darwin" +OS_BSD = "freebsd" +OS_DRAGONFLY = "dragonfly" \ No newline at end of file diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index 9e5f855..56e6b4e 100644 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -6,6 +6,7 @@ from syncplay.players.basePlayer import BasePlayer from syncplay import constants, utils from syncplay.messages import getMessage import os, sys +from syncplay.utils import isWindows class MplayerPlayer(BasePlayer): speedSupported = True @@ -282,7 +283,7 @@ class MplayerPlayer(BasePlayer): call = [playerPath] if filePath: - if sys.platform.startswith('win') and not utils.isASCII(filePath): + if isWindows() and not utils.isASCII(filePath): self.__playerController.delayedFilePath = filePath filePath = None else: diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index dde4d5b..2a4cd77 100755 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -11,6 +11,7 @@ import asynchat, asyncore import urllib import time from syncplay.messages import getMessage +from syncplay.utils import isBSD, isLinux, isWindows, isOSX class VlcPlayer(BasePlayer): speedSupported = True @@ -20,7 +21,7 @@ class VlcPlayer(BasePlayer): RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX) SLAVE_ARGS = constants.VLC_SLAVE_ARGS - if sys.platform.startswith('darwin'): + if isOSX(): SLAVE_ARGS.extend(constants.VLC_SLAVE_OSX_ARGS) else: SLAVE_ARGS.extend(constants.VLC_SLAVE_NONOSX_ARGS) @@ -146,7 +147,7 @@ class VlcPlayer(BasePlayer): fileURL = fileURL.replace(u'\\', u'/') fileURL = fileURL.encode('utf8') fileURL = urllib.quote_plus(fileURL) - if sys.platform.startswith('win'): + if isWindows(): fileURL = "file:///" + fileURL else: fileURL = "file://" + fileURL @@ -331,13 +332,13 @@ class VlcPlayer(BasePlayer): return False playerController._client.ui.showErrorMessage(getMessage("vlc-interface-not-installed")) return False - if sys.platform.startswith('linux'): + if isLinux(): playerController.vlcIntfPath = "/usr/lib/vlc/lua/intf/" playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/") - elif sys.platform.startswith('darwin'): + elif isOSX(): playerController.vlcIntfPath = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/" playerController.vlcIntfUserPath = os.path.join(os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/") - elif 'bsd' in sys.platform or sys.platform.startswith('dragonfly'): + elif isBSD(): # *BSD ports/pkgs install to /usr/local by default. # This should also work for all the other BSDs, such as OpenBSD or DragonFly. playerController.vlcIntfPath = "/usr/local/lib/vlc/lua/intf/" @@ -349,7 +350,7 @@ class VlcPlayer(BasePlayer): if _usevlcintf(playerController.vlcIntfPath, playerController.vlcIntfUserPath): playerController.SLAVE_ARGS.append('--lua-config=syncplay={{port=\"{}\"}}'.format(str(playerController.vlcport))) else: - if sys.platform.startswith('linux'): + if isLinux(): playerController.vlcDataPath = "/usr/lib/syncplay/resources" else: playerController.vlcDataPath = utils.findWorkingDir() + "\\resources" @@ -387,7 +388,7 @@ class VlcPlayer(BasePlayer): playerController._client.ui.showErrorMessage( getMessage("media-player-error").format(line), True) break - if not sys.platform.startswith('darwin'): + if not isOSX(): self.__process.stderr = None else: vlcoutputthread = threading.Thread(target = self.handle_vlcoutput, args=()) @@ -401,7 +402,7 @@ class VlcPlayer(BasePlayer): self._sendingData = threading.Lock() def _shouldListenForSTDOUT(self): - if sys.platform.startswith('win'): + if isWindows(): return False # Due to VLC3 not using STDOUT/STDERR else: return True diff --git a/syncplay/ui/ConfigurationGetter.py b/syncplay/ui/ConfigurationGetter.py index 79e4f1e..67b515d 100755 --- a/syncplay/ui/ConfigurationGetter.py +++ b/syncplay/ui/ConfigurationGetter.py @@ -6,6 +6,7 @@ import ast from syncplay import constants, utils, version, milestone from syncplay.messages import getMessage, setLanguage, isValidLanguage from syncplay.players.playerFactory import PlayerFactory +from syncplay.utils import isOSX import codecs class InvalidConfigValue(Exception): @@ -411,7 +412,7 @@ class ConfigurationGetter(object): if QCoreApplication.instance() is None: self.app = QtWidgets.QApplication(sys.argv) qt5reactor.install() - if sys.platform.startswith('darwin'): + if isOSX(): import appnope appnope.nope() except ImportError: diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 2cda809..fd09cf4 100755 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -12,6 +12,7 @@ import sys import threading from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage from syncplay import constants +from syncplay.utils import isBSD, isLinux, isWindows, isOSX class GuiConfiguration: def __init__(self, config, error=None, defaultConfig=None): @@ -238,11 +239,11 @@ class ConfigDialog(QtWidgets.QDialog): defaultdirectory = os.environ["ProgramFiles"] elif "PROGRAMW6432" in os.environ: defaultdirectory = os.environ["ProgramW6432"] - elif sys.platform.startswith('linux'): + elif isLinux(): defaultdirectory = "/usr/bin" - elif sys.platform.startswith('darwin'): + elif isOSX(): defaultdirectory = "/Applications/" - elif "bsd" in sys.platform or sys.platform.startswith('dragonfly'): + elif isBSD(): defaultdirectory = "/usr/local/bin" fileName, filtr = QtWidgets.QFileDialog.getOpenFileName(self, @@ -250,7 +251,7 @@ class ConfigDialog(QtWidgets.QDialog): defaultdirectory, browserfilter, "", options) if fileName: - if sys.platform.startswith('darwin') and fileName.endswith('.app'): # see GitHub issue #91 + if isOSX() and fileName.endswith('.app'): # see GitHub issue #91 # Mac OS X application bundles contain a Info.plist in the Contents subdirectory of the .app. # This plist file includes the 'CFBundleExecutable' key, which specifies the name of the # executable. I would have used plistlib here, but since the version of this library in @@ -1109,7 +1110,7 @@ class ConfigDialog(QtWidgets.QDialog): self.QtWidgets = QtWidgets self.QtGui = QtGui self.error = error - if sys.platform.startswith('win'): + if isWindows(): resourcespath = utils.findWorkingDir() + "\\resources\\" else: resourcespath = utils.findWorkingDir() + u"/resources/" diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index de9c823..5c7359d 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -9,12 +9,13 @@ import sys import time import urllib from datetime import datetime +from syncplay.utils import isLinux, isWindows, isOSX import re import os from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize, isURL from functools import wraps from twisted.internet import task -if sys.platform.startswith('darwin') and IsPySide: +if isOSX() and IsPySide: from Foundation import NSURL lastCheckedForUpdates = None @@ -34,7 +35,7 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate): if column == constants.USERLIST_GUI_USERNAME_COLUMN: currentQAbstractItemModel = indexQModelIndex.model() itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_USERNAME_COLUMN, indexQModelIndex.parent()) - if sys.platform.startswith('win'): + if isWindows(): resourcespath = utils.findWorkingDir() + u"\\resources\\" else: resourcespath = utils.findWorkingDir() + u"/resources/" @@ -65,7 +66,7 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate): if isUserRow: optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+constants.USERLIST_GUI_USERNAME_OFFSET) if column == constants.USERLIST_GUI_FILENAME_COLUMN: - if sys.platform.startswith('win'): + if isWindows(): resourcespath = utils.findWorkingDir() + u"\\resources\\" else: resourcespath = utils.findWorkingDir() + u"/resources/" @@ -90,18 +91,18 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate): QtWidgets.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex) class AboutDialog(QtWidgets.QDialog): - if sys.platform.startswith('win'): + if isWindows(): resourcespath = utils.findWorkingDir() + u"\\resources\\" else: resourcespath = utils.findWorkingDir() + u"/resources/" def __init__(self, parent=None): super(AboutDialog, self).__init__(parent) - if sys.platform.startswith('darwin'): + if isOSX(): self.setWindowTitle("") else: self.setWindowTitle(getMessage("about-dialog-title")) - if sys.platform.startswith('win'): + if isWindows(): self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) nameLabel = QtWidgets.QLabel("