diff --git a/openlp/plugins/images/forms/__init__.py b/openlp/plugins/images/forms/__init__.py index 8c33c656e..0904f4c63 100644 --- a/openlp/plugins/images/forms/__init__.py +++ b/openlp/plugins/images/forms/__init__.py @@ -54,4 +54,5 @@ from the .ui files later if necessary. """ from addgroupform import AddGroupForm +from choosegroupform import ChooseGroupForm diff --git a/openlp/plugins/images/forms/choosegroupdialog.py b/openlp/plugins/images/forms/choosegroupdialog.py new file mode 100644 index 000000000..6c6f253c2 --- /dev/null +++ b/openlp/plugins/images/forms/choosegroupdialog.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 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 # +############################################################################### + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import translate +from openlp.core.lib.ui import create_button_box + +class Ui_ChooseGroupDialog(object): + def setupUi(self, chooseGroupDialog): + chooseGroupDialog.setObjectName(u'chooseGroupDialog') + chooseGroupDialog.resize(440, 119) + self.chooseGroupLayout = QtGui.QFormLayout(chooseGroupDialog) + self.chooseGroupLayout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow) + self.chooseGroupLayout.setMargin(8) + self.chooseGroupLayout.setSpacing(8) + self.chooseGroupLayout.setObjectName(u'chooseGroupLayout') + self.groupQuestionLabel = QtGui.QLabel(chooseGroupDialog) + self.groupQuestionLabel.setWordWrap(True) + self.groupQuestionLabel.setObjectName(u'groupQuestionLabel') + self.chooseGroupLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.groupQuestionLabel) + self.groupComboBox = QtGui.QComboBox(chooseGroupDialog) + self.groupComboBox.setObjectName(u'groupComboBox') + self.chooseGroupLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.groupComboBox) + self.groupButtonBox = create_button_box(chooseGroupDialog, u'buttonBox', [u'ok']) + self.chooseGroupLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.groupButtonBox) + + self.retranslateUi(chooseGroupDialog) + QtCore.QMetaObject.connectSlotsByName(chooseGroupDialog) + + def retranslateUi(self, chooseGroupDialog): + chooseGroupDialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Choose group')) + self.groupQuestionLabel.setText(translate('ImagePlugin.ChooseGroupForm', + 'To which group do you want these images to be added?')) + diff --git a/openlp/plugins/images/forms/choosegroupform.py b/openlp/plugins/images/forms/choosegroupform.py new file mode 100644 index 000000000..0226c42f8 --- /dev/null +++ b/openlp/plugins/images/forms/choosegroupform.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 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 # +############################################################################### + +from PyQt4 import QtGui + +from openlp.core.lib import translate +from openlp.core.lib.ui import critical_error_message_box +from openlp.plugins.images.forms.choosegroupdialog import Ui_ChooseGroupDialog + +class ChooseGroupForm(QtGui.QDialog, Ui_ChooseGroupDialog): + """ + Class documentation goes here. + """ + def __init__(self, parent=None): + """ + Constructor + """ + QtGui.QDialog.__init__(self, parent) + self.setupUi(self) + diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 871f88714..08e166887 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -37,7 +37,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, Sett UiStrings from openlp.core.lib.ui import critical_error_message_box from openlp.core.utils import AppLocation, delete_file, locale_compare, get_images_filter -from openlp.plugins.images.forms import AddGroupForm +from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups log = logging.getLogger(__name__) @@ -54,8 +54,9 @@ class ImageMediaItem(MediaManagerItem): self.quickPreviewAllowed = True self.hasSearch = True self.manager = plugin.manager + self.choosegroupform = ChooseGroupForm(self) self.addgroupform = AddGroupForm(self) - self.fillGroupsComboBox() + self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged) # Allow DnD from the desktop self.listView.activateDnD() @@ -153,18 +154,19 @@ class ImageMediaItem(MediaManagerItem): groupList[image_group.id] = group self.addSubGroups(groupList, image_group.id) - def fillGroupsComboBox(self, parentGroupId=0, prefix=''): + def fillGroupsComboBox(self, comboBox, parentGroupId=0, prefix='', showTopLevelGroup=True): """ Recursively add groups to the combobox in the 'Add group' dialog """ if parentGroupId is 0: - self.addgroupform.parentGroupComboBox.clear() - self.addgroupform.parentGroupComboBox.addItem(translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0) + comboBox.clear() + if showTopLevelGroup is True: + comboBox.addItem(translate('ImagePlugin.MediaItem', '-- Top-level group --'), 0) image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parentGroupId) image_groups.sort(cmp=locale_compare, key=lambda group_object: group_object.group_name) for image_group in image_groups: - self.addgroupform.parentGroupComboBox.addItem(prefix+image_group.group_name, image_group.id) - self.fillGroupsComboBox(image_group.id, prefix+' ') + comboBox.addItem(prefix+image_group.group_name, image_group.id) + self.fillGroupsComboBox(comboBox, image_group.id, prefix+' ') def loadFullList(self, images, initialLoad=False): """ @@ -215,15 +217,21 @@ class ImageMediaItem(MediaManagerItem): """ Add new images to the database. This method is called when adding images using the Add button or DnD. """ - for filename in images: - if filename is None: - continue - imageFile = ImageFilenames() - imageFile.group_id = 0 - imageFile.filename = unicode(filename) - success = self.manager.save_object(imageFile) - self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), - initialLoad) + # Ask which group the images should be saved in + self.fillGroupsComboBox(self.choosegroupform.groupComboBox, showTopLevelGroup=False) + if self.choosegroupform.exec_(): + group_id = self.choosegroupform.groupComboBox.itemData( + self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole) + # Save the new images in the database + for filename in images: + if filename is None: + continue + imageFile = ImageFilenames() + imageFile.group_id = group_id + imageFile.filename = unicode(filename) + success = self.manager.save_object(imageFile) + self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), + initialLoad) def generateSlideData(self, service_item, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Service): @@ -316,7 +324,7 @@ class ImageMediaItem(MediaManagerItem): if self.checkGroupName(new_group): if self.manager.save_object(new_group): self.loadList([]) - self.fillGroupsComboBox() + self.fillGroupsComboBox(self.addgroupform.parentGroupComboBox) else: critical_error_message_box( message=translate('ImagePlugin.AddGroupForm', 'Could not add the new group.')) diff --git a/resources/forms/imageschoosegroupdialog.ui b/resources/forms/imageschoosegroupdialog.ui new file mode 100644 index 000000000..6f4eb5b41 --- /dev/null +++ b/resources/forms/imageschoosegroupdialog.ui @@ -0,0 +1,55 @@ + + + ChooseGroupDialog + + + + 0 + 0 + 440 + 119 + + + + Choose group + + + + QFormLayout::ExpandingFieldsGrow + + + 8 + + + 8 + + + 8 + + + + + To which group do you want these images to be added? + + + true + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + +