00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033
00034
00036
00037
00039 #include "infinint.hpp"
00041
00042
00043
00044 #ifndef USER_INTERACTION_HPP
00045 #define USER_INTERACTION_HPP
00046
00047 #include "../my_config.h"
00048
00049 #include <string>
00050 #include "erreurs.hpp"
00051 #include "integers.hpp"
00052
00053 namespace libdar
00054 {
00055
00057
00091 class user_interaction
00092 {
00093 public:
00094
00096 user_interaction();
00097 virtual ~user_interaction() {};
00098
00100
00104 virtual void pause(const std::string & message)
00105 {
00106 if(!pause2(message))
00107 throw Euser_abort(message);
00108 };
00109
00111
00118 virtual bool pause2(const std::string & message)
00119 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
00120
00121
00127 void warning(const std::string & message);
00128
00130
00134 virtual std::string get_string(const std::string & message, bool echo) = 0;
00135
00142
00154 virtual void listing(const std::string & flag,
00155 const std::string & perm,
00156 const std::string & uid,
00157 const std::string & gid,
00158 const std::string & size,
00159 const std::string & date,
00160 const std::string & filename,
00161 bool is_dir,
00162 bool has_children);
00163
00164
00165
00172
00177 virtual void dar_manager_show_files(const std::string & filename,
00178 bool available_data,
00179 bool available_ea);
00180
00181
00188
00193 virtual void dar_manager_contents(U_I number,
00194 const std::string & chemin,
00195 const std::string & archive_name);
00196
00203
00210 virtual void dar_manager_statistics(U_I number,
00211 const infinint & data_count,
00212 const infinint & total_data,
00213 const infinint & ea_count,
00214 const infinint & total_ea);
00215
00222
00227 virtual void dar_manager_show_version(U_I number,
00228 const std::string & data_date,
00229 const std::string & ea_date);
00230
00232
00240 void printf(const char *format, ...);
00241
00245
00247 bool get_use_listing() const { return use_listing; };
00249 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
00251 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
00253 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
00255 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
00256
00257
00259
00265 virtual user_interaction *clone() const = 0;
00266
00268
00273 void warning_with_more(U_I num) { at_once = num; count = 0; };
00274
00275 protected:
00276
00278
00283 void set_use_listing(bool val) { use_listing = val; };
00284
00286 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
00287
00289 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
00290
00292 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
00293
00295 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
00296
00298
00301 virtual void inherited_warning(const std::string & message) = 0;
00302
00303 private:
00304 bool use_listing;
00305 bool use_dar_manager_show_files;
00306 bool use_dar_manager_contents;
00307 bool use_dar_manager_statistics;
00308 bool use_dar_manager_show_version;
00309 U_I at_once, count;
00310
00311 };
00312
00313
00315
00319 class user_interaction_callback : public user_interaction
00320 {
00321 public:
00322
00324
00334 user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context),
00335 bool (*x_answer_callback)(const std::string &x, void *context),
00336 std::string (*x_string_callback)(const std::string &x, bool echo, void *context),
00337 void *context_value);
00338
00340 void pause(const std::string & message);
00342 std::string get_string(const std::string & message, bool echo);
00343
00345 void listing(const std::string & flag,
00346 const std::string & perm,
00347 const std::string & uid,
00348 const std::string & gid,
00349 const std::string & size,
00350 const std::string & date,
00351 const std::string & filename,
00352 bool is_dir,
00353 bool has_children);
00354
00356 void dar_manager_show_files(const std::string & filename,
00357 bool available_data,
00358 bool available_ea);
00359
00361 void dar_manager_contents(U_I number,
00362 const std::string & chemin,
00363 const std::string & archive_name);
00364
00366 void dar_manager_statistics(U_I number,
00367 const infinint & data_count,
00368 const infinint & total_data,
00369 const infinint & ea_count,
00370 const infinint & total_ea);
00371
00373 void dar_manager_show_version(U_I number,
00374 const std::string & data_date,
00375 const std::string & ea_date);
00376
00378
00382 void set_listing_callback(void (*callback)(const std::string & flag,
00383 const std::string & perm,
00384 const std::string & uid,
00385 const std::string & gid,
00386 const std::string & size,
00387 const std::string & date,
00388 const std::string & filename,
00389 bool is_dir,
00390 bool has_children,
00391 void *context))
00392 {
00393 tar_listing_callback = callback;
00394 set_use_listing(true);
00395 };
00396
00397
00398
00399 void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename,
00400 bool available_data,
00401 bool available_ea,
00402 void *context))
00403 {
00404 dar_manager_show_files_callback = callback;
00405 set_use_dar_manager_show_files(true);
00406 };
00407
00408 void set_dar_manager_contents_callback(void (*callback)(U_I number,
00409 const std::string & chemin,
00410 const std::string & archive_name,
00411 void *context))
00412 {
00413 dar_manager_contents_callback = callback;
00414 set_use_dar_manager_contents(true);
00415 };
00416
00417 void set_dar_manager_statistics_callback(void (*callback)(U_I number,
00418 const infinint & data_count,
00419 const infinint & total_data,
00420 const infinint & ea_count,
00421 const infinint & total_ea,
00422 void *context))
00423 {
00424 dar_manager_statistics_callback = callback;
00425 set_use_dar_manager_statistics(true);
00426 };
00427
00428 void set_dar_manager_show_version_callback(void (*callback)(U_I number,
00429 const std::string & data_date,
00430 const std::string & ea_date,
00431 void *context))
00432 {
00433 dar_manager_show_version_callback = callback;
00434 set_use_dar_manager_show_version(true);
00435 };
00436
00437
00439 virtual user_interaction *clone() const;
00440
00441 protected:
00443 void inherited_warning(const std::string & message);
00444
00445 private:
00446 void (*warning_callback)(const std::string & x, void *context);
00447 bool (*answer_callback)(const std::string & x, void *context);
00448 std::string (*string_callback)(const std::string & x, bool echo, void *context);
00449 void (*tar_listing_callback)(const std::string & flags,
00450 const std::string & perm,
00451 const std::string & uid,
00452 const std::string & gid,
00453 const std::string & size,
00454 const std::string & date,
00455 const std::string & filename,
00456 bool is_dir,
00457 bool has_children,
00458 void *context);
00459 void (*dar_manager_show_files_callback)(const std::string & filename,
00460 bool available_data,
00461 bool available_ea,
00462 void *context);
00463 void (*dar_manager_contents_callback)(U_I number,
00464 const std::string & chemin,
00465 const std::string & archive_name,
00466 void *context);
00467 void (*dar_manager_statistics_callback)(U_I number,
00468 const infinint & data_count,
00469 const infinint & total_data,
00470 const infinint & ea_count,
00471 const infinint & total_ea,
00472 void *context);
00473 void (*dar_manager_show_version_callback)(U_I number,
00474 const std::string & data_date,
00475 const std::string & ea_date,
00476 void *context);
00477
00478 void *context_val;
00479 };
00480
00481 }
00482
00483 #endif
00484