1 /* LightTheme -- Disable preference of dark theme variants
2 *
3 * Copyright (C) 2012 Felix Riemann
4 *
5 * Author: Felix Riemann <friemann@gnome.org>
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 2 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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <gtk/gtk.h>
27 #include <eog/eog-application.h>
28 #include <eog/eog-application-activatable.h>
29
30 #include "eog-light-theme-plugin.h"
31
32
33 static void
34 eog_application_activatable_iface_init (EogApplicationActivatableInterface *iface);
35
36 G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogLightThemePlugin, eog_light_theme_plugin,
37 PEAS_TYPE_EXTENSION_BASE, 0,
38 G_IMPLEMENT_INTERFACE_DYNAMIC (EOG_TYPE_APPLICATION_ACTIVATABLE,
39 eog_application_activatable_iface_init))
40
41 enum {
42 PROP_0,
43 PROP_APPLICATION
44 };
45
46
47 static void
eog_light_theme_plugin_init(EogLightThemePlugin * plugin)48 eog_light_theme_plugin_init (EogLightThemePlugin *plugin)
49 {
50 }
51
52 static void
_set_theme_setting(gboolean state)53 _set_theme_setting (gboolean state)
54 {
55 GtkSettings *settings = gtk_settings_get_default ();
56 g_object_set (G_OBJECT (settings),
57 "gtk-application-prefer-dark-theme", state,
58 NULL);
59
60 }
61
62 static void
impl_activate(EogApplicationActivatable * activatable)63 impl_activate (EogApplicationActivatable *activatable)
64 {
65 _set_theme_setting (FALSE);
66 }
67
68 static void
impl_deactivate(EogApplicationActivatable * activatable)69 impl_deactivate (EogApplicationActivatable *activatable)
70 {
71 _set_theme_setting (TRUE);
72 }
73
74
75 static void
eog_light_theme_plugin_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)76 eog_light_theme_plugin_get_property (GObject *object,
77 guint prop_id,
78 GValue *value,
79 GParamSpec *pspec)
80 {
81 EogLightThemePlugin *plugin = EOG_LIGHT_THEME_PLUGIN (object);
82
83 switch (prop_id)
84 {
85 case PROP_APPLICATION:
86 g_value_set_object (value, plugin->app);
87 break;
88
89 default:
90 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91 break;
92 }
93 }
94
95 static void
eog_light_theme_plugin_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)96 eog_light_theme_plugin_set_property (GObject *object,
97 guint prop_id,
98 const GValue *value,
99 GParamSpec *pspec)
100 {
101 EogLightThemePlugin *plugin = EOG_LIGHT_THEME_PLUGIN (object);
102
103 switch (prop_id)
104 {
105 case PROP_APPLICATION:
106 plugin->app = EOG_APPLICATION (g_value_dup_object (value));
107 break;
108
109 default:
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
111 break;
112 }
113 }
114
115 static void
eog_light_theme_plugin_class_init(EogLightThemePluginClass * klass)116 eog_light_theme_plugin_class_init (EogLightThemePluginClass *klass)
117 {
118 GObjectClass *object_class = G_OBJECT_CLASS (klass);
119
120 object_class->set_property = eog_light_theme_plugin_set_property;
121 object_class->get_property = eog_light_theme_plugin_get_property;
122
123 g_object_class_override_property (object_class, PROP_APPLICATION,
124 "app");
125 }
126
127 static void
eog_light_theme_plugin_class_finalize(EogLightThemePluginClass * klass)128 eog_light_theme_plugin_class_finalize (EogLightThemePluginClass *klass)
129 {
130 /* Dummy needed for G_DEFINE_DYNAMIC_TYPE_EXTENDED */
131 }
132
133 static void
eog_application_activatable_iface_init(EogApplicationActivatableInterface * iface)134 eog_application_activatable_iface_init (EogApplicationActivatableInterface *iface)
135 {
136 iface->activate = impl_activate;
137 iface->deactivate = impl_deactivate;
138 }
139
140 G_MODULE_EXPORT void
peas_register_types(PeasObjectModule * module)141 peas_register_types (PeasObjectModule *module)
142 {
143 eog_light_theme_plugin_register_type (G_TYPE_MODULE (module));
144 peas_object_module_register_extension_type (module,
145 EOG_TYPE_APPLICATION_ACTIVATABLE,
146 EOG_TYPE_LIGHT_THEME_PLUGIN);
147 }
148