Strip license key and software expiry stuff now that Synfig is free software and...
[synfig.git] / synfig-core / trunk / src / synfig / general.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file general.h
3 **      \brief General macros, classes, and procedure declarations
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_GENERAL_H
26 #define __SYNFIG_GENERAL_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <ETL/stringf>
31 #include "string.h"
32 #include "version.h"
33 #include <locale.h>
34 #include <libintl.h>
35
36 /* === M A C R O S ========================================================= */
37
38 #define _(x) dgettext("synfig",x)
39 #define gettext_noop(x) x
40 #define N_(x) gettext_noop(x)
41
42 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2005 Robert B. Quattlebaum Jr., Adrian Bentley"
43
44
45 #ifdef _DEBUG
46 #ifdef __FUNC__
47 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
48 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
49 #else
50 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
51 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
52 #endif
53
54 #else
55 #define DEBUGPOINT()
56 #define DEBUGINFO(x)
57 #endif
58
59 /* === C L A S S E S & S T R U C T S ======================================= */
60
61 namespace synfig {
62
63 class ChangeLocale {
64     const String previous;
65     const int category;
66 public:
67     ChangeLocale(int category, const char *locale):
68         previous(setlocale(category,locale)),category(category)
69     {
70     }
71     ~ChangeLocale() {
72         setlocale(category,previous.c_str());
73     }
74 };
75
76 /*!     \class ProgressCallback
77 **      \todo writeme
78 */
79 class ProgressCallback
80 {
81 public:
82
83         virtual ~ProgressCallback() { }
84         virtual bool task(const String &/*task*/) { return true; }
85         virtual bool error(const String &/*task*/) { return true; }
86         virtual bool warning(const String &/*task*/) { return true; }
87         virtual bool amount_complete(int /*current*/, int /*total*/) { return true; }
88
89         virtual bool valid() const { return true; }
90 };
91
92 typedef ProgressCallback ProgressManager;
93
94 /*!     \class SuperCallback
95 **      \todo writeme
96 */
97 class SuperCallback : public ProgressCallback
98 {
99         ProgressCallback *cb;
100         int start,end,tot;
101         int w;
102 public:
103
104         SuperCallback() { cb=NULL; }
105         SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
106         {
107                 //make sure we don't "inherit" if our subcallback is invalid
108                 if(!cb || !cb->valid())
109                         cb = NULL;
110                 w=end-start;
111         }
112         virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
113         virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
114         virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
115         virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
116
117         virtual bool valid() const { return cb != 0; }
118 };
119
120
121 /*
122 extern bool add_to_module_search_path(const std:string &path);
123 extern bool add_to_config_search_path(const std:string &path);
124 */
125
126 //! Shutdown the synfig environment
127 extern void shutdown();
128
129 //! Reports an error
130 /*! Call this when an error occurs, describing what happened */
131 extern void error(const char *format,...);
132 extern void error(const String &str);
133
134 //! Reports a warning
135 /*! Call this when something questionable occurs, describing what happened */
136 extern void warning(const char *format,...);
137 extern void warning(const String &str);
138
139 //! Reports some information
140 /*! Call this to report various information. Please be sparse... */
141 extern void info(const char *format,...);
142 extern void info(const String &str);
143
144 }; // END of namespace synfig
145
146 /* === E N D =============================================================== */
147
148 #endif