From 1b10d02f5c4d1a8231ec7b5625a527a82b1e95af Mon Sep 17 00:00:00 2001 From: Harbour Date: Mon, 17 Dec 2007 22:02:12 +0200 Subject: [PATCH] Remove/Unsort slices and files --- docs/ru/TODO | 3 +- faraon/x11_ui.C | 47 ++++++++++++++++++++++++---- faraon/x11_ui.fl | 54 +++++++++++++++++++++++++------- include/elements.H | 3 ++ include/proto.H | 9 ++++-- include/sfinx.H | 4 +-- sfinx/sfinx.C | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 7 files changed, 181 insertions(+), 31 deletions(-) diff --git a/docs/ru/TODO b/docs/ru/TODO index 2327f3e..85a911d 100644 --- a/docs/ru/TODO +++ b/docs/ru/TODO @@ -49,11 +49,10 @@ - ÁÕÔÅÎÔÉÆÉËÁÃÉÑ -------------------------------------------------------- - ÍÏÄÕÌØ ÓÌÁÊÓÏ× : - - ÕÄÁÌÅÎÉÅ/ÐÅÒÅÍÅÝÅÎÉÅ ÏÂØÅËÔÏ× × unsorted location -------------------------------------------------------- - ÍÏÄÕÌØ ÆÁÊÌÏ× : - - ÕÄÁÌÅÎÉÅ/ÐÅÒÅÍÅÛÅÎÉÅ × unsorted location - ÄÏÄÅÌÁÔØ ÒÅÄÁËÔÉÒÏ×ÁÎÉÅ ÆÁÊÌÁ + - ÇÅÎÅÒÁÃÉÑ desc-ÆÁÊÌÏ× - ÐÏÄÄÅÒÖËÁ ÄÉÒÅËÔÏÒÉÊ - encrypt feature - ÆÌÁÇ store_in_dir diff --git a/faraon/x11_ui.C b/faraon/x11_ui.C index a777525..927602e 100644 --- a/faraon/x11_ui.C +++ b/faraon/x11_ui.C @@ -534,8 +534,8 @@ static void cb_classify_file_b(Fl_Button*, void*) { if (!n) return; sfinx_file_t *file = ((sfinx_files_vector_t *)files_module_tree_br->user_data())->files[n - 1]; -debug("slice_id - %d, parent_id - %d, name - %s", current_files_module_tree_path.file_id, current_files_module_tree_path.main_slice_id, - file->name.c_str()); +//debug("slice_id - %d, parent_id - %d, name - %s", current_files_module_tree_path.file_id, current_files_module_tree_path.main_slice_id, +// file->name.c_str()); string path; if (current_files_module_tree_path.id() == SFINX_FILES_MODULE_UNSORTED_TREE_REQUEST) app->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, path); @@ -547,8 +547,8 @@ file->etime.GetDate(eyear, emonth, eday); file->etime.GetTime(ehour, emin, esec); file->ctime.GetDate(cyear, cmonth, cday); file->ctime.GetTime(chour, cmin, csec); -sprintf(buf, "%llu bytes | Modified: %02d/%02d/%02d %02d:%02d:%02d | Last Status Changed: %02d/%02d/%02d %02d:%02d:%02d", file->fsize, cyear, - cmonth, cday, chour, cmin, csec, eyear, emonth, eday, ehour, emin, esec); +sprintf(buf, "%llu bytes | Modified: %02d/%02d/%04d %02d:%02d:%02d | Last Status Changed: %02d/%02d/%04d %02d:%02d:%02d", file->fsize, cday, cmonth, + cyear, chour, cmin, csec, eday, emonth, eyear, ehour, emin, esec); string t = "URL: " + path + current_files_module_tree_path.name + "/" + file->name + " | " + file->mimetype + " | Size: " + buf; classify_file_to->value(t.c_str()); file_title_i->value(0); @@ -604,6 +604,40 @@ if (tree->files[n - 1]->is_directory) { // }; } +static void cb_Delete2(Fl_Button*, void*) { + int n = files_module_tree_br->value(); +if (!n) + return; +sfinx_file_t *file = ((sfinx_files_vector_t *)files_module_tree_br->user_data())->files[n - 1]; +string path; +if (current_files_module_tree_path.id() == SFINX_FILES_MODULE_UNSORTED_TREE_REQUEST) { + // sure ? + string message = "Deleting \'" + file->name + "\'. Are you sure ?"; + if (fl_choice(message.c_str(), "Yes", "No", 0L)) + return; + app->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, path); + path += "/" + file->name; + sfinx_string_t f(SFINX_FILES_MODULE_UNLINK); + f.set(path); + app->sfinx.send(f); +} else { + // sorted can be marked unsorted or deleted + string message = "Delete or Unsort \'" + file->name + "\' ?"; + int res = fl_choice(message.c_str(), "Cancel", "Unsort", "Delete"); + if (!res) + return; + if (res == 2) { // delete + file->id(SFINX_FILES_MODULE_SORTED_UNLINK); + app->sfinx.send(file); + } else { + file->id(SFINX_FILES_MODULE_UNSORT); + app->sfinx.send(file); + } +} +//files_module_tree_br->remove(n); +app->sfinx.send(current_files_module_tree_path); +} + Fl_Button *select_files_tree_b=(Fl_Button *)0; static void cb_select_files_tree_b(Fl_Button*, void*) { @@ -2723,6 +2757,7 @@ void x11_ui::init() { } // Fl_Browser* files_module_tree_br { Fl_Button* o = new Fl_Button(300, 312, 112, 25, gettext("Delete")); o->labeltype(FL_ENGRAVED_LABEL); + o->callback((Fl_Callback*)cb_Delete2); } // Fl_Button* o { select_files_tree_b = new Fl_Button(562, 10, 128, 25, gettext("Sorted tree")); select_files_tree_b->labeltype(FL_ENGRAVED_LABEL); @@ -3177,8 +3212,8 @@ void x11_ui::files_module_classify_reply(sfinx_string_t *classify_error) { Fl::lock(); if (classify_error->size() == 1) { classify_file_w->hide(); - // app->sfinx.send(current_files_module_tree_path); - files_module_tree_br->remove(files_module_tree_br->value()); + app->sfinx.send(current_files_module_tree_path); + // files_module_tree_br->remove(files_module_tree_br->value()); } else fl_alert(classify_error->c_str()); Fl::unlock(); diff --git a/faraon/x11_ui.fl b/faraon/x11_ui.fl index 532a85e..d529fbc 100644 --- a/faraon/x11_ui.fl +++ b/faraon/x11_ui.fl @@ -148,7 +148,7 @@ Function {x11_ui::init()} {open private return_type void label Faraon callback {if (fl_choice("Really quit ?", "No", "Yes", 0L)) F::shutdown(0);} open - xywh {132 109 941 367} type Double hide + xywh {34 45 941 367} type Double hide } { Fl_Menu_Bar {} { xywh {0 0 940 22} @@ -718,7 +718,7 @@ app->sfinx.send(SFINX_SLICES_MODULE_TREE_REQUEST, (u8_t)0);} } Fl_Window files_module_w { label {Files Module} - xywh {41 39 733 370} type Double color 31 hide resizable + xywh {150 105 733 370} type Double color 31 resizable visible } { Fl_Button {} { label Cancel @@ -734,8 +734,8 @@ app->sfinx.send(SFINX_SLICES_MODULE_TREE_REQUEST, (u8_t)0);} if (!n) return; sfinx_file_t *file = ((sfinx_files_vector_t *)files_module_tree_br->user_data())->files[n - 1]; -debug("slice_id - %d, parent_id - %d, name - %s", current_files_module_tree_path.file_id, current_files_module_tree_path.main_slice_id, - file->name.c_str()); +//debug("slice_id - %d, parent_id - %d, name - %s", current_files_module_tree_path.file_id, current_files_module_tree_path.main_slice_id, +// file->name.c_str()); string path; if (current_files_module_tree_path.id() == SFINX_FILES_MODULE_UNSORTED_TREE_REQUEST) app->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, path); @@ -747,8 +747,8 @@ file->etime.GetDate(eyear, emonth, eday); file->etime.GetTime(ehour, emin, esec); file->ctime.GetDate(cyear, cmonth, cday); file->ctime.GetTime(chour, cmin, csec); -sprintf(buf, "%llu bytes | Modified: %02d/%02d/%02d %02d:%02d:%02d | Last Status Changed: %02d/%02d/%02d %02d:%02d:%02d", file->fsize, cyear, - cmonth, cday, chour, cmin, csec, eyear, emonth, eday, ehour, emin, esec); +sprintf(buf, "%llu bytes | Modified: %02d/%02d/%04d %02d:%02d:%02d | Last Status Changed: %02d/%02d/%04d %02d:%02d:%02d", file->fsize, cday, cmonth, + cyear, chour, cmin, csec, eday, emonth, eyear, ehour, emin, esec); string t = "URL: " + path + current_files_module_tree_path.name + "/" + file->name + " | " + file->mimetype + " | Size: " + buf; classify_file_to->value(t.c_str()); file_title_i->value(0); @@ -810,6 +810,37 @@ if (tree->files[n - 1]->is_directory) { // } Fl_Button {} { label Delete + callback {int n = files_module_tree_br->value(); +if (!n) + return; +sfinx_file_t *file = ((sfinx_files_vector_t *)files_module_tree_br->user_data())->files[n - 1]; +string path; +if (current_files_module_tree_path.id() == SFINX_FILES_MODULE_UNSORTED_TREE_REQUEST) { + // sure ? + string message = "Deleting \\'" + file->name + "\\'. Are you sure ?"; + if (fl_choice(message.c_str(), "Yes", "No", 0L)) + return; + app->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, path); + path += "/" + file->name; + sfinx_string_t f(SFINX_FILES_MODULE_UNLINK); + f.set(path); + app->sfinx.send(f); +} else { + // sorted can be marked unsorted or deleted + string message = "Delete or Unsort \\'" + file->name + "\\' ?"; + int res = fl_choice(message.c_str(), "Cancel", "Unsort", "Delete"); + if (!res) + return; + if (res == 2) { // delete + file->id(SFINX_FILES_MODULE_SORTED_UNLINK); + app->sfinx.send(file); + } else { + file->id(SFINX_FILES_MODULE_UNSORT); + app->sfinx.send(file); + } +} +//files_module_tree_br->remove(n); +app->sfinx.send(current_files_module_tree_path);} selected xywh {300 312 112 25} labeltype ENGRAVED_LABEL } Fl_Button select_files_tree_b { @@ -867,7 +898,7 @@ app->sfinx.send(current_files_module_tree_path);} } Fl_Window classify_file_w { label {Classify File} - xywh {84 374 1022 518} type Double color 31 hide modal + xywh {76 244 1022 518} type Double color 31 hide modal } { Fl_Button {} { label Cancel @@ -1297,8 +1328,8 @@ Function {x11_ui::files_module_classify_reply(sfinx_string_t *classify_error)} { code {Fl::lock(); if (classify_error->size() == 1) { classify_file_w->hide(); - // app->sfinx.send(current_files_module_tree_path); - files_module_tree_br->remove(files_module_tree_br->value()); + app->sfinx.send(current_files_module_tree_path); + // files_module_tree_br->remove(files_module_tree_br->value()); } else fl_alert(classify_error->c_str()); Fl::unlock();} {} @@ -1337,7 +1368,7 @@ if (alert->size() != 1) Fl::unlock();} {} } -Function {x11_ui::files_module_edit(sfinx_file_t *f)} {open private return_type void +Function {x11_ui::files_module_edit(sfinx_file_t *f)} {private return_type void } { code {Fl::lock(); static sfinx_file_t file; @@ -1378,8 +1409,7 @@ for (u32_t i = 0; i < file.slices.size(); i++) file_additional_slices_br->add((app->slice_name(file.slices[i]).c_str()), (void *)file.slices[i]); classify_file_w->user_data((void *)&file); classify_file_w->show(); -Fl::unlock();} {selected - } +Fl::unlock();} {} } Function {x11_ui::files_module_edit_reply(sfinx_string_t *classify_error)} {private return_type void diff --git a/include/elements.H b/include/elements.H index c7b9bd3..5979254 100644 --- a/include/elements.H +++ b/include/elements.H @@ -1083,6 +1083,7 @@ static sfinx_t *make_sfinx_element(u32_t id) case SFINX_ALERT: case SFINX_FILES_MODULE_CLASSIFY_REPLY: case SFINX_FILES_MODULE_EDIT_REPLY: + case SFINX_FILES_MODULE_UNLINK: return new sfinx_string_t(id); case SFINX_ELEMENT_FILE_VECTOR: case SFINX_FILES_MODULE_SORTED_TREE: @@ -1096,6 +1097,8 @@ static sfinx_t *make_sfinx_element(u32_t id) case SFINX_FILES_MODULE_UNSORTED_TREE_REQUEST: case SFINX_FILES_MODULE_EDIT_FILE_REQUEST: case SFINX_FILES_MODULE_EDIT_FILE: + case SFINX_FILES_MODULE_SORTED_UNLINK: + case SFINX_FILES_MODULE_UNSORT: return new sfinx_file_t(id); case SFINX_ELEMENT_SEARCH_QUERY: return new sfinx_search_query_t(id); diff --git a/include/proto.H b/include/proto.H index 6549907..289dd9c 100644 --- a/include/proto.H +++ b/include/proto.H @@ -115,9 +115,12 @@ #define SFINX_FILES_MODULE_EDIT_FILE_REQUEST 0x217 #define SFINX_FILES_MODULE_EDIT_FILE 0x218 #define SFINX_FILES_MODULE_EDIT_REPLY 0x219 -#define SFINX_ALERT 0x220 -#define SFINX_SEARCH_QUERY 0x221 -#define SFINX_SEARCH_RESULT 0x222 +#define SFINX_FILES_MODULE_UNLINK 0x220 +#define SFINX_FILES_MODULE_SORTED_UNLINK 0x221 +#define SFINX_FILES_MODULE_UNSORT 0x222 +#define SFINX_ALERT 0x223 +#define SFINX_SEARCH_QUERY 0x224 +#define SFINX_SEARCH_RESULT 0x225 #define SFINX_KEY_UNASSIGNED 0 // files module conf keys diff --git a/include/sfinx.H b/include/sfinx.H index f75f66a..dab3720 100644 --- a/include/sfinx.H +++ b/include/sfinx.H @@ -97,8 +97,8 @@ class faraon_session : public sfinx_stream, public TCPSession { bool gen_desc_file(u32_t slice_id); void search_query(sfinx_search_query_t *); void search_in_files(string &pattern, sfinx_pair_vector_t *r); - void delete_files(u32_t slice_id, bool recursivly); - void mark_files_unsorted(u32_t slice_id, bool recursivly); + void mark_files_unsorted(u32_t slice_id, bool recursivly, bool remove = false); + void mark_file_unsorted(sfinx_file_t *f, bool remove = false); bool connect(); diff --git a/sfinx/sfinx.C b/sfinx/sfinx.C index 564972a..a16f3b7 100644 --- a/sfinx/sfinx.C +++ b/sfinx/sfinx.C @@ -365,7 +365,7 @@ void faraon_session::delete_slice_with_reattach(u32_t slice_id) void faraon_session::delete_slice_assoc_data(u32_t slice_id, bool recursivly) { - delete_files(slice_id, recursivly); + mark_files_unsorted(slice_id, recursivly, true); // delete_notes(); // ... } @@ -377,14 +377,82 @@ void faraon_session::delete_slice_mark_data_unsorted(u32_t slice_id, bool recurs // ... } -void faraon_session::delete_files(u32_t slice_id, bool recursivly) +void faraon_session::mark_files_unsorted(u32_t slice_id, bool recursivly, bool remove) { - bug(); + // delete from file_slices + IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, + IBPP::ilConcurrency, IBPP::lrWait); + tr->Start(); + IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr); + st->Prepare("delete from file_slices where slice_id = ?"); + st->Set(1, (int32_t)slice_id); + st->Execute(); + // move to unsorted location + st->Prepare("select name from files where main_slice_id = ?"); + st->Set(1, (int32_t)slice_id); + st->Execute(); + string udir, sdir; + sfinx->get_sorted_path(slice_id, &sdir); + sdir += "/"; + sfinx->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, udir); + while(st->Fetch()) { + string name, from; + st->Get(1, name); + from = sdir + name; + if (remove) + unlink(from.c_str()); + else + move(from, udir); + } + // delete from files + st->Prepare("delete from files where main_slice_id = ?"); + st->Set(1, (int32_t)slice_id); + st->Execute(); + if (recursivly) { + u32_t pid = sfinx->parent_id(slice_id); + if (pid) + mark_files_unsorted(pid, true, remove); + } + tr->Commit(); } -void faraon_session::mark_files_unsorted(u32_t slice_id, bool recursivly) +// ÕÓÔÁÎÏ×ÌÅÎ file_id = main_slice_id É name +void faraon_session::mark_file_unsorted(sfinx_file_t *f, bool remove) { - bug(); + // delete from file_slices + IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, + IBPP::ilConcurrency, IBPP::lrWait); + tr->Start(); + IBPP::Statement st = sfinx->driver_->StatementFactory(sfinx->db_, tr); + f->main_slice_id = f->file_id; + // get file_id + st->Prepare("select id from files where main_slice_id = ? and name = ?"); + st->Set(1, (int32_t)f->file_id); + st->Set(2, f->name); + int32_t file_id; + st->Execute(); + if (!st->Fetch()) + return; + else + st->Get(1, file_id); + st->Prepare("delete from file_slices where file_id = ?"); + st->Set(1, file_id); + st->Execute(); + // move to unsorted location + string udir, sdir; + sfinx->get_sorted_path(f->main_slice_id, &sdir); + sdir += "/"; + sfinx->files_module_conf.get(FILES_MODULE_UNSORTED_PATH, udir); + string from = sdir + f->name; + if (remove) + unlink(from.c_str()); + else + move(from, udir); + // delete from files + st->Prepare("delete from files where id = ?"); + st->Set(1, file_id); + st->Execute(); + tr->Commit(); } void faraon_session::update_files_module_conf(sfinx_pair_vector_t *conf) @@ -771,8 +839,11 @@ void faraon_session::files_module_classify(sfinx_file_t *f) st->Set(2, (int32_t)f->main_slice_id); st->Execute(); int64_t file_id; - while (st->Fetch()) { + if (!st->Fetch()) + bug(); + else { st->Get(1, &file_id); + debug("added file has id - %d", file_id); } // add to file_slices for (u32_t i = 0; i < f->slices.size(); i++) { @@ -940,6 +1011,15 @@ bool faraon_session::process_requests() string root; while ((el = rx_elements.next())) { switch (el->id()) { + case SFINX_FILES_MODULE_SORTED_UNLINK: + mark_file_unsorted((sfinx_file_t *)el, true); + break; + case SFINX_FILES_MODULE_UNSORT: + mark_file_unsorted((sfinx_file_t *)el); + break; + case SFINX_FILES_MODULE_UNLINK: + unlink(((sfinx_string_t *)el)->c_str()); + break; case SFINX_ELEMENT_SEARCH_QUERY: search_query((sfinx_search_query_t *)el); break; -- 2.11.4.GIT