Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mainprogress.C

Go to the documentation of this file.
00001 #include "bcprogressbox.h"
00002 #include "language.h"
00003 #include "mainprogress.h"
00004 #include "mwindow.h"
00005 #include "mwindowgui.h"
00006 #include "statusbar.h"
00007 #include "bctimer.h"
00008 
00009 #include <string.h>
00010 
00011 MainProgressBar::MainProgressBar(MWindow *mwindow, MainProgress *mainprogress)
00012 {
00013         progress_box = 0;
00014         progress_bar = 0;
00015         this->mwindow = mwindow;
00016         this->mainprogress = mainprogress;
00017         eta_timer = new Timer;
00018 }
00019 
00020 MainProgressBar::~MainProgressBar()
00021 {
00022         if(progress_box) delete progress_box;
00023 
00024         if(mainprogress->mwindow_progress == this)
00025         {
00026                 mainprogress->mwindow_progress = 0;
00027         }
00028         else
00029         {
00030                 mainprogress->progress_bars.remove(this);
00031         }
00032         delete eta_timer;
00033 }
00034 
00035 void MainProgressBar::start()
00036 {
00037         if(progress_box)
00038         {
00039                 progress_box->start();
00040         }
00041         eta_timer->update();
00042         last_eta = 0;
00043 }
00044 
00045 void MainProgressBar::stop_progress()
00046 {
00047         if(progress_box)
00048         {
00049                 progress_box->stop_progress();
00050         }
00051         else
00052         if(progress_bar)
00053         {
00054                 progress_bar->update(0);
00055                 mwindow->gui->statusbar->default_message();
00056         }
00057 }
00058 
00059 int MainProgressBar::is_cancelled()
00060 {
00061         if(progress_box)
00062         {
00063 //printf("MainProgressBar::is_cancelled 1 %d\n", progress_box->is_cancelled());
00064                 return progress_box->is_cancelled();
00065         }
00066         else
00067         if(progress_bar)
00068         {
00069                 return mainprogress->cancelled;
00070         }
00071 
00072         return 0;
00073 }
00074 
00075 void MainProgressBar::update_title(char *string, int default_)
00076 {
00077         if(default_) strcpy(default_title, string);
00078 //printf("MainProgressBar::update_title %p %p %s\n", progress_bar, progress_box, string);
00079 
00080         if(progress_box)
00081         {
00082                 progress_box->update_title(string, 1);
00083         }
00084         else
00085         if(progress_bar)
00086         {
00087                 mwindow->gui->lock_window("MainProgressBar::update_title");
00088                 mwindow->gui->show_message(string);
00089                 mwindow->gui->unlock_window();
00090         }
00091 }
00092 
00093 void MainProgressBar::update_length(int64_t length)
00094 {
00095         this->length = length;
00096 //printf("MainProgressBar::update_length %d\n", length);
00097         if(progress_box)
00098         {
00099                 progress_box->update_length(length, 1);
00100         }
00101         else
00102         if(progress_bar)
00103         {
00104                 mwindow->gui->lock_window("MainProgressBar::update_length");
00105                 progress_bar->update_length(length);
00106                 mwindow->gui->unlock_window();
00107         }
00108 }
00109 
00110 int MainProgressBar::update(int64_t value)
00111 {
00112 // Print ETA on title
00113         double current_eta = (double)eta_timer->get_scaled_difference(1000);
00114 
00115 //printf("MainProgressBar::update %f %f %f\n", current_eta, last_eta, current_eta - last_eta);
00116         if(current_eta - last_eta > 1000)
00117         {
00118                 char string[BCTEXTLEN];
00119                 char time_string[BCTEXTLEN];
00120                 double eta;
00121 
00122                 if(value > 0.001)
00123                         eta = (double)current_eta / 
00124                                 1000 * 
00125                                 length / 
00126                                 value - 
00127                                 current_eta / 
00128                                 1000;
00129                 else
00130                         eta = 0;
00131 
00132 //printf("MainProgressBar::update %f %d %d %f\n", current_eta, length, value, eta);
00133                 Units::totext(time_string, 
00134                         eta,
00135                         TIME_HMS2);
00136 //              sprintf(time_string, 
00137 //                      "%dh%dm%ds", 
00138 //                      (int64_t)eta / 3600,
00139 //                      ((int64_t)eta / 60) % 60,
00140 //                      (int64_t)eta % 60);
00141 
00142                 sprintf(string, _("%s ETA: %s"), 
00143                         default_title, 
00144                         time_string);
00145                 update_title(string, 0);
00146 
00147                 last_eta = (int64_t)current_eta;
00148         }
00149 
00150         if(progress_box)
00151         {
00152                 progress_box->update(value, 1);
00153         }
00154         else
00155         if(progress_bar)
00156         {
00157                 mwindow->gui->lock_window("MainProgressBar::update");
00158                 progress_bar->update(value);
00159                 mwindow->gui->unlock_window();
00160         }
00161 
00162         return is_cancelled();
00163 }
00164 
00165 void MainProgressBar::get_time(char *text)
00166 {
00167         double current_time = (double)eta_timer->get_scaled_difference(1);
00168 //printf("MainProgressBar::get_time %f\n", current_time);
00169         Units::totext(text, 
00170                         current_time,
00171                         TIME_HMS2);
00172 }
00173 
00174 double MainProgressBar::get_time()
00175 {
00176         return (double)eta_timer->get_scaled_difference(1);
00177 }
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 MainProgress::MainProgress(MWindow *mwindow, MWindowGUI *gui)
00190 {
00191         this->mwindow = mwindow;
00192         this->gui = gui;
00193         mwindow_progress = 0;
00194         cancelled = 0;
00195 }
00196 
00197 
00198 MainProgress::~MainProgress()
00199 {
00200 }
00201 
00202 MainProgressBar* MainProgress::start_progress(char *text, 
00203         int64_t total_length,
00204         int use_window)
00205 {
00206         MainProgressBar *result = 0;
00207 
00208 // Default to main window
00209         if(!mwindow_progress && !use_window)
00210         {
00211                 mwindow_progress = new MainProgressBar(mwindow, this);
00212                 mwindow_progress->progress_bar = gui->statusbar->main_progress;
00213                 mwindow_progress->progress_bar->update_length(total_length);
00214                 mwindow_progress->update_title(text);
00215                 result = mwindow_progress;
00216                 cancelled = 0;
00217         }
00218 
00219         if(!result)
00220         {
00221                 result = new MainProgressBar(mwindow, this);
00222                 progress_bars.append(result);
00223                 result->progress_box = new BC_ProgressBox(gui->get_abs_cursor_x(1), 
00224                         gui->get_abs_cursor_y(1), 
00225                         text, 
00226                         total_length);
00227         }
00228 
00229         result->length = total_length;
00230         strcpy(result->default_title, text);
00231         result->start();
00232         return result;
00233 }
00234 
00235 
00236 void MainProgress::end_progress(MainProgressBar* progress_bar)
00237 {
00238         if(mwindow_progress == progress_bar)
00239         {
00240                 delete mwindow_progress;
00241                 mwindow_progress = 0;
00242         }
00243         else
00244         {
00245                 delete progress_bar;
00246                 progress_bars.remove(progress_bar);
00247         }
00248 }

Generated on Sun Jan 8 13:38:56 2006 for Cinelerra-svn by  doxygen 1.4.4