|
Disk ARchive
2.4.12
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00033 00035 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp // 00036 // (and infinint.hpp must be included too, always) // 00038 #include "infinint.hpp" 00040 00041 00042 00043 #ifndef USER_INTERACTION_HPP 00044 #define USER_INTERACTION_HPP 00045 00046 #include "../my_config.h" 00047 00048 #include <string> 00049 #include "erreurs.hpp" 00050 #include "integers.hpp" 00051 #include "secu_string.hpp" 00052 00053 namespace libdar 00054 { 00055 00058 00059 00060 00062 00097 class user_interaction 00098 { 00099 public: 00100 00102 user_interaction(); 00103 virtual ~user_interaction() {}; 00104 00106 00110 virtual void pause(const std::string & message) 00111 { 00112 if(!pause2(message)) 00113 throw Euser_abort(message); 00114 }; 00115 00117 00124 virtual bool pause2(const std::string & message) 00125 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); }; 00126 00127 00133 void warning(const std::string & message); 00134 00136 00140 virtual std::string get_string(const std::string & message, bool echo) = 0; 00141 00143 00147 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0; 00148 00149 00156 00168 virtual void listing(const std::string & flag, 00169 const std::string & perm, 00170 const std::string & uid, 00171 const std::string & gid, 00172 const std::string & size, 00173 const std::string & date, 00174 const std::string & filename, 00175 bool is_dir, 00176 bool has_children); 00177 00178 00179 00186 00191 virtual void dar_manager_show_files(const std::string & filename, 00192 bool data_change, 00193 bool ea_change); 00194 00195 00202 00207 virtual void dar_manager_contents(U_I number, 00208 const std::string & chemin, 00209 const std::string & archive_name); 00210 00217 00224 virtual void dar_manager_statistics(U_I number, 00225 const infinint & data_count, 00226 const infinint & total_data, 00227 const infinint & ea_count, 00228 const infinint & total_ea); 00229 00236 00243 virtual void dar_manager_show_version(U_I number, 00244 const std::string & data_date, 00245 const std::string & data_presence, 00246 const std::string & ea_date, 00247 const std::string & ea_presence); 00248 00250 00258 void printf(const char *format, ...); 00259 00263 00265 bool get_use_listing() const { return use_listing; }; 00267 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; }; 00269 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; }; 00271 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; }; 00273 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; }; 00274 00275 00277 00283 virtual user_interaction *clone() const = 0; 00284 00286 00291 void warning_with_more(U_I num) { at_once = num; count = 0; }; 00292 00293 protected: 00294 00296 00301 void set_use_listing(bool val) { use_listing = val; }; 00302 00304 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; }; 00305 00307 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; }; 00308 00310 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; }; 00311 00313 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; }; 00314 00316 00319 virtual void inherited_warning(const std::string & message) = 0; 00320 00321 private: 00322 bool use_listing; 00323 bool use_dar_manager_show_files; 00324 bool use_dar_manager_contents; 00325 bool use_dar_manager_statistics; 00326 bool use_dar_manager_show_version; 00327 U_I at_once, count; 00328 00329 }; 00330 00331 00333 00337 class user_interaction_callback : public user_interaction 00338 { 00339 public: 00340 00342 00353 user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context), 00354 bool (*x_answer_callback)(const std::string &x, void *context), 00355 std::string (*x_string_callback)(const std::string &x, bool echo, void *context), 00356 secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context), 00357 void *context_value); 00358 00360 void pause(const std::string & message); 00362 std::string get_string(const std::string & message, bool echo); 00364 secu_string get_secu_string(const std::string & message, bool echo); 00366 void listing(const std::string & flag, 00367 const std::string & perm, 00368 const std::string & uid, 00369 const std::string & gid, 00370 const std::string & size, 00371 const std::string & date, 00372 const std::string & filename, 00373 bool is_dir, 00374 bool has_children); 00375 00377 void dar_manager_show_files(const std::string & filename, 00378 bool available_data, 00379 bool available_ea); 00380 00382 void dar_manager_contents(U_I number, 00383 const std::string & chemin, 00384 const std::string & archive_name); 00385 00387 void dar_manager_statistics(U_I number, 00388 const infinint & data_count, 00389 const infinint & total_data, 00390 const infinint & ea_count, 00391 const infinint & total_ea); 00392 00394 void dar_manager_show_version(U_I number, 00395 const std::string & data_date, 00396 const std::string & data_presence, 00397 const std::string & ea_date, 00398 const std::string & ea_presence); 00399 00401 00405 void set_listing_callback(void (*callback)(const std::string & flag, 00406 const std::string & perm, 00407 const std::string & uid, 00408 const std::string & gid, 00409 const std::string & size, 00410 const std::string & date, 00411 const std::string & filename, 00412 bool is_dir, 00413 bool has_children, 00414 void *context)) 00415 { 00416 tar_listing_callback = callback; 00417 set_use_listing(true); // this is to inform libdar to use listing() 00418 }; 00419 00420 // You can set a dar_manager_show_files callback thanks to this method 00421 00422 void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename, 00423 bool available_data, 00424 bool available_ea, 00425 void *context)) 00426 { 00427 dar_manager_show_files_callback = callback; 00428 set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method 00429 }; 00430 00431 void set_dar_manager_contents_callback(void (*callback)(U_I number, 00432 const std::string & chemin, 00433 const std::string & archive_name, 00434 void *context)) 00435 { 00436 dar_manager_contents_callback = callback; 00437 set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method 00438 }; 00439 00440 void set_dar_manager_statistics_callback(void (*callback)(U_I number, 00441 const infinint & data_count, 00442 const infinint & total_data, 00443 const infinint & ea_count, 00444 const infinint & total_ea, 00445 void *context)) 00446 { 00447 dar_manager_statistics_callback = callback; 00448 set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method 00449 }; 00450 00451 void set_dar_manager_show_version_callback(void (*callback)(U_I number, 00452 const std::string & data_date, 00453 const std::string & data_presence, 00454 const std::string & ea_date, 00455 const std::string & ea_presence, 00456 void *context)) 00457 { 00458 dar_manager_show_version_callback = callback; 00459 set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method 00460 }; 00461 00462 00464 virtual user_interaction *clone() const; 00465 00466 protected: 00468 void inherited_warning(const std::string & message); 00469 00470 private: 00471 void (*warning_callback)(const std::string & x, void *context); // pointer to function 00472 bool (*answer_callback)(const std::string & x, void *context); // pointer to function 00473 std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00474 secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00475 void (*tar_listing_callback)(const std::string & flags, 00476 const std::string & perm, 00477 const std::string & uid, 00478 const std::string & gid, 00479 const std::string & size, 00480 const std::string & date, 00481 const std::string & filename, 00482 bool is_dir, 00483 bool has_children, 00484 void *context); 00485 void (*dar_manager_show_files_callback)(const std::string & filename, 00486 bool available_data, 00487 bool available_ea, 00488 void *context); 00489 void (*dar_manager_contents_callback)(U_I number, 00490 const std::string & chemin, 00491 const std::string & archive_name, 00492 void *context); 00493 void (*dar_manager_statistics_callback)(U_I number, 00494 const infinint & data_count, 00495 const infinint & total_data, 00496 const infinint & ea_count, 00497 const infinint & total_ea, 00498 void *context); 00499 void (*dar_manager_show_version_callback)(U_I number, 00500 const std::string & data_date, 00501 const std::string & data_presence, 00502 const std::string & ea_date, 00503 const std::string & ea_presence, 00504 void *context); 00505 00506 void *context_val; 00507 }; 00508 00509 00511 00512 class user_interaction_blind : public user_interaction 00513 { 00514 public: 00515 bool pause2(const std::string & message) { return false; }; 00516 00517 std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; }; 00518 secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); }; 00519 00520 user_interaction *clone() const { user_interaction *ret = new (std::nothrow) user_interaction_blind(); if(ret == NULL) throw Ememory("user_interaction_blind::clone"); return ret; }; 00521 00522 protected: 00523 void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" ! 00524 00525 }; 00526 00528 00529 } // end of namespace 00530 00531 #endif 00532
1.7.6.1