~ubuntu-branches/ubuntu/lucid/gnome-subtitles/lucid

« back to all changes in this revision

Viewing changes to sublib-0.8/src/SubLib/Application/SubtitleSaver.cs

  • Committer: Bazaar Package Importer
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2007-12-03 20:52:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071203205252-2y6uuv4gcw9mi9n5
Tags: 0.7-1
* New upstream release;
* Add libxml-parser-perl to Build-Depends-Indep. Thanks to Lucas Nussbaum.
  (Closes: #445799);
* Fixes manpage issue with dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of SubLib.
 
3
 * Copyright (C) 2005-2007 Pedro Castro
 
4
 *
 
5
 * SubLib is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * SubLib is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
namespace SubLib {
 
21
 
 
22
/// <summary>Represents the main mechanism for saving <see cref="Subtitles" />.</summary>
 
23
public class SubtitleSaver {
 
24
        private FileProperties fileProperties = null;
 
25
 
 
26
        
 
27
        /* Public properties */
 
28
        
 
29
        /// <summary>The new properties of the file after saving.</summary>
 
30
        /// <remarks>This includes the updated <see cref="TimingMode" /> for the subtitles after saving. When saving to
 
31
        /// a subtitle format that supports only time or frame timing modes, this is updated to reflect that.</remarks>
 
32
        public FileProperties FileProperties {
 
33
                get { return fileProperties; }
 
34
        }
 
35
        
 
36
        /* Public methods */
 
37
        
 
38
        /// <summary>Saves subtitles to the file with the specified properties.</summary>
 
39
        /// <param name="subtitles">The subtitles to save.</param>
 
40
        /// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to
 
41
        /// choose the timing mode for subtitle formats that support both time and frame modes.</param>
 
42
        /// <param name="textType">The type of text content to save.</param>
 
43
        /// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks>
 
44
        public void Save (Subtitles subtitles, FileProperties properties, SubtitleTextType textType) {
 
45
                SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
 
46
                SubtitleOutput output = new SubtitleOutput(format, textType);
 
47
 
 
48
                string text = output.Build(subtitles.Collection, subtitles.Properties, properties);
 
49
                FileInputOutput.WriteFile(properties.Path, text, properties.Encoding);
 
50
 
 
51
                
 
52
                fileProperties = GetUpdatedFileProperties(properties); 
 
53
                VerboseConsole.WriteLine("[*] Saved " + textType + " " + properties.Path + " with encoding " + properties.Encoding + " and format " + format.Name);
 
54
        }
 
55
        
 
56
        /* Private methods */
 
57
        
 
58
        private FileProperties GetUpdatedFileProperties (FileProperties properties) {
 
59
                SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
 
60
                TimingMode newTimingMode = (format.Mode == SubtitleMode.Both) ? properties.TimingMode : format.ModeAsTimingMode;
 
61
                
 
62
                return new FileProperties(properties.Path, properties.Encoding, properties.SubtitleType, newTimingMode, properties.NewlineType);
 
63
        }
 
64
}
 
65
 
 
66
}
 
 
b'\\ No newline at end of file'