Skip to content

Commit 026b114

Browse files
fxriraveit65
authored andcommitted
Add our own activatable interface to EomWindow
Improves typesafety by explicitly passing the EomWindow and allows us to extend the interface if necessary. https://bugzilla.gnome.org/show_bug.cgi?id=626091 origin commit: https://gitlab.gnome.org/GNOME/eog/commit/397a6a5
1 parent 17e6cdb commit 026b114

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ INST_H_FILES = \
4040
eom-application.h \
4141
eom-debug.h \
4242
eom-window.h \
43+
eom-window-activatable.h \
4344
eom-sidebar.h \
4445
eom-dialog.h \
4546
eom-properties-dialog.h \
@@ -66,6 +67,7 @@ libeom_c_files = \
6667
eom-util.c \
6768
eom-pixbuf-util.c \
6869
eom-window.c \
70+
eom-window-activatable.c \
6971
eom-sidebar.c \
7072
eom-dialog.c \
7173
eom-preferences-dialog.c \

src/eom-window-activatable.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* eom-window-activatable.c
3+
* This file is part of eom
4+
*
5+
* Author: Felix Riemann <friemann@gnome.org>
6+
*
7+
* Copyright (C) 2011 Felix Riemann
8+
*
9+
* Base on code by:
10+
* - Steve Frécinaux <code@istique.net>
11+
*
12+
* This program is free software; you can redistribute it and/or
13+
* modify it under the terms of the GNU General Public License
14+
* as published by the Free Software Foundation; either version 2
15+
* of the License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License along
23+
* with this program; if not, write to the Free Software Foundation, Inc.,
24+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25+
*/
26+
27+
#ifdef HAVE_CONFIG_H
28+
#include "config.h"
29+
#endif
30+
31+
#include "eom-window-activatable.h"
32+
33+
#include <glib-object.h>
34+
#include "eom-window.h"
35+
36+
G_DEFINE_INTERFACE(EomWindowActivatable, eom_window_activatable, G_TYPE_OBJECT)
37+
38+
void
39+
eom_window_activatable_default_init (EomWindowActivatableInterface *iface)
40+
{
41+
static gboolean initialized = FALSE;
42+
43+
if (!initialized) {
44+
/**
45+
* EomWindowActivatable:window:
46+
*
47+
* This is the #EomWindow this #EomWindowActivatable instance
48+
* should be attached to.
49+
*/
50+
g_object_interface_install_property (iface,
51+
g_param_spec_object ("window", "Window",
52+
"The EomWindow this "
53+
"instance it attached to",
54+
EOM_TYPE_WINDOW,
55+
G_PARAM_READWRITE |
56+
G_PARAM_CONSTRUCT_ONLY |
57+
G_PARAM_STATIC_STRINGS));
58+
initialized = TRUE;
59+
}
60+
}
61+
62+
void
63+
eom_window_activatable_activate (EomWindowActivatable *activatable)
64+
{
65+
EomWindowActivatableInterface *iface;
66+
67+
g_return_if_fail (EOM_IS_WINDOW_ACTIVATABLE (activatable));
68+
69+
iface = EOM_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
70+
71+
if (G_LIKELY (iface->activate != NULL))
72+
iface->activate (activatable);
73+
}
74+
75+
void
76+
eom_window_activatable_deactivate (EomWindowActivatable *activatable)
77+
{
78+
EomWindowActivatableInterface *iface;
79+
80+
g_return_if_fail (EOM_IS_WINDOW_ACTIVATABLE (activatable));
81+
82+
iface = EOM_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
83+
84+
if (G_LIKELY (iface->deactivate != NULL))
85+
iface->deactivate (activatable);
86+
}
87+

src/eom-window-activatable.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* eom-window-activatable.h
3+
* This file is part of eom
4+
*
5+
* Author: Felix Riemann <friemann@gnome.org>
6+
*
7+
* Copyright (C) 2011 Felix Riemann
8+
*
9+
* Base on code by:
10+
* - Steve Frécinaux <code@istique.net>
11+
*
12+
* This program is free software; you can redistribute it and/or
13+
* modify it under the terms of the GNU General Public License
14+
* as published by the Free Software Foundation; either version 2
15+
* of the License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License along
23+
* with this program; if not, write to the Free Software Foundation, Inc.,
24+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25+
*/
26+
27+
#ifndef __EOM_WINDOW_ACTIVATABLE_H__
28+
#define __EOM_WINDOW_ACTIVATABLE_H__
29+
30+
#include <glib-object.h>
31+
32+
G_BEGIN_DECLS
33+
34+
#define EOM_TYPE_WINDOW_ACTIVATABLE (eom_window_activatable_get_type ())
35+
#define EOM_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
36+
EOM_TYPE_WINDOW_ACTIVATABLE, \
37+
EomWindowActivatable))
38+
#define EOM_WINDOW_ACTIVATABLE_IFACE(obj) \
39+
(G_TYPE_CHECK_CLASS_CAST ((obj), \
40+
EOM_TYPE_WINDOW_ACTIVATABLE, \
41+
EomWindowActivatableInterface))
42+
#define EOM_IS_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
43+
EOM_TYPE_WINDOW_ACTIVATABLE))
44+
#define EOM_WINDOW_ACTIVATABLE_GET_IFACE(obj) \
45+
(G_TYPE_INSTANCE_GET_INTERFACE ((obj), \
46+
EOM_TYPE_WINDOW_ACTIVATABLE, \
47+
EomWindowActivatableInterface))
48+
49+
typedef struct _EomWindowActivatable EomWindowActivatable;
50+
typedef struct _EomWindowActivatableInterface EomWindowActivatableInterface;
51+
52+
struct _EomWindowActivatableInterface
53+
{
54+
GTypeInterface g_iface;
55+
56+
/* vfuncs */
57+
58+
void (*activate) (EomWindowActivatable *activatable);
59+
void (*deactivate) (EomWindowActivatable *activatable);
60+
};
61+
62+
GType eom_window_activatable_get_type (void) G_GNUC_CONST;
63+
64+
void eom_window_activatable_activate (EomWindowActivatable *activatable);
65+
void eom_window_activatable_deactivate (EomWindowActivatable *activatable);
66+
67+
G_END_DECLS
68+
#endif /* __EOM_WINDOW_ACTIVATABLE_H__ */
69+

src/eom-window.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "eom-save-as-dialog-helper.h"
5353
#include "eom-close-confirmation-dialog.h"
5454
#include "eom-clipboard-handler.h"
55+
#include "eom-window-activatable.h"
5556
#include "eom-metadata-sidebar.h"
5657

5758
#include "eom-enum-types.h"
@@ -5127,8 +5128,9 @@ eom_window_constructor (GType type,
51275128
eom_window_construct_ui (EOM_WINDOW (object));
51285129

51295130
priv->extensions = peas_extension_set_new (PEAS_ENGINE (EOM_APP->plugin_engine),
5130-
PEAS_TYPE_ACTIVATABLE,
5131-
"object", object, NULL);
5131+
EOM_TYPE_WINDOW_ACTIVATABLE,
5132+
"window",
5133+
EOM_WINDOW (object), NULL);
51325134

51335135
peas_extension_set_call (priv->extensions, "activate");
51345136

0 commit comments

Comments
 (0)