module MultimediaParadise::GUI::Gtk::MultimediaConverterModule

Constants

ARRAY_FILTER_THESE_FILES
#

ARRAY_FILTER_THESE_FILES

#
HEIGHT
#

HEIGHT

#
NAMESPACE
#

NAMESPACE

#
WIDTH
#

WIDTH

#

Public Class Methods

new( this_file = ARGV, run_already = true ) click to toggle source
#

initialize

You can pass an argument as optional file name. @save_file_to_this_directory should always have a trailing /

#
Calls superclass method
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 75
def initialize(
    this_file   = ARGV,
    run_already = true
  )
  super(:vertical, 2)
  set_selected_file(this_file)
  reset
  run if run_already
end
run() click to toggle source
#

MultimediaParadise::GUI::Gtk::MultimediaConverterModule.run

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 441
def self.run
  require 'gtk_paradise/run'
  _ = ::MultimediaParadise::GUI::Gtk::MultimediaConverter.new
  r = ::Gtk.run
  r << _
  r.set_width(_.width?)
  r.set_height(_.height?)
  r.set_size_request(
    _.width?  / 1.5,
    _.height? / 1.5
  )
  r.realize # This has to be called before set_cursor() below.
  boat_cursor = :boat
  if ::Gtk.use_gtk2?
    boat_cursor = Gdk::CursorType::BOAT
  end
  r.window.set_cursor(Gdk::Cursor.new(boat_cursor))
  r.signal_connect(:delete_event) { |_widget| ::Gtk.main_quit }
  r.enable_simple_exit
  # ======================================================================= #
  # Next we will add several alt+key shortcuts.
  # ======================================================================= #
  r.shortcuts {[
    [1, 'click_on_button_number(0)', :alt],
    [2, 'click_on_button_number(1)', :alt],
    [3, 'click_on_button_number(2)', :alt],
    [4, 'click_on_button_number(3)', :alt],
    [5, 'click_on_button_number(4)', :alt],
    [6, 'click_on_button_number(5)', :alt],
    [7, 'click_on_button_number(6)', :alt],
    [8, 'click_on_button_number(7)', :alt],
    [9, 'click_on_button_number(8)', :alt]
  ]}
  r.top_left_then_run
  return r
end
width?() click to toggle source
#

MultimediaConverter.width?

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 65
def self.width?
  WIDTH
end

Public Instance Methods

add_statusbar_message( this_msg = 'Start' ) click to toggle source
#

add_statusbar_message

This method will add to the status-bar queue.

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 127
def add_statusbar_message(
    this_msg = 'Start'
  )
  @status_bar.push(@status_bar_context_id, this_msg) # Add message
end
add_to_statusbar( this_msg = 'Start' )
connect_skeleton() click to toggle source
#

connect_skeleton

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 371
def connect_skeleton
  label = modify_bold_label('Convert to the following format:','slateblue')
  label.the_text_appears_on_the_left_side
  hbox = ::Gtk.create_paned_hbox(@entry_base_file, 
    ::Gtk.create_paned_vbox( 
      label, 
      @combo_box_convert_to_this_audio_type)
    )
  add(hbox)
  hbox2 = gtk_hbox
  hbox2.minimal(
    modify_bold_label('Save file to this directory:'),
    0
  )
  hbox2.maximal(
    @entry_save_where_to, 0
  )
  add(hbox2)
  add(@button_convert)
  add(
    ::Gtk.create_paned_hbox(@button_file_chooser, @button_quit)
  )
  minimal(
    @status_bar, 2
  )
end
create_buttons() click to toggle source
#

create_buttons

butt tag.

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 184
def create_buttons
  @button_quit = gtk_button('_Quit')
  @button_convert = gtk_button('_Convert')
  @button_convert.on_clicked { |widget|
    do_convert_multimedia_file
  }
  @button_convert.fancy_tooltips =
    ' <b>Click</b> this button in order to <b>convert the '\
    'audio-file to another format</b>. '
  @button_file_chooser = gtk_button('_Open File')
  @button_file_chooser.on_clicked { |widget|
    @file_chooser_dialog = ::Gtk::FileChooserDialog.new(
      'Open MultimediaFile',
      ::Gtk::Window.new,
      ::Gtk::FileChooser::ACTION_OPEN,
      nil,
      [ ::Gtk::Stock::CANCEL, ::Gtk::Dialog::RESPONSE_CANCEL ],
      [ ::Gtk::Stock::OPEN,   ::Gtk::Dialog::RESPONSE_ACCEPT ]
    )
    @file_chooser_dialog.current_folder = return_pwd
    if ENV.has_key? 'MY_SONGS'
      @file_chooser_dialog.add_shortcut_folder(ENV['MY_SONGS'])
    end

    @file_filter_audio_files = gtk_file_filter
    @file_filter_audio_files.name = 'Audio Files'
    ARRAY_FILTER_THESE_FILES.each { |entry|
      @file_filter_audio_files.add_pattern(entry)
    }
          
    @file_chooser_dialog.add_filter(@file_filter_audio_files)
    if File.directory? @save_file_to_this_directory
      _ = @save_file_to_this_directory
      if ::Gtk.is_on_roebe?
        _ = '/Depot/j/'
      end
      @file_chooser_dialog.cd_to(_)
    end

    case @file_chooser_dialog.run
    when ::Gtk::Dialog::RESPONSE_ACCEPT
      @entry_base_file.set_text(@file_chooser_dialog.filename)
      @selected_file = @file_chooser_dialog.filename
      add_to_statusbar(@selected_file)
    else
      puts 'No file selected.'
    end
    @file_chooser_dialog.destroy
  }
end
create_combo_boxes() click to toggle source
#

create_combo_boxes

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 281
def create_combo_boxes
  @combo_box_convert_to_this_audio_type = gtk_combo_box(true)
  %w( wav mp3 ogg ).each {|val| 
    @combo_box_convert_to_this_audio_type.append_text(val) 
  }
  @combo_box_convert_to_this_audio_type.active = 0
end
create_entries() click to toggle source
#

create_entries

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 238
def create_entries
  @entry_base_file = gtk_entry
  @entry_base_file.signal_connect(:event) { |widget, event|
    _ = event.event_type
    case _.name
    when 'GDK_BUTTON_PRESS'
      @button_file_chooser.signal_emit(:clicked)
    when 'GDK_SCROLL'
      case event.direction
      # === scroll-up event
      when Gdk::EventScroll::UP
        get_audio_file_listing
        @counter_position += 1
        pp @counter_position
        pp @array_audio_files[@counter_position]
      # === scroll-down event
      when Gdk::EventScroll::DOWN
        get_audio_file_listing
        @counter_position -= 1
        pp @counter_position
        pp @array_audio_files[@counter_position]
      end
    else
    end
  }  
  @entry_save_where_to = gtk_entry
  update
end
create_skeleton() click to toggle source
#

create_skeleton

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 137
def create_skeleton
  create_buttons
  create_entries
  create_combo_boxes
  create_statusbar
end
create_statusbar() click to toggle source
#

create_statusbar

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 157
def create_statusbar
  @status_bar = gtk_statusbar { :with_resize_grip }
  @status_bar_context_id = @status_bar.get_context_id('Conversion Information') 
end
do_convert_multimedia_file() click to toggle source
#

do_convert_multimedia_file

This is the unified method to convert a multimedia file from one format to another one.

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 295
def do_convert_multimedia_file
  if @selected_file.to_s.empty?
    statusbar_message(
      'Please input a valid (existing) file, on the top-left most entry.'
    )
    return
  end
  format_type = @combo_box_convert_to_this_audio_type.active_text
  case format_type
  # === mp3
  when 'mp3'
    application_to_use = 'lame --decode '
  # === ogg
  when 'ogg'
    application_to_use = 'ffmpeg -i '
  # === wav
  when 'wav'
    application_to_use = 'lame --decode '
  else
    application_to_use = '' # empty fall back...
  end
  e ::Colours.sfancy(
    'Now converting '+@selected_file
  )
  cmd = application_to_use.dup
  cmd << "#{@selected_file} "
  cmd << @entry_save_where_to.text
  cmd << get_rid_of_mp3_and_other_dirs+'.'
  cmd << format_type
  esystem(cmd)
  # ======================================================================= #
  # After the system-command has been run, we may modify the statusbar, to
  # keep track of changes. This will only be done if the converted file
  # actually exists.
  # ======================================================================= #
  converted_file = @entry_save_where_to.text+
                   File.basename(@selected_file)
  if File.exist?(converted_file)
    add_statusbar_message(
      "The file #{@selected_file} has been "\
      "converted. New location should be: #{converted_file}"
    )
  end
end
esystem(i) click to toggle source
#

esystem

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 343
def esystem(i)
  e i
  system_command(i)
end
favicon?() click to toggle source
#

favicon?

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 424
def favicon?
  '/home/x/programming/ruby/src/multimedia_paradise/lib/multimedia_paradise/images/'\
  'MULTIMEDIA.jpg'
end
get_audio_file_listing( i = return_pwd ) click to toggle source
#

get_audio_file_listing

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 270
def get_audio_file_listing(
    i = return_pwd
  )
  @array_audio_files = Dir["#{i}*"].select {|entry|
    File.file?(entry)
  }
end
get_rid_of_mp3() click to toggle source
#

get_rid_of_mp3

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 165
def get_rid_of_mp3
  return @selected_file.gsub(/\.mp3/,'')
end
get_rid_of_mp3_and_other_dirs() click to toggle source
#

get_rid_of_mp3_and_other_dirs

we get rid of .mp3 in our name, and any pathname.

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 174
def get_rid_of_mp3_and_other_dirs
  tmp = get_rid_of_mp3
  tmp = Pathname.new(tmp).basename.to_s
end
padding?() click to toggle source
#

padding?

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 401
def padding?
  10
end
reset() click to toggle source
#

reset

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 88
def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  increase_font_size
  # ======================================================================= #
  # === @counter_position
  # ======================================================================= #
  @counter_position = 0
  set_width(WIDTH)
  set_height(HEIGHT)
  # ======================================================================= #
  # === @save_file_to_this_directory
  #
  # The next variable keeps track into which directory we will save
  # the converted files.
  # ======================================================================= #
  @save_file_to_this_directory = return_pwd
  if is_on_roebe? and File.directory?('/home/Temp')
    @save_file_to_this_directory = '/home/Temp/'
  end
  append_project_css_file
  infer_the_size_automatically
end
run() click to toggle source
#

run

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 432
def run
  create_skeleton
  connect_skeleton
  sync_selected_file_to_the_corresponding_entry
end
set_selected_file(i) click to toggle source
#

set_selected_file

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 147
def set_selected_file(i)
  if i.is_a? Array
    i = i.first
  end
  @selected_file = i
end
statusbar_message( this_msg = 'Start' )
sync_selected_file_to_the_corresponding_entry() click to toggle source
#

sync_selected_file_to_the_corresponding_entry

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 417
def sync_selected_file_to_the_corresponding_entry
  @entry_base_file.set_text(@selected_file.to_s)
end
system_command(cmd) click to toggle source
#

system_command

Wrapper to run a system-command

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 353
def system_command(cmd)
  if cmd.include? ' '
    # Find out if the program exists.
    first_command = cmd.split(' ').first
    result = `#{first_command} 2>&1`
    if result.empty? # if empty we assume sox was not installed.
      _ = 'The program `'+first_command+'` was not found. Is it installed?'
      e _
      add_to_statusbar(_)
    else
      system cmd
    end
  end
end
title?() click to toggle source
#

title?

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 118
def title?
  'Simple Play Widget'
end
update() click to toggle source
#

update

Update certain components of the widget.

#
# File lib/multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb, line 410
def update
  @entry_save_where_to.set_text(@save_file_to_this_directory.to_s)
end