# program_entry.rb

# $Id: program_entry.rb,v 1.1.1.1 2002/04/30 04:15:45 kenji Exp $

# 2002/4/30  Takuro Ashie <ashie@homa.ne.jp>
# Copyright (C) 2002 Takuro Ashie <ashie@homa.ne.jp>
# This is free software with ABSOLUTELY NO WARRANTY.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

require 'time_entry'


###############################################################################
#
#   ProgramEntry Widget
#
###############################################################################
class ProgramEntry < Gtk::HBox
  include Gtk

  #
  # initialize ()
  #
  def initialize ()
    super (false, 0)

    @start_time_entry = nil   # Gtk::TimeEntry
    @end_time_entry   = nil   # Gtk::TimeEntry

    @channel_combo    = nil   # Gtk::Combo
    @quality_combo    = nil   # Gtk::Combo
    @filename_entry   = nil   # Gtk::Entry

    createChildren
  end


  #
  # getProgram () :
  #   Create new ProgramItem using each entry's value
  #
  # Return : a New ProgramItem
  #
  def getProgram ()
    item = ProgramItem::new
    item.starttime = @start_time_entry.getTime
    item.endtime   = @end_time_entry.getTime
    item.channel   = @channel_combo.entry.get_text
    item.quality   = @quality_combo.entry.get_text
    item.filename  = @filename_entry.get_text

    return item
  end


  #
  # setProgram () :
  #
  # aItem : The ProgramItem to set
  #
  def setProgram (aItem)
    if !aItem then
      return
    end

    @start_time_entry.setTime (aItem.starttime)
    @end_time_entry.setTime (aItem.endtime)

    if aItem.channel then
      @channel_combo.entry.set_text (aItem.channel)
    end

    if aItem.quality then
      @quality_combo.entry.set_text (aItem.quality)
    end

    if aItem.filename then
      @filename_entry.set_text (aItem.filename)
    end
  end


  #
  # set_quality_items () :
  #   create channel list popdown menu.
  #
  # aList : Array of channels (String)
  #
  def setChannelItems (aList)
    if aList then
      @channel_combo.set_popdown_strings (aList)
    end
  end

   
  #
  # set_quality_items () :
  #   create quality list popdown menu.
  #
  # aList : Array of quality items (String)
  #
  def setQualityItems (aList)
    if aList then
      @quality_combo.set_popdown_strings (aList)
    end

    # FIXME!!
    @quality_combo.entry.set_text ('NormalQ')
  end


 private

  #
  # createChildren () :
  #   create all child widget.
  #
  def createChildren ()
    time_entry_area = createTimeEntryArea
    pack_start (time_entry_area, false, false, 0)
    time_entry_area.show

    data_entry_area = createDataEntryArea
    pack_start (data_entry_area, false, false, 0)
    data_entry_area.show
  end


  #
  # createTimeEntryArea () :
  #
  def createTimeEntryArea ()
    vbox = VBox::new (false, 0)

    # Start Time Entry
    frame = Frame::new ('開始時刻')
    frame.border_width (5)
    vbox.pack_start (frame, false, false, 0)
    frame.show

    @start_time_entry = TimeEntry::new
    frame.add (@start_time_entry)
    @start_time_entry.show

    # End Time Entry
    frame = Frame::new ('終了時刻')
    frame.border_width (5)
    vbox.pack_start (frame, false, false, 0)
    frame.show

    @end_time_entry = TimeEntry::new
    frame.add (@end_time_entry)
    @end_time_entry.show

    return vbox
  end


  #
  # createDataEntryArea () :
  #
  def createDataEntryArea ()
    vbox = VBox::new (false, 0)

    hbox = HBox::new (false, 0)
    vbox.pack_start (hbox, false, false, 0)
    hbox.show

    # Channel Entry
    frame = Frame::new ('チャンネル')
    frame.border_width (5)
    hbox.pack_start (frame, true, true, 0)
    frame.show

    hbox1 = HBox::new (false, 0)
    frame.add (hbox1)
    hbox1.show

    @channel_combo = Combo::new
    hbox1.pack_start (@channel_combo, false, false, 0)
    @channel_combo.set_usize (100, -1)
    @channel_combo.show

    # Quality Entry
    frame = Frame::new ('品質')
    frame.border_width (5)
    hbox.pack_start (frame, true, true, 0)
    frame.show

    hbox1 = HBox::new (false, 0)
    frame.add (hbox1)
    hbox1.show

    @quality_combo = Combo::new
    hbox1.pack_start (@quality_combo, false, false, 0)
    @quality_combo.set_usize (100, -1)
    @quality_combo.show

    # File Name Entry
    frame = Frame::new ('ファイル名')
    frame.border_width (5)
    vbox.pack_start (frame, false, false, 0)
    frame.show

    hbox1 = HBox::new (false, 0)
    frame.add (hbox1)
    hbox1.show

    @filename_entry = Entry::new
    hbox1.pack_start (@filename_entry, true, true, 0)
    @filename_entry.show

    return vbox
  end
end
