file size 3dgts+sfx, timebar tweak, mask msg
[goodguy/history.git] / cinelerra-5.1 / guicast / bcfilebox.C
index 0fae125014cba9c23d97c15c8e9d6c3c621e4028..03a49e9a9161c3968e3919d7660ce597c567d0d5 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
  * CINELERRA
- * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 1997-2017 Adam Williams <broadcast at earthling dot net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -683,9 +683,7 @@ int BC_FileBox::get_listbox_w()
 
 int BC_FileBox::get_listbox_h(int y)
 {
-       int result = get_h() -
-               y -
-               h_padding;
+       int result = get_h() - y - h_padding - 10;
        if(want_directory)
                result -= BC_WindowBase::get_resources()->dirbox_margin;
        else
@@ -796,6 +794,13 @@ int BC_FileBox::extract_extension(char *out, const char *in)
        return 0;
 }
 
+static inline int64_t ipow(int m, int n)
+{
+       int64_t v = 1;
+       for( int64_t vv=m; n>0; vv*=vv,n>>=1 ) if( n & 1 ) v *= vv;
+       return v;
+}
+
 int BC_FileBox::create_tables()
 {
        delete_tables();
@@ -823,7 +828,27 @@ int BC_FileBox::create_tables()
 //             {
                        if(!is_dir)
                        {
-                               sprintf(string, "%jd", file_item->size);
+                               int64_t size = file_item->size;
+#if 1
+                               int len = 1;
+                               static const char *suffix[] = { "", "K", "M", "G", "T", "P" };
+                               for( int64_t s=size; len<15 && (s/=10)>0; ++len );
+                               int drop = len-3;
+                               if( drop > 0 ) {
+                                       size /= ipow(10,drop);
+                                       int sfx = (len-1)/3;
+                                       int digits = (sfx+1)*3 - len;
+                                       int64_t frac = ipow(10,digits);
+                                       int mantisa = size / frac;
+                                       int fraction = size - mantisa*frac;
+                                       if( fraction )
+                                               sprintf(string, "%d.%0*d%s", mantisa, digits, fraction, suffix[sfx]);
+                                       else
+                                               sprintf(string, "%d%s", mantisa, suffix[sfx]);
+                               }
+                               else
+#endif
+                                       sprintf(string, "%jd", size);
                                new_item = new BC_ListBoxItem(string, get_resources()->file_color);
                        }
                        else
@@ -837,15 +862,11 @@ int BC_FileBox::create_tables()
 // Date entry
                if(!is_dir || 1)
                {
-                       static const char *month_text[13] = { "Nul",
-                               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-                               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-                       };
-                       sprintf(string,
-                               "%s %d, %d",
-                               month_text[file_item->month],
-                               file_item->day,
-                               file_item->year);
+                       struct tm mod_time;
+                       localtime_r(&file_item->mtime, &mod_time);
+                       sprintf(string, "%04d.%02d.%02d  %02d:%02d:%02d",
+                               mod_time.tm_year+1900, mod_time.tm_mon+1, mod_time.tm_mday,
+                               mod_time.tm_hour, mod_time.tm_min, mod_time.tm_sec);
                        new_item = new BC_ListBoxItem(string, get_resources()->file_color);
                }
                else
@@ -883,25 +904,13 @@ int BC_FileBox::delete_tables()
 
 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
 {
-       char *suffix = strrchr(path, '.');
+       if( is_dir ) return icons[ICON_FOLDER];
        int icon_type = ICON_UNKNOWN;
-
-       if(is_dir) return icons[ICON_FOLDER];
-
-       if(suffix)
-       {
-               suffix++;
-               if(*suffix != 0)
-               {
-                       for(int i = 0; i < TOTAL_SUFFIXES; i++)
-                       {
-                               if(!strcasecmp(suffix, BC_WindowBase::get_resources()->suffix_to_type[i].suffix))
-                               {
-                                       icon_type = BC_WindowBase::get_resources()->suffix_to_type[i].icon_type;
-                                       break;
-                               }
-                       }
-               }
+       char *suffix = strrchr(path, '.');
+       if( suffix && *++suffix ) {
+               suffix_to_type_t *stp = &BC_WindowBase::get_resources()->suffix_to_type[0];
+               while( stp->suffix && strcasecmp(stp->suffix, suffix) ) ++stp;
+               if( stp->icon_type ) icon_type = stp->icon_type;
        }
 
        return icons[icon_type];
@@ -1038,12 +1047,17 @@ int BC_FileBox::submit_dir(char *dir)
 
 int BC_FileBox::submit_file(const char *path, int use_this)
 {
+       char path1[BCTEXTLEN];
+       strcpy(path1, path);
+       char *cp = strchr(path1,'\n');
+       if( cp ) *cp = 0;
+
 // Deactivate textbox to hide suggestions
        textbox->deactivate();
 
 // If file wanted, take the current directory as the desired file.
 // If directory wanted, ignore it.
-       if(!path[0] && !want_directory)
+       if(!path1[0] && !want_directory)
        {
 // save complete path
                strcpy(this->current_path, directory);
@@ -1057,9 +1071,9 @@ int BC_FileBox::submit_file(const char *path, int use_this)
        }
 
 // is a directory, change directories
-       if(fs->is_dir(path) && !use_this)
+       if(fs->is_dir(path1) && !use_this)
        {
-               fs->change_dir(path, 0);
+               fs->change_dir(path1, 0);
                refresh(1);
                directory_title->update(fs->get_current_dir());
                strcpy(this->current_path, fs->get_current_dir());
@@ -1078,7 +1092,7 @@ int BC_FileBox::submit_file(const char *path, int use_this)
 // Is a file or desired directory.  Quit the operation.
        {
                char path2[BCTEXTLEN];
-               strcpy(path2, path);
+               strcpy(path2, path1);
 
 // save directory for defaults
                fs->extract_dir(directory, path2);
@@ -1114,7 +1128,7 @@ void BC_FileBox::update_history()
        strcpy(path, directory);
 // enfore one trailing slash
        char *cp = path;
-       while( *cp ) ++cp;
+       while( *cp && *cp != '\n' ) ++cp;
        while( cp > path && *(cp-1) == '/' ) --cp;
        *cp++ = '/';  *cp = 0;