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 vte.Pty;
26 
27 private import gio.Cancellable;
28 private import gio.InitableIF;
29 private import gio.InitableT;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.GException;
33 private import gobject.ObjectG;
34 private import vtec.vte;
35 public  import vtec.vtetypes;
36 
37 
38 public class Pty : ObjectG, InitableIF
39 {
40 	/** the main Gtk struct */
41 	protected VtePty* vtePty;
42 
43 	/** Get the main Gtk struct */
44 	public VtePty* getPtyStruct()
45 	{
46 		return vtePty;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected override void* getStruct()
51 	{
52 		return cast(void*)vtePty;
53 	}
54 
55 	protected override void setStruct(GObject* obj)
56 	{
57 		vtePty = cast(VtePty*)obj;
58 		super.setStruct(obj);
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (VtePty* vtePty, bool ownedRef = false)
65 	{
66 		this.vtePty = vtePty;
67 		super(cast(GObject*)vtePty, ownedRef);
68 	}
69 
70 	// add the Initable capabilities
71 	mixin InitableT!(VtePty);
72 
73 	/**
74 	 */
75 
76 	public static GType getType()
77 	{
78 		return vte_pty_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new #VtePty for the PTY master @fd.
83 	 *
84 	 * No entry will be made in the lastlog, utmp or wtmp system files.
85 	 *
86 	 * Note that the newly created #VtePty will take ownership of @fd
87 	 * and close it on finalize.
88 	 *
89 	 * Params:
90 	 *     fd = a file descriptor to the PTY
91 	 *     cancellable = a #GCancellable, or %NULL
92 	 *
93 	 * Return: a new #VtePty for @fd, or %NULL on error with @error filled in
94 	 *
95 	 * Throws: GException on failure.
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this(int fd, Cancellable cancellable)
99 	{
100 		GError* err = null;
101 		
102 		auto p = vte_pty_new_foreign_sync(fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
103 		
104 		if(p is null)
105 		{
106 			throw new ConstructionException("null returned by new_foreign_sync");
107 		}
108 		
109 		if (err !is null)
110 		{
111 			throw new GException( new ErrorG(err) );
112 		}
113 		
114 		this(cast(VtePty*) p, true);
115 	}
116 
117 	/**
118 	 * Allocates a new pseudo-terminal.
119 	 *
120 	 * You can later use fork() or the g_spawn_async() family of functions
121 	 * to start a process on the PTY.
122 	 *
123 	 * If using fork(), you MUST call vte_pty_child_setup() in the child.
124 	 *
125 	 * If using g_spawn_async() and friends, you MUST either use
126 	 * vte_pty_child_setup() directly as the child setup function, or call
127 	 * vte_pty_child_setup() from your own child setup function supplied.
128 	 *
129 	 * When using vte_terminal_spawn_sync() with a custom child setup
130 	 * function, vte_pty_child_setup() will be called before the supplied
131 	 * function; you must not call it again.
132 	 *
133 	 * Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
134 	 *
135 	 * If GNOME PTY Helper is available and
136 	 * unless some of the %VTE_PTY_NO_LASTLOG, %VTE_PTY_NO_UTMP or
137 	 * %VTE_PTY_NO_WTMP flags are passed in @flags, the
138 	 * session is logged in the corresponding lastlog, utmp or wtmp
139 	 * system files.  When passing %VTE_PTY_NO_HELPER in @flags, the
140 	 * GNOME PTY Helper is bypassed entirely.
141 	 *
142 	 * When passing %VTE_PTY_NO_FALLBACK in @flags,
143 	 * and opening a PTY using the PTY helper fails, there will
144 	 * be no fallback to allocate a PTY using Unix98 PTY functions.
145 	 *
146 	 * Params:
147 	 *     flags = flags from #VtePtyFlags
148 	 *     cancellable = a #GCancellable, or %NULL
149 	 *
150 	 * Return: a new #VtePty, or %NULL on error with @error filled in
151 	 *
152 	 * Throws: GException on failure.
153 	 * Throws: ConstructionException GTK+ fails to create the object.
154 	 */
155 	public this(VtePtyFlags flags, Cancellable cancellable)
156 	{
157 		GError* err = null;
158 		
159 		auto p = vte_pty_new_sync(flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
160 		
161 		if(p is null)
162 		{
163 			throw new ConstructionException("null returned by new_sync");
164 		}
165 		
166 		if (err !is null)
167 		{
168 			throw new GException( new ErrorG(err) );
169 		}
170 		
171 		this(cast(VtePty*) p, true);
172 	}
173 
174 	/**
175 	 * FIXMEchpe
176 	 */
177 	public void childSetup()
178 	{
179 		vte_pty_child_setup(vtePty);
180 	}
181 
182 	/**
183 	 * Cleans up the PTY, specifically any logging performed for the session.
184 	 * The file descriptor to the PTY master remains open.
185 	 */
186 	public void close()
187 	{
188 		vte_pty_close(vtePty);
189 	}
190 
191 	/**
192 	 * Return: the file descriptor of the PTY master in @pty. The
193 	 *     file descriptor belongs to @pty and must not be closed
194 	 */
195 	public int getFd()
196 	{
197 		return vte_pty_get_fd(vtePty);
198 	}
199 
200 	/**
201 	 * Reads the pseudo terminal's window size.
202 	 *
203 	 * If getting the window size failed, @error will be set to a #GIOError.
204 	 *
205 	 * Params:
206 	 *     rows = a location to store the number of rows, or %NULL
207 	 *     columns = a location to store the number of columns, or %NULL
208 	 *
209 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
210 	 *
211 	 * Throws: GException on failure.
212 	 */
213 	public bool getSize(out int rows, out int columns)
214 	{
215 		GError* err = null;
216 		
217 		auto p = vte_pty_get_size(vtePty, &rows, &columns, &err) != 0;
218 		
219 		if (err !is null)
220 		{
221 			throw new GException( new ErrorG(err) );
222 		}
223 		
224 		return p;
225 	}
226 
227 	/**
228 	 * Attempts to resize the pseudo terminal's window size.  If successful, the
229 	 * OS kernel will send #SIGWINCH to the child process group.
230 	 *
231 	 * If setting the window size failed, @error will be set to a #GIOError.
232 	 *
233 	 * Params:
234 	 *     rows = the desired number of rows
235 	 *     columns = the desired number of columns
236 	 *
237 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
238 	 *
239 	 * Throws: GException on failure.
240 	 */
241 	public bool setSize(int rows, int columns)
242 	{
243 		GError* err = null;
244 		
245 		auto p = vte_pty_set_size(vtePty, rows, columns, &err) != 0;
246 		
247 		if (err !is null)
248 		{
249 			throw new GException( new ErrorG(err) );
250 		}
251 		
252 		return p;
253 	}
254 
255 	/**
256 	 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
257 	 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
258 	 * discipline do multibyte backspace correctly.
259 	 *
260 	 * Params:
261 	 *     utf8 = whether or not the pty is in UTF-8 mode
262 	 *
263 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
264 	 *
265 	 * Throws: GException on failure.
266 	 */
267 	public bool setUtf8(bool utf8)
268 	{
269 		GError* err = null;
270 		
271 		auto p = vte_pty_set_utf8(vtePty, utf8, &err) != 0;
272 		
273 		if (err !is null)
274 		{
275 			throw new GException( new ErrorG(err) );
276 		}
277 		
278 		return p;
279 	}
280 }