1 /*
2  * This file is part of d-dazzle.
3  *
4  * d-dazzle is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * d-dazzle is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with d-dazzle; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module dazzle.ThemeManager;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import glib.ConstructionException;
24 private import glib.Str;
25 private import gobject.ObjectG;
26 
27 
28 /** */
29 public class ThemeManager : ObjectG
30 {
31 	/** the main Gtk struct */
32 	protected DzlThemeManager* dzlThemeManager;
33 
34 	/** Get the main Gtk struct */
35 	public DzlThemeManager* getThemeManagerStruct(bool transferOwnership = false)
36 	{
37 		if (transferOwnership)
38 			ownedRef = false;
39 		return dzlThemeManager;
40 	}
41 
42 	/** the main Gtk struct as a void* */
43 	protected override void* getStruct()
44 	{
45 		return cast(void*)dzlThemeManager;
46 	}
47 
48 	/**
49 	 * Sets our main struct and passes it to the parent class.
50 	 */
51 	public this (DzlThemeManager* dzlThemeManager, bool ownedRef = false)
52 	{
53 		this.dzlThemeManager = dzlThemeManager;
54 		super(cast(GObject*)dzlThemeManager, ownedRef);
55 	}
56 
57 
58 	/** */
59 	public static GType getType()
60 	{
61 		return dzl_theme_manager_get_type();
62 	}
63 
64 	/** */
65 	public this()
66 	{
67 		auto p = dzl_theme_manager_new();
68 
69 		if(p is null)
70 		{
71 			throw new ConstructionException("null returned by new");
72 		}
73 
74 		this(cast(DzlThemeManager*) p, true);
75 	}
76 
77 	/**
78 	 * This will automatically register resources found within @resource_path.
79 	 *
80 	 * If @resource_path starts with "resource://", embedded #GResources will be
81 	 * used to locate the theme files. Otherwise, @resource_path is expected to be
82 	 * a path on disk that may or may not exist.
83 	 *
84 	 * If the @resource_path contains a directory named "themes", that directory
85 	 * will be traversed for files matching the theme name and variant. For
86 	 * example, if using the Adwaita theme, "themes/Adwaita.css" will be loaded. If
87 	 * the dark variant is being used, "themes/Adwaita-dark.css" will be loaeded. If
88 	 * no matching theme file is located, "themes/shared.css" will be loaded.
89 	 *
90 	 * When the current theme changes, the CSS will be reloaded to adapt.
91 	 *
92 	 * The "icons" sub-directory will be used to locate icon themes.
93 	 *
94 	 * Params:
95 	 *     resourcePath = A path to a #GResources directory
96 	 */
97 	public void addResources(string resourcePath)
98 	{
99 		dzl_theme_manager_add_resources(dzlThemeManager, Str.toStringz(resourcePath));
100 	}
101 
102 	/**
103 	 * This removes the CSS providers that were registered using @resource_path.
104 	 *
105 	 * You must have previously called dzl_theme_manager_add_resources() for
106 	 * this function to do anything.
107 	 *
108 	 * Since icons cannot be unloaded, previously loaded icons will continue to
109 	 * be available even after calling this function.
110 	 *
111 	 * Params:
112 	 *     resourcePath = A previously registered resources path
113 	 */
114 	public void removeResources(string resourcePath)
115 	{
116 		dzl_theme_manager_remove_resources(dzlThemeManager, Str.toStringz(resourcePath));
117 	}
118 }