Skip to content

Commit f01acc3

Browse files
committed
Merge pull request linuxmint#25 from ebbes/base-2
Allow use of base-2 file size prefixes (kiB, MiB, GiB) instead of base-10
2 parents 6a6c78c + b51f389 commit f01acc3

File tree

8 files changed

+159
-12
lines changed

8 files changed

+159
-12
lines changed

libnemo-private/nemo-file-operations.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,11 @@ custom_size_to_string (char *format, va_list va)
848848
goffset size;
849849

850850
size = va_arg (va, goffset);
851-
return g_format_size (size);
851+
852+
int prefix;
853+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
854+
855+
return g_format_size_full (size, prefix);
852856
}
853857

854858
static void

libnemo-private/nemo-file.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5844,6 +5844,7 @@ nemo_file_get_size_as_string (NemoFile *file)
58445844
{
58455845
guint item_count;
58465846
gboolean count_unreadable;
5847+
int prefix;
58475848

58485849
if (file == NULL) {
58495850
return NULL;
@@ -5861,7 +5862,9 @@ nemo_file_get_size_as_string (NemoFile *file)
58615862
if (file->details->size == -1) {
58625863
return NULL;
58635864
}
5864-
return g_format_size (file->details->size);
5865+
5866+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
5867+
return g_format_size_full (file->details->size, prefix);
58655868
}
58665869

58675870
/**
@@ -5881,6 +5884,7 @@ nemo_file_get_size_as_string_with_real_size (NemoFile *file)
58815884
{
58825885
guint item_count;
58835886
gboolean count_unreadable;
5887+
int prefix;
58845888

58855889
if (file == NULL) {
58865890
return NULL;
@@ -5898,8 +5902,11 @@ nemo_file_get_size_as_string_with_real_size (NemoFile *file)
58985902
if (file->details->size == -1) {
58995903
return NULL;
59005904
}
5901-
5902-
return g_format_size_full (file->details->size, G_FORMAT_SIZE_LONG_FORMAT);
5905+
5906+
/* If base-2 or base-2-full, then prefix will be 2 (i.e. base-2), if base-10 or base-10-long
5907+
then prefix will be 0 (i.e. base-0). Prefix will be added to LONG_FORMAT */
5908+
prefix = (g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES) / 2) * 2;
5909+
return g_format_size_full (file->details->size, G_FORMAT_SIZE_LONG_FORMAT + prefix);
59035910
}
59045911

59055912

@@ -5915,6 +5922,7 @@ nemo_file_get_deep_count_as_string_internal (NemoFile *file,
59155922
guint unreadable_count;
59165923
guint total_count;
59175924
goffset total_size;
5925+
int prefix;
59185926

59195927
/* Must ask for size or some kind of count, but not both. */
59205928
g_assert (!report_size || (!report_directory_count && !report_file_count));
@@ -5959,7 +5967,8 @@ nemo_file_get_deep_count_as_string_internal (NemoFile *file,
59595967
* directly if desired.
59605968
*/
59615969
if (report_size) {
5962-
return g_format_size (total_size);
5970+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
5971+
return g_format_size_full (total_size, prefix);
59635972
}
59645973

59655974
return format_item_count_for_display (report_directory_count
@@ -6672,6 +6681,7 @@ nemo_file_get_volume_free_space (NemoFile *file)
66726681
GFile *location;
66736682
char *res;
66746683
time_t now;
6684+
int prefix;
66756685

66766686
now = time (NULL);
66776687
/* Update first time and then every 2 seconds */
@@ -6689,7 +6699,8 @@ nemo_file_get_volume_free_space (NemoFile *file)
66896699

66906700
res = NULL;
66916701
if (file->details->free_space != (guint64)-1) {
6692-
res = g_format_size (file->details->free_space);
6702+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
6703+
res = g_format_size_full (file->details->free_space, prefix);
66936704
}
66946705

66956706
return res;

libnemo-private/nemo-global-preferences.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ typedef enum
194194
/* Desktop background */
195195
#define NEMO_PREFERENCES_SHOW_DESKTOP "show-desktop-icons"
196196

197+
/* File size unit prefix */
198+
#define NEMO_PREFERENCES_SIZE_PREFIXES "size-prefixes"
199+
197200

198201
void nemo_global_preferences_init (void);
199202
char *nemo_global_preferences_get_default_folder_viewer_preference_as_iid (void);

libnemo-private/org.nemo.gschema.xml.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
<value nick="after-current-tab" value="0"/>
5353
<value nick="end" value="1"/>
5454
</enum>
55+
56+
<enum id="org.nemo.SizePrefixes">
57+
<value value="0" nick="base-10"/>
58+
<value value="1" nick="base-10-full"/>
59+
<value value="2" nick="base-2"/>
60+
<value value="3" nick="base-2-full"/>
61+
</enum>
5562

5663
<schema id="org.nemo" path="/org/nemo/" gettext-domain="nemo">
5764
<child name="preferences" schema="org.nemo.preferences"/>
@@ -233,6 +240,11 @@
233240
<_summary>Bulk rename utility</_summary>
234241
<_description>If set, Nemo will append URIs of selected files and treat the result as a command line for bulk renaming. Bulk rename applications can register themselves in this key by setting the key to a space-separated string of their executable name and any command line options. If the executable name is not set to a full path, it will be searched for in the search path.</_description>
235242
</key>
243+
<key name="size-prefixes" enum="org.nemo.SizePrefixes">
244+
<default>'base-10'</default>
245+
<_summary>Prefixes used for file sizes</_summary>
246+
<_description>Determines whether Nemo uses base-10, base-10 long, base-2 or base-2 long file size prefixes</_description>
247+
</key>
236248
</schema>
237249

238250
<schema id="org.nemo.icon-view" path="/org/nemo/icon-view/" gettext-domain="nemo">

src/nemo-file-management-properties.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define NEMO_FILE_MANAGEMENT_PROPERTIES_PREVIEW_TEXT_WIDGET "preview_text_combobox"
5151
#define NEMO_FILE_MANAGEMENT_PROPERTIES_PREVIEW_IMAGE_WIDGET "preview_image_combobox"
5252
#define NEMO_FILE_MANAGEMENT_PROPERTIES_PREVIEW_FOLDER_WIDGET "preview_folder_combobox"
53+
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SIZE_PREFIXES_WIDGET "size_prefixes_combobox"
5354

5455
/* bool preferences */
5556
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_LOCATION_ENTRY_WIDGET "show_location_entry_checkbutton"
@@ -143,6 +144,14 @@ static const char * const executable_text_values[] = {
143144
NULL
144145
};
145146

147+
static const char * const size_prefixes_values[] = {
148+
"base-10",
149+
"base-10-full",
150+
"base-2",
151+
"base-2-full",
152+
NULL
153+
};
154+
146155
static const guint64 thumbnail_limit_values[] = {
147156
102400,
148157
512000,
@@ -814,6 +823,10 @@ nemo_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow *wi
814823
NEMO_FILE_MANAGEMENT_PROPERTIES_PREVIEW_FOLDER_WIDGET,
815824
NEMO_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
816825
(const char **) preview_values);
826+
bind_builder_enum (builder, nemo_preferences,
827+
NEMO_FILE_MANAGEMENT_PROPERTIES_SIZE_PREFIXES_WIDGET,
828+
NEMO_PREFERENCES_SIZE_PREFIXES,
829+
(const char **) size_prefixes_values);
817830
bind_builder_enum (builder, nemo_preferences,
818831
NEMO_FILE_MANAGEMENT_PROPERTIES_DATE_FORMAT_WIDGET,
819832
NEMO_PREFERENCES_DATE_FORMAT,

src/nemo-file-management-properties.ui

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,84 @@
11601160
<property name="position">1</property>
11611161
</packing>
11621162
</child>
1163+
<child>
1164+
<object class="GtkBox" id="vbox12">
1165+
<property name="visible">True</property>
1166+
<property name="can_focus">False</property>
1167+
<property name="orientation">vertical</property>
1168+
<property name="spacing">6</property>
1169+
<child>
1170+
<object class="GtkLabel" id="label7">
1171+
<property name="visible">True</property>
1172+
<property name="can_focus">False</property>
1173+
<property name="xalign">0</property>
1174+
<property name="label" translatable="yes">&lt;b&gt;File Size&lt;/b&gt;</property>
1175+
<property name="use_markup">True</property>
1176+
</object>
1177+
<packing>
1178+
<property name="expand">False</property>
1179+
<property name="fill">False</property>
1180+
<property name="position">0</property>
1181+
</packing>
1182+
</child>
1183+
<child>
1184+
<object class="GtkAlignment" id="alignment12">
1185+
<property name="visible">True</property>
1186+
<property name="can_focus">False</property>
1187+
<property name="left_padding">12</property>
1188+
<child>
1189+
<object class="GtkBox" id="hbox1">
1190+
<property name="visible">True</property>
1191+
<property name="can_focus">False</property>
1192+
<property name="spacing">12</property>
1193+
<child>
1194+
<object class="GtkLabel" id="label8">
1195+
<property name="visible">True</property>
1196+
<property name="can_focus">False</property>
1197+
<property name="label" translatable="yes">_Prefixes:</property>
1198+
<property name="use_underline">True</property>
1199+
<property name="mnemonic_widget">size_prefixes_combobox</property>
1200+
</object>
1201+
<packing>
1202+
<property name="expand">False</property>
1203+
<property name="fill">False</property>
1204+
<property name="position">0</property>
1205+
</packing>
1206+
</child>
1207+
<child>
1208+
<object class="GtkComboBox" id="size_prefixes_combobox">
1209+
<property name="visible">True</property>
1210+
<property name="can_focus">False</property>
1211+
<property name="model">model11</property>
1212+
<child>
1213+
<object class="GtkCellRendererText" id="renderer11"/>
1214+
<attributes>
1215+
<attribute name="text">0</attribute>
1216+
</attributes>
1217+
</child>
1218+
</object>
1219+
<packing>
1220+
<property name="expand">False</property>
1221+
<property name="fill">False</property>
1222+
<property name="position">1</property>
1223+
</packing>
1224+
</child>
1225+
</object>
1226+
</child>
1227+
</object>
1228+
<packing>
1229+
<property name="expand">False</property>
1230+
<property name="fill">False</property>
1231+
<property name="position">1</property>
1232+
</packing>
1233+
</child>
1234+
</object>
1235+
<packing>
1236+
<property name="expand">False</property>
1237+
<property name="fill">False</property>
1238+
<property name="position">2</property>
1239+
</packing>
1240+
</child>
11631241
</object>
11641242
<packing>
11651243
<property name="position">2</property>
@@ -1834,6 +1912,26 @@
18341912
</row>
18351913
</data>
18361914
</object>
1915+
<object class="GtkListStore" id="model11">
1916+
<columns>
1917+
<!-- column-name gchararray -->
1918+
<column type="gchararray"/>
1919+
</columns>
1920+
<data>
1921+
<row>
1922+
<col id="0" translatable="yes">Decimal</col>
1923+
</row>
1924+
<row>
1925+
<col id="0" translatable="yes">Decimal (long format)</col>
1926+
</row>
1927+
<row>
1928+
<col id="0" translatable="yes">Binary</col>
1929+
</row>
1930+
<row>
1931+
<col id="0" translatable="yes">Binary (long format)</col>
1932+
</row>
1933+
</data>
1934+
</object>
18371935
<object class="GtkListStore" id="model2">
18381936
<columns>
18391937
<!-- column-name gchararray -->

src/nemo-properties-window.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,9 @@ directory_contents_value_field_update (NemoPropertiesWindow *window)
21182118
}
21192119
} else {
21202120
char *size_str;
2121-
size_str = g_format_size (total_size);
2121+
int prefix;
2122+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
2123+
size_str = g_format_size_full (total_size, prefix);
21222124
text = g_strdup_printf (ngettext("%'d item, with size %s",
21232125
"%'d items, totalling %s",
21242126
total_count),
@@ -2878,10 +2880,12 @@ create_pie_widget (NemoPropertiesWindow *window)
28782880
gchar *uri;
28792881
GFile *location;
28802882
GFileInfo *info;
2883+
int prefix;
28812884

2882-
capacity = g_format_size (window->details->volume_capacity);
2883-
free = g_format_size (window->details->volume_free);
2884-
used = g_format_size (window->details->volume_capacity - window->details->volume_free);
2885+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
2886+
capacity = g_format_size_full (window->details->volume_capacity, prefix);
2887+
free = g_format_size_full (window->details->volume_free, prefix);
2888+
used = g_format_size_full (window->details->volume_capacity - window->details->volume_free, prefix);
28852889

28862890
file = get_original_file (window);
28872891

src/nemo-view.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,8 +2848,10 @@ nemo_view_display_selection_info (NemoView *view)
28482848

28492849
if (non_folder_size_known) {
28502850
char *size_string;
2851-
2852-
size_string = g_format_size (non_folder_size);
2851+
int prefix;
2852+
2853+
prefix = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_SIZE_PREFIXES);
2854+
size_string = g_format_size_full (non_folder_size, prefix);
28532855
/* This is marked for translation in case a localiser
28542856
* needs to use something other than parentheses. The
28552857
* first message gives the number of items selected;

0 commit comments

Comments
 (0)