gth-browser-actions-callbacks.c 13.3 KB
Newer Older
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1 2 3 4 5
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  GThumb
 *
6
 *  Copyright (C) 2010 Free Software Foundation, Inc.
Paolo Bacchilega's avatar
Paolo Bacchilega committed
7 8 9 10 11 12 13 14 15 16 17 18
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  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/>.
Paolo Bacchilega's avatar
Paolo Bacchilega committed
20 21 22 23
 */

#include <config.h>
#include <glib/gi18n.h>
24
#include "dlg-location.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
25 26 27 28 29
#include "dlg-personalize-filters.h"
#include "dlg-preferences.h"
#include "dlg-sort-order.h"
#include "glib-utils.h"
#include "gth-browser.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
30
#include "gth-browser-actions-callbacks.h"
31
#include "gth-file-list.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
32
#include "gth-file-selection.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
33
#include "gth-folder-tree.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
34 35
#include "gth-main.h"
#include "gth-preferences.h"
36
#include "gth-sidebar.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
37
#include "gtk-utils.h"
38
#include "gth-viewer-page.h"
39
#include "main.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
40 41


Paolo Bacchilega's avatar
Paolo Bacchilega committed
42
static GtkWidget *
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
_gth_application_get_current_window (GApplication *application)
{
        GList *windows;

        windows = gtk_application_get_windows (GTK_APPLICATION (application));
        if (windows == NULL)
        	return NULL;

        return GTK_WIDGET (windows->data);
}


void
gth_application_activate_new_window (GSimpleAction *action,
				     GVariant      *parameter,
				     gpointer       user_data)
{
        GApplication *application = user_data;
        GtkWidget    *browser;
        GtkWidget    *window;

        browser = _gth_application_get_current_window (application);
        window = gth_browser_new (gth_browser_get_location (GTH_BROWSER (browser)), NULL);
        gtk_window_present (GTK_WINDOW (window));
}


void
gth_application_activate_preferences (GSimpleAction *action,
				      GVariant      *parameter,
				      gpointer       user_data)
{
        GApplication *application = user_data;
        GtkWidget    *browser;

        browser = _gth_application_get_current_window (application);
        dlg_preferences (GTH_BROWSER (browser));
}


void
gth_application_activate_show_help (GSimpleAction *action,
				    GVariant      *parameter,
				    gpointer       user_data)
{
        GApplication *application = user_data;
        GtkWidget    *browser;

        browser = _gth_application_get_current_window (application);
        show_help_dialog (GTK_WINDOW (browser), NULL);
}


void
gth_application_activate_show_shortcuts (GSimpleAction *action,
					 GVariant      *parameter,
					 gpointer       user_data)
{
        GApplication *application = user_data;
        GtkWidget    *browser;

        browser = _gth_application_get_current_window (application);
        show_help_dialog (GTK_WINDOW (browser), "gthumb-shortcuts");
}


void
gth_application_activate_about (GSimpleAction *action,
				GVariant      *parameter,
				gpointer       user_data)
{
        GApplication *application = user_data;
	GthWindow    *window;
	const char   *authors[] = {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
117 118 119
#include "AUTHORS.tab"
		NULL
	};
120
	const char   *documenters [] = {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
121 122 123 124 125 126
		"Paolo Bacchilega",
		"Alexander Kirillov",
		NULL
	};
	char       *license_text;
	const char *license[] = {
127
		N_("gThumb is free software; you can redistribute it and/or modify "
Paolo Bacchilega's avatar
Paolo Bacchilega committed
128 129
		"it under the terms of the GNU General Public License as published by "
		"the Free Software Foundation; either version 2 of the License, or "
130
		"(at your option) any later version."),
131
		N_("gThumb is distributed in the hope that it will be useful, "
Paolo Bacchilega's avatar
Paolo Bacchilega committed
132 133
		"but WITHOUT ANY WARRANTY; without even the implied warranty of "
		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
134 135
		"GNU General Public License for more details."),
		N_("You should have received a copy of the GNU General Public License "
136
		"along with gThumb.  If not, see http://www.gnu.org/licenses/.")
Paolo Bacchilega's avatar
Paolo Bacchilega committed
137
	};
138
	GdkPixbuf *logo;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
139

140
	window = (GthWindow *) _gth_application_get_current_window (application);
141 142 143 144
	license_text = g_strconcat (_(license[0]), "\n\n",
				    _(license[1]), "\n\n",
				    _(license[2]),
				    NULL);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
145

146
	logo = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
147
					 "org.gnome.gThumb",
148
					 128,
149
					 0,
150 151
					 NULL);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
152
	gtk_show_about_dialog (GTK_WINDOW (window),
Paolo Bacchilega's avatar
Paolo Bacchilega committed
153
			       "version", PACKAGE_VERSION,
154
			       "copyright", "Copyright \xc2\xa9 2001-2013 Free Software Foundation, Inc.",
Paolo Bacchilega's avatar
Paolo Bacchilega committed
155 156 157
			       "comments", _("An image viewer and browser for GNOME."),
			       "authors", authors,
			       "documenters", documenters,
Piotr Drąg's avatar
Piotr Drąg committed
158
			       "translator-credits", _("translator-credits"),
Paolo Bacchilega's avatar
Paolo Bacchilega committed
159 160
			       "license", license_text,
			       "wrap-license", TRUE,
161
			       "website", "https://wiki.gnome.org/Apps/Gthumb",
162
			       (logo != NULL ? "logo" : NULL), logo,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
163 164
			       NULL);

165
	_g_object_unref (logo);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
166 167 168 169 170
	g_free (license_text);
}


void
171 172 173
gth_application_activate_quit (GSimpleAction *action,
			       GVariant      *parameter,
			       gpointer       user_data)
Paolo Bacchilega's avatar
Paolo Bacchilega committed
174
{
175 176
        GApplication *application = user_data;
        GList        *windows;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
177

178 179 180
        windows = gtk_application_get_windows (GTK_APPLICATION (application));
        if (windows != NULL)
        	gth_quit (FALSE);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
181
}
182 183 184


void
185 186 187
gth_browser_activate_browser_mode (GSimpleAction *action,
				   GVariant      *parameter,
				   gpointer       user_data)
188 189
{
	GthBrowser *browser = user_data;
190
	GtkWidget  *viewer_sidebar;
191

192 193
	gth_browser_stop (browser);

194 195 196 197 198 199
	viewer_sidebar = gth_browser_get_viewer_sidebar (browser);
	if (gth_sidebar_tool_is_active (GTH_SIDEBAR (viewer_sidebar)))
		gth_sidebar_deactivate_tool (GTH_SIDEBAR (viewer_sidebar));
	else
		gth_window_set_current_page (GTH_WINDOW (browser), GTH_BROWSER_PAGE_BROWSER);
}
200

201

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
void
gth_browser_activate_browser_edit_file (GSimpleAction *action,
					GVariant      *parameter,
					gpointer       user_data)
{
	gth_browser_show_viewer_tools (GTH_BROWSER (user_data));
}


void
gth_browser_activate_browser_properties (GSimpleAction *action,
					 GVariant      *state,
					 gpointer       user_data)
{
	GthBrowser *browser = user_data;

	g_simple_action_set_state (action, state);
	if (g_variant_get_boolean (state))
		gth_browser_show_file_properties (GTH_BROWSER (browser));
	else
		gth_browser_hide_sidebar (GTH_BROWSER (browser));
}


226 227 228 229 230 231
void
gth_browser_activate_clear_history (GSimpleAction *action,
				    GVariant      *parameter,
				    gpointer       user_data)
{
	gth_browser_clear_history (GTH_BROWSER (user_data));
232 233 234 235
}


void
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
gth_browser_activate_close (GSimpleAction *action,
			    GVariant      *parameter,
			    gpointer       user_data)
{
	GthBrowser *browser = user_data;

	gth_window_close (GTH_WINDOW (browser));
}


void
gth_browser_activate_fullscreen (GSimpleAction *action,
				 GVariant      *parameter,
				 gpointer       user_data)
{
	gth_browser_fullscreen (GTH_BROWSER (user_data));
}


void
gth_browser_activate_go_back (GSimpleAction *action,
257 258 259
			      GVariant      *parameter,
			      gpointer       user_data)
{
260 261
	gth_browser_go_back (GTH_BROWSER (user_data), 1);
}
262 263


264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
void
gth_browser_activate_go_forward (GSimpleAction *action,
			         GVariant      *parameter,
			         gpointer       user_data)
{
	gth_browser_go_forward (GTH_BROWSER (user_data), 1);
}


void
gth_browser_activate_go_to_history_pos (GSimpleAction *action,
					GVariant      *parameter,
					gpointer       user_data)
{
	gth_browser_go_to_history_pos (GTH_BROWSER (user_data), atoi (g_variant_get_string (parameter, NULL)));
}


282 283 284 285 286 287 288 289 290 291 292 293 294 295
void
gth_browser_activate_go_to_location (GSimpleAction *action,
				     GVariant      *parameter,
				     gpointer       user_data)
{
	GFile *file;

	file = g_file_new_for_uri (g_variant_get_string (parameter, NULL));
	gth_browser_go_to (GTH_BROWSER (user_data), file, NULL);

	g_object_unref (file);
}


296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
void
gth_browser_activate_go_home (GSimpleAction *action,
			      GVariant      *parameter,
			      gpointer       user_data)
{
	gth_browser_go_home (GTH_BROWSER (user_data));
}


void
gth_browser_activate_go_up (GSimpleAction *action,
			    GVariant      *parameter,
			    gpointer       user_data)
{
	gth_browser_go_up (GTH_BROWSER (user_data), 1);
}


314 315 316 317 318 319 320 321 322
void
gth_browser_activate_reload (GSimpleAction *action,
			     GVariant      *parameter,
			     gpointer       user_data)
{
	gth_browser_reload (GTH_BROWSER (user_data));
}


323
void
324 325 326
gth_browser_activate_open_location (GSimpleAction *action,
				    GVariant      *parameter,
				    gpointer       user_data)
327
{
328
	dlg_location (GTH_BROWSER (user_data));
329 330 331 332 333 334 335 336
}


void
gth_browser_activate_revert_to_saved (GSimpleAction *action,
				      GVariant      *parameter,
				      gpointer       user_data)
{
337 338
	GthBrowser    *browser = user_data;
	GthViewerPage *viewer_page;
339 340 341 342 343

	viewer_page = gth_browser_get_viewer_page (browser);
	if (viewer_page == NULL)
		return;

344
	gth_viewer_page_revert (viewer_page);
345 346
}

347

348
void
349 350 351
gth_browser_activate_save (GSimpleAction *action,
			   GVariant      *parameter,
			   gpointer       user_data)
352
{
353 354
	GthBrowser    *browser = user_data;
	GthViewerPage *viewer_page;
355

356 357 358 359
	viewer_page = gth_browser_get_viewer_page (browser);
	if (viewer_page == NULL)
		return;

360
	gth_viewer_page_save (viewer_page, NULL, NULL, browser);
361 362 363 364
}


void
365 366 367
gth_browser_activate_save_as (GSimpleAction *action,
			      GVariant      *parameter,
			      gpointer       user_data)
368
{
369 370
	GthBrowser    *browser = user_data;
	GthViewerPage *viewer_page;
371 372 373 374 375

	viewer_page = gth_browser_get_viewer_page (browser);
	if (viewer_page == NULL)
		return;

376
	gth_viewer_page_save_as (viewer_page, NULL, NULL);
377
}
378

379

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
void
gth_browser_activate_viewer_edit_file (GSimpleAction *action,
				       GVariant      *state,
				       gpointer       user_data)
{
	GthBrowser *browser = user_data;

	g_simple_action_set_state (action, state);
	if (g_variant_get_boolean (state))
		gth_browser_show_viewer_tools (browser);
	else
		gth_browser_hide_sidebar (browser);
}


void
gth_browser_activate_viewer_properties (GSimpleAction *action,
				        GVariant      *state,
				        gpointer       user_data)
{
	GthBrowser *browser = user_data;

	g_simple_action_set_state (action, state);
	if (g_variant_get_boolean (state))
		gth_browser_show_file_properties (browser);
	else
		gth_browser_hide_sidebar (browser);
}


410 411 412 413 414 415
void
gth_browser_activate_unfullscreen (GSimpleAction *action,
				   GVariant      *parameter,
				   gpointer       user_data)
{
	gth_browser_unfullscreen (GTH_BROWSER (user_data));
416
}
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436


void
gth_browser_activate_open_folder_in_new_window (GSimpleAction *action,
						GVariant      *parameter,
						gpointer       user_data)
{
	GthBrowser  *browser = GTH_BROWSER (user_data);
	GthFileData *file_data;
	GtkWidget   *new_browser;

	file_data = gth_browser_get_folder_popup_file_data (browser);
	if (file_data == NULL)
		return;

	new_browser = gth_browser_new (file_data->file, NULL);
	gtk_window_present (GTK_WINDOW (new_browser));

	g_object_unref (file_data);
}
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505


void
gth_browser_activate_show_hidden_files (GSimpleAction *action,
					GVariant      *state,
					gpointer       user_data)
{
	GSettings *settings;

	g_simple_action_set_state (action, state);

	settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
	g_settings_set_boolean (settings, PREF_BROWSER_SHOW_HIDDEN_FILES, g_variant_get_boolean (state));
	g_object_unref (settings);
}


void
gth_browser_activate_sort_by (GSimpleAction *action,
			      GVariant      *parameter,
			      gpointer       user_data)
{
	dlg_sort_order (GTH_BROWSER (user_data));
}


void
gth_browser_activate_show_statusbar (GSimpleAction *action,
				     GVariant      *state,
				     gpointer       user_data)
{
	GSettings *settings;

	g_simple_action_set_state (action, state);

	settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
	g_settings_set_boolean (settings, PREF_BROWSER_STATUSBAR_VISIBLE, g_variant_get_boolean (state));
	g_object_unref (settings);
}


void
gth_browser_activate_show_sidebar (GSimpleAction *action,
				   GVariant      *state,
				   gpointer       user_data)
{
	GSettings *settings;

	g_simple_action_set_state (action, state);

	settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
	g_settings_set_boolean (settings, PREF_BROWSER_SIDEBAR_VISIBLE, g_variant_get_boolean (state));
	g_object_unref (settings);
}


void
gth_browser_activate_show_thumbnail_list (GSimpleAction *action,
					  GVariant      *state,
					  gpointer       user_data)
{
	GSettings *settings;

	g_simple_action_set_state (action, state);

	settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
	g_settings_set_boolean (settings, PREF_BROWSER_THUMBNAIL_LIST_VISIBLE, g_variant_get_boolean (state));
	g_object_unref (settings);
}
506 507 508 509 510 511 512 513 514 515 516


void
gth_browser_activate_show_previous_image (GSimpleAction *action,
					  GVariant      *state,
					  gpointer       user_data)
{
	GthBrowser *browser = GTH_BROWSER (user_data);
	gth_browser_show_prev_image (browser, FALSE, FALSE);
}

517

518 519 520 521 522 523 524 525
void
gth_browser_activate_show_next_image (GSimpleAction *action,
				      GVariant      *state,
				      gpointer       user_data)
{
	GthBrowser *browser = GTH_BROWSER (user_data);
	gth_browser_show_next_image (browser, FALSE, FALSE);
}
526 527 528 529 530 531 532 533 534 535


void
gth_browser_activate_apply_editor_changes (GSimpleAction *action,
					   GVariant      *state,
					   gpointer       user_data)
{
	GthBrowser *browser = GTH_BROWSER (user_data);
	gth_browser_apply_editor_changes (browser);
}