Hi all !

I made a little patch (rare project I managed to realize ;-) ) to show
smart sizes in gnunet-gtk :  "10 MiB" instead of "10485760".

It's made of a little function in helper.c, which is used 3 times, from
search.c, download.c and namespace.c. Patch is attached.

I also changed the title of columns in the Advanced panel to "Name" and
"Size" instead of "Filename" and "Filesize", for consistency with other
panels (downloads and search). Hope this is good...

Christian, could you commit the patch to SVN ? Please tell me if there's
any problem.

diff -r ../gnunet-gtk-0.7.0c.orig/src/common/helper.c src/common/helper.c
31a32,35
> #define KIBIBYTE_SIZE 1024
> #define MEBIBYTE_SIZE 1048576
> #define GIBIBYTE_SIZE 1073741824
> 
252a257,282
>  * Little method to get human-readable filesizes from byte numbers.
>  */
> char * getHumanSize (unsigned long long int size_n)
> {
>   long double size_d;
>   char * size;
> 
>   if (size_n == 0) {
>     size = STRDUP(_("unknown")); }
>   else if (size_n > GIBIBYTE_SIZE) {
>     size_d = (long double) size_n / GIBIBYTE_SIZE;
>     size = g_strdup_printf ("%.1Lf %s", size_d, _("GiB")); }
>   else if (size_n > MEBIBYTE_SIZE) {
>     size_d = (long double) size_n / MEBIBYTE_SIZE;
>     size = g_strdup_printf ("%.1Lf %s", size_d, _("MiB")); }
>   else if (size_n > KIBIBYTE_SIZE) {
>     size_d = (long double) size_n / KIBIBYTE_SIZE;
>     size = g_strdup_printf ("%.1Lf %s", size_d, _("KiB")); }
>   else {
>     size_d = (long double) size_n;
>     size = g_strdup_printf ("%.1Lf %s", size_d, _("Bytes")); }
> 
>   return size;
> }
> 
> /**

diff -r ../gnunet-gtk-0.7.0c.orig/src/include/gnunetgtk_common.h 
src/include/gnunetgtk_common.h
62a63,69
> 
> /**
>  * Little method to get human-readable filesizes from byte numbers.
>  *
>  * @param size_n the size in bytes
>  */
> char * getHumanSize (unsigned long long int size_n);

diff -r ../gnunet-gtk-0.7.0c.orig/src/plugins/fs/download.c 
src/plugins/fs/download.c
115a116
>   char * size;
256a258
>   size = getHumanSize(ECRS_fileSize(uri));
265c267
<                      DOWNLOAD_SIZE, ECRS_fileSize(uri),
---
>                      DOWNLOAD_SIZE, size,
273a276
>   FREE(size);
560c563
<                        G_TYPE_UINT64,  /* size */
---
>                        G_TYPE_STRING,  /* size (human-readable)*/


diff -r ../gnunet-gtk-0.7.0c.orig/src/plugins/fs/namespace.c 
src/plugins/fs/namespace.c
196c196
<   unsigned long long size;
---
>   char * size;
233c233
<     size = ECRS_fileSize(fi->uri);
---
>     size = getHumanSize(ECRS_fileSize(fi->uri));
235c235
<     size = 0;
---
>     size = _("unknown");
1116c1116
<                            G_TYPE_UINT64, /* size */
---
>                            G_TYPE_STRING, /* size (human-readable) */
1125c1125
<                                             _("Filename"),
---
>                                             _("Name"),
1132a1133
>   g_object_set (renderer, "xalign", 1.00);
1135c1136
<                                             _("Filesize"),
---
>                                             _("Size"),


diff -r ../gnunet-gtk-0.7.0c.orig/src/plugins/fs/search.c 
src/plugins/fs/search.c
67a68
>   char * size;
72d72
<   unsigned long long size;
108,110c108,110
<     
<   if (ECRS_isFileUri(uri)) {
<     size = ECRS_fileSize(uri);
---
> 
>    if (ECRS_isFileUri(uri)) {
>     size = getHumanSize(ECRS_fileSize(uri));
112,113c112,114
<     size = 0;
<   }
---
>     size = _("unknown");
>   } 
> 
145a147
>   FREE(size);
552c554
<                      G_TYPE_UINT64,  /* size */
---
>                      G_TYPE_STRING,  /* size (human-readable)*/
571a574
>   g_object_set (renderer, "xalign", 1.00);
_______________________________________________
GNUnet-developers mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnunet-developers

Reply via email to