From ce230df91d889faae6ca1f0300f1fb458eb8c1c6 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Thu, 19 Jan 2012 15:25:53 -0500 Subject: [PATCH 1/7] Added code to allow user to change the location of the OpenLP data directory --- openlp/core/ui/advancedtab.py | 240 ++++++++++++++++++++++++++++++++- openlp/core/ui/mainwindow.py | 56 +++++++- openlp/core/ui/settingsform.py | 4 +- openlp/core/utils/__init__.py | 24 +++- 4 files changed, 318 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 045d38a7e..9dd8dbf70 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -29,9 +29,11 @@ The :mod:`advancedtab` provides an advanced settings facility. """ from PyQt4 import QtCore, QtGui +import os +import sys from openlp.core.lib import SettingsTab, translate, build_icon, Receiver from openlp.core.lib.ui import UiStrings -from openlp.core.utils import get_images_filter +from openlp.core.utils import get_images_filter, AppLocation class AdvancedTab(SettingsTab): """ @@ -84,6 +86,53 @@ class AdvancedTab(SettingsTab): u'enableAutoCloseCheckBox') self.uiLayout.addRow(self.enableAutoCloseCheckBox) self.leftLayout.addWidget(self.uiGroupBox) + self.dataDirectoryGroupBox = QtGui.QGroupBox(self.leftColumn) + self.dataDirectoryGroupBox.setObjectName(u'dataDirectoryGroupBox') + self.dataDirectoryLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryLabel.setObjectName(u'dataDirectoryLabel') + self.newDataDirectoryEdit = QtGui.QLineEdit(self.dataDirectoryGroupBox) + self.newDataDirectoryEdit.setObjectName(u'newDataDirectoryEdit') + self.newDataDirectoryEdit.setReadOnly(True) + self.newDataDirectoryHasFilesLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.newDataDirectoryHasFilesLabel.setObjectName( + u'newDataDirectoryHasFilesLabel') + self.newDataDirectoryHasFilesLabel.setWordWrap(True) + self.dataDirectoryBrowseButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryBrowseButton.setObjectName( + u'dataDirectoryBrowseButton') + self.dataDirectoryBrowseButton.setIcon( + build_icon(u':/general/general_open.png')) + self.dataDirectoryDefaultButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryDefaultButton.setObjectName( + u'dataDirectoryBrowseButton') + self.dataDirectoryDefaultButton.setIcon( + build_icon(u':/general/general_revert.png')) + self.dataDirectoryCancelButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryCancelButton.setObjectName( + u'dataDirectoryCancelButton') + self.dataDirectoryCancelButton.setIcon( + build_icon(u':/general/general_revert.png')) + self.dataDirectoryCopyCheckBox = QtGui.QCheckBox( + self.dataDirectoryGroupBox) + self.dataDirectoryCopyCheckBox.setObjectName( + u'dataDirectoryCopyCheckBox') + self.dataDirectoryCopyCheckBox.hide() + self.newDataDirectoryHasFilesLabel.hide() + self.dataDirectoryDefaultButton.hide() + self.dataDirectoryCancelButton.hide() + self.dataDirectoryLayout =QtGui.QFormLayout(self.dataDirectoryGroupBox) + self.dataDirectoryLayout.setObjectName(u'dataDirectoryLayout') + self.dataDirectoryLayout.addWidget(self.dataDirectoryLabel) + self.dataDirectoryLayout.addWidget(self.dataDirectoryBrowseButton) + self.dataDirectoryLayout.addWidget(self.newDataDirectoryEdit) + self.dataDirectoryLayout.addWidget(self.dataDirectoryCopyCheckBox) + self.dataDirectoryLayout.addWidget(self.newDataDirectoryHasFilesLabel) + self.dataDirectoryLayout.addWidget(self.dataDirectoryDefaultButton) + self.dataDirectoryLayout.addWidget(self.dataDirectoryCancelButton) + self.leftLayout.addWidget(self.dataDirectoryGroupBox) self.leftLayout.addStretch() self.defaultImageGroupBox = QtGui.QGroupBox(self.rightColumn) self.defaultImageGroupBox.setObjectName(u'defaultImageGroupBox') @@ -141,6 +190,15 @@ class AdvancedTab(SettingsTab): QtCore.SIGNAL(u'pressed()'), self.onDefaultRevertButtonPressed) QtCore.QObject.connect(self.x11BypassCheckBox, QtCore.SIGNAL(u'toggled(bool)'), self.onX11BypassCheckBoxToggled) + QtCore.QObject.connect(self.dataDirectoryBrowseButton, + QtCore.SIGNAL(u'pressed()'), + self.onDataDirectoryBrowseButtonPressed) + QtCore.QObject.connect(self.dataDirectoryDefaultButton, + QtCore.SIGNAL(u'pressed()'), + self.onDataDirectoryDefaultButtonPressed) + QtCore.QObject.connect(self.dataDirectoryCancelButton, + QtCore.SIGNAL(u'pressed()'), + self.onDataDirectoryCancelButtonPressed) def retranslateUi(self): """ @@ -149,6 +207,8 @@ class AdvancedTab(SettingsTab): self.tabTitleVisible = UiStrings().Advanced self.uiGroupBox.setTitle( translate('OpenLP.AdvancedTab', 'UI Settings')) + self.dataDirectoryGroupBox.setTitle( + translate('OpenLP.AdvancedTab', 'Data Location')) self.recentLabel.setText( translate('OpenLP.AdvancedTab', 'Number of recent files to display:')) @@ -178,6 +238,33 @@ class AdvancedTab(SettingsTab): 'Browse for an image file to display.')) self.defaultRevertButton.setToolTip(translate('OpenLP.AdvancedTab', 'Revert to the default OpenLP logo.')) + self.dataDirectoryBrowseButton.setText(translate('OpenLP.AdvancedTab', + 'Select new location.')) + self.dataDirectoryBrowseButton.setToolTip( + translate('OpenLP.AdvancedTab', + 'Browse for new data file location.')) + self.dataDirectoryDefaultButton.setText( + translate('OpenLP.AdvancedTab', + 'Set to default location.')) + self.dataDirectoryDefaultButton.setToolTip( + translate('OpenLP.AdvancedTab', + 'Set the data location to the default.')) + self.dataDirectoryCancelButton.setText( + translate('OpenLP.AdvancedTab', + 'Cancel data directory change')) + self.dataDirectoryCancelButton.setToolTip( + translate('OpenLP.AdvancedTab', + 'Cancel OpenLP data directory location change.')) + self.dataDirectoryCopyCheckBox.setText( + translate('OpenLP.AdvancedTab', + 'Copy data to new location.')) + self.dataDirectoryCopyCheckBox.setToolTip( + translate('OpenLP.AdvancedTab', + 'Copy the OpenLP data files to the new location.')) + self.newDataDirectoryHasFilesLabel.setText( + translate('OpenLP.AdvancedTab', + 'Warning - New data directory location contains OpenLP ' + 'data files. These files WILL be replaced during a copy.')) self.x11GroupBox.setTitle(translate('OpenLP.AdvancedTab', 'X11')) self.x11BypassCheckBox.setText(translate('OpenLP.AdvancedTab', @@ -221,6 +308,35 @@ class AdvancedTab(SettingsTab): QtCore.QVariant(u':/graphics/openlp-splash-screen.png'))\ .toString()) settings.endGroup() + # Since data location can be changed, make sure the path is present. + data_path = AppLocation.get_data_path() + if not os.path.exists(data_path): + answer = QtGui.QMessageBox.critical(self, + translate('OpenLP.AdvancedTab', + 'Data directory error - Reset to default?'), + translate('OpenLP.AdvancedTab', + 'OpenLP data directory was not found \n\n %s \n\n' + 'This data directory was previously changed from the OpenLP ' + 'default location. If the new location was on removable ' + 'media, that media needs to be made available.\n\n' + 'Click "No" to stop loading OpenLP. allowing you to fix ' + 'the the problem.\n\n' + 'Click "Yes" to reset the data directory location to the ' + 'default' % data_path), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if answer == QtGui.QMessageBox.No: + Receiver.send_message(u'cleanup') + sys.exit() + data_path = AppLocation.set_default_data_path() + print AppLocation.IsDefaultDataPath + if AppLocation.IsDefaultDataPath: + self.dataDirectoryDefaultButton.hide() + else: + self.dataDirectoryDefaultButton.show() + self.dataDirectoryLabel.setText(data_path) self.defaultColorButton.setStyleSheet( u'background-color: %s' % self.default_color) @@ -248,6 +364,10 @@ class AdvancedTab(SettingsTab): QtCore.QVariant(self.x11BypassCheckBox.isChecked())) settings.setValue(u'default color', self.default_color) settings.setValue(u'default image', self.defaultFileEdit.text()) + if not AppLocation.IsDefaultDataPath: + settings.setValue(u'data path', self.dataDirectoryLabel.text()) + settings.setValue(u'copy data', + QtCore.QVariant(self.dataDirectoryCopyCheckBox.isChecked())) settings.endGroup() if self.display_changed: Receiver.send_message(u'config_screen_changed') @@ -271,6 +391,124 @@ class AdvancedTab(SettingsTab): self.defaultFileEdit.setText(filename) self.defaultFileEdit.setFocus() + def onDataDirectoryBrowseButtonPressed(self): + """ + Browse for a new data directory location. + """ + old_data_path = str(self.dataDirectoryLabel.text()) + old_root_path = os.path.abspath(os.path.join( + old_data_path, u'..', u'..')) + # Get the new directory location. + new_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, + translate('OpenLP.AdvancedTab', + 'Select Data Folder Root Directory'), old_root_path, + options=QtGui.QFileDialog.ShowDirsOnly)) + # Set the new data path + settings = QtCore.QSettings() + new_data_path = os.path.join(new_path, 'OpenLP', 'Data') + if new_path: + if old_data_path.lower() == new_data_path.lower(): + self.onDataDirectoryCancelButtonPressed() + return + else: + return + # Make sure they want to change the data. + answer = QtGui.QMessageBox.question(self, + translate('OpenLP.AdvancedTab', 'Change data directory?'), + translate('OpenLP.AdvancedTab', + 'Are you sure you want to change the location of the OpenLP data\n' + 'directory to:\n\n %s \n\n' + 'This is the root folder for the data. The data will be stored ' + 'in:\n\n %s \n\n ' + 'The data directory will be changed when OpenLP is closed.' + % (new_path, new_data_path)), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if answer != QtGui.QMessageBox.Yes: + return + # Check if data already exists here + self.checkDataOverwrite(new_data_path) + # Save the new location. + settings.setValue(u'%s/new data path' % self.settingsSection, + new_data_path) + self.newDataDirectoryEdit.setText(new_data_path) + self.dataDirectoryCancelButton.show() + + def onDataDirectoryDefaultButtonPressed(self): + """ + Re-set the data directory location to the 'default' location. + """ + # Make sure they want to change the data location back to the default. + answer = QtGui.QMessageBox.question(self, + translate('OpenLP.AdvancedTab', 'Reset data directory to default?'), + translate('OpenLP.AdvancedTab', + 'Are you sure you want to change the location of the OpenLP data\n' + 'directory to the default locatiom? \n\n' + 'This location will be used after OpenLP is closed.'), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if answer != QtGui.QMessageBox.Yes: + return + old_data_path = str(self.dataDirectoryLabel.text()) + new_data_path = AppLocation.get_directory(AppLocation.DataDir) + if old_data_path.lower() == new_data_path.lower(): + self.onDataDirectoryCancelButtonPressed() + return + self.checkDataOverwrite(new_data_path) + # Save the new location. + settings = QtCore.QSettings() + settings.setValue(u'%s/new data path' % self.settingsSection, + new_data_path) + self.newDataDirectoryEdit.setText(new_data_path) + self.dataDirectoryCancelButton.show() + + def checkDataOverwrite(self, data_path ): + test_path = os.path.join(data_path, u'songs') + self.dataDirectoryCopyCheckBox.show() + if os.path.exists(test_path): + # Check is they want to replace existing data + answer = QtGui.QMessageBox.warning(self, + translate('OpenLP.AdvancedTab', 'Replace existing data?'), + translate('OpenLP.AdvancedTab', + 'WARNING \n\n' + 'The location you have selected \n\n %s \n\n' + 'appears to contain OpenLP data files. Do you wish to replace ' + 'these files with the current data files?' % data_path), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if answer == QtGui.QMessageBox.Yes: + self.dataDirectoryCopyCheckBox.setChecked(True) + else: + self.dataDirectoryCopyCheckBox.setChecked(False) + self.newDataDirectoryHasFilesLabel.show() + else: + self.dataDirectoryCopyCheckBox.setChecked(True) + self.newDataDirectoryHasFilesLabel.hide() + + def onDataDirectoryCancelButtonPressed(self): + """ + Cancel the data directory location change + """ + self.newDataDirectoryEdit.setText(u'') + self.dataDirectoryCopyCheckBox.setChecked(False) + settings = QtCore.QSettings() + settings.remove(u'%s/new data path' % self.settingsSection) + settings.remove(u'%s/copy data' % self.settingsSection) + self.dataDirectoryCopyCheckBox.hide() + self.dataDirectoryCancelButton.hide() + self.newDataDirectoryHasFilesLabel.hide() + print AppLocation.IsDefaultDataPath + if AppLocation.IsDefaultDataPath: + self.dataDirectoryDefaultButton.hide() + else: + self.dataDirectoryDefaultButton.show() + def onDefaultRevertButtonPressed(self): self.defaultFileEdit.setText(u':/graphics/openlp-splash-screen.png') self.defaultFileEdit.setFocus() diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 3490dfada..f5d493ff4 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -29,13 +29,16 @@ import logging import os import sys import shutil +from distutils import dir_util +from distutils.errors import DistutilsFileError from tempfile import gettempdir from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, \ - PluginManager, Receiver, translate, ImageManager, PluginStatus + PluginManager, Receiver, translate, ImageManager, PluginStatus, \ + SettingsManager from openlp.core.lib.ui import UiStrings, base_action, checkable_action, \ icon_action, shortcut_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ @@ -629,6 +632,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'config_screen_changed'), self.screenChanged) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mainwindow_status_text'), self.showStatusMessage) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'cleanup'), self.cleanUp) # Media Manager QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged) @@ -1181,6 +1186,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.pluginManager.finalise_plugins() # Save settings self.saveSettings() + # Check if we need to change the data directory + if QtCore.QSettings().value(u'advanced/new data path', + QtCore.QVariant(u'none')).toString() != u'none': + self.changeDataDirectory() # Close down the display self.liveController.display.close() @@ -1445,3 +1454,48 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.timer_id = 0 self.loadProgressBar.hide() Receiver.send_message(u'openlp_process_events') + + def changeDataDirectory(self): + old_data_path = str(AppLocation.get_data_path()) + settings = QtCore.QSettings() + new_data_path = str(settings.value(u'advanced/new data path', + QtCore.QVariant(u'none')).toString()) + settings.remove(u'advanced/new data path') + # Copy OpenLP data to new location if requested. + if settings.value(u'advanced/copy data', + QtCore.QVariant(u'none')).toBool(): + try: + Receiver.send_message(u'openlp_process_events') + QtGui.QMessageBox.information(self, + translate('OpenLP.MainWindow', 'Copy Data Directory'), + translate('OpenLP.MainWindow', + 'OpenLP will now copy your data files from \n\n %s \n\n' + 'to \n\n %s' % (old_data_path, new_data_path)), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Ok)) + Receiver.send_message(u'cursor_busy') + dir_util.copy_tree(old_data_path, new_data_path) + except (IOError, os.error, DistutilsFileError), why: + Receiver.send_message(u'cursor_normal') + QtGui.QMessageBox.critical(self, + translate('OpenLP.MainWindow', 'New data directory error'), + translate('OpenLP.MainWindow', + 'OpenLP Data directory copy failed \n\n %s' % str(why)), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Ok)) + return False + settings.remove(u'advanced/copy data') + Receiver.send_message(u'cursor_normal') + # Change the location of data directory in config file. + settings.setValue(u'advanced/data path', new_data_path) + QtGui.QMessageBox.information(self, + translate('OpenLP.MainWindow', 'New data directory'), + translate('OpenLP.MainWindow', + 'OpenLP Data directory successfully changed to:\n\n %s \n\n' + 'The new data directory location will be used ' + 'the next time you start OpenLP.' % new_data_path), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Ok)) + # Check if the new data path is our default. + if new_data_path == AppLocation.get_directory(AppLocation.DataDir): + settings.remove(u'advanced/data path') diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 0aa5d44d0..abafe2af7 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -29,7 +29,7 @@ The :mod:`settingsform` provides a user interface for the OpenLP settings """ import logging -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, build_icon, PluginStatus from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab @@ -102,6 +102,8 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Process the form saving the settings """ + # Dialog was cancelled, remove any pending data move + QtCore.QSettings().remove(u'advanced/new data path') for tabIndex in range(0, self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9fa5bcd77..00e763751 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -126,7 +126,8 @@ class AppLocation(object): VersionDir = 5 CacheDir = 6 LanguageDir = 7 - + IsDefaultDataPath = True + # Base path where data/config/cache dir is located BaseDir = None @@ -165,10 +166,27 @@ class AppLocation(object): """ Return the path OpenLP stores all its data under. """ - path = AppLocation.get_directory(AppLocation.DataDir) - check_directory_exists(path) + # Check if we have a different data location. + path = unicode(QtCore.QSettings().value( + u'advanced/data path', QtCore.QVariant(u'none')).toString()) + if path == u'none': + AppLocation.IsDefaultDataPath = True + path = AppLocation.get_directory(AppLocation.DataDir) + check_directory_exists(path) + else: + AppLocation.IsDefaultDataPath = False return path + @staticmethod + def set_default_data_path(): + """ + Reset to default and return the path OpenLP stores all its data under. + """ + # Remove override location. + QtCore.QSettings().remove(u'advanced/data path') + data_path = AppLocation.get_data_path() + return data_path + @staticmethod def get_section_data_path(section): """ From e86272f4d501a44762a94b0159b16a242fb5d9f2 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Thu, 3 May 2012 14:30:30 -0400 Subject: [PATCH 2/7] Fixed dialogues. Made changes to GUI. --- openlp/core/ui/advancedtab.py | 311 ++++++++++++++++++--------------- openlp/core/ui/mainwindow.py | 67 +++---- openlp/core/ui/settingsform.py | 4 +- openlp/core/utils/__init__.py | 21 +-- 4 files changed, 207 insertions(+), 196 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index d04da8b61..1af8d1268 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -31,12 +31,15 @@ from datetime import datetime, timedelta from PyQt4 import QtCore, QtGui +import logging import os import sys from openlp.core.lib import SettingsTab, translate, build_icon, Receiver from openlp.core.lib.ui import UiStrings -from openlp.core.lib import SlideLimits from openlp.core.utils import get_images_filter, AppLocation +from openlp.core.lib import SlideLimits + +log = logging.getLogger(__name__) class AdvancedTab(SettingsTab): """ @@ -61,6 +64,7 @@ class AdvancedTab(SettingsTab): '#strftime-strptime-behavior for more information.')) self.defaultImage = u':/graphics/openlp-splash-screen.png' self.defaultColor = u'#ffffff' + self.dataExists = False self.iconPath = u':/system/system_settings.png' advanced_translated = translate('OpenLP.AdvancedTab', 'Advanced') SettingsTab.__init__(self, parent, u'Advanced', advanced_translated) @@ -100,53 +104,6 @@ class AdvancedTab(SettingsTab): u'enableAutoCloseCheckBox') self.uiLayout.addRow(self.enableAutoCloseCheckBox) self.leftLayout.addWidget(self.uiGroupBox) - self.dataDirectoryGroupBox = QtGui.QGroupBox(self.leftColumn) - self.dataDirectoryGroupBox.setObjectName(u'dataDirectoryGroupBox') - self.dataDirectoryLabel= QtGui.QLabel(self.dataDirectoryGroupBox) - self.dataDirectoryLabel.setObjectName(u'dataDirectoryLabel') - self.newDataDirectoryEdit = QtGui.QLineEdit(self.dataDirectoryGroupBox) - self.newDataDirectoryEdit.setObjectName(u'newDataDirectoryEdit') - self.newDataDirectoryEdit.setReadOnly(True) - self.newDataDirectoryHasFilesLabel= QtGui.QLabel(self.dataDirectoryGroupBox) - self.newDataDirectoryHasFilesLabel.setObjectName( - u'newDataDirectoryHasFilesLabel') - self.newDataDirectoryHasFilesLabel.setWordWrap(True) - self.dataDirectoryBrowseButton = QtGui.QPushButton( - self.dataDirectoryGroupBox) - self.dataDirectoryBrowseButton.setObjectName( - u'dataDirectoryBrowseButton') - self.dataDirectoryBrowseButton.setIcon( - build_icon(u':/general/general_open.png')) - self.dataDirectoryDefaultButton = QtGui.QPushButton( - self.dataDirectoryGroupBox) - self.dataDirectoryDefaultButton.setObjectName( - u'dataDirectoryBrowseButton') - self.dataDirectoryDefaultButton.setIcon( - build_icon(u':/general/general_revert.png')) - self.dataDirectoryCancelButton = QtGui.QPushButton( - self.dataDirectoryGroupBox) - self.dataDirectoryCancelButton.setObjectName( - u'dataDirectoryCancelButton') - self.dataDirectoryCancelButton.setIcon( - build_icon(u':/general/general_revert.png')) - self.dataDirectoryCopyCheckBox = QtGui.QCheckBox( - self.dataDirectoryGroupBox) - self.dataDirectoryCopyCheckBox.setObjectName( - u'dataDirectoryCopyCheckBox') - self.dataDirectoryCopyCheckBox.hide() - self.newDataDirectoryHasFilesLabel.hide() - self.dataDirectoryDefaultButton.hide() - self.dataDirectoryCancelButton.hide() - self.dataDirectoryLayout =QtGui.QFormLayout(self.dataDirectoryGroupBox) - self.dataDirectoryLayout.setObjectName(u'dataDirectoryLayout') - self.dataDirectoryLayout.addWidget(self.dataDirectoryLabel) - self.dataDirectoryLayout.addWidget(self.dataDirectoryBrowseButton) - self.dataDirectoryLayout.addWidget(self.newDataDirectoryEdit) - self.dataDirectoryLayout.addWidget(self.dataDirectoryCopyCheckBox) - self.dataDirectoryLayout.addWidget(self.newDataDirectoryHasFilesLabel) - self.dataDirectoryLayout.addWidget(self.dataDirectoryDefaultButton) - self.dataDirectoryLayout.addWidget(self.dataDirectoryCancelButton) - self.leftLayout.addWidget(self.dataDirectoryGroupBox) # Default service name self.serviceNameGroupBox = QtGui.QGroupBox(self.leftColumn) self.serviceNameGroupBox.setObjectName(u'serviceNameGroupBox') @@ -200,6 +157,70 @@ class AdvancedTab(SettingsTab): self.serviceNameLayout.addRow(self.serviceNameExampleLabel, self.serviceNameExample) self.leftLayout.addWidget(self.serviceNameGroupBox) + # Data Directory + self.dataDirectoryGroupBox = QtGui.QGroupBox(self.leftColumn) + self.dataDirectoryGroupBox.setObjectName(u'dataDirectoryGroupBox') + self.dataDirectoryLayout =QtGui.QFormLayout(self.dataDirectoryGroupBox) + self.dataDirectoryLayout.setObjectName(u'dataDirectoryLayout') + self.dataDirectoryCurrentLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryCurrentLabel.setObjectName( + u'dataDirectoryCurrentLabel') + self.dataDirectoryLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryLabel.setObjectName(u'dataDirectoryLabel') + self.dataDirectoryNewLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryNewLabel.setObjectName(u'dataDirectoryCurrentLabel') + self.newDataDirectoryEdit = QtGui.QLineEdit(self.dataDirectoryGroupBox) + self.newDataDirectoryEdit.setObjectName(u'newDataDirectoryEdit') + self.newDataDirectoryEdit.setReadOnly(True) + self.newDataDirectoryHasFilesLabel = QtGui.QLabel( + self.dataDirectoryGroupBox) + self.newDataDirectoryHasFilesLabel.setObjectName( + u'newDataDirectoryHasFilesLabel') + self.newDataDirectoryHasFilesLabel.setWordWrap(True) + self.newDataDirectoryLabelHBox = QtGui.QHBoxLayout() + self.newDataDirectoryLabelHBox.setObjectName( + u'newDataDirectoryLabelHBox') + self.dataDirectoryBrowseButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryBrowseButton.setObjectName( + u'dataDirectoryBrowseButton') + self.dataDirectoryBrowseButton.setIcon( + build_icon(u':/general/general_open.png')) + self.dataDirectoryDefaultButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryDefaultButton.setObjectName( + u'dataDirectoryDefaultButton') + self.dataDirectoryDefaultButton.setIcon( + build_icon(u':/general/general_revert.png')) + self.dataDirectoryCancelButton = QtGui.QPushButton( + self.dataDirectoryGroupBox) + self.dataDirectoryCancelButton.setObjectName( + u'dataDirectoryCancelButton') + self.dataDirectoryCancelButton.setIcon( + build_icon(u':/general/general_delete.png')) + self.newDataDirectoryLabelHBox.addWidget(self.newDataDirectoryEdit) + self.newDataDirectoryLabelHBox.addWidget( + self.dataDirectoryBrowseButton) + self.newDataDirectoryLabelHBox.addWidget( + self.dataDirectoryDefaultButton) + self.dataDirectoryCopyCheckHBox = QtGui.QHBoxLayout() + self.dataDirectoryCopyCheckHBox.setObjectName( + u'dataDirectoryCopyCheckHBox') + self.dataDirectoryCopyCheckBox = QtGui.QCheckBox( + self.dataDirectoryGroupBox) + self.dataDirectoryCopyCheckBox.setObjectName( + u'dataDirectoryCopyCheckBox') + self.dataDirectoryCopyCheckHBox.addWidget( + self.dataDirectoryCopyCheckBox) + self.dataDirectoryCopyCheckHBox.addWidget( + self.dataDirectoryCancelButton) + self.dataDirectoryLayout.addRow(self.dataDirectoryCurrentLabel, + self.dataDirectoryLabel) + self.dataDirectoryLayout.addRow(self.dataDirectoryNewLabel, + self.newDataDirectoryLabelHBox) + self.dataDirectoryLayout.addRow(self.dataDirectoryCopyCheckHBox) + self.dataDirectoryLayout.addRow(self.newDataDirectoryHasFilesLabel) + self.leftLayout.addWidget(self.dataDirectoryGroupBox) self.leftLayout.addStretch() # Default Image self.defaultImageGroupBox = QtGui.QGroupBox(self.rightColumn) @@ -268,7 +289,6 @@ class AdvancedTab(SettingsTab): self.x11Layout.addWidget(self.x11BypassCheckBox) self.rightLayout.addWidget(self.x11GroupBox) self.rightLayout.addStretch() - self.shouldUpdateServiceNameExample = False QtCore.QObject.connect(self.serviceNameCheckBox, QtCore.SIGNAL(u'toggled(bool)'), self.serviceNameCheckBoxToggled) @@ -292,21 +312,24 @@ class AdvancedTab(SettingsTab): QtCore.SIGNAL(u'clicked()'), self.onDefaultRevertButtonClicked) QtCore.QObject.connect(self.x11BypassCheckBox, QtCore.SIGNAL(u'toggled(bool)'), self.onX11BypassCheckBoxToggled) + QtCore.QObject.connect(self.dataDirectoryBrowseButton, + QtCore.SIGNAL(u'clicked()'), + self.onDataDirectoryBrowseButtonClicked) + QtCore.QObject.connect(self.dataDirectoryDefaultButton, + QtCore.SIGNAL(u'clicked()'), + self.onDataDirectoryDefaultButtonClicked) + QtCore.QObject.connect(self.dataDirectoryCancelButton, + QtCore.SIGNAL(u'clicked()'), + self.onDataDirectoryCancelButtonClicked) + QtCore.QObject.connect(self.dataDirectoryCopyCheckBox, + QtCore.SIGNAL(u'toggled(bool)'), + self.onDataDirectoryCopyCheckBoxToggled) QtCore.QObject.connect(self.endSlideRadioButton, QtCore.SIGNAL(u'clicked()'), self.onEndSlideButtonClicked) QtCore.QObject.connect(self.wrapSlideRadioButton, QtCore.SIGNAL(u'clicked()'), self.onWrapSlideButtonClicked) QtCore.QObject.connect(self.nextItemRadioButton, QtCore.SIGNAL(u'clicked()'), self.onnextItemButtonClicked) - QtCore.QObject.connect(self.dataDirectoryBrowseButton, - QtCore.SIGNAL(u'pressed()'), - self.onDataDirectoryBrowseButtonPressed) - QtCore.QObject.connect(self.dataDirectoryDefaultButton, - QtCore.SIGNAL(u'pressed()'), - self.onDataDirectoryDefaultButtonPressed) - QtCore.QObject.connect(self.dataDirectoryCancelButton, - QtCore.SIGNAL(u'pressed()'), - self.onDataDirectoryCancelButtonPressed) def retranslateUi(self): """ @@ -380,20 +403,19 @@ class AdvancedTab(SettingsTab): 'Browse for an image file to display.')) self.defaultRevertButton.setToolTip(translate('OpenLP.AdvancedTab', 'Revert to the default OpenLP logo.')) - self.dataDirectoryBrowseButton.setText(translate('OpenLP.AdvancedTab', - 'Select new location.')) + self.dataDirectoryCurrentLabel.setText(translate('OpenLP.AdvancedTab', + 'Current:')) + self.dataDirectoryNewLabel.setText(translate('OpenLP.AdvancedTab', + 'New:')) self.dataDirectoryBrowseButton.setToolTip( translate('OpenLP.AdvancedTab', 'Browse for new data file location.')) - self.dataDirectoryDefaultButton.setText( - translate('OpenLP.AdvancedTab', - 'Set to default location.')) self.dataDirectoryDefaultButton.setToolTip( translate('OpenLP.AdvancedTab', 'Set the data location to the default.')) self.dataDirectoryCancelButton.setText( translate('OpenLP.AdvancedTab', - 'Cancel data directory change')) + 'Cancel Location Change')) self.dataDirectoryCancelButton.setToolTip( translate('OpenLP.AdvancedTab', 'Cancel OpenLP data directory location change.')) @@ -405,8 +427,8 @@ class AdvancedTab(SettingsTab): 'Copy the OpenLP data files to the new location.')) self.newDataDirectoryHasFilesLabel.setText( translate('OpenLP.AdvancedTab', - 'Warning - New data directory location contains OpenLP ' - 'data files. These files WILL be replaced during a copy.')) + 'WARNING: New data directory location contains' + 'OpenLP data files. These files WILL be replaced during a copy.')) self.x11GroupBox.setTitle(translate('OpenLP.AdvancedTab', 'X11')) self.x11BypassCheckBox.setText(translate('OpenLP.AdvancedTab', @@ -484,12 +506,16 @@ class AdvancedTab(SettingsTab): else: self.nextItemRadioButton.setChecked(True) settings.endGroup() + self.dataDirectoryCopyCheckBox.hide() + self.newDataDirectoryHasFilesLabel.hide() + self.dataDirectoryCancelButton.hide() # Since data location can be changed, make sure the path is present. - data_path = AppLocation.get_data_path() - if not os.path.exists(data_path): + self.currentDataPath = AppLocation.get_data_path() + if not os.path.exists(self.currentDataPath): + log.exception(u'Data path not found %s' % self.currentDataPath) answer = QtGui.QMessageBox.critical(self, translate('OpenLP.AdvancedTab', - 'Data directory error - Reset to default?'), + 'Data Directory Error'), translate('OpenLP.AdvancedTab', 'OpenLP data directory was not found \n\n %s \n\n' 'This data directory was previously changed from the OpenLP ' @@ -497,22 +523,23 @@ class AdvancedTab(SettingsTab): 'media, that media needs to be made available.\n\n' 'Click "No" to stop loading OpenLP. allowing you to fix ' 'the the problem.\n\n' - 'Click "Yes" to reset the data directory location to the ' - 'default' % data_path), + 'Click "Yes" to reset the data directory to the default ' + 'location.' % self.currentDataPath), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) if answer == QtGui.QMessageBox.No: + log.exception(u'User requested termination') Receiver.send_message(u'cleanup') sys.exit() - data_path = AppLocation.set_default_data_path() - print AppLocation.IsDefaultDataPath - if AppLocation.IsDefaultDataPath: - self.dataDirectoryDefaultButton.hide() - else: - self.dataDirectoryDefaultButton.show() - self.dataDirectoryLabel.setText(data_path) + # Set data location to default. + settings.remove(u'advanced/data path') + self.currentDataPath = AppLocation.get_data_path() + log.exception(u'User requested data path set to default %s' + % self.currentDataPath) + self.dataDirectoryLabel.setText(os.path.abspath( + os.path.join(self.currentDataPath, u'..'))) self.defaultColorButton.setStyleSheet( u'background-color: %s' % self.defaultColor) @@ -556,10 +583,6 @@ class AdvancedTab(SettingsTab): settings.setValue(u'default color', self.defaultColor) settings.setValue(u'default image', self.defaultFileEdit.text()) settings.setValue(u'slide limits', QtCore.QVariant(self.slide_limits)) - if not AppLocation.IsDefaultDataPath: - settings.setValue(u'data path', self.dataDirectoryLabel.text()) - settings.setValue(u'copy data', - QtCore.QVariant(self.dataDirectoryCopyCheckBox.isChecked())) settings.endGroup() if self.displayChanged: Receiver.send_message(u'config_screen_changed') @@ -627,123 +650,123 @@ class AdvancedTab(SettingsTab): self.defaultFileEdit.setText(filename) self.defaultFileEdit.setFocus() - def onDataDirectoryBrowseButtonPressed(self): + def onDataDirectoryBrowseButtonClicked(self): """ Browse for a new data directory location. """ - old_data_path = str(self.dataDirectoryLabel.text()) - old_root_path = os.path.abspath(os.path.join( - old_data_path, u'..', u'..')) + old_root_path = unicode(str(self.dataDirectoryLabel.text())) # Get the new directory location. new_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, translate('OpenLP.AdvancedTab', - 'Select Data Folder Root Directory'), old_root_path, + 'Select Data Directory Location'), old_root_path, options=QtGui.QFileDialog.ShowDirsOnly)) - # Set the new data path - settings = QtCore.QSettings() - new_data_path = os.path.join(new_path, 'OpenLP', 'Data') + # Set the new data path. + new_data_path = os.path.join(new_path, 'openlp_data') if new_path: - if old_data_path.lower() == new_data_path.lower(): - self.onDataDirectoryCancelButtonPressed() + if self.currentDataPath.lower() == new_data_path.lower(): + self.onDataDirectoryCancelButtonClicked() return else: return # Make sure they want to change the data. answer = QtGui.QMessageBox.question(self, - translate('OpenLP.AdvancedTab', 'Change data directory?'), + translate('OpenLP.AdvancedTab', 'Confirm Data Directory Change'), translate('OpenLP.AdvancedTab', - 'Are you sure you want to change the location of the OpenLP data\n' - 'directory to:\n\n %s \n\n' - 'This is the root folder for the data. The data will be stored ' - 'in:\n\n %s \n\n ' - 'The data directory will be changed when OpenLP is closed.' - % (new_path, new_data_path)), + 'Are you sure you want to change the location of the OpenLP ' + 'data directory to:\n\n %s \n\n' + 'The data directory will be changed when OpenLP is closed.' + % new_path), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) if answer != QtGui.QMessageBox.Yes: return - # Check if data already exists here + # Check if data already exists here. self.checkDataOverwrite(new_data_path) # Save the new location. - settings.setValue(u'%s/new data path' % self.settingsSection, - new_data_path) - self.newDataDirectoryEdit.setText(new_data_path) + Receiver.send_message(u'set_new_data_path', new_data_path) + self.newDataDirectoryEdit.setText(new_path) self.dataDirectoryCancelButton.show() - def onDataDirectoryDefaultButtonPressed(self): + def onDataDirectoryDefaultButtonClicked(self): """ Re-set the data directory location to the 'default' location. """ - # Make sure they want to change the data location back to the default. - answer = QtGui.QMessageBox.question(self, - translate('OpenLP.AdvancedTab', 'Reset data directory to default?'), - translate('OpenLP.AdvancedTab', - 'Are you sure you want to change the location of the OpenLP data\n' - 'directory to the default locatiom? \n\n' - 'This location will be used after OpenLP is closed.'), - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Yes | - QtGui.QMessageBox.No), - QtGui.QMessageBox.No) - if answer != QtGui.QMessageBox.Yes: - return - old_data_path = str(self.dataDirectoryLabel.text()) new_data_path = AppLocation.get_directory(AppLocation.DataDir) - if old_data_path.lower() == new_data_path.lower(): - self.onDataDirectoryCancelButtonPressed() - return - self.checkDataOverwrite(new_data_path) - # Save the new location. - settings = QtCore.QSettings() - settings.setValue(u'%s/new data path' % self.settingsSection, - new_data_path) - self.newDataDirectoryEdit.setText(new_data_path) - self.dataDirectoryCancelButton.show() + if self.currentDataPath.lower() != new_data_path.lower(): + # Make sure they want to change the data location back to the default. + answer = QtGui.QMessageBox.question(self, + translate('OpenLP.AdvancedTab', 'Reset Data Directory'), + translate('OpenLP.AdvancedTab', + 'Are you sure you want to change the location of the OpenLP ' + 'data directory to the default location? \n\n' + 'This location will be used after OpenLP is closed.'), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if answer != QtGui.QMessageBox.Yes: + return + self.checkDataOverwrite(new_data_path) + # Save the new location. + Receiver.send_message(u'set_new_data_path', new_data_path) + self.newDataDirectoryEdit.setText(os.path.abspath( + os.path.join(new_data_path, u'..'))) + self.dataDirectoryCancelButton.show() + else: + # We cancel the change in case user changed their mind. + self.onDataDirectoryCancelButtonClicked() + + def onDataDirectoryCopyCheckBoxToggled(self): + Receiver.send_message(u'set_copy_data', + self.dataDirectoryCopyCheckBox.isChecked()) + if self.dataExists: + if self.dataDirectoryCopyCheckBox.isChecked(): + self.newDataDirectoryHasFilesLabel.show() + else: + self.newDataDirectoryHasFilesLabel.hide() def checkDataOverwrite(self, data_path ): test_path = os.path.join(data_path, u'songs') self.dataDirectoryCopyCheckBox.show() if os.path.exists(test_path): - # Check is they want to replace existing data + self.dataExists = True + # Check is they want to replace existing data. answer = QtGui.QMessageBox.warning(self, - translate('OpenLP.AdvancedTab', 'Replace existing data?'), + translate('OpenLP.AdvancedTab', 'Overwrite Existing Data'), translate('OpenLP.AdvancedTab', - 'WARNING \n\n' + 'WARNING: \n\n' 'The location you have selected \n\n %s \n\n' 'appears to contain OpenLP data files. Do you wish to replace ' - 'these files with the current data files?' % data_path), + 'these files with the current data files?' + % os.path.abspath(os.path.join(data_path, u'..'))), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) if answer == QtGui.QMessageBox.Yes: self.dataDirectoryCopyCheckBox.setChecked(True) + self.newDataDirectoryHasFilesLabel.show() else: self.dataDirectoryCopyCheckBox.setChecked(False) - self.newDataDirectoryHasFilesLabel.show() + self.newDataDirectoryHasFilesLabel.hide() else: + self.dataExists = False self.dataDirectoryCopyCheckBox.setChecked(True) self.newDataDirectoryHasFilesLabel.hide() - - def onDataDirectoryCancelButtonPressed(self): + + def onDataDirectoryCancelButtonClicked(self): """ Cancel the data directory location change """ - self.newDataDirectoryEdit.setText(u'') + self.newDataDirectoryEdit.clear() self.dataDirectoryCopyCheckBox.setChecked(False) - settings = QtCore.QSettings() - settings.remove(u'%s/new data path' % self.settingsSection) - settings.remove(u'%s/copy data' % self.settingsSection) + Receiver.send_message(u'set_new_data_path', u'') + Receiver.send_message(u'set_copy_data', False) self.dataDirectoryCopyCheckBox.hide() self.dataDirectoryCancelButton.hide() self.newDataDirectoryHasFilesLabel.hide() - print AppLocation.IsDefaultDataPath - if AppLocation.IsDefaultDataPath: - self.dataDirectoryDefaultButton.hide() - else: - self.dataDirectoryDefaultButton.show() def onDefaultRevertButtonClicked(self): self.defaultFileEdit.setText(u':/graphics/openlp-splash-screen.png') diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index af95d5782..0ee6c2606 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -37,8 +37,7 @@ from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, \ - PluginManager, Receiver, translate, ImageManager, PluginStatus, \ - SettingsManager + PluginManager, Receiver, translate, ImageManager, PluginStatus from openlp.core.lib.ui import UiStrings, create_action from openlp.core.lib import SlideLimits from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ @@ -583,6 +582,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Once settings are loaded update the menu with the recent files. self.updateRecentFilesMenu() self.pluginForm = PluginForm(self) + self.newDataPath = u'' + self.copyData = False # Set up signals and slots QtCore.QObject.connect(self.importThemeItem, QtCore.SIGNAL(u'triggered()'), @@ -649,6 +650,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_information_message'), self.onInformationMessage) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'set_new_data_path'), self.setNewDataPath) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'set_copy_data'), self.setCopyData) # warning cyclic dependency # renderer needs to call ThemeManager and # ThemeManager needs to call Renderer @@ -1189,8 +1194,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Save settings self.saveSettings() # Check if we need to change the data directory - if QtCore.QSettings().value(u'advanced/new data path', - QtCore.QVariant(u'none')).toString() != u'none': + if self.newDataPath: self.changeDataDirectory() # Close down the display self.liveController.display.close() @@ -1467,47 +1471,44 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.loadProgressBar.hide() Receiver.send_message(u'openlp_process_events') + def setNewDataPath(self, new_data_path): + self.newDataPath = new_data_path + + def setCopyData(self, copy_data): + self.copyData = copy_data + def changeDataDirectory(self): - old_data_path = str(AppLocation.get_data_path()) - settings = QtCore.QSettings() - new_data_path = str(settings.value(u'advanced/new data path', - QtCore.QVariant(u'none')).toString()) - settings.remove(u'advanced/new data path') + log.info(u'Changing data path to %s' % self.newDataPath ) + old_data_path = unicode(str(AppLocation.get_data_path())) # Copy OpenLP data to new location if requested. - if settings.value(u'advanced/copy data', - QtCore.QVariant(u'none')).toBool(): + if self.copyData: + log.info(u'Copying data to new path') try: Receiver.send_message(u'openlp_process_events') - QtGui.QMessageBox.information(self, - translate('OpenLP.MainWindow', 'Copy Data Directory'), - translate('OpenLP.MainWindow', - 'OpenLP will now copy your data files from \n\n %s \n\n' - 'to \n\n %s' % (old_data_path, new_data_path)), - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Ok)) Receiver.send_message(u'cursor_busy') - dir_util.copy_tree(old_data_path, new_data_path) + self.showStatusMessage( + translate('OpenLP.MainWindow', + 'Copying OpenLP data to new data directory location - %s ' + '- Please wait for copy to finish' + % os.path.abspath(os.path.join(self.newDataPath, u'..')))) + dir_util.copy_tree(old_data_path, self.newDataPath) + log.info(u'Copy sucessful') except (IOError, os.error, DistutilsFileError), why: Receiver.send_message(u'cursor_normal') + log.exception(u'Data copy failed %s' % unicode(str(why))) QtGui.QMessageBox.critical(self, - translate('OpenLP.MainWindow', 'New data directory error'), + translate('OpenLP.MainWindow', 'New Data Directory Error'), translate('OpenLP.MainWindow', - 'OpenLP Data directory copy failed \n\n %s' % str(why)), + 'OpenLP Data directory copy failed \n\n %s' + % unicode(str(why))), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Ok)) return False - settings.remove(u'advanced/copy data') - Receiver.send_message(u'cursor_normal') + else: + log.info(u'No data copy requested') # Change the location of data directory in config file. - settings.setValue(u'advanced/data path', new_data_path) - QtGui.QMessageBox.information(self, - translate('OpenLP.MainWindow', 'New data directory'), - translate('OpenLP.MainWindow', - 'OpenLP Data directory successfully changed to:\n\n %s \n\n' - 'The new data directory location will be used ' - 'the next time you start OpenLP.' % new_data_path), - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Ok)) + settings = QtCore.QSettings() + settings.setValue(u'advanced/data path', self.newDataPath) # Check if the new data path is our default. - if new_data_path == AppLocation.get_directory(AppLocation.DataDir): + if self.newDataPath == AppLocation.get_directory(AppLocation.DataDir): settings.remove(u'advanced/data path') diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 0b1d3e894..9c3dcac03 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -102,8 +102,8 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Process the form saving the settings """ - # Dialog was cancelled, remove any pending data move - QtCore.QSettings().remove(u'advanced/new data path') + # Dialogue was cancelled, remove any pending data path change. + self.advancedTab.onDataDirectoryCancelButtonClicked(); for tabIndex in range(0, self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index cd97b2a2a..d07727b2d 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -128,7 +128,6 @@ class AppLocation(object): VersionDir = 5 CacheDir = 6 LanguageDir = 7 - IsDefaultDataPath = True # Base path where data/config/cache dir is located BaseDir = None @@ -169,26 +168,14 @@ class AppLocation(object): Return the path OpenLP stores all its data under. """ # Check if we have a different data location. - path = unicode(QtCore.QSettings().value( - u'advanced/data path', QtCore.QVariant(u'none')).toString()) - if path == u'none': - AppLocation.IsDefaultDataPath = True + if QtCore.QSettings().contains("advanced/data path"): + path = unicode(QtCore.QSettings().value( + u'advanced/data path', QtCore.QVariant(u'')).toString()) + else: path = AppLocation.get_directory(AppLocation.DataDir) check_directory_exists(path) - else: - AppLocation.IsDefaultDataPath = False return path - @staticmethod - def set_default_data_path(): - """ - Reset to default and return the path OpenLP stores all its data under. - """ - # Remove override location. - QtCore.QSettings().remove(u'advanced/data path') - data_path = AppLocation.get_data_path() - return data_path - @staticmethod def get_section_data_path(section): """ From cf0e8c184e72c6e4ee610bd466a2d1b3381830b5 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Thu, 10 May 2012 19:23:45 -0400 Subject: [PATCH 3/7] Fixed code per comments. Fixed misc syntax errors. --- openlp/core/ui/advancedtab.py | 26 +++++++++++++------------- openlp/core/ui/mainwindow.py | 8 ++++---- openlp/core/utils/__init__.py | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 1af8d1268..a623c6a40 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -160,14 +160,14 @@ class AdvancedTab(SettingsTab): # Data Directory self.dataDirectoryGroupBox = QtGui.QGroupBox(self.leftColumn) self.dataDirectoryGroupBox.setObjectName(u'dataDirectoryGroupBox') - self.dataDirectoryLayout =QtGui.QFormLayout(self.dataDirectoryGroupBox) + self.dataDirectoryLayout = QtGui.QFormLayout(self.dataDirectoryGroupBox) self.dataDirectoryLayout.setObjectName(u'dataDirectoryLayout') - self.dataDirectoryCurrentLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryCurrentLabel = QtGui.QLabel(self.dataDirectoryGroupBox) self.dataDirectoryCurrentLabel.setObjectName( u'dataDirectoryCurrentLabel') - self.dataDirectoryLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryLabel = QtGui.QLabel(self.dataDirectoryGroupBox) self.dataDirectoryLabel.setObjectName(u'dataDirectoryLabel') - self.dataDirectoryNewLabel= QtGui.QLabel(self.dataDirectoryGroupBox) + self.dataDirectoryNewLabel = QtGui.QLabel(self.dataDirectoryGroupBox) self.dataDirectoryNewLabel.setObjectName(u'dataDirectoryCurrentLabel') self.newDataDirectoryEdit = QtGui.QLineEdit(self.dataDirectoryGroupBox) self.newDataDirectoryEdit.setObjectName(u'newDataDirectoryEdit') @@ -512,12 +512,12 @@ class AdvancedTab(SettingsTab): # Since data location can be changed, make sure the path is present. self.currentDataPath = AppLocation.get_data_path() if not os.path.exists(self.currentDataPath): - log.exception(u'Data path not found %s' % self.currentDataPath) + log.error(u'Data path not found %s' % self.currentDataPath) answer = QtGui.QMessageBox.critical(self, translate('OpenLP.AdvancedTab', 'Data Directory Error'), translate('OpenLP.AdvancedTab', - 'OpenLP data directory was not found \n\n %s \n\n' + 'OpenLP data directory was not found\n\n%s\n\n' 'This data directory was previously changed from the OpenLP ' 'default location. If the new location was on removable ' 'media, that media needs to be made available.\n\n' @@ -530,13 +530,13 @@ class AdvancedTab(SettingsTab): QtGui.QMessageBox.No), QtGui.QMessageBox.No) if answer == QtGui.QMessageBox.No: - log.exception(u'User requested termination') + log.info(u'User requested termination') Receiver.send_message(u'cleanup') sys.exit() # Set data location to default. settings.remove(u'advanced/data path') self.currentDataPath = AppLocation.get_data_path() - log.exception(u'User requested data path set to default %s' + log.warning(u'User requested data path set to default %s' % self.currentDataPath) self.dataDirectoryLabel.setText(os.path.abspath( os.path.join(self.currentDataPath, u'..'))) @@ -654,12 +654,12 @@ class AdvancedTab(SettingsTab): """ Browse for a new data directory location. """ - old_root_path = unicode(str(self.dataDirectoryLabel.text())) + old_root_path = unicode(self.dataDirectoryLabel.text()) # Get the new directory location. new_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, translate('OpenLP.AdvancedTab', 'Select Data Directory Location'), old_root_path, - options=QtGui.QFileDialog.ShowDirsOnly)) + options = QtGui.QFileDialog.ShowDirsOnly)) # Set the new data path. new_data_path = os.path.join(new_path, 'openlp_data') if new_path: @@ -673,7 +673,7 @@ class AdvancedTab(SettingsTab): translate('OpenLP.AdvancedTab', 'Confirm Data Directory Change'), translate('OpenLP.AdvancedTab', 'Are you sure you want to change the location of the OpenLP ' - 'data directory to:\n\n %s \n\n' + 'data directory to:\n\n%s\n\n' 'The data directory will be changed when OpenLP is closed.' % new_path), QtGui.QMessageBox.StandardButtons( @@ -700,7 +700,7 @@ class AdvancedTab(SettingsTab): translate('OpenLP.AdvancedTab', 'Reset Data Directory'), translate('OpenLP.AdvancedTab', 'Are you sure you want to change the location of the OpenLP ' - 'data directory to the default location? \n\n' + 'data directory to the default location?\n\n' 'This location will be used after OpenLP is closed.'), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | @@ -737,7 +737,7 @@ class AdvancedTab(SettingsTab): translate('OpenLP.AdvancedTab', 'Overwrite Existing Data'), translate('OpenLP.AdvancedTab', 'WARNING: \n\n' - 'The location you have selected \n\n %s \n\n' + 'The location you have selected \n\n%s\n\n' 'appears to contain OpenLP data files. Do you wish to replace ' 'these files with the current data files?' % os.path.abspath(os.path.join(data_path, u'..'))), diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 68078d305..fdcacd3d8 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -1479,7 +1479,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def changeDataDirectory(self): log.info(u'Changing data path to %s' % self.newDataPath ) - old_data_path = unicode(str(AppLocation.get_data_path())) + old_data_path = unicode(AppLocation.get_data_path()) # Copy OpenLP data to new location if requested. if self.copyData: log.info(u'Copying data to new path') @@ -1495,12 +1495,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): log.info(u'Copy sucessful') except (IOError, os.error, DistutilsFileError), why: Receiver.send_message(u'cursor_normal') - log.exception(u'Data copy failed %s' % unicode(str(why))) + log.exception(u'Data copy failed %s' % unicode(why)) QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'New Data Directory Error'), translate('OpenLP.MainWindow', - 'OpenLP Data directory copy failed \n\n %s' - % unicode(str(why))), + 'OpenLP Data directory copy failed\n\n%s' + % unicode(why)), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Ok)) return False diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9e8efa153..fd54aa338 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -128,9 +128,9 @@ class AppLocation(object): Return the path OpenLP stores all its data under. """ # Check if we have a different data location. - if QtCore.QSettings().contains("advanced/data path"): + if QtCore.QSettings().contains(u'advanced/data path'): path = unicode(QtCore.QSettings().value( - u'advanced/data path', QtCore.QVariant(u'')).toString()) + u'advanced/data path').toString()) else: path = AppLocation.get_directory(AppLocation.DataDir) check_directory_exists(path) From 0548bfb34599039957aac0602ea3b0f74465035d Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Sun, 20 May 2012 21:23:50 -0400 Subject: [PATCH 4/7] Modified code to use the directory choosen by user, don't append a sub-dir --- openlp/core/ui/advancedtab.py | 16 +++++++--------- openlp/core/ui/mainwindow.py | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index a623c6a40..f2f0389b3 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -539,7 +539,7 @@ class AdvancedTab(SettingsTab): log.warning(u'User requested data path set to default %s' % self.currentDataPath) self.dataDirectoryLabel.setText(os.path.abspath( - os.path.join(self.currentDataPath, u'..'))) + self.currentDataPath)) self.defaultColorButton.setStyleSheet( u'background-color: %s' % self.defaultColor) @@ -656,13 +656,12 @@ class AdvancedTab(SettingsTab): """ old_root_path = unicode(self.dataDirectoryLabel.text()) # Get the new directory location. - new_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, + new_data_path = unicode(QtGui.QFileDialog.getExistingDirectory(self, translate('OpenLP.AdvancedTab', 'Select Data Directory Location'), old_root_path, options = QtGui.QFileDialog.ShowDirsOnly)) # Set the new data path. - new_data_path = os.path.join(new_path, 'openlp_data') - if new_path: + if new_data_path: if self.currentDataPath.lower() == new_data_path.lower(): self.onDataDirectoryCancelButtonClicked() return @@ -675,7 +674,7 @@ class AdvancedTab(SettingsTab): 'Are you sure you want to change the location of the OpenLP ' 'data directory to:\n\n%s\n\n' 'The data directory will be changed when OpenLP is closed.' - % new_path), + % new_data_path), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), @@ -686,7 +685,7 @@ class AdvancedTab(SettingsTab): self.checkDataOverwrite(new_data_path) # Save the new location. Receiver.send_message(u'set_new_data_path', new_data_path) - self.newDataDirectoryEdit.setText(new_path) + self.newDataDirectoryEdit.setText(new_data_path) self.dataDirectoryCancelButton.show() def onDataDirectoryDefaultButtonClicked(self): @@ -711,8 +710,7 @@ class AdvancedTab(SettingsTab): self.checkDataOverwrite(new_data_path) # Save the new location. Receiver.send_message(u'set_new_data_path', new_data_path) - self.newDataDirectoryEdit.setText(os.path.abspath( - os.path.join(new_data_path, u'..'))) + self.newDataDirectoryEdit.setText(os.path.abspath(new_data_path)) self.dataDirectoryCancelButton.show() else: # We cancel the change in case user changed their mind. @@ -740,7 +738,7 @@ class AdvancedTab(SettingsTab): 'The location you have selected \n\n%s\n\n' 'appears to contain OpenLP data files. Do you wish to replace ' 'these files with the current data files?' - % os.path.abspath(os.path.join(data_path, u'..'))), + % os.path.abspath(data_path,)), QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index fdcacd3d8..f19b04174 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -1490,7 +1490,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - %s ' '- Please wait for copy to finish' - % os.path.abspath(os.path.join(self.newDataPath, u'..')))) + % self.newDataPath)) dir_util.copy_tree(old_data_path, self.newDataPath) log.info(u'Copy sucessful') except (IOError, os.error, DistutilsFileError), why: From de15cf85a39a6a45b63ac69ee0d3f5046c4cbb1f Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Fri, 1 Jun 2012 14:36:53 -0400 Subject: [PATCH 5/7] Changed some labels. Fixed GUI buttons --- openlp/core/ui/advancedtab.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index f2f0389b3..e1cfdb62d 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -177,27 +177,27 @@ class AdvancedTab(SettingsTab): self.newDataDirectoryHasFilesLabel.setObjectName( u'newDataDirectoryHasFilesLabel') self.newDataDirectoryHasFilesLabel.setWordWrap(True) - self.newDataDirectoryLabelHBox = QtGui.QHBoxLayout() - self.newDataDirectoryLabelHBox.setObjectName( - u'newDataDirectoryLabelHBox') - self.dataDirectoryBrowseButton = QtGui.QPushButton( + self.dataDirectoryBrowseButton = QtGui.QToolButton( self.dataDirectoryGroupBox) self.dataDirectoryBrowseButton.setObjectName( u'dataDirectoryBrowseButton') self.dataDirectoryBrowseButton.setIcon( build_icon(u':/general/general_open.png')) - self.dataDirectoryDefaultButton = QtGui.QPushButton( + self.dataDirectoryDefaultButton = QtGui.QToolButton( self.dataDirectoryGroupBox) self.dataDirectoryDefaultButton.setObjectName( u'dataDirectoryDefaultButton') self.dataDirectoryDefaultButton.setIcon( build_icon(u':/general/general_revert.png')) - self.dataDirectoryCancelButton = QtGui.QPushButton( + self.dataDirectoryCancelButton = QtGui.QToolButton( self.dataDirectoryGroupBox) self.dataDirectoryCancelButton.setObjectName( u'dataDirectoryCancelButton') self.dataDirectoryCancelButton.setIcon( build_icon(u':/general/general_delete.png')) + self.newDataDirectoryLabelHBox = QtGui.QHBoxLayout() + self.newDataDirectoryLabelHBox.setObjectName( + u'newDataDirectoryLabelHBox') self.newDataDirectoryLabelHBox.addWidget(self.newDataDirectoryEdit) self.newDataDirectoryLabelHBox.addWidget( self.dataDirectoryBrowseButton) @@ -212,6 +212,7 @@ class AdvancedTab(SettingsTab): u'dataDirectoryCopyCheckBox') self.dataDirectoryCopyCheckHBox.addWidget( self.dataDirectoryCopyCheckBox) + self.dataDirectoryCopyCheckHBox.addStretch() self.dataDirectoryCopyCheckHBox.addWidget( self.dataDirectoryCancelButton) self.dataDirectoryLayout.addRow(self.dataDirectoryCurrentLabel, @@ -404,9 +405,9 @@ class AdvancedTab(SettingsTab): self.defaultRevertButton.setToolTip(translate('OpenLP.AdvancedTab', 'Revert to the default OpenLP logo.')) self.dataDirectoryCurrentLabel.setText(translate('OpenLP.AdvancedTab', - 'Current:')) + 'Current path:')) self.dataDirectoryNewLabel.setText(translate('OpenLP.AdvancedTab', - 'New:')) + 'Custom path:')) self.dataDirectoryBrowseButton.setToolTip( translate('OpenLP.AdvancedTab', 'Browse for new data file location.')) @@ -415,7 +416,7 @@ class AdvancedTab(SettingsTab): 'Set the data location to the default.')) self.dataDirectoryCancelButton.setText( translate('OpenLP.AdvancedTab', - 'Cancel Location Change')) + 'Cancel')) self.dataDirectoryCancelButton.setToolTip( translate('OpenLP.AdvancedTab', 'Cancel OpenLP data directory location change.')) @@ -427,7 +428,7 @@ class AdvancedTab(SettingsTab): 'Copy the OpenLP data files to the new location.')) self.newDataDirectoryHasFilesLabel.setText( translate('OpenLP.AdvancedTab', - 'WARNING: New data directory location contains' + 'WARNING: New data directory location contains ' 'OpenLP data files. These files WILL be replaced during a copy.')) self.x11GroupBox.setTitle(translate('OpenLP.AdvancedTab', 'X11')) From b8cd0dc7b3136d8cf00a2b1a86e85ee404829e68 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Fri, 8 Jun 2012 15:27:08 -0400 Subject: [PATCH 6/7] Moved cancel button call to advancedtab --- openlp/core/ui/advancedtab.py | 4 ++++ openlp/core/ui/settingsform.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index e1cfdb62d..061d69a35 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -590,6 +590,10 @@ class AdvancedTab(SettingsTab): self.displayChanged = False Receiver.send_message(u'slidecontroller_update_slide_limits') + def cancel(self): + # Dialogue was cancelled, remove any pending data path change. + self.onDataDirectoryCancelButtonClicked() + def serviceNameCheckBoxToggled(self, default_service_enabled): self.serviceNameDay.setEnabled(default_service_enabled) time_enabled = default_service_enabled and \ diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 03f5c93a5..d183d9d4a 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -102,8 +102,6 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Process the form saving the settings """ - # Dialogue was cancelled, remove any pending data path change. - self.advancedTab.onDataDirectoryCancelButtonClicked(); for tabIndex in range(self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) From 67093ed65f81e50a1dc2c2fabbf0278a2258caaf Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Sat, 9 Jun 2012 08:03:47 -0400 Subject: [PATCH 7/7] Added code to call superclass cancel --- openlp/core/ui/advancedtab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 061d69a35..1c382cf5e 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -593,6 +593,7 @@ class AdvancedTab(SettingsTab): def cancel(self): # Dialogue was cancelled, remove any pending data path change. self.onDataDirectoryCancelButtonClicked() + SettingsTab.cancel(self) def serviceNameCheckBoxToggled(self, default_service_enabled): self.serviceNameDay.setEnabled(default_service_enabled)