2009-05-15 05:15:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-09 09:26:47 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2012-12-29 20:56:56 +00:00
|
|
|
# Copyright (c) 2008-2013 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
2012-06-22 14:14:53 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
2012-11-11 21:16:14 +00:00
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
2012-10-21 13:16:22 +00:00
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
2012-12-01 07:57:54 +00:00
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-05-15 05:15:53 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2013-02-07 08:42:17 +00:00
|
|
|
from openlp.core.lib import ItemCapabilities, MediaManagerItem,MediaType, Registry, ServiceItem, ServiceItemContext, \
|
2013-02-05 08:05:28 +00:00
|
|
|
Settings, UiStrings, build_icon, check_item_selected, check_directory_exists, translate
|
2013-01-11 00:19:11 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box
|
2012-10-20 19:52:04 +00:00
|
|
|
from openlp.core.ui import DisplayController, Display, DisplayControllerType
|
2012-03-16 21:52:15 +00:00
|
|
|
from openlp.core.ui.media import get_media_players, set_media_players
|
2013-04-05 17:41:01 +00:00
|
|
|
from openlp.core.utils import AppLocation, get_locale_key
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2013-04-19 19:03:16 +00:00
|
|
|
|
2010-02-27 09:55:44 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2011-03-24 19:04:02 +00:00
|
|
|
|
2013-04-19 19:03:16 +00:00
|
|
|
|
2012-10-09 18:00:33 +00:00
|
|
|
CLAPPERBOARD = u':/media/slidecontroller_multimedia.png'
|
2013-04-28 17:17:45 +00:00
|
|
|
VIDEO_ICON = build_icon(u':/media/media_video.png')
|
|
|
|
AUDIO_ICON = build_icon(u':/media/media_audio.png')
|
|
|
|
DVD_ICON = build_icon(u':/media/media_video.png')
|
|
|
|
ERROR_ICON = build_icon(u':/general/general_delete.png')
|
2011-07-27 18:28:35 +00:00
|
|
|
|
2013-04-19 19:03:16 +00:00
|
|
|
|
2009-05-15 05:15:53 +00:00
|
|
|
class MediaMediaItem(MediaManagerItem):
|
|
|
|
"""
|
2009-05-16 10:24:03 +00:00
|
|
|
This is the custom media manager item for Media Slides.
|
2009-05-15 05:15:53 +00:00
|
|
|
"""
|
2010-02-27 09:55:44 +00:00
|
|
|
log.info(u'%s MediaMediaItem loaded', __name__)
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2013-03-07 13:14:31 +00:00
|
|
|
def __init__(self, parent, plugin):
|
2013-03-19 20:05:13 +00:00
|
|
|
self.icon_path = u'images/image'
|
2010-04-30 16:30:25 +00:00
|
|
|
self.background = False
|
2011-12-15 20:13:45 +00:00
|
|
|
self.automatic = u''
|
2013-03-07 13:14:31 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, plugin)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.single_service_item = False
|
2013-03-23 06:46:41 +00:00
|
|
|
self.has_search = True
|
2013-03-06 22:42:52 +00:00
|
|
|
self.media_object = None
|
2013-02-20 20:43:20 +00:00
|
|
|
self.display_controller = DisplayController(parent)
|
|
|
|
self.display_controller.controller_layout = QtGui.QVBoxLayout()
|
|
|
|
self.media_controller.register_controller(self.display_controller)
|
|
|
|
self.media_controller.set_controls_visible(self.display_controller, False)
|
|
|
|
self.display_controller.preview_display = Display(self.display_controller, False, self.display_controller)
|
|
|
|
self.display_controller.preview_display.hide()
|
|
|
|
self.display_controller.preview_display.setGeometry(QtCore.QRect(0, 0, 300, 300))
|
|
|
|
self.display_controller.preview_display.screen = {u'size': self.display_controller.preview_display.geometry()}
|
|
|
|
self.display_controller.preview_display.setup()
|
|
|
|
self.media_controller.setup_display(self.display_controller.preview_display, False)
|
2013-02-07 11:33:47 +00:00
|
|
|
Registry().register_function(u'video_background_replaced', self.video_background_replaced)
|
2013-02-07 08:42:17 +00:00
|
|
|
Registry().register_function(u'mediaitem_media_rebuild', self.rebuild_players)
|
2013-02-07 11:33:47 +00:00
|
|
|
Registry().register_function(u'config_screen_changed', self.display_setup)
|
2011-07-27 18:28:35 +00:00
|
|
|
# Allow DnD from the desktop
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view.activateDnD()
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2009-10-31 16:17:26 +00:00
|
|
|
def retranslateUi(self):
|
2013-03-19 22:00:50 +00:00
|
|
|
self.on_new_prompt = translate('MediaPlugin.MediaItem', 'Select Media')
|
2013-04-19 19:15:12 +00:00
|
|
|
self.replace_action.setText(UiStrings().ReplaceBG)
|
|
|
|
self.replace_action.setToolTip(UiStrings().ReplaceLiveBG)
|
|
|
|
self.reset_action.setText(UiStrings().ResetBG)
|
|
|
|
self.reset_action.setToolTip(UiStrings().ResetLiveBG)
|
2012-11-22 22:02:40 +00:00
|
|
|
self.automatic = UiStrings().Automatic
|
2013-04-19 19:15:12 +00:00
|
|
|
self.display_type_label.setText(translate('MediaPlugin.MediaItem', 'Use Player:'))
|
2012-11-21 21:49:18 +00:00
|
|
|
self.rebuild_players()
|
2009-10-29 18:25:34 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def required_icons(self):
|
|
|
|
"""
|
|
|
|
Set which icons the media manager tab should show
|
|
|
|
"""
|
|
|
|
MediaManagerItem.required_icons(self)
|
|
|
|
self.has_file_icon = True
|
|
|
|
self.has_new_icon = False
|
|
|
|
self.has_edit_icon = False
|
2009-09-26 09:11:39 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_list_view_to_toolbar(self):
|
|
|
|
MediaManagerItem.add_list_view_to_toolbar(self)
|
2013-04-19 19:15:12 +00:00
|
|
|
self.list_view.addAction(self.replace_action)
|
2010-04-30 16:30:25 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_end_header_bar(self):
|
2010-12-29 09:14:13 +00:00
|
|
|
# Replace backgrounds do not work at present so remove functionality.
|
2013-04-19 19:15:12 +00:00
|
|
|
self.replace_action = self.toolbar.add_toolbar_action(u'replace_action', icon=u':/slides/slide_blank.png',
|
2012-12-10 06:15:42 +00:00
|
|
|
triggers=self.onReplaceClick)
|
2013-04-19 19:15:12 +00:00
|
|
|
self.reset_action = self.toolbar.add_toolbar_action(u'reset_action', icon=u':/system/system_close.png',
|
2012-12-10 06:15:42 +00:00
|
|
|
visible=False, triggers=self.onResetClick)
|
2013-04-19 19:15:12 +00:00
|
|
|
self.media_widget = QtGui.QWidget(self)
|
|
|
|
self.media_widget.setObjectName(u'media_widget')
|
|
|
|
self.display_layout = QtGui.QFormLayout(self.media_widget)
|
|
|
|
self.display_layout.setMargin(self.display_layout.spacing())
|
|
|
|
self.display_layout.setObjectName(u'display_layout')
|
|
|
|
self.display_type_label = QtGui.QLabel(self.media_widget)
|
|
|
|
self.display_type_label.setObjectName(u'display_type_label')
|
|
|
|
self.display_type_combo_box = create_horizontal_adjusting_combo_box(
|
|
|
|
self.media_widget, u'display_type_combo_box')
|
|
|
|
self.display_type_label.setBuddy(self.display_type_combo_box)
|
|
|
|
self.display_layout.addRow(self.display_type_label, self.display_type_combo_box)
|
|
|
|
# Add the Media widget to the page layout.
|
|
|
|
self.page_layout.addWidget(self.media_widget)
|
|
|
|
self.display_type_combo_box.currentIndexChanged.connect(self.overridePlayerChanged)
|
2012-12-30 19:49:48 +00:00
|
|
|
|
2011-11-11 16:45:25 +00:00
|
|
|
def overridePlayerChanged(self, index):
|
2012-03-16 21:52:15 +00:00
|
|
|
player = get_media_players()[0]
|
|
|
|
if index == 0:
|
|
|
|
set_media_players(player)
|
|
|
|
else:
|
|
|
|
set_media_players(player, player[index-1])
|
2010-04-30 16:30:25 +00:00
|
|
|
|
2010-07-19 20:05:25 +00:00
|
|
|
def onResetClick(self):
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2011-08-29 19:55:58 +00:00
|
|
|
Called to reset the Live background with the media selected,
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2013-01-25 20:50:18 +00:00
|
|
|
self.media_controller.media_reset(self.live_controller)
|
2013-04-19 19:15:12 +00:00
|
|
|
self.reset_action.setVisible(False)
|
2010-07-02 18:21:45 +00:00
|
|
|
|
2013-02-07 11:33:47 +00:00
|
|
|
def video_background_replaced(self):
|
2011-01-23 15:36:15 +00:00
|
|
|
"""
|
2011-10-15 11:30:39 +00:00
|
|
|
Triggered by main display on change of serviceitem.
|
2011-01-23 15:36:15 +00:00
|
|
|
"""
|
2013-04-19 19:15:12 +00:00
|
|
|
self.reset_action.setVisible(False)
|
2011-01-23 15:36:15 +00:00
|
|
|
|
2010-07-19 20:05:25 +00:00
|
|
|
def onReplaceClick(self):
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2011-08-29 19:55:58 +00:00
|
|
|
Called to replace Live background with the media selected.
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if check_item_selected(self.list_view,
|
2012-12-09 09:26:47 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')):
|
2013-03-19 22:00:50 +00:00
|
|
|
item = self.list_view.currentItem()
|
2013-02-10 16:11:12 +00:00
|
|
|
filename = item.data(QtCore.Qt.UserRole)
|
2011-01-03 19:50:25 +00:00
|
|
|
if os.path.exists(filename):
|
2012-09-29 16:27:55 +00:00
|
|
|
service_item = ServiceItem()
|
2012-12-13 18:55:11 +00:00
|
|
|
service_item.title = u'webkit'
|
2013-05-24 20:17:47 +00:00
|
|
|
service_item.processor = u'webkit'
|
2012-09-29 16:27:55 +00:00
|
|
|
(path, name) = os.path.split(filename)
|
2012-10-10 18:10:10 +00:00
|
|
|
service_item.add_from_command(path, name,CLAPPERBOARD)
|
2013-03-06 22:50:49 +00:00
|
|
|
if self.media_controller.video(DisplayControllerType.Live, service_item, video_behind_text=True):
|
2013-04-19 19:15:12 +00:00
|
|
|
self.reset_action.setVisible(True)
|
2011-07-03 08:13:48 +00:00
|
|
|
else:
|
|
|
|
critical_error_message_box(UiStrings().LiveBGError,
|
2012-12-09 09:26:47 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'There was no display item to amend.'))
|
2011-01-03 19:50:25 +00:00
|
|
|
else:
|
2011-04-15 21:43:59 +00:00
|
|
|
critical_error_message_box(UiStrings().LiveBGError,
|
2012-05-17 18:57:01 +00:00
|
|
|
translate('MediaPlugin.MediaItem',
|
2012-12-20 12:09:12 +00:00
|
|
|
'There was a problem replacing your background, the media file "%s" no longer exists.') % filename)
|
2010-04-30 16:30:25 +00:00
|
|
|
|
2013-04-19 19:15:12 +00:00
|
|
|
def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
|
2012-12-09 09:26:47 +00:00
|
|
|
context=ServiceItemContext.Live):
|
2013-03-19 22:00:50 +00:00
|
|
|
"""
|
|
|
|
Generate the slide data. Needs to be implemented by the plugin.
|
|
|
|
"""
|
2010-04-05 07:22:21 +00:00
|
|
|
if item is None:
|
2013-03-19 22:00:50 +00:00
|
|
|
item = self.list_view.currentItem()
|
2010-04-05 07:22:21 +00:00
|
|
|
if item is None:
|
|
|
|
return False
|
2013-02-10 16:11:12 +00:00
|
|
|
filename = item.data(QtCore.Qt.UserRole)
|
2011-03-19 15:48:26 +00:00
|
|
|
if not os.path.exists(filename):
|
2011-09-06 17:53:43 +00:00
|
|
|
if not remote:
|
|
|
|
# File is no longer present
|
|
|
|
critical_error_message_box(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Missing Media File'),
|
2012-12-20 12:09:12 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'The file %s no longer exists.') % filename)
|
2010-12-29 09:27:13 +00:00
|
|
|
return False
|
2012-09-09 06:54:09 +00:00
|
|
|
(path, name) = os.path.split(filename)
|
2013-05-24 20:17:47 +00:00
|
|
|
service_item.title = name
|
|
|
|
service_item.processor = self.display_type_combo_box.currentText()
|
2012-10-13 20:54:56 +00:00
|
|
|
service_item.add_from_command(path, name, CLAPPERBOARD)
|
2012-10-20 08:20:11 +00:00
|
|
|
# Only get start and end times if going to a service
|
|
|
|
if context == ServiceItemContext.Service:
|
|
|
|
# Start media and obtain the length
|
2013-01-23 19:28:47 +00:00
|
|
|
if not self.media_controller.media_length(service_item):
|
2012-10-20 08:20:11 +00:00
|
|
|
return False
|
2012-09-09 06:54:09 +00:00
|
|
|
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
|
2011-03-19 15:48:26 +00:00
|
|
|
service_item.add_capability(ItemCapabilities.RequiresMedia)
|
2013-03-19 19:43:22 +00:00
|
|
|
if Settings().value(self.settings_section + u'/media auto start') == QtCore.Qt.Checked:
|
2012-09-09 06:54:09 +00:00
|
|
|
service_item.will_auto_start = True
|
|
|
|
# force a non-existent theme
|
2011-03-19 15:48:26 +00:00
|
|
|
service_item.theme = -1
|
|
|
|
return True
|
|
|
|
|
2009-07-04 05:52:30 +00:00
|
|
|
def initialise(self):
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view.clear()
|
|
|
|
self.list_view.setIconSize(QtCore.QSize(88, 50))
|
2013-03-19 19:43:22 +00:00
|
|
|
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails')
|
2012-12-09 09:26:47 +00:00
|
|
|
check_directory_exists(self.servicePath)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.load_list(Settings().value(self.settings_section + u'/media files'))
|
2011-09-22 18:22:35 +00:00
|
|
|
self.populateDisplayTypes()
|
|
|
|
|
2012-10-07 07:25:55 +00:00
|
|
|
def rebuild_players(self):
|
2011-09-22 18:22:35 +00:00
|
|
|
"""
|
2013-04-19 19:15:12 +00:00
|
|
|
Rebuild the tab in the media manager when changes are made in the settings.
|
2011-09-22 18:22:35 +00:00
|
|
|
"""
|
|
|
|
self.populateDisplayTypes()
|
2013-03-19 22:00:50 +00:00
|
|
|
self.on_new_file_masks = translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)') % (
|
2013-01-23 19:28:47 +00:00
|
|
|
u' '.join(self.media_controller.video_extensions_list),
|
|
|
|
u' '.join(self.media_controller.audio_extensions_list), UiStrings().AllFiles)
|
2011-12-01 18:07:15 +00:00
|
|
|
|
2013-02-07 11:33:47 +00:00
|
|
|
def display_setup(self):
|
2013-03-06 22:59:25 +00:00
|
|
|
self.media_controller.setup_display(self.display_controller.preview_display, False)
|
2011-12-01 18:07:15 +00:00
|
|
|
|
2011-09-22 18:22:35 +00:00
|
|
|
def populateDisplayTypes(self):
|
|
|
|
"""
|
2013-04-19 19:15:12 +00:00
|
|
|
Load the combobox with the enabled media players, allowing user to select a specific player if settings allow.
|
2011-09-22 18:22:35 +00:00
|
|
|
"""
|
2013-04-19 19:15:12 +00:00
|
|
|
# block signals to avoid unnecessary overridePlayerChanged Signals while combo box creation
|
|
|
|
self.display_type_combo_box.blockSignals(True)
|
|
|
|
self.display_type_combo_box.clear()
|
2012-03-16 21:52:15 +00:00
|
|
|
usedPlayers, overridePlayer = get_media_players()
|
2013-03-06 17:46:19 +00:00
|
|
|
media_players = self.media_controller.media_players
|
2012-03-16 21:52:15 +00:00
|
|
|
currentIndex = 0
|
2012-03-12 08:17:20 +00:00
|
|
|
for player in usedPlayers:
|
2011-09-22 18:22:35 +00:00
|
|
|
# load the drop down selection
|
2013-04-19 19:15:12 +00:00
|
|
|
self.display_type_combo_box.addItem(media_players[player].original_name)
|
2012-03-16 21:52:15 +00:00
|
|
|
if overridePlayer == player:
|
2013-04-19 19:15:12 +00:00
|
|
|
currentIndex = len(self.display_type_combo_box)
|
|
|
|
if self.display_type_combo_box.count() > 1:
|
|
|
|
self.display_type_combo_box.insertItem(0, self.automatic)
|
|
|
|
self.display_type_combo_box.setCurrentIndex(currentIndex)
|
2012-03-21 19:30:18 +00:00
|
|
|
if overridePlayer:
|
2013-04-19 19:15:12 +00:00
|
|
|
self.media_widget.show()
|
2011-09-22 18:22:35 +00:00
|
|
|
else:
|
2013-04-19 19:15:12 +00:00
|
|
|
self.media_widget.hide()
|
|
|
|
self.display_type_combo_box.blockSignals(False)
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_delete_click(self):
|
2010-06-16 01:23:57 +00:00
|
|
|
"""
|
2011-10-15 11:30:39 +00:00
|
|
|
Remove a media item from the list.
|
2010-06-16 01:23:57 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if check_item_selected(self.list_view,
|
2012-12-30 19:49:48 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'You must select a media file to delete.')):
|
2013-03-19 22:00:50 +00:00
|
|
|
row_list = [item.row() for item in self.list_view.selectedIndexes()]
|
2010-06-28 18:20:05 +00:00
|
|
|
row_list.sort(reverse=True)
|
|
|
|
for row in row_list:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view.takeItem(row)
|
|
|
|
Settings().setValue(self.settings_section + u'/media files', self.get_file_list())
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def load_list(self, media, target_group=None):
|
2013-05-24 20:17:47 +00:00
|
|
|
# Sort the media by its filename considering language specific characters.
|
2013-04-05 17:41:01 +00:00
|
|
|
media.sort(key=lambda filename: get_locale_key(os.path.split(unicode(filename))[1]))
|
2011-07-27 18:28:35 +00:00
|
|
|
for track in media:
|
2011-09-22 18:22:35 +00:00
|
|
|
track_info = QtCore.QFileInfo(track)
|
2012-11-04 14:25:48 +00:00
|
|
|
if not os.path.exists(track):
|
|
|
|
filename = os.path.split(unicode(track))[1]
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
2013-04-19 19:15:12 +00:00
|
|
|
item_name.setIcon(ERROR_ICON)
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name.setData(QtCore.Qt.UserRole, track)
|
2012-11-04 14:25:48 +00:00
|
|
|
elif track_info.isFile():
|
2011-09-22 18:22:35 +00:00
|
|
|
filename = os.path.split(unicode(track))[1]
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
2013-01-23 19:28:47 +00:00
|
|
|
if u'*.%s' % (filename.split(u'.')[-1].lower()) in self.media_controller.audio_extensions_list:
|
2013-04-19 19:15:12 +00:00
|
|
|
item_name.setIcon(AUDIO_ICON)
|
2012-10-06 10:01:04 +00:00
|
|
|
else:
|
2013-04-19 19:15:12 +00:00
|
|
|
item_name.setIcon(VIDEO_ICON)
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name.setData(QtCore.Qt.UserRole, track)
|
2011-09-22 18:22:35 +00:00
|
|
|
else:
|
|
|
|
filename = os.path.split(unicode(track))[1]
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
2013-04-19 19:15:12 +00:00
|
|
|
item_name.setIcon(build_icon(DVD_ICON))
|
2013-02-10 16:11:12 +00:00
|
|
|
item_name.setData(QtCore.Qt.UserRole, track)
|
|
|
|
item_name.setToolTip(track)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view.addItem(item_name)
|
2011-04-29 16:41:26 +00:00
|
|
|
|
2013-04-19 19:15:12 +00:00
|
|
|
def get_list(self, type=MediaType.Audio):
|
2013-03-19 19:43:22 +00:00
|
|
|
media = Settings().value(self.settings_section + u'/media files')
|
2013-04-05 17:41:01 +00:00
|
|
|
media.sort(key=lambda filename: get_locale_key(os.path.split(unicode(filename))[1]))
|
2013-04-19 19:15:12 +00:00
|
|
|
extension = []
|
2011-08-23 21:48:46 +00:00
|
|
|
if type == MediaType.Audio:
|
2013-04-19 19:15:12 +00:00
|
|
|
extension = self.media_controller.audio_extensions_list
|
2011-08-23 21:48:46 +00:00
|
|
|
else:
|
2013-04-19 19:15:12 +00:00
|
|
|
extension = self.media_controller.video_extensions_list
|
|
|
|
extension = map(lambda x: x[1:], extension)
|
|
|
|
media = filter(lambda x: os.path.splitext(x)[1] in extension, media)
|
2011-08-23 21:48:46 +00:00
|
|
|
return media
|
|
|
|
|
2012-03-15 06:15:21 +00:00
|
|
|
def search(self, string, showError):
|
2013-03-19 19:43:22 +00:00
|
|
|
files = Settings().value(self.settings_section + u'/media files')
|
2011-05-15 20:03:45 +00:00
|
|
|
results = []
|
|
|
|
string = string.lower()
|
2011-06-12 11:51:23 +00:00
|
|
|
for file in files:
|
2011-05-15 20:03:45 +00:00
|
|
|
filename = os.path.split(unicode(file))[1]
|
|
|
|
if filename.lower().find(string) > -1:
|
|
|
|
results.append([file, filename])
|
|
|
|
return results
|