← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/dnd into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/dnd into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~trb143/openlp/dnd/+merge/69526

Move all the Drag and Drop changes from the B1 tree which is stuck at present.
It is no possible to Dnd Images, Presentations and Media into the plugins as wee as dragging a otz file into the service manager.

Can you check for qthread errors my box is giving them but I am not sure if it's the code or my box!
-- 
https://code.launchpad.net/~trb143/openlp/dnd/+merge/69526
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/dnd into lp:openlp.
=== modified file 'openlp.pyw'
--- openlp.pyw	2011-06-12 16:02:52 +0000
+++ openlp.pyw	2011-07-27 18:36:43 +0000
@@ -93,7 +93,7 @@
         # On Windows, the args passed into the constructor are
         # ignored. Not very handy, so set the ones we want to use.
         self.args = args
-        # provide a listener for widgets to reqest a screen update.
+        # provide a listener for widgets to request a screen update.
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'openlp_process_events'), self.processEvents)
         QtCore.QObject.connect(Receiver.get_receiver(),
@@ -125,6 +125,8 @@
             # now kill the splashscreen
             self.splash.finish(self.mainWindow)
             log.debug(u'Splashscreen closed')
+        # make sure Qt really display the splash screen
+        self.processEvents()
         self.mainWindow.repaint()
         self.processEvents()
         if not has_run_wizard:

=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py	2011-07-16 09:00:30 +0000
+++ openlp/core/lib/__init__.py	2011-07-27 18:36:43 +0000
@@ -233,9 +233,9 @@
     except IOError:
         pass
 
+from eventreceiver import Receiver
 from listwidgetwithdnd import ListWidgetWithDnD
 from displaytags import DisplayTags
-from eventreceiver import Receiver
 from spelltextedit import SpellTextEdit
 from settingsmanager import SettingsManager
 from plugin import PluginStatus, StringContent, Plugin

=== modified file 'openlp/core/lib/listwidgetwithdnd.py'
--- openlp/core/lib/listwidgetwithdnd.py	2011-06-12 16:02:52 +0000
+++ openlp/core/lib/listwidgetwithdnd.py	2011-07-27 18:36:43 +0000
@@ -27,8 +27,12 @@
 """
 Extend QListWidget to handle drag and drop functionality
 """
+import os.path
+
 from PyQt4 import QtCore, QtGui
 
+from openlp.core.lib import Receiver
+
 class ListWidgetWithDnD(QtGui.QListWidget):
     """
     Provide a list widget to store objects and handle drag and drop events
@@ -41,6 +45,13 @@
         self.mimeDataText = name
         assert(self.mimeDataText)
 
+    def activateDnD(self):
+        """
+        Activate DnD of widget
+        """
+        self.setAcceptDrops(True)
+        self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
+
     def mouseMoveEvent(self, event):
         """
         Drag and drop event does not care what data is selected
@@ -58,3 +69,33 @@
         drag.setMimeData(mimeData)
         mimeData.setText(self.mimeDataText)
         drag.start(QtCore.Qt.CopyAction)
+
+    def dragEnterEvent(self, event):
+        if event.mimeData().hasUrls:
+            event.accept()
+        else:
+            event.ignore()
+
+    def dragMoveEvent(self, event):
+        if event.mimeData().hasUrls:
+            event.setDropAction(QtCore.Qt.CopyAction)
+            event.accept()
+        else:
+            event.ignore()
+
+    def dropEvent(self, event):
+        """
+        Receive drop event check if it is a file and process it if it is.
+
+        ``event``
+            Handle of the event pint passed
+        """
+        if event.mimeData().hasUrls():
+            event.setDropAction(QtCore.Qt.CopyAction)
+            event.accept()
+            for url in event.mimeData().urls():
+                if os.path.isfile(url.toLocalFile()):
+                    Receiver.send_message(u'%s_dnd' % self.mimeDataText,
+                        url.toLocalFile())
+        else:
+            event.ignore()

=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py	2011-07-23 21:29:24 +0000
+++ openlp/core/lib/mediamanageritem.py	2011-07-27 18:36:43 +0000
@@ -252,7 +252,6 @@
         self.listView.setSelectionMode(
             QtGui.QAbstractItemView.ExtendedSelection)
         self.listView.setAlternatingRowColors(True)
-        self.listView.setDragEnabled(True)
         self.listView.setObjectName(u'%sListView' % self.plugin.name)
         # Add to pageLayout
         self.pageLayout.addWidget(self.listView)
@@ -339,27 +338,57 @@
         log.info(u'New files(s) %s', unicode(files))
         if files:
             Receiver.send_message(u'cursor_busy')
-            names = []
-            for count in range(0, self.listView.count()):
-                names.append(self.listView.item(count).text())
-            newFiles = []
-            for file in files:
-                filename = os.path.split(unicode(file))[1]
-                if filename in names:
-                    critical_error_message_box(
-                        UiStrings().Duplicate,
-                        unicode(translate('OpenLP.MediaManagerItem',
-                        'Duplicate filename %s.\nThis filename is already in '
-                        'the list')) % filename)
-                else:
-                    newFiles.append(file)
-            self.loadList(newFiles)
-            lastDir = os.path.split(unicode(files[0]))[0]
-            SettingsManager.set_last_dir(self.settingsSection, lastDir)
-            SettingsManager.set_list(self.settingsSection,
-                self.settingsSection, self.getFileList())
+            self.validateAndLoad(files)
         Receiver.send_message(u'cursor_normal')
 
+    def loadFile(self, filename):
+        """
+        Turn file from Drag and Drop into a array so the Validate code
+        can runn it.
+
+         ``filename``
+         The file to be loaded
+        """
+        filename = unicode(filename)
+        type = filename.split(u'.')[-1]
+        if type.lower() not in self.onNewFileMasks:
+            critical_error_message_box(
+                translate('OpenLP.MediaManagerItem',
+                'Invalid File Type'),
+                unicode(translate('OpenLP.MediaManagerItem',
+                'Invalid File %s.\nSuffix not supported'))
+                % filename)
+        else:
+            self.validateAndLoad([filename])
+
+    def validateAndLoad(self, files):
+        """
+        Process a list for files either from the File Dialog or from Drag and
+        Drop
+
+         ``files``
+         The files to be loaded
+        """
+        names = []
+        for count in range(0, self.listView.count()):
+            names.append(self.listView.item(count).text())
+        newFiles = []
+        for file in files:
+            filename = os.path.split(unicode(file))[1]
+            if filename in names:
+                critical_error_message_box(
+                    UiStrings().Duplicate,
+                    unicode(translate('OpenLP.MediaManagerItem',
+                    'Duplicate filename %s.\nThis filename is already in '
+                    'the list')) % filename)
+            else:
+                newFiles.append(file)
+        self.loadList(newFiles)
+        lastDir = os.path.split(unicode(files[0]))[0]
+        SettingsManager.set_last_dir(self.settingsSection, lastDir)
+        SettingsManager.set_list(self.settingsSection,
+            self.settingsSection, self.getFileList())
+
     def contextMenu(self, point):
         item = self.listView.itemAt(point)
         # Decide if we have to show the context menu or not.

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2011-07-24 17:52:53 +0000
+++ openlp/core/ui/servicemanager.py	2011-07-27 18:36:43 +0000
@@ -1239,7 +1239,14 @@
             Handle of the event pint passed
         """
         link = event.mimeData()
-        if link.hasText():
+        if event.mimeData().hasUrls():
+            event.setDropAction(QtCore.Qt.CopyAction)
+            event.accept()
+            for url in event.mimeData().urls():
+                filename = unicode(url.toLocalFile())
+                if filename.endswith(u'.osz'):
+                    self.loadFile(filename)
+        elif event.mimeData().hasText():
             plugin = unicode(event.mimeData().text())
             item = self.serviceManagerList.itemAt(event.pos())
             # ServiceManager started the drag and drop

=== modified file 'openlp/plugins/images/lib/mediaitem.py'
--- openlp/plugins/images/lib/mediaitem.py	2011-07-03 08:13:48 +0000
+++ openlp/plugins/images/lib/mediaitem.py	2011-07-27 18:36:43 +0000
@@ -52,6 +52,10 @@
         self.hasSearch = True
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged)
+        # Allow DnD from the desktop
+        self.listView.activateDnD()
+        QtCore.QObject.connect(Receiver.get_receiver(),
+            QtCore.SIGNAL(u'images_dnd'), self.loadFile)
 
     def retranslateUi(self):
         self.onNewPrompt = translate('ImagePlugin.MediaItem',
@@ -131,6 +135,7 @@
                 icon = self.iconFromFile(imageFile, thumb)
             item_name = QtGui.QListWidgetItem(filename)
             item_name.setIcon(icon)
+            item_name.setToolTip(imageFile)
             item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile))
             self.listView.addItem(item_name)
         if not initialLoad:

=== modified file 'openlp/plugins/media/lib/mediaitem.py'
--- openlp/plugins/media/lib/mediaitem.py	2011-07-03 08:13:48 +0000
+++ openlp/plugins/media/lib/mediaitem.py	2011-07-27 18:36:43 +0000
@@ -39,6 +39,8 @@
 
 log = logging.getLogger(__name__)
 
+CLAPPERBOARD = QtGui.QPixmap(u':/media/media_video.png').toImage()
+
 class MediaMediaItem(MediaManagerItem):
     """
     This is the custom media manager item for Media Slides.
@@ -48,8 +50,7 @@
     def __init__(self, parent, plugin, icon):
         self.IconPath = u'images/image'
         self.background = False
-        self.PreviewFunction = QtGui.QPixmap(
-            u':/media/media_video.png').toImage()
+        self.PreviewFunction = CLAPPERBOARD
         MediaManagerItem.__init__(self, parent, plugin, icon)
         self.singleServiceItem = False
         self.hasSearch = True
@@ -60,6 +61,10 @@
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'openlp_phonon_creation'),
             self.createPhonon)
+        # Allow DnD from the desktop
+        self.listView.activateDnD()
+        QtCore.QObject.connect(Receiver.get_receiver(),
+            QtCore.SIGNAL(u'media_dnd'), self.loadFile)
 
     def retranslateUi(self):
         self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
@@ -201,17 +206,17 @@
             SettingsManager.set_list(self.settingsSection,
                 u'media', self.getFileList())
 
-    def loadList(self, files):
+    def loadList(self, media):
         # Sort the themes by its filename considering language specific
         # characters. lower() is needed for windows!
-        files.sort(cmp=locale.strcoll,
+        media.sort(cmp=locale.strcoll,
             key=lambda filename: os.path.split(unicode(filename))[1].lower())
-        for file in files:
-            filename = os.path.split(unicode(file))[1]
+        for track in media:
+            filename = os.path.split(unicode(track))[1]
             item_name = QtGui.QListWidgetItem(filename)
-            img = QtGui.QPixmap(u':/media/media_video.png').toImage()
-            item_name.setIcon(build_icon(img))
-            item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
+            item_name.setIcon(build_icon(CLAPPERBOARD))
+            item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track))
+            item_name.setToolTip(track)
             self.listView.addItem(item_name)
 
     def createPhonon(self):

=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
--- openlp/plugins/presentations/lib/mediaitem.py	2011-06-12 17:56:11 +0000
+++ openlp/plugins/presentations/lib/mediaitem.py	2011-07-27 18:36:43 +0000
@@ -58,6 +58,10 @@
         self.hasSearch = True
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'mediaitem_presentation_rebuild'), self.rebuild)
+        # Allow DnD from the desktop
+        self.listView.activateDnD()
+        QtCore.QObject.connect(Receiver.get_receiver(),
+            QtCore.SIGNAL(u'presentations_dnd'), self.loadFile)
 
     def retranslateUi(self):
         """
@@ -205,6 +209,7 @@
             item_name = QtGui.QListWidgetItem(filename)
             item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
             item_name.setIcon(icon)
+            item_name.setToolTip(file)
             self.listView.addItem(item_name)
         Receiver.send_message(u'cursor_normal')
         if not initialLoad:


Follow ups