Class: SettingsManager

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/gswax/settings_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeSettingsManager

Returns a new instance of SettingsManager.



35
36
37
38
39
40
41
42
43
# File 'lib/gswax/settings_manager.rb', line 35

def initialize
	Settings.read
	bga = Settings.bg_color
	@bg_color = Gdk::Color.new(bga[0], bga[1], bga[2])
	tca = Settings.text_color
	@text_color = Gdk::Color.new(tca[0], tca[1], tca[2])
	@font_desc = Pango::FontDescription.new(Settings.font_desc)
	init_ui
end

Instance Method Details

#bg_color_selectObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/gswax/settings_manager.rb', line 217

def bg_color_select
	d = Gtk::ColorSelectionDialog.new
	sel = d.colorsel
	sel.set_previous_color(@bg_color)
	sel.set_current_color(@bg_color)
	sel.set_has_palette(true)
	response = d.run

	if response == Gtk::Dialog::RESPONSE_OK
		bgR = sel.current_color.red
		bgG = sel.current_color.green
		bgB = sel.current_color.blue
		Settings.bg_color = [bgR, bgG, bgB]
		@bg_color = Gdk::Color.new(bgR, bgG, bgB)
		@bg_btn.modify_bg(Gtk::STATE_NORMAL, @bg_color)
	end
	d.destroy
end

#close_windowObject



280
281
282
# File 'lib/gswax/settings_manager.rb', line 280

def close_window
	@win.destroy
end

#font_selectObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/gswax/settings_manager.rb', line 255

def font_select
	d = Gtk::FontSelectionDialog.new
	d.set_font_name(Settings.font_desc)
	response = d.run
	
	if response == Gtk::Dialog::RESPONSE_OK
		font = d.font_name
		Settings.font_desc = font
		@font_desc = Pango::FontDescription.new(font)
		@font_text.text = font
		@font_text.modify_font(@font_desc)
	end
	d.destroy
end

#init_uiObject



45
46
47
48
49
50
51
52
53
54
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/gswax/settings_manager.rb', line 45

def init_ui
	@win = Gtk::Window.new
	@win.title = "gsWax Settings"
	@win.icon = Gdk::Pixbuf.new File.join(DIR, '../static/gshoes-icon.png')
	@win.set_size_request(400, 400)
	@win.signal_connect("destroy"){
		changed; notify_observers("SETTINGS_CLOSED")
	}
		nb = Gtk::Notebook.new
			page1 = Gtk::VBox.new(false, 2)
		
			mdir_frame = SettingsCell.new
			mdir_frame.set("music library directory:", 0.95, nil, 50)
				mdir_btn = Gtk::EventBox.new()
					@mdir_text = Gtk::Label.new(Settings.music_dir)
					@mdir_text.set_alignment(0.05, 0.3)
					@mdir_text.set_wrap(true)
					@mdir_text.justify = Gtk::JUSTIFY_LEFT
				mdir_btn.add(@mdir_text)
				mdir_btn.signal_connect("button_press_event"){music_dir_select}
				mdir_btn.signal_connect("enter_notify_event"){mdir_frame.hover}
				mdir_btn.signal_connect("leave_notify_event"){mdir_frame.leave}
			mdir_frame.add(mdir_btn)
			
			hbox1 = Gtk::HBox.new(false, 5)
			hbox1.set_height_request(50)
				scale_frame = SettingsCell.new
				scale_frame.set("scale: [0.35 - 1.0]", 0.05, 193, nil)
					scale_btn = Gtk::EventBox.new()
						@scale_text = Gtk::Entry.new
						@scale_text.text = Settings.scale.to_s
						@scale_text.xalign = 0.95
						@scale_text.signal_connect("enter_notify_event"){scale_frame.hover}
						@scale_text.signal_connect("leave_notify_event"){scale_frame.leave}
					scale_btn.add(@scale_text)
				scale_frame.add(scale_btn)
		
				bg_frame = SettingsCell.new
				bg_frame.set("background color:", 0.95, nil, nil)
					@bg_btn = Gtk::EventBox.new()
					@bg_btn.modify_bg(Gtk::STATE_NORMAL, @bg_color)
					@bg_btn.signal_connect("button_press_event"){bg_color_select}
					@bg_btn.signal_connect("enter_notify_event"){bg_frame.hover}
					@bg_btn.signal_connect("leave_notify_event"){bg_frame.leave}
				bg_frame.add(@bg_btn)
			hbox1.pack_start(scale_frame, false, false, 0)
			hbox1.pack_start(bg_frame, true, true, 2)
	
			hbox2 = Gtk::HBox.new(false, 5)
			hbox2.set_height_request(50)
				font_frame = SettingsCell.new
				font_frame.set("text font:", 0.05, 193, nil)
					font_btn = Gtk::EventBox.new()
						@font_text = Gtk::Label.new(@font_desc)
						@font_text.modify_font(@font_desc)
						@font_text.xalign = 0.95
						@font_text.justify = Gtk::JUSTIFY_RIGHT
					font_btn.add(@font_text)
					font_btn.signal_connect("button_press_event"){font_select}
					font_btn.signal_connect("enter_notify_event"){font_frame.hover}
					font_btn.signal_connect("leave_notify_event"){font_frame.leave}
				font_frame.add(font_btn)
		
				txtclr_frame = SettingsCell.new
				txtclr_frame.set("text color:", 0.95, nil, nil)
					@txtclr_btn = Gtk::EventBox.new()
					@txtclr_btn.modify_bg(Gtk::STATE_NORMAL, @text_color)
					@txtclr_btn.modify_fg(Gtk::STATE_SELECTED, @text_color)
					@txtclr_btn.signal_connect("button_press_event"){text_color_select}
					@txtclr_btn.signal_connect("enter_notify_event"){txtclr_frame.hover}
					@txtclr_btn.signal_connect("leave_notify_event"){txtclr_frame.leave}
				txtclr_frame.add(@txtclr_btn)
			hbox2.pack_start(font_frame, false, false, 0)
			hbox2.pack_start(txtclr_frame, true, true, 2)
		
			format_frame = SettingsCell.new
			format_frame.set("title format:", 0.05, nil, nil)
				format_box = Gtk::EventBox.new
					vbox = Gtk::VBox.new(false, 5)
					
						valign = Gtk::Alignment.new(0.05, 0.15, 0, 0)
							@format_text = Gtk::TextView.new
							@format_text.set_size_request(390, 200)
							@format_text.wrap_mode = Gtk::TextTag::WRAP_WORD
							@format_text.justification = Gtk::JUSTIFY_LEFT
							@format_text.editable =  true
							@format_text.cursor_visible =  true
							@format_text.pixels_above_lines = 5
							@format_text.pixels_below_lines = 5
							@format_text.pixels_inside_wrap = 5
							@format_text.left_margin = 10
							@format_text.right_margin = 10
							@format_text.buffer.text = Settings.title_format
						valign.add(@format_text)
					
						halign = Gtk::Alignment.new(0.01, 0, 1, 0)
							add_field = Gtk::ComboBox.new
								fields = ["add field", "#track-number#", "#title#", "#album#",
								"#artist#", "#album-artist#", "#genre#", "#comments#"
								]
								fields.each{|field| add_field.append_text(field)}
							add_field.active = 0
							add_field.signal_connect("changed"){
								@format_text.buffer.insert(
									@format_text.buffer.end_iter, add_field.active_iter[0]
								)
							}
						halign.add(add_field)
					
					vbox.pack_start(valign, true, true, 2)
					vbox.pack_start(halign, false, false, 2)
				format_box.add(vbox)
				format_box.signal_connect("enter_notify_event"){format_frame.hover}
				format_box.signal_connect("leave_notify_event"){format_frame.leave}
			format_frame.add(format_box)
	
			btn_box = Gtk::HBox.new(false, 2)
				save_btn = Gtk::Button.new(" save settings ")
				save_btn.signal_connect("clicked"){save_settings}
				close_btn = Gtk::Button.new("  close  ")
				close_btn.signal_connect("clicked"){@win.destroy}

			btn_box.pack_end(close_btn, false, false, 2)
			btn_box.pack_end(save_btn, false, false, 2)		

		page1.pack_start(mdir_frame, false, false, 10)
		page1.pack_start(hbox1, false, false, 2)
		page1.pack_start(hbox2, false, false, 2)
		page1.pack_start(format_frame, true, true, 12)
		page1.pack_start(btn_box, false, false, 0)
		
		page2 = Gtk::VBox.new(false, 2)
			about_frame = Gtk::Frame.new()
			about = "gsWax version 0.0.2\nhttps://github.com/lljk/gsWax"
			about_text = Gtk::Label.new(about)
			about_text.set_alignment(0.05, 0.5)
			about_text.set_wrap(true)
			about_text.justify = Gtk::JUSTIFY_CENTER
			about_frame.add(about_text)
		page2.pack_start(about_frame, true, true, 2)

		label1 = Gtk::Label.new("  general  ")
		label2 = Gtk::Label.new("  about  ")
	
		nb.append_page(page1, label1)
		nb.append_page(page2, label2)
	@win.add(nb)
	@win.show_all
end

#music_dir_selectObject

init_ui



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/gswax/settings_manager.rb', line 195

def music_dir_select
	if Settings.music_dir
		open_dir = Settings.music_dir if File.exists?(Settings.music_dir)
	else
		open_dir = File.dirname(File.expand_path(__FILE__))
	end
	dialog = Gtk::FileChooserDialog.new(
		nil,nil,
		Gtk::FileChooser::ACTION_SELECT_FOLDER,
		nil,
		["Cancel", Gtk::Dialog::RESPONSE_CANCEL],
		["Select", Gtk::Dialog::RESPONSE_ACCEPT]
	)
	dialog.current_folder = (open_dir)
	dialog.signal_connect("delete_event"){dialog.destroy}
	if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
		Settings.music_dir = dialog.filename
		@mdir_text.text = Settings.music_dir
		dialog.destroy
	end
end

#save_settingsObject



270
271
272
273
274
275
276
277
278
# File 'lib/gswax/settings_manager.rb', line 270

def save_settings
	scale = @scale_text.text.to_f
	scale = 0.35 if scale < 0.35; scale = 1.0 if scale > 1.0
	Settings.scale = scale
	Settings.title_format = @format_text.buffer.text
	Settings.save
	changed; notify_observers("UPDATE_SETTINGS")
	@win.destroy
end

#text_color_selectObject



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/gswax/settings_manager.rb', line 236

def text_color_select
	d = Gtk::ColorSelectionDialog.new
	sel = d.colorsel
	sel.set_previous_color(@text_color)
	sel.set_current_color(@text_color)
	sel.set_has_palette(true)
	response = d.run

	if response == Gtk::Dialog::RESPONSE_OK
		tR = sel.current_color.red
		tG = sel.current_color.green
		tB = sel.current_color.blue
		Settings.text_color = [tR, tG, tB]
		@text_color = Gdk::Color.new(tR, tG, tB)
		@txtclr_btn.modify_bg(Gtk::STATE_NORMAL, @text_color)
	end
	d.destroy
end