Class: GTK::SubmitAlbumDialog

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) ⇒ SubmitAlbumDialog

Returns a new instance of SubmitAlbumDialog.



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 513

def initialize( values )
	super( values )

	set_border_width( 5 )
	set_resizable( true )
	set_default_size( 600, 400 )
	resize( 600, 400 )

	set_title( I18n.get( "gui.submitalbum.title", values["site_name"] ) )

	artist_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.artist" )}</b>" );
	artist_label.set_xalign( 0.9 )
	artist_label.set_use_markup( true )
	@artist_lineedit = Gtk::Entry.new()
	@artist_lineedit.set_text( values["artist"] )

	album_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.album" )}</b>" );
	album_label.set_xalign( 0.9 )
	album_label.set_use_markup( true )
	@album_lineedit = Gtk::Entry.new()
	@album_lineedit.set_text( values["album"] )

	year_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.year" )}</b>" );
	year_label.set_xalign( 0.9 )
	year_label.set_use_markup( true )
	@year_spinbox = Gtk::SpinButton.new( Gtk::Adjustment.new( values["year"].to_i(), 1900, Date.today().year, 1, 10, 0 ) )
	@year_spinbox.set_numeric( true )

	month_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.month" )}</b>" );
	month_label.set_xalign( 0.9 )
	month_label.set_use_markup( true )
	@month_spinbox = Gtk::SpinButton.new( Gtk::Adjustment.new( values["month"].to_i(), 0, 12, 1, 1, 0 ) )
	@month_spinbox.set_numeric( true )

	day_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.day" )}</b>" );
	day_label.set_xalign( 0.9 )
	day_label.set_use_markup( true )
	@day_spinbox = Gtk::SpinButton.new( Gtk::Adjustment.new( values["day"].to_i(), 0, 31, 1, 1, 0 ) )
	@day_spinbox.set_numeric( true )

	image_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.image" )}</b>" );
	image_label.set_xalign( 0.9 )
	image_label.set_use_markup( true )
	@image_path_lineedit = Gtk::Entry.new()
	if values.include?( "image_path" )
		@image_path_lineedit.set_text( values["image_path"] )
		@image_button = Gtk::Button.new( "..." )
		@image_button.signal_connect( "clicked" ) { browse_image() }
	else
		@image_path_lineedit.set_text( I18n.get( "gui.submitalbum.coverfound" ) )
		@image_path_lineedit.set_sensitive( false )
	end

	tracks_scrolled_window = Gtk::ScrolledWindow.new()
	tracks_scrolled_window.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC )
	@tracks_text_buffer = GTK::TextBuffer.new()
	@tracks_text_buffer.set_text( values["tracks"] )
	@tracks_text = GTK::TextView.new()
	@tracks_text.set_indent( 2 )
	@tracks_text.set_buffer( @tracks_text_buffer )
	tracks_scrolled_window.add( @tracks_text )

	@reviewed_checkbox = Gtk::CheckButton.new( I18n.get( "gui.common.reviewed" ) )
	@reviewed_checkbox.set_active( false )

	buttons = create_action_buttons( "split", I18n.get( "gui.common.submit" ) )

	image_hbox = Gtk::HBox.new();
	image_hbox.pack_start( @image_path_lineedit, true, true )
	image_hbox.pack_start( @image_button, false, true ) if values.include?( "image_path" )

	tracks_frame = Gtk::Frame.new()
	tracks_frame.add( tracks_scrolled_window )
	tracks_frame.set_shadow_type( Gtk::SHADOW_IN )

	grid = Gtk::Table.new( 9, 4, false )
	grid.set_row_spacings( 3 )
	grid.attach( artist_label, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @artist_lineedit, 1, 6, 0, 1, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( album_label, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @album_lineedit, 1, 6, 1, 2, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( year_label, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @year_spinbox, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( month_label, 2, 3, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @month_spinbox, 3, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( day_label, 4, 5, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @day_spinbox, 5, 6, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( image_label, 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( image_hbox, 1, 6, 3, 4, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( tracks_frame, 0, 6, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL )
	grid.attach( @reviewed_checkbox, 0, 6, 5, 6, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( buttons, 0, 6, 6, 7, Gtk::EXPAND|Gtk::FILL, 0 )

	add( grid )

end

Instance Method Details

#acceptObject



638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 638

def accept()
	aux = {
		"artist"	=> @artist_lineedit.text(),
		"album"		=> @album_lineedit.text(),
		"year"		=> @year_spinbox.value().to_i(),
		"month"		=> @month_spinbox.value().to_i(),
		"day"		=> @day_spinbox.value().to_i(),
		"tracks"	=> @tracks_text_buffer.text(),
		"reviewed"	=> @reviewed_checkbox.active?()
	}
	aux["image_path"] = @image_path_lineedit.text() if @values.include?( "image_path" )
	@values = aux
	super()
end

#browse_imageObject



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 610

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