Class: GTK::UploadCoverDialog

Inherits:
BaseDialog
  • Object
show all
Defined in:
lib/wiki_lyrics/gui/gui-gtk.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#accepted, #values

Instance Method Summary collapse

Methods inherited from BaseDialog

#exec

Constructor Details

#initialize(values) ⇒ UploadCoverDialog

Returns a new instance of UploadCoverDialog.



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 658

def initialize( values )
	super( values )

	set_border_width( 5 )
	set_resizable( true )
	set_default_size( 350, 100 )
	set_title( I18n.get( "gui.uploadcover.title", values["site_name"] ) )

	album_group = Gtk::Frame.new( I18n.get( "gui.common.album" ) )

	artist_label = Gtk::Label.new( I18n.get( "gui.common.artist" ) )
	artist_label.set_xalign( 0 )
	@artist_lineedit = Gtk::Entry.new()
	@artist_lineedit.set_text( values["artist"] )

	album_label = Gtk::Label.new( I18n.get( "gui.common.album" ) )
	album_label.set_xalign( 0 )
	@album_lineedit = Gtk::Entry.new()
	@album_lineedit.set_text( values["album"] )

	year_label = Gtk::Label.new( I18n.get( "gui.common.year" ) );
	year_label.set_xalign( 0 )
	@year_spinbox = Gtk::SpinButton.new( Gtk::Adjustment.new( values["year"], 1900, Date.today().year, 1, 10, 0 ) )
	@year_spinbox.set_numeric( true )

	image_group = Gtk::Frame.new( I18n.get( "gui.common.image" ) )

	image_label = Gtk::Label.new( I18n.get( "gui.uploadcover.imagepath" ) )
	image_label.set_use_markup( true )
	@image_path_lineedit = Gtk::Entry.new()
	@image_path_lineedit.set_text( values["image_path"] )
	@image_button = Gtk::Button.new( "..." )
	@image_button.signal_connect( "clicked" ) { browse_image() }

	buttons = create_action_buttons()

	album_grid = Gtk::Table.new( 4, 4, false )
	album_grid.set_row_spacings( 3 )
	album_grid.set_column_spacings( 3 )
	album_grid.attach( artist_label, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	album_grid.attach( @artist_lineedit, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, 0 )
	album_grid.attach( album_label, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	album_grid.attach( @album_lineedit, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	album_grid.attach( year_label, 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	album_grid.attach( @year_spinbox, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, 0 )
	album_group.add( album_grid )

	image_grid = Gtk::Table.new( 4, 4, false )
	image_grid.set_row_spacings( 3 )
	image_grid.set_column_spacings( 3 )
	image_grid.attach( image_label, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	image_grid.attach( @image_path_lineedit, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, 0 )
	image_grid.attach( @image_button, 2, 3, 0, 1, 0, 0 )
	image_group.add( image_grid )

	vbox = Gtk::VBox.new( false, 3 );
	vbox.add( album_group )
	vbox.add( image_group )
	vbox.add( buttons )

	add( vbox )

end

Instance Method Details

#acceptObject



750
751
752
753
754
755
756
757
758
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 750

def accept()
	@values = {
		"artist"		=> @artist_lineedit.text(),
		"album"			=> @album_lineedit.text(),
		"year"			=> @year_spinbox.value().to_i(),
		"image_path"	=> @image_path_lineedit.text()
	}
	super()
end

#browse_imageObject



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 722

def browse_image()
	dirname = @image_path_lineedit.text().strip()
	dirname = GTK.empty_string?( dirname ) ? (ENV["HOME"] ? ENV["HOME"] : ".") : File.dirname( dirname )
	dialog = Gtk::FileChooserDialog.new(
		I18n.get( "gui.uploadcover.browseimage.title" ), self, Gtk::FileChooser::ACTION_OPEN, nil,
		[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
		[Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]
	)

	filter = Gtk::FileFilter.new()
	filter.set_name( I18n.get( "gui.uploadcover.browseimage.images" ) )
	["jpg", "png", "bmp"].each() { |ext| filter.add_pattern( "*.#{ext}" ).add_pattern( "*.#{ext.upcase}" ) }
	dialog.add_filter( filter )
	filter = Gtk::FileFilter.new()
	filter.set_name( I18n.get( "gui.uploadcover.browseimage.allfiles" ) )
	filter.add_pattern( "*" )
	dialog.add_filter( filter )

	dialog.set_local_only( true )
	dialog.set_select_multiple( false )
	dialog.set_current_folder( File.expand_path( dirname ) )
	if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
      		image_path = GLib.filename_to_utf8( dialog.filename )
		@image_path_lineedit.set_text( image_path.strip() ) if ! GTK.empty_string?( image_path )
	end
	dialog.destroy()
end