initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / deleteallindexes.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 "deleteallindexes.h"
23 #include "filesystem.h"
24 #include "mwindow.h"
25 #include "mwindowgui.h"
26 #include "preferences.h"
27 #include "preferencesthread.h"
28 #include "question.h"
29 #include "theme.h"
30 #include <string.h>
31
32 #include <libintl.h>
33 #define _(String) gettext(String)
34 #define gettext_noop(String) String
35 #define N_(String) gettext_noop (String)
36
37 DeleteAllIndexes::DeleteAllIndexes(MWindow *mwindow, PreferencesWindow *pwindow, int x, int y)
38  : BC_GenericButton(x, y, _("Delete existing indexes")), Thread()
39 {
40         this->mwindow = mwindow;
41         this->pwindow = pwindow;
42 }
43
44 DeleteAllIndexes::~DeleteAllIndexes() 
45 {
46 }
47
48 int DeleteAllIndexes::handle_event() 
49
50         start(); 
51         return 1;
52 }
53
54 static int test_filter(char *string, const char *filter)
55 {
56         return (strlen(string) > strlen(filter) &&
57                         !strcmp(string + strlen(string) - strlen(filter), filter));
58 }
59
60 void DeleteAllIndexes::run()
61 {
62         char string[BCTEXTLEN], string1[BCTEXTLEN], string2[BCTEXTLEN];
63 // prepare directory
64         strcpy(string1, pwindow->thread->preferences->index_directory);
65         FileSystem dir;
66         dir.update(pwindow->thread->preferences->index_directory);
67         dir.complete_path(string1);
68 // prepare filter
69         const char *filter1 = ".idx";
70         const char *filter2 = ".toc";
71
72 //      pwindow->disable_window();
73         sprintf(string, _("Delete all indexes in %s?"), string1);
74 //      QuestionWindow confirm(mwindow);
75 //      confirm.create_objects(string, 0);
76
77 //      int result = confirm.run_window();
78
79         int result = 0;
80         if(!result)
81         {
82                 for(int i = 0; i < dir.dir_list.total; i++)
83                 {
84                         result = 1;
85                         sprintf(string2, "%s%s", string1, dir.dir_list.values[i]->name);
86 // test filter
87                         if(test_filter(string2, filter1) ||
88                                 test_filter(string2, filter2))
89                         {
90                                 remove(string2);
91 printf("DeleteAllIndexes::run %s\n", string2);
92                         }
93                 }
94         }
95
96         pwindow->thread->redraw_indexes = 1;
97 //      pwindow->enable_window();
98 }
99
100
101 ConfirmDeleteAllIndexes::ConfirmDeleteAllIndexes(MWindow *mwindow, char *string)
102  : BC_Window(PROGRAM_NAME ": Delete All Indexes", 
103                 mwindow->gui->get_abs_cursor_x(1), 
104                 mwindow->gui->get_abs_cursor_y(1), 
105                 340, 
106                 140)
107
108         this->string = string; 
109 }
110
111 ConfirmDeleteAllIndexes::~ConfirmDeleteAllIndexes()
112 {
113 }
114         
115 void ConfirmDeleteAllIndexes::create_objects()
116
117         int x = 10, y = 10;
118         add_subwindow(new BC_Title(x, y, string));
119         
120         y += 20;
121         add_subwindow(new BC_OKButton(x, y));
122         x = get_w() - 100;
123         add_subwindow(new BC_CancelButton(x, y));
124 }