← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~arjan-i/openlp/images_groups_bugfix into lp:openlp

 

Arjan Schrijver has proposed merging lp:~arjan-i/openlp/images_groups_bugfix into lp:openlp.

Requested reviews:
  Andreas Preikschat (googol)

For more details, see:
https://code.launchpad.net/~arjan-i/openlp/images_groups_bugfix/+merge/156165

- Fixed traceback on canceling the 'choose group' dialog
- Clear the 'new group' lineedit in the 'choose group' dialog
- Fixed traceback on adding multiple image groups to the service in one go
- Cleaned up obsolete line in imagetab
- Added a simple test for onResetClick()
- Added a test for recursively_delete_group()


Note: please look at the change in core/lib/mediamanageritem.py carefully. I'm not sure if this could break something, although everything still works fine in my tests.
-- 
https://code.launchpad.net/~arjan-i/openlp/images_groups_bugfix/+merge/156165
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py	2013-03-23 06:46:41 +0000
+++ openlp/core/lib/mediamanageritem.py	2013-03-29 14:15:28 +0000
@@ -464,7 +464,7 @@
                 translate('OpenLP.MediaManagerItem', 'You must select one or more items to preview.'))
         else:
             log.debug(u'%s Preview requested', self.plugin.name)
-            service_item = self.build_service_item()
+            service_item = self.build_service_item(context=ServiceItemContext.Preview)
             if service_item:
                 service_item.from_plugin = True
                 self.preview_controller.add_service_item(service_item)

=== modified file 'openlp/plugins/images/forms/choosegroupform.py'
--- openlp/plugins/images/forms/choosegroupform.py	2013-03-18 13:43:45 +0000
+++ openlp/plugins/images/forms/choosegroupform.py	2013-03-29 14:15:28 +0000
@@ -50,6 +50,7 @@
         ``selected_group``
             The ID of the group that should be selected by default when showing the dialog
         """
+        self.new_group_edit.clear()
         if selected_group is not None:
             for i in range(self.group_combobox.count()):
                 if self.group_combobox.itemData(i) == selected_group:

=== modified file 'openlp/plugins/images/lib/imagetab.py'
--- openlp/plugins/images/lib/imagetab.py	2013-03-18 14:11:58 +0000
+++ openlp/plugins/images/lib/imagetab.py	2013-03-29 14:15:28 +0000
@@ -32,7 +32,6 @@
 from openlp.core.lib import Registry, SettingsTab, Settings, UiStrings, translate
 
 
-
 class ImageTab(SettingsTab):
     """
     ImageTab is the images settings tab in the settings dialog.

=== modified file 'openlp/plugins/images/lib/mediaitem.py'
--- openlp/plugins/images/lib/mediaitem.py	2013-03-23 07:07:06 +0000
+++ openlp/plugins/images/lib/mediaitem.py	2013-03-29 14:15:28 +0000
@@ -32,7 +32,7 @@
 
 from PyQt4 import QtCore, QtGui
 
-from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, Settings, \
+from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItem, ServiceItemContext, Settings, \
     StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_directory_exists, check_item_selected, \
     create_thumb, translate, validate_thumb
 from openlp.core.lib.ui import create_widget_action, critical_error_message_box
@@ -394,6 +394,7 @@
         ``initial_load``
             When set to False, the busy cursor and progressbar will be shown while loading images
         """
+        parent_group = None
         if target_group is None:
             # Find out if a group must be pre-selected
             preselect_group = None
@@ -537,63 +538,76 @@
         """
         background = QtGui.QColor(Settings().value(self.settings_section + u'/background color'))
         if item:
-            items = [item]
+            new_items = [item]
         else:
-            items = self.list_view.selectedItems()
-            if not items:
+            new_items = self.list_view.selectedItems()
+            if not new_items:
                 return False
-        # Determine service item title
-        if isinstance(items[0].data(0, QtCore.Qt.UserRole), ImageGroups):
-            service_item.title = items[0].text(0)
-        else:
-            service_item.title = unicode(self.plugin.name_strings[u'plural'])
-        service_item.add_capability(ItemCapabilities.CanMaintain)
-        service_item.add_capability(ItemCapabilities.CanPreview)
-        service_item.add_capability(ItemCapabilities.CanLoop)
-        service_item.add_capability(ItemCapabilities.CanAppend)
-        # force a nonexistent theme
-        service_item.theme = -1
-        missing_items = []
-        missing_items_filenames = []
-        # Expand groups to images
-        for bitem in items:
+        for bitem in new_items:
+            new_service_item = ServiceItem(self.plugin)
+            new_service_item.add_icon(self.plugin.icon_path)
+            # Determine service item title
+            if isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageGroups):
+                new_service_item.title = bitem.text(0)
+            else:
+                new_service_item.title = unicode(self.plugin.name_strings[u'plural'])
+            new_service_item.add_capability(ItemCapabilities.CanMaintain)
+            new_service_item.add_capability(ItemCapabilities.CanPreview)
+            new_service_item.add_capability(ItemCapabilities.CanLoop)
+            new_service_item.add_capability(ItemCapabilities.CanAppend)
+            # force a nonexistent theme
+            new_service_item.theme = -1
+            sub_images = []
+            missing_items = []
+            missing_items_filenames = []
+            # Expand groups to images
             if isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageGroups) or bitem.data(0, QtCore.Qt.UserRole) is None:
                 for index in range(0, bitem.childCount()):
                     if isinstance(bitem.child(index).data(0, QtCore.Qt.UserRole), ImageFilenames):
-                        items.append(bitem.child(index))
-                items.remove(bitem)
-        # Don't try to display empty groups
-        if not items:
-            return False
-        # Find missing files
-        for bitem in items:
-            filename = bitem.data(0, QtCore.Qt.UserRole).filename
-            if not os.path.exists(filename):
-                missing_items.append(bitem)
-                missing_items_filenames.append(filename)
-        for item in missing_items:
-            items.remove(item)
-        # We cannot continue, as all images do not exist.
-        if not items:
-            if not remote:
-                critical_error_message_box(
-                    translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
-                    translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s') %
-                        u'\n'.join(missing_items_filenames))
-            return False
-        # We have missing as well as existing images. We ask what to do.
-        elif missing_items and QtGui.QMessageBox.question(self,
-            translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
-            translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s\n'
-                'Do you want to add the other images anyway?') % u'\n'.join(missing_items_filenames),
-            QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
-            return False
-        # Continue with the existing images.
-        for bitem in items:
-            filename = bitem.data(0, QtCore.Qt.UserRole).filename
-            name = os.path.split(filename)[1]
-            service_item.add_from_image(filename, name, background)
-        return True
+                        sub_images.append(bitem.child(index))
+            if isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageFilenames):
+                sub_images.append(bitem)
+            # Don't try to display empty groups
+            if not sub_images:
+                return False
+            # Find missing files
+            for bitem in sub_images:
+                filename = bitem.data(0, QtCore.Qt.UserRole).filename
+                if not os.path.exists(filename):
+                    missing_items.append(bitem)
+                    missing_items_filenames.append(filename)
+            for item in missing_items:
+                sub_images.remove(item)
+            # We cannot continue, as all images do not exist.
+            if not sub_images:
+                if not remote:
+                    critical_error_message_box(
+                        translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
+                        translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s') %
+                            u'\n'.join(missing_items_filenames))
+                return False
+            # We have missing as well as existing images. We ask what to do.
+            elif missing_items and QtGui.QMessageBox.question(self,
+                translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
+                translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s\n'
+                    'Do you want to add the other images anyway?') % u'\n'.join(missing_items_filenames),
+                QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \
+                QtGui.QMessageBox.No:
+                return False
+            # Continue with the existing images.
+            for sub_image in sub_images:
+                filename = sub_image.data(0, QtCore.Qt.UserRole).filename
+                name = os.path.split(filename)[1]
+                new_service_item.add_from_image(filename, name, background)
+            # Add the service item to the correct controller
+            if context == ServiceItemContext.Service:
+                self.service_manager.add_service_item(new_service_item)
+            elif context == ServiceItemContext.Preview:
+                self.preview_controller.add_service_item(new_service_item)
+            elif context == ServiceItemContext.Live:
+                self.live_controller.add_service_item(new_service_item)
+        # Return False because we added the service item ourselves
+        return False
 
     def check_group_exists(self, new_group):
         """

=== modified file 'tests/functional/openlp_plugins/images/test_lib.py'
--- tests/functional/openlp_plugins/images/test_lib.py	2013-03-19 20:05:13 +0000
+++ tests/functional/openlp_plugins/images/test_lib.py	2013-03-29 14:15:28 +0000
@@ -9,7 +9,7 @@
 from mock import MagicMock, patch
 
 from openlp.core.lib import Registry
-from openlp.plugins.images.lib.db import ImageFilenames
+from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
 from openlp.plugins.images.lib.mediaitem import ImageMediaItem
 
 
@@ -23,6 +23,7 @@
         Registry.create()
         Registry().register(u'service_list', MagicMock())
         Registry().register(u'main_window', self.mocked_main_window)
+        Registry().register(u'live_controller', MagicMock())
         mocked_parent = MagicMock()
         mocked_plugin = MagicMock()
         with patch(u'openlp.plugins.images.lib.mediaitem.ImageMediaItem.__init__') as mocked_init:
@@ -110,3 +111,68 @@
             # THEN: loadFullList() should not have been called
             assert self.media_item.manager.save_object.call_count == 2, \
                 u'loadFullList() should have been called only once'
+
+    def on_reset_click_test(self):
+        """
+        Test that onResetClick() actually resets the background
+        """
+        # GIVEN: A mocked version of resetAction
+        self.media_item.resetAction = MagicMock()
+
+        # WHEN: onResetClick is called
+        self.media_item.onResetClick()
+
+        # THEN: the resetAction should be set visible, and the image should be reset
+        self.media_item.resetAction.setVisible.assert_called_with(False)
+        self.media_item.live_controller.display.reset_image.assert_called_with()
+
+    def recursively_delete_group_side_effect(*args, **kwargs):
+        """
+        Side effect method that creates custom retun values for the recursively_delete_group method
+        """
+        if args[1] == ImageFilenames and args[2]:
+            # Create some fake objects that should be removed
+            returned_object1 = ImageFilenames()
+            returned_object1.id = 1
+            returned_object1.filename = u'/tmp/test_file_1.jpg'
+            returned_object2 = ImageFilenames()
+            returned_object2.id = 2
+            returned_object2.filename = u'/tmp/test_file_2.jpg'
+            returned_object3 = ImageFilenames()
+            returned_object3.id = 3
+            returned_object3.filename = u'/tmp/test_file_3.jpg'
+            return [returned_object1, returned_object2, returned_object3]
+        if args[1] == ImageGroups and args[2]:
+            # Change the parent_id that is matched so we don't get into an endless loop
+            ImageGroups.parent_id = 0
+            # Create a fake group that will be used in the next run
+            returned_object1 = ImageGroups()
+            returned_object1.id = 1
+            return [returned_object1]
+        return []
+
+    def recursively_delete_group_test(self):
+        """
+        Test that recursively_delete_group() works
+        """
+        # GIVEN: An ImageGroups object and mocked functions
+        with patch(u'openlp.core.utils.delete_file') as mocked_delete_file:
+            ImageFilenames.group_id = 1
+            ImageGroups.parent_id = 1
+            self.media_item.manager = MagicMock()
+            self.media_item.manager.get_all_objects.side_effect = self.recursively_delete_group_side_effect
+            self.media_item.servicePath = ""
+            test_group = ImageGroups()
+            test_group.id = 1
+
+            # WHEN: recursively_delete_group() is called
+            self.media_item.recursively_delete_group(test_group)
+
+            # THEN:
+            assert mocked_delete_file.call_count == 0, u'delete_file() should not be called'
+            assert self.media_item.manager.delete_object.call_count == 7, \
+                u'manager.delete_object() should be called exactly 7 times'
+
+            # CLEANUP: Remove added attribute from ImageFilenames and ImageGroups
+            delattr(ImageFilenames, 'group_id')
+            delattr(ImageGroups, 'parent_id')

=== removed file 'tests/interfaces/openlp_plugins/__init__.pyc'
Binary files tests/interfaces/openlp_plugins/__init__.pyc	2013-03-29 06:25:01 +0000 and tests/interfaces/openlp_plugins/__init__.pyc	1970-01-01 00:00:00 +0000 differ

Follow ups