1 /*
2  * gtr-tab-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-tab-activatable.h"
26 #include "gtr-tab.h"
27 
28 /**
29  * SECTION:gtr-tab-activatable
30  * @short_description: Interface for activatable extensions on tabs
31  * @see_also: #PeasExtensionSet
32  *
33  * #GtrTabActivatable is an interface which should be implemented by
34  * extensions that should be activated on a gtr main tab.
35  **/
36 
G_DEFINE_INTERFACE(GtrTabActivatable,gtr_tab_activatable,G_TYPE_OBJECT)37 G_DEFINE_INTERFACE (GtrTabActivatable, gtr_tab_activatable, G_TYPE_OBJECT)
38 
39 void
40 gtr_tab_activatable_default_init (GtrTabActivatableInterface * iface)
41 {
42   static gboolean initialized = FALSE;
43 
44   if (!initialized)
45     {
46       /**
47        * GtrTabActivatable:tab:
48        *
49        * The tab property contains the gtr tab for this
50        * #GtrTabActivatable instance.
51        */
52       g_object_interface_install_property (iface,
53                                            g_param_spec_object ("tab",
54                                                                 "Tab",
55                                                                 "The gtranslator tab",
56                                                                 GTR_TYPE_TAB,
57                                                                 G_PARAM_READWRITE |
58                                                                 G_PARAM_CONSTRUCT_ONLY |
59                                                                 G_PARAM_STATIC_STRINGS));
60 
61       initialized = TRUE;
62     }
63 }
64 
65 /**
66  * gtr_tab_activatable_activate:
67  * @activatable: A #GtrTabActivatable.
68  *
69  * Activates the extension on the tab property.
70  */
71 void
gtr_tab_activatable_activate(GtrTabActivatable * activatable)72 gtr_tab_activatable_activate (GtrTabActivatable * activatable)
73 {
74   GtrTabActivatableInterface *iface;
75 
76   g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
77 
78   iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
79   if (iface->activate != NULL)
80     {
81       iface->activate (activatable);
82     }
83 }
84 
85 /**
86  * gtr_tab_activatable_deactivate:
87  * @activatable: A #GtrTabActivatable.
88  *
89  * Deactivates the extension on the tab property.
90  */
91 void
gtr_tab_activatable_deactivate(GtrTabActivatable * activatable)92 gtr_tab_activatable_deactivate (GtrTabActivatable * activatable)
93 {
94   GtrTabActivatableInterface *iface;
95 
96   g_return_if_fail (GTR_IS_TAB_ACTIVATABLE (activatable));
97 
98   iface = GTR_TAB_ACTIVATABLE_GET_IFACE (activatable);
99   if (iface->deactivate != NULL)
100     {
101       iface->deactivate (activatable);
102     }
103 }
104