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.Application; 20 21 private import dazzle.MenuManager; 22 private import dazzle.ShortcutManager; 23 private import dazzle.ThemeManager; 24 private import dazzle.c.functions; 25 public import dazzle.c.types; 26 private import gio.Menu; 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtk.Application : GtkApp = Application; 31 32 33 /** */ 34 public class Application : GtkApp 35 { 36 /** the main Gtk struct */ 37 protected DzlApplication* dzlApplication; 38 39 /** Get the main Gtk struct */ 40 public DzlApplication* getDazzleApplicationStruct(bool transferOwnership = false) 41 { 42 if (transferOwnership) 43 ownedRef = false; 44 return dzlApplication; 45 } 46 47 /** the main Gtk struct as a void* */ 48 protected override void* getStruct() 49 { 50 return cast(void*)dzlApplication; 51 } 52 53 /** 54 * Sets our main struct and passes it to the parent class. 55 */ 56 public this (DzlApplication* dzlApplication, bool ownedRef = false) 57 { 58 this.dzlApplication = dzlApplication; 59 super(cast(GtkApplication*)dzlApplication, ownedRef); 60 } 61 62 63 /** */ 64 public static GType getType() 65 { 66 return dzl_application_get_type(); 67 } 68 69 /** */ 70 public this(string applicationId, GApplicationFlags flags) 71 { 72 auto p = dzl_application_new(Str.toStringz(applicationId), flags); 73 74 if(p is null) 75 { 76 throw new ConstructionException("null returned by new"); 77 } 78 79 this(cast(DzlApplication*) p, true); 80 } 81 82 /** 83 * This adds @resource_path to the list of "automatic resources". 84 * 85 * If @resource_path starts with "resource://", then the corresponding 86 * #GResources path will be searched for resources. Otherwise, @resource_path 87 * should be a path to a location on disk. 88 * 89 * The #DzlApplication will locate resources such as CSS themes, icons, and 90 * keyboard shortcuts using @resource_path. 91 * 92 * Params: 93 * resourcePath = the location of the resources. 94 */ 95 public void addResources(string resourcePath) 96 { 97 dzl_application_add_resources(dzlApplication, Str.toStringz(resourcePath)); 98 } 99 100 /** 101 * Similar to gtk_application_get_menu_by_id() but takes into account 102 * menu merging which could have occurred upon loading plugins. 103 * 104 * Params: 105 * menuId = the id of the menu to locate 106 * 107 * Returns: A #GMenu 108 */ 109 public override Menu getMenuById(string menuId) 110 { 111 auto p = dzl_application_get_menu_by_id(dzlApplication, Str.toStringz(menuId)); 112 113 if(p is null) 114 { 115 return null; 116 } 117 118 return ObjectG.getDObject!(Menu)(cast(GMenu*) p); 119 } 120 121 /** 122 * Gets the menu manager for the application. 123 * 124 * Returns: A #DzlMenuManager 125 */ 126 public MenuManager getMenuManager() 127 { 128 auto p = dzl_application_get_menu_manager(dzlApplication); 129 130 if(p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(MenuManager)(cast(DzlMenuManager*) p); 136 } 137 138 /** 139 * Gets the #DzlShortcutManager for the application. 140 * 141 * Returns: A #DzlShortcutManager 142 */ 143 public ShortcutManager getShortcutManager() 144 { 145 auto p = dzl_application_get_shortcut_manager(dzlApplication); 146 147 if(p is null) 148 { 149 return null; 150 } 151 152 return ObjectG.getDObject!(ShortcutManager)(cast(DzlShortcutManager*) p); 153 } 154 155 /** 156 * Get the theme manager for the application. 157 * 158 * Returns: A #DzlThemeManager 159 */ 160 public ThemeManager getThemeManager() 161 { 162 auto p = dzl_application_get_theme_manager(dzlApplication); 163 164 if(p is null) 165 { 166 return null; 167 } 168 169 return ObjectG.getDObject!(ThemeManager)(cast(DzlThemeManager*) p); 170 } 171 172 /** 173 * This attempts to undo as many side-effects as possible from a call to 174 * dzl_application_add_resources(). 175 * 176 * Params: 177 * resourcePath = the location of the resources. 178 */ 179 public void removeResources(string resourcePath) 180 { 181 dzl_application_remove_resources(dzlApplication, Str.toStringz(resourcePath)); 182 } 183 }