00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_GENERAL_H
00026 #define __SYNFIG_GENERAL_H
00027
00028
00029
00030 #include <ETL/stringf>
00031 #include "string.h"
00032 #include "version.h"
00033 #ifdef ENABLE_NLS
00034 #include <locale.h>
00035 #include <libintl.h>
00036 #endif
00037
00038
00039
00040 #ifdef ENABLE_NLS
00041 #define _(x) dgettext("synfig",x)
00042 #define gettext_noop(x) x
00043 #define N_(x) gettext_noop(x)
00044 #else
00045 #define dgettext(a,x) (x)
00046 #define _(x) (x)
00047 #define N_(x) (x)
00048 #endif
00049
00050 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2005 Robert B. Quattlebaum Jr., Adrian Bentley"
00051
00052
00053 #ifdef _DEBUG
00054 #ifdef __FUNC__
00055 #define DEBUGPOINT() synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
00056 #define DEBUGINFO(x) synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
00057 #else
00058 #define DEBUGPOINT() synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
00059 #define DEBUGINFO(x) synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
00060 #endif
00061
00062 #else
00063 #define DEBUGPOINT()
00064 #define DEBUGINFO(x)
00065 #endif
00066
00067
00068
00069 namespace synfig {
00070
00071 class ChangeLocale {
00072 const String previous;
00073 const int category;
00074 public:
00075 ChangeLocale(int category, const char *locale):
00076 previous(setlocale(category,locale)),category(category)
00077 {
00078 }
00079 ~ChangeLocale() {
00080 setlocale(category,previous.c_str());
00081 }
00082 };
00083
00087 class ProgressCallback
00088 {
00089 public:
00090
00091 virtual ~ProgressCallback() { }
00092 virtual bool task(const String &) { return true; }
00093 virtual bool error(const String &) { return true; }
00094 virtual bool warning(const String &) { return true; }
00095 virtual bool amount_complete(int , int ) { return true; }
00096
00097 virtual bool valid() const { return true; }
00098 };
00099
00100 typedef ProgressCallback ProgressManager;
00101
00105 class SuperCallback : public ProgressCallback
00106 {
00107 ProgressCallback *cb;
00108 int start,end,tot;
00109 int w;
00110 public:
00111
00112 SuperCallback() { cb=NULL; }
00113 SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
00114 {
00115
00116 if(!cb || !cb->valid())
00117 cb = NULL;
00118 w=end-start;
00119 }
00120 virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
00121 virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
00122 virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
00123 virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
00124
00125 virtual bool valid() const { return cb != 0; }
00126 };
00127
00128
00129
00130
00131
00132
00133
00135 extern void shutdown();
00136
00138
00139 extern void error(const char *format,...);
00140 extern void error(const String &str);
00141
00143
00144 extern void warning(const char *format,...);
00145 extern void warning(const String &str);
00146
00148
00149 extern void info(const char *format,...);
00150 extern void info(const String &str);
00151
00152 };
00153
00154
00155
00156 #endif