openlp/openlp/core/ui/firsttimeform.py

218 lines
10 KiB
Python
Raw Normal View History

2011-02-26 11:16:21 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Meinert Jordan, Armin Köhler, Andreas Preikschat, #
# Christian Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon #
# Tibble, Carsten Tinggaard, Frode Woldsund #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2011-03-02 19:01:18 +00:00
import ConfigParser
import io
2011-02-26 15:19:43 +00:00
import logging
2011-03-04 18:22:44 +00:00
import os
import urllib
2011-02-26 15:19:43 +00:00
2011-02-26 16:51:00 +00:00
from PyQt4 import QtCore, QtGui
2011-02-26 11:16:21 +00:00
2011-02-26 15:19:43 +00:00
from firsttimewizard import Ui_FirstTimeWizard
2011-02-26 11:16:21 +00:00
2011-03-06 13:44:35 +00:00
from openlp.core.lib import translate, PluginStatus, check_directory_exists, \
Receiver
2011-03-04 18:22:44 +00:00
from openlp.core.utils import get_web_page, AppLocation
2011-02-26 11:16:21 +00:00
2011-03-06 19:44:33 +00:00
log = logging.getLogger(__name__)
2011-02-26 15:19:43 +00:00
class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
"""
This is the Theme Import Wizard, which allows easy creation and editing of
OpenLP themes.
"""
log.info(u'ThemeWizardForm loaded')
2011-02-26 11:16:21 +00:00
2011-03-06 19:44:33 +00:00
def __init__(self, screens, parent=None):
QtGui.QWizard.__init__(self, parent)
2011-02-26 11:16:21 +00:00
# check to see if we have web access
2011-03-04 18:22:44 +00:00
self.web = u'http://openlp.org/files/frw/'
2011-03-02 19:01:18 +00:00
self.config = ConfigParser.ConfigParser()
2011-03-04 18:22:44 +00:00
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg'))
2011-02-27 15:33:08 +00:00
if self.webAccess:
2011-03-02 19:01:18 +00:00
files = self.webAccess.read()
self.config.readfp(io.BytesIO(files))
2011-02-26 15:19:43 +00:00
self.setupUi(self)
2011-03-04 19:02:00 +00:00
for screen in screens.get_screen_list():
self.displaySelectionComboBox.addItem(screen)
2011-03-05 09:23:47 +00:00
self.songsText = translate('OpenLP.FirstTimeWizard', 'Songs')
self.biblesText = translate('OpenLP.FirstTimeWizard', 'Bibles')
self.themesText = translate('OpenLP.FirstTimeWizard', 'Themes')
self.startUpdates = translate('OpenLP.FirstTimeWizard',
'Starting Updates')
2011-03-06 20:09:03 +00:00
self.downloading = unicode(translate('OpenLP.FirstTimeWizard',
'Downloading %s'))
2011-03-07 19:58:51 +00:00
QtCore.QObject.connect(self,
QtCore.SIGNAL(u'currentIdChanged(int)'),
self.onCurrentIdChanged)
2011-02-26 15:19:43 +00:00
2011-02-26 20:52:26 +00:00
def exec_(self, edit=False):
"""
Run the wizard.
"""
self.setDefaults()
return QtGui.QWizard.exec_(self)
def setDefaults(self):
"""
Set up display at start of theme edit.
"""
self.restart()
2011-02-27 14:29:19 +00:00
# Sort out internet access for downloads
2011-02-26 20:52:26 +00:00
if self.webAccess:
self.internetGroupBox.setVisible(True)
self.noInternetLabel.setVisible(False)
2011-03-07 17:38:04 +00:00
# If songs database exists do not allow a copy
songs = os.path.join(AppLocation.get_section_data_path(u'songs'),
u'songs.sqlite')
if not os.path.exists(songs):
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
treewidgetitem.setText(0, self.songsText)
self._loadChild(treewidgetitem, u'songs', u'languages', u'songs')
2011-03-02 19:01:18 +00:00
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
2011-03-05 09:23:47 +00:00
treewidgetitem.setText(0, self.biblesText)
2011-03-06 19:25:35 +00:00
self._loadChild(treewidgetitem, u'bibles', u'translations',
2011-03-06 13:44:35 +00:00
u'bible')
2011-03-02 19:01:18 +00:00
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
2011-03-05 09:23:47 +00:00
treewidgetitem.setText(0, self.themesText)
2011-03-06 19:25:35 +00:00
self._loadChild(treewidgetitem, u'themes', u'files', 'theme')
2011-02-26 20:52:26 +00:00
else:
self.internetGroupBox.setVisible(False)
self.noInternetLabel.setVisible(True)
2011-02-27 15:33:08 +00:00
2011-03-06 19:25:35 +00:00
def _loadChild(self, tree, list, tag, root):
2011-03-02 19:01:18 +00:00
files = self.config.get(list, tag)
files = files.split(u',')
for file in files:
if file:
2011-02-27 15:33:08 +00:00
child = QtGui.QTreeWidgetItem(tree)
2011-03-05 09:23:47 +00:00
child.setText(0, self.config.get(u'%s_%s'
% (root, file), u'title'))
2011-03-02 21:47:55 +00:00
child.setData(0, QtCore.Qt.UserRole,
2011-03-05 09:23:47 +00:00
QtCore.QVariant(self.config.get(u'%s_%s'
% (root, file), u'filename')))
2011-02-27 15:33:08 +00:00
child.setCheckState(0, QtCore.Qt.Unchecked)
child.setFlags(QtCore.Qt.ItemIsUserCheckable |
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2011-02-26 20:52:26 +00:00
2011-03-07 19:58:51 +00:00
def onCurrentIdChanged(self, pageId):
2011-03-02 21:47:55 +00:00
"""
2011-03-07 19:58:51 +00:00
Detects Page changes and updates as approprate.
2011-03-02 21:47:55 +00:00
"""
2011-03-07 19:58:51 +00:00
if self.page(pageId) == self.DefaultsPage:
2011-03-08 18:50:26 +00:00
self.themeSelectionComboBox.clear()
2011-03-05 09:23:47 +00:00
listIterator = QtGui.QTreeWidgetItemIterator(
self.selectionTreeWidget)
2011-03-02 21:47:55 +00:00
while listIterator.value():
parent = listIterator.value().parent()
2011-03-05 09:23:47 +00:00
if parent and listIterator.value().checkState(0) \
== QtCore.Qt.Checked:
if unicode(parent.text(0)) == self.themesText:
2011-03-06 13:44:35 +00:00
self.themeSelectionComboBox.addItem(
listIterator.value().text(0))
2011-03-02 21:47:55 +00:00
listIterator += 1
2011-02-26 15:19:43 +00:00
def accept(self):
2011-03-07 19:58:51 +00:00
Receiver.send_message(u'cursor_busy')
2011-03-06 19:25:35 +00:00
self._updateMessage(self.startUpdates)
2011-03-06 13:44:35 +00:00
# Set up the Plugin status's
2011-03-06 19:25:35 +00:00
self._pluginStatus(self.songsCheckBox, u'songs/status')
self._pluginStatus(self.bibleCheckBox, u'bibles/status')
self._pluginStatus(self.presentationCheckBox, u'presentations/status')
self._pluginStatus(self.imageCheckBox, u'images/status')
self._pluginStatus(self.mediaCheckBox, u'media/status')
self._pluginStatus(self.remoteCheckBox, u'remotes/status')
self._pluginStatus(self.customCheckBox, u'custom/status')
self._pluginStatus(self.songUsageCheckBox, u'songusage/status')
self._pluginStatus(self.alertCheckBox, u'alerts/status')
2011-03-06 13:44:35 +00:00
# Build directories for downloads
2011-03-04 18:22:44 +00:00
songsDestination = AppLocation.get_section_data_path(u'songs')
check_directory_exists(songsDestination)
bibleDestination = AppLocation.get_section_data_path(u'bibles')
check_directory_exists(bibleDestination)
themeDestination = AppLocation.get_section_data_path(u'themes')
check_directory_exists(themeDestination)
2011-03-06 13:44:35 +00:00
# Install Selected Items looping through them
listIterator = QtGui.QTreeWidgetItemIterator(self.selectionTreeWidget)
2011-03-02 21:47:55 +00:00
while listIterator.value():
type = listIterator.value().parent()
if listIterator.value().parent():
if listIterator.value().checkState(0) == QtCore.Qt.Checked:
2011-03-06 13:44:35 +00:00
# Install items as theu have been selected
item = unicode(listIterator.value().text(0))
# Download Song database if selected
if unicode(type.text(0)) == self.songsText:
songs = unicode(listIterator.value().data(0,
QtCore.Qt.UserRole).toString())
2011-03-06 20:09:03 +00:00
message = self.downloading % item
2011-03-06 19:25:35 +00:00
self._updateMessage(message)
2011-03-06 13:44:35 +00:00
# Song database is a fixed file name
urllib.urlretrieve(u'%s%s' % (self.web, songs),
os.path.join(songsDestination, u'songs.sqlite'))
# Download and selected Bibles
2011-03-05 09:23:47 +00:00
if unicode(type.text(0)) == self.biblesText:
bible = unicode(listIterator.value().data(0,
2011-03-04 18:22:44 +00:00
QtCore.Qt.UserRole).toString())
2011-03-06 20:09:03 +00:00
message = self.downloading % item
2011-03-06 19:25:35 +00:00
self._updateMessage(message)
2011-03-05 09:23:47 +00:00
urllib.urlretrieve(u'%s%s' % (self.web, bible),
os.path.join(bibleDestination, bible))
2011-03-06 13:44:35 +00:00
# Download any themes
2011-03-05 09:23:47 +00:00
if unicode(type.text(0)) == self.themesText:
2011-03-04 18:22:44 +00:00
theme = unicode(listIterator.value().data(0,
QtCore.Qt.UserRole).toString())
2011-03-06 20:09:03 +00:00
message = self.downloading % item
2011-03-06 19:25:35 +00:00
self._updateMessage(message)
2011-03-04 18:22:44 +00:00
urllib.urlretrieve(u'%s%s' % (self.web, theme),
os.path.join(themeDestination, theme))
2011-03-02 21:47:55 +00:00
listIterator += 1
2011-03-06 13:44:35 +00:00
# Set Default Display
if self.displaySelectionComboBox.currentIndex() != -1:
QtCore.QSettings().setValue(u'General/monitor',
QtCore.QVariant(self.displaySelectionComboBox.
currentIndex()))
# Set Global Theme
if self.themeSelectionComboBox.currentIndex() != -1:
QtCore.QSettings().setValue(u'themes/global theme',
QtCore.QVariant(self.themeSelectionComboBox.currentText()))
QtCore.QSettings().setValue(u'general/first time',
QtCore.QVariant(False))
2011-03-07 19:58:51 +00:00
Receiver.send_message(u'cursor_normal')
2011-02-26 15:19:43 +00:00
return QtGui.QWizard.accept(self)
2011-02-26 16:51:00 +00:00
2011-03-06 19:25:35 +00:00
def _pluginStatus(self, field, tag):
2011-02-26 16:51:00 +00:00
status = PluginStatus.Active if field.checkState() \
== QtCore.Qt.Checked else PluginStatus.Inactive
QtCore.QSettings().setValue(tag, QtCore.QVariant(status))
2011-03-05 09:23:47 +00:00
2011-03-06 19:25:35 +00:00
def _updateMessage(self, text):
2011-03-06 13:44:35 +00:00
"""
Keep screen up to date
"""
2011-03-05 09:23:47 +00:00
self.updateLabel.setText(text)
Receiver.send_message(u'openlp_process_events')