1 module webkit2.PrintOperation; 2 3 private import glib.ConstructionException; 4 private import glib.ErrorG; 5 private import gobject.ObjectG; 6 private import gobject.Signals; 7 private import gtk.PageSetup; 8 private import gtk.PrintSettings; 9 private import gtk.Window; 10 private import std.algorithm; 11 private import webkit2.PrintCustomWidget; 12 private import webkit2.WebView; 13 private import webkit2.c.functions; 14 public import webkit2.c.types; 15 16 17 /** 18 * A #WebKitPrintOperation controls a print operation in WebKit. With 19 * a similar API to #GtkPrintOperation, it lets you set the print 20 * settings with webkit_print_operation_set_print_settings() or 21 * display the print dialog with webkit_print_operation_run_dialog(). 22 */ 23 public class PrintOperation : ObjectG 24 { 25 /** the main Gtk struct */ 26 protected WebKitPrintOperation* webKitPrintOperation; 27 28 /** Get the main Gtk struct */ 29 public WebKitPrintOperation* getPrintOperationStruct(bool transferOwnership = false) 30 { 31 if (transferOwnership) 32 ownedRef = false; 33 return webKitPrintOperation; 34 } 35 36 /** the main Gtk struct as a void* */ 37 protected override void* getStruct() 38 { 39 return cast(void*)webKitPrintOperation; 40 } 41 42 /** 43 * Sets our main struct and passes it to the parent class. 44 */ 45 public this (WebKitPrintOperation* webKitPrintOperation, bool ownedRef = false) 46 { 47 this.webKitPrintOperation = webKitPrintOperation; 48 super(cast(GObject*)webKitPrintOperation, ownedRef); 49 } 50 51 52 /** */ 53 public static GType getType() 54 { 55 return webkit_print_operation_get_type(); 56 } 57 58 /** 59 * Create a new #WebKitPrintOperation to print @web_view contents. 60 * 61 * Params: 62 * webView = a #WebKitWebView 63 * 64 * Returns: a new #WebKitPrintOperation. 65 * 66 * Throws: ConstructionException GTK+ fails to create the object. 67 */ 68 public this(WebView webView) 69 { 70 auto __p = webkit_print_operation_new((webView is null) ? null : webView.getWebViewStruct()); 71 72 if(__p is null) 73 { 74 throw new ConstructionException("null returned by new"); 75 } 76 77 this(cast(WebKitPrintOperation*) __p, true); 78 } 79 80 /** 81 * Return the current page setup of @print_operation. It returns %NULL until 82 * either webkit_print_operation_set_page_setup() or webkit_print_operation_run_dialog() 83 * have been called. 84 * 85 * Returns: the current #GtkPageSetup of @print_operation. 86 */ 87 public PageSetup getPageSetup() 88 { 89 auto __p = webkit_print_operation_get_page_setup(webKitPrintOperation); 90 91 if(__p is null) 92 { 93 return null; 94 } 95 96 return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) __p); 97 } 98 99 /** 100 * Return the current print settings of @print_operation. It returns %NULL until 101 * either webkit_print_operation_set_print_settings() or webkit_print_operation_run_dialog() 102 * have been called. 103 * 104 * Returns: the current #GtkPrintSettings of @print_operation. 105 */ 106 public PrintSettings getPrintSettings() 107 { 108 auto __p = webkit_print_operation_get_print_settings(webKitPrintOperation); 109 110 if(__p is null) 111 { 112 return null; 113 } 114 115 return ObjectG.getDObject!(PrintSettings)(cast(GtkPrintSettings*) __p); 116 } 117 118 /** 119 * Start a print operation using current print settings and page setup 120 * without showing the print dialog. If either print settings or page setup 121 * are not set with webkit_print_operation_set_print_settings() and 122 * webkit_print_operation_set_page_setup(), the default options will be used 123 * and the print job will be sent to the default printer. 124 * The #WebKitPrintOperation::finished signal is emitted when the printing 125 * operation finishes. If an error occurs while printing the signal 126 * #WebKitPrintOperation::failed is emitted before #WebKitPrintOperation::finished. 127 */ 128 public void print() 129 { 130 webkit_print_operation_print(webKitPrintOperation); 131 } 132 133 /** 134 * Run the print dialog and start printing using the options selected by 135 * the user. This method returns when the print dialog is closed. 136 * If the print dialog is cancelled %WEBKIT_PRINT_OPERATION_RESPONSE_CANCEL 137 * is returned. If the user clicks on the print button, %WEBKIT_PRINT_OPERATION_RESPONSE_PRINT 138 * is returned and the print operation starts. In this case, the #WebKitPrintOperation::finished 139 * signal is emitted when the operation finishes. If an error occurs while printing, the signal 140 * #WebKitPrintOperation::failed is emitted before #WebKitPrintOperation::finished. 141 * If the print dialog is not cancelled current print settings and page setup of @print_operation 142 * are updated with options selected by the user when Print button is pressed in print dialog. 143 * You can get the updated print settings and page setup by calling 144 * webkit_print_operation_get_print_settings() and webkit_print_operation_get_page_setup() 145 * after this method. 146 * 147 * Params: 148 * parent = transient parent of the print dialog 149 * 150 * Returns: the #WebKitPrintOperationResponse of the print dialog 151 */ 152 public WebKitPrintOperationResponse runDialog(Window parent) 153 { 154 return webkit_print_operation_run_dialog(webKitPrintOperation, (parent is null) ? null : parent.getWindowStruct()); 155 } 156 157 /** 158 * Set the current page setup of @print_operation. Current page setup is used for the 159 * initial values of the print dialog when webkit_print_operation_run_dialog() is called. 160 * 161 * Params: 162 * pageSetup = a #GtkPageSetup to set 163 */ 164 public void setPageSetup(PageSetup pageSetup) 165 { 166 webkit_print_operation_set_page_setup(webKitPrintOperation, (pageSetup is null) ? null : pageSetup.getPageSetupStruct()); 167 } 168 169 /** 170 * Set the current print settings of @print_operation. Current print settings are used for 171 * the initial values of the print dialog when webkit_print_operation_run_dialog() is called. 172 * 173 * Params: 174 * printSettings = a #GtkPrintSettings to set 175 */ 176 public void setPrintSettings(PrintSettings printSettings) 177 { 178 webkit_print_operation_set_print_settings(webKitPrintOperation, (printSettings is null) ? null : printSettings.getPrintSettingsStruct()); 179 } 180 181 /** 182 * Emitted when displaying the print dialog with webkit_print_operation_run_dialog(). 183 * The returned #WebKitPrintCustomWidget will be added to the print dialog and 184 * it will be owned by the @print_operation. However, the object is guaranteed 185 * to be alive until the #WebKitPrintCustomWidget::apply is emitted. 186 * 187 * Returns: A #WebKitPrintCustomWidget that will be embedded in the dialog. 188 * 189 * Since: 2.16 190 */ 191 gulong addOnCreateCustomWidget(PrintCustomWidget delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 192 { 193 return Signals.connect(this, "create-custom-widget", dlg, connectFlags ^ ConnectFlags.SWAPPED); 194 } 195 196 /** 197 * Emitted when an error occurs while printing. The given @error, of the domain 198 * %WEBKIT_PRINT_ERROR, contains further details of the failure. 199 * The #WebKitPrintOperation::finished signal is emitted after this one. 200 * 201 * Params: 202 * error = the #GError that was triggered 203 */ 204 gulong addOnFailed(void delegate(ErrorG, PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 205 { 206 return Signals.connect(this, "failed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 207 } 208 209 /** 210 * Emitted when the print operation has finished doing everything 211 * required for printing. 212 */ 213 gulong addOnFinished(void delegate(PrintOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 214 { 215 return Signals.connect(this, "finished", dlg, connectFlags ^ ConnectFlags.SWAPPED); 216 } 217 }