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