Disk ARchive
2.4.2
|
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 // $Id: user_interaction.hpp,v 1.27 2011/01/09 17:25:58 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00036 00038 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp // 00039 // (and infinint.hpp must be included too, always) // 00041 #include "infinint.hpp" 00043 00044 00045 00046 #ifndef USER_INTERACTION_HPP 00047 #define USER_INTERACTION_HPP 00048 00049 #include "../my_config.h" 00050 00051 #include <string> 00052 #include "erreurs.hpp" 00053 #include "integers.hpp" 00054 #include "secu_string.hpp" 00055 00056 namespace libdar 00057 { 00058 00061 00062 00063 00065 00100 class user_interaction 00101 { 00102 public: 00103 00105 user_interaction(); 00106 virtual ~user_interaction() {}; 00107 00109 00113 virtual void pause(const std::string & message) 00114 { 00115 if(!pause2(message)) 00116 throw Euser_abort(message); 00117 }; 00118 00120 00127 virtual bool pause2(const std::string & message) 00128 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); }; 00129 00130 00136 void warning(const std::string & message); 00137 00139 00143 virtual std::string get_string(const std::string & message, bool echo) = 0; 00144 00146 00150 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0; 00151 00152 00159 00171 virtual void listing(const std::string & flag, 00172 const std::string & perm, 00173 const std::string & uid, 00174 const std::string & gid, 00175 const std::string & size, 00176 const std::string & date, 00177 const std::string & filename, 00178 bool is_dir, 00179 bool has_children); 00180 00181 00182 00189 00194 virtual void dar_manager_show_files(const std::string & filename, 00195 bool data_change, 00196 bool ea_change); 00197 00198 00205 00210 virtual void dar_manager_contents(U_I number, 00211 const std::string & chemin, 00212 const std::string & archive_name); 00213 00220 00227 virtual void dar_manager_statistics(U_I number, 00228 const infinint & data_count, 00229 const infinint & total_data, 00230 const infinint & ea_count, 00231 const infinint & total_ea); 00232 00239 00246 virtual void dar_manager_show_version(U_I number, 00247 const std::string & data_date, 00248 const std::string & data_presence, 00249 const std::string & ea_date, 00250 const std::string & ea_presence); 00251 00253 00261 void printf(const char *format, ...); 00262 00266 00268 bool get_use_listing() const { return use_listing; }; 00270 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; }; 00272 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; }; 00274 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; }; 00276 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; }; 00277 00278 00280 00286 virtual user_interaction *clone() const = 0; 00287 00289 00294 void warning_with_more(U_I num) { at_once = num; count = 0; }; 00295 00296 protected: 00297 00299 00304 void set_use_listing(bool val) { use_listing = val; }; 00305 00307 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; }; 00308 00310 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; }; 00311 00313 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; }; 00314 00316 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; }; 00317 00319 00322 virtual void inherited_warning(const std::string & message) = 0; 00323 00324 private: 00325 bool use_listing; 00326 bool use_dar_manager_show_files; 00327 bool use_dar_manager_contents; 00328 bool use_dar_manager_statistics; 00329 bool use_dar_manager_show_version; 00330 U_I at_once, count; 00331 00332 }; 00333 00334 00336 00340 class user_interaction_callback : public user_interaction 00341 { 00342 public: 00343 00345 00356 user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context), 00357 bool (*x_answer_callback)(const std::string &x, void *context), 00358 std::string (*x_string_callback)(const std::string &x, bool echo, void *context), 00359 secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context), 00360 void *context_value); 00361 00363 void pause(const std::string & message); 00365 std::string get_string(const std::string & message, bool echo); 00367 secu_string get_secu_string(const std::string & message, bool echo); 00369 void listing(const std::string & flag, 00370 const std::string & perm, 00371 const std::string & uid, 00372 const std::string & gid, 00373 const std::string & size, 00374 const std::string & date, 00375 const std::string & filename, 00376 bool is_dir, 00377 bool has_children); 00378 00380 void dar_manager_show_files(const std::string & filename, 00381 bool available_data, 00382 bool available_ea); 00383 00385 void dar_manager_contents(U_I number, 00386 const std::string & chemin, 00387 const std::string & archive_name); 00388 00390 void dar_manager_statistics(U_I number, 00391 const infinint & data_count, 00392 const infinint & total_data, 00393 const infinint & ea_count, 00394 const infinint & total_ea); 00395 00397 void dar_manager_show_version(U_I number, 00398 const std::string & data_date, 00399 const std::string & data_presence, 00400 const std::string & ea_date, 00401 const std::string & ea_presence); 00402 00404 00408 void set_listing_callback(void (*callback)(const std::string & flag, 00409 const std::string & perm, 00410 const std::string & uid, 00411 const std::string & gid, 00412 const std::string & size, 00413 const std::string & date, 00414 const std::string & filename, 00415 bool is_dir, 00416 bool has_children, 00417 void *context)) 00418 { 00419 tar_listing_callback = callback; 00420 set_use_listing(true); // this is to inform libdar to use listing() 00421 }; 00422 00423 // You can set a dar_manager_show_files callback thanks to this method 00424 00425 void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename, 00426 bool available_data, 00427 bool available_ea, 00428 void *context)) 00429 { 00430 dar_manager_show_files_callback = callback; 00431 set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method 00432 }; 00433 00434 void set_dar_manager_contents_callback(void (*callback)(U_I number, 00435 const std::string & chemin, 00436 const std::string & archive_name, 00437 void *context)) 00438 { 00439 dar_manager_contents_callback = callback; 00440 set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method 00441 }; 00442 00443 void set_dar_manager_statistics_callback(void (*callback)(U_I number, 00444 const infinint & data_count, 00445 const infinint & total_data, 00446 const infinint & ea_count, 00447 const infinint & total_ea, 00448 void *context)) 00449 { 00450 dar_manager_statistics_callback = callback; 00451 set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method 00452 }; 00453 00454 void set_dar_manager_show_version_callback(void (*callback)(U_I number, 00455 const std::string & data_date, 00456 const std::string & data_presence, 00457 const std::string & ea_date, 00458 const std::string & ea_presence, 00459 void *context)) 00460 { 00461 dar_manager_show_version_callback = callback; 00462 set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method 00463 }; 00464 00465 00467 virtual user_interaction *clone() const; 00468 00469 protected: 00471 void inherited_warning(const std::string & message); 00472 00473 private: 00474 void (*warning_callback)(const std::string & x, void *context); // pointer to function 00475 bool (*answer_callback)(const std::string & x, void *context); // pointer to function 00476 std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00477 secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00478 void (*tar_listing_callback)(const std::string & flags, 00479 const std::string & perm, 00480 const std::string & uid, 00481 const std::string & gid, 00482 const std::string & size, 00483 const std::string & date, 00484 const std::string & filename, 00485 bool is_dir, 00486 bool has_children, 00487 void *context); 00488 void (*dar_manager_show_files_callback)(const std::string & filename, 00489 bool available_data, 00490 bool available_ea, 00491 void *context); 00492 void (*dar_manager_contents_callback)(U_I number, 00493 const std::string & chemin, 00494 const std::string & archive_name, 00495 void *context); 00496 void (*dar_manager_statistics_callback)(U_I number, 00497 const infinint & data_count, 00498 const infinint & total_data, 00499 const infinint & ea_count, 00500 const infinint & total_ea, 00501 void *context); 00502 void (*dar_manager_show_version_callback)(U_I number, 00503 const std::string & data_date, 00504 const std::string & data_presence, 00505 const std::string & ea_date, 00506 const std::string & ea_presence, 00507 void *context); 00508 00509 void *context_val; 00510 }; 00511 00512 00514 00515 class user_interaction_blind : public user_interaction 00516 { 00517 public: 00518 bool pause2(const std::string & message) { return false; }; 00519 00520 std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; }; 00521 secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); }; 00522 00523 user_interaction *clone() const { user_interaction *ret = new user_interaction_blind(); if(ret == NULL) throw Ememory("user_interaction_blind::clone"); return ret; }; 00524 00525 protected: 00526 void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" ! 00527 00528 }; 00529 00531 00532 } // end of namespace 00533 00534 #endif 00535