Merge lp:~tomasgroth/openlp/bugfixes9 into lp:openlp

Proposed by Tomas Groth
Status: Merged
Merged at revision: 2454
Proposed branch: lp:~tomasgroth/openlp/bugfixes9
Merge into: lp:openlp
Diff against target: 255 lines (+74/-25)
9 files modified
openlp/core/lib/serviceitem.py (+7/-2)
openlp/core/ui/servicemanager.py (+1/-2)
openlp/core/ui/slidecontroller.py (+14/-9)
openlp/plugins/presentations/lib/pdfcontroller.py (+3/-9)
openlp/plugins/songs/lib/mediaitem.py (+12/-0)
openlp/plugins/songs/songsplugin.py (+1/-1)
tests/functional/openlp_core_lib/test_serviceitem.py (+34/-1)
tests/resources/service/serviceitem-song-linked-audio.osj (+1/-0)
tests/utils/osdinteraction.py (+1/-1)
To merge this branch: bzr merge lp:~tomasgroth/openlp/bugfixes9
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tim Bentley Approve
Review via email: mp+243901@code.launchpad.net

This proposal supersedes a proposal from 2014-12-05.

Description of the change

Added a refresh call to the hide-toolbar so that it gets updated if needed. Makes the blank-to-theme button visible in the toolbar.
Fix for loading songs with linked audio + test. Fixes bug 1398403
Remove dummy initialization of preview_display to solve issue of mediaplayer preview being hidden.
When cloning a song copy the mediafiles as well. Fixes bug 1309998.
Use shutil.which instead of calling which with check_output, when detecting mudraw/gs.
Moved test service files into appropriate folder.
Set the default song search to search as type.

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

One minor nit pick

review: Needs Fixing
Revision history for this message
Tomas Groth (tomasgroth) wrote :
Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/lib/serviceitem.py'
2--- openlp/core/lib/serviceitem.py 2014-09-23 21:45:42 +0000
3+++ openlp/core/lib/serviceitem.py 2014-12-06 21:11:25 +0000
4@@ -36,6 +36,7 @@
5 import logging
6 import os
7 import uuid
8+import ntpath
9
10 from PyQt4 import QtGui
11
12@@ -423,8 +424,12 @@
13 if 'background_audio' in header:
14 self.background_audio = []
15 for filename in header['background_audio']:
16- # Give them real file paths
17- self.background_audio.append(os.path.join(path, filename))
18+ # Give them real file paths.
19+ filepath = filename
20+ if path:
21+ # Windows can handle both forward and backward slashes, so we use ntpath to get the basename
22+ filepath = os.path.join(path, ntpath.basename(filename))
23+ self.background_audio.append(filepath)
24 self.theme_overwritten = header.get('theme_overwritten', False)
25 if self.service_item_type == ServiceItemType.Text:
26 for slide in service_item['serviceitem']['data']:
27
28=== modified file 'openlp/core/ui/servicemanager.py'
29--- openlp/core/ui/servicemanager.py 2014-11-11 11:34:47 +0000
30+++ openlp/core/ui/servicemanager.py 2014-12-06 21:11:25 +0000
31@@ -747,8 +747,7 @@
32 'File is not a valid service.\n The content encoding is not UTF-8.'))
33 continue
34 os_file = ucs_file.replace('/', os.path.sep)
35- if not os_file.startswith('audio'):
36- os_file = os.path.split(os_file)[1]
37+ os_file = os.path.basename(os_file)
38 self.log_debug('Extract file: %s' % os_file)
39 zip_info.filename = os_file
40 zip_file.extract(zip_info, self.service_path)
41
42=== modified file 'openlp/core/ui/slidecontroller.py'
43--- openlp/core/ui/slidecontroller.py 2014-11-13 11:21:54 +0000
44+++ openlp/core/ui/slidecontroller.py 2014-12-06 21:11:25 +0000
45@@ -141,6 +141,7 @@
46 self.slide_list = {}
47 self.slide_count = 0
48 self.slide_image = None
49+ self.controller_width = -1
50 # Layout for holding panel
51 self.panel_layout = QtGui.QVBoxLayout(self.panel)
52 self.panel_layout.setSpacing(0)
53@@ -331,9 +332,6 @@
54 self.slide_layout.setMargin(0)
55 self.slide_layout.setObjectName('SlideLayout')
56 self.preview_display = Display(self)
57- self.preview_display.setGeometry(QtCore.QRect(0, 0, 300, 300))
58- self.preview_display.screen = {'size': self.preview_display.geometry()}
59- self.preview_display.setup()
60 self.slide_layout.insertWidget(0, self.preview_display)
61 self.preview_display.hide()
62 # Actual preview screen
63@@ -382,13 +380,11 @@
64 Registry().register_function('slidecontroller_live_spin_delay', self.receive_spin_delay)
65 self.toolbar.set_widget_visible(LOOP_LIST, False)
66 self.toolbar.set_widget_visible(WIDE_MENU, False)
67+ self.set_live_hot_keys(self)
68+ self.__add_actions_to_widget(self.controller)
69 else:
70 self.preview_widget.doubleClicked.connect(self.on_preview_add_to_service)
71 self.toolbar.set_widget_visible(['editSong'], False)
72- if self.is_live:
73- self.set_live_hot_keys(self)
74- self.__add_actions_to_widget(self.controller)
75- else:
76 self.controller.addActions([self.next_item, self.previous_item])
77 Registry().register_function('slidecontroller_%s_stop_loop' % self.type_prefix, self.on_stop_loop)
78 Registry().register_function('slidecontroller_%s_change' % self.type_prefix, self.on_slide_change)
79@@ -599,7 +595,10 @@
80 self.slide_preview.setFixedSize(QtCore.QSize(max_width, max_width / self.ratio))
81 self.preview_display.setFixedSize(QtCore.QSize(max_width, max_width / self.ratio))
82 self.preview_display.screen = {'size': self.preview_display.geometry()}
83- self.on_controller_size_changed(self.controller.width())
84+ # Only update controller layout if width has actually changed
85+ if self.controller_width != self.controller.width():
86+ self.controller_width = self.controller.width()
87+ self.on_controller_size_changed(self.controller_width)
88
89 def on_controller_size_changed(self, width):
90 """
91@@ -618,6 +617,10 @@
92 elif width < used_space - HIDE_MENU_THRESHOLD and not self.hide_menu.isVisible():
93 self.set_blank_menu(False)
94 self.toolbar.set_widget_visible(NARROW_MENU)
95+ # Fallback to the standard blank toolbar if the hide_menu is not visible.
96+ elif not self.hide_menu.isVisible():
97+ self.toolbar.set_widget_visible(NARROW_MENU, False)
98+ self.set_blank_menu()
99
100 def set_blank_menu(self, visible=True):
101 """
102@@ -692,7 +695,9 @@
103 self.mediabar.show()
104 self.previous_item.setVisible(not item.is_media())
105 self.next_item.setVisible(not item.is_media())
106- # The layout of the toolbar is size dependent, so make sure it fits
107+ # The layout of the toolbar is size dependent, so make sure it fits. Reset stored controller_width.
108+ if self.is_live:
109+ self.controller_width = -1
110 self.on_controller_size_changed(self.controller.width())
111 # Work-around for OS X, hide and then show the toolbar
112 # See bug #791050
113
114=== modified file 'openlp/plugins/presentations/lib/pdfcontroller.py'
115--- openlp/plugins/presentations/lib/pdfcontroller.py 2014-10-14 09:05:35 +0000
116+++ openlp/plugins/presentations/lib/pdfcontroller.py 2014-12-06 21:11:25 +0000
117@@ -31,6 +31,7 @@
118 import logging
119 from tempfile import NamedTemporaryFile
120 import re
121+from shutil import which
122 from subprocess import check_output, CalledProcessError, STDOUT
123
124 from openlp.core.utils import AppLocation
125@@ -144,17 +145,10 @@
126 else:
127 DEVNULL = open(os.devnull, 'wb')
128 # First try to find mupdf
129- try:
130- self.mudrawbin = check_output(['which', 'mudraw'],
131- stderr=DEVNULL).decode(encoding='UTF-8').rstrip('\n')
132- except CalledProcessError:
133- self.mudrawbin = ''
134+ self.mudrawbin = which('mudraw')
135 # if mupdf isn't installed, fallback to ghostscript
136 if not self.mudrawbin:
137- try:
138- self.gsbin = check_output(['which', 'gs'], stderr=DEVNULL).decode(encoding='UTF-8').rstrip('\n')
139- except CalledProcessError:
140- self.gsbin = ''
141+ self.gsbin = which('gs')
142 # Last option: check if mudraw is placed in OpenLP base folder
143 if not self.mudrawbin and not self.gsbin:
144 application_path = AppLocation.get_directory(AppLocation.AppDir)
145
146=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
147--- openlp/plugins/songs/lib/mediaitem.py 2014-11-12 22:18:57 +0000
148+++ openlp/plugins/songs/lib/mediaitem.py 2014-12-06 21:11:25 +0000
149@@ -395,6 +395,18 @@
150 new_song = self.open_lyrics.xml_to_song(song_xml)
151 new_song.title = '%s <%s>' % \
152 (new_song.title, translate('SongsPlugin.MediaItem', 'copy', 'For song cloning'))
153+ # Copy audio files from the old to the new song
154+ if len(old_song.media_files) > 0:
155+ save_path = os.path.join(AppLocation.get_section_data_path(self.plugin.name), 'audio', str(new_song.id))
156+ check_directory_exists(save_path)
157+ for media_file in old_song.media_files:
158+ new_media_file_name = os.path.join(save_path, os.path.basename(media_file.file_name))
159+ shutil.copyfile(media_file.file_name, new_media_file_name)
160+ new_media_file = MediaFile()
161+ new_media_file.file_name = new_media_file_name
162+ new_media_file.type = media_file.type
163+ new_media_file.weight = media_file.weight
164+ new_song.media_files.append(new_media_file)
165 self.plugin.manager.save_object(new_song)
166 self.on_song_list_load()
167
168
169=== modified file 'openlp/plugins/songs/songsplugin.py'
170--- openlp/plugins/songs/songsplugin.py 2014-11-09 00:41:30 +0000
171+++ openlp/plugins/songs/songsplugin.py 2014-12-06 21:11:25 +0000
172@@ -60,7 +60,7 @@
173 'songs/last search type': SongSearch.Entire,
174 'songs/last import type': SongFormat.OpenLyrics,
175 'songs/update service on edit': False,
176- 'songs/search as type': False,
177+ 'songs/search as type': True,
178 'songs/add song from service': True,
179 'songs/display songbar': True,
180 'songs/display songbook': False,
181
182=== modified file 'tests/functional/openlp_core_lib/test_serviceitem.py'
183--- tests/functional/openlp_core_lib/test_serviceitem.py 2014-09-23 21:45:42 +0000
184+++ tests/functional/openlp_core_lib/test_serviceitem.py 2014-12-06 21:11:25 +0000
185@@ -46,7 +46,7 @@
186 '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\
187 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
188 FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
189-TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
190+TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources', 'service'))
191
192
193 class TestServiceItem(TestCase):
194@@ -271,3 +271,36 @@
195 self.assertEqual(service_item.start_time, 654.375, 'Start time should be 654.375')
196 self.assertEqual(service_item.end_time, 672.069, 'End time should be 672.069')
197 self.assertEqual(service_item.media_length, 17.694, 'Media length should be 17.694')
198+
199+ def service_item_load_song_and_audio_from_service_test(self):
200+ """
201+ Test the Service Item - adding a song slide from a saved service
202+ """
203+ # GIVEN: A new service item and a mocked add icon function
204+ service_item = ServiceItem(None)
205+ service_item.add_icon = MagicMock()
206+
207+ # WHEN: We add a custom from a saved service
208+ line = convert_file_service_item(TEST_PATH, 'serviceitem-song-linked-audio.osj')
209+ service_item.set_from_service(line, '/test/')
210+
211+ # THEN: We should get back a valid service item
212+ self.assertTrue(service_item.is_valid, 'The new service item should be valid')
213+ assert_length(0, service_item._display_frames, 'The service item should have no display frames')
214+ assert_length(7, service_item.capabilities, 'There should be 7 default custom item capabilities')
215+
216+ # WHEN: We render the frames of the service item
217+ service_item.render(True)
218+
219+ # THEN: The frames should also be valid
220+ self.assertEqual('Amazing Grace', service_item.get_display_title(), 'The title should be "Amazing Grace"')
221+ self.assertEqual(VERSE[:-1], service_item.get_frames()[0]['text'],
222+ 'The returned text matches the input, except the last line feed')
223+ self.assertEqual(VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
224+ 'The first line has been returned')
225+ self.assertEqual('Amazing Grace! how sweet the s', service_item.get_frame_title(0),
226+ '"Amazing Grace! how sweet the s" has been returned as the title')
227+ self.assertEqual('’Twas grace that taught my hea', service_item.get_frame_title(1),
228+ '"’Twas grace that taught my hea" has been returned as the title')
229+ self.assertEqual('/test/amazing_grace.mp3', service_item.background_audio[0],
230+ '"/test/amazing_grace.mp3" should be in the background_audio list')
231
232=== renamed file 'tests/resources/migrate_video_20_22.osd' => 'tests/resources/service/migrate_video_20_22.osd'
233=== renamed file 'tests/resources/serviceitem-dvd.osj' => 'tests/resources/service/serviceitem-dvd.osj'
234=== added file 'tests/resources/service/serviceitem-song-linked-audio.osj'
235--- tests/resources/service/serviceitem-song-linked-audio.osj 1970-01-01 00:00:00 +0000
236+++ tests/resources/service/serviceitem-song-linked-audio.osj 2014-12-06 21:11:25 +0000
237@@ -0,0 +1,1 @@
238+[{"serviceitem": {"header": {"will_auto_start": false, "title": "Amazing Grace", "audit": ["Amazing Grace", ["John Newton"], "", ""], "processor": null, "theme_overwritten": false, "start_time": 0, "auto_play_slides_loop": false, "plugin": "songs", "auto_play_slides_once": false, "from_plugin": false, "media_length": 0, "xml_version": "<?xml version='1.0' encoding='UTF-8'?>\n<song xmlns=\"http://openlyrics.info/namespace/2009/song\" version=\"0.8\" createdIn=\"OpenLP 2.1.0\" modifiedIn=\"OpenLP 2.1.0\" modifiedDate=\"2014-12-03T21:31:35\"><properties><titles><title>Amazing Grace</title></titles><authors><author>John Newton</author></authors></properties><lyrics><verse name=\"v1\"><lines>Amazing Grace! how sweet the sound<br/>That saved a wretch like me;<br/>I once was lost, but now am found,<br/>Was blind, but now I see.</lines></verse><verse name=\"v2\"><lines>\u2019Twas grace that taught my heart to fear,<br/>And grace my fears relieved;<br/>How precious did that grace appear,<br/>The hour I first believed!</lines></verse><verse name=\"v3\"><lines>Through many dangers, toils and snares<br/>I have already come;<br/>\u2019Tis grace that brought me safe thus far,<br/>And grace will lead me home.</lines></verse><verse name=\"v4\"><lines>The Lord has promised good to me,<br/>His word my hope secures;<br/>He will my shield and portion be<br/>As long as life endures.</lines></verse><verse name=\"v5\"><lines>Yes, when this heart and flesh shall fail,<br/>And mortal life shall cease,<br/>I shall possess within the veil<br/>A life of joy and peace.</lines></verse><verse name=\"v6\"><lines>When we\u2019ve been there a thousand years,<br/>Bright shining as the sun,<br/>We\u2019ve no less days to sing God\u2019s praise<br/>Than when we first begun.</lines></verse></lyrics></song>", "timed_slide_interval": 0, "data": {"title": "amazing grace@", "authors": "John Newton"}, "type": 1, "background_audio": ["/home/tgc/.local/share/openlp/songs/audio/7/amazing_grace.mp3"], "theme": null, "footer": ["Amazing Grace", "Written by: John Newton"], "name": "songs", "capabilities": [2, 1, 5, 8, 9, 13, 15], "end_time": 0, "notes": "", "search": "", "icon": ":/plugins/plugin_songs.png"}, "data": [{"title": "Amazing Grace! how sweet the s", "verseTag": "V1", "raw_slide": "Amazing Grace! how sweet the sound\nThat saved a wretch like me;\nI once was lost, but now am found,\nWas blind, but now I see."}, {"title": "\u2019Twas grace that taught my hea", "verseTag": "V2", "raw_slide": "\u2019Twas grace that taught my heart to fear,\nAnd grace my fears relieved;\nHow precious did that grace appear,\nThe hour I first believed!"}, {"title": "Through many dangers, toils an", "verseTag": "V3", "raw_slide": "Through many dangers, toils and snares\nI have already come;\n\u2019Tis grace that brought me safe thus far,\nAnd grace will lead me home."}, {"title": "The Lord has promised good to ", "verseTag": "V4", "raw_slide": "The Lord has promised good to me,\nHis word my hope secures;\nHe will my shield and portion be\nAs long as life endures."}, {"title": "Yes, when this heart and flesh", "verseTag": "V5", "raw_slide": "Yes, when this heart and flesh shall fail,\nAnd mortal life shall cease,\nI shall possess within the veil\nA life of joy and peace."}, {"title": "When we\u2019ve been there a thousa", "verseTag": "V6", "raw_slide": "When we\u2019ve been there a thousand years,\nBright shining as the sun,\nWe\u2019ve no less days to sing God\u2019s praise\nThan when we first begun."}]}}]
239
240=== renamed file 'tests/resources/serviceitem_custom_1.osj' => 'tests/resources/service/serviceitem_custom_1.osj'
241=== renamed file 'tests/resources/serviceitem_image_1.osj' => 'tests/resources/service/serviceitem_image_1.osj'
242=== renamed file 'tests/resources/serviceitem_image_2.osj' => 'tests/resources/service/serviceitem_image_2.osj'
243=== renamed file 'tests/resources/serviceitem_image_3.osj' => 'tests/resources/service/serviceitem_image_3.osj'
244=== modified file 'tests/utils/osdinteraction.py'
245--- tests/utils/osdinteraction.py 2013-12-24 08:56:50 +0000
246+++ tests/utils/osdinteraction.py 2014-12-06 21:11:25 +0000
247@@ -42,7 +42,7 @@
248 @param file_name: File name of an OSD file residing in the tests/resources folder.
249 @return: The service contained in the file.
250 """
251- service_file = os.path.join(TEST_RESOURCES_PATH, file_name)
252+ service_file = os.path.join(TEST_RESOURCES_PATH, 'service', file_name)
253 with open(service_file, 'r') as open_file:
254 service = json.load(open_file)
255 return service