actions.c 5.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  GThumb
 *
 *  Copyright (C) 2009 Free Software Foundation, Inc.
 *
 *  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/>.
20 21 22 23 24 25
 */


#include <config.h>
#include <glib/gi18n.h>
#include <gthumb.h>
Paolo Bacchilega's avatar
Paolo Bacchilega committed
26
#include "actions.h"
27
#include "gth-slideshow.h"
28 29
#include "gth-transition.h"
#include "preferences.h"
30 31 32


void
33 34 35
gth_browser_activate_slideshow (GSimpleAction *action,
				GVariant      *parameter,
				gpointer       user_data)
36
{
37
	GthBrowser   *browser = user_data;
38
	GSettings    *settings;
39 40
	GList        *items;
	GList        *file_list;
41 42
	GList        *filtered_list;
	GList        *scan;
43 44 45 46 47
	GthProjector *projector;
	GtkWidget    *slideshow;
	GthFileData  *location;
	char         *transition_id;
	GList        *transitions = NULL;
48 49 50 51 52 53 54

	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	if ((items == NULL) || (items->next == NULL))
		file_list = gth_file_store_get_visibles (GTH_FILE_STORE (gth_browser_get_file_store (browser)));
	else
		file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	filtered_list = NULL;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;

		if (_g_mime_type_is_image (gth_file_data_get_mime_type (file_data)))
			filtered_list = g_list_prepend (filtered_list, g_object_ref (file_data));
	}
	filtered_list = g_list_reverse (filtered_list);

	if (filtered_list == NULL) {
		_g_object_list_unref (file_list);
		_gtk_tree_path_list_free (items);
		return;
	}

70 71
	settings = g_settings_new (GTHUMB_SLIDESHOW_SCHEMA);

72 73 74 75
	location = gth_browser_get_location_data (browser);
	if (g_file_info_get_attribute_boolean (location->info, "slideshow::personalize"))
		transition_id = g_strdup (g_file_info_get_attribute_string (location->info, "slideshow::transition"));
	else
76
		transition_id = g_settings_get_string (settings, PREF_SLIDESHOW_TRANSITION);
77

78
	projector = NULL;
79

80
#ifdef HAVE_CLUTTER
81
	if (gtk_clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS)
82 83
		projector = &clutter_projector;
#endif /* HAVE_CLUTTER */
84 85

	if ((projector == NULL) || (strcmp (transition_id, "none") == 0))
86 87
		projector = &default_projector;

88
	slideshow = gth_slideshow_new (projector, browser, filtered_list);
89

90
	if (g_file_info_get_attribute_boolean (location->info, "slideshow::personalize")) {
91
		gth_slideshow_set_delay (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_int32 (location->info, "slideshow::delay"));
92 93
		gth_slideshow_set_automatic (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::automatic"));
		gth_slideshow_set_wrap_around (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::wrap-around"));
94
		gth_slideshow_set_random_order (GTH_SLIDESHOW (slideshow), g_file_info_get_attribute_boolean (location->info, "slideshow::random-order"));
95 96
	}
	else {
97 98 99 100
		gth_slideshow_set_delay (GTH_SLIDESHOW (slideshow), (guint) (1000.0 * g_settings_get_double (settings, PREF_SLIDESHOW_CHANGE_DELAY)));
		gth_slideshow_set_automatic (GTH_SLIDESHOW (slideshow), g_settings_get_boolean (settings, PREF_SLIDESHOW_AUTOMATIC));
		gth_slideshow_set_wrap_around (GTH_SLIDESHOW (slideshow), g_settings_get_boolean (settings, PREF_SLIDESHOW_WRAP_AROUND));
		gth_slideshow_set_random_order (GTH_SLIDESHOW (slideshow), g_settings_get_boolean (settings, PREF_SLIDESHOW_RANDOM_ORDER));
101 102
	}

103
	if (g_file_info_get_attribute_status (location->info, "slideshow::playlist") == G_FILE_ATTRIBUTE_STATUS_SET)
104
		gth_slideshow_set_playlist (GTH_SLIDESHOW (slideshow),
105
					    g_file_info_get_attribute_stringv (location->info, "slideshow::playlist"));
106

107
	if (strcmp (transition_id, "random") == 0) {
108 109
		GList *scan;

110
		transitions = gth_main_get_registered_objects (GTH_TYPE_TRANSITION);
111 112 113 114 115 116 117 118 119
		for (scan = transitions; scan; scan = scan->next) {
			GthTransition *transition = scan->data;

			if (strcmp (gth_transition_get_id (transition), "none") == 0) {
				transitions = g_list_remove_link (transitions, scan);
				_g_object_list_unref (scan);
				break;
			}
		}
120 121 122 123 124 125 126 127 128 129 130
	}
	else {
		GthTransition *transition = gth_main_get_registered_object (GTH_TYPE_TRANSITION, transition_id);

		if (transition != NULL)
			transitions = g_list_append (NULL, transition);
		else
			transitions = NULL;
	}
	gth_slideshow_set_transitions (GTH_SLIDESHOW (slideshow), transitions);

131 132 133 134
	{
		GdkRectangle  monitor_geometry;
		int           monitor_num;

135
		if (_gtk_window_get_monitor_info (GTK_WINDOW (browser), &monitor_geometry, &monitor_num, NULL)) {
136 137 138 139 140 141 142
			gtk_window_set_default_size (GTK_WINDOW (slideshow), monitor_geometry.width, monitor_geometry.height);
			gtk_window_fullscreen_on_monitor (GTK_WINDOW (slideshow), gtk_window_get_screen (GTK_WINDOW (browser)), monitor_num);
		}
		else
			gtk_window_fullscreen (GTK_WINDOW (slideshow));
		gtk_window_present (GTK_WINDOW (slideshow));
	}
143

144
	_g_object_list_unref (transitions);
145
	g_object_unref (settings);
146
	g_free (transition_id);
147
	_g_object_list_unref (filtered_list);
148 149 150
	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (items);
}