Disk ARchive 2.7.14
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
src/libdar/user_interaction5.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef USER_INTERACTION5_HPP
27#define USER_INTERACTION5_HPP
28
29#include "../my_config.h"
30
31#include <string>
32#include <memory>
33#include "user_interaction.hpp"
34#include "secu_string.hpp"
35
36namespace libdar5
37{
38
41
43 using libdar::U_I;
44 using libdar::infinint;
46 using libdar::Elibcall;
47
48 using libdar::Ebug;
49 using libdar::Egeneric;
50 using libdar::Ememory;
51
53
87 class user_interaction : public libdar::user_interaction
88 {
89 public:
90
93 user_interaction(const user_interaction & ref) = default;
94 user_interaction(user_interaction && ref) noexcept = default;
95 user_interaction & operator = (const user_interaction & ref) = default;
96 user_interaction & operator = (user_interaction && ref) noexcept = default;
97 virtual ~user_interaction() = default;
98
100
106 void warning(const std::string & msg) { message(msg); };
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
131
135 virtual std::string get_string(const std::string & message, bool echo) = 0;
136
138
142 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
143
144
151
163 virtual void listing(const std::string & flag,
164 const std::string & perm,
165 const std::string & uid,
166 const std::string & gid,
167 const std::string & size,
168 const std::string & date,
169 const std::string & filename,
170 bool is_dir,
171 bool has_children);
172
173
174
181
186 virtual void dar_manager_show_files(const std::string & filename,
187 bool data_change,
188 bool ea_change);
189
190
197
202 virtual void dar_manager_contents(U_I number,
203 const std::string & chemin,
204 const std::string & archive_name);
205
212
219 virtual void dar_manager_statistics(U_I number,
220 const infinint & data_count,
221 const infinint & total_data,
222 const infinint & ea_count,
223 const infinint & total_ea);
224
231
238 virtual void dar_manager_show_version(U_I number,
239 const std::string & data_date,
240 const std::string & data_presence,
241 const std::string & ea_date,
242 const std::string & ea_presence);
243
247
249 bool get_use_listing() const { return use_listing; };
251 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
253 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
255 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
257 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
258
259 virtual void printf(const char *format, ...) override;
260
262
268 virtual user_interaction *clone() const = 0;
269
271
276 void warning_with_more(U_I num) { at_once = num; count = 0; };
277
278 protected:
279
281
286 void set_use_listing(bool val) { use_listing = val; };
287
289 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
290
292 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
293
295 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
296
298 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
299
301
302 // inherited from libdar::user_interaction
303 virtual void inherited_message(const std::string & message) override;
304 virtual bool inherited_pause(const std::string & message) override;
305 virtual std::string inherited_get_string(const std::string & message, bool echo) override;
306 virtual secu_string inherited_get_secu_string(const std::string & message, bool echo) override;
307
309 virtual void inherited_warning(const std::string & message) = 0;
310
311
312 private:
313 bool use_listing;
314 bool use_dar_manager_show_files;
315 bool use_dar_manager_contents;
316 bool use_dar_manager_statistics;
317 bool use_dar_manager_show_version;
318 U_I at_once, count;
319
320 };
321
323
324 extern std::shared_ptr<user_interaction> user_interaction5_clone_to_shared_ptr(user_interaction & dialog);
325
327
328} // end of namespace
329
330#endif
This is a pure virtual class that is used by libdar when interaction with the user is required.
virtual void dar_manager_show_files(const std::string &filename, bool data_change, bool ea_change)
virtual secu_string get_secu_string(const std::string &message, bool echo)=0
same a get_string() but uses secu_string instead
virtual void inherited_warning(const std::string &message)=0
to be defined by inherited classes
virtual void inherited_message(const std::string &message) override
need to be overwritten in place of the warning() method since API 3.1.x
user_interaction()
class constructor.
virtual secu_string inherited_get_secu_string(const std::string &message, bool echo) override
same a get_string() but uses libdar::secu_string instead of std::string
virtual void dar_manager_statistics(U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea)
bool get_use_dar_manager_contents() const
this is not a virtual method, it has not to be overwritten in inherited classes.
void set_use_dar_manager_contents(bool val)
method to be called with true as argument if you have defined a dar_manager_contents() method.
void set_use_dar_manager_show_version(bool val)
method to be called with true as argument if you have defined a dar_manager_show_version() method.
void warning_with_more(U_I num)
make a pause each N line of output when calling the warning method
virtual bool pause2(const std::string &message)
alternative method to the pause() method
virtual user_interaction * clone() const =0
make a newly allocated object which has the same properties as "this".
virtual void listing(const std::string &flag, const std::string &perm, const std::string &uid, const std::string &gid, const std::string &size, const std::string &date, const std::string &filename, bool is_dir, bool has_children)
bool get_use_listing() const
this is not a virtual method, it has not to be overwritten in inherited classes.
virtual bool inherited_pause(const std::string &message) override
method used to ask a boolean question to the user.
virtual void pause(const std::string &message)
method used to ask a boolean question to the user.
virtual std::string inherited_get_string(const std::string &message, bool echo) override
method used to ask a question that needs an arbitrary answer.
virtual void dar_manager_show_version(U_I number, const std::string &data_date, const std::string &data_presence, const std::string &ea_date, const std::string &ea_presence)
bool get_use_dar_manager_statistics() const
this is not a virtual method, it has not to be overwritten in inherited classes.
virtual void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
void set_use_listing(bool val)
method to be called with true as argument if you have defined a listing() method.
bool get_use_dar_manager_show_files() const
this is not a virtual method, it has not to be overwritten in inherited classes.
virtual std::string get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
bool get_use_dar_manager_show_version() const
this is not a virtual method, it has not to be overwritten in inherited classes.
void warning(const std::string &msg)
method added for backward compatibility with API v5
virtual void printf(const char *format,...) override
libdar uses this call to format output before send to message() method.
void set_use_dar_manager_show_files(bool val)
method to be called with true as argument if you have defined a dar_manager_show_files() method.
void set_use_dar_manager_statistics(bool val)
method to be called with true as argument if you have defined a dar_manager_statistics() method.
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
this is the parent class of all exception classes.
exception used to signal an error in the argument given to libdar call of the API
exception used when memory has been exhausted
exception used to signal that the user has aborted the operation
the arbitrary large positive integer class
This is a pure virtual class that is used by libdar when interaction with the user is required.
std::shared_ptr< user_interaction > user_interaction5_clone_to_shared_ptr(user_interaction &dialog)
convert a user_interaction to a shared_pointer on a clone of that user_interaction
include macro defined by the configure script and some specific additional ones
libdar5 namespace encapsulate all libdar symbols
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
defines the interaction interface between libdar and users.