Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / filesystem.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef FILESYSTEM_H
23 #define FILESYSTEM_H
24
25 #include "arraylist.h"
26 #include "bcwindowbase.inc"
27 #include "sizes.h"
28
29 #if defined (__FreeBSD__) || (__NetBSD__)
30 #define dirent64 dirent
31 #define readdir64 readdir
32 #endif
33
34 class FileItem
35 {
36 public:
37         FileItem();
38         FileItem(const char *path, const char *name, int is_dir,
39                 int64_t size, time_t mtime, int item_no=-1);
40         ~FileItem();
41
42         int set_path(char *path);
43         int set_name(char *name);
44         int reset();
45
46         const char *get_path() { return path; }
47         const char *get_name() { return name; }
48         int get_is_dir() { return is_dir; }
49
50         char *path;
51         char *name;
52         int is_dir;
53         int64_t size;
54         time_t mtime;
55         int item_no;
56 };
57
58 class FileSystem
59 {
60 public:
61 // sets the working directory to the user
62         FileSystem();
63         virtual ~FileSystem();
64
65 // Load the new directory and change current_dir to it.
66 // This does not complete the dir path.
67 // If any of the files failed to stat, it returns nonzero.
68         int scan_directory(const char*);
69         int update(const char *new_dir = 0);
70         int update_sort();
71
72 // Complete the path in the string and change to the directory in the string.
73 // Does not change new_dir
74 // update - causes the directory to be loaded
75         int change_dir(const char *new_dir, int update = 1);
76 // Set the current_dir to something without completing the path.
77         int set_current_dir(const char *new_dir);
78
79         int move_up();
80 // Syntax of filter is
81 // single filter without [].
82 // multiple filters enclosed in [].
83         int set_filter(const char *new_filter);
84         int set_show_all();     // show hidden files
85         int set_want_directory();
86         int set_sort_order(int value);
87         int set_sort_field(int field);
88         int create_dir(const char *new_dir_);    // create a new directory
89         int complete_path(char *filename);   // use the filename and the current_dir to create a complete filename
90 // return 1 if the text is a directory
91         int is_dir(const char *new_dir_);
92         int extract_dir(char *out, const char *in);    // extract the directory from the path
93         int extract_name(char *out, const char *in, int test_dir = 1);  // extract the name from the path
94         int join_names(char *out, const char *dir_in, const char *name_in);    // combine a directory and filename
95         static int64_t get_date(const char *path);        // get the date of the filename modification
96         static void set_date(const char *path, int64_t value); // set the date of the file
97         static int64_t get_size(char *filename);        // Get the number of bytes in the file.
98         int add_end_slash(char *new_dir);
99
100         int parse_tildas(char *new_dir);     // expand tildas
101         int parse_directories(char *new_dir);  // add directories
102         int parse_dots(char *new_dir);         // move up directory tree after expanding tildas
103         static char *basepath(const char *path); // collapse ".", "..", "//" elements
104         static int test_filter(const char *url, const char *filter); // returns 0 if url matches filter
105
106 // Array of files and directories in the directory pointed to by current_dir.
107 // Directories are first.
108         ArrayList<FileItem*> dir_list;
109         char *get_current_dir() { return current_dir; }
110         FileItem* get_entry(int entry) { return dir_list.values[entry]; }
111         int total_files() { return dir_list.total; }
112         void alphabetize() { sort_table(&dir_list); }
113
114 // Sorting order and sorting field.  These are identical in BC_ListBox.
115         enum
116         {
117                 SORT_ASCENDING,
118                 SORT_DESCENDING
119         };
120
121 // Match column definitions in BC_FileBox.
122         enum
123         {
124                 SORT_PATH,
125                 SORT_SIZE,
126                 SORT_DATE,
127                 SORT_EXTENSION
128         };
129
130 private:
131         int sort_table(ArrayList<FileItem*> *dir_list);
132         static int path_ascending(const void *ptr1, const void *ptr2);
133         static int path_descending(const void *ptr1, const void *ptr2);
134         static int size_ascending(const void *ptr1, const void *ptr2);
135         static int size_descending(const void *ptr1, const void *ptr2);
136         static int date_ascending(const void *ptr1, const void *ptr2);
137         static int date_descending(const void *ptr1, const void *ptr2);
138         static int ext_ascending(const void *ptr1, const void *ptr2);
139         static int ext_descending(const void *ptr1, const void *ptr2);
140         static int dot_reverse_filename(char *out, const char *in);
141
142 // Combine the directories and files into the master list, directories first.
143         int combine(ArrayList<FileItem*> *dir_list, ArrayList<FileItem*> *file_list);
144 // Whether or not the file passes the current filter.
145         int test_filter(FileItem *file);
146         int reset_parameters();
147         int delete_directory();
148
149         char filter[BCTEXTLEN];     // what filenames have to end in to get displayed
150         int want_directory;
151         int show_all_files;       // shows . files
152         char current_dir[BCTEXTLEN];
153         int sort_order;
154         int sort_field;
155 };
156
157 #endif