~tomasgroth/openlp/portable-path

« back to all changes in this revision

Viewing changes to openlp/core/lib/serviceitem.py

  • Committer: Tim Bentley
  • Author(s): Phill
  • Date: 2018-01-24 20:55:22 UTC
  • mfrom: (2803.3.14 pathlib12)
  • Revision ID: tim.bentley@gmail.com-20180124205522-k20tv9ybia457stj
Started work on storing path objects in service file.
Refactored save code and reduced duplication.
Fixed + improved the loading / saving progress bars
improved performance

loading powerpoint from a service still does work

--------------------------------------------------------------------------------
lp:~phill-ridout/openlp/pathlib12 (revision 2817)
https://ci.openlp.io/job/Branch-01-Pull/2428/                          [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-02a-Linu...

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from openlp.core.common.applocation import AppLocation
37
37
from openlp.core.common.i18n import translate
38
38
from openlp.core.common.mixins import RegistryProperties
 
39
from openlp.core.common.path import Path
39
40
from openlp.core.common.settings import Settings
40
41
from openlp.core.lib import ImageSource, build_icon, clean_tags, expand_tags, expand_chords
41
42
 
427
428
        self.has_original_files = True
428
429
        if 'background_audio' in header:
429
430
            self.background_audio = []
430
 
            for filename in header['background_audio']:
431
 
                # Give them real file paths.
432
 
                filepath = str(filename)
433
 
                if path:
 
431
            for file_path in header['background_audio']:
 
432
                # In OpenLP 3.0 we switched to storing Path objects in JSON files
 
433
                if isinstance(file_path, str):
 
434
                    # Handle service files prior to OpenLP 3.0
434
435
                    # Windows can handle both forward and backward slashes, so we use ntpath to get the basename
435
 
                    filepath = os.path.join(path, ntpath.basename(str(filename)))
436
 
                self.background_audio.append(filepath)
 
436
                    file_path = Path(path, ntpath.basename(file_path))
 
437
                self.background_audio.append(file_path)
437
438
        self.theme_overwritten = header.get('theme_overwritten', False)
438
439
        if self.service_item_type == ServiceItemType.Text:
439
440
            for slide in service_item['serviceitem']['data']:
444
445
            if path:
445
446
                self.has_original_files = False
446
447
                for text_image in service_item['serviceitem']['data']:
447
 
                    filename = os.path.join(path, text_image)
448
 
                    self.add_from_image(filename, text_image, background)
 
448
                    file_path = os.path.join(path, text_image)
 
449
                    self.add_from_image(file_path, text_image, background)
449
450
            else:
450
451
                for text_image in service_item['serviceitem']['data']:
451
452
                    self.add_from_image(text_image['path'], text_image['title'], background)