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

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

#include "ephy-encoding.h"

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

Michael Catanzaro's avatar
Michael Catanzaro committed
29 30
struct _EphyEncodingRow {
  GtkGrid parent_instance;
Arnaud B.'s avatar
Arnaud B. committed
31

Michael Catanzaro's avatar
Michael Catanzaro committed
32
  EphyEncoding *encoding;
Arnaud B.'s avatar
Arnaud B. committed
33

Michael Catanzaro's avatar
Michael Catanzaro committed
34 35 36
  /* from the UI file */
  GtkLabel *encoding_label;
  GtkImage *selected_image;
Arnaud B.'s avatar
Arnaud B. committed
37 38
};

Michael Catanzaro's avatar
Michael Catanzaro committed
39 40 41 42
enum {
  PROP_0,
  PROP_ENCODING,
  LAST_PROP
Arnaud B.'s avatar
Arnaud B. committed
43 44 45 46 47 48 49 50 51 52
};

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)
{
53
  g_assert (EPHY_IS_ENCODING_ROW (row));
Arnaud B.'s avatar
Arnaud B. committed
54

Michael Catanzaro's avatar
Michael Catanzaro committed
55 56 57 58
  if (selected)
    gtk_widget_show (GTK_WIDGET (row->selected_image));
  else
    gtk_widget_hide (GTK_WIDGET (row->selected_image));
Arnaud B.'s avatar
Arnaud B. committed
59 60 61 62 63
}

static void
ephy_encoding_row_init (EphyEncodingRow *self)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
64
  gtk_widget_init_template (GTK_WIDGET (self));
Arnaud B.'s avatar
Arnaud B. committed
65 66 67 68 69 70
}

static void
ephy_encoding_row_set_encoding (EphyEncodingRow *self,
                                EphyEncoding    *encoding)
{
71
  g_assert (EPHY_IS_ENCODING (encoding));
Arnaud B.'s avatar
Arnaud B. committed
72

Michael Catanzaro's avatar
Michael Catanzaro committed
73 74 75
  self->encoding = encoding;
  gtk_label_set_text (self->encoding_label,
                      ephy_encoding_get_title_elided (encoding));
Arnaud B.'s avatar
Arnaud B. committed
76 77 78 79 80
}

EphyEncoding *
ephy_encoding_row_get_encoding (EphyEncodingRow *row)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
81
  return row->encoding;
Arnaud B.'s avatar
Arnaud B. committed
82 83 84 85 86 87 88 89
}

static void
ephy_encoding_row_set_property (GObject      *object,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
90 91 92 93 94 95 96 97 98
  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;
  }
Arnaud B.'s avatar
Arnaud B. committed
99 100 101 102 103 104 105 106
}

static void
ephy_encoding_row_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
107 108 109 110 111 112 113 114
  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;
  }
Arnaud B.'s avatar
Arnaud B. committed
115 116 117 118 119
}

static void
ephy_encoding_row_class_init (EphyEncodingRowClass *klass)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
120 121
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
Arnaud B.'s avatar
Arnaud B. committed
122

Michael Catanzaro's avatar
Michael Catanzaro committed
123 124 125
  /* class creation */
  object_class->set_property = ephy_encoding_row_set_property;
  object_class->get_property = ephy_encoding_row_get_property;
Arnaud B.'s avatar
Arnaud B. committed
126

Michael Catanzaro's avatar
Michael Catanzaro committed
127 128 129 130 131 132
  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);
Arnaud B.'s avatar
Arnaud B. committed
133

Michael Catanzaro's avatar
Michael Catanzaro committed
134
  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
Arnaud B.'s avatar
Arnaud B. committed
135

Michael Catanzaro's avatar
Michael Catanzaro committed
136
  /* load from UI file */
137
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/encoding-row.ui");
Arnaud B.'s avatar
Arnaud B. committed
138

Michael Catanzaro's avatar
Michael Catanzaro committed
139 140
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingRow, encoding_label);
  gtk_widget_class_bind_template_child (widget_class, EphyEncodingRow, selected_image);
Arnaud B.'s avatar
Arnaud B. committed
141 142 143 144 145
}

EphyEncodingRow *
ephy_encoding_row_new (EphyEncoding *encoding)
{
Michael Catanzaro's avatar
Michael Catanzaro committed
146 147 148
  return g_object_new (EPHY_TYPE_ENCODING_ROW,
                       "encoding", encoding,
                       NULL);
Arnaud B.'s avatar
Arnaud B. committed
149
}