1 /*
2  * gtr-window-activatable.h
3  * This file is part of gtr
4  *
5  * Copyright (C) 2010 Steve Frécinaux
6  *
7  *     This program is free software: you can redistribute it and/or modify
8  *     it under the terms of the GNU General Public License as published by
9  *     the Free Software Foundation, either version 3 of the License, or
10  *     (at your option) any later version.
11  *
12  *     This program is distributed in the hope that it will be useful,
13  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *     GNU General Public License for more details.
16  *
17  *     You should have received a copy of the GNU General Public License
18  *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include "gtr-window-activatable.h"
26 #include "gtr-window.h"
27 
28 /**
29  * SECTION:gtr-window-activatable
30  * @short_description: Interface for activatable extensions on windows
31  * @see_also: #PeasExtensionSet
32  *
33  * #GtrWindowActivatable is an interface which should be implemented by
34  * extensions that should be activated on a gtr main window.
35  **/
36 
G_DEFINE_INTERFACE(GtrWindowActivatable,gtr_window_activatable,G_TYPE_OBJECT)37 G_DEFINE_INTERFACE (GtrWindowActivatable, gtr_window_activatable,
38                     G_TYPE_OBJECT)
39      void gtr_window_activatable_default_init (GtrWindowActivatableInterface *
40                                                iface)
41 {
42   static gboolean initialized = FALSE;
43 
44   if (!initialized)
45     {
46                 /**
47 		 * GtrWindowActivatable:window:
48 		 *
49 		 * The window property contains the gtr window for this
50 		 * #GtrWindowActivatable instance.
51 		 */
52       g_object_interface_install_property (iface,
53                                            g_param_spec_object ("window",
54                                                                 "Window",
55                                                                 "The gtranslator window",
56                                                                 GTR_TYPE_WINDOW,
57                                                                 G_PARAM_READWRITE
58                                                                 |
59                                                                 G_PARAM_CONSTRUCT_ONLY
60                                                                 |
61                                                                 G_PARAM_STATIC_STRINGS));
62 
63       initialized = TRUE;
64     }
65 }
66 
67 /**
68  * gtr_window_activatable_activate:
69  * @activatable: A #GtrWindowActivatable.
70  *
71  * Activates the extension on the window property.
72  */
73 void
gtr_window_activatable_activate(GtrWindowActivatable * activatable)74 gtr_window_activatable_activate (GtrWindowActivatable * activatable)
75 {
76   GtrWindowActivatableInterface *iface;
77 
78   g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
79 
80   iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
81   if (iface->activate != NULL)
82     {
83       iface->activate (activatable);
84     }
85 }
86 
87 /**
88  * gtr_window_activatable_deactivate:
89  * @activatable: A #GtrWindowActivatable.
90  *
91  * Deactivates the extension on the window property.
92  */
93 void
gtr_window_activatable_deactivate(GtrWindowActivatable * activatable)94 gtr_window_activatable_deactivate (GtrWindowActivatable * activatable)
95 {
96   GtrWindowActivatableInterface *iface;
97 
98   g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
99 
100   iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
101   if (iface->deactivate != NULL)
102     {
103       iface->deactivate (activatable);
104     }
105 }
106 
107 /**
108  * gtr_window_activatable_update_state:
109  * @activatable: A #GtrWindowActivatable.
110  *
111  * Triggers an update of the extension internal state to take into account
112  * state changes in the window, due to some event or user action.
113  */
114 void
gtr_window_activatable_update_state(GtrWindowActivatable * activatable)115 gtr_window_activatable_update_state (GtrWindowActivatable * activatable)
116 {
117   GtrWindowActivatableInterface *iface;
118 
119   g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
120 
121   iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
122   if (iface->update_state != NULL)
123     {
124       iface->update_state (activatable);
125     }
126 }
127