1 #include "html_import_dialog.h"
2 #include "selection_view.h"
3 #include "selection_store.h"
4 #include "urlgfe.h"
5
6 // signal handler --------------------------------------------------------------
on_choose(GtkWidget * w,HtmlImportDialog * hid)7 static void on_choose(GtkWidget* w, HtmlImportDialog* hid)
8 {
9 HtmlImportElement* hie;
10 HtmlImportElementDialog* hied;
11 gint n_page;
12
13 n_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(hid->notebook));
14
15 hie = html_import_get_element (hid->html_import, n_page);
16
17 hied = html_import_element_dialog_new (hie, GTK_WINDOW(hid->self));
18
19 if (gtk_dialog_run (hied->self)==GTK_RESPONSE_OK)
20 html_import_element_apply_selection (hie);
21
22 html_import_element_dialog_destroy (hied);
23 }
24
on_select_all(GtkWidget * w,HtmlImportDialog * hid)25 static void on_select_all(GtkWidget* w, HtmlImportDialog* hid)
26 {
27 HtmlImportElement* hie;
28 gint n_page;
29
30 n_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(hid->notebook));
31
32 hie = html_import_get_element (hid->html_import, n_page);
33
34 selection_store_set_selection_all (hie->url_store, TRUE);
35 }
36
on_select_none(GtkWidget * w,HtmlImportDialog * hid)37 static void on_select_none(GtkWidget* w, HtmlImportDialog* hid)
38 {
39 HtmlImportElement* hie;
40 gint n_page;
41
42 n_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(hid->notebook));
43
44 hie = html_import_get_element (hid->html_import, n_page);
45
46 selection_store_set_selection_all (hie->url_store, FALSE);
47 }
48
49 void html_import_dialog_add_page (HtmlImportDialog* hid,
50 HtmlImportElement* hie);
51
html_import_dialog_new(HtmlImport * hi,GtkWindow * parent)52 HtmlImportDialog* html_import_dialog_new (HtmlImport* hi,
53 GtkWindow* parent)
54 {
55 HtmlImportDialog* hid = g_malloc (sizeof (HtmlImportDialog));
56 GList* node;
57
58 GtkWidget* action_area;
59 GtkWidget* vbox;
60 GtkWidget* hbox;
61 GtkWidget* label;
62 GtkWidget* button;
63 GtkWidget* separator;
64
65 hid->html_import = hi;
66
67 hid->self = (GtkDialog*)gtk_dialog_new_with_buttons (_("Import HTML file"),
68 parent,
69 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
70 NULL);
71 vbox = GTK_DIALOG (hid->self)->vbox;
72 action_area = GTK_DIALOG (hid->self)->action_area;
73
74 hid->notebook = gtk_notebook_new ();
75 separator = gtk_hseparator_new ();
76
77 // setup dialog & vbox
78 gtk_window_set_default_size (GTK_WINDOW(hid->self), 450, 350);
79 gtk_container_set_border_width (GTK_CONTAINER(hid->self), 5);
80 gtk_box_set_spacing (GTK_BOX(vbox), 5);
81
82 // action_area ( GtkHButtonBox )
83 button = gtk_button_new_with_label (_("Select none"));
84 gtk_box_pack_start (GTK_BOX(action_area), button, FALSE, FALSE, 0);
85 g_signal_connect (G_OBJECT(button), "clicked",
86 G_CALLBACK(on_select_none), (gpointer)hid);
87
88 button = gtk_button_new_with_label (_("Select all"));
89 gtk_box_pack_start (GTK_BOX(action_area), button, FALSE, FALSE, 0);
90 g_signal_connect (G_OBJECT(button), "clicked",
91 G_CALLBACK(on_select_all), (gpointer)hid);
92
93 button = gtk_button_new_with_label (_("Choose"));
94 gtk_box_pack_start (GTK_BOX(action_area), button, FALSE, FALSE, 0);
95 g_signal_connect (G_OBJECT(button), "clicked",
96 G_CALLBACK(on_choose), (gpointer)hid);
97
98 // response buttons
99 gtk_dialog_add_button (GTK_DIALOG(hid->self),
100 GTK_STOCK_CANCEL,
101 GTK_RESPONSE_CANCEL);
102 gtk_dialog_add_button (GTK_DIALOG(hid->self),
103 GTK_STOCK_OK,
104 GTK_RESPONSE_OK);
105
106 // vbox
107 hbox = gtk_hbox_new (FALSE, 5);
108 hid->entry = gtk_entry_new ();
109 label = gtk_label_new_with_mnemonic (_("_Base href"));
110 gtk_label_set_mnemonic_widget (GTK_LABEL(label), hid->entry);
111 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
112 gtk_box_pack_start (GTK_BOX(hbox), hid->entry, TRUE, TRUE, 0);
113
114 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
115 gtk_box_pack_start (GTK_BOX(vbox), separator, FALSE, FALSE, 0);
116 gtk_box_pack_start (GTK_BOX(vbox), hid->notebook, TRUE, TRUE, 0);
117
118 if (hi->base_href)
119 gtk_entry_set_text (GTK_ENTRY (hid->entry), hi->base_href);
120
121 // add element
122 for (node=hi->element_list; node; node=node->next)
123 html_import_dialog_add_page (hid, node->data);
124
125 gtk_widget_show_all (vbox);
126
127 return hid;
128 }
129
html_import_dialog_destroy(HtmlImportDialog * hid)130 void html_import_dialog_destroy (HtmlImportDialog* hid)
131 {
132 gtk_widget_destroy (GTK_WIDGET (hid->self));
133 g_free (hid);
134 }
135
html_import_dialog_run(HtmlImportDialog * hid)136 gint html_import_dialog_run (HtmlImportDialog* hid)
137 {
138 gint response;
139
140 response = gtk_dialog_run (hid->self);
141
142 g_free (hid->html_import->base_href);
143 hid->html_import->base_href = g_strdup (gtk_entry_get_text (GTK_ENTRY (hid->entry)));
144
145 return response;
146 }
147
html_import_dialog_add_page(HtmlImportDialog * hid,HtmlImportElement * hie)148 void html_import_dialog_add_page (HtmlImportDialog* hid,
149 HtmlImportElement* hie)
150 {
151 GtkWidget* label;
152 GtkWidget* scrolled_window;
153 GtkTreeView* sv;
154
155 sv = selection_view_new (hie->url_store, _("URL"));
156 label = gtk_label_new_with_mnemonic (hie->label_name);
157
158 // wrap tree_view with scrolled_window
159 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
160 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_window),
161 GTK_POLICY_AUTOMATIC,
162 GTK_POLICY_AUTOMATIC);
163
164 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled_window),
165 GTK_SHADOW_IN);
166
167 gtk_container_set_border_width ((GtkContainer*)scrolled_window, 5);
168
169 gtk_container_add ((GtkContainer*)scrolled_window,
170 GTK_WIDGET(sv) );
171
172 gtk_notebook_append_page (GTK_NOTEBOOK(hid->notebook),
173 scrolled_window, label);
174 }
175
176 // =================================================================
177
selection_store_select_all(GtkListStore * list_store)178 static void selection_store_select_all (GtkListStore* list_store)
179 {
180 selection_store_set_selection_all (list_store, TRUE);
181 }
182
selection_store_select_none(GtkListStore * list_store)183 static void selection_store_select_none (GtkListStore* list_store)
184 {
185 selection_store_set_selection_all (list_store, FALSE);
186 }
187
html_import_element_dialog_new(HtmlImportElement * hie,GtkWindow * parent)188 HtmlImportElementDialog* html_import_element_dialog_new (HtmlImportElement* hie,
189 GtkWindow* parent)
190 {
191 HtmlImportElementDialog* hied;
192 GtkWidget* hbox;
193 GtkWidget* vbox;
194 GtkWidget* vbox_sn;
195 GtkWidget* hbox_sn;
196 GtkWidget* scrolled_window;
197
198
199 hied = g_malloc (sizeof (HtmlImportElementDialog));
200
201 hied->element = hie;
202
203 hied->self = (GtkDialog*)gtk_dialog_new_with_buttons (_("Choose URL from class"),
204 parent,
205 GTK_DIALOG_MODAL,
206 GTK_STOCK_CANCEL,
207 GTK_RESPONSE_CANCEL,
208 GTK_STOCK_OK,
209 GTK_RESPONSE_OK,
210 NULL);
211 vbox = GTK_DIALOG (hied->self)->vbox;
212 hbox = gtk_hbox_new (TRUE, 5);
213 hied->button_all_address = gtk_button_new_with_mnemonic (_("Select _All"));
214 hied->button_none_address = gtk_button_new_with_mnemonic (_("Select _None"));
215 hied->button_all_extension = gtk_button_new_with_mnemonic (_("Select A_ll"));
216 hied->button_none_extension = gtk_button_new_with_mnemonic (_("Select Non_e"));
217
218 // create address_view & extension_view
219 hied->address_view = selection_view_new (hie->address.list_store,
220 _("Address"));
221 hied->extension_view = selection_view_new (hie->extension.list_store,
222 _("Extension"));
223 // setup dialog & vbox
224 gtk_box_set_spacing (GTK_BOX(vbox), 5);
225 gtk_window_set_default_size (GTK_WINDOW(hied->self), 420, 320);
226 gtk_container_set_border_width (GTK_CONTAINER(hied->self), 5);
227
228 // address
229 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
230 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
231 GTK_POLICY_AUTOMATIC,
232 GTK_POLICY_AUTOMATIC);
233 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
234 GTK_SHADOW_IN);
235 gtk_container_add (GTK_CONTAINER (scrolled_window),
236 GTK_WIDGET (hied->address_view) );
237 vbox_sn = gtk_vbox_new (FALSE, 5);
238 hbox_sn = gtk_hbox_new (FALSE, 5);
239 gtk_box_pack_start (GTK_BOX(vbox_sn), scrolled_window, TRUE, TRUE, 0);
240 gtk_box_pack_start (GTK_BOX(hbox_sn), hied->button_all_address, FALSE, FALSE, 0);
241 gtk_box_pack_start (GTK_BOX(hbox_sn), hied->button_none_address, FALSE, FALSE, 0);
242 gtk_box_pack_start (GTK_BOX(vbox_sn), hbox_sn, FALSE, FALSE, 0);
243 gtk_box_pack_start (GTK_BOX(hbox), vbox_sn, TRUE, TRUE, 0);
244
245 // extension
246 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
247 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
248 GTK_POLICY_AUTOMATIC,
249 GTK_POLICY_AUTOMATIC);
250 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
251 GTK_SHADOW_IN);
252 gtk_container_add (GTK_CONTAINER (scrolled_window),
253 GTK_WIDGET (hied->extension_view) );
254 vbox_sn = gtk_vbox_new (FALSE, 5);
255 hbox_sn = gtk_hbox_new (FALSE, 5);
256 gtk_box_pack_start (GTK_BOX(vbox_sn), scrolled_window, TRUE, TRUE, 0);
257 gtk_box_pack_start (GTK_BOX(hbox_sn), hied->button_all_extension, FALSE, FALSE, 0);
258 gtk_box_pack_start (GTK_BOX(hbox_sn), hied->button_none_extension, FALSE, FALSE, 0);
259 gtk_box_pack_start (GTK_BOX(vbox_sn), hbox_sn, FALSE, FALSE, 0);
260 gtk_box_pack_start (GTK_BOX(hbox), vbox_sn, TRUE, TRUE, 0);
261 gtk_box_pack_start (GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
262
263 // signal
264 g_signal_connect_swapped (hied->button_all_address, "clicked",
265 G_CALLBACK (selection_store_select_all),
266 hied->element->address.list_store);
267 g_signal_connect_swapped (hied->button_none_address, "clicked",
268 G_CALLBACK (selection_store_select_none),
269 hied->element->address.list_store);
270 g_signal_connect_swapped (hied->button_all_extension, "clicked",
271 G_CALLBACK (selection_store_select_all),
272 hied->element->extension.list_store);
273 g_signal_connect_swapped (hied->button_none_extension, "clicked",
274 G_CALLBACK (selection_store_select_none),
275 hied->element->extension.list_store);
276
277 selection_store_select_all (hied->element->address.list_store);
278
279 gtk_widget_show_all (GTK_WIDGET(vbox));
280
281 return hied;
282 }
283
html_import_element_dialog_destroy(HtmlImportElementDialog * hied)284 void html_import_element_dialog_destroy (HtmlImportElementDialog* hied)
285 {
286 gtk_widget_destroy (GTK_WIDGET (hied->self));
287 g_free (hied);
288 }
289
290