1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * GThumb
5 *
6 * Copyright (C) 2010 Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23 #include <glib/gi18n.h>
24 #include "dlg-location.h"
25 #include "dlg-personalize-filters.h"
26 #include "dlg-preferences.h"
27 #include "dlg-sort-order.h"
28 #include "glib-utils.h"
29 #include "gth-browser.h"
30 #include "gth-browser-actions-callbacks.h"
31 #include "gth-file-list.h"
32 #include "gth-file-selection.h"
33 #include "gth-folder-tree.h"
34 #include "gth-main.h"
35 #include "gth-preferences.h"
36 #include "gth-shortcuts-window.h"
37 #include "gth-sidebar.h"
38 #include "gtk-utils.h"
39 #include "gth-viewer-page.h"
40 #include "main.h"
41
42
43 void
gth_browser_activate_new_window(GSimpleAction * action,GVariant * parameter,gpointer user_data)44 gth_browser_activate_new_window (GSimpleAction *action,
45 GVariant *parameter,
46 gpointer user_data)
47 {
48 GtkWidget *browser = user_data;
49 GtkWidget *window;
50
51 window = gth_browser_new (gth_browser_get_location (GTH_BROWSER (browser)), NULL);
52 gtk_window_present (GTK_WINDOW (window));
53 }
54
55
56 void
gth_browser_activate_preferences(GSimpleAction * action,GVariant * parameter,gpointer user_data)57 gth_browser_activate_preferences (GSimpleAction *action,
58 GVariant *parameter,
59 gpointer user_data)
60 {
61 dlg_preferences (GTH_BROWSER (user_data));
62 }
63
64
65 void
gth_browser_activate_show_help(GSimpleAction * action,GVariant * parameter,gpointer user_data)66 gth_browser_activate_show_help (GSimpleAction *action,
67 GVariant *parameter,
68 gpointer user_data)
69 {
70 show_help_dialog (GTK_WINDOW (user_data), NULL);
71 }
72
73
74 void
gth_browser_activate_show_shortcuts(GSimpleAction * action,GVariant * parameter,gpointer user_data)75 gth_browser_activate_show_shortcuts (GSimpleAction *action,
76 GVariant *parameter,
77 gpointer user_data)
78 {
79 gth_shortcuts_window_new (GTH_WINDOW (user_data));
80 }
81
82
83 void
gth_browser_activate_about(GSimpleAction * action,GVariant * parameter,gpointer user_data)84 gth_browser_activate_about (GSimpleAction *action,
85 GVariant *parameter,
86 gpointer user_data)
87 {
88 GthBrowser *browser = user_data;
89 const char *authors[] = {
90 #include "AUTHORS.tab"
91 NULL
92 };
93 const char *documenters [] = {
94 "Paolo Bacchilega",
95 "Alexander Kirillov",
96 NULL
97 };
98 char *license_text;
99 const char *license[] = {
100 N_("gThumb is free software; you can redistribute it and/or modify "
101 "it under the terms of the GNU General Public License as published by "
102 "the Free Software Foundation; either version 2 of the License, or "
103 "(at your option) any later version."),
104 N_("gThumb is distributed in the hope that it will be useful, "
105 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
106 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
107 "GNU General Public License for more details."),
108 N_("You should have received a copy of the GNU General Public License "
109 "along with gThumb. If not, see http://www.gnu.org/licenses/.")
110 };
111 GdkPixbuf *logo;
112
113 license_text = g_strconcat (_(license[0]), "\n\n",
114 _(license[1]), "\n\n",
115 _(license[2]),
116 NULL);
117
118 logo = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (browser))),
119 "org.gnome.gThumb",
120 128,
121 0,
122 NULL);
123
124 gtk_show_about_dialog (GTK_WINDOW (browser),
125 "version", PACKAGE_VERSION,
126 "copyright", "Copyright \xc2\xa9 2001-2020 Free Software Foundation, Inc.",
127 "comments", _("An image viewer and browser for GNOME."),
128 "authors", authors,
129 "documenters", documenters,
130 "translator-credits", _("translator-credits"),
131 "license", license_text,
132 "wrap-license", TRUE,
133 "website", "https://wiki.gnome.org/Apps/Gthumb",
134 (logo != NULL ? "logo" : NULL), logo,
135 NULL);
136
137 _g_object_unref (logo);
138 g_free (license_text);
139 }
140
141
142 void
gth_browser_activate_quit(GSimpleAction * action,GVariant * parameter,gpointer user_data)143 gth_browser_activate_quit (GSimpleAction *action,
144 GVariant *parameter,
145 gpointer user_data)
146 {
147 gth_quit (FALSE);
148 }
149
150
151 void
gth_browser_activate_browser_mode(GSimpleAction * action,GVariant * parameter,gpointer user_data)152 gth_browser_activate_browser_mode (GSimpleAction *action,
153 GVariant *parameter,
154 gpointer user_data)
155 {
156 GthBrowser *browser = user_data;
157 GtkWidget *viewer_sidebar;
158
159 gth_browser_stop (browser);
160
161 viewer_sidebar = gth_browser_get_viewer_sidebar (browser);
162 if (gth_sidebar_tool_is_active (GTH_SIDEBAR (viewer_sidebar)))
163 gth_sidebar_deactivate_tool (GTH_SIDEBAR (viewer_sidebar));
164 else if (gth_browser_get_is_fullscreen (browser))
165 gth_browser_unfullscreen (browser);
166 else
167 gth_window_set_current_page (GTH_WINDOW (browser), GTH_BROWSER_PAGE_BROWSER);
168 }
169
170
171 void
gth_browser_activate_browser_edit_file(GSimpleAction * action,GVariant * parameter,gpointer user_data)172 gth_browser_activate_browser_edit_file (GSimpleAction *action,
173 GVariant *parameter,
174 gpointer user_data)
175 {
176 gth_browser_show_viewer_tools (GTH_BROWSER (user_data));
177 }
178
179
180 void
gth_browser_activate_browser_properties(GSimpleAction * action,GVariant * state,gpointer user_data)181 gth_browser_activate_browser_properties (GSimpleAction *action,
182 GVariant *state,
183 gpointer user_data)
184 {
185 GthBrowser *browser = user_data;
186
187 g_simple_action_set_state (action, state);
188 if (g_variant_get_boolean (state))
189 gth_browser_show_file_properties (GTH_BROWSER (browser));
190 else
191 gth_browser_hide_sidebar (GTH_BROWSER (browser));
192 }
193
194
195 void
gth_browser_activate_clear_history(GSimpleAction * action,GVariant * parameter,gpointer user_data)196 gth_browser_activate_clear_history (GSimpleAction *action,
197 GVariant *parameter,
198 gpointer user_data)
199 {
200 gth_browser_clear_history (GTH_BROWSER (user_data));
201 }
202
203
204 void
gth_browser_activate_close(GSimpleAction * action,GVariant * parameter,gpointer user_data)205 gth_browser_activate_close (GSimpleAction *action,
206 GVariant *parameter,
207 gpointer user_data)
208 {
209 GthBrowser *browser = user_data;
210
211 gth_window_close (GTH_WINDOW (browser));
212 }
213
214
215 void
gth_browser_activate_fullscreen(GSimpleAction * action,GVariant * parameter,gpointer user_data)216 gth_browser_activate_fullscreen (GSimpleAction *action,
217 GVariant *parameter,
218 gpointer user_data)
219 {
220 gth_browser_fullscreen (GTH_BROWSER (user_data));
221 }
222
223
224 void
gth_browser_activate_go_back(GSimpleAction * action,GVariant * parameter,gpointer user_data)225 gth_browser_activate_go_back (GSimpleAction *action,
226 GVariant *parameter,
227 gpointer user_data)
228 {
229 gth_browser_go_back (GTH_BROWSER (user_data), 1);
230 }
231
232
233 void
gth_browser_activate_go_forward(GSimpleAction * action,GVariant * parameter,gpointer user_data)234 gth_browser_activate_go_forward (GSimpleAction *action,
235 GVariant *parameter,
236 gpointer user_data)
237 {
238 gth_browser_go_forward (GTH_BROWSER (user_data), 1);
239 }
240
241
242 void
gth_browser_activate_go_to_history_pos(GSimpleAction * action,GVariant * parameter,gpointer user_data)243 gth_browser_activate_go_to_history_pos (GSimpleAction *action,
244 GVariant *parameter,
245 gpointer user_data)
246 {
247 gth_browser_go_to_history_pos (GTH_BROWSER (user_data), atoi (g_variant_get_string (parameter, NULL)));
248 }
249
250
251 void
gth_browser_activate_go_to_location(GSimpleAction * action,GVariant * parameter,gpointer user_data)252 gth_browser_activate_go_to_location (GSimpleAction *action,
253 GVariant *parameter,
254 gpointer user_data)
255 {
256 GFile *file;
257
258 file = g_file_new_for_uri (g_variant_get_string (parameter, NULL));
259 gth_browser_go_to (GTH_BROWSER (user_data), file, NULL);
260
261 g_object_unref (file);
262 }
263
264
265 void
gth_browser_activate_go_home(GSimpleAction * action,GVariant * parameter,gpointer user_data)266 gth_browser_activate_go_home (GSimpleAction *action,
267 GVariant *parameter,
268 gpointer user_data)
269 {
270 gth_browser_go_home (GTH_BROWSER (user_data));
271 }
272
273
274 void
gth_browser_activate_go_up(GSimpleAction * action,GVariant * parameter,gpointer user_data)275 gth_browser_activate_go_up (GSimpleAction *action,
276 GVariant *parameter,
277 gpointer user_data)
278 {
279 gth_browser_go_up (GTH_BROWSER (user_data), 1);
280 }
281
282
283 void
gth_browser_activate_reload(GSimpleAction * action,GVariant * parameter,gpointer user_data)284 gth_browser_activate_reload (GSimpleAction *action,
285 GVariant *parameter,
286 gpointer user_data)
287 {
288 gth_browser_reload (GTH_BROWSER (user_data));
289 }
290
291
292 void
gth_browser_activate_open_location(GSimpleAction * action,GVariant * parameter,gpointer user_data)293 gth_browser_activate_open_location (GSimpleAction *action,
294 GVariant *parameter,
295 gpointer user_data)
296 {
297 dlg_location (GTH_BROWSER (user_data));
298 }
299
300
301 void
gth_browser_activate_revert_to_saved(GSimpleAction * action,GVariant * parameter,gpointer user_data)302 gth_browser_activate_revert_to_saved (GSimpleAction *action,
303 GVariant *parameter,
304 gpointer user_data)
305 {
306 GthBrowser *browser = user_data;
307 GthViewerPage *viewer_page;
308
309 viewer_page = gth_browser_get_viewer_page (browser);
310 if (viewer_page == NULL)
311 return;
312
313 gth_viewer_page_revert (viewer_page);
314 }
315
316
317 void
gth_browser_activate_save(GSimpleAction * action,GVariant * parameter,gpointer user_data)318 gth_browser_activate_save (GSimpleAction *action,
319 GVariant *parameter,
320 gpointer user_data)
321 {
322 GthBrowser *browser = user_data;
323 GthViewerPage *viewer_page;
324
325 viewer_page = gth_browser_get_viewer_page (browser);
326 if (viewer_page == NULL)
327 return;
328
329 gth_viewer_page_save (viewer_page, NULL, NULL, browser);
330 }
331
332
333 void
gth_browser_activate_save_as(GSimpleAction * action,GVariant * parameter,gpointer user_data)334 gth_browser_activate_save_as (GSimpleAction *action,
335 GVariant *parameter,
336 gpointer user_data)
337 {
338 GthBrowser *browser = user_data;
339 GthViewerPage *viewer_page;
340
341 viewer_page = gth_browser_get_viewer_page (browser);
342 if (viewer_page == NULL)
343 return;
344
345 gth_viewer_page_save_as (viewer_page, NULL, NULL);
346 }
347
348
349 void
gth_browser_activate_toggle_edit_file(GSimpleAction * action,GVariant * state,gpointer user_data)350 gth_browser_activate_toggle_edit_file (GSimpleAction *action,
351 GVariant *state,
352 gpointer user_data)
353 {
354 GthBrowser *browser = user_data;
355 gth_browser_toggle_viewer_tools (browser);
356 }
357
358
359 void
gth_browser_activate_toggle_file_properties(GSimpleAction * action,GVariant * state,gpointer user_data)360 gth_browser_activate_toggle_file_properties (GSimpleAction *action,
361 GVariant *state,
362 gpointer user_data)
363 {
364 GthBrowser *browser = user_data;
365 gth_browser_toggle_file_properties (browser);
366 }
367
368
369 void
gth_browser_activate_viewer_edit_file(GSimpleAction * action,GVariant * state,gpointer user_data)370 gth_browser_activate_viewer_edit_file (GSimpleAction *action,
371 GVariant *state,
372 gpointer user_data)
373 {
374 GthBrowser *browser = user_data;
375
376 g_simple_action_set_state (action, state);
377 if (g_variant_get_boolean (state))
378 gth_browser_show_viewer_tools (browser);
379 else
380 gth_browser_hide_sidebar (browser);
381 }
382
383
384 void
gth_browser_activate_viewer_properties(GSimpleAction * action,GVariant * state,gpointer user_data)385 gth_browser_activate_viewer_properties (GSimpleAction *action,
386 GVariant *state,
387 gpointer user_data)
388 {
389 GthBrowser *browser = user_data;
390
391 g_simple_action_set_state (action, state);
392 if (g_variant_get_boolean (state))
393 gth_browser_show_file_properties (browser);
394 else
395 gth_browser_hide_sidebar (browser);
396 }
397
398
399 void
gth_browser_activate_unfullscreen(GSimpleAction * action,GVariant * parameter,gpointer user_data)400 gth_browser_activate_unfullscreen (GSimpleAction *action,
401 GVariant *parameter,
402 gpointer user_data)
403 {
404 gth_browser_unfullscreen (GTH_BROWSER (user_data));
405 }
406
407
408 void
gth_browser_activate_open_folder_in_new_window(GSimpleAction * action,GVariant * parameter,gpointer user_data)409 gth_browser_activate_open_folder_in_new_window (GSimpleAction *action,
410 GVariant *parameter,
411 gpointer user_data)
412 {
413 GthBrowser *browser = GTH_BROWSER (user_data);
414 GthFileData *file_data;
415 GtkWidget *new_browser;
416
417 file_data = gth_browser_get_folder_popup_file_data (browser);
418 if (file_data == NULL)
419 return;
420
421 new_browser = gth_browser_new (file_data->file, NULL);
422 gtk_window_present (GTK_WINDOW (new_browser));
423
424 g_object_unref (file_data);
425 }
426
427
428 void
gth_browser_activate_show_hidden_files(GSimpleAction * action,GVariant * state,gpointer user_data)429 gth_browser_activate_show_hidden_files (GSimpleAction *action,
430 GVariant *state,
431 gpointer user_data)
432 {
433 GSettings *settings;
434
435 g_simple_action_set_state (action, state);
436
437 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
438 g_settings_set_boolean (settings, PREF_BROWSER_SHOW_HIDDEN_FILES, g_variant_get_boolean (state));
439 g_object_unref (settings);
440 }
441
442
443 void
gth_browser_activate_sort_by(GSimpleAction * action,GVariant * parameter,gpointer user_data)444 gth_browser_activate_sort_by (GSimpleAction *action,
445 GVariant *parameter,
446 gpointer user_data)
447 {
448 dlg_sort_order (GTH_BROWSER (user_data));
449 }
450
451
452 void
gth_browser_activate_show_statusbar(GSimpleAction * action,GVariant * state,gpointer user_data)453 gth_browser_activate_show_statusbar (GSimpleAction *action,
454 GVariant *state,
455 gpointer user_data)
456 {
457 GSettings *settings;
458
459 g_simple_action_set_state (action, state);
460
461 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
462 g_settings_set_boolean (settings, PREF_BROWSER_STATUSBAR_VISIBLE, g_variant_get_boolean (state));
463 g_object_unref (settings);
464 }
465
466
467 void
gth_browser_activate_toggle_statusbar(GSimpleAction * action,GVariant * state,gpointer user_data)468 gth_browser_activate_toggle_statusbar (GSimpleAction *action,
469 GVariant *state,
470 gpointer user_data)
471 {
472 GSettings *settings;
473
474 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
475 g_settings_set_boolean (settings, PREF_BROWSER_STATUSBAR_VISIBLE, ! g_settings_get_boolean (settings, PREF_BROWSER_STATUSBAR_VISIBLE));
476 g_object_unref (settings);
477 }
478
479
480 void
gth_browser_activate_show_sidebar(GSimpleAction * action,GVariant * state,gpointer user_data)481 gth_browser_activate_show_sidebar (GSimpleAction *action,
482 GVariant *state,
483 gpointer user_data)
484 {
485 GSettings *settings;
486
487 g_simple_action_set_state (action, state);
488
489 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
490 g_settings_set_boolean (settings, PREF_BROWSER_SIDEBAR_VISIBLE, g_variant_get_boolean (state));
491 g_object_unref (settings);
492 }
493
494
495 void
gth_browser_activate_toggle_sidebar(GSimpleAction * action,GVariant * state,gpointer user_data)496 gth_browser_activate_toggle_sidebar (GSimpleAction *action,
497 GVariant *state,
498 gpointer user_data)
499 {
500 GSettings *settings;
501
502 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
503 g_settings_set_boolean (settings, PREF_BROWSER_SIDEBAR_VISIBLE, ! g_settings_get_boolean (settings, PREF_BROWSER_SIDEBAR_VISIBLE));
504 g_object_unref (settings);
505 }
506
507
508 void
gth_browser_activate_show_thumbnail_list(GSimpleAction * action,GVariant * state,gpointer user_data)509 gth_browser_activate_show_thumbnail_list (GSimpleAction *action,
510 GVariant *state,
511 gpointer user_data)
512 {
513 GSettings *settings;
514
515 g_simple_action_set_state (action, state);
516
517 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
518 g_settings_set_boolean (settings, PREF_BROWSER_THUMBNAIL_LIST_VISIBLE, g_variant_get_boolean (state));
519 g_object_unref (settings);
520 }
521
522
523 void
gth_browser_activate_toggle_thumbnail_list(GSimpleAction * action,GVariant * state,gpointer user_data)524 gth_browser_activate_toggle_thumbnail_list (GSimpleAction *action,
525 GVariant *state,
526 gpointer user_data)
527 {
528 GSettings *settings;
529
530 settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
531 g_settings_set_boolean (settings, PREF_BROWSER_THUMBNAIL_LIST_VISIBLE, ! g_settings_get_boolean (settings, PREF_BROWSER_THUMBNAIL_LIST_VISIBLE));
532 g_object_unref (settings);
533 }
534
535
536 void
gth_browser_activate_show_first_image(GSimpleAction * action,GVariant * state,gpointer user_data)537 gth_browser_activate_show_first_image (GSimpleAction *action,
538 GVariant *state,
539 gpointer user_data)
540 {
541 GthBrowser *browser = GTH_BROWSER (user_data);
542 gth_browser_show_first_image (browser, FALSE, FALSE);
543 }
544
545
546 void
gth_browser_activate_show_last_image(GSimpleAction * action,GVariant * state,gpointer user_data)547 gth_browser_activate_show_last_image (GSimpleAction *action,
548 GVariant *state,
549 gpointer user_data)
550 {
551 GthBrowser *browser = GTH_BROWSER (user_data);
552 gth_browser_show_last_image (browser, FALSE, FALSE);
553 }
554
555
556 void
gth_browser_activate_show_previous_image(GSimpleAction * action,GVariant * state,gpointer user_data)557 gth_browser_activate_show_previous_image (GSimpleAction *action,
558 GVariant *state,
559 gpointer user_data)
560 {
561 GthBrowser *browser = GTH_BROWSER (user_data);
562 gth_browser_show_prev_image (browser, FALSE, FALSE);
563 }
564
565
566 void
gth_browser_activate_show_next_image(GSimpleAction * action,GVariant * state,gpointer user_data)567 gth_browser_activate_show_next_image (GSimpleAction *action,
568 GVariant *state,
569 gpointer user_data)
570 {
571 GthBrowser *browser = GTH_BROWSER (user_data);
572 gth_browser_show_next_image (browser, FALSE, FALSE);
573 }
574
575
576 void
gth_browser_activate_apply_editor_changes(GSimpleAction * action,GVariant * state,gpointer user_data)577 gth_browser_activate_apply_editor_changes (GSimpleAction *action,
578 GVariant *state,
579 gpointer user_data)
580 {
581 GthBrowser *browser = GTH_BROWSER (user_data);
582 gth_browser_apply_editor_changes (browser);
583 }
584
585
586 void
gth_browser_activate_select_all(GSimpleAction * action,GVariant * state,gpointer user_data)587 gth_browser_activate_select_all (GSimpleAction *action,
588 GVariant *state,
589 gpointer user_data)
590 {
591 GthBrowser *browser = GTH_BROWSER (user_data);
592 GtkWidget *file_view;
593
594 file_view = gth_browser_get_file_list_view (browser);
595 gth_file_selection_select_all (GTH_FILE_SELECTION (file_view));
596 }
597
598
599 void
gth_browser_activate_unselect_all(GSimpleAction * action,GVariant * state,gpointer user_data)600 gth_browser_activate_unselect_all (GSimpleAction *action,
601 GVariant *state,
602 gpointer user_data)
603 {
604 GthBrowser *browser = GTH_BROWSER (user_data);
605 GtkWidget *file_view;
606
607 file_view = gth_browser_get_file_list_view (browser);
608 gth_file_selection_unselect_all (GTH_FILE_SELECTION (file_view));
609 }
610
611
612 void
gth_browser_activate_show_menu(GSimpleAction * action,GVariant * state,gpointer user_data)613 gth_browser_activate_show_menu (GSimpleAction *action,
614 GVariant *state,
615 gpointer user_data)
616 {
617 gth_browser_show_menu (GTH_BROWSER (user_data));
618 }
619