diff --git a/ChangeLog b/ChangeLog index d13e458..47bcc9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,13 @@ Change Log ========== +## 0.2.1 (2021-05-03) + +Changes: + +* Code review in the build system and the extension source code + + ## 0.2.0 (2021-04-28) Changes: diff --git a/Makefile.am b/Makefile.am index 29d1fec..fe6488e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,7 @@ EXTRA_DIST = \ README.md \ bootstrap \ package.json \ + .editorconfig \ $(INTLTOOL_FILES) DISTCLEANFILES = \ @@ -34,6 +35,11 @@ DISTCLEANFILES = \ po/.intltool-merge-cache +# Shell expansion is supported here +_distclean_dirs_ = \ + 'po/backups' + + if NLS_ENABLED SUBDIRS += \ @@ -52,5 +58,19 @@ uninstall-local: -rm -r '$(DESTDIR)$(docdir)' +distclean-local: + -rm -rf $(_distclean_dirs_); + + +# Update translations +.PHONY: i18n-update +i18n-update: + (cd 'po' && intltool-update -p --gettext-package='$(PACKAGE_TARNAME)' \ + && mkdir -p 'backups' && grep -o '^\s*\w\S\+' 'LINGUAS' | while read \ + coin; do mv "$${coin}.po" "$${coin}.po.bak" && msgmerge \ + "$${coin}.po.bak" '$(PACKAGE_TARNAME).pot' > "$${coin}.po" && mv \ + "$${coin}.po.bak" 'backups'; done; rm '$(PACKAGE_TARNAME).pot') + + # EOF diff --git a/configure.ac b/configure.ac index e16af3a..709e748 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,7 @@ dnl *************************************************************************** AC_PREREQ([2.69]) AC_INIT([Nautilus Hide], - [0.2.0], + [0.2.1], [madmurphy333@gmail.com], [nautilus-hide], [https://gitlab.gnome.org/madmurphy/nautilus-hide]) @@ -64,7 +64,7 @@ dnl *************************************************************************** AC_SUBST([NAUTILUS_EXTENSION_DIR], - [$($PKG_CONFIG --variable=extensiondir libnautilus-extension)]) + ["$($PKG_CONFIG --variable=extensiondir libnautilus-extension)"]) LT_INIT([disable-static]) diff --git a/package.json b/package.json index ff5efff..d282d9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nautilus-hide", - "version": "0.2.0", + "version": "0.2.1", "description": "A simple Nautilus extension that adds \"Hide\" and \"Unhide\" to Nautilus right-click menu", "homepage": "https://gitlab.gnome.org/madmurphy/nautilus-hide", "author": "madmurphy333@gmail.com", diff --git a/po/it.po b/po/it.po index b8d7a5e..82f3ab2 100644 --- a/po/it.po +++ b/po/it.po @@ -5,10 +5,10 @@ # msgid "" msgstr "" -"Project-Id-Version: 0.1.1\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-28 10:03+0200\n" -"PO-Revision-Date: 2021-04-28 10:03+0200\n" +"Project-Id-Version: 0.2.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-05-02 23:17+0200\n" +"PO-Revision-Date: 2021-05-02 23:17+0200\n" "Last-Translator: FULL NAME \n" "Language-Team: Italian \n" "Language: it\n" @@ -17,37 +17,41 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: ../src/nautilus-hide.c:99 +#: ../src/nautilus-hide.c:105 msgid "Could not close the database of hidden files" msgstr "Impossibile chiudere il database dei file nascosti" -#: ../src/nautilus-hide.c:119 ../src/nautilus-hide.c:136 -#: ../src/nautilus-hide.c:150 ../src/nautilus-hide.c:243 -#: ../src/nautilus-hide.c:296 ../src/nautilus-hide.c:348 +#: ../src/nautilus-hide.c:125 ../src/nautilus-hide.c:142 +#: ../src/nautilus-hide.c:156 ../src/nautilus-hide.c:249 +#: ../src/nautilus-hide.c:302 msgid "Error allocating memory" msgstr "Errore nell'allocare memoria" -#: ../src/nautilus-hide.c:201 +#: ../src/nautilus-hide.c:207 msgid "Error attempting to access the database of hidden files" msgstr "Impossibile accedere al database dei file nascosti" -#: ../src/nautilus-hide.c:215 +#: ../src/nautilus-hide.c:221 msgid "Could not calculate the size of the database of hidden files" msgstr "Impossibile calcolare le dimensioni del database dei file nascosti" -#: ../src/nautilus-hide.c:228 +#: ../src/nautilus-hide.c:234 msgid "Database of hidden files is too big" msgstr "Il database dei file nascosti è troppo grande" -#: ../src/nautilus-hide.c:257 +#: ../src/nautilus-hide.c:263 msgid "I/O error while accessing database of hidden files" msgstr "Errore I/O nell'accedere al database dei file nascosti" -#: ../src/nautilus-hide.c:430 -msgid "No files were selected to be hidden" +#: ../src/nautilus-hide.c:356 +msgid "Could not get file path" +msgstr "Impossibile ottenere la posizione del file" + +#: ../src/nautilus-hide.c:438 +msgid "No files have been selected to be hidden" msgstr "Non ci sono file selezionati da nascondere" -#: ../src/nautilus-hide.c:444 +#: ../src/nautilus-hide.c:453 msgid "" "Could not hide the selected files, error attempting to group them according " "to their parent directories" @@ -55,18 +59,18 @@ msgstr "" "Impossibile nascondere i file selezionati, errore nel tentativo di " "raggrupparli in base alla loro directory di appartenenza" -#: ../src/nautilus-hide.c:472 +#: ../src/nautilus-hide.c:481 msgid "" "Could not hide the selected files, error attempting to edit the database" msgstr "" "Impossibile nascondere i file selezionati, errore nel tentativo di " "modificare il database" -#: ../src/nautilus-hide.c:589 -msgid "No files were selected to be unhidden" +#: ../src/nautilus-hide.c:607 +msgid "No files have been selected to be unhidden" msgstr "Non ci sono file selezionati da rendere visibili" -#: ../src/nautilus-hide.c:603 +#: ../src/nautilus-hide.c:622 msgid "" "Could not unhide the selected files, error attempting to group them " "according to their parent directories" @@ -74,32 +78,32 @@ msgstr "" "Impossibile rendere visibili i file selezionati, errore nel tentativo di " "raggrupparli in base alla loro directory di appartenenza" -#: ../src/nautilus-hide.c:643 +#: ../src/nautilus-hide.c:662 msgid "" "Could not unhide the selected files, error attempting to edit the database" msgstr "" "Impossibile rendere visibili i file selezionati, errore nel tentativo di " "modificare il database" -#: ../src/nautilus-hide.c:893 +#: ../src/nautilus-hide.c:920 msgid "_Hide file" msgid_plural "_Hide files" msgstr[0] "_Nascondi" msgstr[1] "_Nascondi i file" -#: ../src/nautilus-hide.c:894 +#: ../src/nautilus-hide.c:926 msgid "Hide the selected file" msgid_plural "Hide the selected files" msgstr[0] "Nascondi il file selezionato" msgstr[1] "Nascondi i file selezionati" -#: ../src/nautilus-hide.c:921 +#: ../src/nautilus-hide.c:959 msgid "_Unhide file" msgid_plural "_Unhide files" msgstr[0] "Ripristina _visibilità" msgstr[1] "Ripristina _visibilità dei file" -#: ../src/nautilus-hide.c:922 +#: ../src/nautilus-hide.c:965 msgid "Unhide the selected file" msgid_plural "Unhide the selected files" msgstr[0] "Rendi visibile il file selezionato" diff --git a/src/nautilus-hide.c b/src/nautilus-hide.c index 29c1675..ab54a54 100644 --- a/src/nautilus-hide.c +++ b/src/nautilus-hide.c @@ -4,6 +4,8 @@ |*| |*| nautilus-hide.c |*| +|*| https://gitlab.gnome.org/madmurphy/nautilus-hide +|*| |*| Copyright (C) 2021 |*| |*| nautilus-hide is free software: you can redistribute it and/or modify it @@ -31,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -38,19 +41,22 @@ #ifdef ENABLE_NLS #include #include +#define I18N_INIT() \ + bindtextdomain(GETTEXT_PACKAGE, NAUTILUS_HIDE_LOCALEDIR) #else #define _(STRING) ((char *) (STRING)) #define g_dngettext(DOMAIN, STRING1, STRING2, NUM) \ ((NUM) > 1 ? (char *) (STRING2) : (char *) (STRING1)) +#define I18N_INIT() #endif -/* - - GLOBAL TYPES AND VARIABLES - -*/ +/*\ +|*| +|*| GLOBAL TYPES AND VARIABLES +|*| +\*/ #define NH_R_OK 1 @@ -69,7 +75,7 @@ typedef struct ssofwcp_T { char * hdb_path; char ** hdb_entries; GList * selection; - guint8 db_access; + guint8 hdb_access; } ssofwcp; static GType provider_types[1]; @@ -79,11 +85,11 @@ static const char hidden_db_fname[] = ".hidden"; -/* - - FUNCTIONS - -*/ +/*\ +|*| +|*| FUNCTIONS +|*| +\*/ static void close_hdb_file ( @@ -164,7 +170,7 @@ static ssofwcp * ssofwcp_new_with_dir ( ); new_ssofwcp->hdb_path[dp_len] = '/'; - new_ssofwcp->db_access = ( + new_ssofwcp->hdb_access = ( !g_access(new_ssofwcp->hdb_path, R_OK) || ( g_access(new_ssofwcp->hdb_path, F_OK) && !g_access(new_ssofwcp->directory, X_OK) @@ -300,7 +306,9 @@ static ssofwcp * ssofwcp_new_with_dir ( } - char * list_buffer = ((char *) new_ssofwcp->hdb_entries) + sizeof(char *) * fileno; + char * const list_buffer = + ((char *) new_ssofwcp->hdb_entries) + sizeof(char *) * fileno; + memcpy(list_buffer, cache, file_size + 1); free(cache); new_ssofwcp->hdb_entries[fileno - 1] = NULL; @@ -344,8 +352,8 @@ static GList * ordered_file_selection_new ( fprintf( stderr, - "Nautilus Hide: %s (ENOMEM ID: jwn8bbt)\n", - _("Error allocating memory") + "Nautilus Hide: %s\n", + _("Could not get file path") ); return NULL; @@ -427,13 +435,14 @@ static void nautilus_hide_push_files ( fprintf( stderr, "Nautilus Hide: %s\n", - _("No files were selected to be hidden") + _("No files have been selected to be hidden") ); return; } - GList * const ordered_selection = ordered_file_selection_new(file_selection); + GList * const ordered_selection = + ordered_file_selection_new(file_selection); if (!ordered_selection) { @@ -482,9 +491,15 @@ static void nautilus_hide_push_files ( /* Database file is empty or missing */ - for (i_iter = subselection->selection; i_iter; i_iter = i_iter->next) { + for ( + i_iter = subselection->selection; + i_iter; + i_iter = i_iter->next + ) { - fname = nautilus_file_info_get_name(NAUTILUS_FILE_INFO(i_iter->data)); + fname = nautilus_file_info_get_name( + NAUTILUS_FILE_INFO(i_iter->data) + ); if (*fname != '.') { @@ -526,7 +541,9 @@ static void nautilus_hide_push_files ( for (i_iter = subselection->selection; i_iter; i_iter = i_iter->next) { - fname = nautilus_file_info_get_name(NAUTILUS_FILE_INFO(i_iter->data)); + fname = nautilus_file_info_get_name( + NAUTILUS_FILE_INFO(i_iter->data) + ); if (*fname != '.') { @@ -541,7 +558,8 @@ static void nautilus_hide_push_files ( if (!subselection->hdb_entries[idx]) { - /* This file has not been found in the database, let's add it */ + /* This file has not been found in the database, + let's add it */ fwrite(fname, 1, strlen(fname), hdb_file_w); fputc('\n', hdb_file_w); @@ -586,13 +604,14 @@ static void nautilus_hide_pop_files ( fprintf( stderr, "Nautilus Hide: %s\n", - _("No files were selected to be unhidden") + _("No files have been selected to be unhidden") ); return; } - GList * const ordered_selection = ordered_file_selection_new(file_selection); + GList * const ordered_selection = + ordered_file_selection_new(file_selection); if (!ordered_selection) { @@ -669,9 +688,15 @@ static void nautilus_hide_pop_files ( } - for (i_iter = subselection->selection; i_iter; i_iter = i_iter->next) { + for ( + i_iter = subselection->selection; + i_iter; + i_iter = i_iter->next + ) { - fname = nautilus_file_info_get_name(NAUTILUS_FILE_INFO(i_iter->data)); + fname = nautilus_file_info_get_name( + NAUTILUS_FILE_INFO(i_iter->data) + ); if (!strcmp(fname, subselection->hdb_entries[idx])) { @@ -734,23 +759,6 @@ static void nautilus_hide_pop_files ( } -GType nautilus_hide_get_type (void) { - - return nautilus_hide_type; - -} - - -static void nautilus_hide_class_init ( - NautilusHideClass * const nautilus_hide_class, - gpointer class_data -) { - - parent_class = g_type_class_peek_parent(nautilus_hide_class); - -} - - static GList * nautilus_hide_get_file_items ( NautilusMenuProvider * const provider, GtkWidget * const window, @@ -763,7 +771,8 @@ static GList * nautilus_hide_get_file_items ( } - GList * const ordered_selection = ordered_file_selection_new(file_selection); + GList * const ordered_selection = + ordered_file_selection_new(file_selection); if (!ordered_selection) { @@ -771,11 +780,12 @@ static GList * nautilus_hide_get_file_items ( } - const unsigned int sellen = g_list_length(file_selection); + const guint sellen = g_list_length(file_selection); bool b_show_hide = false; bool b_show_unhide = false; gsize idx; char * fname; + NautilusMenuItem * menu_item; for ( GList * i_iter, * o_iter = ordered_selection; @@ -785,7 +795,10 @@ static GList * nautilus_hide_get_file_items ( #define subselection ((ssofwcp *) o_iter->data) - if ((subselection->db_access & (NH_R_OK | NH_W_OK)) != (NH_R_OK | NH_W_OK)) { + if ( + (subselection->hdb_access & (NH_R_OK | NH_W_OK)) != + (NH_R_OK | NH_W_OK) + ) { /* At least one database has not enough permissions */ @@ -797,9 +810,15 @@ static GList * nautilus_hide_get_file_items ( /* Database file is not empty */ - for (i_iter = subselection->selection; i_iter; i_iter = i_iter->next) { + for ( + i_iter = subselection->selection; + i_iter; + i_iter = i_iter->next + ) { - fname = nautilus_file_info_get_name(NAUTILUS_FILE_INFO(i_iter->data)); + fname = nautilus_file_info_get_name( + NAUTILUS_FILE_INFO(i_iter->data) + ); if (*fname == '.') { @@ -851,9 +870,15 @@ static GList * nautilus_hide_get_file_items ( /* Database file is empty or missing */ - for (i_iter = subselection->selection; i_iter; i_iter = i_iter->next) { + for ( + i_iter = subselection->selection; + i_iter; + i_iter = i_iter->next + ) { - fname = nautilus_file_info_get_name(NAUTILUS_FILE_INFO(i_iter->data)); + fname = nautilus_file_info_get_name( + NAUTILUS_FILE_INFO(i_iter->data) + ); if (*fname != '.') { @@ -888,27 +913,38 @@ static GList * nautilus_hide_get_file_items ( /* Show a `Hide` menu entry */ - NautilusMenuItem * const menu_item_hide = nautilus_menu_item_new( + menu_item = nautilus_menu_item_new( "NautilusHide::hide", - g_dngettext(GETTEXT_PACKAGE, "_Hide file", "_Hide files", sellen), - g_dngettext(GETTEXT_PACKAGE, "Hide the selected file", "Hide the selected files", sellen), + g_dngettext( + GETTEXT_PACKAGE, + "_Hide file", + "_Hide files", + sellen + ), + g_dngettext( + GETTEXT_PACKAGE, + "Hide the selected file", + "Hide the selected files", + sellen + ), NULL /* icon name or `NULL` */ ); g_signal_connect( - menu_item_hide, + menu_item, "activate", G_CALLBACK(nautilus_hide_push_files), NULL /* or any custom user data */ ); g_object_set_data_full( - (GObject *) menu_item_hide, "nautilus_hide_files", + (GObject *) menu_item, + "nautilus_hide_files", nautilus_file_info_list_copy(file_selection), (GDestroyNotify) nautilus_file_info_list_free ); - menu_entries = g_list_append(NULL, menu_item_hide); + menu_entries = g_list_append(NULL, menu_item); } @@ -916,27 +952,38 @@ static GList * nautilus_hide_get_file_items ( /* Show an `Unhide` menu entry */ - NautilusMenuItem * const menu_item_unhide = nautilus_menu_item_new( + menu_item = nautilus_menu_item_new( "NautilusHide::unhide", - g_dngettext(GETTEXT_PACKAGE, "_Unhide file", "_Unhide files", sellen), - g_dngettext(GETTEXT_PACKAGE, "Unhide the selected file", "Unhide the selected files", sellen), + g_dngettext( + GETTEXT_PACKAGE, + "_Unhide file", + "_Unhide files", + sellen + ), + g_dngettext( + GETTEXT_PACKAGE, + "Unhide the selected file", + "Unhide the selected files", + sellen + ), NULL /* icon name or `NULL` */ ); g_signal_connect( - menu_item_unhide, + menu_item, "activate", G_CALLBACK(nautilus_hide_pop_files), NULL /* or any custom user data */ ); g_object_set_data_full( - (GObject *) menu_item_unhide, "nautilus_hide_files", + (GObject *) menu_item, + "nautilus_hide_files", nautilus_file_info_list_copy(file_selection), (GDestroyNotify) nautilus_file_info_list_free ); - menu_entries = g_list_append(menu_entries, menu_item_unhide); + menu_entries = g_list_append(menu_entries, menu_item); } @@ -947,7 +994,7 @@ static GList * nautilus_hide_get_file_items ( static void nautilus_hide_menu_provider_iface_init ( NautilusMenuProviderIface * const iface, - gpointer iface_data + gpointer const iface_data ) { iface->get_file_items = nautilus_hide_get_file_items; @@ -955,7 +1002,19 @@ static void nautilus_hide_menu_provider_iface_init ( } -static void nautilus_hide_register_type (GTypeModule * const module) { +static void nautilus_hide_class_init ( + NautilusHideClass * const nautilus_hide_class, + gpointer const class_data +) { + + parent_class = g_type_class_peek_parent(nautilus_hide_class); + +} + + +static void nautilus_hide_register_type ( + GTypeModule * const module +) { static const GTypeInfo info = { sizeof(NautilusHideClass), @@ -967,6 +1026,7 @@ static void nautilus_hide_register_type (GTypeModule * const module) { sizeof(NautilusHide), 0, (GInstanceInitFunc) NULL, + (GTypeValueTable * ) NULL }; static const GInterfaceInfo menu_provider_iface_info = { @@ -993,12 +1053,18 @@ static void nautilus_hide_register_type (GTypeModule * const module) { } -void nautilus_module_initialize (GTypeModule * const module) { +GType nautilus_hide_get_type (void) { - #ifdef ENABLE_NLS - bindtextdomain(GETTEXT_PACKAGE, NAUTILUS_HIDE_LOCALEDIR); - #endif + return nautilus_hide_type; +} + + +void nautilus_module_initialize ( + GTypeModule * const module +) { + + I18N_INIT(); nautilus_hide_register_type(module); *provider_types = nautilus_hide_get_type(); @@ -1012,7 +1078,10 @@ void nautilus_module_shutdown (void) { } -void nautilus_module_list_types (const GType ** types, int * num_types) { +void nautilus_module_list_types ( + const GType ** const types, + int * const num_types +) { *types = provider_types; *num_types = G_N_ELEMENTS(provider_types);