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