mirror of
https://github.com/fergalmoran/picard.git
synced 2026-01-07 17:14:55 +00:00
Merge CD drive detection for Linux
This commit is contained in:
@@ -22,9 +22,10 @@ import sys
|
||||
from PyQt4 import QtGui
|
||||
from picard.config import TextOption
|
||||
from picard.ui.options import OptionsPage, register_options_page
|
||||
from picard.util.cdrom import get_cdrom_drives
|
||||
if sys.platform == "win32":
|
||||
from picard.ui.ui_options_cdlookup_win32 import Ui_CDLookupOptionsPage
|
||||
from picard.util.cdrom import get_cdrom_drives, AUTO_DETECT_DRIVES
|
||||
|
||||
if AUTO_DETECT_DRIVES:
|
||||
from picard.ui.ui_options_cdlookup_select import Ui_CDLookupOptionsPage
|
||||
else:
|
||||
from picard.ui.ui_options_cdlookup import Ui_CDLookupOptionsPage
|
||||
|
||||
@@ -45,12 +46,12 @@ class CDLookupOptionsPage(OptionsPage):
|
||||
super(CDLookupOptionsPage, self).__init__(parent)
|
||||
self.ui = Ui_CDLookupOptionsPage()
|
||||
self.ui.setupUi(self)
|
||||
if sys.platform == "win32":
|
||||
if AUTO_DETECT_DRIVES:
|
||||
self.drives = get_cdrom_drives()
|
||||
self.ui.cd_lookup_device.addItems(self.drives)
|
||||
|
||||
def load(self):
|
||||
if sys.platform == "win32":
|
||||
if AUTO_DETECT_DRIVES:
|
||||
try:
|
||||
self.ui.cd_lookup_device.setCurrentIndex(self.drives.index(self.config.setting["cd_lookup_device"]))
|
||||
except ValueError:
|
||||
@@ -59,7 +60,7 @@ class CDLookupOptionsPage(OptionsPage):
|
||||
self.ui.cd_lookup_device.setText(self.config.setting["cd_lookup_device"])
|
||||
|
||||
def save(self):
|
||||
if sys.platform == "win32":
|
||||
if AUTO_DETECT_DRIVES:
|
||||
self.config.setting["cd_lookup_device"] = unicode(self.ui.cd_lookup_device.currentText())
|
||||
else:
|
||||
self.config.setting["cd_lookup_device"] = unicode(self.ui.cd_lookup_device.text())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'ui/options_cdlookup_win32.ui'
|
||||
# Form implementation generated from reading ui file 'ui/options_cdlookup_select.ui'
|
||||
#
|
||||
# Created: Sun Jan 13 17:42:14 2008
|
||||
# by: PyQt4 UI code generator 4.3
|
||||
# Created: Mon Dec 1 01:28:45 2008
|
||||
# by: PyQt4 UI code generator 4.4.3
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
@@ -12,40 +12,32 @@ from PyQt4 import QtCore, QtGui
|
||||
class Ui_CDLookupOptionsPage(object):
|
||||
def setupUi(self, CDLookupOptionsPage):
|
||||
CDLookupOptionsPage.setObjectName("CDLookupOptionsPage")
|
||||
CDLookupOptionsPage.resize(QtCore.QSize(QtCore.QRect(0,0,255,155).size()).expandedTo(CDLookupOptionsPage.minimumSizeHint()))
|
||||
|
||||
CDLookupOptionsPage.resize(255, 155)
|
||||
self.vboxlayout = QtGui.QVBoxLayout(CDLookupOptionsPage)
|
||||
self.vboxlayout.setMargin(9)
|
||||
self.vboxlayout.setSpacing(6)
|
||||
self.vboxlayout.setObjectName("vboxlayout")
|
||||
|
||||
self.rename_files = QtGui.QGroupBox(CDLookupOptionsPage)
|
||||
self.rename_files.setObjectName("rename_files")
|
||||
|
||||
self.gridlayout = QtGui.QGridLayout(self.rename_files)
|
||||
self.gridlayout.setMargin(9)
|
||||
self.gridlayout.setSpacing(2)
|
||||
self.gridlayout.setObjectName("gridlayout")
|
||||
|
||||
self.cd_lookup_ = QtGui.QLabel(self.rename_files)
|
||||
self.cd_lookup_.setObjectName("cd_lookup_")
|
||||
self.gridlayout.addWidget(self.cd_lookup_,0,0,1,1)
|
||||
|
||||
self.gridlayout.addWidget(self.cd_lookup_, 0, 0, 1, 1)
|
||||
self.hboxlayout = QtGui.QHBoxLayout()
|
||||
self.hboxlayout.setMargin(0)
|
||||
self.hboxlayout.setSpacing(6)
|
||||
self.hboxlayout.setObjectName("hboxlayout")
|
||||
|
||||
self.cd_lookup_device = QtGui.QComboBox(self.rename_files)
|
||||
self.cd_lookup_device.setObjectName("cd_lookup_device")
|
||||
self.hboxlayout.addWidget(self.cd_lookup_device)
|
||||
|
||||
spacerItem = QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum)
|
||||
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||
self.hboxlayout.addItem(spacerItem)
|
||||
self.gridlayout.addLayout(self.hboxlayout,1,0,1,1)
|
||||
self.gridlayout.addLayout(self.hboxlayout, 1, 0, 1, 1)
|
||||
self.vboxlayout.addWidget(self.rename_files)
|
||||
|
||||
spacerItem1 = QtGui.QSpacerItem(161,81,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
|
||||
spacerItem1 = QtGui.QSpacerItem(161, 81, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
|
||||
self.vboxlayout.addItem(spacerItem1)
|
||||
self.cd_lookup_.setBuddy(self.cd_lookup_device)
|
||||
|
||||
@@ -19,7 +19,12 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
import sys
|
||||
from PyQt4.QtCore import QFile
|
||||
|
||||
LINUX_CDROM_INFO = '/proc/sys/dev/cdrom/info'
|
||||
|
||||
if sys.platform == 'win32':
|
||||
AUTO_DETECT_DRIVES = True
|
||||
from ctypes import windll
|
||||
GetLogicalDrives = windll.kernel32.GetLogicalDrives
|
||||
GetDriveType = windll.kernel32.GetDriveTypeA
|
||||
@@ -34,7 +39,41 @@ if sys.platform == 'win32':
|
||||
if GetDriveType(drive) == DRIVE_CDROM:
|
||||
drives.append(drive)
|
||||
return drives
|
||||
|
||||
elif sys.platform == 'linux2' and QFile.exists(LINUX_CDROM_INFO):
|
||||
AUTO_DETECT_DRIVES = True
|
||||
from PyQt4.QtCore import QIODevice, QString
|
||||
|
||||
# Read info from /proc/sys/dev/cdrom/info
|
||||
def get_cdrom_drives():
|
||||
drives = []
|
||||
cdinfo = QFile(LINUX_CDROM_INFO)
|
||||
if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
|
||||
drive_names = []
|
||||
drive_audio_caps = []
|
||||
line = cdinfo.readLine()
|
||||
while not line.isEmpty():
|
||||
if line.indexOf(':') != -1:
|
||||
key, values = line.split(':')
|
||||
if key == 'drive name':
|
||||
drive_names = QString(values).trimmed().split(' ', QString.SkipEmptyParts)
|
||||
elif key == 'Can play audio':
|
||||
drive_audio_caps = [v == '1' for v in
|
||||
QString(values).trimmed().split(' ', QString.SkipEmptyParts)]
|
||||
line = cdinfo.readLine()
|
||||
# Show only drives that are capable of playing audio
|
||||
for drive in drive_names:
|
||||
if drive_audio_caps[drive_names.indexOf(drive)]:
|
||||
device = u'/dev/%s' % drive
|
||||
symlink_target = QFile.symLinkTarget(device)
|
||||
if symlink_target != '':
|
||||
device = symlink_target
|
||||
drives.append(device)
|
||||
return sorted(drives)
|
||||
|
||||
else:
|
||||
AUTO_DETECT_DRIVES = False
|
||||
|
||||
def get_cdrom_drives():
|
||||
from picard.tagger import Tagger
|
||||
tagger = Tagger.instance()
|
||||
|
||||
Reference in New Issue
Block a user