Skip to content

Commit

Permalink
- Address segfault caused by missing sources - Closes #405
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryCasiano committed Jan 2, 2025
1 parent 626b4fe commit fc1b0c0
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 19 deletions.
4 changes: 2 additions & 2 deletions fedora/font-manager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -188,6 +188,6 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/*.metain
%endif

%changelog
* Tue Aug 6 2024 JerryCasiano <[email protected]> 0.9.1-1
* Thu Jan 2 2025 JerryCasiano <[email protected]> 0.9.1-2
- Refer to https://github.com/FontManager/font-manager/commits/master for changes.

5 changes: 3 additions & 2 deletions lib/common/font-manager-string-set.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/fontconfig/font-manager-selections.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/fontconfig/font-manager-source.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 23 additions & 4 deletions src/font-manager/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/font-manager/FontList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace FontManager {
}

protected override void reset () {
if (binding != null)
binding.unbind();
if (binding is Binding)
binding.unref();
binding = null;
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions src/font-manager/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/font-manager/preferences/UserSources.vala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fc1b0c0

Please sign in to comment.