Module: GUI

Defined in:
lib/wiki_lyrics/gui/gui.rb

Constant Summary collapse

@@toolkits =
[]
@@run_out_of_process =
false
@@running_out_of_process =
false

Class Method Summary collapse

Class Method Details

.create_exchange_fileObject



89
90
91
92
93
94
95
96
97
# File 'lib/wiki_lyrics/gui/gui.rb', line 89

def GUI.create_exchange_file()
	base_filename = Dir.tmpdir() + "/wikilyrics.gui." + $$.to_s()
	filename = nil
	loop do
		filename = base_filename + "." + rand( 65536 ).to_s()
		break unless File.exists?( filename )
	end
	return File.new( filename, "w+" )
end

.get_current_toolkitObject



85
86
87
# File 'lib/wiki_lyrics/gui/gui.rb', line 85

def GUI.get_current_toolkit()
	return @@toolkits.length > 0 ? @@toolkits[0].downcase() : nil
end

.load_toolkit(toolkit) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wiki_lyrics/gui/gui.rb', line 55

def GUI.load_toolkit( toolkit )
	toolkit = toolkit.downcase()
	if toolkit == "qt" || toolkit == "qt4"
		begin
			return require( File.expand_path( File.dirname( __FILE__ ) + "/gui-qt4" ) )
		rescue LoadError => e
			$stderr << "Error loading Qt4 GUI backend: #{e}\n"
		end
	elsif toolkit == "qt3"
		begin
			return require( File.expand_path( File.dirname( __FILE__ ) + "/gui-qt3" ) )
		rescue LoadError => e
			$stderr << "Error loading Qt3 GUI backend: #{e}\n"
		end
	elsif toolkit == "gtk"
		begin
			return require( File.expand_path( File.dirname( __FILE__ ) + "/gui-gtk" ) )
		rescue LoadError => e
			$stderr << "Error loading GTK GUI backend: #{e}\n"
		end
	elsif toolkit == "tk"
		begin
			return require( File.expand_path( File.dirname( __FILE__ ) + "/gui-tk" ) )
		rescue LoadError => e
			$stderr << "Error loading Tk GUI backend: #{e}\n"
		end
	end
	return false
end

.run_out_of_process?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/wiki_lyrics/gui/gui.rb', line 28

def GUI.run_out_of_process?()
	return @@run_out_of_process
end

.set_run_out_of_process(value) ⇒ Object



32
33
34
# File 'lib/wiki_lyrics/gui/gui.rb', line 32

def GUI.set_run_out_of_process( value )
	@@run_out_of_process = value
end

.set_running_out_of_process(value) ⇒ Object



36
37
38
# File 'lib/wiki_lyrics/gui/gui.rb', line 36

def GUI.set_running_out_of_process( value )
	@@running_out_of_process = value
end

.set_toolkit_priority(toolkits) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wiki_lyrics/gui/gui.rb', line 40

def GUI.set_toolkit_priority( toolkits )
	toolkits.each() do |toolkit|
		if @@toolkits.include?( toolkit )
			# check if the toolkit is already loaded (and change it's priority)
			@@toolkits.delete( toolkit )
			@@toolkits.insert( 0, toolkit )
			return toolkit
		elsif GUI.load_toolkit( toolkit ) # try to load the toolkit
			@@toolkits.insert( 0, toolkit )
			return toolkit
		end
	end
	return GUI.get_current_toolkit()
end

.show_confirmation_dialog(message, title = nil) ⇒ Object



239
240
241
242
243
244
245
246
# File 'lib/wiki_lyrics/gui/gui.rb', line 239

def GUI.show_confirmation_dialog( message, title=nil )
	if title
		system( "kdialog", "--icon", "amarok", "--title", title, "--yesno", "<qt>" + message.gsub( "\n", "<br/>" ) + "</qt>" )
	else
		system( "kdialog", "--icon", "amarok", "--yesno", "<qt>" + message.gsub( "\n", "<br/>" ) + "</qt>" )
	end
	return $? == 0
end

.show_dialog(dialog_name, values) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/wiki_lyrics/gui/gui.rb', line 99

def GUI.show_dialog( dialog_name, values )

	if @@run_out_of_process && ! @@running_out_of_process
		file = GUI.create_exchange_file()
		begin
			XMLHash.write( file, values )
			if ( (ret = system( "ruby", __FILE__, dialog_name, file.path, @@toolkits.join( "," ) )) )
				values = {}
				file.rewind()
				XMLHash.read( file.path, values, false )
			end
			return ret ? values : nil
		ensure
			file.close()
			File.delete( file.path )
		end
	end

	current_toolkit = GUI.get_current_toolkit()

	if current_toolkit == "qt" || current_toolkit == "qt4"
		app = Qt::Application.new( ARGV )
		# FIXME: there's currently a weird bug when using Oxygen style:
		# the first time it's used, it renders and works properly but,
		# when used again, renders badly and generally also crashes.
		if ( ! @@running_out_of_process )
			["plastique", "cleanlooks", "windows", "cde", "motif"].each() do |style|
				break if app.setStyle( style )
			end
		end
		dialog = eval( "QT4::" + dialog_name + ".new( values )" )
		dialog.show()
		app.exec()
	elsif current_toolkit == "qt3"
		app = Qt::Application.new( ARGV )
		dialog = eval( "QT3::" + dialog_name + ".new( values )" )
		app.setMainWidget( dialog )
		app.mainWidget.show()
		app.exec()
	elsif current_toolkit == "gtk"
		dialog = eval( "GTK::" + dialog_name + ".new( values )" )
		dialog.exec()
		Gtk.main()
	elsif current_toolkit == "tk"
		dialog = eval( "TK::" + dialog_name + ".new( values )" )
		dialog.exec()
	else
		return nil
	end

	if dialog.accepted()
		return dialog.values()
	else
		return nil
	end

end

.show_lyrics_dialog(values) ⇒ Object



227
228
229
# File 'lib/wiki_lyrics/gui/gui.rb', line 227

def GUI.show_lyrics_dialog( values )
	GUI.show_dialog( "ShowLyricsDialog", values )
end

.show_message_dialog(message, title = nil) ⇒ Object



231
232
233
234
235
236
237
# File 'lib/wiki_lyrics/gui/gui.rb', line 231

def GUI.show_message_dialog( message, title=nil )
	if title
		system( "kdialog", "--icon", "amarok", "--title", title, "--msgbox","<qt>" + message.gsub( "\n", "<br/>" ) + "</qt>" )
	else
		system( "kdialog", "--icon", "amarok", "--msgbox", "<qt>" + message.gsub( "\n", "<br/>" ) + "</qt>" )
	end
end

.show_plugins_manager_dialog(values) ⇒ Object



157
158
159
160
161
162
# File 'lib/wiki_lyrics/gui/gui.rb', line 157

def GUI.show_plugins_manager_dialog( values )
	values["script_name"] = "Wiki-Lyrics" if ! values.include?( "script_name" )
	ret = GUI.show_dialog( "PluginsManagerDialog", values )
	values.update( ret ) if ret
	return ret != nil
end

.show_search_lyrics_dialog(values) ⇒ Object



220
221
222
223
224
225
# File 'lib/wiki_lyrics/gui/gui.rb', line 220

def GUI.show_search_lyrics_dialog( values )
	values["year"] = values["year"].to_i()
	ret = GUI.show_dialog( "SearchLyricsDialog", values )
	values.update( ret ) if ret
	return ret != nil
end

.show_submit_album_dialog(values) ⇒ Object



198
199
200
201
202
203
204
205
# File 'lib/wiki_lyrics/gui/gui.rb', line 198

def GUI.show_submit_album_dialog( values )
	values["released"] = values["released"].to_s()
	values["site_name"] = "Wiki-Lyrics" if ! values.include?( "site_name" )
	ret = GUI.show_dialog( "SubmitAlbumDialog", values )
	values.update( ret ) if ret
	values["reviewed"] = values["reviewed"].to_s() == "true"
	return ret != nil
end

.show_submit_song_dialog(values) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/wiki_lyrics/gui/gui.rb', line 183

def GUI.show_submit_song_dialog( values )
	values["year"] = values["year"].to_i()
	values["site_name"] = "Wiki-Lyrics" if ! values.include?( "site_name" )
	ret = GUI.show_dialog( "SubmitSongDialog", values )
	values.update( ret ) if ret
	if values["instrumental"]
		values["lyrics"] = nil
	else
		values["lyrics"] = values["lyrics"].to_s().strip()
	end
	values["reviewed"] = values["reviewed"].to_s() == "true"
	values["instrumental"] = values["instrumental"].to_s() == "true"
	return ret != nil
end

.show_upload_cover_dialog(values) ⇒ Object



207
208
209
210
211
212
213
# File 'lib/wiki_lyrics/gui/gui.rb', line 207

def GUI.show_upload_cover_dialog( values )
	values["site_name"] = "Wiki-Lyrics" if ! values.include?( "site_name" )
	values["year"] = values["year"].to_i()
	ret = GUI.show_dialog( "UploadCoverDialog", values )
	values.update( ret ) if ret
	return ret != nil
end

.show_wiki_fix_pages_dialog(values) ⇒ Object



215
216
217
218
# File 'lib/wiki_lyrics/gui/gui.rb', line 215

def GUI.show_wiki_fix_pages_dialog( values )
	values["title"] = "Pages fixer" if ! values.include?( "title" )
	GUI.show_dialog( "FixPagesDialog", values )
end

.show_wiki_plugin_dialog(values) ⇒ Object



172
173
174
175
176
177
178
179
180
181
# File 'lib/wiki_lyrics/gui/gui.rb', line 172

def GUI.show_wiki_plugin_dialog( values )
	values["site_name"] = "Wiki-Lyrics" if ! values.include?( "site_name" )
	ret = GUI.show_dialog( "WikiPluginDialog", values )
	values.update( ret ) if ret
	values["submit"] = values["submit"].to_s() == "true"
	values["review"] = values["review"].to_s() == "true"
	values["prompt_autogen"] = values["prompt_autogen"].to_s() == "true"
	values["prompt_no_lyrics"] = values["prompt_no_lyrics"].to_s() == "true"
	return ret != nil
end