diff --git a/fedora/font-manager.spec b/fedora/font-manager.spec index bf83a2f2..376eb937 100644 --- a/fedora/font-manager.spec +++ b/fedora/font-manager.spec @@ -14,7 +14,7 @@ Name: font-manager Version: %{MajorVersion}.%{MinorVersion}.%{PatchVersion}.%{build_timestamp} -Release: 1 +Release: 2 Summary: A simple font management application for Gtk+ Desktop Environments License: GPLv3+ Url: http://fontmanager.github.io/ @@ -188,6 +188,6 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/*.metain %endif %changelog -* Tue Aug 6 2024 JerryCasiano 0.9.1-1 +* Thu Jan 2 2025 JerryCasiano 0.9.1-2 - Refer to https://github.com/FontManager/font-manager/commits/master for changes. diff --git a/lib/common/font-manager-string-set.c b/lib/common/font-manager-string-set.c index f35f07a8..6548c54b 100644 --- a/lib/common/font-manager-string-set.c +++ b/lib/common/font-manager-string-set.c @@ -1,6 +1,6 @@ /* font-manager-string-set.c * - * Copyright (C) 2009-2024 Jerry Casiano + * Copyright (C) 2009-2025 Jerry Casiano * * 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 @@ -173,7 +173,8 @@ font_manager_string_set_add_all (FontManagerStringSet *self, FontManagerStringSe gboolean font_manager_string_set_contains (FontManagerStringSet *self, const gchar *str) { - g_return_val_if_fail(self != NULL && str != NULL, FALSE); + if (!self || !str || font_manager_string_set_size(self) < 1) + return FALSE; FontManagerStringSetPrivate *priv = font_manager_string_set_get_instance_private(self); return g_ptr_array_find_with_equal_func(priv->strings, str, (GEqualFunc) g_str_equal, NULL); } diff --git a/lib/fontconfig/font-manager-selections.c b/lib/fontconfig/font-manager-selections.c index 8c15061e..66baa81a 100644 --- a/lib/fontconfig/font-manager-selections.c +++ b/lib/fontconfig/font-manager-selections.c @@ -1,6 +1,6 @@ /* font-manager-selections.c * - * Copyright (C) 2009-2024 Jerry Casiano + * Copyright (C) 2009-2025 Jerry Casiano * * 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 @@ -135,10 +135,10 @@ font_manager_selections_parse_selections (FontManagerSelections *self, if (iter->type != XML_ELEMENT_NODE) continue; xmlChar *content = xmlNodeGetContent(iter); - if (content == NULL) + if (!content) continue; content = (xmlChar *) g_strstrip((gchar *) content); - if (g_strcmp0((const char *) content, "") != 0) + if (content && g_strcmp0((const char *) content, "") != 0) font_manager_string_set_add(FONT_MANAGER_STRING_SET(self), (const gchar *) content); xmlFree(content); } diff --git a/lib/fontconfig/font-manager-source.c b/lib/fontconfig/font-manager-source.c index a5ad5e3e..3a620e98 100644 --- a/lib/fontconfig/font-manager-source.c +++ b/lib/fontconfig/font-manager-source.c @@ -1,6 +1,6 @@ /* font-manager-source.c * - * Copyright (C) 2009-2023 Jerry Casiano + * Copyright (C) 2009-2025 Jerry Casiano * * 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 @@ -317,12 +317,12 @@ font_manager_source_update (FontManagerSource *self) g_return_if_fail(self != NULL); FontManagerSourcePrivate *priv = font_manager_source_get_instance_private(self); g_free(priv->name); + g_free(priv->path); priv->name = g_strdup(_("Source Unavailable")); + priv->path = priv->file ? g_file_get_path(priv->file) : g_strdup(_("Source Unavailable")); priv->active = FALSE; if (priv->file == NULL || !g_file_query_exists(priv->file, NULL)) return; - g_free(priv->path); - priv->path = g_file_get_path(priv->file); g_autoptr(GFileInfo) fileinfo = g_file_query_info(priv->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, diff --git a/src/font-manager/Application.vala b/src/font-manager/Application.vala index cdaaf077..2747359b 100644 --- a/src/font-manager/Application.vala +++ b/src/font-manager/Application.vala @@ -42,6 +42,8 @@ namespace FontManager { public Reject? disabled_families { get; private set; default = new Reject(); } [DBus (visible = false)] public StringSet? temp_files { get; private set; default = new StringSet(); } + [DBus (visible = false)] + public FontCache? cache { get; private set; default = null; } const OptionEntry[] options = { { "about", 'a', 0, OptionArg.NONE, null, "About the application", null }, @@ -278,23 +280,40 @@ namespace FontManager { requires (main_window != null) { if (update_in_progress) return; - var ctx = main_window.get_pango_context(); - available_fonts = get_sorted_font_list(ctx); - main_window.present(); + // var ctx = main_window.get_pango_context(); + // available_fonts = get_sorted_font_list(ctx); + // Idle.add_full(GLib.Priority.HIGH_IDLE, () => { + // main_window.present(); + // return GLib.Source.REMOVE; + // }); + // message("updating cache"); + // cache.update(); + message("updating database"); db.update(available_fonts); + message("done"); return; } protected override void activate () { if (main_window == null) { + message("Creating main window"); main_window = new MainWindow(settings); + message("complete"); add_window(main_window); + message("adding idle call to present"); + Idle.add_full(GLib.Priority.HIGH_IDLE, () => { + main_window.present(); + return GLib.Source.REMOVE; + }); + message("instantiating cache"); + cache = new FontCache(main_window); + message("complete"); BindingFlags flags = BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE; + cache.bind_property("available-fonts", this, "available-fonts", flags); bind_property("available-fonts", main_window, "available-fonts", flags); bind_property("disabled-families", main_window, "disabled-families", flags); // Why is this needed? shutdown.connect(() => { quit(); }); - main_window.present(); } db.update_complete.connect(() => { update_item_preview_text(available_fonts); diff --git a/src/font-manager/FontList.vala b/src/font-manager/FontList.vala index 24f9a611..bed8f101 100644 --- a/src/font-manager/FontList.vala +++ b/src/font-manager/FontList.vala @@ -40,8 +40,6 @@ namespace FontManager { } protected override void reset () { - if (binding != null) - binding.unbind(); if (binding is Binding) binding.unref(); binding = null; @@ -667,7 +665,7 @@ namespace FontManager { var tree_expander = (Gtk.TreeExpander) list_item.get_child(); var row = (FontListRow) tree_expander.get_child(); Object? _item = list_row.get_item(); - if (_item is Family) + if (_item is Family && disabled_families != null) row.item_state.active = !(((Family) _item).family in disabled_families); row.item_state_changed.connect(on_item_state_changed); return; diff --git a/src/font-manager/Utils.vala b/src/font-manager/Utils.vala index d8b5d989..fe5534db 100644 --- a/src/font-manager/Utils.vala +++ b/src/font-manager/Utils.vala @@ -242,6 +242,53 @@ namespace FontManager { return sorted_fonts; } + public class FontCache : Object { + + public Json.Array? available_fonts { get; protected set; default = null; } + public Gtk.Window? parent { get; set; default = null; } + + public FontCache (Gtk.Window? parent) { + Object(parent: parent); + // var ctx = parent.get_pango_context(); + // available_fonts = get_sorted_font_list(ctx); + load_from_cache(); + // update(); + } + + public void update () { + var ctx = parent.get_pango_context(); + available_fonts = get_sorted_font_list(ctx); + save(); + return; + } + + public static string get_cache_file () { + string dirpath = get_package_cache_directory(); + string filepath = Path.build_filename(dirpath, "fonts.cache"); + DirUtils.create_with_parents(dirpath ,0755); + return filepath; + } + + public void load_from_cache () { + Json.Node? root = load_json_file(get_cache_file()); + if (root == null) + return; + Json.NodeType node_type = root.get_node_type(); + if (node_type == Json.NodeType.ARRAY) + available_fonts = root.get_array(); + else + assert_not_reached(); + return; + } + + public bool save () { + var node = new Json.Node(Json.NodeType.ARRAY); + node.set_array(available_fonts); + return write_json_file(node, get_cache_file(), false); + } + + } + public bool remove_directory_tree_if_empty (File dir) { try { var enumerator = dir.enumerate_children(FileAttribute.STANDARD_NAME, diff --git a/src/font-manager/preferences/UserSources.vala b/src/font-manager/preferences/UserSources.vala index a2884727..12c71477 100644 --- a/src/font-manager/preferences/UserSources.vala +++ b/src/font-manager/preferences/UserSources.vala @@ -1,6 +1,6 @@ /* UserSources.vala * - * Copyright (C) 2009-2024 Jerry Casiano + * Copyright (C) 2009-2025 Jerry Casiano * * 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 @@ -48,7 +48,9 @@ namespace FontManager { sources.load(); var active = new Directories(); active.load(); - foreach (var path in sources) { + foreach (string path in sources) { + if (path == null) + continue; var item = new Source(File.new_for_path(path)); item.active = (item.path in active); add_item(item);