Ejemplo n.º 1
0
	def slot_register_id3editor_in_context_menu(self, val):
		if val and not utils.check_context_menu_status():
			log.debug("Registering Context Menu Object...")
			try:
				utils.register_with_context_menu()
			except WindowsError, e:
				if e.winerror == 5: # Access is denied
					log.debug("Access is denied. Setting id3editor_in_context_menu to False.")
					QtGui.QMessageBox.critical(self, tr("Error"), tr("Access is denied. Please run this application as an administrator and try again."), QtGui.QMessageBox.Ok)
					self.id3editor_in_context_menu.setCheckState(False)
					self.id3editor_in_context_menu.setTristate(False)
				else:
					raise
			else:
				if sys.getwindowsversion().major == 6: # If Windows Vista/7/8
					QtGui.QMessageBox.information(self, tr("Information"), tr("You need to restart your computer for the changes to take effect."), QtGui.QMessageBox.Ok)
Ejemplo n.º 2
0
 def slot_register_id3editor_in_context_menu(self, val):
     if val and not utils.check_context_menu_status():
         log.debug("Registering Context Menu Object...")
         try:
             utils.register_with_context_menu()
         except WindowsError, e:
             if e.winerror == 5:  # Access is denied
                 log.debug(
                     "Access is denied. Setting id3editor_in_context_menu to False."
                 )
                 QtGui.QMessageBox.critical(
                     self, tr("Error"),
                     tr("Access is denied. Please run this application as an administrator and try again."
                        ), QtGui.QMessageBox.Ok)
                 self.id3editor_in_context_menu.setCheckState(False)
                 self.id3editor_in_context_menu.setTristate(False)
             else:
                 raise
         else:
             if sys.getwindowsversion().major == 6:  # If Windows Vista/7/8
                 QtGui.QMessageBox.information(
                     self, tr("Information"),
                     tr("You need to restart your computer for the changes to take effect."
                        ), QtGui.QMessageBox.Ok)
Ejemplo n.º 3
0
class MainWin(QtGui.QDialog):
    def __init__(self, parent=None):
        super(MainWin, self).__init__(parent)

        self.setWindowTitle(tr("Preferences"))
        self.resize(400, 60)
        self.setWindowIcon(QtGui.QIcon(os.path.join('pics', 'settings.png')))
        self.init_widgets()

    def init_widgets(self):
        self.dl_dir = QtGui.QLineEdit(config.dl_dir)
        self.folder_button = QtGui.QPushButton("...")
        self.folder_button.clicked.connect(self.slot_choose_dl_dir)
        self.temp_dir = QtGui.QLineEdit(config.temp_dir)
        self.temp_folder_button = QtGui.QPushButton("...")
        self.temp_folder_button.clicked.connect(self.slot_choose_temp_dir)
        self.post_download_action = QtGui.QComboBox()
        self.post_download_action.addItems(
            map(tr, config.post_download_action_dict.values()))
        self.post_download_action.setCurrentIndex(
            config.post_download_action_dict.keys().index(
                config.post_download_action))
        self.post_download_action.currentIndexChanged.connect(
            self.slot_post_download_action_changed)

        # These labels and lineedits are set by self.slot_changed_checkbox
        self.post_download_custom_label = QtGui.QLabel()
        self.post_download_custom_label2 = QtGui.QLabel()
        self.post_download_custom_cmd = QtGui.QLineEdit()
        self.post_download_custom_wait_checkbox = QtGui.QCheckBox(
            tr("Wait for exit"))
        self.post_download_custom_wait_checkbox.setCheckState(
            config.post_download_custom_wait_checkbox)
        self.post_download_custom_wait_checkbox.setTristate(False)

        self.table_doubleClick_action = QtGui.QComboBox()
        self.table_doubleClick_action.addItems(
            map(tr, config.table_doubleClick_action_dict.values()))
        self.table_doubleClick_action.setCurrentIndex(
            config.table_doubleClick_action_dict.keys().index(
                config.table_doubleClick_action))

        self.auto_update = QtGui.QCheckBox(
            tr("Update automatically when a new version is available"))
        self.auto_update.setCheckState(config.auto_update)
        self.auto_update.setTristate(False)
        self.hide_url_column = QtGui.QCheckBox(tr("Hide URL Column"))
        self.hide_url_column.setCheckState(config.hide_url_column)
        self.hide_url_column.setTristate(False)
        self.install_cccp = QtGui.QPushButton(tr("Trigger CCCP Installation"))
        self.install_cccp.clicked.connect(self.slot_install_cccp)
        self.enableSpellCheck = QtGui.QCheckBox(tr("Enable Spell Check"))
        self.enableSpellCheck.setCheckState(config.enableSpellCheck)
        self.enableSpellCheck.setTristate(False)
        self.prefetch_charts = QtGui.QCheckBox(
            tr("Fetch song charts at startup"))
        self.prefetch_charts.setCheckState(config.prefetch_charts)
        self.prefetch_charts.setTristate(False)
        self.artist_lookup = QtGui.QCheckBox(tr("Look for discography"))
        self.artist_lookup.setCheckState(config.artist_lookup)
        self.artist_lookup.setTristate(False)
        self.lyrics_lookup = QtGui.QCheckBox(
            tr("Search for a song by it's lyrics"))
        self.lyrics_lookup.setCheckState(config.lyrics_lookup)
        self.lyrics_lookup.setTristate(False)
        self.search_autocomplete = QtGui.QCheckBox(
            tr("Search Auto-completion"))
        self.search_autocomplete.setCheckState(config.search_autocomplete)
        self.search_autocomplete.setTristate(False)
        self.id3editor_in_context_menu = QtGui.QCheckBox(
            tr("Show ID3 Editor in Explorer's Context Menu (shown when you right-click a .mp3 file)"
               ))
        self.id3editor_in_context_menu.setCheckState(
            config.id3editor_in_context_menu)
        self.id3editor_in_context_menu.setTristate(False)
        self.id3editor_in_context_menu.clicked.connect(
            self.slot_register_id3editor_in_context_menu)
        self.parse_links_from_clipboard_at_startup = QtGui.QCheckBox(
            tr("Parse links from clipboard at startup"))
        self.parse_links_from_clipboard_at_startup.setCheckState(
            config.parse_links_from_clipboard_at_startup)
        self.parse_links_from_clipboard_at_startup.setTristate(False)
        self.editID3 = QtGui.QCheckBox(tr("Modify ID3 Tags"))
        self.editID3.setCheckState(config.editID3)
        self.editID3.setTristate(False)
        self.editID3.stateChanged.connect(self.slot_changed_checkbox)

        self.label1 = QtGui.QLabel(
            tr("ID3 is a metadata container for MP3 files, which allows for information like the title, artist, album, album art and\nlyrics to be stored on the file itself and later viewed by any modern multimedia player, such as iPod, Windows\nMedia Player and Android phones.\n\niQuality can fetch ID3 tags from the web automatically."
               ))
        # id3_action's values are noask, ask, ask_albumart'
        self.label2 = QtGui.QLabel(tr('After Fetching:'))
        self.id3_autoclose = QtGui.QComboBox()
        self.id3_autoclose.addItems([
            tr('Leave window open for editing'),
            tr('Close window while saving changes')
        ])
        if config.id3_action == 'noask':
            self.id3_autoclose.setCurrentIndex(1)
        else:
            self.id3_autoclose.setCurrentIndex(0)
        self.id3_autoclose.currentIndexChanged.connect(
            self.slot_id3_autoclose_action_changes)

        self.label3 = QtGui.QLabel(tr('AlbumArt:'))
        self.id3_autoalbumart = QtGui.QComboBox()
        self.id3_autoalbumart.addItems(
            [tr('Let me choose it'),
             tr('Choose it automatically for me')])
        if config.id3_action == 'ask_albumart':
            self.id3_autoclose.setCurrentIndex(0)
        else:
            self.id3_autoalbumart.setCurrentIndex(1)

        self.useMp3soup = QtGui.QCheckBox(tr("Use %s") % "Mp3soup")
        self.useMp3soup.setCheckState(config.search_sources['mp3soup'])
        self.useMp3soup.setTristate(False)
        self.useMusicAddict = QtGui.QCheckBox(tr("Use %s") % "MusicAddict")
        self.useMusicAddict.setCheckState(config.search_sources['musicaddict'])
        self.useMusicAddict.setTristate(False)
        self.useMp3Skull = QtGui.QCheckBox(tr("Use %s") % "Mp3Skull")
        self.useMp3Skull.setCheckState(config.search_sources['Mp3skull'])
        self.useMp3Skull.setTristate(False)
        self.useSoundcloud = QtGui.QCheckBox(tr("Use %s") % "SoundCloud")
        self.useSoundcloud.setCheckState(config.search_sources['soundcloud'])
        self.useSoundcloud.setTristate(False)
        self.useBandcamp = QtGui.QCheckBox(tr("Use %s") % "Bandcamp")
        self.useBandcamp.setCheckState(config.search_sources['bandcamp'])
        self.useBandcamp.setTristate(False)
        self.useYoutube = QtGui.QCheckBox(tr("Use %s") % "Youtube")
        self.useYoutube.setCheckState(config.search_sources['youtube'])
        self.useYoutube.setTristate(False)
        self.useYoutube.stateChanged.connect(self.slot_changed_checkbox)
        self.prefered_youtube_format = QtGui.QComboBox()
        self.prefered_youtube_format.addItems(config.youtube_formats_priority)
        self.label_youtube_format = QtGui.QLabel(tr("Prefered Video Format:"))
        self.prefer720p = QtGui.QCheckBox(tr("Prefer 720p over 1080p"))
        self.prefer720p.setCheckState(
            not 'hd1080' in config.youtube_quality_priority)
        self.prefer720p.setTristate(False)

        self.songs_count_spinBox = QtGui.QSpinBox()
        self.songs_count_spinBox.setMaximum(25)
        self.songs_count_spinBox.setMinimum(5)
        self.songs_count_spinBox.setValue(config.songs_count_spinBox)

        self.score_spinBox = QtGui.QDoubleSpinBox()
        self.score_spinBox.setMinimum(0.0)
        self.score_spinBox.setMaximum(5.0)
        self.score_spinBox.setSingleStep(0.5)
        self.score_spinBox.setValue(config.relevance_minimum)

        self.slot_changed_checkbox()

        # General Tab
        layout0 = QtGui.QHBoxLayout()
        layout0.addWidget(QtGui.QLabel(tr("Download Dir:")))
        layout0.addWidget(self.dl_dir)
        layout0.addWidget(self.folder_button)

        layout1 = QtGui.QHBoxLayout()
        layout1.addWidget(QtGui.QLabel(tr("Post-Download Action:")))
        layout1.addWidget(self.post_download_action)
        layout1.addSpacerItem(QtGui.QSpacerItem(450, 10))
        layout15 = QtGui.QHBoxLayout()
        layout15.addWidget(self.post_download_custom_label2)
        layout15.addWidget(self.post_download_custom_cmd)
        layout15.addWidget(self.post_download_custom_wait_checkbox)

        layout2 = QtGui.QHBoxLayout()
        if Phonon.BackendCapabilities.isMimeTypeAvailable('video/x-flv'):
            layout2.addWidget(
                QtGui.QLabel(
                    tr('video/x-flv support: <b><font color="green">yes</font></b>'
                       )))
        else:
            layout2.addWidget(
                QtGui.QLabel(
                    tr('video/x-flv support: <b><font color="red">no</font></b>'
                       )))
        layout2.addWidget(self.install_cccp)
        layout2.addSpacerItem(QtGui.QSpacerItem(550, 10))

        generalTab = QtGui.QWidget()
        # QGridLayout.addWidget (self, QWidget, int row, int column, int rowSpan, int columnSpan, Qt.Alignment alignment = 0)
        generalLayout = QtGui.QVBoxLayout()
        generalLayout.addLayout(layout0)
        generalLayout.addLayout(layout1)
        generalLayout.addLayout(layout15)
        generalLayout.addWidget(self.post_download_custom_label)
        generalLayout.addWidget(self.auto_update)
        generalLayout.addWidget(self.hide_url_column)
        generalLayout.addLayout(layout2)
        generalLayout.addSpacerItem(QtGui.QSpacerItem(100, 100))
        generalTab.setLayout(generalLayout)

        # Media Sources Tab
        mediaSourcesGroupBox = QtGui.QVBoxLayout()
        layout2 = QtGui.QHBoxLayout()
        layout2.addWidget(self.useMp3soup)
        layout2.addWidget(self.useMusicAddict)
        layout2.addWidget(self.useMp3Skull)
        layout2.addWidget(self.useSoundcloud)
        layout2.addWidget(self.useBandcamp)
        layout3 = QtGui.QHBoxLayout()
        layout3.addWidget(self.useYoutube)
        layout3.addWidget(self.prefer720p)
        layout3.addWidget(self.label_youtube_format)
        layout3.addWidget(self.prefered_youtube_format)
        mediaSourcesGroupBox.addLayout(layout3)
        mediaSourcesGroupBox.addLayout(layout2)

        id3GroupBox = QtGui.QGroupBox(tr("ID3 Tags"))
        lay = QtGui.QGridLayout()
        layout4 = QtGui.QHBoxLayout()
        layout4.addWidget(self.editID3)
        layout4.addWidget(self.label2)
        layout4.addWidget(self.id3_autoclose)
        layout4.addWidget(self.label3)
        layout4.addWidget(self.id3_autoalbumart)
        lay.addWidget(self.label1, 0, 0)
        lay.addLayout(layout4, 1, 0)
        lay.addWidget(self.id3editor_in_context_menu, 2, 0)
        id3GroupBox.setLayout(lay)

        mediaSourcesTab = QtGui.QWidget()
        mediaSourcesLayout = QtGui.QVBoxLayout()
        mediaSourcesLayout.addLayout(mediaSourcesGroupBox)
        mediaSourcesLayout.addWidget(id3GroupBox)
        mediaSourcesTab.setLayout(mediaSourcesLayout)

        # Etc Tab
        etcTab = QtGui.QWidget()
        # QGridLayout.addWidget (self, QWidget, int row, int column, int rowSpan, int columnSpan, Qt.Alignment alignment = 0)
        etcLayout = QtGui.QGridLayout()
        etcLayout.addWidget(QtGui.QLabel(tr("Temp Files Directory:")), 0, 0, 1,
                            1)
        etcLayout.addWidget(self.temp_dir, 0, 1, 1, 2)
        etcLayout.addWidget(self.temp_folder_button, 0, 3, 1, 1)
        etcLayout.addWidget(QtGui.QLabel(tr("Table DoubleClick Action:")), 1,
                            0)
        etcLayout.addWidget(self.table_doubleClick_action, 1, 1)
        etcLayout.addWidget(QtGui.QLabel(tr("Num. of songs:")), 2, 0)
        etcLayout.addWidget(self.songs_count_spinBox, 2, 1)
        etcLayout.addWidget(QtGui.QLabel(tr("Min. Score:")), 3, 0)
        etcLayout.addWidget(self.score_spinBox, 3, 1)
        etcLayout.addWidget(self.artist_lookup, 4, 0)
        etcLayout.addWidget(self.lyrics_lookup, 4, 1)
        etcLayout.addWidget(self.parse_links_from_clipboard_at_startup, 4, 2)
        etcLayout.addWidget(self.enableSpellCheck, 5, 0)
        etcLayout.addWidget(self.prefetch_charts, 5, 1)
        etcLayout.addWidget(self.search_autocomplete, 5, 2)
        etcTab.setLayout(etcLayout)

        # Row Layouts
        buttonLayout = QtGui.QHBoxLayout()
        applyButton = QtGui.QPushButton(tr("Apply"))
        applyButton.clicked.connect(self.slot_apply)
        closeButton = QtGui.QPushButton(tr("Dismiss"))
        closeButton.clicked.connect(self.close)
        restoreButton = QtGui.QPushButton(
            tr("(*) Restore to Default Settings"))
        restoreButton.clicked.connect(self.slot_restore)

        buttonLayout.addWidget(applyButton)
        buttonLayout.addWidget(closeButton)
        buttonLayout.addWidget(restoreButton)

        # Form Layout
        tabWidget = QtGui.QTabWidget()
        tabWidget.addTab(generalTab, tr("General"))
        tabWidget.addTab(mediaSourcesTab, tr("Media Sources + ID3"))
        tabWidget.addTab(etcTab, tr("Advanced"))

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(tabWidget)
        mainLayout.addWidget(
            QtGui.QLabel(
                tr("<h3>* Must restart the application to apply.</h3>")))
        mainLayout.addLayout(buttonLayout)

        self.setLayout(mainLayout)

    def slot_choose_dl_dir(self):
        dialog = QtGui.QFileDialog()
        dialog.setFileMode(QtGui.QFileDialog.Directory)
        dialog.setDirectory(self.dl_dir.displayText())
        dl_dir = unicode(
            dialog.getExistingDirectory(
                options=QtGui.QFileDialog.ShowDirsOnly))
        dl_dir = dl_dir.replace('/', '\\')

        if dl_dir:
            if utils.get_free_space(dl_dir) < 200 * 1024**2:  # 200 MB
                log.warning(
                    "The Directory has less than 200 MB available. Application may not function properly."
                )
                QtGui.QMessageBox.warning(
                    self, tr("Warning"),
                    tr("The Directory has less than 200 MB available. Application may not function properly."
                       ), QtGui.QMessageBox.Ok)
            log.debug("dl_dir is set to: %s" % dl_dir)
            self.dl_dir.setText(dl_dir)

    def slot_choose_temp_dir(self):
        dialog = QtGui.QFileDialog()
        dialog.setFileMode(QtGui.QFileDialog.Directory)
        dialog.setDirectory(self.temp_dir.displayText())
        temp_dir = unicode(
            dialog.getExistingDirectory(
                options=QtGui.QFileDialog.ShowDirsOnly))
        temp_dir = temp_dir.replace('/', '\\')

        if temp_dir:
            if utils.get_free_space(temp_dir) < 200 * 1024**2:  # 200 MB
                log.warning(
                    "The Directory has less than 200 MB available. Application may not function properly."
                )
                QtGui.QMessageBox.warning(
                    self, tr("Warning"),
                    tr("The Directory has less than 200 MB available. Application may not function properly."
                       ), QtGui.QMessageBox.Ok)
            log.debug("temp_dir is set to: %s" % temp_dir)
            self.temp_dir.setText(temp_dir)

    def slot_changed_checkbox(self, state=None):
        if config.post_download_action == 'customLaunch':
            self.post_download_custom_label2.setText(tr("Command:"))
            self.post_download_custom_cmd.setVisible(True)
            self.post_download_custom_label2.setVisible(True)
            self.post_download_custom_wait_checkbox.setVisible(True)

            if config.post_download_custom_cmd:
                self.post_download_custom_cmd.setText(
                    config.post_download_custom_cmd)
            else:
                self.post_download_custom_cmd.setText(
                    r'"C:\Program Files\AnyApp\encoder.exe" -i "%AUDIO%" -o C:\Encoded\song.mp3'
                )

            self.post_download_custom_label.setText(
                tr("You may use the %AUDIO% var in the command. Will be launched only on audio songs."
                   ))

        elif config.post_download_action == 'addPlaylist':
            self.post_download_custom_label2.setText(tr("Playlist Path:"))

            if config.post_download_playlist_path:
                self.post_download_custom_cmd.setText(
                    config.post_download_playlist_path)
            else:
                log.error(
                    "in config.post_download_action after sanity check, however playlist path is not valid"
                )

            self.post_download_custom_cmd.setVisible(True)
            self.post_download_custom_label2.setVisible(True)
            self.post_download_custom_label.setText(
                tr("Supported Playlist Formats: m3u, wpl."))
            self.post_download_custom_wait_checkbox.setVisible(False)

        else:
            self.post_download_custom_label2.setText(tr("Command:"))
            self.post_download_custom_cmd.setVisible(False)
            self.post_download_custom_label2.setVisible(False)

            self.post_download_custom_wait_checkbox.setVisible(False)

            if config.post_download_custom_cmd:
                self.post_download_custom_cmd.setText(
                    config.post_download_custom_cmd)
            else:
                self.post_download_custom_cmd.setText(
                    r'"C:\Program Files\AnyApp\encoder.exe" -i "%AUDIO%" -o C:\Encoded\song.mp3'
                )

            self.post_download_custom_label.setText("")

        if not self.useYoutube.isChecked():
            self.prefered_youtube_format.setEnabled(False)
            self.label_youtube_format.setEnabled(False)
            self.prefer720p.setEnabled(False)
        else:
            self.prefered_youtube_format.setEnabled(True)
            self.label_youtube_format.setEnabled(True)
            self.prefer720p.setEnabled(True)

        if not self.editID3.isChecked():
            self.label2.setEnabled(False)
            self.id3_autoclose.setEnabled(False)
            self.label3.setEnabled(False)
            self.id3_autoalbumart.setEnabled(False)
        else:
            self.label2.setEnabled(True)
            self.id3_autoclose.setEnabled(True)
            if self.id3_autoclose.currentIndex() == 1:  # if noask
                self.label3.setEnabled(False)
                self.id3_autoalbumart.setEnabled(False)
            else:
                self.label3.setEnabled(True)
                self.id3_autoalbumart.setEnabled(True)

    def slot_id3_autoclose_action_changes(self, i):
        if i == 1 and self.id3_autoalbumart.currentIndex() == 0:
            # if autoclose is True and albumart is set to "ask user", we should change it to "do it automatically", as if the window is closing itself automatically, it can't ask the user for input.
            self.id3_autoalbumart.setCurrentIndex(1)
        self.slot_changed_checkbox()

    def slot_post_download_action_changed(self, i):
        val = config.post_download_action_dict.keys()[i]
        if val == 'addItunes' and not config.is_itunes_installed:
            QtGui.QMessageBox.critical(
                self, tr("Error"),
                tr("iTunes is not installed on this system."),
                QtGui.QMessageBox.Ok)
            self.post_download_action.setCurrentIndex(
                config.post_download_action_dict.keys().index(
                    config.post_download_action))
        elif val == 'addPlaylist':
            dialog = QtGui.QFileDialog()
            dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
            if config.post_download_playlist_path:
                dialog.setDirectory(
                    os.path.dirname(config.post_download_playlist_path))
            else:
                dialog.setDirectory(
                    r'%s\My Documents\My Music\My Playlists' %
                    utils.get_home_dir())  # The default playlist directory

            f = unicode(
                dialog.getOpenFileName(caption=tr("Open Playlist"),
                                       filter=tr("Supported Playlist Files") +
                                       " (*.m3u *.wpl)"))
            f = f.replace('/', '\\')

            if f:
                config.post_download_playlist_path = f
            elif not config.post_download_playlist_path:
                # if new playlist is not choosed, and there is NO playlist path in the config file, we should revert the post_download_action to the last one.
                self.post_download_action.setCurrentIndex(
                    config.post_download_action_dict.keys().index(
                        config.post_download_action))
                return

        config.post_download_action = val
        self.slot_changed_checkbox()

    def slot_install_cccp(self):
        win = UpdaterWindow.MainWin('install_package',
                                    ['Combined Community Codec Pack'])
        win.exec_()

    def slot_register_id3editor_in_context_menu(self, val):
        if val and not utils.check_context_menu_status():
            log.debug("Registering Context Menu Object...")
            try:
                utils.register_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to False."
                    )
                    QtGui.QMessageBox.critical(
                        self, tr("Error"),
                        tr("Access is denied. Please run this application as an administrator and try again."
                           ), QtGui.QMessageBox.Ok)
                    self.id3editor_in_context_menu.setCheckState(False)
                    self.id3editor_in_context_menu.setTristate(False)
                else:
                    raise
            else:
                if sys.getwindowsversion().major == 6:  # If Windows Vista/7/8
                    QtGui.QMessageBox.information(
                        self, tr("Information"),
                        tr("You need to restart your computer for the changes to take effect."
                           ), QtGui.QMessageBox.Ok)
        if not val and utils.check_context_menu_status():
            log.debug("Unregistering Context Menu Object...")
            try:
                utils.unregister_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to True."
                    )
                    QtGui.QMessageBox.critical(
                        self, tr("Error"),
                        tr("Access is denied. Please run this application as an administrator and try again."
                           ), QtGui.QMessageBox.Ok)
                    self.id3editor_in_context_menu.setCheckState(True)
                    self.id3editor_in_context_menu.setTristate(False)
                else:
                    raise
            else:
                if sys.getwindowsversion().major == 6:  # If Windows Vista/7/8
                    QtGui.QMessageBox.information(
                        self, tr("Information"),
                        tr("You need to restart your computer for the changes to take effect."
                           ), QtGui.QMessageBox.Ok)
Ejemplo n.º 4
0
def sanity_check():
	"Sanity Check for script."
	config.count_application_runs += 1
	_warnings = []
	
	### LOCAL CHECKS ###
	
	# Windows version check
	winver = sys.getwindowsversion()
	log.debug('Running iQuality v%s (r%d) on Windows %d.%d.%d %s' % (__version__, __rev__, winver.major, winver.minor, winver.build, winver.service_pack))
	
	# Python version check
	if sys.version_info < (2, 6) or sys.version_info >= (3, 0):
		msg = "must use python 2.7"
		log.critical(msg)
		raise Exception(msg)
	log.debug('CPython version is %d.%d.%d' % (sys.version_info.major, sys.version_info.minor, sys.version_info.micro))
	log.debug('PyQt version is %s, Qt version is %s' % (QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))
		
	# youtube-dl check
	try:
		import youtube_dl
		log.debug("youtube-dl version is %s" % youtube_dl.__version__)
	except ImportError:
		log.warning("Could not load the youtube-dl module")
		
	# Phonon version check
	try:
		from PyQt4.phonon import Phonon
		if Phonon.BackendCapabilities.isMimeTypeAvailable('video/x-flv'):
			log.debug('Phonon version is %s. video/x-flv is supported.' % Phonon.phononVersion())
		else:
			log.warning('Phonon version is %s. video/x-flv is not supported.' % Phonon.phononVersion())
	except ImportError:
		log.warning("Could not load the phonon module")
	
	# Free space check
	freespace = utils.get_free_space(config.temp_dir)
	if freespace < 200*1024**2: # 200 MB
		drive = os.path.splitdrive(config.temp_dir)[0]
		log.warning("There are less than 200MB available in drive %s (%.2fMB left)." % (drive, freespace/1024.0**2))
		_warnings.append(NoSpaceWarning(drive, freespace))

	# iTunes' availablity check
	itunesPath = r'%s\My Documents\My Music\iTunes\iTunes Media\Automatically Add to iTunes' % utils.get_home_dir()
	if not os.path.exists(itunesPath):
		config.is_itunes_installed = False
		if config.post_download_action == 'addItunes':
			config.post_download_action = 'ask'
		log.warning("iTunes Media not found. setting is_itunes_installed to False")
		
	# Context Menu check
	try: # IMPROVE: REMOVE THE TRY-EXCEPT BLOCK
		if config.id3editor_in_context_menu and not utils.check_context_menu_status():
			log.debug("Registering Context Menu Object...")
			try:
				utils.register_with_context_menu()
			except WindowsError, e:
				if e.winerror == 5: # Access is denied
					log.debug("Access is denied. Setting id3editor_in_context_menu to False.")
					config.id3editor_in_context_menu = False
				else:
					raise
		if not config.id3editor_in_context_menu and utils.check_context_menu_status():
			log.debug("Unregistering Context Menu Object...")
			try:
				utils.unregister_with_context_menu()
			except WindowsError, e:
				if e.winerror == 5: # Access is denied
					log.debug("Access is denied. Setting id3editor_in_context_menu to True.")
					config.id3editor_in_context_menu = True
				else:
					raise
Ejemplo n.º 5
0
def sanity_check():
    "Sanity Check for script."
    config.count_application_runs += 1
    _warnings = []

    ### LOCAL CHECKS ###

    # Windows version check
    winver = sys.getwindowsversion()
    log.debug('Running iQuality v%s (r%d) on Windows %d.%d.%d %s' %
              (__version__, __rev__, winver.major, winver.minor, winver.build,
               winver.service_pack))

    # Python version check
    if sys.version_info < (2, 6) or sys.version_info >= (3, 0):
        msg = "must use python 2.7"
        log.critical(msg)
        raise Exception(msg)
    log.debug('CPython version is %d.%d.%d' %
              (sys.version_info.major, sys.version_info.minor,
               sys.version_info.micro))
    log.debug('PyQt version is %s, Qt version is %s' %
              (QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR))

    # youtube-dl check
    try:
        import youtube_dl
        log.debug("youtube-dl version is %s" % youtube_dl.__version__)
    except ImportError:
        log.warning("Could not load the youtube-dl module")

    # Phonon version check
    try:
        from PyQt4.phonon import Phonon
        if Phonon.BackendCapabilities.isMimeTypeAvailable('video/x-flv'):
            log.debug('Phonon version is %s. video/x-flv is supported.' %
                      Phonon.phononVersion())
        else:
            log.warning('Phonon version is %s. video/x-flv is not supported.' %
                        Phonon.phononVersion())
    except ImportError:
        log.warning("Could not load the phonon module")

    # Free space check
    freespace = utils.get_free_space(config.temp_dir)
    if freespace < 200 * 1024**2:  # 200 MB
        drive = os.path.splitdrive(config.temp_dir)[0]
        log.warning(
            "There are less than 200MB available in drive %s (%.2fMB left)." %
            (drive, freespace / 1024.0**2))
        _warnings.append(NoSpaceWarning(drive, freespace))

    # iTunes' availablity check
    itunesPath = r'%s\My Documents\My Music\iTunes\iTunes Media\Automatically Add to iTunes' % utils.get_home_dir(
    )
    if not os.path.exists(itunesPath):
        config.is_itunes_installed = False
        if config.post_download_action == 'addItunes':
            config.post_download_action = 'ask'
        log.warning(
            "iTunes Media not found. setting is_itunes_installed to False")

    # Context Menu check
    try:  # IMPROVE: REMOVE THE TRY-EXCEPT BLOCK
        if config.id3editor_in_context_menu and not utils.check_context_menu_status(
        ):
            log.debug("Registering Context Menu Object...")
            try:
                utils.register_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to False."
                    )
                    config.id3editor_in_context_menu = False
                else:
                    raise
        if not config.id3editor_in_context_menu and utils.check_context_menu_status(
        ):
            log.debug("Unregistering Context Menu Object...")
            try:
                utils.unregister_with_context_menu()
            except WindowsError, e:
                if e.winerror == 5:  # Access is denied
                    log.debug(
                        "Access is denied. Setting id3editor_in_context_menu to True."
                    )
                    config.id3editor_in_context_menu = True
                else:
                    raise