| 1 |
/* font-manager-directories.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-directories.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* SECTION: font-manager-directories |
| 25 |
* @short_description: Fontconfig font selection configuration |
| 26 |
* @title: Font Directories |
| 27 |
* @include: font-manager-directories.h |
| 28 |
* |
| 29 |
* Set of directories which will be scanned for font files to include in the set of available fonts. |
| 30 |
*/ |
| 31 |
|
| 32 |
G_DEFINE_TYPE(FontManagerDirectories, font_manager_directories, FONT_MANAGER_TYPE_SELECTIONS) |
| 33 |
|
| 34 |
xmlNodePtr |
| 35 |
font_manager_directories_get_selections (FontManagerSelections *self, xmlDocPtr doc) |
| 36 |
{ |
| 37 |
xmlNodePtr root = xmlDocGetRootElement(doc); |
| 38 |
return (root != NULL) ? root->children : NULL; |
| 39 |
} |
| 40 |
|
| 41 |
static void |
| 42 |
font_manager_directories_write_selections (FontManagerSelections *self, |
| 43 |
FontManagerXmlWriter *writer) |
| 44 |
{ |
| 45 |
g_return_if_fail(FONT_MANAGER_IS_SELECTIONS(self)); |
| 46 |
g_return_if_fail(FONT_MANAGER_IS_XML_WRITER(writer)); |
| 47 |
GList *directories = font_manager_string_set_list(FONT_MANAGER_STRING_SET(self)); |
| 48 |
g_autofree gchar *element = NULL; |
| 49 |
g_object_get(G_OBJECT(self), "target-element", &element, NULL); |
| 50 |
font_manager_xml_writer_add_elements(writer, element, directories); |
| 51 |
g_list_free_full(directories, g_free); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
static void |
| 56 |
font_manager_directories_class_init (FontManagerDirectoriesClass *klass) |
| 57 |
{ |
| 58 |
FontManagerSelectionsClass *parent_class = (FontManagerSelectionsClass *) klass; |
| 59 |
parent_class->get_selections = font_manager_directories_get_selections; |
| 60 |
parent_class->write_selections = font_manager_directories_write_selections; |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
font_manager_directories_init (FontManagerDirectories *self) |
| 66 |
{ |
| 67 |
g_return_if_fail(self != NULL); |
| 68 |
g_autofree gchar *config_dir = font_manager_get_user_fontconfig_directory(); |
| 69 |
g_object_set(G_OBJECT(self), |
| 70 |
"config-dir", config_dir, |
| 71 |
"target-element", "dir", |
| 72 |
"target-file", "09-Directories.conf", |
| 73 |
NULL); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* font_manager_directories_new: |
| 79 |
* |
| 80 |
* Returns: (transfer full): A newly created #FontManagerDirectories. |
| 81 |
* Free the returned object using #g_object_unref(). |
| 82 |
*/ |
| 83 |
FontManagerDirectories * |
| 84 |
font_manager_directories_new (void) |
| 85 |
{ |
| 86 |
|
| 87 |
return g_object_new(FONT_MANAGER_TYPE_DIRECTORIES, NULL); |
| 88 |
} |
| 89 |
|