| 1 |
/* font-manager-license-page.c |
| 2 |
* |
| 3 |
* Copyright (C) 2009-2023 Jerry Casiano |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. |
| 17 |
* |
| 18 |
* If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "font-manager-license-page.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* SECTION: font-manager-license-page |
| 25 |
* @short_description: Font licensing details |
| 26 |
* @title: License Pane |
| 27 |
* @include: font-manager-license-page.h |
| 28 |
* |
| 29 |
* Widget which displays embedded or detected font licensing data. |
| 30 |
*/ |
| 31 |
|
| 32 |
struct _FontManagerLicensePage |
| 33 |
{ |
| 34 |
GtkWidget parent; |
| 35 |
|
| 36 |
gint _fsType; |
| 37 |
GtkWidget *fsType; |
| 38 |
GtkWidget *license_data; |
| 39 |
GtkWidget *license_url; |
| 40 |
GtkWidget *placeholder; |
| 41 |
|
| 42 |
}; |
| 43 |
|
| 44 |
G_DEFINE_TYPE(FontManagerLicensePage, font_manager_license_page, GTK_TYPE_WIDGET) |
| 45 |
|
| 46 |
enum |
| 47 |
{ |
| 48 |
PROP_RESERVED, |
| 49 |
PROP_FSTYPE, |
| 50 |
PROP_LICENSE_DATA, |
| 51 |
PROP_LICENSE_URL, |
| 52 |
N_PROPERTIES |
| 53 |
}; |
| 54 |
|
| 55 |
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; |
| 56 |
|
| 57 |
static void |
| 58 |
font_manager_license_page_dispose (GObject *gobject) |
| 59 |
{ |
| 60 |
FontManagerLicensePage *self = FONT_MANAGER_LICENSE_PAGE(gobject); |
| 61 |
g_return_if_fail(self != NULL); |
| 62 |
font_manager_widget_dispose(GTK_WIDGET(gobject)); |
| 63 |
G_OBJECT_CLASS(font_manager_license_page_parent_class)->dispose(gobject); |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
font_manager_license_page_get_property (GObject *gobject, |
| 69 |
guint property_id, |
| 70 |
GValue *value, |
| 71 |
GParamSpec *pspec) |
| 72 |
{ |
| 73 |
g_return_if_fail(gobject != NULL); |
| 74 |
FontManagerLicensePage *self = FONT_MANAGER_LICENSE_PAGE(gobject); |
| 75 |
g_autofree gchar *data = NULL; |
| 76 |
switch (property_id) { |
| 77 |
case PROP_FSTYPE: |
| 78 |
g_value_set_enum(value, self->_fsType); |
| 79 |
break; |
| 80 |
case PROP_LICENSE_DATA: |
| 81 |
data = font_manager_license_page_get_license_data(self); |
| 82 |
g_value_set_string(value, data); |
| 83 |
break; |
| 84 |
case PROP_LICENSE_URL: |
| 85 |
data = font_manager_license_page_get_license_url(self); |
| 86 |
g_value_set_string(value, data); |
| 87 |
break; |
| 88 |
default: |
| 89 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); |
| 90 |
} |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
font_manager_license_page_set_property (GObject *gobject, |
| 96 |
guint property_id, |
| 97 |
const GValue *value, |
| 98 |
GParamSpec *pspec) |
| 99 |
{ |
| 100 |
g_return_if_fail(gobject != NULL); |
| 101 |
FontManagerLicensePage *self = FONT_MANAGER_LICENSE_PAGE(gobject); |
| 102 |
switch (property_id) { |
| 103 |
case PROP_FSTYPE: |
| 104 |
font_manager_license_page_set_fsType(self, g_value_get_int(value)); |
| 105 |
break; |
| 106 |
case PROP_LICENSE_DATA: |
| 107 |
font_manager_license_page_set_license_data(self, g_value_get_string(value)); |
| 108 |
break; |
| 109 |
case PROP_LICENSE_URL: |
| 110 |
font_manager_license_page_set_license_url(self, g_value_get_string(value)); |
| 111 |
break; |
| 112 |
default: |
| 113 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); |
| 114 |
} |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
static void |
| 119 |
font_manager_license_page_class_init (FontManagerLicensePageClass *klass) |
| 120 |
{ |
| 121 |
GObjectClass *object_class = G_OBJECT_CLASS(klass); |
| 122 |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| 123 |
|
| 124 |
object_class->dispose = font_manager_license_page_dispose; |
| 125 |
object_class->get_property = font_manager_license_page_get_property; |
| 126 |
object_class->set_property = font_manager_license_page_set_property; |
| 127 |
gtk_widget_class_set_layout_manager_type(widget_class, GTK_TYPE_BOX_LAYOUT); |
| 128 |
|
| 129 |
/** |
| 130 |
* FontManagerLicensePage:fstype: |
| 131 |
* |
| 132 |
* Font embedding information |
| 133 |
*/ |
| 134 |
obj_properties[PROP_FSTYPE] = g_param_spec_int("fstype", |
| 135 |
NULL, |
| 136 |
"Font embedding information", |
| 137 |
G_MININT, G_MAXINT, 0, |
| 138 |
G_PARAM_STATIC_STRINGS | |
| 139 |
G_PARAM_READWRITE | |
| 140 |
G_PARAM_EXPLICIT_NOTIFY); |
| 141 |
|
| 142 |
/** |
| 143 |
* FontManagerLicensePage:license-data: |
| 144 |
* |
| 145 |
* Embedded or detected license text |
| 146 |
*/ |
| 147 |
obj_properties[PROP_LICENSE_DATA] = g_param_spec_string("license-data", |
| 148 |
NULL, |
| 149 |
"Embedded or detected license text", |
| 150 |
NULL, |
| 151 |
G_PARAM_STATIC_STRINGS | |
| 152 |
G_PARAM_READWRITE | |
| 153 |
G_PARAM_EXPLICIT_NOTIFY); |
| 154 |
|
| 155 |
/** |
| 156 |
* FontManagerLicensePage:license-url: |
| 157 |
* |
| 158 |
* Embedded or detected license url |
| 159 |
*/ |
| 160 |
obj_properties[PROP_LICENSE_URL] = g_param_spec_string("license-url", |
| 161 |
NULL, |
| 162 |
"Embedded or detected license url", |
| 163 |
NULL, |
| 164 |
G_PARAM_STATIC_STRINGS | |
| 165 |
G_PARAM_READWRITE | |
| 166 |
G_PARAM_EXPLICIT_NOTIFY); |
| 167 |
|
| 168 |
g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties); |
| 169 |
return; |
| 170 |
} |
| 171 |
|
| 172 |
static void |
| 173 |
font_manager_license_page_init (FontManagerLicensePage *self) |
| 174 |
{ |
| 175 |
g_return_if_fail(self != NULL); |
| 176 |
gtk_widget_add_css_class(GTK_WIDGET(self), FONT_MANAGER_STYLE_CLASS_VIEW); |
| 177 |
font_manager_widget_set_name(GTK_WIDGET(self), "FontManagerLicensePage"); |
| 178 |
self->fsType = gtk_label_new(NULL); |
| 179 |
const gchar *msg = _("File does not contain license information."); |
| 180 |
self->placeholder = font_manager_place_holder_new(NULL, NULL, msg, "dialog-question-symbolic"); |
| 181 |
self->license_data = gtk_text_view_new(); |
| 182 |
self->license_url = gtk_link_button_new(""); |
| 183 |
GtkWidget *overlay = gtk_overlay_new(); |
| 184 |
GtkWidget *scroll = gtk_scrolled_window_new(); |
| 185 |
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); |
| 186 |
g_autoptr(PangoAttrList) attrs = pango_attr_list_new(); |
| 187 |
PangoAttribute *attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); |
| 188 |
pango_attr_list_insert(attrs, attr); |
| 189 |
gtk_label_set_attributes(GTK_LABEL(self->fsType), attrs); |
| 190 |
gtk_text_view_set_editable(GTK_TEXT_VIEW(self->license_data), FALSE); |
| 191 |
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(self->license_data), FALSE); |
| 192 |
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->license_data), GTK_WRAP_WORD_CHAR); |
| 193 |
GtkWidget *separator_top = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
| 194 |
GtkWidget *separator_bottom = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
| 195 |
gtk_widget_add_css_class(separator_top, "thin-separator"); |
| 196 |
gtk_widget_add_css_class(separator_bottom, "thin-separator"); |
| 197 |
gtk_widget_set_opacity(separator_top, 0.25); |
| 198 |
gtk_widget_set_opacity(separator_bottom, 0.25); |
| 199 |
gtk_box_prepend(GTK_BOX(box), self->fsType); |
| 200 |
gtk_box_append(GTK_BOX(box), separator_top); |
| 201 |
gtk_box_append(GTK_BOX(box), overlay); |
| 202 |
gtk_box_append(GTK_BOX(box), separator_bottom); |
| 203 |
gtk_box_append(GTK_BOX(box), self->license_url); |
| 204 |
gtk_overlay_set_child(GTK_OVERLAY(overlay), scroll); |
| 205 |
gtk_overlay_add_overlay(GTK_OVERLAY(overlay), self->placeholder); |
| 206 |
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scroll), self->license_data); |
| 207 |
gtk_widget_set_parent(box, GTK_WIDGET(self)); |
| 208 |
gtk_widget_set_opacity(self->fsType, 0.55); |
| 209 |
font_manager_widget_set_expand(GTK_WIDGET(self), TRUE); |
| 210 |
font_manager_widget_set_expand(scroll, TRUE); |
| 211 |
font_manager_widget_set_margin(separator_top, 0); |
| 212 |
font_manager_widget_set_margin(separator_bottom, 0); |
| 213 |
gtk_widget_set_margin_start(separator_top, FONT_MANAGER_DEFAULT_MARGIN * 1.5); |
| 214 |
gtk_widget_set_margin_end(separator_top, FONT_MANAGER_DEFAULT_MARGIN * 1.5); |
| 215 |
gtk_widget_set_margin_start(separator_bottom, FONT_MANAGER_DEFAULT_MARGIN * 1.5); |
| 216 |
gtk_widget_set_margin_end(separator_bottom, FONT_MANAGER_DEFAULT_MARGIN * 1.5); |
| 217 |
font_manager_widget_set_margin(self->fsType, FONT_MANAGER_DEFAULT_MARGIN * 1.25); |
| 218 |
gtk_widget_set_margin_start(self->license_data, FONT_MANAGER_DEFAULT_MARGIN * 2); |
| 219 |
gtk_widget_set_margin_end(self->license_data, FONT_MANAGER_DEFAULT_MARGIN * 2); |
| 220 |
gtk_widget_set_visible(self->fsType, FALSE); |
| 221 |
gtk_widget_set_visible(self->license_data, FALSE); |
| 222 |
gtk_widget_set_visible(self->license_url, FALSE); |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* font_manager_license_page_get_fsType: |
| 228 |
* @self: #FontManagerLicensePage |
| 229 |
* |
| 230 |
* Returns: #FontManagerfsType |
| 231 |
*/ |
| 232 |
gint |
| 233 |
font_manager_license_page_get_fsType (FontManagerLicensePage *self) |
| 234 |
{ |
| 235 |
g_return_val_if_fail(self != NULL, 0); |
| 236 |
return self->_fsType; |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* font_manager_license_page_get_license_data: |
| 241 |
* @self: #FontManagerLicensePage |
| 242 |
* |
| 243 |
* Returns: (transfer none) (nullable): |
| 244 |
* A newly allocated string that must be freed with #g_free or %NULL |
| 245 |
*/ |
| 246 |
gchar * |
| 247 |
font_manager_license_page_get_license_data (FontManagerLicensePage *self) |
| 248 |
{ |
| 249 |
g_return_val_if_fail(self != NULL, NULL); |
| 250 |
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->license_data)); |
| 251 |
GtkTextIter start, end; |
| 252 |
gtk_text_buffer_get_bounds(buffer, &start, &end); |
| 253 |
return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* font_manager_license_page_get_license_url: |
| 258 |
* @self: #FontManagerLicensePage |
| 259 |
* |
| 260 |
* Returns: (transfer none) (nullable): |
| 261 |
* A newly allocated string that must be freed with #g_free or %NULL |
| 262 |
*/ |
| 263 |
gchar * |
| 264 |
font_manager_license_page_get_license_url (FontManagerLicensePage *self) |
| 265 |
{ |
| 266 |
g_return_val_if_fail(self != NULL, NULL); |
| 267 |
return g_strdup(gtk_link_button_get_uri(GTK_LINK_BUTTON(self->license_url))); |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* font_manager_license_page_set_fsType: |
| 272 |
* @self: #FontManagerLicensePage |
| 273 |
* @fstype: #FontManagerfsType |
| 274 |
*/ |
| 275 |
void |
| 276 |
font_manager_license_page_set_fsType (FontManagerLicensePage *self, gint fstype) |
| 277 |
{ |
| 278 |
g_return_if_fail(self != NULL); |
| 279 |
self->_fsType = fstype; |
| 280 |
gtk_label_set_label(GTK_LABEL(self->fsType), font_manager_fsType_to_string(fstype)); |
| 281 |
gtk_widget_set_visible(self->fsType, gtk_widget_get_visible(self->license_data)); |
| 282 |
return; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* font_manager_license_page_set_license_data: |
| 287 |
* @self: #FontManagerLicensePage |
| 288 |
* @license_data: (nullable): License data embedded in font file or %NULL |
| 289 |
*/ |
| 290 |
void |
| 291 |
font_manager_license_page_set_license_data (FontManagerLicensePage *self, |
| 292 |
const gchar *license_data) |
| 293 |
{ |
| 294 |
g_return_if_fail(self != NULL); |
| 295 |
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->license_data)); |
| 296 |
g_autofree gchar *license_text = license_data ? |
| 297 |
g_strdup_printf("\n%s\n", license_data) : |
| 298 |
g_strdup(""); |
| 299 |
gtk_text_buffer_set_text(buffer, license_text, -1); |
| 300 |
gtk_widget_set_visible(self->placeholder, license_data == NULL); |
| 301 |
gtk_widget_set_visible(self->license_data, license_data != NULL); |
| 302 |
gtk_widget_set_visible(self->fsType, license_data != NULL); |
| 303 |
const gchar *uri = gtk_link_button_get_uri(GTK_LINK_BUTTON(self->license_url)); |
| 304 |
gtk_widget_set_visible(self->license_url, uri != NULL); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* font_manager_license_page_set_license_url: |
| 310 |
* @self: #FontManagerLicensePage |
| 311 |
* @url: (nullable): URL to latest version of license or %NULL |
| 312 |
*/ |
| 313 |
void |
| 314 |
font_manager_license_page_set_license_url (FontManagerLicensePage *self, |
| 315 |
const gchar *url) |
| 316 |
{ |
| 317 |
g_return_if_fail(self != NULL); |
| 318 |
gtk_button_set_label(GTK_BUTTON(self->license_url), url); |
| 319 |
gtk_link_button_set_uri(GTK_LINK_BUTTON(self->license_url), url ? url : ""); |
| 320 |
gboolean visible = url != NULL && gtk_widget_get_visible(self->license_data); |
| 321 |
gtk_widget_set_visible(self->license_url, visible); |
| 322 |
return; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* font_manager_license_page_new: |
| 327 |
* |
| 328 |
* Returns: (transfer full): A newly created #FontManagerLicensePage. |
| 329 |
* Free the returned object using #g_object_unref(). |
| 330 |
*/ |
| 331 |
GtkWidget * |
| 332 |
font_manager_license_page_new (void) |
| 333 |
{ |
| 334 |
return g_object_new(FONT_MANAGER_TYPE_LICENSE_PAGE, NULL); |
| 335 |
} |
| 336 |
|