From 7f440527f84ad96320521691ea31378f536b4dfd Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Wed, 3 Aug 2011 14:49:47 -0400 Subject: [PATCH 1/5] modified servicemanager to check for missing files during service save --- openlp/core/ui/servicemanager.py | 61 ++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 351e5bbc6..721d50d6e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -465,10 +465,13 @@ class ServiceManager(QtGui.QWidget): service = [] write_list = [] total_size = 0 + abort_save = False Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) for item in self.serviceItems: + if abort_save: + continue self.mainwindow.incrementProgressBar() service.append({u'serviceitem': item[u'service_item'].get_service_repr()}) @@ -482,25 +485,45 @@ class ServiceManager(QtGui.QWidget): # Only write a file once if path_from in write_list: continue - file_size = os.path.getsize(path_from) - size_limit = 52428800 # 50MiB - #if file_size > size_limit: - # # File exeeds size_limit bytes, ask user - # message = unicode(translate('OpenLP.ServiceManager', - # 'Do you want to include \n%.1f MB file "%s"\n' - # 'into the service file?\nThis may take some time.\n\n' - # 'Please note that you need to\ntake care of that file' - # ' yourself,\nif you leave it out.')) % \ - # (file_size/1048576, os.path.split(path_from)[1]) - # ans = QtGui.QMessageBox.question(self.mainwindow, - # translate('OpenLP.ServiceManager', 'Including Large ' - # 'File'), message, QtGui.QMessageBox.StandardButtons( - # QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel), - # QtGui.QMessageBox.Ok) - # if ans == QtGui.QMessageBox.Cancel: - # continue - write_list.append(path_from) - total_size += file_size + if not os.path.isfile(path_from): + Receiver.send_message(u'cursor_normal') + title = unicode(translate('OpenLP.ServiceManager', + 'Service File Missing')) + message = unicode(translate('OpenLP.ServiceManager', + 'File missing from service\n\n %s \n\n' + 'Continue saving?' % path_from )) + ans = QtGui.QMessageBox.critical(self, title, message, + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) + if ans == QtGui.QMessageBox.No: + abort_save = True + continue + Receiver.send_message(u'cursor_busy') + else: + file_size = os.path.getsize(path_from) + size_limit = 52428800 # 50MiB + #if file_size > size_limit: + # # File exeeds size_limit bytes, ask user + # message = unicode(translate('OpenLP.ServiceManager', + # 'Do you want to include \n%.1f MB file "%s"\n' + # 'into the service file?\nThis may take some time.\n\n' + # 'Please note that you need to\ntake care of that file' + # ' yourself,\nif you leave it out.')) % \ + # (file_size/1048576, os.path.split(path_from)[1]) + # ans = QtGui.QMessageBox.question(self.mainwindow, + # translate('OpenLP.ServiceManager', 'Including Large ' + # 'File'), message, QtGui.QMessageBox.StandardButtons( + # QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel), + # QtGui.QMessageBox.Ok) + # if ans == QtGui.QMessageBox.Cancel: + # continue + write_list.append(path_from) + total_size += file_size + if abort_save: + self._fileName = u'' + self.mainwindow.finishedProgressBar() + Receiver.send_message(u'cursor_normal') + return False log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' % total_size) service_content = cPickle.dumps(service) From b4e776b92c7d96acc69fe0815fe6f0afdde4dc02 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Thu, 4 Aug 2011 09:43:05 -0400 Subject: [PATCH 2/5] removed un-needed code --- openlp/core/ui/servicemanager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 721d50d6e..8b5d93c5e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -485,7 +485,7 @@ class ServiceManager(QtGui.QWidget): # Only write a file once if path_from in write_list: continue - if not os.path.isfile(path_from): + if not os.path.exists(path_from): Receiver.send_message(u'cursor_normal') title = unicode(translate('OpenLP.ServiceManager', 'Service File Missing')) @@ -520,7 +520,6 @@ class ServiceManager(QtGui.QWidget): write_list.append(path_from) total_size += file_size if abort_save: - self._fileName = u'' self.mainwindow.finishedProgressBar() Receiver.send_message(u'cursor_normal') return False From a66f7f3365a1fa59f07441469ff8e258b4485242 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Fri, 5 Aug 2011 17:53:56 -0400 Subject: [PATCH 3/5] removed un-needed commented code. fixed dialog "no" answer --- openlp/core/ui/servicemanager.py | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 8b5d93c5e..6d4ae6ec0 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -465,13 +465,10 @@ class ServiceManager(QtGui.QWidget): service = [] write_list = [] total_size = 0 - abort_save = False Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) for item in self.serviceItems: - if abort_save: - continue self.mainwindow.incrementProgressBar() service.append({u'serviceitem': item[u'service_item'].get_service_repr()}) @@ -492,37 +489,17 @@ class ServiceManager(QtGui.QWidget): message = unicode(translate('OpenLP.ServiceManager', 'File missing from service\n\n %s \n\n' 'Continue saving?' % path_from )) - ans = QtGui.QMessageBox.critical(self, title, message, + answer = QtGui.QMessageBox.critical(self, title, message, QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) - if ans == QtGui.QMessageBox.No: - abort_save = True - continue + if answer == QtGui.QMessageBox.No: + self.mainwindow.finishedProgressBar() + return False Receiver.send_message(u'cursor_busy') else: file_size = os.path.getsize(path_from) - size_limit = 52428800 # 50MiB - #if file_size > size_limit: - # # File exeeds size_limit bytes, ask user - # message = unicode(translate('OpenLP.ServiceManager', - # 'Do you want to include \n%.1f MB file "%s"\n' - # 'into the service file?\nThis may take some time.\n\n' - # 'Please note that you need to\ntake care of that file' - # ' yourself,\nif you leave it out.')) % \ - # (file_size/1048576, os.path.split(path_from)[1]) - # ans = QtGui.QMessageBox.question(self.mainwindow, - # translate('OpenLP.ServiceManager', 'Including Large ' - # 'File'), message, QtGui.QMessageBox.StandardButtons( - # QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel), - # QtGui.QMessageBox.Ok) - # if ans == QtGui.QMessageBox.Cancel: - # continue write_list.append(path_from) total_size += file_size - if abort_save: - self.mainwindow.finishedProgressBar() - Receiver.send_message(u'cursor_normal') - return False log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' % total_size) service_content = cPickle.dumps(service) From c0978d8e2235b88ae950fad20416890e2b0b4766 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Wed, 10 Aug 2011 17:29:44 -0400 Subject: [PATCH 4/5] Added code to skip-all missing files during service save --- openlp/core/ui/servicemanager.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 6d4ae6ec0..bd4035d54 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -474,6 +474,7 @@ class ServiceManager(QtGui.QWidget): item[u'service_item'].get_service_repr()}) if not item[u'service_item'].uses_file(): continue + skipMissing = False for frame in item[u'service_item'].get_frames(): if item[u'service_item'].is_image(): path_from = frame[u'path'] @@ -483,19 +484,24 @@ class ServiceManager(QtGui.QWidget): if path_from in write_list: continue if not os.path.exists(path_from): - Receiver.send_message(u'cursor_normal') - title = unicode(translate('OpenLP.ServiceManager', - 'Service File Missing')) - message = unicode(translate('OpenLP.ServiceManager', - 'File missing from service\n\n %s \n\n' - 'Continue saving?' % path_from )) - answer = QtGui.QMessageBox.critical(self, title, message, - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) - if answer == QtGui.QMessageBox.No: - self.mainwindow.finishedProgressBar() - return False - Receiver.send_message(u'cursor_busy') + if not skipMissing: + Receiver.send_message(u'cursor_normal') + title = unicode(translate('OpenLP.ServiceManager', + 'Service File Missing')) + message = unicode(translate('OpenLP.ServiceManager', + 'File missing from service\n\n %s \n\n' + 'Continue saving?' % path_from )) + answer = QtGui.QMessageBox.critical(self, title, + message, + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | + QtGui.QMessageBox.YesToAll)) + if answer == QtGui.QMessageBox.No: + self.mainwindow.finishedProgressBar() + return False + if answer == QtGui.QMessageBox.YesToAll: + skipMissing = True + Receiver.send_message(u'cursor_busy') else: file_size = os.path.getsize(path_from) write_list.append(path_from) From ba02eb6a98a096d2895330107b465611264c934a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 11 Aug 2011 11:01:25 +0200 Subject: [PATCH 5/5] moved recent files to a menu (bug #818794) Fixes: https://launchpad.net/bugs/818794 --- openlp/core/ui/mainwindow.py | 57 +++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index c7ff6c52a..510a94dfd 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -109,6 +109,8 @@ class Ui_MainWindow(object): self.menuBar.setObjectName(u'menuBar') self.fileMenu = QtGui.QMenu(self.menuBar) self.fileMenu.setObjectName(u'fileMenu') + self.recentFilesMenu = QtGui.QMenu(self.fileMenu) + self.recentFilesMenu.setObjectName(u'recentFilesMenu') self.fileImportMenu = QtGui.QMenu(self.fileMenu) self.fileImportMenu.setObjectName(u'fileImportMenu') self.fileExportMenu = QtGui.QMenu(self.fileMenu) @@ -302,10 +304,11 @@ class Ui_MainWindow(object): (self.importThemeItem, self.importLanguageItem)) add_actions(self.fileExportMenu, (self.exportThemeItem, self.exportLanguageItem)) - self.fileMenuActions = (self.fileNewItem, self.fileOpenItem, + add_actions(self.fileMenu, (self.fileNewItem, self.fileOpenItem, self.fileSaveItem, self.fileSaveAsItem, None, - self.printServiceOrderItem, None, self.fileImportMenu.menuAction(), - self.fileExportMenu.menuAction(), self.fileExitItem) + self.recentFilesMenu.menuAction(), None, self.printServiceOrderItem, + None, self.fileImportMenu.menuAction(), + self.fileExportMenu.menuAction(), self.fileExitItem)) add_actions(self.viewModeMenu, (self.modeDefaultItem, self.modeSetupItem, self.modeLiveItem)) add_actions(self.viewMenu, (self.viewModeMenu.menuAction(), @@ -346,7 +349,7 @@ class Ui_MainWindow(object): self.mediaToolBox.setCurrentIndex(0) # Connect up some signals and slots QtCore.QObject.connect(self.fileMenu, - QtCore.SIGNAL(u'aboutToShow()'), self.updateFileMenu) + QtCore.SIGNAL(u'aboutToShow()'), self.updateRecentFilesMenu) QtCore.QMetaObject.connectSlotsByName(mainWindow) # Hide the entry, as it does not have any functionality yet. self.toolsAddToolItem.setVisible(False) @@ -363,6 +366,8 @@ class Ui_MainWindow(object): self.fileMenu.setTitle(translate('OpenLP.MainWindow', '&File')) self.fileImportMenu.setTitle(translate('OpenLP.MainWindow', '&Import')) self.fileExportMenu.setTitle(translate('OpenLP.MainWindow', '&Export')) + self.recentFilesMenu.setTitle( + translate('OpenLP.MainWindow', '&Recent Files')) self.viewMenu.setTitle(translate('OpenLP.MainWindow', '&View')) self.viewModeMenu.setTitle(translate('OpenLP.MainWindow', 'M&ode')) self.toolsMenu.setTitle(translate('OpenLP.MainWindow', '&Tools')) @@ -534,8 +539,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.setupUi(self) # Load settings after setupUi so default UI sizes are overwritten self.loadSettings() - # Once settings are loaded update FileMenu with recentFiles - self.updateFileMenu() + # Once settings are loaded update the menu with the recent files. + self.updateRecentFilesMenu() self.pluginForm = PluginForm(self) # Set up signals and slots QtCore.QObject.connect(self.importThemeItem, @@ -1137,30 +1142,36 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QVariant(self.controlSplitter.saveState())) settings.endGroup() - def updateFileMenu(self): + def updateRecentFilesMenu(self): """ - Updates the file menu with the latest list of service files accessed. + Updates the recent file menu with the latest list of service files + accessed. """ recentFileCount = QtCore.QSettings().value( u'advanced/recent file count', QtCore.QVariant(4)).toInt()[0] - self.fileMenu.clear() - add_actions(self.fileMenu, self.fileMenuActions[:-1]) existingRecentFiles = [recentFile for recentFile in self.recentFiles if QtCore.QFile.exists(recentFile)] recentFilesToDisplay = existingRecentFiles[0:recentFileCount] - if recentFilesToDisplay: - self.fileMenu.addSeparator() - for fileId, filename in enumerate(recentFilesToDisplay): - log.debug('Recent file name: %s', filename) - action = base_action(self, u'') - action.setText(u'&%d %s' % - (fileId + 1, QtCore.QFileInfo(filename).fileName())) - action.setData(QtCore.QVariant(filename)) - self.connect(action, QtCore.SIGNAL(u'triggered()'), - self.serviceManagerContents.onRecentServiceClicked) - self.fileMenu.addAction(action) - self.fileMenu.addSeparator() - self.fileMenu.addAction(self.fileMenuActions[-1]) + self.recentFilesMenu.clear() + for fileId, filename in enumerate(recentFilesToDisplay): + log.debug('Recent file name: %s', filename) + action = base_action(self, u'') + action.setText(u'&%d %s' % + (fileId + 1, QtCore.QFileInfo(filename).fileName())) + action.setData(QtCore.QVariant(filename)) + self.connect(action, QtCore.SIGNAL(u'triggered()'), + self.serviceManagerContents.onRecentServiceClicked) + self.recentFilesMenu.addAction(action) + clearRecentFilesAction = base_action(self, u'') + clearRecentFilesAction.setText( + translate('OpenLP.MainWindow', 'Clear List', + 'Clear List of recent files')) + clearRecentFilesAction.setStatusTip( + translate('OpenLP.MainWindow', 'Clear the list of recent files.')) + add_actions(self.recentFilesMenu, (None, clearRecentFilesAction)) + self.connect(clearRecentFilesAction, QtCore.SIGNAL(u'triggered()'), + self.recentFiles.clear) + clearRecentFilesAction.setEnabled(not self.recentFiles.isEmpty()) def addRecentFile(self, filename): """