1 /*
2  *
3  *   Copyright (C) 2005-2018 by C.H. Huang
4  *   plushuang.tw@gmail.com
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2.1 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  *  ---
21  *
22  *  In addition, as a special exception, the copyright holders give
23  *  permission to link the code of portions of this program with the
24  *  OpenSSL library under certain conditions as described in each
25  *  individual source file, and distribute linked combinations
26  *  including the two.
27  *  You must obey the GNU Lesser General Public License in all respects
28  *  for all of the code used other than OpenSSL.  If you modify
29  *  file(s) with this exception, you may extend this exception to your
30  *  version of the file(s), but you are not obligated to do so.  If you
31  *  do not wish to do so, delete this exception statement from your
32  *  version.  If you delete this exception statement from all source
33  *  files in the program, then also delete it here.
34  *
35  */
36 
37 #include <UgString.h>
38 #include <UgetMedia.h>
39 #include <UgtkSettingForm.h>
40 
41 #include <glib/gi18n.h>
42 
43 // ----------------------------------------------------------------------------
44 // UgtkClipboardForm
45 //
46 //
ugtk_clipboard_form_init(struct UgtkClipboardForm * cbform)47 void  ugtk_clipboard_form_init (struct UgtkClipboardForm* cbform)
48 {
49 	PangoContext*  context;
50 	PangoLayout*   layout;
51 	int            text_height;
52 	GtkTextView* textview;
53 	GtkWidget*   widget;
54 	GtkBox*      vbox;
55 	GtkBox*      hbox;
56 	GtkScrolledWindow*  scroll;
57 
58 	cbform->self = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
59 	vbox = (GtkBox*) cbform->self;
60 	// Monitor button
61 	widget = gtk_check_button_new_with_mnemonic (_("_Enable clipboard monitor"));
62 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
63 	cbform->monitor = (GtkToggleButton*) widget;
64 
65 	// quiet mode
66 	widget = gtk_check_button_new_with_mnemonic (_("_Quiet mode"));
67 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 0);
68 	cbform->quiet = (GtkToggleButton*) widget;
69 	// Nth category
70 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
71 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
72 	widget = gtk_label_new (_("Default category index"));
73 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
74 	cbform->nth_label = widget;
75 	widget = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
76 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
77 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
78 	cbform->nth_spin = (GtkSpinButton*) widget;
79 	// hint
80 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
81 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
82 	widget = gtk_label_new (" - ");
83 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
84 	widget = gtk_label_new (_("Adding to Nth category if no matched category."));
85 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
86 
87 	gtk_box_pack_start (vbox, gtk_label_new (""), FALSE, FALSE, 2);
88 
89 	// media or storage website
90 	widget = gtk_check_button_new_with_mnemonic (_("_Monitor URL of website"));
91 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
92 	cbform->website = (GtkToggleButton*) widget;
93 
94 	gtk_box_pack_start (vbox, gtk_label_new (""), FALSE, FALSE, 2);
95 
96 	// get text height --- begin ---
97 	context = gtk_widget_get_pango_context (widget);
98 	layout = pango_layout_new (context);
99 	pango_layout_set_text (layout, "joIN", -1);
100 	pango_layout_get_pixel_size (layout, NULL, &text_height);
101 	g_object_unref (layout);
102 	//  get text height --- end ---
103 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
104 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
105 	widget = gtk_label_new (_("Monitor clipboard for specified file types:"));
106 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 1);
107 	// Scrolled Window
108 	scroll = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
109 	gtk_scrolled_window_set_shadow_type (scroll, GTK_SHADOW_IN);
110 	gtk_widget_set_size_request (GTK_WIDGET (scroll), 100, text_height * 6);
111 	gtk_box_pack_start (vbox, GTK_WIDGET (scroll), FALSE, FALSE, 2);
112 	// file type pattern : TextView
113 	cbform->buffer = gtk_text_buffer_new (NULL);
114 	cbform->pattern = gtk_text_view_new_with_buffer (cbform->buffer);
115 	g_object_unref (cbform->buffer);
116 	textview = (GtkTextView*) cbform->pattern;
117 	gtk_text_view_set_wrap_mode (textview, GTK_WRAP_WORD_CHAR);
118 	gtk_container_add (GTK_CONTAINER (scroll),
119 			GTK_WIDGET (cbform->pattern));
120 
121 	// tips
122 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
123 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 1);
124 	gtk_box_pack_end (hbox,
125 			gtk_label_new (_("Separate the types with character '|'.")),
126 			FALSE, FALSE, 2);
127 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
128 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 1);
129 	gtk_box_pack_end (hbox,
130 			gtk_label_new (_("You can use regular expressions here.")),
131 			FALSE, FALSE, 2);
132 }
133 
ugtk_clipboard_form_set(struct UgtkClipboardForm * cbform,UgtkSetting * setting)134 void  ugtk_clipboard_form_set (struct UgtkClipboardForm* cbform, UgtkSetting* setting)
135 {
136 	if (setting->clipboard.pattern)
137 		gtk_text_buffer_set_text (cbform->buffer, setting->clipboard.pattern, -1);
138 	gtk_toggle_button_set_active (cbform->monitor, setting->clipboard.monitor);
139 	gtk_toggle_button_set_active (cbform->quiet, setting->clipboard.quiet);
140 	gtk_toggle_button_set_active (cbform->website, setting->clipboard.website);
141 	gtk_spin_button_set_value (cbform->nth_spin, setting->clipboard.nth_category);
142 	gtk_toggle_button_toggled (cbform->monitor);
143 	gtk_toggle_button_toggled (cbform->quiet);
144 //	on_clipboard_quiet_mode_toggled ((GtkWidget*) cbform->quiet, cbform);
145 }
146 
ugtk_clipboard_form_get(struct UgtkClipboardForm * cbform,UgtkSetting * setting)147 void  ugtk_clipboard_form_get (struct UgtkClipboardForm* cbform, UgtkSetting* setting)
148 {
149 	GtkTextIter  iter1;
150 	GtkTextIter  iter2;
151 
152 	gtk_text_buffer_get_start_iter (cbform->buffer, &iter1);
153 	gtk_text_buffer_get_end_iter (cbform->buffer, &iter2);
154 
155 	ug_free (setting->clipboard.pattern);
156 	setting->clipboard.pattern = gtk_text_buffer_get_text (cbform->buffer, &iter1, &iter2, FALSE);
157 	setting->clipboard.monitor = gtk_toggle_button_get_active (cbform->monitor);
158 	setting->clipboard.quiet = gtk_toggle_button_get_active (cbform->quiet);
159 	setting->clipboard.website = gtk_toggle_button_get_active (cbform->website);
160 	setting->clipboard.nth_category = gtk_spin_button_get_value_as_int (cbform->nth_spin);
161 	// remove line break
162 	ug_str_remove_crlf (setting->clipboard.pattern, setting->clipboard.pattern);
163 }
164 
165 // ----------------------------------------------------------------------------
166 // UgtkUserInterfaceForm
167 //
ugtk_user_interface_form_init(struct UgtkUserInterfaceForm * uiform)168 void  ugtk_user_interface_form_init (struct UgtkUserInterfaceForm* uiform)
169 {
170 	GtkWidget*  widget;
171 	GtkBox*     vbox;
172 
173 	uiform->self = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
174 	// Confirmation
175 	vbox = (GtkBox*) uiform->self;
176 	widget = gtk_frame_new (_("Confirmation"));
177 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
178 	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
179 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) vbox);
180 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
181 	// Confirmation check buttons
182 	widget = gtk_check_button_new_with_label (_("Show confirmation dialog on exit"));
183 	uiform->confirm_exit = (GtkToggleButton*) widget;
184 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
185 	widget = gtk_check_button_new_with_label (_("Confirm when deleting files"));
186 	uiform->confirm_delete = (GtkToggleButton*) widget;
187 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
188 
189 	// System Tray
190 	vbox = (GtkBox*) uiform->self;
191 	widget = gtk_frame_new (_("System Tray"));
192 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
193 	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
194 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) vbox);
195 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
196 	// System Tray check buttons
197 	widget = gtk_check_button_new_with_label (_("Always show tray icon"));
198 	uiform->show_trayicon = (GtkToggleButton*) widget;
199 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
200 	widget = gtk_check_button_new_with_label (_("Minimize to tray on startup"));
201 	uiform->start_in_tray = (GtkToggleButton*) widget;
202 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
203 	widget = gtk_check_button_new_with_label (_("Close to tray on window close"));
204 	uiform->close_to_tray = (GtkToggleButton*) widget;
205 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
206 #ifdef HAVE_APP_INDICATOR
207 	widget = gtk_check_button_new_with_label (_("Use Ubuntu's App Indicator"));
208 	uiform->app_indicator = (GtkToggleButton*) widget;
209 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
210 #endif
211 
212 	// Others
213 	vbox = (GtkBox*) uiform->self;
214 	widget = gtk_check_button_new_with_label (_("Enable offline mode on startup"));
215 	uiform->start_in_offline_mode = (GtkToggleButton*) widget;
216 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
217 	widget = gtk_check_button_new_with_label (_("Download starting notification"));
218 	uiform->start_notification = (GtkToggleButton*) widget;
219 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
220 	widget = gtk_check_button_new_with_label (_("Sound when download is finished"));
221 	uiform->sound_notification = (GtkToggleButton*) widget;
222 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
223 	widget = gtk_check_button_new_with_label (_("Apply recent download settings"));
224 	uiform->apply_recent = (GtkToggleButton*) widget;
225 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
226 //	widget = gtk_check_button_new_with_label (_("Skip existing URI from clipboard and command-line"));
227 //	uiform->skip_existing = (GtkToggleButton*) widget;
228 //	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
229 	widget = gtk_check_button_new_with_label (_("Display large icon"));
230 	uiform->large_icon = (GtkToggleButton*) widget;
231 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
232 }
233 
ugtk_user_interface_form_set(struct UgtkUserInterfaceForm * uiform,UgtkSetting * setting)234 void  ugtk_user_interface_form_set (struct UgtkUserInterfaceForm* uiform, UgtkSetting* setting)
235 {
236 	gtk_toggle_button_set_active (uiform->close_to_tray,
237 			setting->ui.close_to_tray);
238 	gtk_toggle_button_set_active (uiform->confirm_exit,
239 			setting->ui.exit_confirmation);
240 	gtk_toggle_button_set_active (uiform->confirm_delete,
241 			setting->ui.delete_confirmation);
242 	gtk_toggle_button_set_active (uiform->show_trayicon,
243 			setting->ui.show_trayicon);
244 	gtk_toggle_button_set_active (uiform->start_in_tray,
245 			setting->ui.start_in_tray);
246 	gtk_toggle_button_set_active (uiform->start_in_offline_mode,
247 			setting->ui.start_in_offline_mode);
248 	gtk_toggle_button_set_active (uiform->start_notification,
249 			setting->ui.start_notification);
250 	gtk_toggle_button_set_active (uiform->sound_notification,
251 			setting->ui.sound_notification);
252 	gtk_toggle_button_set_active (uiform->apply_recent,
253 			setting->ui.apply_recent);
254 //	gtk_toggle_button_set_active (uiform->skip_existing,
255 //			setting->ui.skip_existing);
256 	gtk_toggle_button_set_active (uiform->large_icon,
257 			setting->ui.large_icon);
258 #ifdef HAVE_APP_INDICATOR
259 	gtk_toggle_button_set_active (uiform->app_indicator,
260 			setting->ui.app_indicator);
261 #endif
262 }
263 
ugtk_user_interface_form_get(struct UgtkUserInterfaceForm * uiform,UgtkSetting * setting)264 void  ugtk_user_interface_form_get (struct UgtkUserInterfaceForm* uiform, UgtkSetting* setting)
265 {
266 	setting->ui.close_to_tray = gtk_toggle_button_get_active (uiform->close_to_tray);
267 	setting->ui.exit_confirmation = gtk_toggle_button_get_active (uiform->confirm_exit);
268 	setting->ui.delete_confirmation = gtk_toggle_button_get_active (uiform->confirm_delete);
269 	setting->ui.show_trayicon = gtk_toggle_button_get_active (uiform->show_trayicon);
270 	setting->ui.start_in_tray = gtk_toggle_button_get_active (uiform->start_in_tray);
271 	setting->ui.start_in_offline_mode = gtk_toggle_button_get_active (uiform->start_in_offline_mode);
272 	setting->ui.start_notification = gtk_toggle_button_get_active (uiform->start_notification);
273 	setting->ui.sound_notification = gtk_toggle_button_get_active (uiform->sound_notification);
274 	setting->ui.apply_recent = gtk_toggle_button_get_active (uiform->apply_recent);
275 //	setting->ui.skip_existing = gtk_toggle_button_get_active (uiform->skip_existing);
276 	setting->ui.large_icon = gtk_toggle_button_get_active (uiform->large_icon);
277 #ifdef HAVE_APP_INDICATOR
278 	setting->ui.app_indicator = gtk_toggle_button_get_active (uiform->app_indicator);
279 #endif
280 }
281 
282 // ----------------------------------------------------------------------------
283 // UgtkBandwidthForm
284 //
285 
ugtk_bandwidth_form_init(struct UgtkBandwidthForm * bwform)286 void  ugtk_bandwidth_form_init (struct UgtkBandwidthForm* bwform)
287 {
288 	GtkWidget*  widget;
289 	GtkBox*     box;
290 	GtkBox*     vbox;
291 	GtkBox*     hbox;
292 
293 	box = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
294 	bwform->self = (GtkWidget*) box;
295 	widget = gtk_label_new (_("These will affect all plug-ins."));
296 	gtk_box_pack_start (box, widget, FALSE, FALSE, 2);
297 	widget = gtk_label_new ("");
298 	gtk_box_pack_start (box, widget, FALSE, FALSE, 2);
299 
300 	// Global speed limit
301 	widget = gtk_frame_new (_("Global speed limit"));
302 	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
303 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) vbox);
304 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
305 	gtk_box_pack_start (box, widget, FALSE, FALSE, 2);
306 	// Max upload speed
307 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
308 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
309 	widget = gtk_label_new (_("Max upload speed"));
310 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
311 	widget = gtk_label_new (_("KiB/s"));
312 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
313 	widget = gtk_spin_button_new_with_range (0.0, 4000000000.0, 5.0);
314 	gtk_entry_set_width_chars (GTK_ENTRY (widget), 15);
315 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
316 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
317 	bwform->upload = (GtkSpinButton*) widget;
318 	// Max download speed
319 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
320 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
321 	widget = gtk_label_new (_("Max download speed"));
322 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
323 	widget = gtk_label_new (_("KiB/s"));
324 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
325 	widget = gtk_spin_button_new_with_range (0.0, 4000000000.0, 5.0);
326 	gtk_entry_set_width_chars (GTK_ENTRY (widget), 15);
327 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
328 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
329 	bwform->download = (GtkSpinButton*) widget;
330 }
331 
ugtk_bandwidth_form_set(struct UgtkBandwidthForm * bwform,UgtkSetting * setting)332 void  ugtk_bandwidth_form_set (struct UgtkBandwidthForm* bwform, UgtkSetting* setting)
333 {
334 	gtk_spin_button_set_value (bwform->upload, setting->bandwidth.normal.upload);
335 	gtk_spin_button_set_value (bwform->download, setting->bandwidth.normal.download);
336 }
337 
ugtk_bandwidth_form_get(struct UgtkBandwidthForm * bwform,UgtkSetting * setting)338 void  ugtk_bandwidth_form_get (struct UgtkBandwidthForm* bwform, UgtkSetting* setting)
339 {
340 	setting->bandwidth.normal.upload   = (guint) gtk_spin_button_get_value (bwform->upload);
341 	setting->bandwidth.normal.download = (guint) gtk_spin_button_get_value (bwform->download);
342 }
343 
344 // ----------------------------------------------------------------------------
345 // UgtkCompletionForm
346 //
ugtk_completion_form_init(struct UgtkCompletionForm * csform)347 void  ugtk_completion_form_init (struct UgtkCompletionForm* csform)
348 {
349 	GtkWidget*  widget;
350 	GtkWidget*  entry;
351 	GtkBox*     vbox;
352 	GtkBox*     hbox;
353 
354 	widget = gtk_frame_new (_("Completion Auto-Actions"));
355 	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
356 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) vbox);
357 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
358 	csform->self = widget;
359 
360 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
361 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 1);
362 	widget = gtk_label_new (_("Custom command:"));
363 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
364 
365 	entry = gtk_entry_new ();
366 	gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
367 	gtk_box_pack_start (vbox, entry, TRUE, TRUE, 2);
368 	csform->command = (GtkEntry*) entry;
369 
370 	gtk_box_pack_start (vbox, gtk_label_new (""), FALSE, FALSE, 2);
371 
372 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
373 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 1);
374 	widget = gtk_label_new (_("Custom command if error occurred:"));
375 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
376 
377 	entry = gtk_entry_new ();
378 	gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
379 	gtk_box_pack_start (vbox, entry, TRUE, TRUE, 2);
380 	csform->on_error = (GtkEntry*) entry;
381 }
382 
ugtk_completion_form_set(struct UgtkCompletionForm * csform,UgtkSetting * setting)383 void  ugtk_completion_form_set (struct UgtkCompletionForm* csform, UgtkSetting* setting)
384 {
385 	if (setting->completion.command)
386 		gtk_entry_set_text (csform->command, setting->completion.command);
387 	if (setting->completion.on_error)
388 		gtk_entry_set_text (csform->command, setting->completion.on_error);
389 }
390 
ugtk_completion_form_get(struct UgtkCompletionForm * csform,UgtkSetting * setting)391 void  ugtk_completion_form_get (struct UgtkCompletionForm* csform, UgtkSetting* setting)
392 {
393 	const char*  string;
394 
395 	ug_free (setting->completion.command);
396 	string = gtk_entry_get_text (csform->command);
397 	setting->completion.command = (string[0]) ? ug_strdup (string) : NULL;
398 
399 	ug_free (setting->completion.on_error);
400 	string = gtk_entry_get_text (csform->on_error);
401 	setting->completion.on_error = (string[0]) ? ug_strdup (string) : NULL;
402 }
403 
404 // ----------------------------------------------------------------------------
405 // UgtkAutoSaveForm
406 //
on_auto_save_toggled(GtkWidget * widget,struct UgtkAutoSaveForm * asform)407 static void on_auto_save_toggled (GtkWidget* widget, struct UgtkAutoSaveForm* asform)
408 {
409 	gboolean  sensitive;
410 
411 	sensitive = gtk_toggle_button_get_active (asform->enable);
412 	gtk_widget_set_sensitive (asform->interval_label, sensitive);
413 	gtk_widget_set_sensitive ((GtkWidget*) asform->interval_spin, sensitive);
414 	gtk_widget_set_sensitive (asform->minutes_label, sensitive);
415 }
416 
ugtk_auto_save_form_init(struct UgtkAutoSaveForm * asform)417 void  ugtk_auto_save_form_init (struct UgtkAutoSaveForm* asform)
418 {
419 	GtkBox*    hbox;
420 	GtkWidget* widget;
421 
422 	asform->self = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
423 	hbox = (GtkBox*) asform->self;
424 	widget = gtk_check_button_new_with_mnemonic (_("_Autosave"));
425 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
426 	g_signal_connect (widget, "toggled",
427 			G_CALLBACK (on_auto_save_toggled), asform);
428 	asform->enable = (GtkToggleButton*) widget;
429 
430 	// space
431 	widget = gtk_label_new ("");
432 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 30);
433 
434 	// auto save interval label
435 	widget = gtk_label_new_with_mnemonic (_("_Interval:"));
436 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
437 	asform->interval_label = widget;
438 	gtk_label_set_mnemonic_widget (GTK_LABEL (asform->interval_label),
439 			(GtkWidget*) asform->interval_spin);
440 	// auto save interval spin
441 	widget = gtk_spin_button_new_with_range (1.0, 120.0, 1.0);
442 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
443 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
444 	asform->interval_spin = (GtkSpinButton*) widget;
445 	// auto save interval unit label
446 	widget = gtk_label_new_with_mnemonic (_("minutes"));
447 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
448 	asform->minutes_label = widget;
449 }
450 
ugtk_auto_save_form_set(struct UgtkAutoSaveForm * asform,UgtkSetting * setting)451 void  ugtk_auto_save_form_set (struct UgtkAutoSaveForm* asform, UgtkSetting* setting)
452 {
453 	gtk_toggle_button_set_active (asform->enable, setting->auto_save.enable);
454 	gtk_spin_button_set_value (asform->interval_spin, (gdouble) setting->auto_save.interval);
455 	gtk_toggle_button_toggled (asform->enable);
456 //	on_auto_save_toggled ((GtkWidget*) asform->enable, asform);
457 }
458 
ugtk_auto_save_form_get(struct UgtkAutoSaveForm * asform,UgtkSetting * setting)459 void  ugtk_auto_save_form_get (struct UgtkAutoSaveForm* asform, UgtkSetting* setting)
460 {
461 	setting->auto_save.enable = gtk_toggle_button_get_active (asform->enable);
462 	setting->auto_save.interval = gtk_spin_button_get_value_as_int (asform->interval_spin);
463 }
464 
465 // ----------------------------------------------------------------------------
466 // UgtkCommandlineForm
467 //
ugtk_commandline_form_init(struct UgtkCommandlineForm * clform)468 void  ugtk_commandline_form_init (struct UgtkCommandlineForm* clform)
469 {
470 	GtkWidget*  widget;
471 	GtkBox*     vbox;
472 	GtkBox*     hbox;
473 
474 	// Commandline Settings
475 	widget = gtk_frame_new (_("Commandline Settings"));
476 	clform->self = widget;
477 	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
478 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) vbox);
479 	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
480 
481 	// --quiet
482 	widget = gtk_check_button_new_with_mnemonic (_("Use '--quiet' by default"));
483 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 1);
484 	clform->quiet = (GtkToggleButton*) widget;
485 	// --category-index
486 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
487 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
488 	widget = gtk_label_new (_("Default category index"));
489 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
490 	clform->index_label = widget;
491 	widget = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
492 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
493 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
494 	clform->index_spin = (GtkSpinButton*) widget;
495 	// hint
496 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
497 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, FALSE, 2);
498 	widget = gtk_label_new (" - ");
499 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
500 	widget = gtk_label_new (_("Adding to Nth category if no matched category."));
501 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
502 }
503 
ugtk_commandline_form_set(struct UgtkCommandlineForm * clform,UgtkSetting * setting)504 void  ugtk_commandline_form_set (struct UgtkCommandlineForm* clform, UgtkSetting* setting)
505 {
506 	gtk_toggle_button_set_active (clform->quiet, setting->commandline.quiet);
507 	gtk_spin_button_set_value (clform->index_spin, setting->commandline.nth_category);
508 }
509 
ugtk_commandline_form_get(struct UgtkCommandlineForm * clform,UgtkSetting * setting)510 void  ugtk_commandline_form_get (struct UgtkCommandlineForm* clform, UgtkSetting* setting)
511 {
512 	setting->commandline.quiet = gtk_toggle_button_get_active (clform->quiet);
513 	setting->commandline.nth_category = gtk_spin_button_get_value_as_int (clform->index_spin);
514 }
515 
516 // ----------------------------------------------------------------------------
517 // UgtkPluginForm
518 //
on_plugin_launch_toggled(GtkWidget * widget,struct UgtkPluginForm * psform)519 static void on_plugin_launch_toggled (GtkWidget* widget, struct UgtkPluginForm* psform)
520 {
521 	gboolean  sensitive;
522 
523 	sensitive = gtk_toggle_button_get_active (psform->launch);
524 	gtk_widget_set_sensitive ((GtkWidget*) psform->local, sensitive);
525 }
526 
on_order_changed(GtkComboBox * widget,struct UgtkPluginForm * psform)527 static void on_order_changed (GtkComboBox* widget, struct UgtkPluginForm* psform)
528 {
529 	int  index;
530 
531 	index = gtk_combo_box_get_active (widget);
532 	if (index >= UGTK_PLUGIN_ORDER_ARIA2)
533 		gtk_widget_set_sensitive (psform->aria2_opts, TRUE);
534 	else
535 		gtk_widget_set_sensitive (psform->aria2_opts, FALSE);
536 }
537 
ugtk_plugin_form_init(struct UgtkPluginForm * psform)538 void  ugtk_plugin_form_init (struct UgtkPluginForm* psform)
539 {
540 	PangoContext*  context;
541 	PangoLayout*   layout;
542 	int            text_height;
543 	GtkBox*      vbox;
544 	GtkBox*      hbox;
545 	GtkBox*      box;
546 	GtkWidget*   widget;
547 	GtkScrolledWindow*  scroll;
548 
549 	psform->self = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
550 	vbox = (GtkBox*) psform->self;
551 
552 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
553 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 2);
554 	widget = gtk_label_new (_("Plug-in matching order:"));
555 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
556 	widget = gtk_combo_box_text_new ();
557 	psform->order = (GtkComboBoxText*) widget;
558 	gtk_combo_box_text_insert_text (psform->order,
559 			UGTK_PLUGIN_ORDER_CURL, "curl");
560 	gtk_combo_box_text_insert_text (psform->order,
561 			UGTK_PLUGIN_ORDER_ARIA2, "aria2");
562 	gtk_combo_box_text_insert_text (psform->order,
563 			UGTK_PLUGIN_ORDER_CURL_ARIA2, "curl + aria2");
564 	gtk_combo_box_text_insert_text (psform->order,
565 			UGTK_PLUGIN_ORDER_ARIA2_CURL, "aria2 + curl");
566 	g_signal_connect (psform->order, "changed",
567 			G_CALLBACK (on_order_changed), psform);
568 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 4);
569 
570 	widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
571 	gtk_box_pack_start (vbox, widget, TRUE, TRUE, 2);
572 	psform->aria2_opts = widget;
573 	vbox = (GtkBox*) widget;
574 
575 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
576 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 4);
577 	widget = gtk_label_new (_("Aria2 plug-in options"));
578 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
579 	gtk_box_pack_start (hbox, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), TRUE, TRUE, 4);
580 
581 	// URI entry
582 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
583 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 2);
584 	widget = gtk_label_new (_("URI"));
585 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
586 	widget = gtk_entry_new ();
587 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
588 	gtk_box_pack_start (hbox, widget, TRUE,  TRUE,  4);
589 	psform->uri = (GtkEntry*) widget;
590 	// Token entry
591 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
592 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 2);
593 	widget = gtk_label_new (_("RPC authorization secret token"));
594 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
595 	widget = gtk_entry_new ();
596 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
597 	gtk_box_pack_start (hbox, widget, TRUE,  TRUE,  4);
598 	psform->token = (GtkEntry*) widget;
599 
600 	// ------------------------------------------------------------------------
601 	// Speed Limits
602 	widget = gtk_frame_new (_("Global speed limit for aria2 only"));
603 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 4);
604 	box = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
605 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) box);
606 	gtk_container_set_border_width (GTK_CONTAINER (box), 2);
607 	// Max upload speed
608 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
609 	gtk_box_pack_start (box, (GtkWidget*) hbox, FALSE, FALSE, 2);
610 	widget = gtk_label_new (_("Max upload speed"));
611 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
612 	widget = gtk_label_new (_("KiB/s"));
613 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
614 	widget = gtk_spin_button_new_with_range (0.0, 4000000000.0, 5.0);
615 	gtk_entry_set_width_chars (GTK_ENTRY (widget), 15);
616 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
617 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
618 	psform->upload = (GtkSpinButton*) widget;
619 	// Max download speed
620 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
621 	gtk_box_pack_start (box, (GtkWidget*) hbox, FALSE, FALSE, 2);
622 	widget = gtk_label_new (_("Max download speed"));
623 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
624 	widget = gtk_label_new (_("KiB/s"));
625 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
626 	widget = gtk_spin_button_new_with_range (0.0, 4000000000.0, 5.0);
627 	gtk_entry_set_width_chars (GTK_ENTRY (widget), 15);
628 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
629 	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 2);
630 	psform->download = (GtkSpinButton*) widget;
631 
632 	// ------------------------------------------------------------------------
633 	// aria2 works on local device
634 	// launch
635 	widget = gtk_check_button_new_with_mnemonic (_("_Launch aria2 on startup"));
636 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 2);
637 	g_signal_connect (widget, "toggled",
638 			G_CALLBACK (on_plugin_launch_toggled), psform);
639 	psform->launch = (GtkToggleButton*) widget;
640 	// shutdown
641 	widget = gtk_check_button_new_with_mnemonic (_("_Shutdown aria2 on exit"));
642 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 2);
643 	psform->shutdown = (GtkToggleButton*) widget;
644 
645 	// ------------------------------------------------------------------------
646 	// Local options
647 	widget = gtk_frame_new (_("Launch aria2 on local device"));
648 	gtk_box_pack_start (vbox, widget, FALSE, FALSE, 4);
649 	psform->local = widget;
650 	box = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
651 	gtk_container_add (GTK_CONTAINER (widget), (GtkWidget*) box);
652 	gtk_container_set_border_width (GTK_CONTAINER (box), 2);
653 	// Path
654 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
655 	gtk_box_pack_start (box, (GtkWidget*) hbox, FALSE, TRUE, 4);
656 	widget = gtk_label_new (_("Path"));
657 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
658 	widget = gtk_entry_new ();
659 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
660 	gtk_box_pack_start (hbox, widget, TRUE,  TRUE,  2);
661 	psform->path = (GtkEntry*) widget;
662 	//
663 	gtk_box_pack_start (box, gtk_label_new (""), FALSE, FALSE, 0);
664 	// Arguments
665 	// get text height --- begin ---
666 	context = gtk_widget_get_pango_context (widget);
667 	layout = pango_layout_new (context);
668 	pango_layout_set_text (layout, "joIN", -1);
669 	pango_layout_get_pixel_size (layout, NULL, &text_height);
670 	g_object_unref (layout);
671 	//  get text height --- end ---
672 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
673 	gtk_box_pack_start (box, (GtkWidget*) hbox, FALSE, TRUE, 2);
674 	widget = gtk_label_new (_("Arguments"));
675 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 2);
676 	widget = gtk_label_new (" - ");
677 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
678 	// Arguments - hint
679 	widget = gtk_label_new (_("You must restart uGet after modifying it."));
680 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
681 	// Arguments - Scrolled Window
682 	scroll = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
683 	gtk_scrolled_window_set_shadow_type (scroll, GTK_SHADOW_IN);
684 	gtk_widget_set_size_request (GTK_WIDGET (scroll), 100, text_height * 3);
685 	gtk_box_pack_start (box, GTK_WIDGET (scroll), FALSE, TRUE, 2);
686 	// Arguments - text view
687 	psform->args_buffer = gtk_text_buffer_new (NULL);
688 	psform->args = gtk_text_view_new_with_buffer (psform->args_buffer);
689 	g_object_unref (psform->args_buffer);
690 	gtk_text_view_set_wrap_mode ((GtkTextView*) psform->args, GTK_WRAP_CHAR);
691 	gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (psform->args));
692 
693 	// ------------------------------------------------------------------------
694 	on_plugin_launch_toggled ((GtkWidget*) psform->launch, psform);
695 	gtk_widget_show (psform->self);
696 }
697 
ugtk_plugin_form_set(struct UgtkPluginForm * psform,UgtkSetting * setting)698 void  ugtk_plugin_form_set (struct UgtkPluginForm* psform, UgtkSetting* setting)
699 {
700 	gtk_combo_box_set_active ((GtkComboBox*) psform->order, setting->plugin_order);
701 
702 	gtk_toggle_button_set_active (psform->launch, setting->aria2.launch);
703 	gtk_toggle_button_set_active (psform->shutdown, setting->aria2.shutdown);
704 
705 	if (setting->aria2.uri)
706 		gtk_entry_set_text (psform->uri,  setting->aria2.uri);
707 	if (setting->aria2.token)
708 		gtk_entry_set_text (psform->token,  setting->aria2.token);
709 	if (setting->aria2.path)
710 		gtk_entry_set_text (psform->path, setting->aria2.path);
711 //	if (setting->aria2.args)
712 //		gtk_entry_set_text (psform->args, setting->aria2.args);
713 	if (setting->aria2.args)
714 		gtk_text_buffer_set_text (psform->args_buffer, setting->aria2.args, -1);
715 
716 	gtk_spin_button_set_value (psform->upload, setting->aria2.limit.upload);
717 	gtk_spin_button_set_value (psform->download, setting->aria2.limit.download);
718 }
719 
ugtk_plugin_form_get(struct UgtkPluginForm * psform,UgtkSetting * setting)720 void  ugtk_plugin_form_get (struct UgtkPluginForm* psform, UgtkSetting* setting)
721 {
722 	GtkTextIter  iter1;
723 	GtkTextIter  iter2;
724 	const char*  token;
725 
726 	setting->plugin_order = gtk_combo_box_get_active ((GtkComboBox*) psform->order);
727 
728 	setting->aria2.launch = gtk_toggle_button_get_active (psform->launch);
729 	setting->aria2.shutdown = gtk_toggle_button_get_active (psform->shutdown);
730 
731 	ug_free (setting->aria2.uri);
732 	ug_free (setting->aria2.token);
733 	ug_free (setting->aria2.path);
734 	ug_free (setting->aria2.args);
735 	setting->aria2.uri = ug_strdup (gtk_entry_get_text (psform->uri));
736 	token = gtk_entry_get_text (psform->token);
737 	if (token[0] == 0)
738 		setting->aria2.token = NULL;
739 	else
740 		setting->aria2.token = ug_strdup (token);
741 	setting->aria2.path = ug_strdup (gtk_entry_get_text (psform->path));
742 //	setting->aria2.args = ug_strdup (gtk_entry_get_text (psform->args));
743 	gtk_text_buffer_get_start_iter (psform->args_buffer, &iter1);
744 	gtk_text_buffer_get_end_iter (psform->args_buffer, &iter2);
745 	setting->aria2.args = gtk_text_buffer_get_text (psform->args_buffer, &iter1, &iter2, FALSE);
746 	ug_str_remove_crlf (setting->aria2.args, setting->aria2.args);
747 
748 	setting->aria2.limit.upload   = (guint) gtk_spin_button_get_value (psform->upload);
749 	setting->aria2.limit.download = (guint) gtk_spin_button_get_value (psform->download);
750 }
751 
752 // ----------------------------------------------------------------------------
753 // UgtkMediaWebsiteForm
754 //
755 
on_match_mode_changed(GtkComboBox * widget,struct UgtkMediaWebsiteForm * mwform)756 static void on_match_mode_changed (GtkComboBox* widget, struct UgtkMediaWebsiteForm* mwform)
757 {
758 	gboolean sensitive;
759 	int      index;
760 
761 	index = gtk_combo_box_get_active (widget);
762 	if (index == UGET_MEDIA_MATCH_0)
763 		sensitive = FALSE;
764 	else
765 		sensitive = TRUE;
766 
767 	gtk_widget_set_sensitive ((GtkWidget*) mwform->quality, sensitive);
768 	gtk_widget_set_sensitive ((GtkWidget*) mwform->type, sensitive);
769 }
770 
ugtk_media_website_form_init(struct UgtkMediaWebsiteForm * mwform)771 void  ugtk_media_website_form_init (struct UgtkMediaWebsiteForm* mwform)
772 {
773 	GtkBox*     vbox;
774 	GtkBox*     hbox;
775 	GtkWidget*  widget;
776 	GtkGrid*    grid;
777 
778 	mwform->self = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
779 	vbox = (GtkBox*) mwform->self;
780 
781 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
782 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 2);
783 	widget = gtk_label_new (_("Media matching mode:"));
784 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
785 	widget = gtk_combo_box_text_new ();
786 	mwform->match_mode = (GtkComboBoxText*) widget;
787 	gtk_combo_box_text_insert_text (mwform->match_mode,
788 			UGET_MEDIA_MATCH_0, _("Don't match"));
789 	gtk_combo_box_text_insert_text (mwform->match_mode,
790 			UGET_MEDIA_MATCH_1, _("Match 1 condition"));
791 	gtk_combo_box_text_insert_text (mwform->match_mode,
792 			UGET_MEDIA_MATCH_2, _("Match 2 condition"));
793 	gtk_combo_box_text_insert_text (mwform->match_mode,
794 			UGET_MEDIA_MATCH_NEAR, _("Near quality"));
795 	g_signal_connect (mwform->match_mode, "changed",
796 			G_CALLBACK (on_match_mode_changed), mwform);
797 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 4);
798 
799 	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
800 	gtk_box_pack_start (vbox, (GtkWidget*) hbox, FALSE, TRUE, 4);
801 	widget = gtk_label_new (_("Match conditions"));
802 	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
803 	gtk_box_pack_start (hbox,
804 			gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), TRUE, TRUE, 4);
805 
806 	// conditions
807 	grid = (GtkGrid*) gtk_grid_new ();
808 	gtk_box_pack_start (vbox, (GtkWidget*) grid, FALSE, FALSE, 0);
809 	// Quality
810 	widget = gtk_label_new (_("Quality:"));
811 	g_object_set (widget, "margin-left", 3, "margin-right", 3, NULL);
812 	g_object_set (widget, "margin-top", 2, "margin-bottom", 2, NULL);
813 	gtk_grid_attach (grid, widget, 0, 0, 1, 1);
814 	widget = gtk_combo_box_text_new ();
815 	mwform->quality = (GtkComboBoxText*) widget;
816 	gtk_combo_box_text_insert_text (mwform->quality,
817 			UGET_MEDIA_QUALITY_240P, "240p");
818 	gtk_combo_box_text_insert_text (mwform->quality,
819 			UGET_MEDIA_QUALITY_360P, "360p");
820 	gtk_combo_box_text_insert_text (mwform->quality,
821 			UGET_MEDIA_QUALITY_480P, "480p");
822 	gtk_combo_box_text_insert_text (mwform->quality,
823 			UGET_MEDIA_QUALITY_720P, "720p");
824 	gtk_combo_box_text_insert_text (mwform->quality,
825 			UGET_MEDIA_QUALITY_1080P, "1080p");
826 	g_object_set (widget, "margin-left", 3, "margin-right", 3, NULL);
827 	g_object_set (widget, "margin-top", 2, "margin-bottom", 2, NULL);
828 	gtk_grid_attach (grid, widget, 1, 0, 1, 1);
829 	// Type
830 	widget = gtk_label_new (_("Type:"));
831 	g_object_set (widget, "margin-left", 3, "margin-right", 3, NULL);
832 	g_object_set (widget, "margin-top", 2, "margin-bottom", 2, NULL);
833 	gtk_grid_attach (grid, widget, 0, 1, 1, 1);
834 	widget = gtk_combo_box_text_new ();
835 	mwform->type = (GtkComboBoxText*) widget;
836 	gtk_combo_box_text_insert_text (mwform->type,
837 			UGET_MEDIA_TYPE_MP4, "mp4");
838 	gtk_combo_box_text_insert_text (mwform->type,
839 			UGET_MEDIA_TYPE_WEBM, "webm");
840 	gtk_combo_box_text_insert_text (mwform->type,
841 			UGET_MEDIA_TYPE_3GPP, "3gpp");
842 	gtk_combo_box_text_insert_text (mwform->type,
843 			UGET_MEDIA_TYPE_FLV, "flv");
844 	g_object_set (widget, "margin-left", 3, "margin-right", 3, NULL);
845 	g_object_set (widget, "margin-top", 2, "margin-bottom", 2, NULL);
846 	gtk_grid_attach (grid, widget, 1, 1, 1, 1);
847 
848 	gtk_widget_show (mwform->self);
849 }
850 
ugtk_media_website_form_set(struct UgtkMediaWebsiteForm * mwform,UgtkSetting * setting)851 void  ugtk_media_website_form_set (struct UgtkMediaWebsiteForm* mwform, UgtkSetting* setting)
852 {
853 	gtk_combo_box_set_active ((GtkComboBox*) mwform->match_mode, setting->media.match_mode);
854 	gtk_combo_box_set_active ((GtkComboBox*) mwform->quality, setting->media.quality);
855 	gtk_combo_box_set_active ((GtkComboBox*) mwform->type, setting->media.type);
856 }
857 
ugtk_media_website_form_get(struct UgtkMediaWebsiteForm * mwform,UgtkSetting * setting)858 void  ugtk_media_website_form_get (struct UgtkMediaWebsiteForm* mwform, UgtkSetting* setting)
859 {
860 	setting->media.match_mode = gtk_combo_box_get_active ((GtkComboBox*) mwform->match_mode);
861 	setting->media.quality = gtk_combo_box_get_active ((GtkComboBox*) mwform->quality);
862 	setting->media.type = gtk_combo_box_get_active ((GtkComboBox*) mwform->type);
863 }
864