~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to libgames-support/games-controls.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
  N_COLUMNS
39
39
};
40
40
 
 
41
/* Class implementation */
 
42
 
 
43
G_DEFINE_TYPE (GamesControlsList, games_controls_list, GTK_TYPE_SCROLLED_WINDOW)
 
44
 
 
45
struct GamesControlsListPrivate {
 
46
  GtkTreeModel *model;
 
47
  GtkListStore *store;
 
48
  GtkWidget *view;
 
49
 
 
50
  char *conf_group;
 
51
  gulong notify_handler_id;
 
52
};
 
53
 
41
54
static void
42
55
accel_edited_cb (GtkCellRendererAccel *cell,
43
56
                 char *path_string,
54
67
  if (!path)
55
68
    return;
56
69
 
57
 
  if (!gtk_tree_model_get_iter (list->model, &iter, path)) {
 
70
  if (!gtk_tree_model_get_iter (list->priv->model, &iter, path)) {
58
71
    gtk_tree_path_free (path);
59
72
    return;
60
73
  }
61
74
  gtk_tree_path_free (path);
62
75
 
63
 
  gtk_tree_model_get (list->model, &iter,
 
76
  gtk_tree_model_get (list->priv->model, &iter,
64
77
                      CONFKEY_COLUMN, &conf_key,
65
78
                      -1);
66
79
  if (!conf_key)
68
81
 
69
82
  /* Note: the model is updated in the conf notification callback */
70
83
  /* FIXME: what to do with the modifiers? */
71
 
  games_conf_set_keyval (list->conf_group, conf_key, keyval);
 
84
  games_conf_set_keyval (list->priv->conf_group, conf_key, keyval);
72
85
  g_free (conf_key);
73
86
}
74
87
 
86
99
  if (!path)
87
100
    return;
88
101
 
89
 
  if (!gtk_tree_model_get_iter (list->model, &iter, path)) {
 
102
  if (!gtk_tree_model_get_iter (list->priv->model, &iter, path)) {
90
103
    gtk_tree_path_free (path);
91
104
    return;
92
105
  }
93
106
  gtk_tree_path_free (path);
94
107
 
95
 
  gtk_tree_model_get (list->model, &iter,
 
108
  gtk_tree_model_get (list->priv->model, &iter,
96
109
                      CONFKEY_COLUMN, &conf_key,
97
110
                      DEFAULT_KEYCODE_COLUMN, &default_keyval,
98
111
                      -1);
101
114
 
102
115
  /* Note: the model is updated in the conf notification callback */
103
116
  /* FIXME: what to do with the modifiers? */
104
 
  games_conf_set_keyval (list->conf_group, conf_key, default_keyval);
 
117
  games_conf_set_keyval (list->priv->conf_group, conf_key, default_keyval);
105
118
  g_free (conf_key);
106
119
}
107
120
 
114
127
  GtkTreeIter iter;
115
128
  gboolean valid;
116
129
 
117
 
  if ((group == NULL && list->conf_group != NULL) ||
118
 
      (group != NULL && (list->conf_group == NULL ||
119
 
                         strcmp (group, list->conf_group) != 0)))
 
130
  if ((group == NULL && list->priv->conf_group != NULL) ||
 
131
      (group != NULL && (list->priv->conf_group == NULL ||
 
132
                         strcmp (group, list->priv->conf_group) != 0)))
120
133
    return;
121
134
 
122
135
  /* find our gconf key in the list store and update it */
123
 
  valid = gtk_tree_model_get_iter_first (list->model, &iter);
 
136
  valid = gtk_tree_model_get_iter_first (list->priv->model, &iter);
124
137
  while (valid) {
125
138
    char *conf_key;
126
139
 
127
 
    gtk_tree_model_get (list->model, &iter,
 
140
    gtk_tree_model_get (list->priv->model, &iter,
128
141
                        CONFKEY_COLUMN, &conf_key,
129
142
                        -1);
130
143
 
131
144
    if (strcmp (key, conf_key) == 0) {
132
145
      guint keyval, default_keyval;
133
146
 
134
 
      gtk_tree_model_get (list->model, &iter,
 
147
      gtk_tree_model_get (list->priv->model, &iter,
135
148
                          DEFAULT_KEYCODE_COLUMN, &default_keyval,
136
149
                          -1);
137
150
 
138
 
      keyval = games_conf_get_keyval_with_default (list->conf_group, key, default_keyval);
 
151
      keyval = games_conf_get_keyval_with_default (list->priv->conf_group, key, default_keyval);
139
152
 
140
 
      gtk_list_store_set (list->store, &iter,
 
153
      gtk_list_store_set (list->priv->store, &iter,
141
154
                          KEYCODE_COLUMN, keyval,
142
155
                          KEYMODS_COLUMN, 0 /* FIXME? */,
143
156
                          -1);
147
160
    }
148
161
 
149
162
    g_free (conf_key);
150
 
    valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list->store), &iter);
 
163
    valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list->priv->store), &iter);
151
164
  }
152
165
}
153
166
 
154
 
/* Class implementation */
155
 
 
156
 
G_DEFINE_TYPE (GamesControlsList, games_controls_list, GTK_TYPE_SCROLLED_WINDOW)
157
 
 
158
167
static void
159
168
games_controls_list_init (GamesControlsList *list)
160
169
{
 
170
  list->priv = G_TYPE_INSTANCE_GET_PRIVATE (list, GAMES_TYPE_CONTROLS_LIST, GamesControlsListPrivate);
161
171
}
162
172
 
163
173
static GObject *
185
195
                              G_TYPE_UINT,
186
196
                              G_TYPE_UINT,
187
197
                              G_TYPE_UINT);
188
 
  list->store = store;
189
 
  list->model = GTK_TREE_MODEL (store);
 
198
  list->priv->store = store;
 
199
  list->priv->model = GTK_TREE_MODEL (store);
190
200
 
191
 
  list->view = gtk_tree_view_new_with_model (list->model);
 
201
  list->priv->view = gtk_tree_view_new_with_model (list->priv->model);
192
202
  g_object_unref (store);
193
203
 
194
 
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list->view), FALSE);
195
 
  gtk_tree_view_set_enable_search (GTK_TREE_VIEW (list->view), FALSE);
 
204
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list->priv->view), FALSE);
 
205
  gtk_tree_view_set_enable_search (GTK_TREE_VIEW (list->priv->view), FALSE);
196
206
 
197
207
  /* label column */
198
208
  label_renderer = gtk_cell_renderer_text_new ();
200
210
                                                     label_renderer,
201
211
                                                     "text", LABEL_COLUMN,
202
212
                                                     NULL);
203
 
  gtk_tree_view_append_column (GTK_TREE_VIEW (list->view), column);
 
213
  gtk_tree_view_append_column (GTK_TREE_VIEW (list->priv->view), column);
204
214
 
205
215
  /* key column */
206
216
  key_renderer = gtk_cell_renderer_accel_new ();
218
228
                                                     "accel-key", KEYCODE_COLUMN,
219
229
                                                     "accel-mods", KEYMODS_COLUMN,
220
230
                                                     NULL);
221
 
  gtk_tree_view_append_column (GTK_TREE_VIEW (list->view), column);
222
 
 
223
 
  gtk_container_add (GTK_CONTAINER (scrolled_window), list->view);
224
 
 
225
 
  list->notify_handler_id = g_signal_connect (games_conf_get_default (),
 
231
  gtk_tree_view_append_column (GTK_TREE_VIEW (list->priv->view), column);
 
232
 
 
233
  gtk_container_add (GTK_CONTAINER (scrolled_window), list->priv->view);
 
234
 
 
235
  list->priv->notify_handler_id = g_signal_connect (games_conf_get_default (),
226
236
                                              "value-changed",
227
237
                                              G_CALLBACK (conf_value_changed_cb),
228
238
                                              list);
232
242
 
233
243
static void
234
244
games_controls_list_finalize (GObject *object)
235
 
        
236
245
{
237
246
  GamesControlsList *list = GAMES_CONTROLS_LIST (object);
238
247
 
239
 
  g_signal_handler_disconnect (games_conf_get_default (), list->notify_handler_id);
 
248
  g_signal_handler_disconnect (games_conf_get_default (), list->priv->notify_handler_id);
240
249
 
241
 
  g_free (list->conf_group);
 
250
  g_free (list->priv->conf_group);
242
251
 
243
252
  G_OBJECT_CLASS (games_controls_list_parent_class)->finalize (object);
244
253
}
250
259
 
251
260
  gobject_class->constructor = games_controls_list_constructor;
252
261
  gobject_class->finalize = games_controls_list_finalize;
 
262
 
 
263
  g_type_class_add_private (gobject_class, sizeof (GamesControlsListPrivate));
253
264
}
254
265
 
255
266
/* Public API */
265
276
                       "shadow-type", GTK_SHADOW_IN,
266
277
                       NULL);
267
278
 
268
 
  list->conf_group = g_strdup (conf_group);
 
279
  list->priv->conf_group = g_strdup (conf_group);
269
280
 
270
281
  return GTK_WIDGET (list);
271
282
}
285
296
  if (!label)
286
297
    label = _("Unknown Command");
287
298
 
288
 
  keyval = games_conf_get_keyval_with_default (list->conf_group, conf_key, default_keyval);
 
299
  keyval = games_conf_get_keyval_with_default (list->priv->conf_group, conf_key, default_keyval);
289
300
 
290
 
  gtk_list_store_insert_with_values (list->store, &iter, -1,
 
301
  gtk_list_store_insert_with_values (list->priv->store, &iter, -1,
291
302
                                     CONFKEY_COLUMN, conf_key,
292
303
                                     LABEL_COLUMN, label,
293
304
                                     KEYCODE_COLUMN, keyval,