file size 3dgts+sfx, timebar tweak, mask msg
[goodguy/history.git] / cinelerra-5.1 / guicast / bcfilebox.C
index 21898b87a02694a91ce7917ff92de4bf710e9780..03a49e9a9161c3968e3919d7660ce597c567d0d5 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
  * CINELERRA
 
 /*
  * 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
  *
  * 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
@@ -128,7 +128,7 @@ int BC_FileBoxListBox::sort_order_event()
 {
        get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
        get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
 {
        get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
        get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
-       filebox->refresh();
+       filebox->refresh(-1);
        return 1;
 }
 
        return 1;
 }
 
@@ -215,7 +215,7 @@ int BC_FileBoxDirectoryText::handle_event()
        while( *cp ) ++cp;
        if( cp > path && *--cp != '/' ) return 0;
        char *file_path = FileSystem::basepath(path);
        while( *cp ) ++cp;
        if( cp > path && *--cp != '/' ) return 0;
        char *file_path = FileSystem::basepath(path);
-       char *dir_path = FileSystem::basepath(filebox->fs->get_current_dir());
+       char *dir_path = FileSystem::basepath(filebox->directory);
        int ret = !strcmp(file_path, dir_path) ? 0 : 1;
        if( ret ) {
                strcpy(filebox->directory, file_path);
        int ret = !strcmp(file_path, dir_path) ? 0 : 1;
        if( ret ) {
                strcpy(filebox->directory, file_path);
@@ -497,7 +497,7 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
        this->want_directory = want_directory;
        if(show_all_files) fs->set_show_all();
        fs->complete_path(this->current_path);
        this->want_directory = want_directory;
        if(show_all_files) fs->set_show_all();
        fs->complete_path(this->current_path);
-       fs->complete_path(this->submitted_path);
+       strcpy(this->submitted_path, this->current_path);
        fs->extract_dir(directory, this->current_path);
        fs->extract_name(filename, this->current_path);
 
        fs->extract_dir(directory, this->current_path);
        fs->extract_name(filename, this->current_path);
 
@@ -535,16 +535,12 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
 // Test if current directory exists
        if(!fs->is_dir(directory))
        {
 // Test if current directory exists
        if(!fs->is_dir(directory))
        {
-               sprintf(this->current_path, "~");
-               fs->complete_path(this->current_path);
-               fs->set_current_dir(this->current_path);
-//             fs->update(this->current_path);
-               strcpy(directory, fs->get_current_dir());
+               sprintf(directory, "~");
+               fs->complete_path(directory);
+               strcpy(current_path,directory);
                filename[0] = 0;
        }
                filename[0] = 0;
        }
-       else
-               fs->set_current_dir(this->directory);
-
+       fs->set_current_dir(directory);
 
        if(h_padding == -1)
        {
 
        if(h_padding == -1)
        {
@@ -580,22 +576,18 @@ void BC_FileBox::create_objects()
        int directory_title_margin = MAX(20,
                resources->filebox_text_images[0]->get_h());
 
        int directory_title_margin = MAX(20,
                resources->filebox_text_images[0]->get_h());
 
-// Create recent dir list
-       create_history();
-
 // Directories aren't filtered in FileSystem so skip this
        if(!want_directory)
        {
                filter_list.append(new BC_ListBoxItem("*"));
 // Directories aren't filtered in FileSystem so skip this
        if(!want_directory)
        {
                filter_list.append(new BC_ListBoxItem("*"));
-               filter_list.append(new BC_ListBoxItem("[*.ifo][*.vob]"));
+               filter_list.append(new BC_ListBoxItem("[*.mkv]"));
+               filter_list.append(new BC_ListBoxItem("[*.mp4]"));
                filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
                filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
                filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
                filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
-               filter_list.append(new BC_ListBoxItem("heroine*"));
                filter_list.append(new BC_ListBoxItem("*.xml"));
                fs->set_filter(get_resources()->filebox_filter);
        }
 
                filter_list.append(new BC_ListBoxItem("*.xml"));
                fs->set_filter(get_resources()->filebox_filter);
        }
 
-//     fs->update(directory);
        create_icons();
        create_tables();
 
        create_icons();
        create_tables();
 
@@ -633,11 +625,9 @@ void BC_FileBox::create_objects()
 
        add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y));
        add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
 
        add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y));
        add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
-       directory_title->reposition_window(x, y,
-               get_w() - recent_popup->get_w() -  20, 1);
-       recent_popup->reposition_window(
-               x + directory_title->get_w(), y,
-               directory_title->get_w(), 200);
+       directory_title->reposition_window(x, y, get_w() - recent_popup->get_w() -  20, 1);
+       x += directory_title->get_w() + 8;
+       recent_popup->reposition_window(x, y, directory_title->get_w(), 200);
 
        x = 10;
        y += directory_title->get_h() + 5;
 
        x = 10;
        y += directory_title->get_h() + 5;
@@ -653,8 +643,16 @@ void BC_FileBox::create_objects()
        if( newest >= 0 ) {
                strcpy(directory, resources->filebox_history[newest].path);
                fs->change_dir(directory, 0);
        if( newest >= 0 ) {
                strcpy(directory, resources->filebox_history[newest].path);
                fs->change_dir(directory, 0);
+               strcpy(directory, fs->get_current_dir());
                directory_title->update(fs->get_current_dir());
        }
                directory_title->update(fs->get_current_dir());
        }
+       fs->set_sort_order(sort_order);
+       fs->set_sort_field(column_type[sort_column]);
+       fs->update(directory);
+
+// Create recent dir list
+       create_history();
+       update_history();
 
        listbox = 0;
        create_listbox(x, y, get_display_mode());
 
        listbox = 0;
        create_listbox(x, y, get_display_mode());
@@ -674,7 +672,7 @@ void BC_FileBox::create_objects()
 
        rename_thread = new BC_RenameThread(this);
 
 
        rename_thread = new BC_RenameThread(this);
 
-
+       refresh();
        show_window();
 }
 
        show_window();
 }
 
@@ -685,9 +683,7 @@ int BC_FileBox::get_listbox_w()
 
 int BC_FileBox::get_listbox_h(int y)
 {
 
 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
        if(want_directory)
                result -= BC_WindowBase::get_resources()->dirbox_margin;
        else
@@ -738,7 +734,7 @@ int BC_FileBox::resize_event(int w, int h)
                get_w() - recent_popup->get_w() -  20,
                1);
        recent_popup->reposition_window(
                get_w() - recent_popup->get_w() -  20,
                1);
        recent_popup->reposition_window(
-               directory_title->get_x() + directory_title->get_w(),
+               directory_title->get_x() + directory_title->get_w() + 8,
                directory_title->get_y(),
                directory_title->get_w() + recent_popup->get_w(),
                recent_popup->get_h());
                directory_title->get_y(),
                directory_title->get_w() + recent_popup->get_w(),
                recent_popup->get_h());
@@ -751,22 +747,15 @@ int BC_FileBox::resize_event(int w, int h)
                w - (get_w() - listbox->get_w()),
                h - (get_h() - listbox->get_h()),
                0);
                w - (get_w() - listbox->get_w()),
                h - (get_h() - listbox->get_h()),
                0);
-       icon_button->reposition_window(w - (get_w() - icon_button->get_x()),
-               icon_button->get_y());
-       text_button->reposition_window(w - (get_w() - text_button->get_x()),
-               text_button->get_y());
-       folder_button->reposition_window(w - (get_w() - folder_button->get_x()),
-               folder_button->get_y());
-       rename_button->reposition_window(w - (get_w() - rename_button->get_x()),
-               rename_button->get_y());
-       reload_button->reposition_window(w - (get_w() - reload_button->get_x()),
-               reload_button->get_y());
-       delete_button->reposition_window(w - (get_w() - delete_button->get_x()),
-               delete_button->get_y());
-       updir_button->reposition_window(w - (get_w() - updir_button->get_x()),
-               updir_button->get_y());
-       set_w(w);
-       set_h(h);
+       int dx = w - get_w();
+       icon_button->reposition_window(icon_button->get_x()+dx, icon_button->get_y());
+       text_button->reposition_window(text_button->get_x()+dx, text_button->get_y());
+       folder_button->reposition_window(folder_button->get_x()+dx, folder_button->get_y());
+       rename_button->reposition_window(rename_button->get_x()+dx, rename_button->get_y());
+       reload_button->reposition_window(reload_button->get_x()+dx, reload_button->get_y());
+       delete_button->reposition_window(delete_button->get_x()+dx, delete_button->get_y());
+       updir_button->reposition_window(updir_button->get_x()+dx, updir_button->get_y());
+       set_w(w);  set_h(h);
        get_resources()->filebox_w = get_w();
        get_resources()->filebox_h = get_h();
        flush();
        get_resources()->filebox_w = get_w();
        get_resources()->filebox_h = get_h();
        flush();
@@ -805,6 +794,13 @@ int BC_FileBox::extract_extension(char *out, const char *in)
        return 0;
 }
 
        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();
 int BC_FileBox::create_tables()
 {
        delete_tables();
@@ -814,8 +810,6 @@ int BC_FileBox::create_tables()
        fs->set_sort_order(sort_order);
        fs->set_sort_field(column_type[sort_column]);
 
        fs->set_sort_order(sort_order);
        fs->set_sort_field(column_type[sort_column]);
 
-// Directory is entered before this from a random source
-       fs->update(0);
        for(int i = 0; i < fs->total_files(); i++)
        {
                FileItem *file_item = fs->get_entry(i);
        for(int i = 0; i < fs->total_files(); i++)
        {
                FileItem *file_item = fs->get_entry(i);
@@ -834,7 +828,27 @@ int BC_FileBox::create_tables()
 //             {
                        if(!is_dir)
                        {
 //             {
                        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
                                new_item = new BC_ListBoxItem(string, get_resources()->file_color);
                        }
                        else
@@ -848,15 +862,11 @@ int BC_FileBox::create_tables()
 // Date entry
                if(!is_dir || 1)
                {
 // 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
                        new_item = new BC_ListBoxItem(string, get_resources()->file_color);
                }
                else
@@ -894,25 +904,13 @@ int BC_FileBox::delete_tables()
 
 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
 {
 
 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;
        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];
        }
 
        return icons[icon_type];
@@ -920,20 +918,11 @@ BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
 
 const char* BC_FileBox::columntype_to_text(int type)
 {
 
 const char* BC_FileBox::columntype_to_text(int type)
 {
-       switch(type)
-       {
-               case FILEBOX_NAME:
-                       return FILEBOX_NAME_TEXT;
-                       break;
-               case FILEBOX_SIZE:
-                       return FILEBOX_SIZE_TEXT;
-                       break;
-               case FILEBOX_DATE:
-                       return FILEBOX_DATE_TEXT;
-                       break;
-               case FILEBOX_EXTENSION:
-                       return FILEBOX_EXTENSION_TEXT;
-                       break;
+       switch(type) {
+               case FILEBOX_NAME: return FILEBOX_NAME_TEXT;
+               case FILEBOX_SIZE: return FILEBOX_SIZE_TEXT;
+               case FILEBOX_DATE: return FILEBOX_DATE_TEXT;
+               case FILEBOX_EXTENSION: return FILEBOX_EXTENSION_TEXT;
        }
        return "";
 }
        }
        return "";
 }
@@ -947,13 +936,19 @@ int BC_FileBox::column_of_type(int type)
 
 
 
 
 
 
-int BC_FileBox::refresh(int zscroll)
+int BC_FileBox::refresh(int reset)
 {
 {
+       fs->set_sort_order(sort_order);
+       fs->set_sort_field(column_type[sort_column]);
+       if( reset >= 0 )
+               fs->update(0);
+       else
+               fs->update_sort();
        create_tables();
        listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
        listbox->update(list_column, column_titles, column_width, columns,
        create_tables();
        listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
        listbox->update(list_column, column_titles, column_width, columns,
-               !zscroll ? listbox->get_xposition() : 0,
-               !zscroll ? listbox->get_yposition() : 0,
+               reset>0 ? 0 : listbox->get_xposition(),
+               reset>0 ? 0 : listbox->get_yposition(),
                -1, 1);
        return 0;
 }
                -1, 1);
        return 0;
 }
@@ -973,7 +968,6 @@ void BC_FileBox::move_column(int src, int dst)
 {
        if(src != dst)
        {
 {
        if(src != dst)
        {
-
                ArrayList<BC_ListBoxItem*> *new_columns =
                        new ArrayList<BC_ListBoxItem*>[columns];
                int *new_types = new int[columns];
                ArrayList<BC_ListBoxItem*> *new_columns =
                        new ArrayList<BC_ListBoxItem*>[columns];
                int *new_types = new int[columns];
@@ -1053,12 +1047,17 @@ int BC_FileBox::submit_dir(char *dir)
 
 int BC_FileBox::submit_file(const char *path, int use_this)
 {
 
 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.
 // 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);
        {
 // save complete path
                strcpy(this->current_path, directory);
@@ -1072,9 +1071,9 @@ int BC_FileBox::submit_file(const char *path, int use_this)
        }
 
 // is a directory, change directories
        }
 
 // 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());
                refresh(1);
                directory_title->update(fs->get_current_dir());
                strcpy(this->current_path, fs->get_current_dir());
@@ -1093,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];
 // 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);
 
 // save directory for defaults
                fs->extract_dir(directory, path2);
@@ -1129,7 +1128,7 @@ void BC_FileBox::update_history()
        strcpy(path, directory);
 // enfore one trailing slash
        char *cp = path;
        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;
 
        while( cp > path && *(cp-1) == '/' ) --cp;
        *cp++ = '/';  *cp = 0;