1 #include "bcprogressbox.h"
3 #include "mainprogress.h"
5 #include "mwindowgui.h"
11 MainProgressBar::MainProgressBar(MWindow *mwindow, MainProgress *mainprogress)
15 this->mwindow = mwindow;
16 this->mainprogress = mainprogress;
17 eta_timer = new Timer;
20 MainProgressBar::~MainProgressBar()
22 if(progress_box) delete progress_box;
24 if(mainprogress->mwindow_progress == this)
26 mainprogress->mwindow_progress = 0;
30 mainprogress->progress_bars.remove(this);
35 void MainProgressBar::start()
39 progress_box->start();
45 void MainProgressBar::stop_progress()
49 progress_box->stop_progress();
54 progress_bar->update(0);
55 mwindow->gui->statusbar->default_message();
59 int MainProgressBar::is_cancelled()
63 //printf("MainProgressBar::is_cancelled 1 %d\n", progress_box->is_cancelled());
64 return progress_box->is_cancelled();
69 return mainprogress->cancelled;
75 void MainProgressBar::update_title(char *string, int default_)
77 if(default_) strcpy(default_title, string);
78 //printf("MainProgressBar::update_title %p %p %s\n", progress_bar, progress_box, string);
82 progress_box->update_title(string, 1);
87 mwindow->gui->lock_window("MainProgressBar::update_title");
88 mwindow->gui->show_message(string);
89 mwindow->gui->unlock_window();
93 void MainProgressBar::update_length(int64_t length)
95 this->length = length;
96 //printf("MainProgressBar::update_length %d\n", length);
99 progress_box->update_length(length, 1);
104 mwindow->gui->lock_window("MainProgressBar::update_length");
105 progress_bar->update_length(length);
106 mwindow->gui->unlock_window();
110 int MainProgressBar::update(int64_t value)
112 // Print ETA on title
113 double current_eta = (double)eta_timer->get_scaled_difference(1000);
115 //printf("MainProgressBar::update %f %f %f\n", current_eta, last_eta, current_eta - last_eta);
116 if(current_eta - last_eta > 1000)
118 char string[BCTEXTLEN];
119 char time_string[BCTEXTLEN];
123 eta = (double)current_eta /
132 //printf("MainProgressBar::update %f %d %d %f\n", current_eta, length, value, eta);
133 Units::totext(time_string,
136 // sprintf(time_string,
138 // (int64_t)eta / 3600,
139 // ((int64_t)eta / 60) % 60,
140 // (int64_t)eta % 60);
142 sprintf(string, _("%s ETA: %s"),
145 update_title(string, 0);
147 last_eta = (int64_t)current_eta;
152 progress_box->update(value, 1);
157 mwindow->gui->lock_window("MainProgressBar::update");
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);
174 double MainProgressBar::get_time()
176 return (double)eta_timer->get_scaled_difference(1);
189 MainProgress::MainProgress(MWindow *mwindow, MWindowGUI *gui)
191 this->mwindow = mwindow;
193 mwindow_progress = 0;
198 MainProgress::~MainProgress()
202 MainProgressBar* MainProgress::start_progress(char *text,
203 int64_t total_length,
206 MainProgressBar *result = 0;
208 // Default to main window
209 if(!mwindow_progress && !use_window)
211 mwindow_progress = new MainProgressBar(mwindow, this);
212 mwindow_progress->progress_bar = gui->statusbar->main_progress;
213 mwindow_progress->progress_bar->update_length(total_length);
214 mwindow_progress->update_title(text);
215 result = mwindow_progress;
221 result = new MainProgressBar(mwindow, this);
222 progress_bars.append(result);
223 result->progress_box = new BC_ProgressBox(gui->get_abs_cursor_x(1),
224 gui->get_abs_cursor_y(1),
229 result->length = total_length;
230 strcpy(result->default_title, text);
236 void MainProgress::end_progress(MainProgressBar* progress_bar)
238 if(mwindow_progress == progress_bar)
240 delete mwindow_progress;
241 mwindow_progress = 0;
246 progress_bars.remove(progress_bar);