00001 #include "deleteallindexes.h"
00002 #include "filesystem.h"
00003 #include "mwindow.h"
00004 #include "mwindowgui.h"
00005 #include "preferences.h"
00006 #include "preferencesthread.h"
00007 #include "question.h"
00008 #include "theme.h"
00009 #include <string.h>
00010
00011 #include <libintl.h>
00012 #define _(String) gettext(String)
00013 #define gettext_noop(String) String
00014 #define N_(String) gettext_noop (String)
00015
00016 DeleteAllIndexes::DeleteAllIndexes(MWindow *mwindow, PreferencesWindow *pwindow, int x, int y)
00017 : BC_GenericButton(x, y, _("Delete existing indexes")), Thread()
00018 {
00019 this->mwindow = mwindow;
00020 this->pwindow = pwindow;
00021 }
00022
00023 DeleteAllIndexes::~DeleteAllIndexes()
00024 {
00025 }
00026
00027 int DeleteAllIndexes::handle_event()
00028 {
00029 start();
00030 }
00031
00032 static int test_filter(char *string, char *filter)
00033 {
00034 return (strlen(string) > strlen(filter) &&
00035 !strcmp(string + strlen(string) - strlen(filter), filter));
00036 }
00037
00038 void DeleteAllIndexes::run()
00039 {
00040 char string[BCTEXTLEN], string1[BCTEXTLEN], string2[BCTEXTLEN];
00041
00042 strcpy(string1, pwindow->thread->preferences->index_directory);
00043 FileSystem dir;
00044 dir.update(pwindow->thread->preferences->index_directory);
00045 dir.complete_path(string1);
00046
00047 char *filter1 = ".idx";
00048 char *filter2 = ".toc";
00049
00050
00051 sprintf(string, _("Delete all indexes in %s?"), string1);
00052
00053
00054
00055
00056
00057 int result = 0;
00058 if(!result)
00059 {
00060 static int i, j, k;
00061
00062 for(i = 0; i < dir.dir_list.total; i++)
00063 {
00064 result = 1;
00065 sprintf(string2, "%s%s", string1, dir.dir_list.values[i]->name);
00066
00067 if(test_filter(string2, filter1) ||
00068 test_filter(string2, filter2))
00069 {
00070 remove(string2);
00071 printf("DeleteAllIndexes::run %s\n", string2);
00072 }
00073 }
00074 }
00075
00076 pwindow->thread->redraw_indexes = 1;
00077
00078 }
00079
00080
00081 ConfirmDeleteAllIndexes::ConfirmDeleteAllIndexes(MWindow *mwindow, char *string)
00082 : BC_Window(PROGRAM_NAME ": Delete All Indexes",
00083 mwindow->gui->get_abs_cursor_x(1),
00084 mwindow->gui->get_abs_cursor_y(1),
00085 340,
00086 140)
00087 {
00088 this->string = string;
00089 }
00090
00091 ConfirmDeleteAllIndexes::~ConfirmDeleteAllIndexes()
00092 {
00093 }
00094
00095 int ConfirmDeleteAllIndexes::create_objects()
00096 {
00097 int x = 10, y = 10;
00098 add_subwindow(new BC_Title(x, y, string));
00099
00100 y += 20;
00101 add_subwindow(new BC_OKButton(x, y));
00102 x = get_w() - 100;
00103 add_subwindow(new BC_CancelButton(x, y));
00104 return 0;
00105 }