Add recent files functionality

This commit is contained in:
Jon Tibble 2010-04-23 19:30:53 +01:00
parent 37720b9cdb
commit fbc36e3e9a
3 changed files with 93 additions and 49 deletions

View File

@ -113,6 +113,8 @@ class OpenLP(QtGui.QApplication):
#provide a listener for widgets to reqest a screen update. #provide a listener for widgets to reqest a screen update.
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'process_events'), self.processEvents) QtCore.SIGNAL(u'process_events'), self.processEvents)
self.setOrganizationName(u'OpenLP')
self.setOrganizationDomain(u'openlp.org')
self.setApplicationName(u'OpenLP') self.setApplicationName(u'OpenLP')
self.setApplicationVersion(app_version[u'version']) self.setApplicationVersion(app_version[u'version'])
if os.name == u'nt': if os.name == u'nt':

View File

@ -28,12 +28,11 @@ import time
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.ui import AboutForm, SettingsForm, \ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \
ServiceManager, ThemeManager, SlideController, \ ThemeManager, SlideController, PluginForm, MediaDockManager, DisplayManager
PluginForm, MediaDockManager, DisplayManager
from openlp.core.lib import RenderManager, PluginConfig, build_icon, \ from openlp.core.lib import RenderManager, PluginConfig, build_icon, \
OpenLPDockWidget, SettingsManager, PluginManager, Receiver, str_to_bool OpenLPDockWidget, SettingsManager, PluginManager, Receiver, str_to_bool
from openlp.core.utils import check_latest_version, AppLocation from openlp.core.utils import check_latest_version, AppLocation, add_actions
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -273,50 +272,36 @@ class Ui_MainWindow(object):
self.settingsmanager.showPreviewPanel) self.settingsmanager.showPreviewPanel)
self.ModeLiveItem = QtGui.QAction(MainWindow) self.ModeLiveItem = QtGui.QAction(MainWindow)
self.ModeLiveItem.setObjectName(u'ModeLiveItem') self.ModeLiveItem.setObjectName(u'ModeLiveItem')
self.FileImportMenu.addAction(self.ImportThemeItem) add_actions(self.FileImportMenu,
self.FileImportMenu.addAction(self.ImportLanguageItem) (self.ImportThemeItem, self.ImportLanguageItem))
self.FileExportMenu.addAction(self.ExportThemeItem) add_actions(self.FileExportMenu,
self.FileExportMenu.addAction(self.ExportLanguageItem) (self.ExportThemeItem, self.ExportLanguageItem))
self.FileMenu.addAction(self.FileNewItem) self.FileMenuActions = (self.FileNewItem, self.FileOpenItem,
self.FileMenu.addAction(self.FileOpenItem) self.FileSaveItem, self.FileSaveAsItem, None,
self.FileMenu.addAction(self.FileSaveItem) self.FileImportMenu.menuAction(), self.FileExportMenu.menuAction(),
self.FileMenu.addAction(self.FileSaveAsItem) self.FileExitItem)
self.FileMenu.addSeparator() add_actions(self.ViewModeMenu, [self.ModeLiveItem])
self.FileMenu.addAction(self.FileImportMenu.menuAction()) add_actions(self.OptionsViewMenu, (self.ViewModeMenu.menuAction(),
self.FileMenu.addAction(self.FileExportMenu.menuAction()) None, self.ViewMediaManagerItem, self.ViewServiceManagerItem,
self.FileMenu.addSeparator() self.ViewThemeManagerItem, None, self.action_Preview_Panel))
self.FileMenu.addAction(self.FileExitItem) add_actions(self.OptionsLanguageMenu, (self.LanguageEnglishItem, None,
self.ViewModeMenu.addAction(self.ModeLiveItem) self.LanguageTranslateItem))
self.OptionsViewMenu.addAction(self.ViewModeMenu.menuAction()) add_actions(self.OptionsMenu, (self.OptionsLanguageMenu.menuAction(),
self.OptionsViewMenu.addSeparator() self.OptionsViewMenu.menuAction(), None, self.OptionsSettingsItem))
self.OptionsViewMenu.addAction(self.ViewMediaManagerItem) add_actions(self.ToolsMenu,
self.OptionsViewMenu.addAction(self.ViewServiceManagerItem) (self.PluginItem, None, self.ToolsAddToolItem))
self.OptionsViewMenu.addAction(self.ViewThemeManagerItem) add_actions(self.HelpMenu,
self.OptionsViewMenu.addSeparator() (self.HelpDocumentationItem, self.HelpOnlineHelpItem, None,
self.OptionsViewMenu.addAction(self.action_Preview_Panel) self.HelpWebSiteItem, self.HelpAboutItem))
self.OptionsLanguageMenu.addAction(self.LanguageEnglishItem) add_actions(self.MenuBar,
self.OptionsLanguageMenu.addSeparator() (self.FileMenu.menuAction(), self.OptionsMenu.menuAction(),
self.OptionsLanguageMenu.addAction(self.LanguageTranslateItem) self.ToolsMenu.menuAction(), self.HelpMenu.menuAction()))
self.OptionsMenu.addAction(self.OptionsLanguageMenu.menuAction())
self.OptionsMenu.addAction(self.OptionsViewMenu.menuAction())
self.OptionsMenu.addSeparator()
self.OptionsMenu.addAction(self.OptionsSettingsItem)
self.ToolsMenu.addAction(self.PluginItem)
self.ToolsMenu.addSeparator()
self.ToolsMenu.addAction(self.ToolsAddToolItem)
self.HelpMenu.addAction(self.HelpDocumentationItem)
self.HelpMenu.addAction(self.HelpOnlineHelpItem)
self.HelpMenu.addSeparator()
self.HelpMenu.addAction(self.HelpWebSiteItem)
self.HelpMenu.addAction(self.HelpAboutItem)
self.MenuBar.addAction(self.FileMenu.menuAction())
self.MenuBar.addAction(self.OptionsMenu.menuAction())
self.MenuBar.addAction(self.ToolsMenu.menuAction())
self.MenuBar.addAction(self.HelpMenu.menuAction())
# Initialise the translation # Initialise the translation
self.retranslateUi(MainWindow) self.retranslateUi(MainWindow)
self.MediaToolBox.setCurrentIndex(0) self.MediaToolBox.setCurrentIndex(0)
# Connect up some signals and slots # Connect up some signals and slots
QtCore.QObject.connect(self.FileMenu,
QtCore.SIGNAL(u'aboutToShow()'), self.updateFileMenu)
QtCore.QObject.connect(self.FileExitItem, QtCore.QObject.connect(self.FileExitItem,
QtCore.SIGNAL(u'triggered()'), MainWindow.close) QtCore.SIGNAL(u'triggered()'), MainWindow.close)
QtCore.QObject.connect(self.ControlSplitter, QtCore.QObject.connect(self.ControlSplitter,
@ -445,12 +430,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.displayManager = DisplayManager(screens) self.displayManager = DisplayManager(screens)
self.aboutForm = AboutForm(self, applicationVersion) self.aboutForm = AboutForm(self, applicationVersion)
self.settingsForm = SettingsForm(self.screens, self, self) self.settingsForm = SettingsForm(self.screens, self, self)
self.recentFiles = []
# Set up the path with plugins # Set up the path with plugins
pluginpath = AppLocation.get_directory(AppLocation.PluginsDir) pluginpath = AppLocation.get_directory(AppLocation.PluginsDir)
self.plugin_manager = PluginManager(pluginpath) self.plugin_manager = PluginManager(pluginpath)
self.plugin_helpers = {} self.plugin_helpers = {}
# Set up the interface # Set up the interface
self.setupUi(self) self.setupUi(self)
# Load settings after setupUi so defaults UI sizes are overwritten
self.loadSettings()
# Once settings are loaded update FileMenu with recentFiles
self.updateFileMenu()
self.pluginForm = PluginForm(self) self.pluginForm = PluginForm(self)
# Set up signals and slots # Set up signals and slots
QtCore.QObject.connect(self.ImportThemeItem, QtCore.QObject.connect(self.ImportThemeItem,
@ -666,6 +656,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# Call the cleanup method to shutdown plugins. # Call the cleanup method to shutdown plugins.
log.info(u'cleanup plugins') log.info(u'cleanup plugins')
self.plugin_manager.finalise_plugins() self.plugin_manager.finalise_plugins()
# Save settings
self.saveSettings()
#Close down the displays #Close down the displays
self.displayManager.close() self.displayManager.close()
@ -720,3 +712,42 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
previewBool = self.PreviewController.Panel.isVisible() previewBool = self.PreviewController.Panel.isVisible()
self.PreviewController.Panel.setVisible(not previewBool) self.PreviewController.Panel.setVisible(not previewBool)
self.settingsmanager.togglePreviewPanel(not previewBool) self.settingsmanager.togglePreviewPanel(not previewBool)
def loadSettings(self):
log.debug(u'Loading QSettings')
settings = QtCore.QSettings()
self.recentFiles = settings.value(u'RecentFiles').toStringList()
def saveSettings(self):
log.debug(u'Saving QSettings')
settings = QtCore.QSettings()
recentFiles = QtCore.QVariant(self.recentFiles) \
if self.recentFiles else QtCore.QVariant()
settings.setValue(u'RecentFiles', recentFiles)
def updateFileMenu(self):
self.FileMenu.clear()
add_actions(self.FileMenu, self.FileMenuActions[:-1])
existingRecentFiles = []
for file in self.recentFiles:
if QtCore.QFile.exists(file):
existingRecentFiles.append(file)
if existingRecentFiles:
self.FileMenu.addSeparator()
for fileId, filename in enumerate(existingRecentFiles):
action = QtGui.QAction(u'&%d %s' % (fileId +1,
QtCore.QFileInfo(filename).fileName()), self)
action.setData(QtCore.QVariant(filename))
self.connect(action, QtCore.SIGNAL(u'triggered()'),
self.ServiceManagerContents.loadService)
self.FileMenu.addAction(action)
self.FileMenu.addSeparator()
self.FileMenu.addAction(self.FileMenuActions[-1])
def addRecentFile(self, filename):
recentFileCount = int(PluginConfig(u'General').
get_config(u'max recent files', 4))
if filename and not self.recentFiles.contains(filename):
self.recentFiles.prepend(QtCore.QString(filename))
while self.recentFiles.count() > recentFileCount:
self.recentFiles.takeLast()

View File

@ -538,23 +538,33 @@ class ServiceManager(QtGui.QWidget):
pass #if not present do not worry pass #if not present do not worry
name = filename.split(os.path.sep) name = filename.split(os.path.sep)
self.serviceName = name[-1] self.serviceName = name[-1]
self.parent.addRecentFile(filename)
self.parent.serviceChanged(True, self.serviceName) self.parent.serviceChanged(True, self.serviceName)
def onQuickSaveService(self): def onQuickSaveService(self):
self.onSaveService(True) self.onSaveService(True)
def onLoadService(self, lastService=False): def onLoadService(self, lastService=False):
"""
Load an existing service from disk and rebuild the serviceitems. All
files retrieved from the zip file are placed in a temporary directory
and will only be used for this service.
"""
if lastService: if lastService:
filename = self.config.get_last_dir() filename = self.config.get_last_dir()
else: else:
filename = QtGui.QFileDialog.getOpenFileName( filename = QtGui.QFileDialog.getOpenFileName(
self, self.trUtf8('Open Service'), self, self.trUtf8('Open Service'),
self.config.get_last_dir(), u'Services (*.osz)') self.config.get_last_dir(), u'Services (*.osz)')
self.loadService(filename)
def loadService(self, filename=None):
"""
Load an existing service from disk and rebuild the serviceitems. All
files retrieved from the zip file are placed in a temporary directory
and will only be used for this service.
"""
if filename is None:
action = self.sender()
if isinstance(action, QtGui.QAction):
filename = action.data().toString()
else:
return
filename = unicode(filename) filename = unicode(filename)
name = filename.split(os.path.sep) name = filename.split(os.path.sep)
if filename: if filename:
@ -598,6 +608,7 @@ class ServiceManager(QtGui.QWidget):
zip.close() zip.close()
self.isNew = False self.isNew = False
self.serviceName = name[len(name) - 1] self.serviceName = name[len(name) - 1]
self.parent.addRecentFile(filename)
self.parent.serviceChanged(True, self.serviceName) self.parent.serviceChanged(True, self.serviceName)
def validateItem(self, serviceItem): def validateItem(self, serviceItem):