openlp/openlp/core/ui/firsttimeform.py

114 lines
5.2 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-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-02-26 16:51:00 +00:00
from openlp.core.lib import translate, PluginStatus
2011-03-02 17:44:33 +00:00
from openlp.core.utils import get_web_page
2011-02-26 11:16:21 +00:00
2011-02-26 15:19:43 +00:00
log = logging.getLogger(__name__)
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-02-26 15:19:43 +00:00
def __init__(self, parent=None):
2011-02-26 11:16:21 +00:00
# check to see if we have web access
2011-03-02 19:01:18 +00:00
self.config = ConfigParser.ConfigParser()
self.webAccess = get_web_page(u'http://openlp.org/files/frw/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
QtGui.QWizard.__init__(self, parent)
self.setupUi(self)
#self.registerFields()
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-02 19:01:18 +00:00
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
treewidgetitem.setText(0, u'Songs')
self.__loadChild(treewidgetitem, u'songs', u'languages', u'songs')
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
treewidgetitem.setText(0, u'Bibles')
self.__loadChild(treewidgetitem, u'bibles', u'translations', u'bible')
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget)
treewidgetitem.setText(0, u'Themes')
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-02 19:01:18 +00:00
def __loadChild(self, tree, list, tag, root):
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-02 19:01:18 +00:00
child.setText(0, self.config.get(u'%s_%s' %(root, file), u'title'))
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-02-26 15:19:43 +00:00
def accept(self):
2011-02-26 16:51:00 +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')
2011-02-27 14:29:19 +00:00
self.__pluginStatus(self.remoteCheckBox, u'remotes/status')
2011-02-26 16:51:00 +00:00
self.__pluginStatus(self.customCheckBox, u'custom/status')
self.__pluginStatus(self.songUsageCheckBox, u'songusage/status')
2011-02-26 20:52:26 +00:00
self.__pluginStatus(self.alertCheckBox, u'alerts/status')
2011-02-26 15:19:43 +00:00
return QtGui.QWizard.accept(self)
2011-02-26 16:51:00 +00:00
def __pluginStatus(self, field, tag):
status = PluginStatus.Active if field.checkState() \
== QtCore.Qt.Checked else PluginStatus.Inactive
QtCore.QSettings().setValue(tag, QtCore.QVariant(status))