Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] File extension column #3086

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gresources/nemo-desktop-overlay.glade
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@
<col id="2">Desktop Sort by Size</col>
</row>
<row>
<col id="0">4</col>
<col id="0">3</col>
<col id="1" translatable="yes">Type</col>
<col id="2">Desktop Sort by Type</col>
</row>
<row>
<col id="0">4</col>
<col id="1" translatable="yes">Extension</col>
<col id="2">Desktop Sort by Extension</col>
</row>
<row>
<col id="0">5</col>
<col id="1" translatable="yes">Date</col>
Expand Down
5 changes: 4 additions & 1 deletion gresources/nemo-file-management-properties.glade
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ along with . If not, see <http://www.gnu.org/licenses/>.
</row>
<row>
<col id="0" translatable="yes">By Type</col>
</row>
<row>
<row>
<col id="0" translatable="yes">By Extension</col>
<row>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags are wrong - this causes nemo to crash.

Each column needs to open with <row> and close with </row>

<row>
<col id="0" translatable="yes">By Detailed Type</col>
</row>
Expand Down
2 changes: 2 additions & 0 deletions gresources/nemo-icon-view-ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<menuitem name="Sort by Name" action="Sort by Name"/>
<menuitem name="Sort by Size" action="Sort by Size"/>
<menuitem name="Sort by Type" action="Sort by Type"/>
<menuitem name="Sort by Extension" action="Sort by Extension"/>
<menuitem name="Sort by Detailed Type" action="Sort by Detailed Type"/>
<menuitem name="Sort by Modification Date" action="Sort by Modification Date"/>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
Expand All @@ -30,6 +31,7 @@
<menuitem name="Sort by Name" action="Sort by Name"/>
<menuitem name="Sort by Size" action="Sort by Size"/>
<menuitem name="Sort by Type" action="Sort by Type"/>
<menuitem name="Sort by Extension" action="Sort by Extension"/>
<menuitem name="Sort by Detailed Type" action="Sort by Detailed Type"/>
<menuitem name="Sort by Modification Date" action="Sort by Modification Date"/>
<menuitem name="Sort by Trash Time" action="Sort by Trash Time"/>
Expand Down
8 changes: 8 additions & 0 deletions libnemo-private/nemo-column-utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ get_builtin_columns (void)
"label", _("Type"),
"description", _("The general type of the file."),
NULL));
columns = g_list_append (columns,
g_object_new (NEMO_TYPE_COLUMN,
"name", "extension",
"attribute", "extension",
"label", _("Extension"),
"description", _("The extension of the file."),
NULL));
columns = g_list_append (columns,
g_object_new (NEMO_TYPE_COLUMN,
"name", "detailed_type",
Expand All @@ -72,6 +79,7 @@ get_builtin_columns (void)
"label", _("Date Modified"),
"description", _("The date the file was modified."),
NULL));

columns = g_list_append (columns,
g_object_new (NEMO_TYPE_COLUMN,
"name", "date_modified_with_time",
Expand Down
61 changes: 61 additions & 0 deletions libnemo-private/nemo-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static GHashTable *symbolic_links;
static GQuark attribute_name_q,
attribute_size_q,
attribute_type_q,
attribute_ext_q,
attribute_detailed_type_q,
attribute_modification_date_q,
attribute_date_modified_q,
Expand Down Expand Up @@ -173,6 +174,7 @@ static void nemo_file_info_iface_init (NemoFileInfoInterface
static gboolean update_info_and_name (NemoFile *file,
GFileInfo *info);
static const char * nemo_file_peek_display_name (NemoFile *file);
const char * nemo_file_peek_extension_name (NemoFile *file);
static const char * nemo_file_peek_display_name_collation_key (NemoFile *file);
static void file_mount_unmounted (GMount *mount, gpointer data);
static void metadata_hash_free (GHashTable *hash);
Expand Down Expand Up @@ -3074,6 +3076,20 @@ compare_by_display_name (NemoFile *file_1, NemoFile *file_2)
return compare;
}

static int
compare_by_extension_name (NemoFile *file_1, NemoFile *file_2)
{
const char *key_1, *key_2;
int compare=0;

key_1 = nemo_file_peek_extension_name (file_1);
key_2 = nemo_file_peek_extension_name (file_2);

compare = g_strcmp0 (key_1, key_2);

return compare;
}

static int
compare_by_directory_name (NemoFile *file_1, NemoFile *file_2)
{
Expand Down Expand Up @@ -3357,6 +3373,12 @@ nemo_file_compare_for_sort (NemoFile *file_1,
result = compare_by_directory_name (file_1, file_2);
}
break;
case NEMO_FILE_SORT_BY_EXTENSION_NAME:
result = compare_by_extension_name (file_1, file_2);
if (result == 0) {
result = compare_by_display_name (file_1, file_2);
}
break;
case NEMO_FILE_SORT_BY_SIZE:
/* Compare directory sizes ourselves, then if necessary
* use GnomeVFS to compare file sizes.
Expand Down Expand Up @@ -3446,6 +3468,13 @@ nemo_file_compare_for_sort_by_attribute_q (NemoFile *file_1,
favorites_first,
reversed,
search_dir);
} else if (attribute == attribute_ext_q) {
return nemo_file_compare_for_sort (file_1, file_2,
NEMO_FILE_SORT_BY_EXTENSION_NAME,
directories_first,
favorites_first,
reversed,
search_dir);
} else if (attribute == attribute_size_q) {
return nemo_file_compare_for_sort (file_1, file_2,
NEMO_FILE_SORT_BY_SIZE,
Expand Down Expand Up @@ -4036,6 +4065,28 @@ nemo_file_peek_display_name_collation_key (NemoFile *file)
return res;
}

const char *
nemo_file_peek_extension_name (NemoFile *file)
{
if (file == NULL) {
return NULL;
}

if (nemo_file_is_broken_symbolic_link (file)) {
return g_strdup (_("link (broken)"));
}

char *str, *token, *result;
str = g_strdup (eel_ref_str_peek(file->details->name));//strdup()

while ((token = strsep(&str, "."))) {result = g_strdup(token);}
if (result == NULL) {result = "";}
g_free(str);
g_free(token);

return result;
}
Comment on lines +4075 to +4088
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few problems here:

Remember you're not returning a new string (const char*), since you're 'peeking' at the value:

  • link broken string should just be a static string (no g_strdup).
  • The remaining code either returns a new string, or a static empty one, and leaks memory (you never free token while running the strsep loop, and if there are multiple separators the intermediate ones leak).

I would suggest using g_strrstr as it works from the end of the string and returns a pointer or NULL, and no new strings need to be created:

    const char *str, *ptr;
    str = eel_ref_str_peek (file->details->name);

    if ((ptr = g_strrstr (str, "."))) {
        return ptr + 1;
    }

    return "";

We usually try to stick with glib functions, as they're generally more convenient (and often safer).


static const char *
nemo_file_peek_display_name (NemoFile *file)
{
Expand Down Expand Up @@ -4077,6 +4128,12 @@ nemo_file_get_display_name (NemoFile *file)
return g_strdup (nemo_file_peek_display_name (file));
}

char *
nemo_file_get_extension_name (NemoFile *file)
{
return nemo_file_peek_extension_name (file);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're returning a new string (char * return), so you would need to g_strdup the peeked extension name.


char *
nemo_file_get_edit_name (NemoFile *file)
{
Expand Down Expand Up @@ -6689,6 +6746,9 @@ nemo_file_get_string_attribute_q (NemoFile *file, GQuark attribute_q)
if (attribute_q == attribute_name_q) {
return nemo_file_get_display_name (file);
}
if (attribute_q == attribute_ext_q) {
return nemo_file_get_extension_name (file);
}
if (attribute_q == attribute_type_q) {
return nemo_file_get_type_as_string (file);
}
Expand Down Expand Up @@ -8902,6 +8962,7 @@ nemo_file_class_init (NemoFileClass *class)
attribute_name_q = g_quark_from_static_string ("name");
attribute_size_q = g_quark_from_static_string ("size");
attribute_type_q = g_quark_from_static_string ("type");
attribute_ext_q = g_quark_from_static_string ("extension");
attribute_detailed_type_q = g_quark_from_static_string ("detailed_type");
attribute_modification_date_q = g_quark_from_static_string ("modification_date");
attribute_date_modified_q = g_quark_from_static_string ("date_modified");
Expand Down
22 changes: 13 additions & 9 deletions libnemo-private/nemo-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef enum {
NEMO_FILE_SORT_BY_DISPLAY_NAME,
NEMO_FILE_SORT_BY_SIZE,
NEMO_FILE_SORT_BY_TYPE,
NEMO_FILE_SORT_BY_EXTENSION_NAME,
NEMO_FILE_SORT_BY_DETAILED_TYPE,
NEMO_FILE_SORT_BY_MTIME,
NEMO_FILE_SORT_BY_ATIME,
Expand Down Expand Up @@ -155,7 +156,7 @@ NemoFile * nemo_file_get_existing_by_uri (const char
* 1) Using these is type safe.
* 2) You are allowed to call these with NULL,
*/
NemoFile * nemo_file_ref (NemoFile *file);
NemoFile * nemo_file_ref (NemoFile *file);
void nemo_file_unref (NemoFile *file);

/* Monitor the file. */
Expand Down Expand Up @@ -189,15 +190,18 @@ gboolean nemo_file_contains_text (NemoFile
char * nemo_file_get_display_name (NemoFile *file);
char * nemo_file_get_edit_name (NemoFile *file);
char * nemo_file_get_name (NemoFile *file);
char * nemo_file_get_extension_name (NemoFile *file);

const char * nemo_file_peek_name (NemoFile *file);
const char * nemo_file_peek_extension_name (NemoFile *file);

GFile * nemo_file_get_location (NemoFile *file);
char * nemo_file_get_description (NemoFile *file);
char * nemo_file_get_description (NemoFile *file);
char * nemo_file_get_uri (NemoFile *file);
char * nemo_file_get_path (NemoFile *file);
char * nemo_file_get_uri_scheme (NemoFile *file);
gboolean nemo_file_has_uri_scheme (NemoFile *file, const gchar *scheme);
NemoFile * nemo_file_get_parent (NemoFile *file);
NemoFile * nemo_file_get_parent (NemoFile *file);
GFile * nemo_file_get_parent_location (NemoFile *file);
char * nemo_file_get_parent_uri (NemoFile *file);
char * nemo_file_get_parent_uri_for_display (NemoFile *file);
Expand All @@ -208,7 +212,7 @@ time_t nemo_file_get_ctime (NemoFile
GFileType nemo_file_get_file_type (NemoFile *file);
char * nemo_file_get_mime_type (NemoFile *file);
gboolean nemo_file_is_mime_type (NemoFile *file,
const char *mime_type);
const char *mime_type);
gboolean nemo_file_is_launchable (NemoFile *file);
gboolean nemo_file_is_symbolic_link (NemoFile *file);
gboolean nemo_file_is_mountpoint (NemoFile *file);
Expand All @@ -220,27 +224,27 @@ char * nemo_file_get_volume_name (NemoFile
char * nemo_file_get_symbolic_link_target_path (NemoFile *file);
char * nemo_file_get_symbolic_link_target_uri (NemoFile *file);
gboolean nemo_file_is_broken_symbolic_link (NemoFile *file);
gboolean nemo_file_is_nemo_link (NemoFile *file);
gboolean nemo_file_is_nemo_link (NemoFile *file);
gboolean nemo_file_is_executable (NemoFile *file);
gboolean nemo_file_is_directory (NemoFile *file);
gboolean nemo_file_is_user_special_directory (NemoFile *file,
GUserDirectory special_directory);
gboolean nemo_file_is_archive (NemoFile *file);
gboolean nemo_file_is_archive (NemoFile *file);
gboolean nemo_file_is_in_trash (NemoFile *file);
gboolean nemo_file_is_in_recent (NemoFile *file);
gboolean nemo_file_is_in_favorites (NemoFile *file);
gboolean nemo_file_is_in_search (NemoFile *file);
gboolean nemo_file_is_unavailable_favorite (NemoFile *file);
gboolean nemo_file_is_in_admin (NemoFile *file);
gboolean nemo_file_is_in_desktop (NemoFile *file);
gboolean nemo_file_is_home (NemoFile *file);
gboolean nemo_file_is_home (NemoFile *file);
gboolean nemo_file_is_desktop_directory (NemoFile *file);
GError * nemo_file_get_file_info_error (NemoFile *file);
gboolean nemo_file_get_directory_item_count (NemoFile *file,
guint *count,
gboolean *count_unreadable);
void nemo_file_recompute_deep_counts (NemoFile *file);
NemoRequestStatus nemo_file_get_deep_counts (NemoFile *file,
NemoRequestStatus nemo_file_get_deep_counts (NemoFile *file,
guint *directory_count,
guint *file_count,
guint *unreadable_directory_count,
Expand All @@ -266,7 +270,7 @@ GFilesystemPreviewType nemo_file_get_filesystem_use_preview (NemoFile *f

char * nemo_file_get_filesystem_id (NemoFile *file);

NemoFile * nemo_file_get_trash_original_file (NemoFile *file);
NemoFile * nemo_file_get_trash_original_file (NemoFile *file);

/* Permissions. */
gboolean nemo_file_can_get_permissions (NemoFile *file);
Expand Down
11 changes: 6 additions & 5 deletions libnemo-private/org.nemo.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
<value nick="name" value="1"/>
<value nick="size" value="2"/>
<value nick="type" value="3"/>
<value nick="detailed_type" value="4"/>
<value nick="mtime" value="5"/>
<value nick="atime" value="6"/>
<value nick="trash-time" value="7"/>
<value nick="extension" value="4"/>
<value nick="detailed_type" value="5"/>
<value nick="mtime" value="6"/>
<value nick="atime" value="7"/>
<value nick="trash-time" value="8"/>
</enum>

<enum id="org.nemo.ZoomLevel">
Expand Down Expand Up @@ -428,7 +429,7 @@
<description>A list of captions below an icon in the icon view and
the desktop. The actual number of captions shown depends on
the zoom level. Some possible values are:
"size", "type", "date_modified", "date_changed", "date_accessed", "owner",
"size", "type", "date_modified", "extension", "date_changed", "date_accessed", "owner",
"group", "permissions", "octal_permissions" and "mime_type".</description>
</key>
<key name="default-use-tighter-layout" type="b">
Expand Down
9 changes: 9 additions & 0 deletions src/nemo-desktop-icon-grid-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ static const DesktopSortCriterion sort_criteria[] = {
"Desktop Sort by Type",
"detailed_type",
NEMO_FILE_SORT_BY_DETAILED_TYPE
},
{
"Desktop Sort by Extension",
"extension",
NEMO_FILE_SORT_BY_EXTENSION_NAME
},
{
"Desktop Sort by Date",
Expand Down Expand Up @@ -1074,6 +1079,10 @@ static const GtkRadioActionEntry desktop_sort_radio_entries[] = {
N_("Name"), NULL,
NULL,
NEMO_FILE_SORT_BY_DISPLAY_NAME },
{ "Desktop Sort by Extension", NULL,
N_("Extension"), NULL,
NULL,
NEMO_FILE_SORT_BY_EXTENSION_NAME },
{ "Desktop Sort by Size", NULL,
N_("Size"), NULL,
NULL,
Expand Down
3 changes: 3 additions & 0 deletions src/nemo-desktop-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ sync_controls (NemoDesktopOverlay *overlay,
case NEMO_FILE_SORT_BY_DETAILED_TYPE:
combo_id = "Desktop Sort by Type";
break;
case NEMO_FILE_SORT_BY_EXTENSION_NAME:
combo_id = "Desktop Sort by Extension";
break;
case NEMO_FILE_SORT_BY_MTIME:
combo_id = "Desktop Sort by Date";
break;
Expand Down
1 change: 1 addition & 0 deletions src/nemo-file-management-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ static const char * const sort_order_values[] = {
"name",
"size",
"type",
"extension",
"detailed_type",
"mtime",
"atime",
Expand Down
11 changes: 11 additions & 0 deletions src/nemo-icon-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ static const SortCriterion sort_criteria[] = {
N_("by _Type"),
N_("Keep icons sorted by type in rows")
},
{
NEMO_FILE_SORT_BY_EXTENSION_NAME,
"extension",
"Sort by Extension",
N_("by _Extension"),
N_("Keep icons sorted by Extension in rows")
},
{
NEMO_FILE_SORT_BY_DETAILED_TYPE,
"detailed_type",
Expand Down Expand Up @@ -1428,6 +1435,10 @@ static const GtkRadioActionEntry arrange_radio_entries[] = {
N_("By _Name"), NULL,
N_("Keep icons sorted by name in rows"),
NEMO_FILE_SORT_BY_DISPLAY_NAME },
{ "Sort by Extension", NULL,
N_("By _Extension"), NULL,
N_("Keep icons sorted by extension in rows"),
NEMO_FILE_SORT_BY_EXTENSION_NAME },
{ "Sort by Size", NULL,
N_("By _Size"), NULL,
N_("Keep icons sorted by size in rows"),
Expand Down
1 change: 1 addition & 0 deletions src/nemo-list-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ get_default_sort_order (NemoFile *file, gboolean *reversed)
"name",
"size",
"type",
"extension",
"detailed_type",
"date_modified",
"date_accessed",
Expand Down