1 #include "bcprogressbox.h"
2 #include "mainprogress.h"
4 #include "mwindowgui.h"
11 #define _(String) gettext(String)
12 #define gettext_noop(String) String
13 #define N_(String) gettext_noop (String)
15 MainProgressBar::MainProgressBar(MWindow *mwindow, MainProgress *mainprogress)
19 this->mwindow = mwindow;
20 this->mainprogress = mainprogress;
21 eta_timer = new Timer;
24 MainProgressBar::~MainProgressBar()
26 if(progress_box) delete progress_box;
28 if(mainprogress->mwindow_progress == this)
30 mainprogress->mwindow_progress = 0;
34 mainprogress->progress_bars.remove(this);
39 void MainProgressBar::start()
43 progress_box->start();
49 void MainProgressBar::stop_progress()
53 progress_box->stop_progress();
58 progress_bar->update(0);
59 mwindow->gui->statusbar->default_message();
63 int MainProgressBar::is_cancelled()
67 //printf("MainProgressBar::is_cancelled 1 %d\n", progress_box->is_cancelled());
68 return progress_box->is_cancelled();
73 return mainprogress->cancelled;
79 void MainProgressBar::update_title(char *string, int default_)
81 if(default_) strcpy(default_title, string);
82 //printf("MainProgressBar::update_title %p %p %s\n", progress_bar, progress_box, string);
86 progress_box->lock_window();
87 progress_box->update_title(string);
88 progress_box->unlock_window();
93 mwindow->gui->lock_window();
94 mwindow->gui->show_message(string, BLACK);
95 mwindow->gui->unlock_window();
99 void MainProgressBar::update_length(long length)
101 this->length = length;
102 //printf("MainProgressBar::update_length %d\n", length);
105 progress_box->lock_window();
106 progress_box->update_length(length);
107 progress_box->unlock_window();
112 mwindow->gui->lock_window();
113 progress_bar->update_length(length);
114 mwindow->gui->unlock_window();
118 int MainProgressBar::update(long value)
120 // Print ETA on title
121 double current_eta = (double)eta_timer->get_scaled_difference(1000);
123 //printf("MainProgressBar::update %f %f %f\n", current_eta, last_eta, current_eta - last_eta);
124 if(current_eta - last_eta > 1000)
126 char string[BCTEXTLEN];
127 char time_string[BCTEXTLEN];
131 eta = (double)current_eta / 1000 * length / value - current_eta / 1000;
135 //printf("MainProgressBar::update %f %d %d %f\n", current_eta, length, value, eta);
136 Units::totext(time_string,
140 sprintf(string, _("%s ETA: %s"),
143 update_title(string, 0);
145 last_eta = (long)current_eta;
150 progress_box->lock_window();
151 progress_box->update(value);
152 progress_box->unlock_window();
157 mwindow->gui->lock_window();
158 progress_bar->update(value);
159 mwindow->gui->unlock_window();
162 return is_cancelled();
165 void MainProgressBar::get_time(char *text)
167 double current_time = (double)eta_timer->get_scaled_difference(1);
168 //printf("MainProgressBar::get_time %f\n", current_time);
185 MainProgress::MainProgress(MWindow *mwindow, MWindowGUI *gui)
187 this->mwindow = mwindow;
189 mwindow_progress = 0;
194 MainProgress::~MainProgress()
198 MainProgressBar* MainProgress::start_progress(char *text, long total_length)
200 MainProgressBar *result = 0;
202 // Default to main window
203 if(!mwindow_progress)
205 mwindow_progress = new MainProgressBar(mwindow, this);
206 mwindow_progress->progress_bar = gui->statusbar->main_progress;
207 mwindow_progress->progress_bar->update_length(total_length);
208 mwindow_progress->update_title(text);
209 result = mwindow_progress;
215 result = new MainProgressBar(mwindow, this);
216 progress_bars.append(result);
217 result->progress_box = new BC_ProgressBox(gui->get_abs_cursor_x(),
218 gui->get_abs_cursor_y(),
223 result->length = total_length;
224 strcpy(result->default_title, text);
230 void MainProgress::end_progress(MainProgressBar* progress_bar)
232 if(mwindow_progress == progress_bar)
234 delete mwindow_progress;
235 mwindow_progress = 0;
240 progress_bars.remove(progress_bar);