Class: PiggyImageBrowser

Inherits:
Fox::FXMainWindow
  • Object
show all
Includes:
Fox, Responder
Defined in:
lib/piggy-gui/piggy_image_browser.rb

Overview

Piggy’s main application window.

Constant Summary collapse

MsgStyle =
MBOX_OK|DECOR_TITLE|DECOR_CLOSE|PIGGY_WINDOW_PLACEMENT
UseImageView =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PiggyImageBrowser

INIT



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/piggy-gui/piggy_image_browser.rb', line 45

def initialize(app)
  super(app, "Piggy", nil, nil, DECOR_ALL,
    0, 0, 200, 700, 0, 0)
  # now in critical order
  init_vars
  init_menubar
  init_toolbar
  init_view
  init_icons
  init_menu
  init_toolbar_buttons
  @tooltip = FXTooltip.new(getApp, TOOLTIP_NORMAL)
  connect(SEL_CLOSE, method(:on_cmd_close)) unless FOXVERSION_GE_1_2
end

Instance Attribute Details

#image_processorObject (readonly)

Returns the value of attribute image_processor.



37
38
39
# File 'lib/piggy-gui/piggy_image_browser.rb', line 37

def image_processor
  @image_processor
end

Instance Method Details

Modified an idea of David Naseby on how to do Hyperlinks with FXRuby



572
573
574
575
576
# File 'lib/piggy-gui/piggy_image_browser.rb', line 572

def add_hyperlink_to(container, url)
  link = FXButton.new(container, ruby_2_fox(url), nil, nil, 0, FRAME_NONE)
  link.textColor = FXColor::Blue
  link.connect(SEL_COMMAND) { open_hyperlink(url, '.') }
end

#check_local_destination_pathObject



508
509
510
511
512
513
514
515
# File 'lib/piggy-gui/piggy_image_browser.rb', line 508

def check_local_destination_path
  output = @options.localDestinationPath
  if(!File.directory?(output))
    error("#{output} ist no directory}")
    return false
  end
  return true
end

#chosen_sequenceObject



39
40
41
# File 'lib/piggy-gui/piggy_image_browser.rb', line 39

def chosen_sequence
  @filelist.chosen_sequence
end

#close(notify = false) ⇒ Object



839
840
841
842
# File 'lib/piggy-gui/piggy_image_browser.rb', line 839

def close(notify=false)
  prepare_closure
  super(notify)
end

#createObject

Create and show window



316
317
318
319
320
321
322
323
324
325
326
# File 'lib/piggy-gui/piggy_image_browser.rb', line 316

def create
  @logFrame.height = 100
  @imageviewframe.width = 240
  @exifFrame.parent.width = 200
  @fileframe.width = 140
  resize(720, 620)
  place(PIGGY_WINDOW_PLACEMENT)
  setIcon(@windowIcon)
  options_changed(@options)
  super
end

#current_file_infoObject



493
494
495
# File 'lib/piggy-gui/piggy_image_browser.rb', line 493

def current_file_info
  info_for_file(@filename)
end

#default_startup_directoryObject



460
461
462
# File 'lib/piggy-gui/piggy_image_browser.rb', line 460

def default_startup_directory
  return @shell.picture_directory
end

#error(msg, title = 'Error') ⇒ Object

MESSAGES



499
500
501
502
# File 'lib/piggy-gui/piggy_image_browser.rb', line 499

def error(msg, title = 'Error')
  FXMessageBox::warning(self, MsgStyle, title, msg)
  return false
end

#fit_imageObject

ACTIONS



519
520
521
# File 'lib/piggy-gui/piggy_image_browser.rb', line 519

def fit_image
  @imageview.fit unless UseImageView
end

#frame_visible(frame, bool) ⇒ Object

CHANGE VIEW



330
331
332
333
334
335
336
# File 'lib/piggy-gui/piggy_image_browser.rb', line 330

def frame_visible(frame, bool)
  if bool
    frame.show
  else
    frame.hide
  end
end

#fullscreen?Boolean

Returns:

  • (Boolean)


710
711
712
# File 'lib/piggy-gui/piggy_image_browser.rb', line 710

def fullscreen?
  @fullscreen && @fullscreen.shown?
end

#generator_classObject

ACCESSING



437
438
439
440
441
442
443
# File 'lib/piggy-gui/piggy_image_browser.rb', line 437

def generator_class
  return NconvertThumbnailPageGenerator if @options.use_nconvert?
  if RMAGICK_AVAILIABLE && @options.use_rmagick?
    return RmagickThumbnailPageGenerator
  end
  return FoxThumbnailPageGenerator
end

#get_icon(filename) ⇒ Object



472
473
474
475
476
477
# File 'lib/piggy-gui/piggy_image_browser.rb', line 472

def get_icon(filename)
  icon_path = File.join(PIGGY_PATH, 'icons', filename)
  icon = @imageProcessor.load_icon(icon_path)
  @icons.push(icon)
  return icon
end


464
465
466
# File 'lib/piggy-gui/piggy_image_browser.rb', line 464

def get_link_path(dirname, linkname)
  return @shell.get_link_target(linkname, dirname)
end

#has_extension?(filename, ext) ⇒ Boolean

Returns:

  • (Boolean)


430
431
432
433
# File 'lib/piggy-gui/piggy_image_browser.rb', line 430

def has_extension?(filename, ext)
  File.basename(filename.upcase, ext.upcase) !=
    File.basename(filename.upcase)
end

#info_for_file(osPathString) ⇒ Object



479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/piggy-gui/piggy_image_browser.rb', line 479

def info_for_file(osPathString)
  path_string = @shell.ruby_path(osPathString)
  @exif = ExifrAdapter.new(path_string)
  info = CommentedFile.new(File.basename(path_string), File.dirname(path_string))
  if @fileInfos.has_key?(info)
    info = @fileInfos[info]
  else
    info.rotation = @exif.view_degrees
    info.comment = @exif.comment
    @fileInfos[info] = info
  end
  return info
end

#init_frame_contentsObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/piggy-gui/piggy_image_browser.rb', line 292

def init_frame_contents
  fill_mode = LAYOUT_FILL_X|LAYOUT_FILL_Y
  @filelist = FilteredFileList.new(@fileframe)
  @filelist.choosable = proc { |filename| supports(filename) }
  @filelist.setLayoutHints(fill_mode)
  @filelist.connect(SEL_COMMAND, method(:on_cmd_file_list_selection))
  @imageview = if UseImageView
    FXImageView.new(@imageviewframe)
  else
    MultiImageCanvas.new(@imageviewframe, fill_mode)
  end
  @imageview.setLayoutHints(fill_mode)
  @imageview.connect(SEL_CONFIGURE, method(:on_configure))
  @imageComment = FXTextField.new(@imageviewframe, 32)
  @imageComment.setLayoutHints(LAYOUT_FILL_X)
  @imageComment.connect(SEL_COMMAND, method(:on_comment_might_have_changed))
  @exifView = FXText.new(@exifFrame)
  @exifView.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @preview = MultiImageCanvas.new(@previewFrame, fill_mode)
  @pipeLog = PipeLog.new(@logFrame)
  @pipeLog.setLayoutHints(LAYOUT_FILL_X|LAYOUT_FILL_Y)
end

#init_framesObject



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/piggy-gui/piggy_image_browser.rb', line 269

def init_frames
  fill_mode = LAYOUT_FILL_X|LAYOUT_FILL_Y
  frame_style = FRAME_SUNKEN
  splitter_mode = SPLITTER_TRACKING
  v_split = FXSplitter.new(self,
    splitter_mode|SPLITTER_REVERSED|SPLITTER_VERTICAL)
  v_split.setLayoutHints(fill_mode)
  h_split = FXSplitter.new(v_split,
    splitter_mode|SPLITTER_HORIZONTAL)
  h_split.setLayoutHints(fill_mode)
  @fileframe = FXVerticalFrame.new(h_split, frame_style|fill_mode)
  h_split2 = FXSplitter.new(h_split,
    splitter_mode|SPLITTER_REVERSED|SPLITTER_HORIZONTAL)
  h_split2.setLayoutHints(fill_mode)
  @imageviewframe = FXVerticalFrame.new(h_split2, frame_style|fill_mode)
  h_split3 = FXSplitter.new(h_split2,
    splitter_mode|SPLITTER_REVERSED|SPLITTER_HORIZONTAL)
  h_split3.setLayoutHints(fill_mode)
  @exifFrame = FXVerticalFrame.new(h_split3, FRAME_NONE|fill_mode)
  @previewFrame = FXVerticalFrame.new(h_split3, frame_style|fill_mode)
  @logFrame = FXVerticalFrame.new(v_split, FRAME_NONE|fill_mode)
end

#init_iconsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/piggy-gui/piggy_image_browser.rb', line 92

def init_icons
  @windowIcon = get_icon("gallery.ico")
  @generateIcon = get_icon("generate.ico")
  @addToPreviewIcon = get_icon("plus.png")
  @removeFromPreviewIcon = get_icon("minus.png")
  @uplevelIcon  = get_icon("dirup.ico")
  @uploadIcon = get_icon("upload.ico")
  @filesaveIcon = get_icon("filesave.ico")
  @rotateIcon = get_icon("rotate.ico")
  @backIcon = get_icon("back.ico")
  @nextImageIcon = get_icon("next-image.ico")
  @previousImageIcon = get_icon("previous-image.ico")
  @slideshowImageIcon = get_icon("slides.ico")
  @slideshowOffImageIcon = get_icon("stop-slides.ico")
  @fullscreenIcon = get_icon("fullscreen.ico")
end

#init_menuObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/piggy-gui/piggy_image_browser.rb', line 123

def init_menu
  menu_titles = {
    'file' => '&File',
    'view' => '&View',
    'actions' => '&Actions',
    'options' => '&Options',
    'help' => '&Help' }
  menus = Hash.new(6)
  @menus = menus # destroy panes on closure
  menu_titles.each_pair { |key, value|
    menus[key] = FXMenuPane.new(self) }
  [ 'file', 'view', 'actions', 'options' ].each { | key |
    FXMenuTitle.new(@menubar, menu_titles[key], nil, menus[key]) }
  FXMenuTitle.new(@menubar, menu_titles['help'], nil, menus['help'],
    LAYOUT_RIGHT)
  
  # File menu entries
  tmp = FXMenuCommand.new(menus['file'],
    "&Open...\tCtl-O\tOpen image file.")
  tmp.connect(SEL_COMMAND, method(:on_cmd_open))
  tmp = FXMenuCommand.new(menus['file'],
    "B&ack\t\tBack in history",
    @backIcon)
  tmp.connect(SEL_COMMAND, method(:on_cmd_back))
  tmp = FXMenuCommand.new(menus['file'],
    "&Save image\t\tSave image.",
    @filesaveIcon)
  tmp.connect(SEL_COMMAND, method(:on_cmd_save_selected_image))
  tmp = FXMenuCommand.new(menus['file'],
    "&Quit\tAlt-X\tQuit Application")
  tmp.connect(SEL_COMMAND, method(:on_terminate))
  
  # View menu entries
  #    tmp = FXMenuCheck.new(menus['view'],
  #			  "S&lides\t\tSlideshow.")
  #    tmp.connect(SEL_COMMAND, method(:on_cmd_slideshow))
  tmp = FXMenuCommand.new(menus['view'],
    "&Rotate 90\t\tRotate 90 degrees.",
    @rotateIcon)
  tmp.connect(SEL_COMMAND, method(:on_rotate_90))

  # Action menu entries
  tmp = FXMenuCommand.new(menus['actions'],
    "&Html\t\tGenerate Html page.",
    @generateIcon)
  tmp.connect(SEL_COMMAND, method(:on_cmd_generate_html))
  tmp = FXMenuCommand.new(menus['actions'],
    "Upl&oad\t\tUpload Files",
    @uploadIcon)
  tmp.connect(SEL_COMMAND, method(:on_cmd_upload))
  
  # Options menu entries
  tmp = FXMenuCommand.new(menus['options'],
    "&Options...\t\tOpen options dialog.")
  tmp.connect(SEL_COMMAND, method(:on_cmd_options))
  
  # Help Menu entries
  tmp = FXMenuCommand.new(menus['help'], "Sample galleries")
  tmp.textColor = FXColor::Blue
  tmp.connect(SEL_COMMAND) {
    open_hyperlink("http://piggy.rubyforge.org/caps/index.htm", '.')
  }

  msg = "Piggy: (P)ick (i)mages and (g)enerate a (g)aller(y)\n"
  msg += "Piggy is a generator for html picture albums.\n\n"
  msg += "Using the FOX C++ GUI Library (http://www.fox-toolkit.org)\n"
  msg += "Using Patrick Fitzgerald's Javascript slideshow (http://slideshow.barelyfitz.com/)\n"
  msg += "\n"
  msg += "#{PiggyVersion.copyright_string}\n\n"
  msg += "Version information:\n"
  msg += "- Plattform #{RUBY_PLATFORM}\n"
  msg += "- Ruby #{RUBY_VERSION} (released #{RUBY_RELEASE_DATE})\n"
  msg += "- FXRuby #{Fox.fxrubyversion}\n"
  msg += "- FOX Toolkit #{Fox.fxversion}\n"
  msg += "- Javascript slideshow no version information availiable\n"
  msg += "- JavaFX animation uses JavaFX Script Version 1.2 which runs on top of Java 6\n"
  msg += "- Piggy #{PiggyVersion.display_string}\n"
  about_title = "About Piggy"
  tmp = FXMenuCommand.new(menus['help'], "&About Piggy...")
  tmp.connect(SEL_COMMAND) do
    FXMessageBox.new(self, ruby_2_fox(about_title), ruby_2_fox(msg), nil, MsgStyle).execute
  end
end

#init_menubarObject



116
117
118
119
120
121
# File 'lib/piggy-gui/piggy_image_browser.rb', line 116

def init_menubar
  @menubar = FXMenubar.new(self, FRAME_RAISED)
  @menubar.setLayoutHints(LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
  FXToolbarGrip.new(@menubar, @menubar, FXMenubar::ID_TOOLBARGRIP,
    TOOLBARGRIP_DOUBLE)
end

#init_statusbarObject



109
110
111
112
113
114
# File 'lib/piggy-gui/piggy_image_browser.rb', line 109

def init_statusbar
  @statusbar = FXStatusbar.new(self, STATUSBAR_WITH_DRAGCORNER)
  @statusbar.setLayoutHints(LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X)
  @orientationStatus = FXTextField.new(@statusbar, 4)
  @orientationStatus.disable
end

#init_toolbarObject



207
208
209
210
211
212
213
214
215
# File 'lib/piggy-gui/piggy_image_browser.rb', line 207

def init_toolbar
  @dragshell = FXToolbarShell.new(self, 0)
  @toolbar = FXToolbar.new(self, @dragshell)
  @toolbar.setFrameStyle(FRAME_RAISED)
  @toolbar.setPackingHints(PACK_UNIFORM_WIDTH|PACK_UNIFORM_HEIGHT)
  @toolbar.setLayoutHints(LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
  FXToolbarGrip.new(@toolbar, @toolbar, FXToolbar::ID_TOOLBARGRIP,
    TOOLBARGRIP_DOUBLE)
end

#init_toolbar_buttonsObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/piggy-gui/piggy_image_browser.rb', line 229

def init_toolbar_buttons
  new_toolbar_button(@uplevelIcon, "&Up\tGo up to higher directory",
    method(:on_one_level_up))
  new_toolbar_button(@backIcon, "&Back\tBack to previous directory",
    method(:on_cmd_back))
  new_toolbar_button(@previousImageIcon, "&Previous\tShow previous selected image",
    method(:on_cmd_previous_image))
  new_toolbar_button(@nextImageIcon, "&Next\tShow next selected image",
    method(:on_cmd_next_image))
  slideshow_button = new_toolbar_toggle_button(@slideshowImageIcon,
    @slideshowOffImageIcon,
    "S&lides on\tStart slideshow",
    "S&lides off\tStop slideshow",
    method(:on_cmd_slideshow))
  @delayField = FXTextField.new(@toolbar, 2)
  @delayField.setText(@options.slideshowDelay.to_s + ' sec')
  @delayField.connect(SEL_COMMAND) { |sender, sel, ptr|
    @options.slideshowDelay = @delayField.getText.to_i
  }
  new_toolbar_button(@fullscreenIcon, "&Full\tOpen fullscreen",
    method(:on_cmd_fullscreen))

  new_toolbar_button(@rotateIcon, "&Rotate\tRotate 90� right",
    method(:on_rotate_90))
  new_toolbar_button(@addToPreviewIcon, "&Add\tSelect image(s)",
    method(:on_cmd_add_files))
  new_toolbar_button(@removeFromPreviewIcon, "S&kip\tDeselect image(s)",
    method(:on_cmd_remove_files))
  new_toolbar_button(@generateIcon, "&Html\tGenerate HTML",
    method(:on_cmd_generate_html))
  new_toolbar_button(@uploadIcon, "Upl&oad\tUpload files",
    method(:on_cmd_upload))
end

#init_varsObject



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
# File 'lib/piggy-gui/piggy_image_browser.rb', line 60

def init_vars
  @slideManager = nil
  @fullscreen = nil
  @fullscreenView = nil
  @shell = WinShell.instance
  @history = Array.new
  @historyPos = @history.size
  @optionStore = PiggyOptionsPersistence.new
  @options = @optionStore.load_yaml
  @imageProcessor = ImageProcessor.new(getApp)
  @fileInfos = FileRepository.new
  @filename = ''
  @currentRotation = 0
  @preferredFileFilter = 0
  @exif = ''
  
  # Which image types are allowed
  @supportedImageTypes = {
    "gif" => "GIF Image (*.gif)",
    "bmp" => "BMP Image (*.bmp)",
    "xpm" => "XPM Image (*.xpm)",
    "pcx" => "PCX Image (*.pcx)",
    "ico" => "ICO Image (*.ico)",
    "png" => "PNG Image (*.png)",
    "jpg" => "JPEG Image (*.jpg)",
    #      "tif" => "TIFF Image (*.tif)",
    "tga" => "TARGA Image (*.tga)" }
  
  @icons = Array.new
  @iconStyle = ICON_ABOVE_TEXT|BUTTON_TOOLBAR|FRAME_RAISED
end

#init_viewObject



263
264
265
266
267
# File 'lib/piggy-gui/piggy_image_browser.rb', line 263

def init_view
  init_statusbar
  init_frames
  init_frame_contents
end

#load_image(file) ⇒ Object



364
365
366
367
368
369
370
# File 'lib/piggy-gui/piggy_image_browser.rb', line 364

def load_image(file)
  @filename = file # needs to be called this early
  info = current_file_info
  @imageComment.setText(ruby_2_fox(info.comment))
  set_current_rotation(info.rotation)
  reload_image(file)
end

#log(msg) ⇒ Object



360
361
362
# File 'lib/piggy-gui/piggy_image_browser.rb', line 360

def log(msg)
  @pipeLog.appendText("#{msg}\n")
end

#new_toolbar_button(icon, bubble, method) ⇒ Object



217
218
219
220
221
# File 'lib/piggy-gui/piggy_image_browser.rb', line 217

def new_toolbar_button(icon, bubble, method)
  button = FXButton.new(@toolbar, bubble, icon, nil, 0, @iconStyle)
  button.connect(SEL_COMMAND, method)
  button
end

#new_toolbar_toggle_button(icon1, icon2, bubble1, bubble2, method) ⇒ Object



223
224
225
226
227
# File 'lib/piggy-gui/piggy_image_browser.rb', line 223

def new_toolbar_toggle_button(icon1, icon2, bubble1, bubble2, method)
  button = FXToggleButton.new(@toolbar, bubble1, bubble2, icon1, icon2, nil, 0, @iconStyle)
  button.connect(SEL_COMMAND, method)
  button
end

#next_imageObject



662
663
664
665
# File 'lib/piggy-gui/piggy_image_browser.rb', line 662

def next_image
  i = @filelist.select_next_chosen
  select_index(i) unless i < 0
end

#on_cmd_add_files(sender, sel, unused) ⇒ Object



734
735
736
737
# File 'lib/piggy-gui/piggy_image_browser.rb', line 734

def on_cmd_add_files(sender, sel, unused)
  @filelist.add_selected_files
  preview if @options.usePreview
end

#on_cmd_back(sender, unused1, unused2) ⇒ Object



744
745
746
747
748
749
# File 'lib/piggy-gui/piggy_image_browser.rb', line 744

def on_cmd_back(sender, unused1, unused2)
  if(@historyPos > 1)
    @historyPos -= 1
    set_directory(@history[@historyPos - 1])
  end
end

#on_cmd_close(sender, sel, ptr) ⇒ Object

Send whenever this window is about to close



848
849
850
851
# File 'lib/piggy-gui/piggy_image_browser.rb', line 848

def on_cmd_close(sender, sel, ptr)
  prepare_closure
  return 0
end

#on_cmd_file_list_selection(sender, dummy, index) ⇒ Object

Command message from the file list



650
651
652
# File 'lib/piggy-gui/piggy_image_browser.rb', line 650

def on_cmd_file_list_selection(sender, dummy, index)
  select_index(index)
end

#on_cmd_fullscreen(sender, sel, index) ⇒ Object



759
760
761
762
763
764
765
# File 'lib/piggy-gui/piggy_image_browser.rb', line 759

def on_cmd_fullscreen(sender, sel, index)
  if fullscreen?
    stop_fullscreen
  else
    start_fullscreen
  end
end

#on_cmd_generate_html(sender, sel, index) ⇒ Object



767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'lib/piggy-gui/piggy_image_browser.rb', line 767

def on_cmd_generate_html(sender, sel, index)
  unless @filelist.any_files_chosen?
    return error("Select some image files first!")
  end
  options_dialog = HtmlGenerationDialog.new(self, @options.clone)
  return false unless options_dialog.execute
  @options = options_dialog.options
  output_dir = options_dialog.get_subdir
  title = options_dialog.get_title
  title = "" if(!title)
  generator = generator_class.new(@options)
  generator.set_title(title)
  generator.set_output_directory(output_dir)
  generator.client = @pipeLog
  generator.set_files(chosen_sequence.collect { |f| info_for_file(f) })
  getApp.beginWaitCursor
  progress = ProgressWithDialog.new(self)
  progress.set_task('Generating', @filelist.num_files_chosen)
  success = false
  overwrite = true # user has been asked in dialog
  begin
    if(@options.stylesSample?)
      actual_options = @options.clone
      begin
        get_style_list.each { |style|
          @options.style = style
          @options.skipImageProcessing = (style != 'basic')
          @options.addJavaFxSlideshow = (style == 'basic')
          @options.stylesSample = (style != 'basic')
          generator.set_title(style)
          generator.set_output_directory(style)
          success = success & generator.generate(progress, overwrite, @options.addZip?)
        }
      ensure
        @options = actual_options
      end
    else
      success = generator.generate(progress, overwrite, @options.addZip?)
    end
    while @pipeLog.has_open_pipes?
    end
  ensure
    progress.finish
    getApp.endWaitCursor
  end
  if(success)
    open_html_browser_on_result(generator)
  else
    @pipeLog.appendText('Error')
    error("Error in html generation!")
  end
  return success
end

#on_cmd_next_image(sender, sel, dummy) ⇒ Object



654
655
656
# File 'lib/piggy-gui/piggy_image_browser.rb', line 654

def on_cmd_next_image(sender, sel, dummy)
  next_image
end

#on_cmd_open(sender, sel, ptr) ⇒ Object

Open a new file



628
629
630
631
# File 'lib/piggy-gui/piggy_image_browser.rb', line 628

def on_cmd_open(sender, sel, ptr)
  open_system_file_chooser
  return 1
end

#on_cmd_options(sender, sel, index) ⇒ Object



622
623
624
625
# File 'lib/piggy-gui/piggy_image_browser.rb', line 622

def on_cmd_options(sender, sel, index)
  dialog = OptionsDialog.new(self, @options.clone)
  options_changed(dialog.options) if dialog.execute
end

#on_cmd_previous_image(sender, sel, dummy) ⇒ Object



658
659
660
# File 'lib/piggy-gui/piggy_image_browser.rb', line 658

def on_cmd_previous_image(sender, sel, dummy)
  previous_image
end

#on_cmd_remove_files(sender, sel, unused) ⇒ Object



739
740
741
742
# File 'lib/piggy-gui/piggy_image_browser.rb', line 739

def on_cmd_remove_files(sender, sel, unused)
  @filelist.remove_selected_files
  preview if @options.usePreview
end

#on_cmd_save_selected_image(sender, sel, ptr) ⇒ Object

EVENTS



601
602
603
# File 'lib/piggy-gui/piggy_image_browser.rb', line 601

def on_cmd_save_selected_image(sender, sel, ptr)
  save_image
end

#on_cmd_slideshow(sender, sel, index) ⇒ Object



751
752
753
754
755
756
757
# File 'lib/piggy-gui/piggy_image_browser.rb', line 751

def on_cmd_slideshow(sender, sel, index)
  if @slideManager
    stop_slideshow
  else
    start_slideshow
  end
end

#on_cmd_upload(sender, sel, index) ⇒ Object



611
612
613
614
615
616
# File 'lib/piggy-gui/piggy_image_browser.rb', line 611

def on_cmd_upload(sender, sel, index)
  upload_dialog = FtpBrowserDialog.new(self, @options.clone)
  upload_dialog.connect(SEL_CLOSE, method(:on_ftp_browser_dialog_closed))
  upload_dialog.execute
  options_changed(upload_dialog.options)
end

#on_comment_might_have_changed(sender, sel, ptr) ⇒ Object



826
827
828
# File 'lib/piggy-gui/piggy_image_browser.rb', line 826

def on_comment_might_have_changed(sender, sel, ptr)
  current_file_info.comment = fox_2_ruby(@imageComment.getText)
end

#on_configure(sender, sel, ptr) ⇒ Object



618
619
620
# File 'lib/piggy-gui/piggy_image_browser.rb', line 618

def on_configure(sender, sel, ptr)
  fit_image
end

#on_ftp_browser_dialog_closed(sender, sel, ptr) ⇒ Object



821
822
823
824
# File 'lib/piggy-gui/piggy_image_browser.rb', line 821

def on_ftp_browser_dialog_closed(sender, sel, ptr)
  # get options?
  return 0
end

#on_one_level_up(sender, sel, unused) ⇒ Object



725
726
727
728
729
730
731
732
# File 'lib/piggy-gui/piggy_image_browser.rb', line 725

def on_one_level_up(sender, sel, unused)
  old_dir = ruby_path(@filelist.get_current_directory)
  new_dir = FilePath.one_dir_up(old_dir)
  if(old_dir == new_dir)
    new_dir = FXDirDialog.getOpenDirectory(self, "Choose directory", old_dir)
  end
  set_directory(new_dir) unless(old_dir == new_dir)
end

#on_rotate_90(sender, sel, ptr) ⇒ Object



605
606
607
608
609
# File 'lib/piggy-gui/piggy_image_browser.rb', line 605

def on_rotate_90(sender, sel, ptr)
  image = @imageview.image
  return error('Doubleclick image file first') if image == nil
  rotate(90)
end

#on_terminate(sender, sel, ptr) ⇒ Object

Use this to react on termination signals



853
854
855
# File 'lib/piggy-gui/piggy_image_browser.rb', line 853

def on_terminate(sender, sel, ptr)
  close
end


396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/piggy-gui/piggy_image_browser.rb', line 396

def open_file_or_link(filename)
  @exifView.setText('')
  ruby_file = ruby_path(filename)
  if FileTest.directory? ruby_file
    set_directory(ruby_file)
    return 1
  end
  if @shell.link?(ruby_file)
    # file is a windows-shortcut
    ruby_file = get_link_path(@filelist.getDirectory, ruby_file)
    return 0 if !ruby_file || ruby_file.empty?
    log("Shortcut to: #{ruby_file}")
    if FileTest.directory?(ruby_file)
      set_directory(ruby_file)
      return 1
    end
  end
  if(supports(filename))
    load_image(ruby_file)
    @exifView.setText(ruby_2_fox("#{File.basename(ruby_file)}\n#{@exif.to_s}"))
    @filelist.assume_selected(ruby_file)
    return 1
  end
  return 0
end

#open_html_browser_on_result(generator) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
# File 'lib/piggy-gui/piggy_image_browser.rb', line 558

def open_html_browser_on_result(generator)
  if(!File.exist? generator.main_index_path)
    return error("#{generator.main_index_path} doesn't exist")
  end
  if(!File.exist? generator.main_index_with_path)
    return error("#{generator.main_index_with_path} doesn't exist")
  end
  url = @shell.os_path(generator.main_index_with_path)
  working_dir = generator.main_index_path
  open_hyperlink(url, working_dir)
end


578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/piggy-gui/piggy_image_browser.rb', line 578

def open_hyperlink(url, working_dir)
  getApp.beginWaitCursor
  begin
    if(@options.browser?)
      cmd = @options.browser
      @pipeLog.run_command(cmd + ' ' + url, working_dir, true)
    else
      if PLATFORM =~ /mswin/
        require 'win32ole'
        ie = WIN32OLE.new('InternetExplorer.Application')
        ie.visible = TRUE
        ie.navigate(url)
      end
    end
  rescue StandardError => ex
    log(ex.to_s)
  ensure
    getApp.endWaitCursor
  end
end

#open_system_file_chooserObject



633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/piggy-gui/piggy_image_browser.rb', line 633

def open_system_file_chooser
  open_dialog = FXFileDialog.new(self, "Open Image")
  #openDialog.filename = @filename
  open_dialog.set_directory(@filelist.get_current_directory)
  patterns = ["All Files (*)" ] + @supportedImageTypes.values
  open_dialog.patternList = patterns
  open_dialog.currentPattern = @preferredFileFilter
  if open_dialog.execute
    @preferredFileFilter = open_dialog.currentPattern
    filename = open_dialog.filename
    set_directory(open_dialog.getDirectory)
    open_file_or_link(filename)
  end
end

#options_changed(newOptions) ⇒ Object



348
349
350
351
352
353
354
# File 'lib/piggy-gui/piggy_image_browser.rb', line 348

def options_changed(newOptions)
  preview if newOptions.usePreview && !@options.usePreview
  frame_visible(@logFrame, newOptions.useLog)
  frame_visible(@previewFrame, newOptions.usePreview)
  refresh_with_new_layout
  @options = newOptions
end

#prepare_closureObject

EXIT



832
833
834
835
836
# File 'lib/piggy-gui/piggy_image_browser.rb', line 832

def prepare_closure
  puts 'About to quit'
  @optionStore.save_yaml(@options)
  @pipeLog.close_pipes
end

#previewObject



344
345
346
# File 'lib/piggy-gui/piggy_image_browser.rb', line 344

def preview
  @preview.load_images(chosen_sequence)
end

#previous_imageObject



667
668
669
670
# File 'lib/piggy-gui/piggy_image_browser.rb', line 667

def previous_image
  i = @filelist.select_previous_chosen
  select_index(i) unless i < 0
end

#question(question, title = 'Question') ⇒ Object



504
505
506
# File 'lib/piggy-gui/piggy_image_browser.rb', line 504

def question(question, title = 'Question')
  MBOX_CLICKED_YES == FXMessageBox.question(self, MBOX_YES_NO, title, question)
end

#refresh_with_new_layoutObject



338
339
340
341
342
# File 'lib/piggy-gui/piggy_image_browser.rb', line 338

def refresh_with_new_layout
  # method layout missing
  resize(width, height - 1)
  resize(width, height + 1)
end

#reload_image(file) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/piggy-gui/piggy_image_browser.rb', line 372

def reload_image(file)
  if UseImageView
    old = @imageview.image.nil? ? nil : fox_2_ruby(@imageview.image)
    image = @imageProcessor.load_image(file, false)
    @imageProcessor.fit_image(image, 800, 600)
    if @currentRotation > 0 
      @imageProcessor.rotate_image(image, @currentRotation)
    end
    image.create
    @imageview.image = image
  else
    if fullscreen? && @fullScreenView
      old = @fullScreenView.image
      @fullScreenView.load_image(@filename, false, @currentRotation)
      @imageProcessor.garbage_image(old) unless old.nil?
    else
      old = @imageview.image
      @imageview.load_image(file, false, @currentRotation)
      @imageProcessor.garbage_image(old) unless old.nil?
    end
  end
  @imageProcessor.garbage_image(old) unless old.nil?
end

#rotate(degree) ⇒ Object



551
552
553
554
555
556
# File 'lib/piggy-gui/piggy_image_browser.rb', line 551

def rotate(degree)
  set_current_rotation(@currentRotation + degree)
  getApp().beginWaitCursor do
    reload_image(@filename)
  end
end

#ruby_path(path) ⇒ Object



468
469
470
# File 'lib/piggy-gui/piggy_image_browser.rb', line 468

def ruby_path(path)
  @shell.ruby_path(path)
end

#run_command(commandline, workingDir) ⇒ Object



356
357
358
# File 'lib/piggy-gui/piggy_image_browser.rb', line 356

def run_command(commandline, workingDir)
  @pipeLog.run_command(commandline, workingDir)
end

#save_imageObject



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/piggy-gui/piggy_image_browser.rb', line 523

def save_image
  save_dialog = FXFileDialog.new(self, "Save Image")
  save_dialog.filename = @filename.gsub(/([^.])\.(.*)/, '\1.piggy.\2')
  return if save_dialog.execute == 0
  if File.exists? save_dialog.filename
    #      return unless question("Overwrite existing image?", "Overwrite Image")
    return error('Sorry, overwrite an existing image is not implemented, yet.')
  end
  getApp().beginWaitCursor do
    manipulatedImage = @imageProcessor.load_image(@filename)
    @imageProcessor.rotate_image(manipulatedImage, @currentRotation)
    @imageProcessor.save_image(manipulatedImage, save_dialog.filename)
    @imageProcessor.garbage_image(manipulatedImage)
    @filelist.update_file_list
  end
  set_directory(save_dialog.getDirectory)
  open_file_or_link(save_dialog.filename)
end

#select_index(index) ⇒ Object



714
715
716
717
718
719
720
721
722
723
# File 'lib/piggy-gui/piggy_image_browser.rb', line 714

def select_index(index)
  return 0 if index < 0
  if @filelist.isItemDirectory(index)
    set_directory(@filelist.get_item_ruby_pathname(index))
    return 1
  end
  return 0 if !@filelist.isItemFile(index)
  filename = @filelist.get_item_ruby_pathname(index)
  return open_file_or_link(filename)
end

#set_current_rotation(newRotation) ⇒ Object



542
543
544
545
546
547
548
549
# File 'lib/piggy-gui/piggy_image_browser.rb', line 542

def set_current_rotation(newRotation)
  @currentRotation = newRotation
  if @currentRotation >= 360
    @currentRotation = @currentRotation - 360
  end
  @orientationStatus.setText(ruby_2_fox(@currentRotation.to_s + ''))
  current_file_info.rotation = @currentRotation
end

#set_directory(dirname) ⇒ Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/piggy-gui/piggy_image_browser.rb', line 445

def set_directory(dirname)
  if @historyPos < @history.size
    @history.pop
  else
    @history.push(dirname)
    @historyPos = @history.size
  end
  @filelist.go_to_directory(dirname)
  if(@options.preselectDirectories?)
    @filelist.choose_all_in_filelist
    next_image
  end
  preview if @options.usePreview
end

#start_fullscreenObject



690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/piggy-gui/piggy_image_browser.rb', line 690

def start_fullscreen
  fill_mode = LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_CENTER_X|LAYOUT_CENTER_Y
  @fullscreen = Fullscreen.new(getApp, "Piggy fullscreen", nil, nil,
    DECOR_BORDER|DECOR_TITLE|DECOR_CLOSE)
  @fullScreenView = MultiImageCanvas.new(@fullscreen, fill_mode)
  @fullscreen.connect(SEL_CLOSE){ |sender, sel, ptr|
    stop_fullscreen
  }
  @fullscreen.create
  @fullscreen.show(PLACEMENT_MAXIMIZED)
  reload_image(@filename)
end

#start_slideshowObject



672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/piggy-gui/piggy_image_browser.rb', line 672

def start_slideshow
  @slideManager = 1
  Thread.new {
    while(@slideManager) do
      # Threading issues: addChore seems to provide enough
      # synchronisation to avoid segfaults here
      getApp().addChore { |x, y, z| next_image }
      delay = @options.slideshowDelay
      sleep(delay > 0 ? delay : 1)
    end
  }
end

#stop_fullscreenObject



703
704
705
706
707
708
# File 'lib/piggy-gui/piggy_image_browser.rb', line 703

def stop_fullscreen
  @fullscreen.destroy if fullscreen?
  @fullscreen = nil
  @fullScreenView = nil
  reload_image(@filename)
end

#stop_slideshowObject



685
686
687
688
# File 'lib/piggy-gui/piggy_image_browser.rb', line 685

def stop_slideshow
  @slideManager = nil
  stop_fullscreen
end

#supports(filename) ⇒ Object

TESTING



424
425
426
427
428
# File 'lib/piggy-gui/piggy_image_browser.rb', line 424

def supports(filename)
  return false if filename == nil || !filename.include?('.')
  extension = filename.split(".").last.downcase
  return @supportedImageTypes.include?(extension)
end