rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / 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(const 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         const char *filter3 = ".mkr";
72
73 //      pwindow->disable_window();
74         sprintf(string, _("Delete all indexes in %s?"), string1);
75 //      QuestionWindow confirm(mwindow);
76 //      confirm.create_objects(string, 0);
77
78 //      int result = confirm.run_window();
79
80         int result = 0;
81         if(!result)
82         {
83                 for(int i = 0; i < dir.dir_list.total; i++)
84                 {
85                         result = 1;
86                         sprintf(string2, "%s%s", string1, dir.dir_list.values[i]->name);
87 // test filter
88                         if(test_filter(string2, filter1) ||
89                                 test_filter(string2, filter2) ||
90                                 test_filter(string2, filter3))
91                         {
92                                 remove(string2);
93 printf("DeleteAllIndexes::run %s\n", string2);
94                         }
95                 }
96         }
97
98         pwindow->thread->redraw_indexes = 1;
99 //      pwindow->enable_window();
100 }
101
102
103 ConfirmDeleteAllIndexes::ConfirmDeleteAllIndexes(MWindow *mwindow, char *string)
104  : BC_Window(_(PROGRAM_NAME ": Delete All Indexes"),
105                 mwindow->gui->get_abs_cursor_x(1),
106                 mwindow->gui->get_abs_cursor_y(1),
107                 340,
108                 140)
109 {
110         this->string = string;
111 }
112
113 ConfirmDeleteAllIndexes::~ConfirmDeleteAllIndexes()
114 {
115 }
116
117 void ConfirmDeleteAllIndexes::create_objects()
118 {
119         int x = 10, y = 10;
120         add_subwindow(new BC_Title(x, y, string));
121
122         y += 20;
123         add_subwindow(new BC_OKButton(x, y));
124         x = get_w() - 100;
125         add_subwindow(new BC_CancelButton(x, y));
126 }
127
128