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