openlp/openlp/core/ui/firsttimeform.py

233 lines
11 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 io
2011-02-26 15:19:43 +00:00
import logging
2011-03-04 18:22:44 +00:00
import os
import urllib
2011-03-10 13:15:49 +00:00
from random import randint
2011-03-10 19:48:15 +00:00
from tempfile import gettempdir
2011-03-10 13:15:49 +00:00
from ConfigParser import SafeConfigParser
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
from openlp.core.lib import translate, PluginStatus, check_directory_exists, \
2011-03-10 19:48:15 +00:00
Receiver, build_icon
2011-03-04 18:22:44 +00:00
from openlp.core.utils import get_web_page, AppLocation
from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
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)
self.setupUi(self)
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-10 13:15:49 +00:00
self.config = SafeConfigParser()
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg?%s' % randint(0, 20)))
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-03-04 19:02:00 +00:00
for screen in screens.get_screen_list():
2011-03-10 13:15:49 +00:00
self.displayComboBox.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:
2011-03-10 13:15:49 +00:00
songs = self.config.get(u'songs', u'languages')
songs = songs.split(u',')
for song in songs:
title = unicode(self.config.get(
u'songs_%s' % song, u'title'), u'utf8')
filename = unicode(self.config.get(
u'songs_%s' % song, u'filename'), u'utf8')
item = QtGui.QListWidgetItem(title, self.songsListWidget)
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename))
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
bible_languages = self.config.get(u'bibles', u'languages')
bible_languages = bible_languages.split(u',')
2011-03-10 19:48:15 +00:00
for lang in bible_languages:
2011-03-10 13:15:49 +00:00
language = unicode(self.config.get(
u'bibles_%s' % lang, u'title'), u'utf8')
langItem = QtGui.QTreeWidgetItem(
self.biblesTreeWidget, QtCore.QStringList(language))
bibles = self.config.get(u'bibles_%s' % lang, u'translations')
bibles = bibles.split(u',')
for bible in bibles:
title = unicode(self.config.get(
u'bible_%s' % bible, u'title'), u'utf8')
filename = unicode(self.config.get(
u'bible_%s' % bible, u'filename'))
item = QtGui.QTreeWidgetItem(
langItem, QtCore.QStringList(title))
item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
item.setCheckState(0, QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
self.biblesTreeWidget.expandAll()
themes = self.config.get(u'themes', u'files')
themes = themes.split(u',')
for theme in themes:
title = self.config.get(u'theme_%s' % theme, u'title')
filename = self.config.get(u'theme_%s' % theme, u'filename')
screenshot = self.config.get(u'theme_%s' % theme, u'screenshot')
2011-03-10 19:48:15 +00:00
urllib.urlretrieve(u'%s/%s' % (self.web, screenshot),
os.path.join(gettempdir(), screenshot))
2011-03-10 13:15:49 +00:00
item = QtGui.QListWidgetItem(title, self.themesListWidget)
2011-03-10 19:48:15 +00:00
item.setData(QtCore.Qt.UserRole,
QtCore.QVariant(filename))
item.setIcon(build_icon(
os.path.join(gettempdir(), screenshot)))
2011-03-10 13:15:49 +00:00
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
2011-02-26 20:52:26 +00:00
def nextId(self):
"""
Determine the next page in the Wizard to go to.
"""
if self.currentId() == FirstTimePage.Plugins:
if not self.webAccess:
return FirstTimePage.NoInternet
else:
return FirstTimePage.Songs
else:
return self.currentId() + 1
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
"""
if pageId == FirstTimePage.NoInternet:
self.finishButton.setVisible(True)
self.finishButton.setEnabled(True)
self.nextButton.setVisible(False)
2011-03-10 13:15:49 +00:00
elif pageId == FirstTimePage.Defaults:
self.themeComboBox.clear()
2011-03-10 19:48:15 +00:00
for iter in xrange(self.themesListWidget.count()):
item = self.themesListWidget.item(iter)
if item.checkState() == QtCore.Qt.Checked:
self.themeComboBox.addItem(item.text())
2011-03-02 21:47:55 +00:00
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-10 13:15:49 +00:00
destination = AppLocation.get_temp_path()
check_directory_exists(destination)
bibles_destination = AppLocation.get_section_data_path(u'bibles')
check_directory_exists(bibles_destination)
themes_destination = AppLocation.get_section_data_path(u'themes')
check_directory_exists(destination)
# Install songs
songs_iterator = QtGui.QListWidgetItemIterator(self.songsListWidget)
while songs_iterator.value():
item = songs_iterator.value()
if item.checkState() == QtCore.Qt.Checked:
filename = item.data(QtCore.Qt.UserRole).toString()
urllib.urlretrieve(u'%s%s' % (self.web, filename),
os.path.join(destination, filename))
#importer = SongImporter()
songs_iterator += 1
# Install Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
while bibles_iterator.value():
item = bibles_iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
urllib.urlretrieve(u'%s%s' % (self.web, bible),
os.path.join(bibles_destination, bible))
bibles_iterator += 1
themes_iterator = QtGui.QListWidgetItemIterator(self.themesListWidget)
while themes_iterator.value():
item = themes_iterator.value()
if item.checkState() == QtCore.Qt.Checked:
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
urllib.urlretrieve(u'%s%s' % (self.web, theme),
os.path.join(theme_destination, theme))
themes_iterator += 1
2011-03-06 13:44:35 +00:00
# Set Default Display
2011-03-10 13:15:49 +00:00
if self.displayComboBox.currentIndex() != -1:
2011-03-06 13:44:35 +00:00
QtCore.QSettings().setValue(u'General/monitor',
2011-03-10 13:15:49 +00:00
QtCore.QVariant(self.displayComboBox.currentIndex()))
2011-03-06 13:44:35 +00:00
# Set Global Theme
2011-03-10 13:15:49 +00:00
if self.themeComboBox.currentIndex() != -1:
2011-03-06 13:44:35 +00:00
QtCore.QSettings().setValue(u'themes/global theme',
2011-03-10 13:15:49 +00:00
QtCore.QVariant(self.themeComboBox.currentText()))
2011-03-06 13:44:35 +00:00
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')