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 	 * Return: the file descriptor of the PTY master in @pty. The
173 	 *     file descriptor belongs to @pty and must not be closed
174 	 */
175 	public int getFd()
176 	{
177 		return vte_pty_get_fd(vtePty);
178 	}
179 
180 	/**
181 	 * Reads the pseudo terminal's window size.
182 	 *
183 	 * If getting the window size failed, @error will be set to a #GIOError.
184 	 *
185 	 * Params:
186 	 *     rows = a location to store the number of rows, or %NULL
187 	 *     columns = a location to store the number of columns, or %NULL
188 	 *
189 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
190 	 *
191 	 * Throws: GException on failure.
192 	 */
193 	public bool getSize(out int rows, out int columns)
194 	{
195 		GError* err = null;
196 		
197 		auto p = vte_pty_get_size(vtePty, &rows, &columns, &err) != 0;
198 		
199 		if (err !is null)
200 		{
201 			throw new GException( new ErrorG(err) );
202 		}
203 		
204 		return p;
205 	}
206 
207 	/**
208 	 * Attempts to resize the pseudo terminal's window size.  If successful, the
209 	 * OS kernel will send #SIGWINCH to the child process group.
210 	 *
211 	 * If setting the window size failed, @error will be set to a #GIOError.
212 	 *
213 	 * Params:
214 	 *     rows = the desired number of rows
215 	 *     columns = the desired number of columns
216 	 *
217 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
218 	 *
219 	 * Throws: GException on failure.
220 	 */
221 	public bool setSize(int rows, int columns)
222 	{
223 		GError* err = null;
224 		
225 		auto p = vte_pty_set_size(vtePty, rows, columns, &err) != 0;
226 		
227 		if (err !is null)
228 		{
229 			throw new GException( new ErrorG(err) );
230 		}
231 		
232 		return p;
233 	}
234 
235 	/**
236 	 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
237 	 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
238 	 * discipline do multibyte backspace correctly.
239 	 *
240 	 * Params:
241 	 *     utf8 = whether or not the pty is in UTF-8 mode
242 	 *
243 	 * Return: %TRUE on success, %FALSE on failure with @error filled in
244 	 *
245 	 * Throws: GException on failure.
246 	 */
247 	public bool setUtf8(bool utf8)
248 	{
249 		GError* err = null;
250 		
251 		auto p = vte_pty_set_utf8(vtePty, utf8, &err) != 0;
252 		
253 		if (err !is null)
254 		{
255 			throw new GException( new ErrorG(err) );
256 		}
257 		
258 		return p;
259 	}
260 }