gimpcolorprofileview.c 6.6 KB
Newer Older
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
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * GimpColorProfileView
 * Copyright (C) 2014 Michael Natterer <mitch@gimp.org>
 *
 * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <string.h>

#include <gegl.h>
#include <gtk/gtk.h>

#include "libgimpcolor/gimpcolor.h"

#include "gimpwidgetstypes.h"

#include "gimpcolorprofileview.h"

34 35
#include "libgimp/libgimp-intl.h"

36 37 38

struct _GimpColorProfileViewPrivate
{
39
  GimpColorProfile *profile;
40 41 42 43
};


static void   gimp_color_profile_view_constructed  (GObject *object);
44
static void   gimp_color_profile_view_finalize     (GObject *object);
45 46 47 48 49 50 51 52 53 54 55 56 57 58


G_DEFINE_TYPE (GimpColorProfileView, gimp_color_profile_view,
               GTK_TYPE_TEXT_VIEW);

#define parent_class gimp_color_profile_view_parent_class


static void
gimp_color_profile_view_class_init (GimpColorProfileViewClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = gimp_color_profile_view_constructed;
59
  object_class->finalize    = gimp_color_profile_view_finalize;
60 61 62 63 64 65 66

  g_type_class_add_private (klass, sizeof (GimpColorProfileViewPrivate));
}

static void
gimp_color_profile_view_init (GimpColorProfileView *view)
{
67 68 69
  view->priv = G_TYPE_INSTANCE_GET_PRIVATE (view,
                                            GIMP_TYPE_COLOR_PROFILE_VIEW,
                                            GimpColorProfileViewPrivate);
70 71 72 73 74 75 76 77 78 79 80
}

static void
gimp_color_profile_view_constructed (GObject *object)
{
  GtkTextBuffer *buffer;

  G_OBJECT_CLASS (parent_class)->constructed (object);

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (object));

81 82 83
  gtk_text_buffer_create_tag (buffer, "text",
                              NULL);
  gtk_text_buffer_create_tag (buffer, "title",
84 85 86
                              "weight", PANGO_WEIGHT_BOLD,
                              "scale",  PANGO_SCALE_LARGE,
                              NULL);
87 88 89 90
  gtk_text_buffer_create_tag (buffer, "header",
                              "weight", PANGO_WEIGHT_BOLD,
                              NULL);
  gtk_text_buffer_create_tag (buffer, "error",
91 92 93 94 95 96 97 98 99 100 101
                              "style",  PANGO_STYLE_OBLIQUE,
                              NULL);

  gtk_text_view_set_editable (GTK_TEXT_VIEW (object), FALSE);
  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (object), GTK_WRAP_WORD);

  gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (object), 6);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (object), 6);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (object), 6);
}

102 103 104 105 106
static void
gimp_color_profile_view_finalize (GObject *object)
{
  GimpColorProfileView *view = GIMP_COLOR_PROFILE_VIEW (object);

107
  g_clear_object (&view->priv->profile);
108 109 110 111

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

112 113 114 115 116 117 118 119
GtkWidget *
gimp_color_profile_view_new (void)
{
  return g_object_new (GIMP_TYPE_COLOR_PROFILE_VIEW, NULL);
}

void
gimp_color_profile_view_set_profile (GimpColorProfileView *view,
120
                                     GimpColorProfile     *profile)
121 122 123 124
{
  GtkTextBuffer *buffer;

  g_return_if_fail (GIMP_IS_COLOR_PROFILE_VIEW (view));
125 126 127 128
  g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));

  if (profile == view->priv->profile)
    return;
129 130 131 132 133

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

  gtk_text_buffer_set_text (buffer, "", 0);

134 135 136
  if (view->priv->profile)
    g_object_unref (view->priv->profile);

137
  view->priv->profile = profile;
138

139 140 141
  if (view->priv->profile)
    {
      GtkTextIter  iter;
142
      const gchar *text;
143

144
      g_object_ref (view->priv->profile);
145

146
      gtk_text_buffer_get_start_iter (buffer, &iter);
147

148 149 150 151 152 153 154 155
      text = gimp_color_profile_get_label (profile);
      if (text && strlen (text))
        {
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                                    text, -1,
                                                    "title", NULL);
          gtk_text_buffer_insert (buffer, &iter, "\n", 1);
        }
156

157 158
      text = gimp_color_profile_get_model (profile);
      if (text && strlen (text))
159 160
        {
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
161 162
                                                    text, -1,
                                                    "text", NULL);
163 164
          gtk_text_buffer_insert (buffer, &iter, "\n", 1);
        }
165

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
      text = gimp_color_profile_get_manufacturer (profile);
      if (text && strlen (text))
        {
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                                    _("Manufacturer: "), -1,
                                                    "header", NULL);
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                                    text, -1,
                                                    "text", NULL);
          gtk_text_buffer_insert (buffer, &iter, "\n", 1);
        }

      text = gimp_color_profile_get_copyright (profile);
      if (text && strlen (text))
        {
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                                    _("Copyright: "), -1,
                                                    "header", NULL);
          gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                                    text, -1,
                                                    "text", NULL);
          gtk_text_buffer_insert (buffer, &iter, "\n", 1);
        }
189
    }
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
}

void
gimp_color_profile_view_set_error (GimpColorProfileView *view,
                                   const gchar          *message)
{
  GtkTextBuffer *buffer;
  GtkTextIter    iter;

  g_return_if_fail (GIMP_IS_COLOR_PROFILE_VIEW (view));
  g_return_if_fail (message != NULL);

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

  gtk_text_buffer_set_text (buffer, "", 0);

  gtk_text_buffer_get_start_iter (buffer, &iter);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            message, -1,
210
                                            "error", NULL);
211
}