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 gio.MountOperation; 26 27 private import glib.ArrayG; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 public import gtkc.gdktypes; 33 private import gtkc.gio; 34 public import gtkc.giotypes; 35 36 37 /** 38 * #GMountOperation provides a mechanism for interacting with the user. 39 * It can be used for authenticating mountable operations, such as loop 40 * mounting files, hard drive partitions or server locations. It can 41 * also be used to ask the user questions or show a list of applications 42 * preventing unmount or eject operations from completing. 43 * 44 * Note that #GMountOperation is used for more than just #GMount 45 * objects – for example it is also used in g_drive_start() and 46 * g_drive_stop(). 47 * 48 * Users should instantiate a subclass of this that implements all the 49 * various callbacks to show the required dialogs, such as 50 * #GtkMountOperation. If no user interaction is desired (for example 51 * when automounting filesystems at login time), usually %NULL can be 52 * passed, see each method taking a #GMountOperation for details. 53 */ 54 public class MountOperation : ObjectG 55 { 56 /** the main Gtk struct */ 57 protected GMountOperation* gMountOperation; 58 59 /** Get the main Gtk struct */ 60 public GMountOperation* getMountOperationStruct() 61 { 62 return gMountOperation; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gMountOperation; 69 } 70 71 protected override void setStruct(GObject* obj) 72 { 73 gMountOperation = cast(GMountOperation*)obj; 74 super.setStruct(obj); 75 } 76 77 /** 78 * Sets our main struct and passes it to the parent class. 79 */ 80 public this (GMountOperation* gMountOperation, bool ownedRef = false) 81 { 82 this.gMountOperation = gMountOperation; 83 super(cast(GObject*)gMountOperation, ownedRef); 84 } 85 86 87 /** */ 88 public static GType getType() 89 { 90 return g_mount_operation_get_type(); 91 } 92 93 /** 94 * Creates a new mount operation. 95 * 96 * Return: a #GMountOperation. 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this() 101 { 102 auto p = g_mount_operation_new(); 103 104 if(p is null) 105 { 106 throw new ConstructionException("null returned by new"); 107 } 108 109 this(cast(GMountOperation*) p, true); 110 } 111 112 /** 113 * Check to see whether the mount operation is being used 114 * for an anonymous user. 115 * 116 * Return: %TRUE if mount operation is anonymous. 117 */ 118 public bool getAnonymous() 119 { 120 return g_mount_operation_get_anonymous(gMountOperation) != 0; 121 } 122 123 /** 124 * Gets a choice from the mount operation. 125 * 126 * Return: an integer containing an index of the user's choice from 127 * the choice's list, or %0. 128 */ 129 public int getChoice() 130 { 131 return g_mount_operation_get_choice(gMountOperation); 132 } 133 134 /** 135 * Gets the domain of the mount operation. 136 * 137 * Return: a string set to the domain. 138 */ 139 public string getDomain() 140 { 141 return Str.toString(g_mount_operation_get_domain(gMountOperation)); 142 } 143 144 /** 145 * Gets a password from the mount operation. 146 * 147 * Return: a string containing the password within @op. 148 */ 149 public string getPassword() 150 { 151 return Str.toString(g_mount_operation_get_password(gMountOperation)); 152 } 153 154 /** 155 * Gets the state of saving passwords for the mount operation. 156 * 157 * Return: a #GPasswordSave flag. 158 */ 159 public GPasswordSave getPasswordSave() 160 { 161 return g_mount_operation_get_password_save(gMountOperation); 162 } 163 164 /** 165 * Get the user name from the mount operation. 166 * 167 * Return: a string containing the user name. 168 */ 169 public string getUsername() 170 { 171 return Str.toString(g_mount_operation_get_username(gMountOperation)); 172 } 173 174 /** 175 * Emits the #GMountOperation::reply signal. 176 * 177 * Params: 178 * result = a #GMountOperationResult 179 */ 180 public void reply(GMountOperationResult result) 181 { 182 g_mount_operation_reply(gMountOperation, result); 183 } 184 185 /** 186 * Sets the mount operation to use an anonymous user if @anonymous is %TRUE. 187 * 188 * Params: 189 * anonymous = boolean value. 190 */ 191 public void setAnonymous(bool anonymous) 192 { 193 g_mount_operation_set_anonymous(gMountOperation, anonymous); 194 } 195 196 /** 197 * Sets a default choice for the mount operation. 198 * 199 * Params: 200 * choice = an integer. 201 */ 202 public void setChoice(int choice) 203 { 204 g_mount_operation_set_choice(gMountOperation, choice); 205 } 206 207 /** 208 * Sets the mount operation's domain. 209 * 210 * Params: 211 * domain = the domain to set. 212 */ 213 public void setDomain(string domain) 214 { 215 g_mount_operation_set_domain(gMountOperation, Str.toStringz(domain)); 216 } 217 218 /** 219 * Sets the mount operation's password to @password. 220 * 221 * Params: 222 * password = password to set. 223 */ 224 public void setPassword(string password) 225 { 226 g_mount_operation_set_password(gMountOperation, Str.toStringz(password)); 227 } 228 229 /** 230 * Sets the state of saving passwords for the mount operation. 231 * 232 * Params: 233 * save = a set of #GPasswordSave flags. 234 */ 235 public void setPasswordSave(GPasswordSave save) 236 { 237 g_mount_operation_set_password_save(gMountOperation, save); 238 } 239 240 /** 241 * Sets the user name within @op to @username. 242 * 243 * Params: 244 * username = input username. 245 */ 246 public void setUsername(string username) 247 { 248 g_mount_operation_set_username(gMountOperation, Str.toStringz(username)); 249 } 250 251 int[string] connectedSignals; 252 253 void delegate(MountOperation)[] onAbortedListeners; 254 /** 255 * Emitted by the backend when e.g. a device becomes unavailable 256 * while a mount operation is in progress. 257 * 258 * Implementations of GMountOperation should handle this signal 259 * by dismissing open password dialogs. 260 * 261 * Since: 2.20 262 */ 263 void addOnAborted(void delegate(MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 264 { 265 if ( "aborted" !in connectedSignals ) 266 { 267 Signals.connectData( 268 this, 269 "aborted", 270 cast(GCallback)&callBackAborted, 271 cast(void*)this, 272 null, 273 connectFlags); 274 connectedSignals["aborted"] = 1; 275 } 276 onAbortedListeners ~= dlg; 277 } 278 extern(C) static void callBackAborted(GMountOperation* mountoperationStruct, MountOperation _mountoperation) 279 { 280 foreach ( void delegate(MountOperation) dlg; _mountoperation.onAbortedListeners ) 281 { 282 dlg(_mountoperation); 283 } 284 } 285 286 void delegate(string, string, string, GAskPasswordFlags, MountOperation)[] onAskPasswordListeners; 287 /** 288 * Emitted when a mount operation asks the user for a password. 289 * 290 * If the message contains a line break, the first line should be 291 * presented as a heading. For example, it may be used as the 292 * primary text in a #GtkMessageDialog. 293 * 294 * Params: 295 * message = string containing a message to display to the user. 296 * defaultUser = string containing the default user name. 297 * defaultDomain = string containing the default domain. 298 * flags = a set of #GAskPasswordFlags. 299 */ 300 void addOnAskPassword(void delegate(string, string, string, GAskPasswordFlags, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 301 { 302 if ( "ask-password" !in connectedSignals ) 303 { 304 Signals.connectData( 305 this, 306 "ask-password", 307 cast(GCallback)&callBackAskPassword, 308 cast(void*)this, 309 null, 310 connectFlags); 311 connectedSignals["ask-password"] = 1; 312 } 313 onAskPasswordListeners ~= dlg; 314 } 315 extern(C) static void callBackAskPassword(GMountOperation* mountoperationStruct, char* message, char* defaultUser, char* defaultDomain, GAskPasswordFlags flags, MountOperation _mountoperation) 316 { 317 foreach ( void delegate(string, string, string, GAskPasswordFlags, MountOperation) dlg; _mountoperation.onAskPasswordListeners ) 318 { 319 dlg(Str.toString(message), Str.toString(defaultUser), Str.toString(defaultDomain), flags, _mountoperation); 320 } 321 } 322 323 void delegate(string, string[], MountOperation)[] onAskQuestionListeners; 324 /** 325 * Emitted when asking the user a question and gives a list of 326 * choices for the user to choose from. 327 * 328 * If the message contains a line break, the first line should be 329 * presented as a heading. For example, it may be used as the 330 * primary text in a #GtkMessageDialog. 331 * 332 * Params: 333 * message = string containing a message to display to the user. 334 * choices = an array of strings for each possible choice. 335 */ 336 void addOnAskQuestion(void delegate(string, string[], MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 337 { 338 if ( "ask-question" !in connectedSignals ) 339 { 340 Signals.connectData( 341 this, 342 "ask-question", 343 cast(GCallback)&callBackAskQuestion, 344 cast(void*)this, 345 null, 346 connectFlags); 347 connectedSignals["ask-question"] = 1; 348 } 349 onAskQuestionListeners ~= dlg; 350 } 351 extern(C) static void callBackAskQuestion(GMountOperation* mountoperationStruct, char* message, char** choices, MountOperation _mountoperation) 352 { 353 foreach ( void delegate(string, string[], MountOperation) dlg; _mountoperation.onAskQuestionListeners ) 354 { 355 dlg(Str.toString(message), Str.toStringArray(choices), _mountoperation); 356 } 357 } 358 359 void delegate(GMountOperationResult, MountOperation)[] onReplyListeners; 360 /** 361 * Emitted when the user has replied to the mount operation. 362 * 363 * Params: 364 * result = a #GMountOperationResult indicating how the request was handled 365 */ 366 void addOnReply(void delegate(GMountOperationResult, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 367 { 368 if ( "reply" !in connectedSignals ) 369 { 370 Signals.connectData( 371 this, 372 "reply", 373 cast(GCallback)&callBackReply, 374 cast(void*)this, 375 null, 376 connectFlags); 377 connectedSignals["reply"] = 1; 378 } 379 onReplyListeners ~= dlg; 380 } 381 extern(C) static void callBackReply(GMountOperation* mountoperationStruct, GMountOperationResult result, MountOperation _mountoperation) 382 { 383 foreach ( void delegate(GMountOperationResult, MountOperation) dlg; _mountoperation.onReplyListeners ) 384 { 385 dlg(result, _mountoperation); 386 } 387 } 388 389 void delegate(string, ArrayG, string[], MountOperation)[] onShowProcessesListeners; 390 /** 391 * Emitted when one or more processes are blocking an operation 392 * e.g. unmounting/ejecting a #GMount or stopping a #GDrive. 393 * 394 * Note that this signal may be emitted several times to update the 395 * list of blocking processes as processes close files. The 396 * application should only respond with g_mount_operation_reply() to 397 * the latest signal (setting #GMountOperation:choice to the choice 398 * the user made). 399 * 400 * If the message contains a line break, the first line should be 401 * presented as a heading. For example, it may be used as the 402 * primary text in a #GtkMessageDialog. 403 * 404 * Params: 405 * message = string containing a message to display to the user. 406 * processes = an array of #GPid for processes 407 * blocking the operation. 408 * choices = an array of strings for each possible choice. 409 * 410 * Since: 2.22 411 */ 412 void addOnShowProcesses(void delegate(string, ArrayG, string[], MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 413 { 414 if ( "show-processes" !in connectedSignals ) 415 { 416 Signals.connectData( 417 this, 418 "show-processes", 419 cast(GCallback)&callBackShowProcesses, 420 cast(void*)this, 421 null, 422 connectFlags); 423 connectedSignals["show-processes"] = 1; 424 } 425 onShowProcessesListeners ~= dlg; 426 } 427 extern(C) static void callBackShowProcesses(GMountOperation* mountoperationStruct, char* message, GArray* processes, char** choices, MountOperation _mountoperation) 428 { 429 foreach ( void delegate(string, ArrayG, string[], MountOperation) dlg; _mountoperation.onShowProcessesListeners ) 430 { 431 dlg(Str.toString(message), new ArrayG(processes), Str.toStringArray(choices), _mountoperation); 432 } 433 } 434 435 void delegate(string, long, long, MountOperation)[] onShowUnmountProgressListeners; 436 /** 437 * Emitted when an unmount operation has been busy for more than some time 438 * (typically 1.5 seconds). 439 * 440 * When unmounting or ejecting a volume, the kernel might need to flush 441 * pending data in its buffers to the volume stable storage, and this operation 442 * can take a considerable amount of time. This signal may be emitted several 443 * times as long as the unmount operation is outstanding, and then one 444 * last time when the operation is completed, with @bytes_left set to zero. 445 * 446 * Implementations of GMountOperation should handle this signal by 447 * showing an UI notification, and then dismiss it, or show another notification 448 * of completion, when @bytes_left reaches zero. 449 * 450 * If the message contains a line break, the first line should be 451 * presented as a heading. For example, it may be used as the 452 * primary text in a #GtkMessageDialog. 453 * 454 * Params: 455 * message = string containing a mesage to display to the user 456 * timeLeft = the estimated time left before the operation completes, 457 * in microseconds, or -1 458 * bytesLeft = the amount of bytes to be written before the operation 459 * completes (or -1 if such amount is not known), or zero if the operation 460 * is completed 461 * 462 * Since: 2.34 463 */ 464 void addOnShowUnmountProgress(void delegate(string, long, long, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 465 { 466 if ( "show-unmount-progress" !in connectedSignals ) 467 { 468 Signals.connectData( 469 this, 470 "show-unmount-progress", 471 cast(GCallback)&callBackShowUnmountProgress, 472 cast(void*)this, 473 null, 474 connectFlags); 475 connectedSignals["show-unmount-progress"] = 1; 476 } 477 onShowUnmountProgressListeners ~= dlg; 478 } 479 extern(C) static void callBackShowUnmountProgress(GMountOperation* mountoperationStruct, char* message, long timeLeft, long bytesLeft, MountOperation _mountoperation) 480 { 481 foreach ( void delegate(string, long, long, MountOperation) dlg; _mountoperation.onShowUnmountProgressListeners ) 482 { 483 dlg(Str.toString(message), timeLeft, bytesLeft, _mountoperation); 484 } 485 } 486 }