fix: surface zoitechat.conf/colors.conf save failures; add missing theme prefs fwd decl

This commit is contained in:
2026-03-16 21:55:36 -06:00
parent e90f0188c1
commit 96af9bdde6
15 changed files with 62 additions and 32 deletions

View File

@@ -1104,7 +1104,8 @@ zoitechat_exit (void)
plugin_kill_all (); plugin_kill_all ();
fe_cleanup (); fe_cleanup ();
save_config (); if (!save_config ())
g_printerr ("Could not save zoitechat.conf.\n");
if (prefs.save_pevents) if (prefs.save_pevents)
{ {
pevent_save (NULL); pevent_save (NULL);

View File

@@ -650,7 +650,8 @@ chanlist_minusers (GtkSpinButton *wid, server *serv)
{ {
serv->gui->chanlist_minusers = gtk_spin_button_get_value_as_int (wid); serv->gui->chanlist_minusers = gtk_spin_button_get_value_as_int (wid);
prefs.hex_gui_chanlist_minusers = serv->gui->chanlist_minusers; prefs.hex_gui_chanlist_minusers = serv->gui->chanlist_minusers;
save_config(); if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
if (serv->gui->chanlist_minusers < serv->gui->chanlist_minusers_downloaded) if (serv->gui->chanlist_minusers < serv->gui->chanlist_minusers_downloaded)
{ {
@@ -672,7 +673,8 @@ chanlist_maxusers (GtkSpinButton *wid, server *serv)
{ {
serv->gui->chanlist_maxusers = gtk_spin_button_get_value_as_int (wid); serv->gui->chanlist_maxusers = gtk_spin_button_get_value_as_int (wid);
prefs.hex_gui_chanlist_maxusers = serv->gui->chanlist_maxusers; prefs.hex_gui_chanlist_maxusers = serv->gui->chanlist_maxusers;
save_config(); if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
} }
static void static void
@@ -893,7 +895,8 @@ chanlist_opengui (server *serv, int do_refresh)
if (prefs.hex_gui_chanlist_minusers < 1 || prefs.hex_gui_chanlist_minusers > 999999) if (prefs.hex_gui_chanlist_minusers < 1 || prefs.hex_gui_chanlist_minusers > 999999)
{ {
prefs.hex_gui_chanlist_minusers = 5; prefs.hex_gui_chanlist_minusers = 5;
save_config(); if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
} }
serv->gui->chanlist_minusers = prefs.hex_gui_chanlist_minusers; serv->gui->chanlist_minusers = prefs.hex_gui_chanlist_minusers;
@@ -904,7 +907,8 @@ chanlist_opengui (server *serv, int do_refresh)
if (prefs.hex_gui_chanlist_maxusers < 1 || prefs.hex_gui_chanlist_maxusers > 999999) if (prefs.hex_gui_chanlist_maxusers < 1 || prefs.hex_gui_chanlist_maxusers > 999999)
{ {
prefs.hex_gui_chanlist_maxusers = 9999; prefs.hex_gui_chanlist_maxusers = 9999;
save_config(); if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
} }
serv->gui->chanlist_maxusers = prefs.hex_gui_chanlist_maxusers; serv->gui->chanlist_maxusers = prefs.hex_gui_chanlist_maxusers;

View File

@@ -3683,7 +3683,8 @@ static void
search_set_option (GtkToggleButton *but, guint *pref) search_set_option (GtkToggleButton *but, guint *pref)
{ {
*pref = gtk_toggle_button_get_active(but); *pref = gtk_toggle_button_get_active(but);
save_config(); if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
} }
void void

View File

@@ -1002,7 +1002,8 @@ servlist_savegui (void)
sp[0] = 0; /* spaces will break the login */ sp[0] = 0; /* spaces will break the login */
/* strcpy (prefs.hex_irc_real_name, gtk_entry_get_text (GTK_ENTRY (entry_greal))); */ /* strcpy (prefs.hex_irc_real_name, gtk_entry_get_text (GTK_ENTRY (entry_greal))); */
servlist_save (); servlist_save ();
save_config (); /* For nicks stored in zoitechat.conf */ if (!save_config ())
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
return 0; return 0;
} }

View File

@@ -2193,8 +2193,10 @@ setup_ok_cb (GtkWidget *but, GtkWidget *win)
{ {
gtk_widget_destroy (win); gtk_widget_destroy (win);
setup_apply (&setup_prefs); setup_apply (&setup_prefs);
save_config (); if (!save_config ())
theme_manager_save_preferences (); fe_message (_("Could not save zoitechat.conf."), FE_MSG_ERROR);
if (!theme_manager_save_preferences ())
fe_message (_("Could not save colors.conf."), FE_MSG_ERROR);
} }
static GtkWidget * static GtkWidget *

View File

@@ -57,9 +57,10 @@ theme_runtime_load (void)
{ {
} }
void gboolean
theme_runtime_save (void) theme_runtime_save (void)
{ {
return TRUE;
} }
void void

View File

@@ -119,8 +119,9 @@ void theme_runtime_load (void)
{ {
} }
void theme_runtime_save (void) gboolean theme_runtime_save (void)
{ {
return TRUE;
} }
gboolean theme_runtime_is_dark_active (void) gboolean theme_runtime_is_dark_active (void)

View File

@@ -112,8 +112,9 @@ void theme_runtime_load (void)
{ {
} }
void theme_runtime_save (void) gboolean theme_runtime_save (void)
{ {
return TRUE;
} }
gboolean theme_runtime_is_dark_active (void) gboolean theme_runtime_is_dark_active (void)

View File

@@ -122,8 +122,9 @@ void theme_runtime_load (void)
{ {
} }
void theme_runtime_save (void) gboolean theme_runtime_save (void)
{ {
return TRUE;
} }
gboolean theme_runtime_is_dark_active (void) gboolean theme_runtime_is_dark_active (void)

View File

@@ -66,9 +66,10 @@ theme_manager_reset_mode_colors (unsigned int mode, gboolean *palette_changed)
*palette_changed = FALSE; *palette_changed = FALSE;
} }
void gboolean
theme_manager_save_preferences (void) theme_manager_save_preferences (void)
{ {
return TRUE;
} }
ThemePaletteBehavior ThemePaletteBehavior

View File

@@ -284,10 +284,10 @@ theme_manager_commit_preferences (unsigned int old_mode, gboolean *color_change)
fe_set_auto_dark_mode_state (theme_policy_is_dark_mode_active (ZOITECHAT_DARK_MODE_AUTO)); fe_set_auto_dark_mode_state (theme_policy_is_dark_mode_active (ZOITECHAT_DARK_MODE_AUTO));
} }
void gboolean
theme_manager_save_preferences (void) theme_manager_save_preferences (void)
{ {
theme_runtime_save (); return theme_runtime_save ();
} }
gboolean gboolean

View File

@@ -43,7 +43,7 @@ void theme_manager_set_mode (unsigned int mode, gboolean *palette_changed);
void theme_manager_set_token_color (unsigned int mode, ThemeSemanticToken token, const GdkRGBA *color, gboolean *palette_changed); void theme_manager_set_token_color (unsigned int mode, ThemeSemanticToken token, const GdkRGBA *color, gboolean *palette_changed);
void theme_manager_reset_mode_colors (unsigned int mode, gboolean *palette_changed); void theme_manager_reset_mode_colors (unsigned int mode, gboolean *palette_changed);
void theme_manager_commit_preferences (unsigned int old_mode, gboolean *color_change); void theme_manager_commit_preferences (unsigned int old_mode, gboolean *color_change);
void theme_manager_save_preferences (void); gboolean theme_manager_save_preferences (void);
gboolean theme_changed_event_has_reason (const ThemeChangedEvent *event, ThemeChangedReason reason); gboolean theme_changed_event_has_reason (const ThemeChangedEvent *event, ThemeChangedReason reason);
void theme_manager_apply_and_dispatch (unsigned int mode, ThemeChangedReason reasons, gboolean *palette_changed); void theme_manager_apply_and_dispatch (unsigned int mode, ThemeChangedReason reasons, gboolean *palette_changed);
void theme_manager_dispatch_changed (ThemeChangedReason reasons); void theme_manager_dispatch_changed (ThemeChangedReason reasons);

View File

@@ -70,6 +70,9 @@ typedef struct
#define COLOR_MANAGER_RESPONSE_RESET 1 #define COLOR_MANAGER_RESPONSE_RESET 1
static void
theme_preferences_show_import_error (GtkWidget *button, const char *message);
static void static void
theme_preferences_manager_row_free (gpointer data) theme_preferences_manager_row_free (gpointer data)
{ {
@@ -735,8 +738,9 @@ theme_preferences_manage_colors_cb (GtkWidget *button, gpointer user_data)
gtk_dialog_run (GTK_DIALOG (dialog)); gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
if (color_change_flag && *color_change_flag != old_changed) if (color_change_flag && *color_change_flag != old_changed &&
theme_manager_save_preferences (); !theme_manager_save_preferences ())
theme_preferences_show_import_error (button, _("Could not save colors.conf."));
} }
static void static void
@@ -912,8 +916,9 @@ theme_preferences_import_colors_conf_cb (GtkWidget *button, gpointer user_data)
if (!any_imported) if (!any_imported)
theme_preferences_show_import_error (button, _("No importable colors were found in that colors.conf file.")); theme_preferences_show_import_error (button, _("No importable colors were found in that colors.conf file."));
else if (color_change_flag && *color_change_flag != old_changed) else if (color_change_flag && *color_change_flag != old_changed &&
theme_manager_save_preferences (); !theme_manager_save_preferences ())
theme_preferences_show_import_error (button, _("Could not save colors.conf."));
g_free (cfg); g_free (cfg);
g_free (path); g_free (path);

View File

@@ -276,7 +276,7 @@ theme_runtime_load_migrated_legacy_color (char *cfg,
return palette_read_legacy_color (cfg, mode->legacy_prefix, def->legacy_index, out_color); return palette_read_legacy_color (cfg, mode->legacy_prefix, def->legacy_index, out_color);
} }
static void static gboolean
palette_write_token_color (int fh, const char *mode_name, const ThemePaletteTokenDef *def, const GdkRGBA *color) palette_write_token_color (int fh, const char *mode_name, const ThemePaletteTokenDef *def, const GdkRGBA *color)
{ {
char prefname[256]; char prefname[256];
@@ -284,13 +284,13 @@ palette_write_token_color (int fh, const char *mode_name, const ThemePaletteToke
guint16 green; guint16 green;
guint16 blue; guint16 blue;
g_return_if_fail (mode_name != NULL); g_return_val_if_fail (mode_name != NULL, FALSE);
g_return_if_fail (def != NULL); g_return_val_if_fail (def != NULL, FALSE);
g_return_if_fail (color != NULL); g_return_val_if_fail (color != NULL, FALSE);
g_snprintf (prefname, sizeof prefname, "theme.mode.%s.token.%s", mode_name, def->name); g_snprintf (prefname, sizeof prefname, "theme.mode.%s.token.%s", mode_name, def->name);
theme_palette_color_get_rgb16 (color, &red, &green, &blue); theme_palette_color_get_rgb16 (color, &red, &green, &blue);
cfg_put_color (fh, red, green, blue, prefname); return cfg_put_color (fh, red, green, blue, prefname);
} }
@@ -449,7 +449,7 @@ theme_runtime_load (void)
user_colors_valid = TRUE; user_colors_valid = TRUE;
} }
void gboolean
theme_runtime_save (void) theme_runtime_save (void)
{ {
size_t i; size_t i;
@@ -487,9 +487,13 @@ theme_runtime_save (void)
fh = zoitechat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); fh = zoitechat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
if (fh == -1) if (fh == -1)
return; return FALSE;
cfg_put_int (fh, THEME_PALETTE_MIGRATION_MARKER_VALUE, (char *) THEME_PALETTE_MIGRATION_MARKER_KEY); if (!cfg_put_int (fh, THEME_PALETTE_MIGRATION_MARKER_VALUE, (char *) THEME_PALETTE_MIGRATION_MARKER_KEY))
{
close (fh);
return FALSE;
}
for (i = 0; i < mode_count; i++) for (i = 0; i < mode_count; i++)
{ {
@@ -507,11 +511,18 @@ theme_runtime_save (void)
if (!custom_tokens[def->token]) if (!custom_tokens[def->token])
continue; continue;
g_assert (theme_palette_get_color (modes[i].palette, def->token, &color)); g_assert (theme_palette_get_color (modes[i].palette, def->token, &color));
palette_write_token_color (fh, modes[i].mode_name, def, &color); if (!palette_write_token_color (fh, modes[i].mode_name, def, &color))
{
close (fh);
return FALSE;
}
} }
} }
close (fh); if (close (fh) == -1)
return FALSE;
return TRUE;
} }
static gboolean static gboolean

View File

@@ -18,7 +18,7 @@ typedef struct
} ThemeGtkPaletteMap; } ThemeGtkPaletteMap;
void theme_runtime_load (void); void theme_runtime_load (void);
void theme_runtime_save (void); gboolean theme_runtime_save (void);
gboolean theme_runtime_apply_mode (unsigned int mode, gboolean *palette_changed); gboolean theme_runtime_apply_mode (unsigned int mode, gboolean *palette_changed);
gboolean theme_runtime_apply_dark_mode (gboolean enable); gboolean theme_runtime_apply_dark_mode (gboolean enable);
void theme_runtime_user_set_color (ThemeSemanticToken token, const GdkRGBA *col); void theme_runtime_user_set_color (ThemeSemanticToken token, const GdkRGBA *col);