diff --git a/include/rofi.h b/include/rofi.h index 7558a45b..be189e0b 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -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 * diff --git a/source/rofi.c b/source/rofi.c index 176ecb93..01cb235d 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -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; } diff --git a/source/theme.c b/source/theme.c index 7270d22d..0319b18d 100644 --- a/source/theme.c +++ b/source/theme.c @@ -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); } } diff --git a/source/view.c b/source/view.c index 7416316f..3ce4d582 100644 --- a/source/view.c +++ b/source/view.c @@ -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) { - textbox_text(state->mesg_tb, msg); + 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) { + 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 %u 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)); diff --git a/test/box-test.c b/test/box-test.c index e2a300e5..dafc526f 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -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); diff --git a/test/helper-config-cmdline-parser.c b/test/helper-config-cmdline-parser.c index 24f0806e..4cbfe78f 100644 --- a/test/helper-config-cmdline-parser.c +++ b/test/helper-config-cmdline-parser.c @@ -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; diff --git a/test/helper-expand.c b/test/helper-expand.c index 965512c8..60c0079e 100644 --- a/test/helper-expand.c +++ b/test/helper-expand.c @@ -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); diff --git a/test/helper-pidfile.c b/test/helper-pidfile.c index 22b66d23..158e078a 100644 --- a/test/helper-pidfile.c +++ b/test/helper-pidfile.c @@ -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; diff --git a/test/helper-test.c b/test/helper-test.c index d8e53fef..4e81b937 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -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); diff --git a/test/helper-tokenize.c b/test/helper-tokenize.c index 4248c6cf..250b6a22 100644 --- a/test/helper-tokenize.c +++ b/test/helper-tokenize.c @@ -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; diff --git a/test/mode-test.c b/test/mode-test.c index 3a26dc3a..7cc04260 100644 --- a/test/mode-test.c +++ b/test/mode-test.c @@ -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); diff --git a/test/scrollbar-test.c b/test/scrollbar-test.c index a0310797..d79154a8 100644 --- a/test/scrollbar-test.c +++ b/test/scrollbar-test.c @@ -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; } diff --git a/test/textbox-test.c b/test/textbox-test.c index eb6ea605..737db4f0 100644 --- a/test/textbox-test.c +++ b/test/textbox-test.c @@ -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) {} diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 9da24f2a..82b77844 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -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) { diff --git a/test/widget-test.c b/test/widget-test.c index ed2bbbfb..69f32132 100644 --- a/test/widget-test.c +++ b/test/widget-test.c @@ -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,