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