1 #include "urlgfe.h"
2 #include "main_window.h"
3 #include "category_view.h"
4
5 // utility functions ------------------------------------------------
6
7 // utility for GtkTextBuffer
text_buffer_add_text(GtkTextBuffer * buffer,GtkTextTag * text_tag,gchar * name,gchar * str)8 static void text_buffer_add_text (GtkTextBuffer* buffer,
9 GtkTextTag* text_tag,
10 gchar *name, gchar *str)
11 {
12 GtkTextIter text_iter;
13 GtkTextIter text_iter2;
14 GtkTextMark* mark;
15
16 gtk_text_buffer_get_end_iter (buffer, &text_iter2);
17 mark = gtk_text_buffer_create_mark (buffer, NULL, &text_iter2, TRUE);
18 gtk_text_buffer_insert (buffer, &text_iter2, name, -1);
19 // apply tag
20 gtk_text_buffer_get_end_iter (buffer, &text_iter2);
21 gtk_text_buffer_get_iter_at_mark (buffer, &text_iter, mark);
22 gtk_text_buffer_apply_tag (buffer, text_tag,
23 &text_iter, &text_iter2);
24 gtk_text_buffer_delete_mark (buffer, mark);
25
26 gtk_text_buffer_insert (buffer, &text_iter2,
27 STR_N2E(str), -1);
28 // to next line
29 gtk_text_buffer_get_end_iter (buffer, &text_iter2);
30 gtk_text_buffer_insert (buffer, &text_iter2, "\n", -1);
31 }
32
33 // utility for create button
tool_button_new(const gchar * stock_id,const gchar * tip_str,GtkTooltips * tips)34 static GtkWidget* tool_button_new (const gchar* stock_id,
35 const gchar* tip_str,
36 GtkTooltips* tips)
37 {
38 GtkWidget* button;
39 GtkWidget* image;
40
41 button = gtk_button_new();
42 image = gtk_image_new_from_stock (stock_id,
43 GTK_ICON_SIZE_SMALL_TOOLBAR);
44
45 gtk_container_add (GTK_CONTAINER(button),
46 image);
47 gtk_button_set_relief (GTK_BUTTON (button),
48 GTK_RELIEF_NONE);
49 GTK_WIDGET_UNSET_FLAGS (button,
50 GTK_CAN_FOCUS);
51
52 gtk_tooltips_set_tip (tips, button,
53 tip_str, NULL);
54
55 return button;
56 }
57
58 // utility for GtkStatusbar
statusbar_set_n_selected(GtkStatusbar * sb,guint n_selected)59 static void statusbar_set_n_selected (GtkStatusbar* sb, guint n_selected)
60 {
61 static guint last_id=0;
62 gchar* string;
63
64 if (last_id)
65 gtk_statusbar_pop (sb, last_id);
66
67 string = g_strdup_printf (_(" Selected %d files"), n_selected);
68 last_id = gtk_statusbar_get_context_id (sb, string);
69 gtk_statusbar_push (sb, last_id, string);
70 g_free (string);
71 }
72 // End of utility functions =========================================
73
74
75 // download view and store signal handler ---------------------------
76
77 // callback for gtk_tree_selection_set_select_function ()
on_download_selected(GtkTreeSelection * selection,GtkTreeModel * model,GtkTreePath * path,gboolean path_currently_selected,MainWindow * mw)78 static gboolean on_download_selected (GtkTreeSelection *selection,
79 GtkTreeModel *model,
80 GtkTreePath *path,
81 gboolean path_currently_selected,
82 MainWindow* mw)
83 {
84 GtkTreeIter iter;
85 GtkTextBuffer* textbuf;
86 Download* dl_data;
87
88 gtk_tree_model_get_iter (model, &iter, path);
89
90 textbuf = gtk_text_view_get_buffer (mw->text_view);
91 gtk_text_buffer_set_text (textbuf, "", 0);
92
93 if (mw->current_category==NULL)
94 return TRUE;
95 // if (path_currently_selected || mw->current_category==NULL)
96 // return TRUE;
97
98 gtk_tree_model_get (model, &iter,
99 DOWNLOAD_COL_DATA,
100 &dl_data,
101 -1);
102 main_window_text_view_show (mw, dl_data);
103
104 return TRUE;
105 }
106
on_download_button_event(GtkWidget * widget,GdkEventButton * event,MainWindow * mw)107 static gboolean on_download_button_event (GtkWidget* widget,
108 GdkEventButton* event,
109 MainWindow* mw)
110 {
111 if (event->type==GDK_BUTTON_PRESS && event->button==3) {
112 // press right button
113 gtk_menu_popup (mw->download_menu.self,
114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 0,
119 gtk_get_current_event_time());
120 return TRUE;
121 }
122 main_window_decide_download_sensitive (mw);
123 return FALSE;
124 }
125
on_download_store_row_changed(GtkTreeModel * treemodel,GtkTreePath * path,GtkTreeIter * iter,MainWindow * mw)126 static void on_download_store_row_changed (GtkTreeModel* treemodel,
127 GtkTreePath* path,
128 GtkTreeIter* iter,
129 MainWindow* mw)
130 {
131 main_window_text_view_decide_update (mw, path);
132 }
133 // End of download view & store signal handler ======================
134
135 // category view signal handler -------------------------------------
on_category_button_event(GtkWidget * widget,GdkEventButton * event,MainWindow * mw)136 static gboolean on_category_button_event (GtkWidget* widget,
137 GdkEventButton* event,
138 MainWindow* mw)
139 {
140 if (event->type==GDK_BUTTON_RELEASE && event->button==3) {
141 // press right button
142 gtk_menu_popup (mw->category_menu.self,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
147 0,
148 gtk_get_current_event_time());
149 return TRUE;
150 }
151 return FALSE;
152 }
153 // End of category view signal handler ==============================
154
155
156 // Menu
file_menu_init(FileMenu * fm)157 void file_menu_init (FileMenu* fm)
158 {
159 GtkWidget* image;
160
161 fm->self = (GtkMenu*)gtk_menu_new ();
162 fm->load = gtk_image_menu_item_new_with_mnemonic (_("_Load..."));
163 image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
164 gtk_image_menu_item_set_image ((GtkImageMenuItem*)fm->load, image);
165
166 fm->save = gtk_image_menu_item_new_with_mnemonic (_("_Save"));
167 image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
168 gtk_image_menu_item_set_image ((GtkImageMenuItem*)fm->save, image);
169
170 fm->save_as = gtk_image_menu_item_new_with_mnemonic (_("Save _as..."));
171 image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
172 gtk_image_menu_item_set_image ((GtkImageMenuItem*)fm->save_as, image);
173
174 fm->import_html = gtk_image_menu_item_new_with_mnemonic (_("_Import from HTML file..."));
175 image = gtk_image_new_from_stock (GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU);
176 gtk_image_menu_item_set_image ((GtkImageMenuItem*)fm->import_html, image);
177
178 fm->export = gtk_image_menu_item_new_with_mnemonic (_("_Export URL..."));
179 image = gtk_image_new_from_stock (GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU);
180 gtk_image_menu_item_set_image ((GtkImageMenuItem*)fm->export, image);
181
182 gtk_menu_append (fm->self, fm->load);
183 gtk_menu_append (fm->self, fm->save);
184 gtk_menu_append (fm->self, fm->save_as);
185 gtk_menu_append (fm->self, gtk_separator_menu_item_new() );
186 gtk_menu_append (fm->self, fm->import_html);
187 gtk_menu_append (fm->self, fm->export);
188 }
189
global_menu_init(GlobalMenu * gm)190 void global_menu_init (GlobalMenu* gm)
191 {
192 GtkWidget* image;
193
194 gm->self = (GtkMenu*)gtk_menu_new ();
195
196 gm->start_job = gtk_image_menu_item_new_with_mnemonic (_("St_art action"));
197 image = gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU);
198 gtk_image_menu_item_set_image ((GtkImageMenuItem*)gm->start_job, image);
199 gm->stop_all = gtk_image_menu_item_new_with_mnemonic (_("_Stop all"));
200 image = gtk_image_new_from_stock (GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
201 gtk_image_menu_item_set_image ((GtkImageMenuItem*)gm->stop_all, image);
202
203 gm->category_default = gtk_menu_item_new_with_mnemonic (_("_Category default..."));
204 gm->setting = gtk_menu_item_new_with_mnemonic (_("_Global Setting..."));
205
206 gtk_menu_append (gm->self, gm->start_job);
207 gtk_menu_append (gm->self, gm->stop_all);
208 gtk_menu_append (gm->self, gtk_separator_menu_item_new() );
209 gtk_menu_append (gm->self, gm->category_default);
210 gtk_menu_append (gm->self, gm->setting);
211 }
212
category_menu_init(CategoryMenu * cm)213 void category_menu_init (CategoryMenu* cm)
214 {
215 GtkWidget* image;
216
217 cm->self = (GtkMenu*)gtk_menu_new ();
218
219 cm->new_category = gtk_image_menu_item_new_with_mnemonic (_("_New"));
220 image = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
221 gtk_image_menu_item_set_image ((GtkImageMenuItem*)cm->new_category, image);
222
223 cm->erase_category = gtk_image_menu_item_new_with_mnemonic (_("_Erase"));
224 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
225 gtk_image_menu_item_set_image ((GtkImageMenuItem*)cm->erase_category, image);
226
227 cm->properties = gtk_image_menu_item_new_with_mnemonic (_("_Properties..."));
228 image = gtk_image_new_from_stock (GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU);
229 gtk_image_menu_item_set_image ((GtkImageMenuItem*)cm->properties ,image);
230
231 // menu.append( gtk_tearoff_menu_item_new() );
232 gtk_menu_append (cm->self, cm->new_category);
233 gtk_menu_append (cm->self, cm->erase_category);
234 gtk_menu_append (cm->self, cm->properties);
235 }
236
download_menu_init(DownloadMenu * dm)237 void download_menu_init (DownloadMenu* dm)
238 {
239 GtkWidget* image;
240
241 dm->self = (GtkMenu*)gtk_menu_new ();
242
243 dm->new_download = gtk_image_menu_item_new_with_mnemonic (_("_New download..."));
244 image = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
245 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->new_download, image);
246
247 dm->add_batch = gtk_image_menu_item_new_with_mnemonic (_("_Add batch download..."));
248 image = gtk_image_new_from_stock (GTK_STOCK_SORT_ASCENDING, GTK_ICON_SIZE_MENU);
249 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->add_batch, image);
250
251 dm->erase = gtk_image_menu_item_new_with_mnemonic(_("_Erase"));
252 image = gtk_image_new_from_stock(GTK_STOCK_DELETE, GTK_ICON_SIZE_MENU);
253 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->erase, image);
254
255 dm->move_to = gtk_image_menu_item_new_with_mnemonic(_("Move t_o..."));
256 image = gtk_image_new_from_stock(GTK_STOCK_DND_MULTIPLE, GTK_ICON_SIZE_MENU);
257 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->move_to, image);
258
259 dm->move_top = gtk_image_menu_item_new_with_mnemonic(_("Move _top"));
260 image = gtk_image_new_from_stock(GTK_STOCK_GOTO_TOP, GTK_ICON_SIZE_MENU);
261 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->move_top, image);
262
263 dm->move_bottom = gtk_image_menu_item_new_with_mnemonic(_("Move _bottom"));
264 image = gtk_image_new_from_stock(GTK_STOCK_GOTO_BOTTOM, GTK_ICON_SIZE_MENU);
265 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->move_bottom, image);
266
267 dm->start = gtk_image_menu_item_new_with_mnemonic(_("Start automatically"));
268 image = gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_MENU);
269 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->start, image);
270
271 dm->stop = gtk_image_menu_item_new_with_mnemonic(_("Stop"));
272 image = gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_MENU);
273 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->stop ,image);
274
275 dm->properties = gtk_image_menu_item_new_with_mnemonic(_("_Properties..."));
276 image = gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU);
277 gtk_image_menu_item_set_image ((GtkImageMenuItem*)dm->properties, image);
278
279 // menu.append( gtk_tearoff_menu_item_new() );
280 gtk_menu_append (dm->self, dm->new_download);
281 gtk_menu_append (dm->self, dm->add_batch);
282 gtk_menu_append (dm->self, dm->erase);
283 gtk_menu_append (dm->self, gtk_separator_menu_item_new() );
284 gtk_menu_append (dm->self, dm->move_to);
285 gtk_menu_append (dm->self, dm->move_top);
286 gtk_menu_append (dm->self, dm->move_bottom);
287 gtk_menu_append (dm->self, gtk_separator_menu_item_new() );
288 gtk_menu_append (dm->self, dm->start);
289 gtk_menu_append (dm->self, dm->stop);
290 gtk_menu_append (dm->self, dm->properties);
291 }
292
help_menu_init(HelpMenu * hm)293 void help_menu_init (HelpMenu* hm)
294 {
295 GtkWidget* image;
296
297 hm->self = (GtkMenu*)gtk_menu_new ();
298 hm->about_urlgfe = gtk_image_menu_item_new_with_mnemonic (_("_About UrlGfe..."));
299 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_MENU);
300 gtk_image_menu_item_set_image ((GtkImageMenuItem*)hm->about_urlgfe, image);
301
302 gtk_menu_append (hm->self, hm->about_urlgfe);
303 }
304
305
306
307 // MainWindow
main_window_init_toolbar(MainWindow * wnd,GtkWidget * hbox)308 void main_window_init_toolbar (MainWindow* wnd,
309 GtkWidget* hbox)
310 {
311 GtkTooltips* tips;
312
313 tips = gtk_tooltips_new ();
314
315 // button Start Download
316 wnd->button_start = tool_button_new (GTK_STOCK_EXECUTE,
317 _("Begin downloading"),
318 tips);
319 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_start,
320 FALSE, FALSE, 1);
321
322 // button Stop Download
323 wnd->button_stop = tool_button_new (GTK_STOCK_STOP,
324 _("Stop downloading"),
325 tips);
326 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_stop,
327 FALSE, FALSE, 1);
328
329 // button New Download
330 wnd->button_new = tool_button_new (GTK_STOCK_NEW,
331 _("Create new download"),
332 tips);
333 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_new,
334 FALSE, FALSE, 1);
335
336 // button Add batch
337 wnd->button_batch = tool_button_new (GTK_STOCK_SORT_ASCENDING,
338 _("Add batch download"),
339 tips);
340 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_batch,
341 FALSE, FALSE, 1);
342
343 // button Delete
344 wnd->button_erase = tool_button_new (GTK_STOCK_DELETE,
345 _("Delete selected jobs"),
346 tips);
347 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_erase,
348 FALSE, FALSE, 1);
349
350 // button Property
351 wnd->button_property = tool_button_new (GTK_STOCK_PROPERTIES,
352 _("Properties"),
353 tips);
354 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_property,
355 FALSE, FALSE, 1);
356
357 // button Move top
358 wnd->button_move_top = tool_button_new (GTK_STOCK_GOTO_TOP,
359 _("Move top"),
360 tips);
361 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_move_top,
362 FALSE, FALSE, 1);
363
364 // button Move bottom
365 wnd->button_move_bottom = tool_button_new (GTK_STOCK_GOTO_BOTTOM,
366 _("Move bottom"),
367 tips);
368 gtk_box_pack_start (GTK_BOX(hbox), wnd->button_move_bottom,
369 FALSE, FALSE, 1);
370
371 gtk_widget_show_all (hbox);
372 }
373
main_window_init(MainWindow * mw,CategoryStore * c_store)374 void main_window_init (MainWindow* mw, CategoryStore* c_store)
375 {
376 GtkScrolledWindow* scrolled;
377 GtkScrolledWindow* scrolled_text;
378 GtkWidget* hbox;
379 GtkWidget* menu_item;
380 GtkTextBuffer *buffer;
381
382 mw->current_category = NULL;
383 mw->current_download_view = NULL;
384 mw->category_store = c_store;
385 mw->vbox = gtk_vbox_new (FALSE, 3);
386 mw->self = (GtkWindow*)gtk_window_new (GTK_WINDOW_TOPLEVEL);
387 gtk_window_set_title (mw->self, "UrlGfe");
388 gtk_window_set_default_size (mw->self, 515, 350);
389
390 // menu bar --------------------------------------------------
391 mw->menu_bar = gtk_menu_bar_new ();
392
393 // file menu
394 file_menu_init (&mw->file_menu);
395 menu_item = gtk_menu_item_new_with_mnemonic (_("_File"));
396 gtk_menu_item_set_submenu ((GtkMenuItem*)menu_item,
397 (GtkWidget*)mw->file_menu.self);
398 gtk_menu_shell_append ((GtkMenuShell *)mw->menu_bar, menu_item);
399
400 // global menu
401 global_menu_init (&mw->global_menu);
402 menu_item = gtk_menu_item_new_with_mnemonic (_("_Global"));
403 gtk_menu_shell_append ((GtkMenuShell *)mw->menu_bar, menu_item);
404 gtk_menu_item_set_submenu ((GtkMenuItem*)menu_item,
405 (GtkWidget*)mw->global_menu.self);
406
407 // category menu
408 category_menu_init (&mw->category_menu);
409 menu_item = gtk_menu_item_new_with_mnemonic (_("_Category"));
410 gtk_menu_item_set_submenu ((GtkMenuItem*)menu_item,
411 (GtkWidget*)mw->category_menu.self);
412 gtk_menu_shell_append ((GtkMenuShell *)mw->menu_bar, menu_item);
413
414 // download menu
415 download_menu_init (&mw->download_menu);
416 menu_item = gtk_menu_item_new_with_mnemonic(_("_Download"));
417 gtk_menu_item_set_submenu ((GtkMenuItem*)menu_item,
418 (GtkWidget*)mw->download_menu.self);
419 gtk_menu_shell_append ((GtkMenuShell *)mw->menu_bar, menu_item);
420
421 // about
422 help_menu_init (&mw->help_menu);
423 menu_item = gtk_menu_item_new_with_mnemonic(_("_Help"));
424 gtk_menu_item_set_submenu ((GtkMenuItem*)menu_item,
425 (GtkWidget*)mw->help_menu.self);
426 gtk_menu_shell_append ((GtkMenuShell *)mw->menu_bar, menu_item);
427 // End of menu bar ==============================================
428
429 // category view
430 mw->category_view = category_tree_view_new (c_store);
431 gtk_tree_view_set_headers_visible (mw->category_view, FALSE);
432 g_signal_connect (mw->category_view, "button-release-event",
433 G_CALLBACK(on_category_button_event), (gpointer)mw);
434 g_signal_connect_swapped (mw->category_view,
435 "cursor-changed",
436 G_CALLBACK(main_window_selection_changed),
437 (gpointer)mw);
438 gtk_widget_set_size_request ((GtkWidget*)mw->category_view, 155, 100);
439 // create ScrolledWindow for CategoryView
440 scrolled = (GtkScrolledWindow*)gtk_scrolled_window_new (NULL, NULL);
441 gtk_scrolled_window_set_policy (scrolled,
442 GTK_POLICY_AUTOMATIC,
443 GTK_POLICY_AUTOMATIC);
444 gtk_scrolled_window_set_shadow_type (scrolled,
445 GTK_SHADOW_IN);
446 gtk_container_add (GTK_CONTAINER (scrolled),
447 GTK_WIDGET (mw->category_view));
448
449 // create and setup TextView
450 mw->text_view = (GtkTextView*)gtk_text_view_new ();
451 gtk_text_view_set_left_margin (mw->text_view, 2);
452 gtk_text_view_set_right_margin (mw->text_view, 2);
453 gtk_text_view_set_editable (mw->text_view, FALSE);
454 gtk_text_view_set_cursor_visible (mw->text_view, FALSE);
455 gtk_widget_set_size_request ((GtkWidget*)mw->text_view, 35, 35);
456 buffer = gtk_text_view_get_buffer (mw->text_view);
457 mw->text_tag = gtk_text_buffer_create_tag (buffer, "blue_foreground",
458 "foreground", "blue", NULL);
459 // create ScrolledWindow for TextView
460 scrolled_text = (GtkScrolledWindow*)gtk_scrolled_window_new (NULL, NULL);
461 gtk_scrolled_window_set_policy (scrolled_text,
462 GTK_POLICY_AUTOMATIC,
463 GTK_POLICY_AUTOMATIC);
464 gtk_scrolled_window_set_shadow_type (scrolled_text,
465 GTK_SHADOW_IN);
466 gtk_container_add (GTK_CONTAINER (scrolled_text),
467 GTK_WIDGET (mw->text_view));
468
469
470 // status bar
471 mw->statusbar = (GtkStatusbar*) gtk_statusbar_new ();
472 statusbar_set_n_selected (mw->statusbar, 0);
473
474 // toolbar
475 hbox = gtk_hbox_new (FALSE, 0);
476 main_window_init_toolbar (mw, hbox);
477 mw->vbox_download = gtk_vbox_new (FALSE, 2);
478 gtk_box_pack_start (GTK_BOX(mw->vbox_download),
479 GTK_WIDGET(hbox),
480 FALSE, FALSE, 0);
481
482 mw->hpaned = (GtkPaned*)gtk_hpaned_new ();
483 mw->vpaned = (GtkPaned*)gtk_vpaned_new ();
484
485 gtk_paned_pack1 (mw->hpaned,
486 (GtkWidget*)scrolled,
487 FALSE, TRUE);
488 gtk_paned_add2 (mw->hpaned,
489 (GtkWidget*)mw->vpaned);
490
491 gtk_paned_pack1 (mw->vpaned,
492 (GtkWidget*)mw->vbox_download,
493 TRUE, FALSE);
494 gtk_paned_add2 (mw->vpaned,
495 (GtkWidget*)scrolled_text);
496
497 gtk_box_pack_start (GTK_BOX (mw->vbox), mw->menu_bar,
498 FALSE, FALSE, 0);
499
500 gtk_box_pack_start (GTK_BOX (mw->vbox), GTK_WIDGET (mw->hpaned),
501 TRUE, TRUE, 0);
502
503 gtk_box_pack_start (GTK_BOX (mw->vbox), GTK_WIDGET (mw->statusbar),
504 FALSE, FALSE, 0);
505
506 gtk_container_add (GTK_CONTAINER (mw->self),
507 GTK_WIDGET (mw->vbox));
508
509 gtk_widget_show_all ((GtkWidget*)mw->vbox);
510 }
511
main_window_connect_download_view(MainWindow * mw,DownloadListView * dlv)512 void main_window_connect_download_view (MainWindow* mw,
513 DownloadListView* dlv)
514 {
515 GtkTreeModel* model;
516 GtkTreeSelection* selection;
517
518 model = gtk_tree_view_get_model (dlv->self);
519
520 g_signal_connect_swapped (dlv->self, "cursor-changed",
521 G_CALLBACK(main_window_decide_download_sensitive),
522 mw);
523 g_signal_connect (dlv->self, "button-press-event",
524 G_CALLBACK(on_download_button_event),
525 mw);
526 g_signal_connect (dlv->self, "button-release-event",
527 G_CALLBACK(on_download_button_event),
528 mw);
529 g_signal_connect_swapped (model, "row-deleted",
530 G_CALLBACK(main_window_decide_download_sensitive),
531 mw);
532 selection = gtk_tree_view_get_selection (dlv->self);
533
534 g_signal_connect (dlv->store->list_store, "row-changed",
535 G_CALLBACK(on_download_store_row_changed),
536 mw);
537
538 gtk_tree_selection_set_select_function (selection,
539 (GtkTreeSelectionFunc)on_download_selected,
540 mw, NULL);
541 }
542
main_window_set_download_view(MainWindow * mw,DownloadListView * dlv)543 void main_window_set_download_view (MainWindow* mw, DownloadListView* dlv)
544 {
545 GtkWidget* current_view;
546
547 if (mw->current_download_view) {
548 current_view = (GtkWidget*)mw->current_download_view->container;
549
550 g_object_ref (current_view);
551
552 gtk_container_remove ((GtkContainer*)mw->vbox_download,
553 current_view);
554 }
555 if (dlv) {
556 gtk_box_pack_start ((GtkBox*)mw->vbox_download,
557 (GtkWidget*)dlv->container,
558 TRUE, TRUE, 0);
559 }
560 mw->current_download_view = dlv;
561 main_window_text_view_update (mw);
562 }
563
main_window_update_download_view(MainWindow * mw)564 void main_window_update_download_view (MainWindow* mw)
565 {
566 if (mw->current_download_view) {
567 gtk_widget_queue_draw (GTK_WIDGET (mw->current_download_view->self));
568 }
569 }
570
main_window_decide_download_sensitive(MainWindow * window)571 void main_window_decide_download_sensitive (MainWindow* window)
572 {
573 GtkTreeSelection* selection;
574 guint n_selected;
575
576 if (window->current_download_view) {
577 selection = gtk_tree_view_get_selection (
578 window->current_download_view->self);
579
580 n_selected = gtk_tree_selection_count_selected_rows (selection);
581 statusbar_set_n_selected (window->statusbar, n_selected);
582 if (n_selected) {
583 main_window_set_download_sensitive (window, TRUE);
584 return;
585 }
586 }
587 main_window_set_download_sensitive (window, FALSE);
588 }
589
main_window_set_download_sensitive(MainWindow * mw,gboolean sens)590 void main_window_set_download_sensitive (MainWindow* mw, gboolean sens)
591 {
592 // tool button
593 gtk_widget_set_sensitive (mw->button_start, sens);
594 gtk_widget_set_sensitive (mw->button_stop, sens);
595 gtk_widget_set_sensitive (mw->button_erase, sens);
596 gtk_widget_set_sensitive (mw->button_property, sens);
597 gtk_widget_set_sensitive (mw->button_move_top, sens);
598 gtk_widget_set_sensitive (mw->button_move_bottom, sens);
599 // menu item
600 gtk_widget_set_sensitive (mw->download_menu.start, sens);
601 gtk_widget_set_sensitive (mw->download_menu.stop, sens);
602 gtk_widget_set_sensitive (mw->download_menu.erase, sens);
603 gtk_widget_set_sensitive (mw->download_menu.move_to, sens);
604 gtk_widget_set_sensitive (mw->download_menu.properties, sens);
605 gtk_widget_set_sensitive (mw->download_menu.move_top, sens);
606 gtk_widget_set_sensitive (mw->download_menu.move_bottom, sens);
607 }
608
main_window_set_category_sensitive(MainWindow * mw,gboolean sens)609 void main_window_set_category_sensitive (MainWindow* mw, gboolean sens)
610 {
611 // tool button
612 gtk_widget_set_sensitive (mw->button_new, sens);
613 gtk_widget_set_sensitive (mw->button_batch, sens);
614 // file menu item
615 gtk_widget_set_sensitive (mw->file_menu.export, sens);
616 gtk_widget_set_sensitive (mw->file_menu.import_html, sens);
617 gtk_widget_set_sensitive (mw->file_menu.save_as, sens);
618 // download menu item
619 gtk_widget_set_sensitive (mw->download_menu.new_download, sens);
620 gtk_widget_set_sensitive (mw->download_menu.add_batch, sens);
621 // category menu item
622 gtk_widget_set_sensitive (mw->category_menu.erase_category, sens);
623 gtk_widget_set_sensitive (mw->category_menu.properties, sens);
624 }
625
626 // signal "cursor-changed" connect here
main_window_selection_changed(MainWindow * window)627 void main_window_selection_changed (MainWindow* window)
628 {
629 GtkTreeIter iter;
630 GtkTreeModel* model;
631 GtkTreeSelection* selection;
632 DownloadListView* download_view;
633 gboolean had_selected;
634
635 selection = gtk_tree_view_get_selection (window->category_view);
636 had_selected = gtk_tree_selection_get_selected (selection,
637 &model,
638 &iter);
639
640 if (had_selected) {
641 gtk_tree_model_get (model,
642 &iter,
643 CATEGORY_COL_DATA,
644 &window->current_category,
645 CATEGORY_COL_DOWNLOAD_VIEW,
646 &download_view,
647 -1);
648
649 main_window_set_download_view (window, download_view);
650 // change sensitive state
651 main_window_set_category_sensitive (window, TRUE);
652 main_window_decide_download_sensitive (window);
653 }
654 else {
655 window->current_category = NULL;
656 main_window_set_category_sensitive (window, FALSE);
657 main_window_set_download_sensitive (window, FALSE);
658 }
659 }
660
main_window_text_view_update(MainWindow * mw)661 void main_window_text_view_update (MainWindow* mw)
662 {
663 GtkTextBuffer* textbuf;
664
665 textbuf = gtk_text_view_get_buffer (mw->text_view);
666 gtk_text_buffer_set_text (textbuf, "", 0);
667 main_window_text_view_decide_update (mw, NULL);
668 }
669
main_window_text_view_decide_update(MainWindow * mw,GtkTreePath * path)670 void main_window_text_view_decide_update (MainWindow* mw, GtkTreePath* path)
671 {
672 Download* dl_data;
673 GtkTreeSelection* selection;
674 GtkTreeModel* model;
675 GtkTreeIter iter;
676 GList* path_list;
677 gint n_selected;
678
679 if (mw->current_download_view == NULL)
680 return;
681
682 selection = gtk_tree_view_get_selection (mw->current_download_view->self);
683 model = gtk_tree_view_get_model (mw->current_download_view->self);
684
685 download_store_lock (mw->current_download_view->store);
686
687 n_selected = gtk_tree_selection_count_selected_rows (selection);
688
689 if (n_selected==1) {
690 path_list = gtk_tree_selection_get_selected_rows (selection, NULL);
691 if (path==NULL || gtk_tree_path_compare (path_list->data, path)==0)
692 {
693 if (gtk_tree_model_get_iter (model, &iter, path_list->data)) {
694 gtk_tree_model_get (model, &iter,
695 DOWNLOAD_COL_DATA,
696 &dl_data,
697 -1);
698 main_window_text_view_show (mw, dl_data);
699 }
700 }
701 g_list_foreach (path_list, (GFunc)gtk_tree_path_free, NULL);
702 g_list_free (path_list);
703 }
704 download_store_unlock (mw->current_download_view->store);
705 }
706
main_window_text_view_show(MainWindow * mw,Download * dl_data)707 void main_window_text_view_show (MainWindow* mw, Download* dl_data)
708 {
709 GtkTextBuffer* textbuf;
710 DownloadSetting* setting = DOWNLOAD_SETTING (dl_data);
711
712 textbuf = gtk_text_view_get_buffer (mw->text_view);
713 gtk_text_buffer_set_text (textbuf, "", 0);
714
715 if (dl_data==NULL)
716 return;
717
718 if (CATEGORY_SETTING (mw->current_category)->text_filename) {
719 text_buffer_add_text (textbuf, mw->text_tag,
720 _("Filename : "), setting->filename);
721 }
722 if (CATEGORY_SETTING (mw->current_category)->text_directory) {
723 text_buffer_add_text (textbuf, mw->text_tag,
724 _("Directory : "), setting->directory);
725 }
726 if (CATEGORY_SETTING (mw->current_category)->text_url) {
727 text_buffer_add_text (textbuf, mw->text_tag,
728 _("URL : "), setting->url);
729 }
730 if (CATEGORY_SETTING (mw->current_category)->text_message) {
731 text_buffer_add_text (textbuf, mw->text_tag,
732 _("Last Message : "),
733 (dl_data->message) ? dl_data->message : _("None"));
734 }
735 }
736
main_window_on_category_erasing(MainWindow * mw,Category * erasing)737 void main_window_on_category_erasing (MainWindow* mw, Category* erasing)
738 {
739 Category* next_category;
740 DownloadListView* dlv = NULL;
741 GtkTreeSelection* selection;
742
743 next_category = category_store_get_next (mw->category_store, erasing);
744
745 if (next_category) {
746 selection = gtk_tree_view_get_selection (mw->category_view);
747 gtk_tree_selection_select_iter (selection, &next_category->iter_tree_store);
748 dlv = &next_category->waiting_view;
749 }
750
751 main_window_set_download_view (mw, dlv);
752 }
753
754