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