File: eog-fullscreen-plugin.c

package info (click to toggle)
eog 49.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,860 kB
  • sloc: ansic: 27,061; python: 347; xml: 28; makefile: 13; javascript: 9
file content (189 lines) | stat: -rw-r--r-- 5,091 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* Fullscreen with double-click -- Sets eog to fullscreen by double-clicking
 *
 * Copyright (C) 2007-2012 The Free Software Foundation
 *
 * Author: Lucas Rocha <lucasr@gnome.org>
 *
 * 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 along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "eog-fullscreen-plugin.h"

#include <gmodule.h>
#include <glib/gi18n-lib.h>
#include <libpeas/peas-activatable.h>

#include <eog-debug.h>
#include <eog-scroll-view.h>
#include <eog-window-activatable.h>

static void eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);

G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogFullscreenPlugin,
		eog_fullscreen_plugin,
		PEAS_TYPE_EXTENSION_BASE,
		0,
		G_IMPLEMENT_INTERFACE_DYNAMIC (EOG_TYPE_WINDOW_ACTIVATABLE,
					     eog_window_activatable_iface_init))

enum {
	PROP_0,
	PROP_WINDOW
};

static gboolean
on_button_press (GtkWidget *widget, GdkEventButton *event, EogWindow *window)
{
	EogScrollView *view = EOG_SCROLL_VIEW (widget);

	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
		EogWindowMode mode = eog_window_get_mode (window);
		GdkEvent *ev = (GdkEvent*) event;

		if(!eog_scroll_view_event_is_over_image (view, ev))
			return FALSE;

		if (mode == EOG_WINDOW_MODE_SLIDESHOW ||
		    mode == EOG_WINDOW_MODE_FULLSCREEN)
			eog_window_set_mode (window, EOG_WINDOW_MODE_NORMAL);
		else if (mode == EOG_WINDOW_MODE_NORMAL)
			eog_window_set_mode (window, EOG_WINDOW_MODE_FULLSCREEN);

		return TRUE;
	}

	return FALSE;
}

static void
eog_fullscreen_plugin_set_property (GObject      *object,
				guint         prop_id,
				const GValue *value,
				GParamSpec   *pspec)
{
	EogFullscreenPlugin *plugin = EOG_FULLSCREEN_PLUGIN (object);

	switch (prop_id)
	{
	case PROP_WINDOW:
		plugin->window = EOG_WINDOW (g_value_dup_object (value));
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
eog_fullscreen_plugin_get_property (GObject    *object,
				guint       prop_id,
				GValue     *value,
				GParamSpec *pspec)
{
	EogFullscreenPlugin *plugin = EOG_FULLSCREEN_PLUGIN (object);

	switch (prop_id)
	{
	case PROP_WINDOW:
		g_value_set_object (value, plugin->window);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
eog_fullscreen_plugin_init (EogFullscreenPlugin *plugin)
{
	eog_debug_message (DEBUG_PLUGINS, "EogFullscreenPlugin initializing");
}

static void
eog_fullscreen_plugin_dispose (GObject *object)
{
	EogFullscreenPlugin *plugin = EOG_FULLSCREEN_PLUGIN (object);

	eog_debug_message (DEBUG_PLUGINS, "EogFullscreenPlugin disposing");

	if (plugin->window != NULL) {
		g_object_unref (plugin->window);
		plugin->window = NULL;
	}

	G_OBJECT_CLASS (eog_fullscreen_plugin_parent_class)->dispose (object);
}

static void
eog_fullscreen_plugin_activate (EogWindowActivatable *activatable)
{
	EogFullscreenPlugin *plugin = EOG_FULLSCREEN_PLUGIN (activatable);
	GtkWidget *view = eog_window_get_view (plugin->window);

	eog_debug (DEBUG_PLUGINS);

	plugin->signal_id = g_signal_connect (G_OBJECT (view),
					      "button-press-event",
					      G_CALLBACK (on_button_press),
					      plugin->window);
}

static void
eog_fullscreen_plugin_deactivate (EogWindowActivatable *activatable)
{
	EogFullscreenPlugin *plugin = EOG_FULLSCREEN_PLUGIN (activatable);
	GtkWidget *view = eog_window_get_view (plugin->window);

	g_signal_handler_disconnect (view, plugin->signal_id);
}

static void
eog_fullscreen_plugin_class_init (EogFullscreenPluginClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->dispose = eog_fullscreen_plugin_dispose;
	object_class->set_property = eog_fullscreen_plugin_set_property;
	object_class->get_property = eog_fullscreen_plugin_get_property;

	g_object_class_override_property (object_class, PROP_WINDOW, "window");
}

static void
eog_fullscreen_plugin_class_finalize (EogFullscreenPluginClass *klass)
{
}

static void
eog_window_activatable_iface_init (EogWindowActivatableInterface *iface)
{
	iface->activate = eog_fullscreen_plugin_activate;
	iface->deactivate = eog_fullscreen_plugin_deactivate;
}

G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
	eog_fullscreen_plugin_register_type (G_TYPE_MODULE (module));
	peas_object_module_register_extension_type (module,
						    EOG_TYPE_WINDOW_ACTIVATABLE,
						    EOG_TYPE_FULLSCREEN_PLUGIN);
}