summaryrefslogtreecommitdiff
path: root/src/ephy-encoding-row.c
blob: ad5894fa1b907cbcc0756170eebb18ec30e1e714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2015 Arnaud Bonatti
 *
 *  This program 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, or (at your option)
 *  any later version.
 *
 *  This program 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, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"
#include "ephy-encoding-row.h"

#include "ephy-encoding.h"

#include <glib/gi18n.h>
#include <gtk/gtk.h>

struct _EphyEncodingRow {
  GtkGrid parent_instance;

  EphyEncoding *encoding;

  /* from the UI file */
  GtkLabel *encoding_label;
  GtkImage *selected_image;
};

enum {
  PROP_0,
  PROP_ENCODING,
  LAST_PROP
};

static GParamSpec *obj_properties[LAST_PROP];

G_DEFINE_TYPE (EphyEncodingRow, ephy_encoding_row, GTK_TYPE_GRID)

void
ephy_encoding_row_set_selected (EphyEncodingRow *row,
                                gboolean         selected)
{
  g_return_if_fail (EPHY_IS_ENCODING_ROW (row));

  if (selected)
    gtk_widget_show (GTK_WIDGET (row->selected_image));
  else
    gtk_widget_hide (GTK_WIDGET (row->selected_image));
}

static void
ephy_encoding_row_init (EphyEncodingRow *self)
{
  gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ephy_encoding_row_set_encoding (EphyEncodingRow *self,
                                EphyEncoding    *encoding)
{
  g_return_if_fail (EPHY_IS_ENCODING (encoding));

  self->encoding = encoding;
  gtk_label_set_text (self->encoding_label,
                      ephy_encoding_get_title_elided (encoding));
}

EphyEncoding *
ephy_encoding_row_get_encoding (EphyEncodingRow *row)
{
  return row->encoding;
}

static void
ephy_encoding_row_set_property (GObject      *object,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  switch (prop_id) {
    case PROP_ENCODING:
      ephy_encoding_row_set_encoding (EPHY_ENCODING_ROW (object),
                                      g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
ephy_encoding_row_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
  switch (prop_id) {
    case PROP_ENCODING:
      g_value_set_object (value, EPHY_ENCODING_ROW (object)->encoding);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
ephy_encoding_row_class_init (EphyEncodingRowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  /* class creation */
  object_class->set_property = ephy_encoding_row_set_property;
  object_class->get_property = ephy_encoding_row_get_property;

  obj_properties[PROP_ENCODING] =
    g_param_spec_object ("encoding",
                         "encoding",
                         "encoding",
                         EPHY_TYPE_ENCODING,
                         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 */
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/encoding-row.ui");

  gtk_widget_class_bind_template_child (widget_class, EphyEncodingRow, encoding_label);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingRow, selected_image);
}

EphyEncodingRow *
ephy_encoding_row_new (EphyEncoding *encoding)
{
  return g_object_new (EPHY_TYPE_ENCODING_ROW,
                       "encoding", encoding,
                       NULL);
}