vinagre-prefs.c 7.2 KB
Newer Older
Jonh Wendell's avatar
Jonh Wendell committed
1
2
3
4
/*
 * vinagre-prefs.c
 * This file is part of vinagre
 *
Jonh Wendell's avatar
Jonh Wendell committed
5
 * Copyright (C) Jonh Wendell 2008,2009 <wendell@bani.com.br>
Jonh Wendell's avatar
Jonh Wendell committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 * 
 * vinagre-prefs.c is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * 
 * vinagre-prefs.c is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib/gi18n.h>
#include "vinagre-prefs.h"
23
#include "vinagre-utils.h"
Jonh Wendell's avatar
Jonh Wendell committed
24

25
26
27
28
29
30
31
#define VINAGRE_SCHEMA_NAME		"org.gnome.Vinagre"
#define VM_ALWAYS_SHOW_TABS		"always-show-tabs"
#define VM_SHOW_ACCELS			"show-accels"
#define VM_HISTORY_SIZE			"history-size"
#define VM_ALWAYS_ENABLE_LISTENING	"always-enable-listening"
#define VM_SHARED_FLAG			"shared-flag"
#define VM_ACTIVE_PLUGINS		"active-plugins"
Jonh Wendell's avatar
Jonh Wendell committed
32

Jonh Wendell's avatar
Jonh Wendell committed
33
34
struct _VinagrePrefsPrivate
{
35
  GSettings *gsettings;
Jonh Wendell's avatar
Jonh Wendell committed
36
37
38
39
40
41
42
};

/* Properties */
enum
{
  PROP_0,
  PROP_SHARED_FLAG,
Jonh Wendell's avatar
Jonh Wendell committed
43
  PROP_HISTORY_SIZE,
44
  PROP_ACTIVE_PLUGINS,
45
46
  PROP_LAST_PROTOCOL,
  PROP_ALWAYS_ENABLE_LISTENING
Jonh Wendell's avatar
Jonh Wendell committed
47
48
49
50
51
52
};

G_DEFINE_TYPE (VinagrePrefs, vinagre_prefs, G_TYPE_OBJECT);

static VinagrePrefs *prefs_singleton = NULL;

Jonh Wendell's avatar
Jonh Wendell committed
53
54
55
56
57
/**
 * vinagre_prefs_get_default:
 *
 * Return value: (transfer none):
 */
Jonh Wendell's avatar
Jonh Wendell committed
58
59
60
61
62
VinagrePrefs *
vinagre_prefs_get_default (void)
{
  if (G_UNLIKELY (!prefs_singleton))
    prefs_singleton = VINAGRE_PREFS (g_object_new (VINAGRE_TYPE_PREFS,
63
						   NULL));
Jonh Wendell's avatar
Jonh Wendell committed
64
65
66
  return prefs_singleton;
}

67
68
69
70
71
72
73
/**
 * vinagre_prefs_get_default_gsettings:
 *
 * Return value: (transfer none):
 */
GSettings *
vinagre_prefs_get_default_gsettings (void)
Jonh Wendell's avatar
Jonh Wendell committed
74
{
75
  VinagrePrefs *pref = vinagre_prefs_get_default ();
Jonh Wendell's avatar
Jonh Wendell committed
76

77
  return pref->priv->gsettings;
78
79
}

Jonh Wendell's avatar
Jonh Wendell committed
80
81
82
83
84
static void
vinagre_prefs_init (VinagrePrefs *prefs)
{
  prefs->priv = G_TYPE_INSTANCE_GET_PRIVATE (prefs, VINAGRE_TYPE_PREFS, VinagrePrefsPrivate);

85
86
  prefs->priv->gsettings = g_settings_new (VINAGRE_SCHEMA_NAME);
  if (prefs->priv->gsettings == NULL)
Jonh Wendell's avatar
Jonh Wendell committed
87
88
89
90
91
92
93
94
95
96
97
98
    g_critical (_("Cannot initialize preferences manager."));

}

static void
vinagre_prefs_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
  VinagrePrefs *prefs = VINAGRE_PREFS (object);

  switch (prop_id)
    {
      case PROP_SHARED_FLAG:
99
	g_settings_set_boolean (prefs->priv->gsettings, VM_SHARED_FLAG, g_value_get_boolean (value));
100
	break;
101
      case PROP_HISTORY_SIZE:
102
	g_settings_set_int (prefs->priv->gsettings, VM_HISTORY_SIZE, g_value_get_int (value));
103
	break;
Jonh Wendell's avatar
Jonh Wendell committed
104
      case PROP_ACTIVE_PLUGINS:
105
	g_settings_set_strv (prefs->priv->gsettings, VM_ACTIVE_PLUGINS, g_value_get_boxed (value));
Jonh Wendell's avatar
Jonh Wendell committed
106
	break;
107
      case PROP_ALWAYS_ENABLE_LISTENING:
108
	g_settings_set_boolean (prefs->priv->gsettings, VM_ALWAYS_ENABLE_LISTENING, g_value_get_boolean (value));
109
	break;
Jonh Wendell's avatar
Jonh Wendell committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
      default:
	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
	break;
    }
}

static void
vinagre_prefs_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
  VinagrePrefs *prefs = VINAGRE_PREFS (object);

  switch (prop_id)
    {
      case PROP_SHARED_FLAG:
124
	g_value_set_boolean (value, g_settings_get_boolean (prefs->priv->gsettings, VM_SHARED_FLAG));
125
	break;
126
      case PROP_HISTORY_SIZE:
127
	g_value_set_int (value, g_settings_get_int (prefs->priv->gsettings, VM_HISTORY_SIZE));
128
	break;
Jonh Wendell's avatar
Jonh Wendell committed
129
      case PROP_ACTIVE_PLUGINS:
130
	g_value_set_boxed (value, g_settings_get_strv (prefs->priv->gsettings, VM_ACTIVE_PLUGINS));
Jonh Wendell's avatar
Jonh Wendell committed
131
	break;
132
      case PROP_ALWAYS_ENABLE_LISTENING:
133
	g_value_set_boolean (value, g_settings_get_boolean (prefs->priv->gsettings, VM_ALWAYS_ENABLE_LISTENING));
134
	break;
Jonh Wendell's avatar
Jonh Wendell committed
135
136
137
138
139
140
      default:
	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
	break;
    }
}

141
142
143
144
145
static void
vinagre_prefs_dispose (GObject *object)
{
  VinagrePrefs *prefs = VINAGRE_PREFS (object);

146
  if (prefs->priv->gsettings)
147
    {
148
149
      g_object_unref (prefs->priv->gsettings);
      prefs->priv->gsettings = NULL;
150
151
152
153
154
155
    }

  G_OBJECT_CLASS (vinagre_prefs_parent_class)->dispose (object);
}


Jonh Wendell's avatar
Jonh Wendell committed
156
157
158
159
160
161
162
static void
vinagre_prefs_class_init (VinagrePrefsClass *klass)
{
  GObjectClass* object_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (VinagrePrefsPrivate));

163
  object_class->dispose = vinagre_prefs_dispose;
Jonh Wendell's avatar
Jonh Wendell committed
164
165
166
167
168
169
170
171
172
  object_class->set_property = vinagre_prefs_set_property;
  object_class->get_property = vinagre_prefs_get_property;

  g_object_class_install_property (object_class,
				   PROP_SHARED_FLAG,
				   g_param_spec_boolean ("shared-flag",
							 "Shared Flag",
							 "Whether we should share the remote connection",
							 TRUE,
173
							 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
174
175
176
177
178
179
  g_object_class_install_property (object_class,
				   PROP_HISTORY_SIZE,
				   g_param_spec_int ("history-size",
						     "History size",
						     "Max number of items in history dropdown entry",
						     0, G_MAXINT, 15,
180
						     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Jonh Wendell's avatar
Jonh Wendell committed
181

Jonh Wendell's avatar
Jonh Wendell committed
182
183
  g_object_class_install_property (object_class,
				   PROP_ACTIVE_PLUGINS,
184
185
186
187
188
				   g_param_spec_boxed ("active-plugins",
						       "Active plugins",
						       "The list of active plugins",
						       G_TYPE_STRV,
						       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Jonh Wendell's avatar
Jonh Wendell committed
189

190
191
192
193
194
195
  g_object_class_install_property (object_class,
				   PROP_ALWAYS_ENABLE_LISTENING,
				   g_param_spec_boolean ("always-enable-listening",
							 "Always enable listening",
							 "Whether we always should listen for reverse connections",
							 FALSE,
196
							 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Jonh Wendell's avatar
Jonh Wendell committed
197
}
198
199
200
201

/* Preferences dialog */

typedef struct {
202
203
204
205
  GtkBuilder  *xml;
  GtkWidget   *dialog;
  GtkWidget   *show_tabs;
  GtkWidget   *show_accels;
206
  GtkWindow   *parent;
207
208
209
} VinagrePrefsDialog;

static void
210
vinagre_prefs_dialog_response (GtkDialog *d, gint response_id, VinagrePrefsDialog *dialog)
211
{
212
213
214
215
216
217
  if (response_id > 0)
    {
      vinagre_utils_help_contents (dialog->parent, "preferences");
      return;
    }

218
219
220
221
222
223
224
225
226
227
  gtk_widget_destroy (dialog->dialog);
  g_object_unref (dialog->xml);
  g_free (dialog);
  dialog = NULL;
}

void
vinagre_prefs_dialog_show (VinagreWindow *window)
{
  VinagrePrefsDialog *dialog;
228
  VinagrePrefs *pref;
229
230
231

  dialog = g_new (VinagrePrefsDialog, 1);

232
  dialog->xml = vinagre_utils_get_builder (NULL);
233
  dialog->dialog = GTK_WIDGET (gtk_builder_get_object (dialog->xml, "preferences_dialog"));
234
235
  dialog->parent = GTK_WINDOW (window);
  gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), dialog->parent);
236

237
238
  dialog->show_tabs = GTK_WIDGET (gtk_builder_get_object (dialog->xml, "always_show_tabs_check"));
  dialog->show_accels = GTK_WIDGET (gtk_builder_get_object (dialog->xml, "show_accels_check"));
239

240
241
242
  pref = vinagre_prefs_get_default ();
  g_settings_bind (pref->priv->gsettings, "always-show-tabs", dialog->show_tabs, "active", G_SETTINGS_BIND_DEFAULT);
  g_settings_bind (pref->priv->gsettings, "show-accels", dialog->show_accels, "active", G_SETTINGS_BIND_DEFAULT);
243

244
245
246
247
  g_signal_connect (dialog->dialog,
		    "response",
		    G_CALLBACK (vinagre_prefs_dialog_response),
		    dialog);
248
249
250

  gtk_widget_show_all (dialog->dialog);
}
251
/* vim: set ts=8: */