1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD 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 * gtkD 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 gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.AppChooserWidget; 26 27 private import gio.AppInfoIF; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.AppChooserIF; 33 private import gtk.AppChooserT; 34 private import gtk.Box; 35 private import gtk.Menu; 36 private import gtk.Widget; 37 private import gtk.c.functions; 38 public import gtk.c.types; 39 public import gtkc.gtktypes; 40 private import std.algorithm; 41 42 43 /** 44 * #GtkAppChooserWidget is a widget for selecting applications. 45 * It is the main building block for #GtkAppChooserDialog. Most 46 * applications only need to use the latter; but you can use 47 * this widget as part of a larger widget if you have special needs. 48 * 49 * #GtkAppChooserWidget offers detailed control over what applications 50 * are shown, using the 51 * #GtkAppChooserWidget:show-default, 52 * #GtkAppChooserWidget:show-recommended, 53 * #GtkAppChooserWidget:show-fallback, 54 * #GtkAppChooserWidget:show-other and 55 * #GtkAppChooserWidget:show-all 56 * properties. See the #GtkAppChooser documentation for more information 57 * about these groups of applications. 58 * 59 * To keep track of the selected application, use the 60 * #GtkAppChooserWidget::application-selected and #GtkAppChooserWidget::application-activated signals. 61 * 62 * # CSS nodes 63 * 64 * GtkAppChooserWidget has a single CSS node with name appchooser. 65 */ 66 public class AppChooserWidget : Box, AppChooserIF 67 { 68 /** the main Gtk struct */ 69 protected GtkAppChooserWidget* gtkAppChooserWidget; 70 71 /** Get the main Gtk struct */ 72 public GtkAppChooserWidget* getAppChooserWidgetStruct(bool transferOwnership = false) 73 { 74 if (transferOwnership) 75 ownedRef = false; 76 return gtkAppChooserWidget; 77 } 78 79 /** the main Gtk struct as a void* */ 80 protected override void* getStruct() 81 { 82 return cast(void*)gtkAppChooserWidget; 83 } 84 85 /** 86 * Sets our main struct and passes it to the parent class. 87 */ 88 public this (GtkAppChooserWidget* gtkAppChooserWidget, bool ownedRef = false) 89 { 90 this.gtkAppChooserWidget = gtkAppChooserWidget; 91 super(cast(GtkBox*)gtkAppChooserWidget, ownedRef); 92 } 93 94 // add the AppChooser capabilities 95 mixin AppChooserT!(GtkAppChooserWidget); 96 97 98 /** */ 99 public static GType getType() 100 { 101 return gtk_app_chooser_widget_get_type(); 102 } 103 104 /** 105 * Creates a new #GtkAppChooserWidget for applications 106 * that can handle content of the given type. 107 * 108 * Params: 109 * contentType = the content type to show applications for 110 * 111 * Returns: a newly created #GtkAppChooserWidget 112 * 113 * Since: 3.0 114 * 115 * Throws: ConstructionException GTK+ fails to create the object. 116 */ 117 public this(string contentType) 118 { 119 auto p = gtk_app_chooser_widget_new(Str.toStringz(contentType)); 120 121 if(p is null) 122 { 123 throw new ConstructionException("null returned by new"); 124 } 125 126 this(cast(GtkAppChooserWidget*) p); 127 } 128 129 /** 130 * Returns the text that is shown if there are not applications 131 * that can handle the content type. 132 * 133 * Returns: the value of #GtkAppChooserWidget:default-text 134 * 135 * Since: 3.0 136 */ 137 public string getDefaultText() 138 { 139 return Str.toString(gtk_app_chooser_widget_get_default_text(gtkAppChooserWidget)); 140 } 141 142 /** 143 * Returns the current value of the #GtkAppChooserWidget:show-all 144 * property. 145 * 146 * Returns: the value of #GtkAppChooserWidget:show-all 147 * 148 * Since: 3.0 149 */ 150 public bool getShowAll() 151 { 152 return gtk_app_chooser_widget_get_show_all(gtkAppChooserWidget) != 0; 153 } 154 155 /** 156 * Returns the current value of the #GtkAppChooserWidget:show-default 157 * property. 158 * 159 * Returns: the value of #GtkAppChooserWidget:show-default 160 * 161 * Since: 3.0 162 */ 163 public bool getShowDefault() 164 { 165 return gtk_app_chooser_widget_get_show_default(gtkAppChooserWidget) != 0; 166 } 167 168 /** 169 * Returns the current value of the #GtkAppChooserWidget:show-fallback 170 * property. 171 * 172 * Returns: the value of #GtkAppChooserWidget:show-fallback 173 * 174 * Since: 3.0 175 */ 176 public bool getShowFallback() 177 { 178 return gtk_app_chooser_widget_get_show_fallback(gtkAppChooserWidget) != 0; 179 } 180 181 /** 182 * Returns the current value of the #GtkAppChooserWidget:show-other 183 * property. 184 * 185 * Returns: the value of #GtkAppChooserWidget:show-other 186 * 187 * Since: 3.0 188 */ 189 public bool getShowOther() 190 { 191 return gtk_app_chooser_widget_get_show_other(gtkAppChooserWidget) != 0; 192 } 193 194 /** 195 * Returns the current value of the #GtkAppChooserWidget:show-recommended 196 * property. 197 * 198 * Returns: the value of #GtkAppChooserWidget:show-recommended 199 * 200 * Since: 3.0 201 */ 202 public bool getShowRecommended() 203 { 204 return gtk_app_chooser_widget_get_show_recommended(gtkAppChooserWidget) != 0; 205 } 206 207 /** 208 * Sets the text that is shown if there are not applications 209 * that can handle the content type. 210 * 211 * Params: 212 * text = the new value for #GtkAppChooserWidget:default-text 213 */ 214 public void setDefaultText(string text) 215 { 216 gtk_app_chooser_widget_set_default_text(gtkAppChooserWidget, Str.toStringz(text)); 217 } 218 219 /** 220 * Sets whether the app chooser should show all applications 221 * in a flat list. 222 * 223 * Params: 224 * setting = the new value for #GtkAppChooserWidget:show-all 225 * 226 * Since: 3.0 227 */ 228 public void setShowAll(bool setting) 229 { 230 gtk_app_chooser_widget_set_show_all(gtkAppChooserWidget, setting); 231 } 232 233 /** 234 * Sets whether the app chooser should show the default handler 235 * for the content type in a separate section. 236 * 237 * Params: 238 * setting = the new value for #GtkAppChooserWidget:show-default 239 * 240 * Since: 3.0 241 */ 242 public void setShowDefault(bool setting) 243 { 244 gtk_app_chooser_widget_set_show_default(gtkAppChooserWidget, setting); 245 } 246 247 /** 248 * Sets whether the app chooser should show related applications 249 * for the content type in a separate section. 250 * 251 * Params: 252 * setting = the new value for #GtkAppChooserWidget:show-fallback 253 * 254 * Since: 3.0 255 */ 256 public void setShowFallback(bool setting) 257 { 258 gtk_app_chooser_widget_set_show_fallback(gtkAppChooserWidget, setting); 259 } 260 261 /** 262 * Sets whether the app chooser should show applications 263 * which are unrelated to the content type. 264 * 265 * Params: 266 * setting = the new value for #GtkAppChooserWidget:show-other 267 * 268 * Since: 3.0 269 */ 270 public void setShowOther(bool setting) 271 { 272 gtk_app_chooser_widget_set_show_other(gtkAppChooserWidget, setting); 273 } 274 275 /** 276 * Sets whether the app chooser should show recommended applications 277 * for the content type in a separate section. 278 * 279 * Params: 280 * setting = the new value for #GtkAppChooserWidget:show-recommended 281 * 282 * Since: 3.0 283 */ 284 public void setShowRecommended(bool setting) 285 { 286 gtk_app_chooser_widget_set_show_recommended(gtkAppChooserWidget, setting); 287 } 288 289 protected class OnApplicationActivatedDelegateWrapper 290 { 291 void delegate(AppInfoIF, AppChooserWidget) dlg; 292 gulong handlerId; 293 294 this(void delegate(AppInfoIF, AppChooserWidget) dlg) 295 { 296 this.dlg = dlg; 297 onApplicationActivatedListeners ~= this; 298 } 299 300 void remove(OnApplicationActivatedDelegateWrapper source) 301 { 302 foreach(index, wrapper; onApplicationActivatedListeners) 303 { 304 if (wrapper.handlerId == source.handlerId) 305 { 306 onApplicationActivatedListeners[index] = null; 307 onApplicationActivatedListeners = std.algorithm.remove(onApplicationActivatedListeners, index); 308 break; 309 } 310 } 311 } 312 } 313 OnApplicationActivatedDelegateWrapper[] onApplicationActivatedListeners; 314 315 /** 316 * Emitted when an application item is activated from the widget's list. 317 * 318 * This usually happens when the user double clicks an item, or an item 319 * is selected and the user presses one of the keys Space, Shift+Space, 320 * Return or Enter. 321 * 322 * Params: 323 * application = the activated #GAppInfo 324 */ 325 gulong addOnApplicationActivated(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 326 { 327 auto wrapper = new OnApplicationActivatedDelegateWrapper(dlg); 328 wrapper.handlerId = Signals.connectData( 329 this, 330 "application-activated", 331 cast(GCallback)&callBackApplicationActivated, 332 cast(void*)wrapper, 333 cast(GClosureNotify)&callBackApplicationActivatedDestroy, 334 connectFlags); 335 return wrapper.handlerId; 336 } 337 338 extern(C) static void callBackApplicationActivated(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, OnApplicationActivatedDelegateWrapper wrapper) 339 { 340 wrapper.dlg(ObjectG.getDObject!(AppInfoIF)(application), wrapper.outer); 341 } 342 343 extern(C) static void callBackApplicationActivatedDestroy(OnApplicationActivatedDelegateWrapper wrapper, GClosure* closure) 344 { 345 wrapper.remove(wrapper); 346 } 347 348 protected class OnApplicationSelectedDelegateWrapper 349 { 350 void delegate(AppInfoIF, AppChooserWidget) dlg; 351 gulong handlerId; 352 353 this(void delegate(AppInfoIF, AppChooserWidget) dlg) 354 { 355 this.dlg = dlg; 356 onApplicationSelectedListeners ~= this; 357 } 358 359 void remove(OnApplicationSelectedDelegateWrapper source) 360 { 361 foreach(index, wrapper; onApplicationSelectedListeners) 362 { 363 if (wrapper.handlerId == source.handlerId) 364 { 365 onApplicationSelectedListeners[index] = null; 366 onApplicationSelectedListeners = std.algorithm.remove(onApplicationSelectedListeners, index); 367 break; 368 } 369 } 370 } 371 } 372 OnApplicationSelectedDelegateWrapper[] onApplicationSelectedListeners; 373 374 /** 375 * Emitted when an application item is selected from the widget's list. 376 * 377 * Params: 378 * application = the selected #GAppInfo 379 */ 380 gulong addOnApplicationSelected(void delegate(AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 381 { 382 auto wrapper = new OnApplicationSelectedDelegateWrapper(dlg); 383 wrapper.handlerId = Signals.connectData( 384 this, 385 "application-selected", 386 cast(GCallback)&callBackApplicationSelected, 387 cast(void*)wrapper, 388 cast(GClosureNotify)&callBackApplicationSelectedDestroy, 389 connectFlags); 390 return wrapper.handlerId; 391 } 392 393 extern(C) static void callBackApplicationSelected(GtkAppChooserWidget* appchooserwidgetStruct, GAppInfo* application, OnApplicationSelectedDelegateWrapper wrapper) 394 { 395 wrapper.dlg(ObjectG.getDObject!(AppInfoIF)(application), wrapper.outer); 396 } 397 398 extern(C) static void callBackApplicationSelectedDestroy(OnApplicationSelectedDelegateWrapper wrapper, GClosure* closure) 399 { 400 wrapper.remove(wrapper); 401 } 402 403 protected class OnPopulatePopupDelegateWrapper 404 { 405 void delegate(Menu, AppInfoIF, AppChooserWidget) dlg; 406 gulong handlerId; 407 408 this(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg) 409 { 410 this.dlg = dlg; 411 onPopulatePopupListeners ~= this; 412 } 413 414 void remove(OnPopulatePopupDelegateWrapper source) 415 { 416 foreach(index, wrapper; onPopulatePopupListeners) 417 { 418 if (wrapper.handlerId == source.handlerId) 419 { 420 onPopulatePopupListeners[index] = null; 421 onPopulatePopupListeners = std.algorithm.remove(onPopulatePopupListeners, index); 422 break; 423 } 424 } 425 } 426 } 427 OnPopulatePopupDelegateWrapper[] onPopulatePopupListeners; 428 429 /** 430 * Emitted when a context menu is about to popup over an application item. 431 * Clients can insert menu items into the provided #GtkMenu object in the 432 * callback of this signal; the context menu will be shown over the item 433 * if at least one item has been added to the menu. 434 * 435 * Params: 436 * menu = the #GtkMenu to populate 437 * application = the current #GAppInfo 438 */ 439 gulong addOnPopulatePopup(void delegate(Menu, AppInfoIF, AppChooserWidget) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 440 { 441 auto wrapper = new OnPopulatePopupDelegateWrapper(dlg); 442 wrapper.handlerId = Signals.connectData( 443 this, 444 "populate-popup", 445 cast(GCallback)&callBackPopulatePopup, 446 cast(void*)wrapper, 447 cast(GClosureNotify)&callBackPopulatePopupDestroy, 448 connectFlags); 449 return wrapper.handlerId; 450 } 451 452 extern(C) static void callBackPopulatePopup(GtkAppChooserWidget* appchooserwidgetStruct, GtkMenu* menu, GAppInfo* application, OnPopulatePopupDelegateWrapper wrapper) 453 { 454 wrapper.dlg(ObjectG.getDObject!(Menu)(menu), ObjectG.getDObject!(AppInfoIF)(application), wrapper.outer); 455 } 456 457 extern(C) static void callBackPopulatePopupDestroy(OnPopulatePopupDelegateWrapper wrapper, GClosure* closure) 458 { 459 wrapper.remove(wrapper); 460 } 461 }