Enable translation for render progress information.
[synfig.git] / synfig-core / src / tool / renderprogress.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file tool/renderprogress.h
3 **      \brief RenderProgress class
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 #ifndef __SYNFIG_RENDERPROGRESS_H
25 #define __SYNFIG_RENDERPROGRESS_H
26
27 using namespace std;
28 using namespace etl;
29 using namespace synfig;
30
31 #include <synfig/string.h>
32 #include "definitions.h"
33
34 class RenderProgress : public synfig::ProgressCallback
35 {
36         string taskname;
37
38         etl::clock clk;
39         int clk_scanline; // The scanline at which the clock was reset
40         etl::clock clk2;
41
42         float last_time;
43 public:
44
45         RenderProgress():clk_scanline(0), last_time(0) { }
46
47         virtual bool
48         task(const String &thetask)
49         {
50                 taskname=thetask;
51                 return true;
52         }
53
54         virtual bool
55         error(const String &task)
56         {
57                 std::cout<<_("error")<<": "<<task<<std::endl;
58                 return true;
59         }
60
61         virtual bool
62         warning(const String &task)
63         {
64                 std::cout<<_("warning")<<": "<<task<<std::endl;
65                 return true;
66         }
67
68         virtual bool
69         amount_complete(int scanline, int h)
70         {
71                 if(be_quiet)return true;
72                 if(scanline!=h)
73                 {
74                         const float time(clk()*(float)(h-scanline)/(float)(scanline-clk_scanline));
75                         const float delta(time-last_time);
76
77                         int weeks=0,days=0,hours=0,minutes=0,seconds=0;
78
79                         last_time=time;
80
81                         if(clk2()<0.2)
82                                 return true;
83                         clk2.reset();
84
85                         if(scanline)
86                                 seconds=(int)time+1;
87                         else
88                         {
89                                 //cerr<<"reset"<<endl;
90                                 clk.reset();
91                                 clk_scanline=scanline;
92                         }
93
94                         if(seconds<0)
95                         {
96                                 clk.reset();
97                                 clk_scanline=scanline;
98                                 seconds=0;
99                         }
100                         while(seconds>=60)
101                                 minutes++,seconds-=60;
102                         while(minutes>=60)
103                                 hours++,minutes-=60;
104                         while(hours>=24)
105                                 days++,hours-=24;
106                         while(days>=7)
107                                 weeks++,days-=7;
108
109                         cerr<<taskname<<": "<<_("Line")<<" "<<scanline<<_(" of ")<<h<<" -- ";
110                         //cerr<<time/(h-clk_scanline)<<" ";
111                         /*
112                         if(delta>=-time/(h-clk_scanline)  )
113                                 cerr<<">";
114                         */
115                         if(delta>=0 && clk()>4.0 && scanline>clk_scanline+200)
116                         {
117                                 //cerr<<"reset"<<endl;
118                                 clk.reset();
119                                 clk_scanline=scanline;
120                         }
121
122                         if(weeks)
123                                 /// TRANSLATORS This "w" stands for weeks
124                                 cerr<<weeks<<_("w ");
125                         if(days)
126                                 /// TRANSLATORS This "d" stands for days
127                                 cerr<<days<<_("d ");
128                         if(hours)
129                                 /// TRANSLATORS This "h" stands for hours
130                                 cerr<<hours<<_("h ");
131                         if(minutes)
132                                 /// TRANSLATORS This "m" stands for minutes
133                                 cerr<<minutes<<_("m ");
134                         if(seconds)
135                                 /// TRANSLATORS This "s" stands for seconds
136                                 cerr<<seconds<<_("s ");
137
138                         cerr<<"           \r";
139                 }
140                 else
141                         cerr<<taskname<<": "<<_("DONE")<<"                        "<<endl;;
142                 return true;
143         }
144 };
145
146 #endif