1 /* theme-gtkcss.c generated by valac 0.48.6, the Vala compiler
2  * generated from theme-gtkcss.vala, do not modify */
3 
4 /*
5  *  Notes - panel plugin for Xfce Desktop Environment
6  *  Copyright (c) 2006-2013  Mike Massonnet <mmassonnet@xfce.org>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22 
23 #include <glib-object.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <gdk/gdk.h>
28 #include <config.h>
29 #include <glib/gstdio.h>
30 #include <gtk/gtk.h>
31 
32 #define XNP_TYPE_THEME_GTKCSS (xnp_theme_gtkcss_get_type ())
33 #define XNP_THEME_GTKCSS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XNP_TYPE_THEME_GTKCSS, XnpThemeGtkcss))
34 #define XNP_THEME_GTKCSS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XNP_TYPE_THEME_GTKCSS, XnpThemeGtkcssClass))
35 #define XNP_IS_THEME_GTKCSS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XNP_TYPE_THEME_GTKCSS))
36 #define XNP_IS_THEME_GTKCSS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XNP_TYPE_THEME_GTKCSS))
37 #define XNP_THEME_GTKCSS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XNP_TYPE_THEME_GTKCSS, XnpThemeGtkcssClass))
38 
39 typedef struct _XnpThemeGtkcss XnpThemeGtkcss;
40 typedef struct _XnpThemeGtkcssClass XnpThemeGtkcssClass;
41 typedef struct _XnpThemeGtkcssPrivate XnpThemeGtkcssPrivate;
42 enum  {
43 	XNP_THEME_GTKCSS_0_PROPERTY,
44 	XNP_THEME_GTKCSS_NUM_PROPERTIES
45 };
46 static GParamSpec* xnp_theme_gtkcss_properties[XNP_THEME_GTKCSS_NUM_PROPERTIES];
47 #define _g_free0(var) (var = (g_free (var), NULL))
48 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
49 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
50 
51 struct _XnpThemeGtkcss {
52 	GObject parent_instance;
53 	XnpThemeGtkcssPrivate * priv;
54 };
55 
56 struct _XnpThemeGtkcssClass {
57 	GObjectClass parent_class;
58 };
59 
60 static gpointer xnp_theme_gtkcss_parent_class = NULL;
61 
62 GType xnp_theme_gtkcss_get_type (void) G_GNUC_CONST;
63 G_DEFINE_AUTOPTR_CLEANUP_FUNC (XnpThemeGtkcss, g_object_unref)
64 gchar* xnp_theme_gtkcss_get_css_path (void);
65 void xnp_theme_gtkcss_update_css (GdkColor* color);
66 void xnp_theme_gtkcss_update_style_context (void);
67 XnpThemeGtkcss* xnp_theme_gtkcss_new (void);
68 XnpThemeGtkcss* xnp_theme_gtkcss_construct (GType object_type);
69 static GType xnp_theme_gtkcss_get_type_once (void);
70 
71 gchar*
xnp_theme_gtkcss_get_css_path(void)72 xnp_theme_gtkcss_get_css_path (void)
73 {
74 	const gchar* _tmp0_;
75 	gchar* _tmp1_;
76 	gchar* result = NULL;
77 	_tmp0_ = g_get_user_config_dir ();
78 	_tmp1_ = g_strdup_printf ("%s/xfce4/xfce4-notes.css", _tmp0_);
79 	result = _tmp1_;
80 	return result;
81 }
82 
83 void
xnp_theme_gtkcss_update_css(GdkColor * color)84 xnp_theme_gtkcss_update_css (GdkColor* color)
85 {
86 	gchar* css = NULL;
87 	GdkColor _tmp0_;
88 	GdkColor _tmp1_;
89 	GdkColor _tmp2_;
90 	gchar* _tmp3_;
91 	GError* _inner_error0_ = NULL;
92 	g_return_if_fail (color != NULL);
93 	_tmp0_ = *color;
94 	_tmp1_ = *color;
95 	_tmp2_ = *color;
96 	_tmp3_ = g_strdup_printf ("@define-color notes_bg_color #%x%x%x;\n" \
97 "@import url(\"%s%c%s%cgtk-main.css\");", (guint) (_tmp0_.red >> 8), (guint) (_tmp1_.green >> 8), (guint) (_tmp2_.blue >> 8), PKGDATADIR, (gint) G_DIR_SEPARATOR, "gtk-3.0", (gint) G_DIR_SEPARATOR);
98 	css = _tmp3_;
99 	{
100 		gchar* _tmp4_;
101 		gchar* _tmp5_;
102 		_tmp4_ = xnp_theme_gtkcss_get_css_path ();
103 		_tmp5_ = _tmp4_;
104 		g_file_set_contents (_tmp5_, css, (gssize) -1, &_inner_error0_);
105 		_g_free0 (_tmp5_);
106 		if (G_UNLIKELY (_inner_error0_ != NULL)) {
107 			if (_inner_error0_->domain == G_FILE_ERROR) {
108 				goto __catch0_g_file_error;
109 			}
110 			_g_free0 (css);
111 			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
112 			g_clear_error (&_inner_error0_);
113 			return;
114 		}
115 	}
116 	goto __finally0;
117 	__catch0_g_file_error:
118 	{
119 		GError* e = NULL;
120 		GError* _tmp6_;
121 		const gchar* _tmp7_;
122 		e = _inner_error0_;
123 		_inner_error0_ = NULL;
124 		_tmp6_ = e;
125 		_tmp7_ = _tmp6_->message;
126 		g_warning ("theme-gtkcss.vala:34: Unable to update CSS file: %s", _tmp7_);
127 		_g_error_free0 (e);
128 	}
129 	__finally0:
130 	if (G_UNLIKELY (_inner_error0_ != NULL)) {
131 		_g_free0 (css);
132 		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
133 		g_clear_error (&_inner_error0_);
134 		return;
135 	}
136 	_g_free0 (css);
137 }
138 
139 void
xnp_theme_gtkcss_update_style_context(void)140 xnp_theme_gtkcss_update_style_context (void)
141 {
142 	GError* _inner_error0_ = NULL;
143 	{
144 		GtkCssProvider* cssprovider = NULL;
145 		GtkCssProvider* _tmp0_;
146 		gchar* _tmp1_;
147 		gchar* _tmp2_;
148 		GdkScreen* _tmp3_;
149 		_tmp0_ = gtk_css_provider_new ();
150 		cssprovider = _tmp0_;
151 		_tmp1_ = xnp_theme_gtkcss_get_css_path ();
152 		_tmp2_ = _tmp1_;
153 		gtk_css_provider_load_from_path (cssprovider, _tmp2_, &_inner_error0_);
154 		_g_free0 (_tmp2_);
155 		if (G_UNLIKELY (_inner_error0_ != NULL)) {
156 			_g_object_unref0 (cssprovider);
157 			goto __catch0_g_error;
158 		}
159 		_tmp3_ = gdk_screen_get_default ();
160 		gtk_style_context_add_provider_for_screen (_tmp3_, (GtkStyleProvider*) cssprovider, (guint) GTK_STYLE_PROVIDER_PRIORITY_USER);
161 		_g_object_unref0 (cssprovider);
162 	}
163 	goto __finally0;
164 	__catch0_g_error:
165 	{
166 		GError* e = NULL;
167 		GError* _tmp4_;
168 		const gchar* _tmp5_;
169 		e = _inner_error0_;
170 		_inner_error0_ = NULL;
171 		_tmp4_ = e;
172 		_tmp5_ = _tmp4_->message;
173 		g_warning ("theme-gtkcss.vala:44: %s", _tmp5_);
174 		_g_error_free0 (e);
175 	}
176 	__finally0:
177 	if (G_UNLIKELY (_inner_error0_ != NULL)) {
178 		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
179 		g_clear_error (&_inner_error0_);
180 		return;
181 	}
182 }
183 
184 XnpThemeGtkcss*
xnp_theme_gtkcss_construct(GType object_type)185 xnp_theme_gtkcss_construct (GType object_type)
186 {
187 	XnpThemeGtkcss * self = NULL;
188 	self = (XnpThemeGtkcss*) g_object_new (object_type, NULL);
189 	return self;
190 }
191 
192 XnpThemeGtkcss*
xnp_theme_gtkcss_new(void)193 xnp_theme_gtkcss_new (void)
194 {
195 	return xnp_theme_gtkcss_construct (XNP_TYPE_THEME_GTKCSS);
196 }
197 
198 static void
xnp_theme_gtkcss_class_init(XnpThemeGtkcssClass * klass,gpointer klass_data)199 xnp_theme_gtkcss_class_init (XnpThemeGtkcssClass * klass,
200                              gpointer klass_data)
201 {
202 	xnp_theme_gtkcss_parent_class = g_type_class_peek_parent (klass);
203 }
204 
205 static void
xnp_theme_gtkcss_instance_init(XnpThemeGtkcss * self,gpointer klass)206 xnp_theme_gtkcss_instance_init (XnpThemeGtkcss * self,
207                                 gpointer klass)
208 {
209 }
210 
211 static GType
xnp_theme_gtkcss_get_type_once(void)212 xnp_theme_gtkcss_get_type_once (void)
213 {
214 	static const GTypeInfo g_define_type_info = { sizeof (XnpThemeGtkcssClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xnp_theme_gtkcss_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XnpThemeGtkcss), 0, (GInstanceInitFunc) xnp_theme_gtkcss_instance_init, NULL };
215 	GType xnp_theme_gtkcss_type_id;
216 	xnp_theme_gtkcss_type_id = g_type_register_static (G_TYPE_OBJECT, "XnpThemeGtkcss", &g_define_type_info, 0);
217 	return xnp_theme_gtkcss_type_id;
218 }
219 
220 GType
xnp_theme_gtkcss_get_type(void)221 xnp_theme_gtkcss_get_type (void)
222 {
223 	static volatile gsize xnp_theme_gtkcss_type_id__volatile = 0;
224 	if (g_once_init_enter (&xnp_theme_gtkcss_type_id__volatile)) {
225 		GType xnp_theme_gtkcss_type_id;
226 		xnp_theme_gtkcss_type_id = xnp_theme_gtkcss_get_type_once ();
227 		g_once_init_leave (&xnp_theme_gtkcss_type_id__volatile, xnp_theme_gtkcss_type_id);
228 	}
229 	return xnp_theme_gtkcss_type_id__volatile;
230 }
231 
232