From f609be65bceebdab81dcf95d90151ac199b2e971 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 12 Nov 2014 21:20:57 +0000 Subject: [PATCH 1/6] Make the settingswindow higher to make room for the new settings. Fixes: https://launchpad.net/bugs/1377283 --- openlp/core/ui/settingsdialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/settingsdialog.py b/openlp/core/ui/settingsdialog.py index ab5931584..61ee10e14 100644 --- a/openlp/core/ui/settingsdialog.py +++ b/openlp/core/ui/settingsdialog.py @@ -46,7 +46,7 @@ class Ui_SettingsDialog(object): """ settings_dialog.setObjectName('settings_dialog') settings_dialog.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) - settings_dialog.resize(800, 500) + settings_dialog.resize(800, 700) self.dialog_layout = QtGui.QGridLayout(settings_dialog) self.dialog_layout.setObjectName('dialog_layout') self.dialog_layout.setMargin(8) From b7e3a33c4ac33fc815be7839588ac6657184aaa5 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 12 Nov 2014 22:18:57 +0000 Subject: [PATCH 2/6] Mark a song edited from preview as coming from plugin. Fixes bug 1382672 Fixes: https://launchpad.net/bugs/1382672 --- openlp/plugins/songs/lib/mediaitem.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 33c4f2e53..18d964115 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -339,6 +339,9 @@ class SongMediaItem(MediaManagerItem): self.remote_song = -1 self.remote_triggered = None if item: + if preview: + # A song can only be edited if it comes from plugin, so we set it again for the new item. + item.from_plugin = True return item return None From 28599c8f245a7dcd104bdde3ade95e66452f4e12 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 13 Nov 2014 11:26:44 +0100 Subject: [PATCH 3/6] Make sure that the slidecontroller toolbar layout is correctly adjusted to fit its size. Fixes bug 1387304 Fixes: https://launchpad.net/bugs/1387304 --- openlp/core/ui/slidecontroller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index d12506452..dfc7db2d8 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -691,7 +691,8 @@ class SlideController(DisplayController, RegistryProperties): self.mediabar.show() self.previous_item.setVisible(not item.is_media()) self.next_item.setVisible(not item.is_media()) - self.set_blank_menu() + # The layout of the toolbar is size dependent, so make sure it fits + self.on_controller_size_changed(self.controller.width()) # Work-around for OS X, hide and then show the toolbar # See bug #791050 self.toolbar.show() From ed13dcbd75b87bbe333873a4ba306e923a4c16b7 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 13 Nov 2014 12:21:54 +0100 Subject: [PATCH 4/6] Only show slide-dropdown on live-slidecontroller when it is populated. Fixes bug 1390238. Fixes: https://launchpad.net/bugs/1390238 --- openlp/core/ui/slidecontroller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index dfc7db2d8..85fe240d4 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -683,7 +683,8 @@ class SlideController(DisplayController, RegistryProperties): self.play_slides_loop.setChecked(False) self.play_slides_loop.setIcon(build_icon(':/media/media_time.png')) if item.is_text(): - if Settings().value(self.main_window.songs_settings_section + '/display songbar') and self.slide_list: + if (Settings().value(self.main_window.songs_settings_section + '/display songbar') + and not self.song_menu.menu().isEmpty()): self.toolbar.set_widget_visible(['song_menu'], True) if item.is_capable(ItemCapabilities.CanLoop) and len(item.get_frames()) > 1: self.toolbar.set_widget_visible(LOOP_LIST) From 571b50f016e4bb7df450ec89cd51fc1618461b13 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 15 Nov 2014 22:38:36 +0000 Subject: [PATCH 5/6] Fix for overwriting files on song export. Fixes bug 1216232 Fixes: https://launchpad.net/bugs/1216232 --- openlp/plugins/songs/lib/openlyricsexport.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index 0458b893b..84647dbee 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -75,9 +75,14 @@ class OpenLyricsExport(RegistryProperties): filename = '%s (%s)' % (song.title, ', '.join([author.display_name for author in song.authors])) filename = clean_filename(filename) # Ensure the filename isn't too long for some filesystems - filename = '%s.xml' % filename[0:250 - len(self.save_path)] + filename_with_ext = '%s.xml' % filename[0:250 - len(self.save_path)] + # Make sure we're not overwriting an existing file + conflicts = 0 + while os.path.exists(os.path.join(self.save_path, filename_with_ext)): + conflicts += 1 + filename_with_ext = '%s-%d.xml' % (filename[0:247 - len(self.save_path)], conflicts) # Pass a file object, because lxml does not cope with some special # characters in the path (see lp:757673 and lp:744337). - tree.write(open(os.path.join(self.save_path, filename), 'wb'), encoding='utf-8', xml_declaration=True, - pretty_print=True) + tree.write(open(os.path.join(self.save_path, filename_with_ext), 'wb'), encoding='utf-8', + xml_declaration=True, pretty_print=True) return True From c85f49a16c8a1d95b849c1135c3d36f9a6647b54 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 16 Nov 2014 22:44:44 +0000 Subject: [PATCH 6/6] Added test for openlyrics export of songs with same title and author --- .../songs/test_openlyricsexport.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/functional/openlp_plugins/songs/test_openlyricsexport.py diff --git a/tests/functional/openlp_plugins/songs/test_openlyricsexport.py b/tests/functional/openlp_plugins/songs/test_openlyricsexport.py new file mode 100644 index 000000000..df28db035 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_openlyricsexport.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# 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, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the OpenLyrics song importer. +""" + +import os +import shutil +from unittest import TestCase +from tempfile import mkdtemp + +from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin +from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport +from openlp.core.common import Registry + + +class TestOpenLyricsExport(TestCase, TestMixin): + """ + Test the functions in the :mod:`openlyricsexport` module. + """ + def setUp(self): + """ + Create the registry + """ + Registry.create() + self.temp_folder = mkdtemp() + + def tearDown(self): + """ + Cleanup + """ + shutil.rmtree(self.temp_folder) + + def export_same_filename_test(self): + """ + Test that files is not overwritten if songs has same title and author + """ + # GIVEN: A mocked song_to_xml, 2 mocked songs, a mocked application and an OpenLyricsExport instance + with patch('openlp.plugins.songs.lib.openlyricsexport.OpenLyrics.song_to_xml') as mocked_song_to_xml: + mocked_song_to_xml.return_value = '\n' + author = MagicMock() + author.display_name = 'Test Author' + song = MagicMock() + song.authors = [author] + song.title = 'Test Title' + parent = MagicMock() + parent.stop_export_flag = False + mocked_application_object = MagicMock() + Registry().register('application', mocked_application_object) + ol_export = OpenLyricsExport(parent, [song, song], self.temp_folder) + + # WHEN: Doing the export + ol_export.do_export() + + # THEN: The exporter should have created 2 files + self.assertTrue(os.path.exists(os.path.join(self.temp_folder, + '%s (%s).xml' % (song.title, author.display_name)))) + self.assertTrue(os.path.exists(os.path.join(self.temp_folder, + '%s (%s)-1.xml' % (song.title, author.display_name))))