1 /*
2  * vinagre-vnc-connection.c
3  * Child class of abstract VinagreConnection, specific to VNC protocol
4  * This file is part of vinagre
5  *
6  * Copyright (C) 2009-2010 - Jonh Wendell <wendell@bani.com.br>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <config.h>
23 #include <glib/gi18n.h>
24 #include <stdlib.h>
25 #include <vinagre/vinagre-cache-prefs.h>
26 
27 #include "vinagre-vnc-connection.h"
28 #include "vinagre-vala.h"
29 
30 gboolean scaling_command_line;
31 
32 struct _VinagreVncConnectionPrivate
33 {
34   gchar    *desktop_name;
35   gboolean view_only;
36   gboolean scaling;
37   gboolean keep_ratio;
38   gint     shared;
39   gint     fd;
40   gint     depth_profile;
41   gboolean lossy_encoding;
42   gchar    *ssh_tunnel_host;
43   GSocket  *socket;
44 };
45 
46 enum
47 {
48   PROP_0,
49   PROP_DESKTOP_NAME,
50   PROP_VIEW_ONLY,
51   PROP_SCALING,
52   PROP_KEEP_RATIO,
53   PROP_SHARED,
54   PROP_FD,
55   PROP_DEPTH_PROFILE,
56   PROP_LOSSY_ENCODING,
57   PROP_SSH_TUNNEL_HOST,
58   PROP_SOCKET
59 };
60 
61 #define VINAGRE_VNC_CONNECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), VINAGRE_TYPE_VNC_CONNECTION, VinagreVncConnectionPrivate))
62 G_DEFINE_TYPE (VinagreVncConnection, vinagre_vnc_connection, VINAGRE_TYPE_CONNECTION);
63 
64 static void
vinagre_vnc_connection_init(VinagreVncConnection * conn)65 vinagre_vnc_connection_init (VinagreVncConnection *conn)
66 {
67   conn->priv = G_TYPE_INSTANCE_GET_PRIVATE (conn, VINAGRE_TYPE_VNC_CONNECTION, VinagreVncConnectionPrivate);
68 
69   conn->priv->desktop_name = NULL;
70   conn->priv->view_only = FALSE;
71   conn->priv->scaling = FALSE;
72   conn->priv->keep_ratio = FALSE;
73   conn->priv->shared = -1;
74   conn->priv->fd = 0;
75   conn->priv->depth_profile = 0;
76   conn->priv->lossy_encoding = FALSE;
77   conn->priv->ssh_tunnel_host = NULL;
78   conn->priv->socket = NULL;
79 }
80 
81 static void
vinagre_vnc_connection_constructed(GObject * object)82 vinagre_vnc_connection_constructed (GObject *object)
83 {
84   vinagre_connection_set_protocol (VINAGRE_CONNECTION (object), "vnc");
85 }
86 
87 static void
vinagre_vnc_connection_finalize(GObject * object)88 vinagre_vnc_connection_finalize (GObject *object)
89 {
90   VinagreVncConnection *conn = VINAGRE_VNC_CONNECTION (object);
91 
92   g_free (conn->priv->desktop_name);
93   g_free (conn->priv->ssh_tunnel_host);
94 
95   G_OBJECT_CLASS (vinagre_vnc_connection_parent_class)->finalize (object);
96 }
97 
98 static void
vinagre_vnc_connection_dispose(GObject * object)99 vinagre_vnc_connection_dispose (GObject *object)
100 {
101   VinagreVncConnection *conn = VINAGRE_VNC_CONNECTION (object);
102 
103   if (conn->priv->socket)
104     {
105       g_object_unref (conn->priv->socket);
106       conn->priv->socket = NULL;
107     }
108 
109   G_OBJECT_CLASS (vinagre_vnc_connection_parent_class)->dispose (object);
110 }
111 
112 static void
vinagre_vnc_connection_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)113 vinagre_vnc_connection_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
114 {
115   VinagreVncConnection *conn;
116 
117   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (object));
118 
119   conn = VINAGRE_VNC_CONNECTION (object);
120 
121   switch (prop_id)
122     {
123       case PROP_DESKTOP_NAME:
124 	vinagre_vnc_connection_set_desktop_name (conn, g_value_get_string (value));
125 	break;
126 
127       case PROP_VIEW_ONLY:
128 	vinagre_vnc_connection_set_view_only (conn, g_value_get_boolean (value));
129 	break;
130 
131       case PROP_SCALING:
132 	vinagre_vnc_connection_set_scaling (conn, g_value_get_boolean (value));
133 	break;
134 
135       case PROP_KEEP_RATIO:
136 	vinagre_vnc_connection_set_keep_ratio (conn, g_value_get_boolean (value));
137 	break;
138 
139       case PROP_SHARED:
140 	vinagre_vnc_connection_set_shared (conn, g_value_get_int (value));
141 	break;
142 
143       case PROP_FD:
144 	vinagre_vnc_connection_set_fd (conn, g_value_get_int (value));
145 	break;
146 
147       case PROP_DEPTH_PROFILE:
148 	vinagre_vnc_connection_set_depth_profile (conn, g_value_get_int (value));
149 	break;
150 
151       case PROP_LOSSY_ENCODING:
152 	vinagre_vnc_connection_set_lossy_encoding (conn, g_value_get_boolean (value));
153 	break;
154 
155       case PROP_SSH_TUNNEL_HOST:
156 	vinagre_vnc_connection_set_ssh_tunnel_host (conn, g_value_get_string (value));
157 	break;
158 
159       case PROP_SOCKET:
160 	vinagre_vnc_connection_set_socket (conn, g_value_get_object (value));
161 	break;
162 
163       default:
164 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 	break;
166     }
167 }
168 
169 static void
vinagre_vnc_connection_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)170 vinagre_vnc_connection_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
171 {
172   VinagreVncConnection *conn;
173 
174   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (object));
175 
176   conn = VINAGRE_VNC_CONNECTION (object);
177 
178   switch (prop_id)
179     {
180       case PROP_DESKTOP_NAME:
181 	g_value_set_string (value, conn->priv->desktop_name);
182 	break;
183 
184       case PROP_VIEW_ONLY:
185 	g_value_set_boolean (value, conn->priv->view_only);
186 	break;
187 
188       case PROP_SCALING:
189 	g_value_set_boolean (value, conn->priv->scaling);
190 	break;
191 
192       case PROP_KEEP_RATIO:
193 	g_value_set_boolean (value, conn->priv->keep_ratio);
194 	break;
195 
196       case PROP_SHARED:
197 	g_value_set_int (value, conn->priv->shared);
198 	break;
199 
200       case PROP_FD:
201 	g_value_set_int (value, vinagre_vnc_connection_get_fd (conn));
202 	break;
203 
204       case PROP_DEPTH_PROFILE:
205 	g_value_set_int (value, conn->priv->depth_profile);
206 	break;
207 
208       case PROP_LOSSY_ENCODING:
209 	g_value_set_boolean (value, conn->priv->lossy_encoding);
210 	break;
211 
212       case PROP_SSH_TUNNEL_HOST:
213 	g_value_set_string (value, conn->priv->ssh_tunnel_host);
214 	break;
215 
216       case PROP_SOCKET:
217 	g_value_set_object (value, conn->priv->socket);
218 	break;
219 
220       default:
221 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222 	break;
223     }
224 }
225 
226 static void
vnc_fill_writer(VinagreConnection * conn,xmlTextWriter * writer)227 vnc_fill_writer (VinagreConnection *conn, xmlTextWriter *writer)
228 {
229   VinagreVncConnection *vnc_conn = VINAGRE_VNC_CONNECTION (conn);
230   VINAGRE_CONNECTION_CLASS (vinagre_vnc_connection_parent_class)->impl_fill_writer (conn, writer);
231 
232   xmlTextWriterWriteFormatElement (writer, BAD_CAST "view_only", "%d", vnc_conn->priv->view_only);
233   xmlTextWriterWriteFormatElement (writer, BAD_CAST "scaling", "%d", vnc_conn->priv->scaling);
234   xmlTextWriterWriteFormatElement (writer, BAD_CAST "keep_ratio", "%d", vnc_conn->priv->keep_ratio);
235   xmlTextWriterWriteFormatElement (writer, BAD_CAST "depth_profile", "%d", vnc_conn->priv->depth_profile);
236   xmlTextWriterWriteFormatElement (writer, BAD_CAST "lossy_encoding", "%d", vnc_conn->priv->lossy_encoding);
237 
238   if (vnc_conn->priv->ssh_tunnel_host && *vnc_conn->priv->ssh_tunnel_host)
239     xmlTextWriterWriteFormatElement (writer, BAD_CAST "ssh_tunnel_host", "%s", vnc_conn->priv->ssh_tunnel_host);
240 }
241 
242 static void
vnc_parse_item(VinagreConnection * conn,xmlNode * root)243 vnc_parse_item (VinagreConnection *conn, xmlNode *root)
244 {
245   xmlNode *curr;
246   xmlChar *s_value;
247   VinagreVncConnection *vnc_conn = VINAGRE_VNC_CONNECTION (conn);
248 
249   VINAGRE_CONNECTION_CLASS (vinagre_vnc_connection_parent_class)->impl_parse_item (conn, root);
250 
251   for (curr = root->children; curr; curr = curr->next)
252     {
253       s_value = xmlNodeGetContent (curr);
254 
255       if (!xmlStrcmp(curr->name, BAD_CAST "view_only"))
256 	{
257 	  vinagre_vnc_connection_set_view_only (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
258 	}
259       else if (!xmlStrcmp(curr->name, BAD_CAST "scaling"))
260 	{
261 	  if (!scaling_command_line)
262 	    vinagre_vnc_connection_set_scaling (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
263 	}
264       else if (!xmlStrcmp(curr->name, BAD_CAST "keep_ratio"))
265 	{
266 	  vinagre_vnc_connection_set_keep_ratio (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
267 	}
268       else if (!xmlStrcmp(curr->name, BAD_CAST "depth_profile"))
269 	{
270 	  vinagre_vnc_connection_set_depth_profile (vnc_conn, atoi((const char *)s_value));
271 	}
272       else if (!xmlStrcmp(curr->name, BAD_CAST "lossy_encoding"))
273 	{
274 	  vinagre_vnc_connection_set_lossy_encoding (vnc_conn, vinagre_utils_parse_boolean ((const gchar *)s_value));
275 	}
276       else if (!xmlStrcmp(curr->name, BAD_CAST "ssh_tunnel_host"))
277 	{
278 	  vinagre_vnc_connection_set_ssh_tunnel_host (vnc_conn, (const gchar *)s_value);
279 	}
280 
281       xmlFree (s_value);
282     }
283 }
284 
285 static gchar *
vnc_get_best_name(VinagreConnection * conn)286 vnc_get_best_name (VinagreConnection *conn)
287 {
288   VinagreVncConnection *vnc_conn = VINAGRE_VNC_CONNECTION (conn);
289 
290   if (vinagre_connection_get_name (conn))
291     return g_strdup (vinagre_connection_get_name (conn));
292 
293   if (vnc_conn->priv->desktop_name)
294     return g_strdup (vnc_conn->priv->desktop_name);
295 
296   if (vinagre_connection_get_host (conn))
297     return vinagre_connection_get_string_rep (conn, FALSE);
298 
299   return NULL;
300 }
301 
302 static void
vnc_fill_conn_from_file(VinagreConnection * conn,GKeyFile * file)303 vnc_fill_conn_from_file (VinagreConnection *conn, GKeyFile *file)
304 {
305   gint shared;
306   GError *e = NULL;
307 
308   shared = g_key_file_get_integer (file, "options", "shared", &e);
309   if (e)
310     {
311       g_error_free (e);
312       return;
313     }
314   else
315     if (shared == 0 || shared == 1)
316       vinagre_vnc_connection_set_shared (VINAGRE_VNC_CONNECTION (conn), shared);
317     else
318       /* Translators: 'shared' here is a VNC protocol specific flag. You can translate it, but I think it's better to let it untranslated */
319       g_message (_("Bad value for 'shared' flag: %d. It is supposed to be 0 or 1. Ignoring it."), shared);
320 }
321 
322 static void
vnc_parse_options_widget(VinagreConnection * conn,GtkWidget * widget)323 vnc_parse_options_widget (VinagreConnection *conn, GtkWidget *widget)
324 {
325   GtkWidget *view_only, *scaling, *depth_combo, *lossy, *ssh_host, *ratio;
326 
327   view_only = g_object_get_data (G_OBJECT (widget), "view_only");
328   scaling = g_object_get_data (G_OBJECT (widget), "scaling");
329   ratio = g_object_get_data (G_OBJECT (widget), "ratio");
330   depth_combo = g_object_get_data (G_OBJECT (widget), "depth_combo");
331   lossy = g_object_get_data (G_OBJECT (widget), "lossy");
332   ssh_host = g_object_get_data (G_OBJECT (widget), "ssh_host");
333   if (!view_only || !scaling || !depth_combo || !lossy || !ssh_host || !ratio)
334     {
335       g_warning ("Wrong widget passed to vnc_parse_options_widget()");
336       return;
337     }
338 
339   vinagre_cache_prefs_set_boolean ("vnc-connection", "view-only", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view_only)));
340   vinagre_cache_prefs_set_boolean ("vnc-connection", "scaling", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scaling)));
341   vinagre_cache_prefs_set_boolean ("vnc-connection", "keep-ratio", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ratio)));
342   vinagre_cache_prefs_set_integer ("vnc-connection", "depth-profile", gtk_combo_box_get_active (GTK_COMBO_BOX (depth_combo)));
343   vinagre_cache_prefs_set_boolean ("vnc-connection", "lossy-encoding", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (lossy)));
344   vinagre_cache_prefs_set_string  ("vnc-connection", "ssh-tunnel-host", gtk_entry_get_text (GTK_ENTRY (ssh_host)));
345 
346   g_object_set (conn,
347 		"view-only", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view_only)),
348 		"scaling", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scaling)),
349 		"keep-ratio", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ratio)),
350 		"depth-profile", gtk_combo_box_get_active (GTK_COMBO_BOX (depth_combo)),
351 		"lossy-encoding", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (lossy)),
352 		"ssh-tunnel-host", gtk_entry_get_text (GTK_ENTRY (ssh_host)),
353 		NULL);
354 }
355 
356 static void
vinagre_vnc_connection_class_init(VinagreVncConnectionClass * klass)357 vinagre_vnc_connection_class_init (VinagreVncConnectionClass *klass)
358 {
359   GObjectClass* object_class = G_OBJECT_CLASS (klass);
360   VinagreConnectionClass* parent_class = VINAGRE_CONNECTION_CLASS (klass);
361 
362   g_type_class_add_private (klass, sizeof (VinagreVncConnectionPrivate));
363 
364   object_class->finalize = vinagre_vnc_connection_finalize;
365   object_class->dispose = vinagre_vnc_connection_dispose;
366   object_class->set_property = vinagre_vnc_connection_set_property;
367   object_class->get_property = vinagre_vnc_connection_get_property;
368   object_class->constructed  = vinagre_vnc_connection_constructed;
369 
370   parent_class->impl_fill_writer = vnc_fill_writer;
371   parent_class->impl_parse_item  = vnc_parse_item;
372   parent_class->impl_get_best_name = vnc_get_best_name;
373   parent_class->impl_fill_conn_from_file = vnc_fill_conn_from_file;
374   parent_class->impl_parse_options_widget = vnc_parse_options_widget;
375 
376   g_object_class_install_property (object_class,
377                                    PROP_DESKTOP_NAME,
378                                    g_param_spec_string ("desktop-name",
379                                                         "desktop-name",
380 	                                                "name of this connection as reported by the server",
381                                                         NULL,
382 	                                                G_PARAM_READWRITE |
383                                                         G_PARAM_CONSTRUCT |
384                                                         G_PARAM_STATIC_NICK |
385                                                         G_PARAM_STATIC_NAME |
386                                                         G_PARAM_STATIC_BLURB));
387 
388   g_object_class_install_property (object_class,
389                                    PROP_VIEW_ONLY,
390                                    g_param_spec_boolean ("view-only",
391                                                         "View-only connection",
392 	                                                "Whether this connection is a view-only one",
393                                                         FALSE,
394 	                                                G_PARAM_READWRITE |
395                                                         G_PARAM_CONSTRUCT |
396                                                         G_PARAM_STATIC_NICK |
397                                                         G_PARAM_STATIC_NAME |
398                                                         G_PARAM_STATIC_BLURB));
399   g_object_class_install_property (object_class,
400                                    PROP_SCALING,
401                                    g_param_spec_boolean ("scaling",
402                                                         "Use scaling",
403 	                                                "Whether to use scaling on this connection",
404                                                         FALSE,
405 	                                                G_PARAM_READWRITE |
406                                                         G_PARAM_CONSTRUCT |
407                                                         G_PARAM_STATIC_NICK |
408                                                         G_PARAM_STATIC_NAME |
409                                                         G_PARAM_STATIC_BLURB));
410 
411   g_object_class_install_property (object_class,
412                                    PROP_KEEP_RATIO,
413                                    g_param_spec_boolean ("keep-ratio",
414                                                         "Keep Ratio",
415 	                                                "Whether to keep the aspect ratio when using scaling",
416                                                         FALSE,
417 	                                                G_PARAM_READWRITE |
418                                                         G_PARAM_CONSTRUCT |
419                                                         G_PARAM_STATIC_NICK |
420                                                         G_PARAM_STATIC_NAME |
421                                                         G_PARAM_STATIC_BLURB));
422 
423   g_object_class_install_property (object_class,
424                                    PROP_SHARED,
425                                    g_param_spec_int ("shared",
426                                                      "shared flag",
427 	                                              "if the server should allow more than one client connected",
428                                                       -1,
429                                                       1,
430                                                       -1,
431 	                                              G_PARAM_READWRITE |
432                                                       G_PARAM_CONSTRUCT |
433                                                       G_PARAM_STATIC_NICK |
434                                                       G_PARAM_STATIC_NAME |
435                                                       G_PARAM_STATIC_BLURB));
436 
437   g_object_class_install_property (object_class,
438                                    PROP_FD,
439                                    g_param_spec_int ("fd",
440                                                      "file descriptor",
441 	                                              "the file descriptor for this connection",
442                                                       0,
443                                                       G_MAXINT,
444                                                       0,
445 	                                              G_PARAM_READWRITE |
446                                                       G_PARAM_CONSTRUCT |
447                                                       G_PARAM_STATIC_NICK |
448                                                       G_PARAM_STATIC_NAME |
449                                                       G_PARAM_STATIC_BLURB));
450 
451   g_object_class_install_property (object_class,
452                                    PROP_DEPTH_PROFILE,
453                                    g_param_spec_int ("depth-profile",
454                                                      "Depth Profile",
455 	                                              "The profile of depth color to be used in gtk-vnc widget",
456                                                       0,
457                                                       5,
458                                                       0,
459 	                                              G_PARAM_READWRITE |
460                                                       G_PARAM_CONSTRUCT |
461                                                       G_PARAM_STATIC_NICK |
462                                                       G_PARAM_STATIC_NAME |
463                                                       G_PARAM_STATIC_BLURB));
464 
465   g_object_class_install_property (object_class,
466                                    PROP_LOSSY_ENCODING,
467                                    g_param_spec_boolean ("lossy-encoding",
468                                                         "Lossy encoding",
469 	                                                "Whether to use a lossy encoding",
470                                                         FALSE,
471 	                                                G_PARAM_READWRITE |
472                                                         G_PARAM_CONSTRUCT |
473                                                         G_PARAM_STATIC_NICK |
474                                                         G_PARAM_STATIC_NAME |
475                                                         G_PARAM_STATIC_BLURB));
476 
477   g_object_class_install_property (object_class,
478                                    PROP_SSH_TUNNEL_HOST,
479                                    g_param_spec_string ("ssh-tunnel-host",
480                                                         "SSH Tunnel Host",
481 	                                                "hostname used to create the SSH tunnel",
482                                                         NULL,
483 	                                                G_PARAM_READWRITE |
484                                                         G_PARAM_CONSTRUCT |
485                                                         G_PARAM_STATIC_NICK |
486                                                         G_PARAM_STATIC_NAME |
487                                                         G_PARAM_STATIC_BLURB));
488 
489   g_object_class_install_property (object_class,
490                                    PROP_SOCKET,
491                                    g_param_spec_object ("socket",
492                                                         "Socket",
493 	                                                "A GSocket for this connection",
494 	                                                G_TYPE_SOCKET,
495 	                                                G_PARAM_READWRITE |
496                                                         G_PARAM_CONSTRUCT |
497                                                         G_PARAM_STATIC_NICK |
498                                                         G_PARAM_STATIC_NAME |
499                                                         G_PARAM_STATIC_BLURB));
500 
501 }
502 
503 VinagreConnection *
vinagre_vnc_connection_new(void)504 vinagre_vnc_connection_new (void)
505 {
506   return VINAGRE_CONNECTION (g_object_new (VINAGRE_TYPE_VNC_CONNECTION, NULL));
507 }
508 
509 void
vinagre_vnc_connection_set_desktop_name(VinagreVncConnection * conn,const gchar * desktop_name)510 vinagre_vnc_connection_set_desktop_name (VinagreVncConnection *conn,
511 					 const gchar *desktop_name)
512 {
513   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
514 
515   g_free (conn->priv->desktop_name);
516   conn->priv->desktop_name = g_strdup (desktop_name);
517 }
518 const gchar *
vinagre_vnc_connection_get_desktop_name(VinagreVncConnection * conn)519 vinagre_vnc_connection_get_desktop_name (VinagreVncConnection *conn)
520 {
521   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), NULL);
522 
523   return conn->priv->desktop_name;
524 }
525 
526 void
vinagre_vnc_connection_set_shared(VinagreVncConnection * conn,gint value)527 vinagre_vnc_connection_set_shared (VinagreVncConnection *conn,
528 				   gint value)
529 {
530   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
531   g_return_if_fail (value >=-1 && value <=1);
532 
533   conn->priv->shared = value;
534 }
535 gint
vinagre_vnc_connection_get_shared(VinagreVncConnection * conn)536 vinagre_vnc_connection_get_shared (VinagreVncConnection *conn)
537 {
538   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), -1);
539 
540   return conn->priv->shared;
541 }
542 
543 void
vinagre_vnc_connection_set_view_only(VinagreVncConnection * conn,gboolean value)544 vinagre_vnc_connection_set_view_only (VinagreVncConnection *conn,
545 				      gboolean value)
546 {
547   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
548 
549   conn->priv->view_only = value;
550 }
551 gboolean
vinagre_vnc_connection_get_view_only(VinagreVncConnection * conn)552 vinagre_vnc_connection_get_view_only (VinagreVncConnection *conn)
553 {
554   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), FALSE);
555 
556   return conn->priv->view_only;
557 }
558 
559 void
vinagre_vnc_connection_set_scaling(VinagreVncConnection * conn,gboolean value)560 vinagre_vnc_connection_set_scaling (VinagreVncConnection *conn,
561 				    gboolean value)
562 {
563   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
564 
565   conn->priv->scaling = value;
566 }
567 gboolean
vinagre_vnc_connection_get_scaling(VinagreVncConnection * conn)568 vinagre_vnc_connection_get_scaling (VinagreVncConnection *conn)
569 {
570   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), FALSE);
571 
572   return conn->priv->scaling;
573 }
574 
575 void
vinagre_vnc_connection_set_keep_ratio(VinagreVncConnection * conn,gboolean value)576 vinagre_vnc_connection_set_keep_ratio (VinagreVncConnection *conn,
577 				       gboolean value)
578 {
579   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
580 
581   conn->priv->keep_ratio = value;
582 }
583 gboolean
vinagre_vnc_connection_get_keep_ratio(VinagreVncConnection * conn)584 vinagre_vnc_connection_get_keep_ratio (VinagreVncConnection *conn)
585 {
586   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), FALSE);
587 
588   return conn->priv->keep_ratio;
589 }
590 
591 void
vinagre_vnc_connection_set_fd(VinagreVncConnection * conn,gint value)592 vinagre_vnc_connection_set_fd (VinagreVncConnection *conn,
593 			       gint                 value)
594 {
595   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
596   g_return_if_fail (value >= 0);
597 
598   conn->priv->fd = value;
599 }
600 gint
vinagre_vnc_connection_get_fd(VinagreVncConnection * conn)601 vinagre_vnc_connection_get_fd (VinagreVncConnection *conn)
602 {
603   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), 0);
604 
605   if (conn->priv->socket)
606     return g_socket_get_fd (conn->priv->socket);
607   else
608     return conn->priv->fd;
609 }
610 
611 void
vinagre_vnc_connection_set_socket(VinagreVncConnection * conn,GSocket * socket)612 vinagre_vnc_connection_set_socket (VinagreVncConnection *conn,
613 				   GSocket              *socket)
614 {
615   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
616 
617   if (socket)
618     conn->priv->socket = g_object_ref (socket);
619 }
620 GSocket *
vinagre_vnc_connection_get_socket(VinagreVncConnection * conn)621 vinagre_vnc_connection_get_socket (VinagreVncConnection *conn)
622 {
623   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), 0);
624 
625   return conn->priv->socket;
626 }
627 
628 void
vinagre_vnc_connection_set_depth_profile(VinagreVncConnection * conn,gint value)629 vinagre_vnc_connection_set_depth_profile (VinagreVncConnection *conn,
630 					  gint                 value)
631 {
632   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
633   g_return_if_fail (value >= 0);
634 
635   conn->priv->depth_profile = value;
636 }
637 gint
vinagre_vnc_connection_get_depth_profile(VinagreVncConnection * conn)638 vinagre_vnc_connection_get_depth_profile (VinagreVncConnection *conn)
639 {
640   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), 0);
641 
642   return conn->priv->depth_profile;
643 }
644 
645 void
vinagre_vnc_connection_set_lossy_encoding(VinagreVncConnection * conn,gboolean value)646 vinagre_vnc_connection_set_lossy_encoding (VinagreVncConnection *conn,
647 					   gboolean value)
648 {
649   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
650 
651   conn->priv->lossy_encoding = value;
652 }
653 gboolean
vinagre_vnc_connection_get_lossy_encoding(VinagreVncConnection * conn)654 vinagre_vnc_connection_get_lossy_encoding (VinagreVncConnection *conn)
655 {
656   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), FALSE);
657 
658   return conn->priv->lossy_encoding;
659 }
660 
661 void
vinagre_vnc_connection_set_ssh_tunnel_host(VinagreVncConnection * conn,const gchar * host)662 vinagre_vnc_connection_set_ssh_tunnel_host (VinagreVncConnection *conn,
663 					    const gchar *host)
664 {
665   g_return_if_fail (VINAGRE_IS_VNC_CONNECTION (conn));
666 
667   g_free (conn->priv->ssh_tunnel_host);
668   conn->priv->ssh_tunnel_host = g_strdup (host);
669 }
670 const gchar *
vinagre_vnc_connection_get_ssh_tunnel_host(VinagreVncConnection * conn)671 vinagre_vnc_connection_get_ssh_tunnel_host (VinagreVncConnection *conn)
672 {
673   g_return_val_if_fail (VINAGRE_IS_VNC_CONNECTION (conn), NULL);
674 
675   return conn->priv->ssh_tunnel_host;
676 }
677 
678 /* vim: set ts=8: */
679