From 4e38d8f45290dc62c91b2bd1fdc478055358a0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 9 Nov 2019 02:18:53 +0100 Subject: [PATCH 1/4] LayerSelector: Add layer_selector_contains_elements() function --- include/gds-render/layer/layer-selector.h | 12 ++++++++++++ layer/layer-selector.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/gds-render/layer/layer-selector.h b/include/gds-render/layer/layer-selector.h index 6a9963f..a3d7535 100644 --- a/include/gds-render/layer/layer-selector.h +++ b/include/gds-render/layer/layer-selector.h @@ -118,6 +118,18 @@ void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalett */ void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean overwrite); +/** + * @brief Check if the given layer selector contains layer elements. + * + * This function checks whether there are elements present. + * If an invalid object pointer \p layer_selector is passed, + * the function returns FALSE + * + * @param[in] layer_selector Selector to check + * @return True, if there is at least one layer present inside the selector + */ +gboolean layer_selector_contains_elements(LayerSelector *layer_selector); + G_END_DECLS #endif /* __LAYER_SELECTOR_H__ */ diff --git a/layer/layer-selector.c b/layer/layer-selector.c index 177cca2..4111731 100644 --- a/layer/layer-selector.c +++ b/layer/layer-selector.c @@ -883,4 +883,19 @@ void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean ove g_list_free(le_list); } +gboolean layer_selector_contains_elements(LayerSelector *layer_selector) +{ + GList *layer_element_list; + + /* Check objects */ + g_return_val_if_fail(LAYER_IS_SELECTOR(layer_selector), FALSE); + g_return_val_if_fail(GTK_IS_LIST_BOX(layer_selector->list_box), FALSE); + + /* Get a list of the child elements inside the list boy associated with this selector */ + layer_element_list = gtk_container_get_children(GTK_CONTAINER(layer_selector->list_box)); + + /* Return TRUE if there is an element in the list, else return FALSE */ + return (layer_element_list ? TRUE : FALSE); +} + /** @} */ From d8f6981fe698b105873f7a82b77bc5e97b8d51ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 9 Nov 2019 02:21:57 +0100 Subject: [PATCH 2/4] Gui: Only promt overwrite message of auto-naming tool when there are actual elements in the layer selector --- gds-render-gui.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gds-render-gui.c b/gds-render-gui.c index df1ce38..cbdd6ee 100644 --- a/gds-render-gui.c +++ b/gds-render-gui.c @@ -758,6 +758,10 @@ static void auto_naming_clicked(GtkWidget *button, gpointer user_data) gui = RENDERER_GUI(user_data); + /* Don't do anything if the selector is empty. */ + if (!layer_selector_contains_elements(gui->layer_selector)) + return; + /* Ask for overwrite */ dialog = GTK_DIALOG(gtk_message_dialog_new(gui->main_window, GTK_DIALOG_USE_HEADER_BAR, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Overwrite existing layer names?")); From 40a7e5a650ba41c77574137073e62c51d5a5f0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 12 Nov 2019 18:14:07 +0100 Subject: [PATCH 3/4] Compilation: Add -Wextra to compile arguments + Fix minor resulting warnings --- CMakeLists.txt | 2 +- layer/color-palette.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dca072..3bbfb23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ pkg_search_module(GLIB REQUIRED glib-2.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(CAIRO REQUIRED cairo) -add_compile_options(-Wall -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) +add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) add_subdirectory(resources) add_subdirectory(doxygen) diff --git a/layer/color-palette.c b/layer/color-palette.c index f965f96..ae51dae 100644 --- a/layer/color-palette.c +++ b/layer/color-palette.c @@ -106,13 +106,13 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc char_array = (const char *)g_bytes_get_data(data, &byte_count); if (!char_array || !byte_count) - goto ret_unref; + goto ret_unref_data; /* Get maximum lenght of color palette, assuming all entries are valid */ lines = count_non_empty_lines_in_array(char_array, byte_count); if (lines <= 0) - goto ret_unref; + goto ret_unref_data; palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines); @@ -128,18 +128,17 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc color_idx = 0; /* interate over lines and match */ - for (idx = 0 ; idx < byte_count; idx++) { + for (idx = 0 ; (unsigned int)idx < byte_count; idx++) { /* Fillup line. */ line[line_idx] = char_array[idx]; - /* If end of line/string is reached, process */ if (line[line_idx] == '\n' || line[line_idx] == '\0') { line[line_idx] = '\0'; /* Match the line */ g_regex_match(regex, line, 0, &mi); - if (g_match_info_matches(mi) && color_idx < lines) { + if (g_match_info_matches(mi) && color_idx < (unsigned int)lines) { match = g_match_info_fetch_named(mi, "red"); palette->color_array[color_idx].red = (double)g_ascii_strtoll(match, NULL, 16) / 255.0; @@ -169,10 +168,10 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc continue; } - /* increment line index. If end is reached write all bytes to the line end - * line is longer than required for parsing. This ensures, that everything works as expected + /* increment line index. If end is reached write all bytes to the line end. + * Line is longer than required for parsing. This ensures, that everything works as expected */ - line_idx += (line_idx < sizeof(line)-1 ? 1 : 0); + line_idx += ((unsigned int)line_idx < sizeof(line)-1 ? 1 : 0); } /* Data read; Shrink array in case of invalid lines */ @@ -180,7 +179,7 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc palette->color_array_length = color_idx; g_regex_unref(regex); -ret_unref: +ret_unref_data: g_bytes_unref(data); return 0; From 11f2068b76992918d8a462266cd2702d31f0b6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 12 Nov 2019 19:50:34 +0100 Subject: [PATCH 4/4] Improve Cmake target for translations. Still not perfect. --- translations/CMakeLists.txt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index a181f7b..c553dee 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -1,4 +1,16 @@ -add_custom_target(translations ALL - COMMAND ./generate-mo.sh "${PROJECT_BINARY_DIR}/translations/output" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Generating translation locales") +add_custom_target(translations + DEPENDS + "${PROJECT_BINARY_DIR}/translations/output/" + ) + +add_custom_command(DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/pot/po/*" + OUTPUT + "${PROJECT_BINARY_DIR}/translations/output/" + COMMAND + COMMAND ./generate-mo.sh "${PROJECT_BINARY_DIR}/translations/output" + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT + "Generating translation locales" + )