Class: Yast::SlidesClass

Inherits:
Module
  • Object
show all
Defined in:
library/packages/src/modules/Slides.rb

Instance Method Summary collapse

Instance Method Details

#CheckBasePathBoolean

Check, if the base path set up for slides is valid (it exists and contains slides)



215
216
217
218
219
220
221
222
223
224
# File 'library/packages/src/modules/Slides.rb', line 215

def CheckBasePath
  tmp = Convert.to_map(WFM.Read(path(".local.stat"), @slide_base_path))
  if !Ops.get_boolean(tmp, "isdir", false)
    Builtins.y2error("Using default path instead of %1", @slide_base_path)
    @slide_base_path = "/var/adm/YaST/InstSrcManager/tmp/CurrentMedia/suse/setup/slide"

    return false
  end
  true
end

#GetSlideList(lang) ⇒ Array

Get a list of available slides (images) for the slide show.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'library/packages/src/modules/Slides.rb', line 59

def GetSlideList(lang)
  slide_list = nil

  txt_path = Builtins.sformat("%1/txt/%2", @slide_base_path, lang)
  if FileUtils.Exists(txt_path)
    slide_list = Convert.convert(
      SCR.Read(path(".target.dir"), txt_path),
      from: "any",
      to:   "list <string>"
    )
  end

  if slide_list.nil?
    Builtins.y2error("Directory %1 does not exist", txt_path)
    if Ops.greater_than(Builtins.size(lang), 2)
      lang = Builtins.substring(lang, 0, 2)
      txt_path = Builtins.sformat("%1/txt/%2", @slide_base_path, lang)

      if FileUtils.Exists(txt_path)
        slide_list = Convert.convert(
          SCR.Read(path(".target.dir"), txt_path),
          from: "any",
          to:   "list <string>"
        )
      end
    end
  end

  if slide_list.nil?
    Builtins.y2milestone("Slideshow directory %1 does not exist", txt_path)
  else
    Builtins.y2milestone(
      "Using slides from '%1' (%2 slides)",
      txt_path,
      Builtins.size(slide_list)
    )

    slide_list = Builtins.sort(Builtins.filter(slide_list) do |filename|
      Builtins.regexpmatch(filename, ".*.(rtf|RTF|html|HTML|htm|HTM)$")
    end)

    Builtins.y2debug(
      "GetSlideList(): Slides at %1: %2",
      txt_path,
      slide_list
    )
  end

  if !slide_list.nil? && Ops.greater_than(Builtins.size(slide_list), 0) # Slide texts found
    @slide_txt_path = txt_path
    @slide_pic_path = Ops.add(@slide_base_path, "/pic")

    Builtins.y2milestone(
      "Using TXT: %1, PIC: %2",
      @slide_txt_path,
      @slide_pic_path
    ) # No slide texts found
  else
    Builtins.y2debug("No slides found at %1", txt_path)

    # function calls itself!
    if lang != @fallback_lang
      Builtins.y2debug(
        "Trying to load slides from fallback: %1",
        @fallback_lang
      )
      slide_list = GetSlideList(@fallback_lang)
    end
  end

  deep_copy(slide_list)
end

#HaveSlidesBoolean

Check if slides are available.

Not to be confused with HaveSlideSupport() which checks if slides could be displayed if there are any.



157
158
159
# File 'library/packages/src/modules/Slides.rb', line 157

def HaveSlides
  Ops.greater_than(Builtins.size(@slides), 0)
end

#HaveSlideSupportBoolean

Check if showing slides is supported.

Not to be confused with HaveSlides() which checks if there are slides available.



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'library/packages/src/modules/Slides.rb', line 137

def HaveSlideSupport
  disp = UI.GetDisplayInfo

  if !disp.nil? && # This shouldn't happen, but who knows?
      Ops.get_boolean(disp, "HasImageSupport", false) &&
      Ops.greater_or_equal(Ops.get_integer(disp, "DefaultWidth", -1), 800) &&
      Ops.greater_or_equal(Ops.get_integer(disp, "DefaultHeight", -1), 600) &&
      Ops.greater_or_equal(Ops.get_integer(disp, "Depth", -1), 8)
    return true
  else
    return false
  end
end

#LoadSlideFile(slide_name) ⇒ Object

Load one slide from files complete with image and textual description. Also adapt img links



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'library/packages/src/modules/Slides.rb', line 166

def LoadSlideFile(slide_name)
  text_file_name = Builtins.sformat("%1/%2", @slide_txt_path, slide_name)
  # returns empty string if not found
  text = Convert.to_string(
    SCR.Read(path(".target.string"), [text_file_name, ""])
  )

  #
  # Fix <img src> tags: Replace image path with current slide_pic_path
  #
  loop do
    replaced = Builtins.regexpsub(
      text,
      "(.*)&imagedir;(.*)",
      Builtins.sformat("\\1%1\\2", @slide_pic_path)
    )
    break if replaced.nil?
    text = replaced
  end

  text
end

#LoadSlides(language) ⇒ Object

Load slides for the given language and store them in the internal variables.



207
208
209
210
211
# File 'library/packages/src/modules/Slides.rb', line 207

def LoadSlides(language)
  @slides = GetSlideList(language)

  nil
end

#mainObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'library/packages/src/modules/Slides.rb', line 35

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "FileUtils"
  Yast.import "Installation"

  # list of currently known slides, in the order they should be shown
  @slides = []
  # base path to look for slides
  @slide_base_path = Ops.add(Installation.sourcedir, "/suse/setup/slide")
  # path to look for texts of slides
  @slide_txt_path = ""
  # path to look for images of slides
  @slide_pic_path = ""
  # if no other language is configured, use this fallback
  @fallback_lang = "en"
end

#SetSlideDir(dir) ⇒ Object

Set the slide show directory



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'library/packages/src/modules/Slides.rb', line 190

def SetSlideDir(dir)
  @slide_base_path = dir

  tmp = Convert.to_map(WFM.Read(path(".local.stat"), @slide_base_path))

  if !Ops.get_boolean(tmp, "isdir", false)
    Builtins.y2error("Using default path instead of %1", tmp)
    @slide_base_path = "/var/adm/YaST/InstSrcManager/tmp/CurrentMedia/suse/setup/slide"
  end

  Builtins.y2milestone("SetSlideDir: %1", @slide_base_path)

  nil
end