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()
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 	 * Returns: 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 	 * Returns: %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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	 * Returns: 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 	protected class OnAbortedDelegateWrapper
252 	{
253 		static OnAbortedDelegateWrapper[] listeners;
254 		void delegate(MountOperation) dlg;
255 		gulong handlerId;
256 		
257 		this(void delegate(MountOperation) dlg)
258 		{
259 			this.dlg = dlg;
260 			this.listeners ~= this;
261 		}
262 		
263 		void remove(OnAbortedDelegateWrapper source)
264 		{
265 			foreach(index, wrapper; listeners)
266 			{
267 				if (wrapper.handlerId == source.handlerId)
268 				{
269 					listeners[index] = null;
270 					listeners = std.algorithm.remove(listeners, index);
271 					break;
272 				}
273 			}
274 		}
275 	}
276 
277 	/**
278 	 * Emitted by the backend when e.g. a device becomes unavailable
279 	 * while a mount operation is in progress.
280 	 *
281 	 * Implementations of GMountOperation should handle this signal
282 	 * by dismissing open password dialogs.
283 	 *
284 	 * Since: 2.20
285 	 */
286 	gulong addOnAborted(void delegate(MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
287 	{
288 		auto wrapper = new OnAbortedDelegateWrapper(dlg);
289 		wrapper.handlerId = Signals.connectData(
290 			this,
291 			"aborted",
292 			cast(GCallback)&callBackAborted,
293 			cast(void*)wrapper,
294 			cast(GClosureNotify)&callBackAbortedDestroy,
295 			connectFlags);
296 		return wrapper.handlerId;
297 	}
298 	
299 	extern(C) static void callBackAborted(GMountOperation* mountoperationStruct, OnAbortedDelegateWrapper wrapper)
300 	{
301 		wrapper.dlg(wrapper.outer);
302 	}
303 	
304 	extern(C) static void callBackAbortedDestroy(OnAbortedDelegateWrapper wrapper, GClosure* closure)
305 	{
306 		wrapper.remove(wrapper);
307 	}
308 
309 	protected class OnAskPasswordDelegateWrapper
310 	{
311 		static OnAskPasswordDelegateWrapper[] listeners;
312 		void delegate(string, string, string, GAskPasswordFlags, MountOperation) dlg;
313 		gulong handlerId;
314 		
315 		this(void delegate(string, string, string, GAskPasswordFlags, MountOperation) dlg)
316 		{
317 			this.dlg = dlg;
318 			this.listeners ~= this;
319 		}
320 		
321 		void remove(OnAskPasswordDelegateWrapper source)
322 		{
323 			foreach(index, wrapper; listeners)
324 			{
325 				if (wrapper.handlerId == source.handlerId)
326 				{
327 					listeners[index] = null;
328 					listeners = std.algorithm.remove(listeners, index);
329 					break;
330 				}
331 			}
332 		}
333 	}
334 
335 	/**
336 	 * Emitted when a mount operation asks the user for a password.
337 	 *
338 	 * If the message contains a line break, the first line should be
339 	 * presented as a heading. For example, it may be used as the
340 	 * primary text in a #GtkMessageDialog.
341 	 *
342 	 * Params:
343 	 *     message = string containing a message to display to the user.
344 	 *     defaultUser = string containing the default user name.
345 	 *     defaultDomain = string containing the default domain.
346 	 *     flags = a set of #GAskPasswordFlags.
347 	 */
348 	gulong addOnAskPassword(void delegate(string, string, string, GAskPasswordFlags, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
349 	{
350 		auto wrapper = new OnAskPasswordDelegateWrapper(dlg);
351 		wrapper.handlerId = Signals.connectData(
352 			this,
353 			"ask-password",
354 			cast(GCallback)&callBackAskPassword,
355 			cast(void*)wrapper,
356 			cast(GClosureNotify)&callBackAskPasswordDestroy,
357 			connectFlags);
358 		return wrapper.handlerId;
359 	}
360 	
361 	extern(C) static void callBackAskPassword(GMountOperation* mountoperationStruct, char* message, char* defaultUser, char* defaultDomain, GAskPasswordFlags flags, OnAskPasswordDelegateWrapper wrapper)
362 	{
363 		wrapper.dlg(Str.toString(message), Str.toString(defaultUser), Str.toString(defaultDomain), flags, wrapper.outer);
364 	}
365 	
366 	extern(C) static void callBackAskPasswordDestroy(OnAskPasswordDelegateWrapper wrapper, GClosure* closure)
367 	{
368 		wrapper.remove(wrapper);
369 	}
370 
371 	protected class OnAskQuestionDelegateWrapper
372 	{
373 		static OnAskQuestionDelegateWrapper[] listeners;
374 		void delegate(string, string[], MountOperation) dlg;
375 		gulong handlerId;
376 		
377 		this(void delegate(string, string[], MountOperation) dlg)
378 		{
379 			this.dlg = dlg;
380 			this.listeners ~= this;
381 		}
382 		
383 		void remove(OnAskQuestionDelegateWrapper source)
384 		{
385 			foreach(index, wrapper; listeners)
386 			{
387 				if (wrapper.handlerId == source.handlerId)
388 				{
389 					listeners[index] = null;
390 					listeners = std.algorithm.remove(listeners, index);
391 					break;
392 				}
393 			}
394 		}
395 	}
396 
397 	/**
398 	 * Emitted when asking the user a question and gives a list of
399 	 * choices for the user to choose from.
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 	 *     choices = an array of strings for each possible choice.
408 	 */
409 	gulong addOnAskQuestion(void delegate(string, string[], MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
410 	{
411 		auto wrapper = new OnAskQuestionDelegateWrapper(dlg);
412 		wrapper.handlerId = Signals.connectData(
413 			this,
414 			"ask-question",
415 			cast(GCallback)&callBackAskQuestion,
416 			cast(void*)wrapper,
417 			cast(GClosureNotify)&callBackAskQuestionDestroy,
418 			connectFlags);
419 		return wrapper.handlerId;
420 	}
421 	
422 	extern(C) static void callBackAskQuestion(GMountOperation* mountoperationStruct, char* message, char** choices, OnAskQuestionDelegateWrapper wrapper)
423 	{
424 		wrapper.dlg(Str.toString(message), Str.toStringArray(choices), wrapper.outer);
425 	}
426 	
427 	extern(C) static void callBackAskQuestionDestroy(OnAskQuestionDelegateWrapper wrapper, GClosure* closure)
428 	{
429 		wrapper.remove(wrapper);
430 	}
431 
432 	protected class OnReplyDelegateWrapper
433 	{
434 		static OnReplyDelegateWrapper[] listeners;
435 		void delegate(GMountOperationResult, MountOperation) dlg;
436 		gulong handlerId;
437 		
438 		this(void delegate(GMountOperationResult, MountOperation) dlg)
439 		{
440 			this.dlg = dlg;
441 			this.listeners ~= this;
442 		}
443 		
444 		void remove(OnReplyDelegateWrapper source)
445 		{
446 			foreach(index, wrapper; listeners)
447 			{
448 				if (wrapper.handlerId == source.handlerId)
449 				{
450 					listeners[index] = null;
451 					listeners = std.algorithm.remove(listeners, index);
452 					break;
453 				}
454 			}
455 		}
456 	}
457 
458 	/**
459 	 * Emitted when the user has replied to the mount operation.
460 	 *
461 	 * Params:
462 	 *     result = a #GMountOperationResult indicating how the request was handled
463 	 */
464 	gulong addOnReply(void delegate(GMountOperationResult, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
465 	{
466 		auto wrapper = new OnReplyDelegateWrapper(dlg);
467 		wrapper.handlerId = Signals.connectData(
468 			this,
469 			"reply",
470 			cast(GCallback)&callBackReply,
471 			cast(void*)wrapper,
472 			cast(GClosureNotify)&callBackReplyDestroy,
473 			connectFlags);
474 		return wrapper.handlerId;
475 	}
476 	
477 	extern(C) static void callBackReply(GMountOperation* mountoperationStruct, GMountOperationResult result, OnReplyDelegateWrapper wrapper)
478 	{
479 		wrapper.dlg(result, wrapper.outer);
480 	}
481 	
482 	extern(C) static void callBackReplyDestroy(OnReplyDelegateWrapper wrapper, GClosure* closure)
483 	{
484 		wrapper.remove(wrapper);
485 	}
486 
487 	protected class OnShowProcessesDelegateWrapper
488 	{
489 		static OnShowProcessesDelegateWrapper[] listeners;
490 		void delegate(string, ArrayG, string[], MountOperation) dlg;
491 		gulong handlerId;
492 		
493 		this(void delegate(string, ArrayG, string[], MountOperation) dlg)
494 		{
495 			this.dlg = dlg;
496 			this.listeners ~= this;
497 		}
498 		
499 		void remove(OnShowProcessesDelegateWrapper source)
500 		{
501 			foreach(index, wrapper; listeners)
502 			{
503 				if (wrapper.handlerId == source.handlerId)
504 				{
505 					listeners[index] = null;
506 					listeners = std.algorithm.remove(listeners, index);
507 					break;
508 				}
509 			}
510 		}
511 	}
512 
513 	/**
514 	 * Emitted when one or more processes are blocking an operation
515 	 * e.g. unmounting/ejecting a #GMount or stopping a #GDrive.
516 	 *
517 	 * Note that this signal may be emitted several times to update the
518 	 * list of blocking processes as processes close files. The
519 	 * application should only respond with g_mount_operation_reply() to
520 	 * the latest signal (setting #GMountOperation:choice to the choice
521 	 * the user made).
522 	 *
523 	 * If the message contains a line break, the first line should be
524 	 * presented as a heading. For example, it may be used as the
525 	 * primary text in a #GtkMessageDialog.
526 	 *
527 	 * Params:
528 	 *     message = string containing a message to display to the user.
529 	 *     processes = an array of #GPid for processes
530 	 *         blocking the operation.
531 	 *     choices = an array of strings for each possible choice.
532 	 *
533 	 * Since: 2.22
534 	 */
535 	gulong addOnShowProcesses(void delegate(string, ArrayG, string[], MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
536 	{
537 		auto wrapper = new OnShowProcessesDelegateWrapper(dlg);
538 		wrapper.handlerId = Signals.connectData(
539 			this,
540 			"show-processes",
541 			cast(GCallback)&callBackShowProcesses,
542 			cast(void*)wrapper,
543 			cast(GClosureNotify)&callBackShowProcessesDestroy,
544 			connectFlags);
545 		return wrapper.handlerId;
546 	}
547 	
548 	extern(C) static void callBackShowProcesses(GMountOperation* mountoperationStruct, char* message, GArray* processes, char** choices, OnShowProcessesDelegateWrapper wrapper)
549 	{
550 		wrapper.dlg(Str.toString(message), new ArrayG(processes), Str.toStringArray(choices), wrapper.outer);
551 	}
552 	
553 	extern(C) static void callBackShowProcessesDestroy(OnShowProcessesDelegateWrapper wrapper, GClosure* closure)
554 	{
555 		wrapper.remove(wrapper);
556 	}
557 
558 	protected class OnShowUnmountProgressDelegateWrapper
559 	{
560 		static OnShowUnmountProgressDelegateWrapper[] listeners;
561 		void delegate(string, long, long, MountOperation) dlg;
562 		gulong handlerId;
563 		
564 		this(void delegate(string, long, long, MountOperation) dlg)
565 		{
566 			this.dlg = dlg;
567 			this.listeners ~= this;
568 		}
569 		
570 		void remove(OnShowUnmountProgressDelegateWrapper source)
571 		{
572 			foreach(index, wrapper; listeners)
573 			{
574 				if (wrapper.handlerId == source.handlerId)
575 				{
576 					listeners[index] = null;
577 					listeners = std.algorithm.remove(listeners, index);
578 					break;
579 				}
580 			}
581 		}
582 	}
583 
584 	/**
585 	 * Emitted when an unmount operation has been busy for more than some time
586 	 * (typically 1.5 seconds).
587 	 *
588 	 * When unmounting or ejecting a volume, the kernel might need to flush
589 	 * pending data in its buffers to the volume stable storage, and this operation
590 	 * can take a considerable amount of time. This signal may be emitted several
591 	 * times as long as the unmount operation is outstanding, and then one
592 	 * last time when the operation is completed, with @bytes_left set to zero.
593 	 *
594 	 * Implementations of GMountOperation should handle this signal by
595 	 * showing an UI notification, and then dismiss it, or show another notification
596 	 * of completion, when @bytes_left reaches zero.
597 	 *
598 	 * If the message contains a line break, the first line should be
599 	 * presented as a heading. For example, it may be used as the
600 	 * primary text in a #GtkMessageDialog.
601 	 *
602 	 * Params:
603 	 *     message = string containing a mesage to display to the user
604 	 *     timeLeft = the estimated time left before the operation completes,
605 	 *         in microseconds, or -1
606 	 *     bytesLeft = the amount of bytes to be written before the operation
607 	 *         completes (or -1 if such amount is not known), or zero if the operation
608 	 *         is completed
609 	 *
610 	 * Since: 2.34
611 	 */
612 	gulong addOnShowUnmountProgress(void delegate(string, long, long, MountOperation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
613 	{
614 		auto wrapper = new OnShowUnmountProgressDelegateWrapper(dlg);
615 		wrapper.handlerId = Signals.connectData(
616 			this,
617 			"show-unmount-progress",
618 			cast(GCallback)&callBackShowUnmountProgress,
619 			cast(void*)wrapper,
620 			cast(GClosureNotify)&callBackShowUnmountProgressDestroy,
621 			connectFlags);
622 		return wrapper.handlerId;
623 	}
624 	
625 	extern(C) static void callBackShowUnmountProgress(GMountOperation* mountoperationStruct, char* message, long timeLeft, long bytesLeft, OnShowUnmountProgressDelegateWrapper wrapper)
626 	{
627 		wrapper.dlg(Str.toString(message), timeLeft, bytesLeft, wrapper.outer);
628 	}
629 	
630 	extern(C) static void callBackShowUnmountProgressDestroy(OnShowUnmountProgressDelegateWrapper wrapper, GClosure* closure)
631 	{
632 		wrapper.remove(wrapper);
633 	}
634 }