Class: QT4::FixPagesDialog

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

Instance Attribute Summary

Attributes inherited from BaseDialog

#values

Instance Method Summary collapse

Methods inherited from BaseDialog

#accepted

Constructor Details

#initialize(values) ⇒ FixPagesDialog

Returns a new instance of FixPagesDialog.



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
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 688

def initialize( values )
	super( values )

	@fetch_func = eval( @values["fetch_func"] )
	@fix_func = eval( @values["fix_func"] )
	@submit_func = eval( @values["submit_func"] )

	setWindowTitle( "#{values["site_name"]} - #{values["title"]}" )

	url_label = Qt::Label.new( "<b>#{I18n.get( "gui.common.url" )}</b>", self )
	@url_lineedit = Qt::LineEdit.new( values["url"], self )

	@page_text = Qt::TextEdit.new( self )
	@page_text.setLineWrapMode( Qt::TextEdit::NoWrap )

	@fetch_button = Qt::PushButton.new( I18n.get( "gui.common.load" ), self )
	@fix_button = Qt::PushButton.new( I18n.get( "gui.common.fix" ), self )
	@submit_button = Qt::PushButton.new( I18n.get( "gui.common.submit" ), self )

	url_layout = Qt::HBoxLayout.new()
	url_layout.spacing = 4
	url_layout.setDirection( Qt::BoxLayout::LeftToRight )
	url_layout.addWidget( url_label )
	url_layout.addWidget( @url_lineedit )

	buttons_layout = Qt::HBoxLayout.new()
	buttons_layout.spacing = 4
	buttons_layout.addStretch()
	buttons_layout.addWidget( @fetch_button )
	buttons_layout.addWidget( @fix_button )
	buttons_layout.addWidget( @submit_button )

	layout = Qt::GridLayout.new( self )
	layout.margin = 4
	layout.spacing = 4
	layout.addLayout( url_layout, 0, 0 )
	layout.addWidget( @page_text, 1, 0 )
	layout.addLayout( buttons_layout, 2, 0 )

	connect( @fetch_button, SIGNAL( "clicked()" ), self, SLOT( "fetch_page()" ) )
	connect( @fix_button, SIGNAL( "clicked()" ), self, SLOT( "fix_page()" ) )
	connect( @submit_button, SIGNAL( "clicked()" ), self, SLOT( "submit_page()" ) )

	resize( 600, 400 )
end

Instance Method Details

#fetch_pageObject



734
735
736
737
738
739
740
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 734

def fetch_page()
	if (page_content = @fetch_func.call( @url_lineedit.text() ))
		@original_content = page_content
		@original_url = @url_lineedit.text()
		@page_text.setPlainText( page_content )
	end
end

#fix_pageObject



742
743
744
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 742

def fix_page()
	@page_text.setPlainText( @fix_func.call( @page_text.toPlainText() ) ) if @original_content
end

#submit_pageObject



746
747
748
749
750
751
752
753
754
755
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 746

def submit_page()
	if @original_content && @original_content != (page_content = @page_text.toPlainText())
		if @submit_func.call( @original_url, page_content )
			@original_content = page_content
			puts I18n.get( "gui.fixpages.success", @original_url )
		else
			puts I18n.get( "gui.fixpages.error", @original_url )
		end
	end
end