diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index f83e92de7..d8ff07281 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -36,6 +36,13 @@ from PyQt4 import QtCore, QtGui log = logging.getLogger(__name__) +class MediaType(object): + """ + An enumeration class for types of media. + """ + Audio = 1 + Video = 2 + def translate(context, text, comment=None, encoding=QtCore.QCoreApplication.CodecForTr, n=-1, translate=QtCore.QCoreApplication.translate): diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index e3c36bd77..2e59ad9e8 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -31,11 +31,11 @@ import os import locale from PyQt4 import QtCore, QtGui +from PyQt4.phonon import Phonon from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \ - SettingsManager, translate, check_item_selected, Receiver + SettingsManager, translate, check_item_selected, Receiver, MediaType from openlp.core.lib.ui import UiStrings, critical_error_message_box -from PyQt4.phonon import Phonon log = logging.getLogger(__name__) @@ -48,9 +48,9 @@ class MediaMediaItem(MediaManagerItem): log.info(u'%s MediaMediaItem loaded', __name__) def __init__(self, parent, plugin, icon): - self.IconPath = u'images/image' + self.iconPath = u'images/image' self.background = False - self.PreviewFunction = CLAPPERBOARD + self.previewFunction = CLAPPERBOARD MediaManagerItem.__init__(self, parent, plugin, icon) self.singleServiceItem = False self.hasSearch = True @@ -139,8 +139,8 @@ class MediaMediaItem(MediaManagerItem): # File is no longer present critical_error_message_box( translate('MediaPlugin.MediaItem', 'Missing Media File'), - unicode(translate('MediaPlugin.MediaItem', - 'The file %s no longer exists.')) % filename) + unicode(translate('MediaPlugin.MediaItem', + 'The file %s no longer exists.')) % filename) return False self.mediaObject.stop() self.mediaObject.clearQueue() @@ -156,8 +156,11 @@ class MediaMediaItem(MediaManagerItem): or self.mediaObject.currentSource().type() \ == Phonon.MediaSource.Invalid: self.mediaObject.stop() - critical_error_message_box(UiStrings().UnsupportedFile, - UiStrings().UnsupportedFile) + critical_error_message_box( + translate('MediaPlugin.MediaItem', 'File Too Big'), + translate('MediaPlugin.MediaItem', 'The file you are ' + 'trying to load is too big. Please reduce it to less ' + 'than 50MiB.')) return False self.mediaObject.stop() service_item.media_length = self.mediaObject.totalTime() / 1000 @@ -217,6 +220,19 @@ class MediaMediaItem(MediaManagerItem): item_name.setToolTip(track) self.listView.addItem(item_name) + def getList(self, type=MediaType.Audio): + media = SettingsManager.load_list(self.settingsSection, u'media') + media.sort(cmp=locale.strcoll, + key=lambda filename: os.path.split(unicode(filename))[1].lower()) + ext = [] + if type == MediaType.Audio: + ext = self.plugin.audio_extensions_list + else: + ext = self.plugin.video_extensions_list + ext = map(lambda x: x[1:], ext) + media = filter(lambda x: os.path.splitext(x)[1] in ext, media) + return media + def createPhonon(self): log.debug(u'CreatePhonon') if not self.mediaObject: diff --git a/openlp/plugins/songs/forms/__init__.py b/openlp/plugins/songs/forms/__init__.py index 0c2434275..d82e3dea3 100644 --- a/openlp/plugins/songs/forms/__init__.py +++ b/openlp/plugins/songs/forms/__init__.py @@ -52,6 +52,7 @@ them separate from the functionality, so that it is easier to recreate the GUI from the .ui files later if necessary. """ +from mediafilesform import MediaFilesForm from authorsform import AuthorsForm from topicsform import TopicsForm from songbookform import SongBookForm diff --git a/openlp/plugins/songs/forms/editsongdialog.py b/openlp/plugins/songs/forms/editsongdialog.py index 13fcd047c..469716f6b 100644 --- a/openlp/plugins/songs/forms/editsongdialog.py +++ b/openlp/plugins/songs/forms/editsongdialog.py @@ -37,9 +37,11 @@ class Ui_EditSongDialog(object): editSongDialog.setObjectName(u'editSongDialog') editSongDialog.resize(650, 400) editSongDialog.setWindowIcon( - build_icon(u':/icon/openlp.org-icon-32.bmp')) + build_icon(u':/icon/openlp-logo-16x16.png')) editSongDialog.setModal(True) self.dialogLayout = QtGui.QVBoxLayout(editSongDialog) + self.dialogLayout.setSpacing(8) + self.dialogLayout.setContentsMargins(8, 8, 8, 8) self.dialogLayout.setObjectName(u'dialogLayout') self.songTabWidget = QtGui.QTabWidget(editSongDialog) self.songTabWidget.setObjectName(u'songTabWidget') diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 763d94e8a..73ab7726b 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -30,10 +30,10 @@ import re from PyQt4 import QtCore, QtGui -from openlp.core.lib import Receiver, translate +from openlp.core.lib import PluginStatus, Receiver, MediaType, translate from openlp.core.lib.ui import UiStrings, add_widget_completer, \ critical_error_message_box, find_and_set_in_combo_box -from openlp.plugins.songs.forms import EditVerseForm +from openlp.plugins.songs.forms import EditVerseForm, MediaFilesForm from openlp.plugins.songs.lib import SongXML, VerseType, clean_song from openlp.plugins.songs.lib.db import Book, Song, Author, Topic from openlp.plugins.songs.lib.ui import SongStrings @@ -95,6 +95,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked) QtCore.QObject.connect(self.audioAddFromFileButton, QtCore.SIGNAL(u'clicked()'), self.onAudioAddFromFileButtonClicked) + QtCore.QObject.connect(self.audioAddFromMediaButton, + QtCore.SIGNAL(u'clicked()'), self.onAudioAddFromMediaButtonClicked) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_list'), self.loadThemes) self.previewButton = QtGui.QPushButton() @@ -106,12 +108,14 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onPreview) # Create other objects and forms self.manager = manager - self.verse_form = EditVerseForm(self) + self.verseForm = EditVerseForm(self) + self.mediaForm = MediaFilesForm(self) self.initialise() self.authorsListView.setSortingEnabled(False) self.authorsListView.setAlternatingRowColors(True) self.topicsListView.setSortingEnabled(False) self.topicsListView.setAlternatingRowColors(True) + self.audioListWidget.setAlternatingRowColors(True) self.findVerseSplit = re.compile(u'---\[\]---\n', re.UNICODE) self.whitespace = re.compile(r'\W+', re.UNICODE) @@ -163,6 +167,15 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.themes.append(theme) add_widget_completer(self.themes, self.themeComboBox) + def loadMediaFiles(self): + self.audioAddFromMediaButton.setVisible(False) + for plugin in self.parent().pluginManager.plugins: + if plugin.name == u'media' and plugin.status == PluginStatus.Active: + self.audioAddFromMediaButton.setVisible(True) + self.mediaForm.populateFiles( + plugin.getMediaManagerItem().getList(MediaType.Audio)) + break + def newSong(self): log.debug(u'New Song') self.song = None @@ -183,6 +196,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.loadAuthors() self.loadTopics() self.loadBooks() + self.loadMediaFiles() self.themeComboBox.setCurrentIndex(0) # it's a new song to preview is not possible self.previewButton.setVisible(False) @@ -203,6 +217,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.loadAuthors() self.loadTopics() self.loadBooks() + self.loadMediaFiles() self.song = self.manager.get_object(Song, id) self.titleEdit.setText(self.song.title) if self.song.alternate_title: @@ -684,6 +699,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): for filename in filenames: self.audioListWidget.addItem(filename) + def onAudioAddFromMediaButtonClicked(self): + """ + Loads file(s) from the media plugin. + """ + self.mediaForm.exec_() + def onUpButtonClicked(self): pass diff --git a/openlp/plugins/songs/forms/mediafilesdialog.py b/openlp/plugins/songs/forms/mediafilesdialog.py new file mode 100644 index 000000000..252dac5ff --- /dev/null +++ b/openlp/plugins/songs/forms/mediafilesdialog.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import translate, build_icon + +class Ui_MediaFilesDialog(object): + def setupUi(self, mediaFilesDialog): + mediaFilesDialog.setObjectName(u'mediaFilesDialog') + mediaFilesDialog.setWindowModality(QtCore.Qt.ApplicationModal) + mediaFilesDialog.resize(400, 300) + mediaFilesDialog.setModal(True) + mediaFilesDialog.setWindowIcon( + build_icon(u':/icon/openlp-logo-16x16.png')) + self.filesVerticalLayout = QtGui.QVBoxLayout(mediaFilesDialog) + self.filesVerticalLayout.setSpacing(8) + self.filesVerticalLayout.setMargin(8) + self.filesVerticalLayout.setObjectName(u'filesVerticalLayout') + self.selectLabel = QtGui.QLabel(mediaFilesDialog) + self.selectLabel.setWordWrap(True) + self.selectLabel.setObjectName(u'selectLabel') + self.filesVerticalLayout.addWidget(self.selectLabel) + self.fileListWidget = QtGui.QListWidget(mediaFilesDialog) + self.fileListWidget.setAlternatingRowColors(True) + self.fileListWidget.setSelectionMode( + QtGui.QAbstractItemView.ExtendedSelection) + self.fileListWidget.setObjectName(u'fileListWidget') + self.filesVerticalLayout.addWidget(self.fileListWidget) + self.buttonBox = QtGui.QDialogButtonBox(mediaFilesDialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons( + QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName(u'buttonBox') + self.filesVerticalLayout.addWidget(self.buttonBox) + + self.retranslateUi(mediaFilesDialog) + QtCore.QObject.connect(self.buttonBox, + QtCore.SIGNAL(u'accepted()'), mediaFilesDialog.accept) + QtCore.QObject.connect(self.buttonBox, + QtCore.SIGNAL(u'rejected()'), mediaFilesDialog.reject) + QtCore.QMetaObject.connectSlotsByName(mediaFilesDialog) + + def retranslateUi(self, mediaFilesDialog): + mediaFilesDialog.setWindowTitle( + translate('SongsPlugin.MediaFilesForm', 'Select Media File(s)')) + self.selectLabel.setText( + translate('SongsPlugin.MediaFilesForm', u'Select one or more ' + 'audio files from the list below, and click OK to import them ' + 'into this song.')) + diff --git a/openlp/plugins/songs/forms/mediafilesform.py b/openlp/plugins/songs/forms/mediafilesform.py new file mode 100644 index 000000000..4ff58b454 --- /dev/null +++ b/openlp/plugins/songs/forms/mediafilesform.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +import logging +import os + +from PyQt4 import QtCore, QtGui + +from mediafilesdialog import Ui_MediaFilesDialog + +log = logging.getLogger(__name__) + +class MediaFilesForm(QtGui.QDialog, Ui_MediaFilesDialog): + """ + Class to show a list of files from the + """ + log.info(u'%s MediaFilesForm loaded', __name__) + + def __init__(self, parent): + QtGui.QDialog.__init__(self) + self.setupUi(self) + + def populateFiles(self, files): + self.fileListWidget.clear() + for file in files: + item = QtGui.QListWidgetItem(os.path.split(file)[1]) + item.setData(QtCore.Qt.UserRole, file) + self.fileListWidget.addItem(item) + + def getSelectedFiles(self): + return [] + diff --git a/resources/forms/mediafilesdialog.ui b/resources/forms/mediafilesdialog.ui new file mode 100644 index 000000000..427e27548 --- /dev/null +++ b/resources/forms/mediafilesdialog.ui @@ -0,0 +1,95 @@ + + + MediaFilesDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 400 + 300 + + + + Select Media File(s) + + + true + + + + 8 + + + 8 + + + + + Select one or more audio files from the list below, and click OK to import them into this song. + + + true + + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + MediaFilesDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MediaFilesDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +