ephy-encoding-dialog.c 15.8 KB
Newer Older
1
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3 4
 *  Copyright © 2000, 2001, 2002, 2003 Marco Pesenti Gritti
 *  Copyright © 2003, 2004 Christian Persch
5
 *  Copyright © 2012 Igalia S.L.
6
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
7 8 9
 *  This file is part of Epiphany.
 *
 *  Epiphany is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
Michael Catanzaro's avatar
Michael Catanzaro committed
11 12
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
13
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
14
 *  Epiphany is distributed in the hope that it will be useful,
15 16 17 18 19
 *  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
Michael Catanzaro's avatar
Michael Catanzaro committed
20
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
21 22 23 24
 */

#include "config.h"
#include "ephy-encoding-dialog.h"
25 26

#include "ephy-debug.h"
27
#include "ephy-embed-container.h"
28
#include "ephy-embed-shell.h"
29
#include "ephy-embed-utils.h"
30 31
#include "ephy-embed.h"
#include "ephy-encodings.h"
Arnaud B.'s avatar
Arnaud B. committed
32
#include "ephy-encoding-row.h"
33
#include "ephy-shell.h"
34

35
#include <glib/gi18n.h>
36
#include <gtk/gtk.h>
37
#include <webkit2/webkit2.h>
38

Michael Catanzaro's avatar
Michael Catanzaro committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
struct _EphyEncodingDialog {
  GtkDialog parent_instance;

  EphyEncodings *encodings;
  EphyWindow *window;
  EphyEmbed *embed;
  GtkWidget *enc_view;
  gboolean update_embed_tag;
  gboolean update_view_tag;
  const char *selected_encoding;

  /* from the UI file */
  GtkStack *type_stack;
  GtkSwitch *default_switch;
  GtkListBox *list_box;
  GtkListBox *recent_list_box;
  GtkListBox *related_list_box;
  GtkGrid *recent_grid;
  GtkGrid *related_grid;
58 59
};

60
enum {
Michael Catanzaro's avatar
Michael Catanzaro committed
61 62 63
  COL_TITLE_ELIDED,
  COL_ENCODING,
  NUM_COLS
64
};
65

Michael Catanzaro's avatar
Michael Catanzaro committed
66 67 68 69
enum {
  PROP_0,
  PROP_PARENT_WINDOW,
  LAST_PROP
70 71
};

72 73
static GParamSpec *obj_properties[LAST_PROP];

74
G_DEFINE_TYPE (EphyEncodingDialog, ephy_encoding_dialog, GTK_TYPE_DIALOG)
75

76
static void
Arnaud B.'s avatar
Arnaud B. committed
77 78
select_encoding_row (GtkListBox   *list_box,
                     EphyEncoding *encoding)
79
{
Michael Catanzaro's avatar
Michael Catanzaro committed
80 81
  const char *target_encoding;
  GList *rows, *r;
82

Michael Catanzaro's avatar
Michael Catanzaro committed
83 84
  target_encoding = ephy_encoding_get_encoding (encoding);
  rows = gtk_container_get_children (GTK_CONTAINER (list_box));
85

Michael Catanzaro's avatar
Michael Catanzaro committed
86 87 88 89
  for (r = rows; r != NULL; r = r->next) {
    EphyEncodingRow *ephy_encoding_row;
    EphyEncoding *ephy_encoding;
    const char *encoding_string = NULL;
90

Michael Catanzaro's avatar
Michael Catanzaro committed
91 92 93
    ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (r->data)));
    ephy_encoding = ephy_encoding_row_get_encoding (ephy_encoding_row);
    encoding_string = ephy_encoding_get_encoding (ephy_encoding);
94

Michael Catanzaro's avatar
Michael Catanzaro committed
95 96
    if (g_strcmp0 (encoding_string, target_encoding) == 0) {
      ephy_encoding_row_set_selected (ephy_encoding_row, TRUE);
97

Michael Catanzaro's avatar
Michael Catanzaro committed
98 99
      gtk_list_box_select_row (list_box, GTK_LIST_BOX_ROW (r->data));
      /* TODO scroll to row */
100

Michael Catanzaro's avatar
Michael Catanzaro committed
101 102 103 104
      break;
    }
  }
  g_list_free (rows);
105 106
}

107
static void
108
sync_encoding_against_embed (EphyEncodingDialog *dialog)
109
{
Michael Catanzaro's avatar
Michael Catanzaro committed
110 111 112
  const char *encoding;
  gboolean is_automatic = FALSE;
  WebKitWebView *view;
113

Michael Catanzaro's avatar
Michael Catanzaro committed
114
  dialog->update_embed_tag = TRUE;
115

Michael Catanzaro's avatar
Michael Catanzaro committed
116 117
  g_return_if_fail (EPHY_IS_EMBED (dialog->embed));
  view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (dialog->embed);
118

Michael Catanzaro's avatar
Michael Catanzaro committed
119 120
  encoding = webkit_web_view_get_custom_charset (view);
  is_automatic = encoding == NULL;
121

Michael Catanzaro's avatar
Michael Catanzaro committed
122 123
  if (!is_automatic) {
    EphyEncoding *node;
124

Michael Catanzaro's avatar
Michael Catanzaro committed
125 126
    node = ephy_encodings_get_encoding (dialog->encodings, encoding, TRUE);
    g_assert (EPHY_IS_ENCODING (node));
127

Michael Catanzaro's avatar
Michael Catanzaro committed
128 129 130 131
    /* Select the current encoding in the lists. */
    select_encoding_row (dialog->list_box, node);
    select_encoding_row (dialog->recent_list_box, node);
    select_encoding_row (dialog->related_list_box, node);
132

Michael Catanzaro's avatar
Michael Catanzaro committed
133 134 135 136 137
    /* TODO scroll the view so the active encoding is visible */
  }
  gtk_switch_set_active (dialog->default_switch, is_automatic);
  gtk_switch_set_state (dialog->default_switch, is_automatic);
  gtk_widget_set_sensitive (GTK_WIDGET (dialog->type_stack), !is_automatic);
138

Michael Catanzaro's avatar
Michael Catanzaro committed
139
  dialog->update_embed_tag = FALSE;
140 141
}

142
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
143 144 145
embed_net_stop_cb (EphyWebView        *view,
                   WebKitLoadEvent     load_event,
                   EphyEncodingDialog *dialog)
146
{
Michael Catanzaro's avatar
Michael Catanzaro committed
147 148
  if (ephy_web_view_is_loading (view) == FALSE)
    sync_encoding_against_embed (dialog);
149 150 151
}

static void
152
ephy_encoding_dialog_detach_embed (EphyEncodingDialog *dialog)
153
{
Michael Catanzaro's avatar
Michael Catanzaro committed
154
  EphyEmbed **embedptr;
155

Michael Catanzaro's avatar
Michael Catanzaro committed
156 157 158
  g_signal_handlers_disconnect_by_func (ephy_embed_get_web_view (dialog->embed),
                                        G_CALLBACK (embed_net_stop_cb),
                                        dialog);
159

Michael Catanzaro's avatar
Michael Catanzaro committed
160 161 162 163
  embedptr = &dialog->embed;
  g_object_remove_weak_pointer (G_OBJECT (dialog->embed),
                                (gpointer *)embedptr);
  dialog->embed = NULL;
164 165
}

166
static void
167
ephy_encoding_dialog_attach_embed (EphyEncodingDialog *dialog)
168
{
Michael Catanzaro's avatar
Michael Catanzaro committed
169 170
  EphyEmbed *embed;
  EphyEmbed **embedptr;
171

Michael Catanzaro's avatar
Michael Catanzaro committed
172 173
  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (dialog->window));
  g_return_if_fail (EPHY_IS_EMBED (embed));
174

Michael Catanzaro's avatar
Michael Catanzaro committed
175 176
  g_signal_connect (G_OBJECT (ephy_embed_get_web_view (embed)), "load-changed",
                    G_CALLBACK (embed_net_stop_cb), dialog);
177

Michael Catanzaro's avatar
Michael Catanzaro committed
178
  dialog->embed = embed;
179

Michael Catanzaro's avatar
Michael Catanzaro committed
180 181 182
  embedptr = &dialog->embed;
  g_object_add_weak_pointer (G_OBJECT (dialog->embed),
                             (gpointer *)embedptr);
183
}
184

185 186 187
static void
ephy_encoding_dialog_sync_embed (EphyWindow *window, GParamSpec *pspec, EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
188 189 190
  ephy_encoding_dialog_detach_embed (dialog);
  ephy_encoding_dialog_attach_embed (dialog);
  sync_encoding_against_embed (dialog);
191 192 193 194 195
}

static void
activate_choice (EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
196
  WebKitWebView *view;
197

Michael Catanzaro's avatar
Michael Catanzaro committed
198 199
  g_return_if_fail (EPHY_IS_EMBED (dialog->embed));
  view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (dialog->embed);
200

Michael Catanzaro's avatar
Michael Catanzaro committed
201 202 203 204
  if (gtk_switch_get_active (dialog->default_switch)) {
    webkit_web_view_set_custom_charset (view, NULL);
  } else if (dialog->selected_encoding != NULL) {
    const char *code;
205

Michael Catanzaro's avatar
Michael Catanzaro committed
206
    code = dialog->selected_encoding;
207

Michael Catanzaro's avatar
Michael Catanzaro committed
208
    webkit_web_view_set_custom_charset (view, code);
209

Michael Catanzaro's avatar
Michael Catanzaro committed
210 211
    ephy_encodings_add_recent (dialog->encodings, code);
  }
212 213
}

214
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
215 216 217
ephy_encoding_dialog_response_cb (GtkWidget          *widget,
                                  int                 response,
                                  EphyEncodingDialog *dialog)
218
{
Michael Catanzaro's avatar
Michael Catanzaro committed
219
  gtk_widget_destroy (GTK_WIDGET (dialog));
220 221 222
}

static void
Arnaud B.'s avatar
Arnaud B. committed
223
clean_selected_row (gpointer row, gpointer null_pointer)
224
{
Michael Catanzaro's avatar
Michael Catanzaro committed
225 226 227
  EphyEncodingRow *ephy_encoding_row;
  ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (row)));
  ephy_encoding_row_set_selected (ephy_encoding_row, FALSE);
Arnaud B.'s avatar
Arnaud B. committed
228
}
229

Arnaud B.'s avatar
Arnaud B. committed
230 231 232
static void
clean_selected_list_box (GtkListBox *list_box)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
233 234 235 236
  GList *rows;
  rows = gtk_container_get_children (GTK_CONTAINER (list_box));
  g_list_foreach (rows, (GFunc)clean_selected_row, NULL);
  g_list_free (rows);
Arnaud B.'s avatar
Arnaud B. committed
237
}
238

Arnaud B.'s avatar
Arnaud B. committed
239 240 241
static void
clean_selected (EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
242 243 244
  clean_selected_list_box (dialog->list_box);
  clean_selected_list_box (dialog->recent_list_box);
  clean_selected_list_box (dialog->related_list_box);
Arnaud B.'s avatar
Arnaud B. committed
245
}
246

Arnaud B.'s avatar
Arnaud B. committed
247 248 249 250 251
static void
row_activated_cb (GtkListBox         *box,
                  GtkListBoxRow      *row,
                  EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
252 253 254
  EphyEncodingRow *ephy_encoding_row;
  EphyEncoding *ephy_encoding;
  const char *selected_encoding;
255

Michael Catanzaro's avatar
Michael Catanzaro committed
256 257
  if (dialog->update_embed_tag || dialog->update_view_tag)
    return;
258

Michael Catanzaro's avatar
Michael Catanzaro committed
259
  dialog->update_view_tag = TRUE;
Arnaud B.'s avatar
Arnaud B. committed
260

Michael Catanzaro's avatar
Michael Catanzaro committed
261 262 263
  ephy_encoding_row = EPHY_ENCODING_ROW (gtk_bin_get_child (GTK_BIN (row)));
  ephy_encoding = ephy_encoding_row_get_encoding (ephy_encoding_row);
  selected_encoding = ephy_encoding_get_encoding (ephy_encoding);
Arnaud B.'s avatar
Arnaud B. committed
264

Michael Catanzaro's avatar
Michael Catanzaro committed
265
  dialog->selected_encoding = selected_encoding;
Arnaud B.'s avatar
Arnaud B. committed
266

Michael Catanzaro's avatar
Michael Catanzaro committed
267 268
  clean_selected (dialog);
  ephy_encoding_row_set_selected (ephy_encoding_row, TRUE);
Arnaud B.'s avatar
Arnaud B. committed
269

Michael Catanzaro's avatar
Michael Catanzaro committed
270
  activate_choice (dialog);
Arnaud B.'s avatar
Arnaud B. committed
271

Michael Catanzaro's avatar
Michael Catanzaro committed
272
  dialog->update_view_tag = FALSE;
273 274
}

275 276 277 278
static gboolean
default_switch_toggled_cb (GtkSwitch          *default_switch,
                           gboolean            state,
                           EphyEncodingDialog *dialog)
279
{
Michael Catanzaro's avatar
Michael Catanzaro committed
280 281 282 283
  if (dialog->update_embed_tag || dialog->update_view_tag) {
    gtk_switch_set_state (default_switch, !state);              /* cancel switch change */
    return TRUE;
  }
284

Michael Catanzaro's avatar
Michael Catanzaro committed
285
  dialog->update_view_tag = TRUE;
Arnaud B.'s avatar
Arnaud B. committed
286

Michael Catanzaro's avatar
Michael Catanzaro committed
287 288
  gtk_switch_set_active (default_switch, state);
  gtk_switch_set_state (default_switch, state);
Arnaud B.'s avatar
Arnaud B. committed
289

Michael Catanzaro's avatar
Michael Catanzaro committed
290 291 292 293
  /* TODO if state == false && selected_encoding == NULL, select safe default in list, or find another solution */
  if (state)
    clean_selected (dialog);
  activate_choice (dialog);
Arnaud B.'s avatar
Arnaud B. committed
294

Michael Catanzaro's avatar
Michael Catanzaro committed
295
  dialog->update_view_tag = FALSE;
296

Michael Catanzaro's avatar
Michael Catanzaro committed
297
  return TRUE;
298 299
}

Arnaud B.'s avatar
Arnaud B. committed
300 301 302 303
static void
show_all_button_clicked_cb (GtkButton          *show_all_button,
                            EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
304
  gtk_stack_set_visible_child_name (dialog->type_stack, "scrolled-window");
Arnaud B.'s avatar
Arnaud B. committed
305 306 307 308 309
}

static gint
sort_list_store (gconstpointer a,
                 gconstpointer b,
Michael Catanzaro's avatar
Michael Catanzaro committed
310
                 gpointer      user_data)
Arnaud B.'s avatar
Arnaud B. committed
311
{
Michael Catanzaro's avatar
Michael Catanzaro committed
312 313
  const char *encoding1 = ephy_encoding_get_title_elided ((EphyEncoding *)a);
  const char *encoding2 = ephy_encoding_get_title_elided ((EphyEncoding *)b);
Arnaud B.'s avatar
Arnaud B. committed
314

Michael Catanzaro's avatar
Michael Catanzaro committed
315
  return g_strcmp0 (encoding1, encoding2);
Arnaud B.'s avatar
Arnaud B. committed
316 317 318 319 320 321
}

static GtkWidget *
create_list_box_row (gpointer object,
                     gpointer user_data)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
322
  return GTK_WIDGET (ephy_encoding_row_new (EPHY_ENCODING (object)));
Arnaud B.'s avatar
Arnaud B. committed
323 324 325
}

static void
Michael Catanzaro's avatar
Michael Catanzaro committed
326
add_list_item (EphyEncoding *encoding, GtkListBox *list_box)
Arnaud B.'s avatar
Arnaud B. committed
327
{
Michael Catanzaro's avatar
Michael Catanzaro committed
328
  gtk_container_add (GTK_CONTAINER (list_box), GTK_WIDGET (ephy_encoding_row_new (encoding)));
Arnaud B.'s avatar
Arnaud B. committed
329 330 331 332 333
}

static int
sort_encodings (gconstpointer a, gconstpointer b)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
334 335 336
  EphyEncoding *enc1 = (EphyEncoding *)a;
  EphyEncoding *enc2 = (EphyEncoding *)b;
  const char *key1, *key2;
Arnaud B.'s avatar
Arnaud B. committed
337

Michael Catanzaro's avatar
Michael Catanzaro committed
338 339
  key1 = ephy_encoding_get_collation_key (enc1);
  key2 = ephy_encoding_get_collation_key (enc2);
Arnaud B.'s avatar
Arnaud B. committed
340

Michael Catanzaro's avatar
Michael Catanzaro committed
341
  return strcmp (key1, key2);
Arnaud B.'s avatar
Arnaud B. committed
342 343
}

344 345 346
static void
ephy_encoding_dialog_init (EphyEncodingDialog *dialog)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
347 348
  GList *encodings, *p;
  GListStore *store;
349

Michael Catanzaro's avatar
Michael Catanzaro committed
350
  gtk_widget_init_template (GTK_WIDGET (dialog));
351

Michael Catanzaro's avatar
Michael Catanzaro committed
352 353
  dialog->update_embed_tag = FALSE;
  dialog->update_view_tag = FALSE;
Arnaud B.'s avatar
Arnaud B. committed
354

355
  dialog->encodings = ephy_embed_shell_get_encodings (EPHY_EMBED_SHELL (ephy_shell_get_default ()));
356

Michael Catanzaro's avatar
Michael Catanzaro committed
357
  encodings = ephy_encodings_get_all (dialog->encodings);
Arnaud B.'s avatar
Arnaud B. committed
358

Michael Catanzaro's avatar
Michael Catanzaro committed
359 360 361 362 363 364
  store = g_list_store_new (EPHY_TYPE_ENCODING);
  for (p = encodings; p; p = p->next) {
    EphyEncoding *encoding = EPHY_ENCODING (p->data);
    g_list_store_insert_sorted (store, encoding, sort_list_store, NULL);
  }
  g_list_free (encodings);
365

Michael Catanzaro's avatar
Michael Catanzaro committed
366 367 368
  gtk_list_box_bind_model (dialog->list_box, G_LIST_MODEL (store),
                           create_list_box_row,
                           NULL, NULL);
Arnaud B.'s avatar
Arnaud B. committed
369 370 371 372 373
}

static void
ephy_encoding_dialog_constructed (GObject *object)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
  EphyEncodingDialog *dialog;
  WebKitWebView *view;
  EphyEncoding *enc_node;
  EphyLanguageGroup groups;
  GList *recent;
  GList *related = NULL;

  /* selected encoding */
  dialog = EPHY_ENCODING_DIALOG (object);

  g_return_if_fail (EPHY_IS_EMBED (dialog->embed));
  view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (dialog->embed);

  dialog->selected_encoding = webkit_web_view_get_custom_charset (view);

  /* recent */
  recent = ephy_encodings_get_recent (dialog->encodings);
  if (recent != NULL) {
    recent = g_list_sort (recent, (GCompareFunc)sort_encodings);
    g_list_foreach (recent, (GFunc)add_list_item, dialog->recent_list_box);
  } else
    gtk_widget_hide (GTK_WIDGET (dialog->recent_grid));

  /* related */
  if (dialog->selected_encoding != NULL) {
    enc_node = ephy_encodings_get_encoding (dialog->encodings, dialog->selected_encoding, TRUE);
    g_assert (EPHY_IS_ENCODING (enc_node));
    groups = ephy_encoding_get_language_groups (enc_node);

    related = ephy_encodings_get_encodings (dialog->encodings, groups);
  }
  if (related != NULL) {
    related = g_list_sort (related, (GCompareFunc)sort_encodings);
    g_list_foreach (related, (GFunc)add_list_item, dialog->related_list_box);
  } else
    gtk_widget_hide (GTK_WIDGET (dialog->related_grid));

  /* update list_boxes */
  sync_encoding_against_embed (dialog);

  /* chaining */
  G_OBJECT_CLASS (ephy_encoding_dialog_parent_class)->constructed (object);
416 417 418 419 420
}

static void
ephy_encoding_dialog_dispose (GObject *object)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
421
  EphyEncodingDialog *dialog = EPHY_ENCODING_DIALOG (object);
422

Michael Catanzaro's avatar
Michael Catanzaro committed
423 424 425
  g_signal_handlers_disconnect_by_func (dialog->window,
                                        G_CALLBACK (ephy_encoding_dialog_sync_embed),
                                        dialog);
426

Michael Catanzaro's avatar
Michael Catanzaro committed
427 428
  if (dialog->embed != NULL)
    ephy_encoding_dialog_detach_embed (dialog);
429

Michael Catanzaro's avatar
Michael Catanzaro committed
430
  G_OBJECT_CLASS (ephy_encoding_dialog_parent_class)->dispose (object);
431 432
}

433 434
static void
ephy_encoding_dialog_set_parent_window (EphyEncodingDialog *dialog,
Michael Catanzaro's avatar
Michael Catanzaro committed
435
                                        EphyWindow         *window)
436
{
Michael Catanzaro's avatar
Michael Catanzaro committed
437
  g_return_if_fail (EPHY_IS_WINDOW (window));
438

Michael Catanzaro's avatar
Michael Catanzaro committed
439 440
  g_signal_connect (G_OBJECT (window), "notify::active-child",
                    G_CALLBACK (ephy_encoding_dialog_sync_embed), dialog);
441

Michael Catanzaro's avatar
Michael Catanzaro committed
442
  dialog->window = window;
443

Michael Catanzaro's avatar
Michael Catanzaro committed
444
  ephy_encoding_dialog_attach_embed (dialog);
445 446 447 448 449 450 451 452
}

static void
ephy_encoding_dialog_set_property (GObject      *object,
                                   guint         prop_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
453 454 455 456 457 458 459 460 461
  switch (prop_id) {
    case PROP_PARENT_WINDOW:
      ephy_encoding_dialog_set_parent_window (EPHY_ENCODING_DIALOG (object),
                                              g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
462
}
463

464 465 466 467 468 469
static void
ephy_encoding_dialog_get_property (GObject    *object,
                                   guint       prop_id,
                                   GValue     *value,
                                   GParamSpec *pspec)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
470 471 472 473 474 475 476 477
  switch (prop_id) {
    case PROP_PARENT_WINDOW:
      g_value_set_object (value, EPHY_ENCODING_DIALOG (object)->window);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
478 479 480 481 482
}

static void
ephy_encoding_dialog_class_init (EphyEncodingDialogClass *klass)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  /* class creation */
  object_class->constructed = ephy_encoding_dialog_constructed;
  object_class->set_property = ephy_encoding_dialog_set_property;
  object_class->get_property = ephy_encoding_dialog_get_property;
  object_class->dispose = ephy_encoding_dialog_dispose;

  obj_properties[PROP_PARENT_WINDOW] =
    g_param_spec_object ("parent-window",
                         "Parent window",
                         "Parent window",
                         EPHY_TYPE_WINDOW,
                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);

  /* load from UI file */
502
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/encoding-dialog.ui");
Michael Catanzaro's avatar
Michael Catanzaro committed
503 504 505 506 507 508 509 510 511 512 513 514 515

  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, type_stack);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, default_switch);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, list_box);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, recent_list_box);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, related_list_box);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, recent_grid);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingDialog, related_grid);

  gtk_widget_class_bind_template_callback (widget_class, default_switch_toggled_cb);
  gtk_widget_class_bind_template_callback (widget_class, ephy_encoding_dialog_response_cb);
  gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
  gtk_widget_class_bind_template_callback (widget_class, show_all_button_clicked_cb);
516
}
517

518 519 520
EphyEncodingDialog *
ephy_encoding_dialog_new (EphyWindow *parent)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
521 522 523 524
  return g_object_new (EPHY_TYPE_ENCODING_DIALOG,
                       "use-header-bar", TRUE,
                       "parent-window", parent,
                       NULL);
525
}