Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
user_interaction.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: user_interaction.hpp,v 1.27 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
36 
38 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp //
39 // (and infinint.hpp must be included too, always) //
41 #include "infinint.hpp"
43 
44 
45 
46 #ifndef USER_INTERACTION_HPP
47 #define USER_INTERACTION_HPP
48 
49 #include "../my_config.h"
50 
51 #include <string>
52 #include "erreurs.hpp"
53 #include "integers.hpp"
54 #include "secu_string.hpp"
55 
56 namespace libdar
57 {
58 
61 
62 
63 
65 
101  {
102  public:
103 
106  virtual ~user_interaction() {};
107 
109 
113  virtual void pause(const std::string & message)
114  {
115  if(!pause2(message))
116  throw Euser_abort(message);
117  };
118 
120 
127  virtual bool pause2(const std::string & message)
128  { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
129 
130 
136  void warning(const std::string & message);
137 
139 
143  virtual std::string get_string(const std::string & message, bool echo) = 0;
144 
146 
150  virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
151 
152 
159 
171  virtual void listing(const std::string & flag,
172  const std::string & perm,
173  const std::string & uid,
174  const std::string & gid,
175  const std::string & size,
176  const std::string & date,
177  const std::string & filename,
178  bool is_dir,
179  bool has_children);
180 
181 
182 
189 
194  virtual void dar_manager_show_files(const std::string & filename,
195  bool data_change,
196  bool ea_change);
197 
198 
205 
210  virtual void dar_manager_contents(U_I number,
211  const std::string & chemin,
212  const std::string & archive_name);
213 
220 
227  virtual void dar_manager_statistics(U_I number,
228  const infinint & data_count,
229  const infinint & total_data,
230  const infinint & ea_count,
231  const infinint & total_ea);
232 
239 
246  virtual void dar_manager_show_version(U_I number,
247  const std::string & data_date,
248  const std::string & data_presence,
249  const std::string & ea_date,
250  const std::string & ea_presence);
251 
253 
261  void printf(const char *format, ...);
262 
266 
268  bool get_use_listing() const { return use_listing; };
270  bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
272  bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
274  bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
276  bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
277 
278 
280 
286  virtual user_interaction *clone() const = 0;
287 
289 
294  void warning_with_more(U_I num) { at_once = num; count = 0; };
295 
296  protected:
297 
299 
304  void set_use_listing(bool val) { use_listing = val; };
305 
307  void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
308 
310  void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
311 
313  void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
314 
316  void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
317 
319 
322  virtual void inherited_warning(const std::string & message) = 0;
323 
324  private:
325  bool use_listing;
326  bool use_dar_manager_show_files;
327  bool use_dar_manager_contents;
328  bool use_dar_manager_statistics;
329  bool use_dar_manager_show_version;
330  U_I at_once, count;
331 
332  };
333 
334 
336 
341  {
342  public:
343 
345 
356  user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context),
357  bool (*x_answer_callback)(const std::string &x, void *context),
358  std::string (*x_string_callback)(const std::string &x, bool echo, void *context),
359  secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context),
360  void *context_value);
361 
363  void pause(const std::string & message);
365  std::string get_string(const std::string & message, bool echo);
367  secu_string get_secu_string(const std::string & message, bool echo);
369  void listing(const std::string & flag,
370  const std::string & perm,
371  const std::string & uid,
372  const std::string & gid,
373  const std::string & size,
374  const std::string & date,
375  const std::string & filename,
376  bool is_dir,
377  bool has_children);
378 
380  void dar_manager_show_files(const std::string & filename,
381  bool available_data,
382  bool available_ea);
383 
385  void dar_manager_contents(U_I number,
386  const std::string & chemin,
387  const std::string & archive_name);
388 
390  void dar_manager_statistics(U_I number,
391  const infinint & data_count,
392  const infinint & total_data,
393  const infinint & ea_count,
394  const infinint & total_ea);
395 
397  void dar_manager_show_version(U_I number,
398  const std::string & data_date,
399  const std::string & data_presence,
400  const std::string & ea_date,
401  const std::string & ea_presence);
402 
404 
408  void set_listing_callback(void (*callback)(const std::string & flag,
409  const std::string & perm,
410  const std::string & uid,
411  const std::string & gid,
412  const std::string & size,
413  const std::string & date,
414  const std::string & filename,
415  bool is_dir,
416  bool has_children,
417  void *context))
418  {
419  tar_listing_callback = callback;
420  set_use_listing(true); // this is to inform libdar to use listing()
421  };
422 
423  // You can set a dar_manager_show_files callback thanks to this method
424 
425  void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename,
426  bool available_data,
427  bool available_ea,
428  void *context))
429  {
430  dar_manager_show_files_callback = callback;
431  set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method
432  };
433 
434  void set_dar_manager_contents_callback(void (*callback)(U_I number,
435  const std::string & chemin,
436  const std::string & archive_name,
437  void *context))
438  {
439  dar_manager_contents_callback = callback;
440  set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method
441  };
442 
443  void set_dar_manager_statistics_callback(void (*callback)(U_I number,
444  const infinint & data_count,
445  const infinint & total_data,
446  const infinint & ea_count,
447  const infinint & total_ea,
448  void *context))
449  {
450  dar_manager_statistics_callback = callback;
451  set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method
452  };
453 
454  void set_dar_manager_show_version_callback(void (*callback)(U_I number,
455  const std::string & data_date,
456  const std::string & data_presence,
457  const std::string & ea_date,
458  const std::string & ea_presence,
459  void *context))
460  {
461  dar_manager_show_version_callback = callback;
462  set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method
463  };
464 
465 
467  virtual user_interaction *clone() const;
468 
469  protected:
471  void inherited_warning(const std::string & message);
472 
473  private:
474  void (*warning_callback)(const std::string & x, void *context); // pointer to function
475  bool (*answer_callback)(const std::string & x, void *context); // pointer to function
476  std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function
477  secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function
478  void (*tar_listing_callback)(const std::string & flags,
479  const std::string & perm,
480  const std::string & uid,
481  const std::string & gid,
482  const std::string & size,
483  const std::string & date,
484  const std::string & filename,
485  bool is_dir,
486  bool has_children,
487  void *context);
488  void (*dar_manager_show_files_callback)(const std::string & filename,
489  bool available_data,
490  bool available_ea,
491  void *context);
492  void (*dar_manager_contents_callback)(U_I number,
493  const std::string & chemin,
494  const std::string & archive_name,
495  void *context);
496  void (*dar_manager_statistics_callback)(U_I number,
497  const infinint & data_count,
498  const infinint & total_data,
499  const infinint & ea_count,
500  const infinint & total_ea,
501  void *context);
502  void (*dar_manager_show_version_callback)(U_I number,
503  const std::string & data_date,
504  const std::string & data_presence,
505  const std::string & ea_date,
506  const std::string & ea_presence,
507  void *context);
508 
509  void *context_val;
510  };
511 
512 
514 
516  {
517  public:
518  bool pause2(const std::string & message) { return false; };
519 
520  std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; };
521  secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); };
522 
523  user_interaction *clone() const { user_interaction *ret = new user_interaction_blind(); if(ret == NULL) throw Ememory("user_interaction_blind::clone"); return ret; };
524 
525  protected:
526  void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" !
527 
528  };
529 
531 
532 } // end of namespace
533 
534 #endif
535