Merge branch 'dev' into japanese-translations

This commit is contained in:
Mario Hüttel 2019-11-12 19:58:03 +01:00
commit c497a41ca6
6 changed files with 56 additions and 14 deletions

View File

@ -30,7 +30,7 @@ pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(CAIRO REQUIRED cairo) 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)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug") IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("${Yellow}Debug mode for translations used!${ColorReset}") message("${Yellow}Debug mode for translations used!${ColorReset}")

View File

@ -759,6 +759,10 @@ static void auto_naming_clicked(GtkWidget *button, gpointer user_data)
gui = RENDERER_GUI(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 */ /* Ask for overwrite */
dialog = GTK_DIALOG(gtk_message_dialog_new(gui->main_window, GTK_DIALOG_USE_HEADER_BAR, GTK_MESSAGE_QUESTION, 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?")); GTK_BUTTONS_YES_NO, "Overwrite existing layer names?"));

View File

@ -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); 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 G_END_DECLS
#endif /* __LAYER_SELECTOR_H__ */ #endif /* __LAYER_SELECTOR_H__ */

View File

@ -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); char_array = (const char *)g_bytes_get_data(data, &byte_count);
if (!char_array || !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 */ /* Get maximum lenght of color palette, assuming all entries are valid */
lines = count_non_empty_lines_in_array(char_array, byte_count); lines = count_non_empty_lines_in_array(char_array, byte_count);
if (lines <= 0) if (lines <= 0)
goto ret_unref; goto ret_unref_data;
palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines); 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; color_idx = 0;
/* interate over lines and match */ /* interate over lines and match */
for (idx = 0 ; idx < byte_count; idx++) { for (idx = 0 ; (unsigned int)idx < byte_count; idx++) {
/* Fillup line. */ /* Fillup line. */
line[line_idx] = char_array[idx]; line[line_idx] = char_array[idx];
/* If end of line/string is reached, process */ /* If end of line/string is reached, process */
if (line[line_idx] == '\n' || line[line_idx] == '\0') { if (line[line_idx] == '\n' || line[line_idx] == '\0') {
line[line_idx] = '\0'; line[line_idx] = '\0';
/* Match the line */ /* Match the line */
g_regex_match(regex, line, 0, &mi); 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"); match = g_match_info_fetch_named(mi, "red");
palette->color_array[color_idx].red = palette->color_array[color_idx].red =
(double)g_ascii_strtoll(match, NULL, 16) / 255.0; (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; continue;
} }
/* increment line index. If end is reached write all bytes to the line end /* 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 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 */ /* 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; palette->color_array_length = color_idx;
g_regex_unref(regex); g_regex_unref(regex);
ret_unref: ret_unref_data:
g_bytes_unref(data); g_bytes_unref(data);
return 0; return 0;

View File

@ -883,4 +883,19 @@ void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean ove
g_list_free(le_list); 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);
}
/** @} */ /** @} */

View File

@ -1,4 +1,16 @@
add_custom_target(translations ALL add_custom_target(translations
COMMAND ./generate-mo.sh "${PROJECT_BINARY_DIR}/translations/output" DEPENDS
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_BINARY_DIR}/translations/output/"
COMMENT "Generating translation locales") )
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"
)