prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / assets.C
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 #include "asset.h"
23 #include "assets.h"
24 #include "awindowgui.inc"
25 #include "batch.h"
26 #include "cache.h"
27 #include "bchash.h"
28 #include "edl.h"
29 #include "file.h"
30 #include "filexml.h"
31 #include "filesystem.h"
32 #include "indexfile.h"
33 #include "mainsession.h"
34 #include "threadindexer.h"
35 #include <string.h>
36
37 Assets::Assets(EDL *edl) : List<Asset>()
38 {
39         this->edl = edl;
40 }
41
42 Assets::~Assets()
43 {
44         delete_all();
45 }
46
47 int Assets::load(FileXML *file, uint32_t load_flags)
48 {
49         int result = 0;
50
51         while(!result)
52         {
53                 result = file->read_tag();
54                 if(!result)
55                 {
56                         if(file->tag.title_is("/ASSETS"))
57                         {
58                                 result = 1;
59                         }
60                         else
61                         if(file->tag.title_is("ASSET"))
62                         {
63                                 const char *path = file->tag.get_property("SRC");
64                                 if(path && path[0] != 0)
65                                 {
66                                         Asset *new_asset = new Asset(path);
67                                         new_asset->read(file);
68                                         Asset *asset = update(new_asset);
69                                         asset->copy_from(new_asset,1);
70                                         new_asset->Garbage::remove_user();
71                                 }
72                         }
73                 }
74         }
75         return 0;
76 }
77
78 int Assets::save(FileXML *file, char *path)
79 {
80         file->tag.set_title("ASSETS");
81         file->append_tag();
82         file->append_newline();
83
84         for(Asset* current = first; current; current = NEXT)
85         {
86                 current->write(file, 
87                         0, 
88                         path);
89         }
90
91         file->tag.set_title("/ASSETS");
92         file->append_tag();
93         file->append_newline(); 
94         file->append_newline(); 
95         return 0;
96 }
97
98 void Assets::copy_from(Assets *assets)
99 {
100         delete_all();
101
102         for(Asset *current = assets->first; current; current = NEXT)
103         {
104                 Asset *new_asset;
105                 append(new_asset = new Asset);
106                 new_asset->copy_from(current, 1);
107         }
108 }
109
110 Assets& Assets::operator=(Assets &assets)
111 {
112 printf("Assets::operator= 1\n");
113         copy_from(&assets);
114         return *this;
115 }
116
117
118 void Assets::update_index(Asset *asset)
119 {
120         if(!asset) return;
121         for(Asset* current = first; current; current = NEXT)
122         {
123                 if(current->test_path(asset->path))
124                 {
125                         current->update_index(asset);
126                 }
127         }
128 }
129
130 Asset* Assets::update(Asset *asset)
131 {
132         if(!asset) return 0;
133
134         for(Asset* current = first; current; current = NEXT)
135         {
136 // Asset already exists.
137                 if(current->test_path(asset->path)) 
138                 {
139                         return current;
140                 }
141         }
142
143 // Asset doesn't exist.
144         Asset *asset_copy = new Asset(*asset);
145         append(asset_copy);
146         return asset_copy;
147 }
148
149 int Assets::delete_all()
150 {
151         while(first) 
152         {
153                 remove_asset(first);
154         }
155         return 0;
156 }
157
158 Asset* Assets::update(const char *path)
159 {
160         Asset* current = first;
161
162         while(current)
163         {
164                 if(current->test_path(path)) 
165                 {
166                         return current;
167                 }
168                 current = NEXT;
169         }
170
171         return append(new Asset(path));
172 }
173
174 Asset* Assets::get_asset(const char *filename)
175 {
176         Asset* current = first;
177         Asset* result = 0;
178
179         while(current)
180         {
181 //printf("Assets::get_asset %p %s\n", filename, filename);
182                 if(current->test_path(filename))
183                 {
184                         result = current;
185                         break;
186                 }
187                 current = current->next;
188         }
189
190         return result;  
191 }
192
193 void Assets::remove_asset(Asset *asset)
194 {
195         remove_pointer(asset);
196         asset->Garbage::remove_user();
197 }
198
199
200 int Assets::number_of(Asset *asset)
201 {
202         int i;
203         Asset *current;
204
205         for(i = 0, current = first; current && current != asset; i++, current = NEXT)
206                 ;
207
208         return i;
209 }
210
211 Asset* Assets::asset_number(int number)
212 {
213         int i;
214         Asset *current;
215
216         for(i = 0, current = first; i < number && current; i++, current = NEXT)
217                 ;
218         
219         return current;
220 }
221
222 int Assets::update_old_filename(char *old_filename, char *new_filename)
223 {
224         for(Asset* current = first; current; current = NEXT)
225         {
226                 if(!strcmp(current->path, old_filename))
227                 {
228                         current->update_path(new_filename);
229                 }
230         }
231         return 0;
232 }
233
234
235 int Assets::dump(FILE *fp)
236 {
237         for(Asset *current = first; current; current = NEXT)
238         {
239                 current->dump(fp);
240         }
241         return 0;
242 }
243
244