Add a warning list and append it to the message box.

This commit is contained in:
Dave Davenport 2022-07-27 23:44:56 +02:00
parent 952aaae295
commit fb24fc0999
15 changed files with 91 additions and 4 deletions

View file

@ -75,6 +75,18 @@ void rofi_add_error_message(GString *str);
* Clear the list of stored error messages.
*/
void rofi_clear_error_messages(void);
/**
* @param str A GString with an warning message to display.
*
* Queue an warning.
*/
void rofi_add_warning_message(GString *str);
/**
* Clear the list of stored warning messages.
*/
void rofi_clear_warning_messages(void);
/**
* @param code the code to return
*

View file

@ -84,6 +84,7 @@ const char *cache_dir = NULL;
/** List of error messages.*/
GList *list_of_error_msgs = NULL;
GList *list_of_warning_msgs = NULL;
static void rofi_collectmodes_destroy(void);
void rofi_add_error_message(GString *str) {
@ -99,6 +100,19 @@ void rofi_clear_error_messages(void) {
list_of_error_msgs = NULL;
}
}
void rofi_add_warning_message(GString *str) {
list_of_warning_msgs = g_list_append(list_of_warning_msgs, str);
}
void rofi_clear_warning_messages(void) {
if (list_of_warning_msgs) {
for (GList *iter = g_list_first(list_of_warning_msgs); iter != NULL;
iter = g_list_next(iter)) {
g_string_free((GString *)iter->data, TRUE);
}
g_list_free(list_of_warning_msgs);
list_of_warning_msgs = NULL;
}
}
/** Path to the configuration file */
G_MODULE_EXPORT char *config_path = NULL;
@ -474,6 +488,7 @@ static void cleanup(void) {
g_free(config_path);
rofi_clear_error_messages();
rofi_clear_warning_messages();
if (rofi_theme) {
rofi_theme_free(rofi_theme);
@ -720,6 +735,13 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
show_error_dialog();
return G_SOURCE_REMOVE;
}
if (list_of_warning_msgs != NULL) {
for (GList *iter = g_list_first(list_of_warning_msgs); iter != NULL;
iter = g_list_next(iter)) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
}
}
// Dmenu mode.
if (dmenu_mode == TRUE) {
// force off sidebar mode:
@ -1123,7 +1145,7 @@ extern GList *list_of_error_msgs;
int rofi_theme_rasi_validate(const char *filename) {
rofi_theme_parse_file(filename);
rofi_theme_parse_process_links();
if (list_of_error_msgs == NULL) {
if (list_of_error_msgs == NULL && list_of_warning_msgs == NULL) {
return EXIT_SUCCESS;
}
@ -1132,6 +1154,11 @@ int rofi_theme_rasi_validate(const char *filename) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
}
for (GList *iter = g_list_first(list_of_warning_msgs); iter != NULL;
iter = g_list_next(iter)) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
}
return EXIT_FAILURE;
}

View file

@ -1594,7 +1594,7 @@ static void rofi_theme_parse_process_links_int(ThemeWidget *wid) {
pv->value.link.name, n, pv->name,
pv->value.link.name);
rofi_add_error_message(str);
rofi_add_warning_message(str);
g_free(n);
}
}

View file

@ -427,14 +427,38 @@ static void rofi_view_window_update_size(RofiViewState *state) {
widget_resize(WIDGET(state->main_window), state->width, state->height);
}
extern GList *list_of_warning_msgs;
static void rofi_view_reload_message_bar(RofiViewState *state) {
if (state->mesg_box == NULL) {
return;
}
char *msg = mode_get_message(state->sw);
if (msg || list_of_warning_msgs) {
/** we want to popin warning here. */
GString *emesg = g_string_new(msg);
if (list_of_warning_msgs) {
if (msg) {
textbox_text(state->mesg_tb, msg);
g_string_append_c(emesg, '\n');
}
g_string_append(
emesg, "The following warnings were detected when starting rofi:\n");
GList *iter = g_list_first(list_of_warning_msgs);
int index = 0;
for (; iter != NULL && index < 2; iter = g_list_next(iter)) {
GString *msg = (GString *)(iter->data);
g_string_append(emesg, "\n\n");
g_string_append(emesg, msg->str);
index++;
}
if (g_list_length(iter) > 1) {
g_string_append_printf(emesg, "\nThere are <b>%u</b> more errors.",
g_list_length(iter) - 1);
}
}
textbox_text(state->mesg_tb, emesg->str);
widget_enable(WIDGET(state->mesg_box));
g_string_free(emesg, TRUE);
g_free(msg);
} else {
widget_disable(WIDGET(state->mesg_box));

View file

@ -96,6 +96,7 @@ char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) {
return g_strdup(file);
}
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int textbox_get_estimated_char_height(void);
int textbox_get_estimated_char_height(void) { return 16; }
double textbox_get_estimated_ch(void);

View file

@ -72,6 +72,7 @@ cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
return NULL;
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) {
return FALSE;
@ -84,6 +85,7 @@ void rofi_view_get_current_monitor(int *width, int *height) {
}
double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
return TRUE;

View file

@ -59,6 +59,7 @@ static int test = 0;
}
ThemeWidget *rofi_theme = NULL;
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name,
G_GNUC_UNUSED const int size) {
return 0;
@ -82,6 +83,7 @@ double textbox_get_estimated_ch(void) { return 9.0; }
gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { return 0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);

View file

@ -65,6 +65,7 @@ cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) {
return FALSE;
@ -76,6 +77,7 @@ void rofi_view_get_current_monitor(int *width, int *height) {
}
double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
return TRUE;

View file

@ -79,6 +79,7 @@ uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name,
return 0;
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name,
G_GNUC_UNUSED const int wsize,
G_GNUC_UNUSED const int hsize) {
@ -96,6 +97,7 @@ void rofi_view_get_current_monitor(int *width, int *height) {
}
double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);

View file

@ -56,6 +56,7 @@ uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name,
return 0;
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
return NULL;
@ -72,6 +73,7 @@ void rofi_view_get_current_monitor(int *width, int *height) {
}
double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
return TRUE;

View file

@ -60,6 +60,7 @@ uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name,
return 0;
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
return NULL;
}
@ -71,6 +72,7 @@ gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) {
double textbox_get_estimated_char_height(void) { return 16.0; }
double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int monitor_active(G_GNUC_UNUSED workarea *d) { return 0; }
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);

View file

@ -85,6 +85,7 @@ gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
return FALSE;
}
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; }
double textbox_get_estimated_char_height(void) { return 16; }

View file

@ -76,6 +76,7 @@ gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
}
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
void rofi_view_queue_redraw() {}
void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
G_GNUC_UNUSED int *height) {}

View file

@ -52,6 +52,7 @@ uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name,
return 0;
}
void rofi_clear_error_messages(void) {}
void rofi_clear_warning_messages(void) {}
uint32_t
rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name,
G_GNUC_UNUSED G_GNUC_UNUSED const int wsize,
@ -104,11 +105,18 @@ void display_startup_notification(
gboolean error = FALSE;
GString *error_msg = NULL;
gboolean warning = FALSE;
GString *warning_msg = NULL;
void rofi_add_error_message(GString *msg) {
ck_assert_ptr_null(error_msg);
error_msg = msg;
error = TRUE;
}
void rofi_add_warning_message(GString *msg) {
ck_assert_ptr_null(warning_msg);
warning_msg = msg;
warning = TRUE;
}
static void theme_parser_setup(void) { error = 0; }
static void theme_parser_teardown(void) {

View file

@ -67,6 +67,7 @@ gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
return FALSE;
}
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
void rofi_view_queue_redraw(void) {}
int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,