Skip to content

Commit bb3b0c0

Browse files
fxriraveit65
authored andcommitted
Add new plugin hook for per-application plugins
These will be loaded on application initialization and disabled once the application is disposed. origin commit: https://gitlab.gnome.org/GNOME/eog/commit/cdfe77e
1 parent 57506ff commit bb3b0c0

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ NOINST_H_FILES = \
3838

3939
INST_H_FILES = \
4040
eom-application.h \
41+
eom-application-activatable.h \
4142
eom-debug.h \
4243
eom-window.h \
4344
eom-window-activatable.h \
@@ -62,6 +63,7 @@ INST_H_FILES = \
6263

6364
libeom_c_files = \
6465
eom-application.c \
66+
eom-application-activatable.c \
6567
eom-session.c \
6668
eom-debug.c \
6769
eom-util.c \

src/eom-application-activatable.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* eom-application-activatable.c
3+
* This file is part of eom
4+
*
5+
* Author: Felix Riemann <friemann@gnome.org>
6+
*
7+
* Copyright (C) 2012 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-application-activatable.h"
32+
33+
#include <glib-object.h>
34+
#include "eom-application.h"
35+
36+
G_DEFINE_INTERFACE(EomApplicationActivatable, eom_application_activatable, G_TYPE_OBJECT)
37+
38+
void
39+
eom_application_activatable_default_init (EomApplicationActivatableInterface *iface)
40+
{
41+
static gboolean initialized = FALSE;
42+
43+
if (!initialized) {
44+
/**
45+
* EomApplicationActivatable:app:
46+
*
47+
* This is the #EomApplication this #EomApplicationActivatable instance
48+
* should be attached to.
49+
*/
50+
g_object_interface_install_property (iface,
51+
g_param_spec_object ("app", "Application",
52+
"The EomApplication this instance it attached to",
53+
EOM_TYPE_APPLICATION,
54+
G_PARAM_READWRITE |
55+
G_PARAM_CONSTRUCT_ONLY |
56+
G_PARAM_STATIC_STRINGS));
57+
initialized = TRUE;
58+
}
59+
}
60+
61+
void
62+
eom_application_activatable_activate (EomApplicationActivatable *activatable)
63+
{
64+
EomApplicationActivatableInterface *iface;
65+
66+
g_return_if_fail (EOM_IS_APPLICATION_ACTIVATABLE (activatable));
67+
68+
iface = EOM_APPLICATION_ACTIVATABLE_GET_IFACE (activatable);
69+
70+
if (G_LIKELY (iface->activate != NULL))
71+
iface->activate (activatable);
72+
}
73+
74+
void
75+
eom_application_activatable_deactivate (EomApplicationActivatable *activatable)
76+
{
77+
EomApplicationActivatableInterface *iface;
78+
79+
g_return_if_fail (EOM_IS_APPLICATION_ACTIVATABLE (activatable));
80+
81+
iface = EOM_APPLICATION_ACTIVATABLE_GET_IFACE (activatable);
82+
83+
if (G_LIKELY (iface->deactivate != NULL))
84+
iface->deactivate (activatable);
85+
}
86+

src/eom-application-activatable.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* eom-application-activatable.h
3+
* This file is part of eom
4+
*
5+
* Author: Felix Riemann <friemann@gnome.org>
6+
*
7+
* Copyright (C) 2012 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_APPLICATION_ACTIVATABLE_H__
28+
#define __EOM_APPLICATION_ACTIVATABLE_H__
29+
30+
#include <glib-object.h>
31+
32+
G_BEGIN_DECLS
33+
34+
#define EOM_TYPE_APPLICATION_ACTIVATABLE (eom_application_activatable_get_type ())
35+
#define EOM_APPLICATION_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
36+
EOM_TYPE_APPLICATION_ACTIVATABLE, \
37+
EomApplicationActivatable))
38+
#define EOM_APPLICATION_ACTIVATABLE_IFACE(obj) \
39+
(G_TYPE_CHECK_CLASS_CAST ((obj), \
40+
EOM_TYPE_APPLICATION_ACTIVATABLE, \
41+
EomApplicationActivatableInterface))
42+
#define EOM_IS_APPLICATION_ACTIVATABLE(obj) \
43+
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
44+
EOM_TYPE_APPLICATION_ACTIVATABLE))
45+
#define EOM_APPLICATION_ACTIVATABLE_GET_IFACE(obj) \
46+
(G_TYPE_INSTANCE_GET_INTERFACE ((obj), \
47+
EOM_TYPE_APPLICATION_ACTIVATABLE, \
48+
EomApplicationActivatableInterface))
49+
50+
typedef struct _EomApplicationActivatable EomApplicationActivatable;
51+
typedef struct _EomApplicationActivatableInterface EomApplicationActivatableInterface;
52+
53+
struct _EomApplicationActivatableInterface
54+
{
55+
GTypeInterface g_iface;
56+
57+
/* vfuncs */
58+
59+
void (*activate) (EomApplicationActivatable *activatable);
60+
void (*deactivate) (EomApplicationActivatable *activatable);
61+
};
62+
63+
GType eom_application_activatable_get_type (void) G_GNUC_CONST;
64+
65+
void eom_application_activatable_activate (EomApplicationActivatable *activatable);
66+
void eom_application_activatable_deactivate (EomApplicationActivatable *activatable);
67+
68+
G_END_DECLS
69+
#endif /* __EOM_APPLICATION_ACTIVATABLE_H__ */
70+

src/eom-application.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "eom-session.h"
3131
#include "eom-window.h"
3232
#include "eom-application.h"
33+
#include "eom-application-activatable.h"
3334
#include "eom-util.h"
3435

3536
#include <string.h>
@@ -86,6 +87,9 @@ eom_application_finalize (GObject *object)
8687
g_free (application->toolbars_file);
8788
application->toolbars_file = NULL;
8889
}
90+
91+
g_clear_object (&application->extensions);
92+
8993
if (application->plugin_engine) {
9094
g_object_unref (application->plugin_engine);
9195
application->plugin_engine = NULL;
@@ -146,6 +150,24 @@ eom_application_class_init (EomApplicationClass *eom_application_class)
146150
application_class->before_emit = eom_application_before_emit;
147151
}
148152

153+
static void
154+
on_extension_added (PeasExtensionSet *set,
155+
PeasPluginInfo *info,
156+
PeasExtension *exten,
157+
EomApplication *app)
158+
{
159+
eom_application_activatable_activate (EOM_APPLICATION_ACTIVATABLE (exten));
160+
}
161+
162+
static void
163+
on_extension_removed (PeasExtensionSet *set,
164+
PeasPluginInfo *info,
165+
PeasExtension *exten,
166+
EomApplication *app)
167+
{
168+
eom_application_activatable_deactivate (EOM_APPLICATION_ACTIVATABLE (exten));
169+
}
170+
149171
static void
150172
eom_application_init (EomApplication *eom_application)
151173
{
@@ -175,6 +197,17 @@ eom_application_init (EomApplication *eom_application)
175197
EGG_TB_MODEL_NOT_REMOVABLE);
176198

177199
eom_application_load_accelerators ();
200+
201+
eom_application->extensions = peas_extension_set_new (
202+
PEAS_ENGINE (eom_application->plugin_engine),
203+
EOM_TYPE_APPLICATION_ACTIVATABLE,
204+
"app", EOM_APPLICATION (eom_application),
205+
NULL);
206+
peas_extension_set_call (eom_application->extensions, "activate");
207+
g_signal_connect (eom_application->extensions, "extension-added",
208+
G_CALLBACK (on_extension_added), eom_application);
209+
g_signal_connect (eom_application->extensions, "extension-removed",
210+
G_CALLBACK (on_extension_removed), eom_application);
178211
}
179212

180213
/**

src/eom-application.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <glib.h>
3333
#include <glib-object.h>
3434

35+
#include <libpeas/peas-extension-set.h>
36+
3537
G_BEGIN_DECLS
3638

3739
typedef struct _EomApplication EomApplication;
@@ -56,6 +58,8 @@ struct _EomApplication {
5658
EomPluginEngine *plugin_engine;
5759

5860
EomStartupFlags flags;
61+
62+
PeasExtensionSet *extensions;
5963
};
6064

6165
struct _EomApplicationClass {

0 commit comments

Comments
 (0)