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 /** */
39 public class Pty : ObjectG, InitableIF
40 {
41 	/** the main Gtk struct */
42 	protected VtePty* vtePty;
43 
44 	/** Get the main Gtk struct */
45 	public VtePty* getPtyStruct()
46 	{
47 		return vtePty;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected override void* getStruct()
52 	{
53 		return cast(void*)vtePty;
54 	}
55 
56 	protected override void setStruct(GObject* obj)
57 	{
58 		vtePty = cast(VtePty*)obj;
59 		super.setStruct(obj);
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (VtePty* vtePty, bool ownedRef = false)
66 	{
67 		this.vtePty = vtePty;
68 		super(cast(GObject*)vtePty, ownedRef);
69 	}
70 
71 	// add the Initable capabilities
72 	mixin InitableT!(VtePty);
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 (err !is null)
105 		{
106 			throw new GException( new ErrorG(err) );
107 		}
108 		
109 		if(p is null)
110 		{
111 			throw new ConstructionException("null returned by new_foreign_sync");
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 	 * Params:
136 	 *     flags = flags from #VtePtyFlags
137 	 *     cancellable = a #GCancellable, or %NULL
138 	 *
139 	 * Return: a new #VtePty, or %NULL on error with @error filled in
140 	 *
141 	 * Throws: GException on failure.
142 	 * Throws: ConstructionException GTK+ fails to create the object.
143 	 */
144 	public this(VtePtyFlags flags, Cancellable cancellable)
145 	{
146 		GError* err = null;
147 		
148 		auto p = vte_pty_new_sync(flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
149 		
150 		if (err !is null)
151 		{
152 			throw new GException( new ErrorG(err) );
153 		}
154 		
155 		if(p is null)
156 		{
157 			throw new ConstructionException("null returned by new_sync");
158 		}
159 		
160 		this(cast(VtePty*) p, true);
161 	}
162 
163 	/**
164 	 * FIXMEchpe
165 	 */
166 	public void childSetup()
167 	{
168 		vte_pty_child_setup(vtePty);
169 	}
170 
171 	/**
172 	 * Since 0.42 this is a no-op.
173 	 */
174 	public void close()
175 	{
176 		vte_pty_close(vtePty);
177 	}
178 
179 	/**
180 	 * Return: the file descriptor of the PTY master in @pty. The
181 	 *     file descriptor belongs to @pty and must not be closed
182 	 */
183 	public int getFd()
184 	{
185 		return vte_pty_get_fd(vtePty);
186 	}
187 
188 	/**
189 	 * Reads the pseudo terminal's window size.
190 	 *
191 	 * If getting the window size failed, @error will be set to a #GIOError.
192 	 *
193 	 * Params:
194 	 *     rows = a location to store the number of rows, or %NULL
195 	 *     columns = a location to store the number of columns, or %NULL
196 	 *
197 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
198 	 *
199 	 * Throws: GException on failure.
200 	 */
201 	public bool getSize(out int rows, out int columns)
202 	{
203 		GError* err = null;
204 		
205 		auto p = vte_pty_get_size(vtePty, &rows, &columns, &err) != 0;
206 		
207 		if (err !is null)
208 		{
209 			throw new GException( new ErrorG(err) );
210 		}
211 		
212 		return p;
213 	}
214 
215 	/**
216 	 * Attempts to resize the pseudo terminal's window size.  If successful, the
217 	 * OS kernel will send #SIGWINCH to the child process group.
218 	 *
219 	 * If setting the window size failed, @error will be set to a #GIOError.
220 	 *
221 	 * Params:
222 	 *     rows = the desired number of rows
223 	 *     columns = the desired number of columns
224 	 *
225 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
226 	 *
227 	 * Throws: GException on failure.
228 	 */
229 	public bool setSize(int rows, int columns)
230 	{
231 		GError* err = null;
232 		
233 		auto p = vte_pty_set_size(vtePty, rows, columns, &err) != 0;
234 		
235 		if (err !is null)
236 		{
237 			throw new GException( new ErrorG(err) );
238 		}
239 		
240 		return p;
241 	}
242 
243 	/**
244 	 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
245 	 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
246 	 * discipline do multibyte backspace correctly.
247 	 *
248 	 * Params:
249 	 *     utf8 = whether or not the pty is in UTF-8 mode
250 	 *
251 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
252 	 *
253 	 * Throws: GException on failure.
254 	 */
255 	public bool setUtf8(bool utf8)
256 	{
257 		GError* err = null;
258 		
259 		auto p = vte_pty_set_utf8(vtePty, utf8, &err) != 0;
260 		
261 		if (err !is null)
262 		{
263 			throw new GException( new ErrorG(err) );
264 		}
265 		
266 		return p;
267 	}
268 }