diff --git a/src/gui/moviebrowser/mb.cpp b/src/gui/moviebrowser/mb.cpp index c115364d1..c035ef58c 100644 --- a/src/gui/moviebrowser/mb.cpp +++ b/src/gui/moviebrowser/mb.cpp @@ -2965,7 +2965,6 @@ void CMovieBrowser::updateDir(void) void CMovieBrowser::loadAllTsFileNamesFromStorage(void) { //TRACE("[mb]->loadAllTsFileNamesFromStorage \n"); - size_t i,size; m_movieSelectionHandler = NULL; m_dirNames.clear(); @@ -2973,16 +2972,26 @@ void CMovieBrowser::loadAllTsFileNamesFromStorage(void) updateDir(); + size_t i, size; size = m_dir.size(); - for (i=0; i < size;i++) + + size_t used_dirs = 0; + for (i = 0; i < size;i++) { - if (*m_dir[i].used == true){ - OnGlobalProgress(i, size, m_dir[i].name); + if (*m_dir[i].used) + used_dirs ++; + } + OnSetGlobalMax(used_dirs); + + for (i = 0; i < size; i++) + { + if (*m_dir[i].used) + { loadTsFileNamesFromDir(m_dir[i].name); } } - TRACE("[mb] Dir%d, Files:%d\n", (int)m_dirNames.size(), (int)m_vMovieInfo.size()); + TRACE("[mb] Dir %d, Files: %d, size %u, used_dirs %u\n", (int)m_dirNames.size(), (int)m_vMovieInfo.size(), size, used_dirs); } bool CMovieBrowser::gotMovie(const char *rec_title) @@ -3100,7 +3109,7 @@ bool CMovieBrowser::loadTsFileNamesFromDir(const std::string & dirname) result |= addFile(flist[i], dirItNr); } if (result) - OnLocalProgress(i, count, dirname ); + OnProgress(i, count, dirname ); } //result = true; } @@ -3342,7 +3351,11 @@ void CMovieBrowser::loadMovies(bool doRefresh) struct timeval t1, t2; gettimeofday(&t1, NULL); - CProgressWindow loadBox((show_mode == MB_SHOW_YT) ? LOCALE_MOVIEPLAYER_YTPLAYBACK : LOCALE_MOVIEBROWSER_SCAN_FOR_MOVIES, CCW_PERCENT 50, CCW_PERCENT 10, NULL, show_mode == MB_SHOW_YT ? &ytparser.OnProgress : &OnLocalProgress, &OnGlobalProgress); + CProgressWindowA loadBox((show_mode == MB_SHOW_YT) ? LOCALE_MOVIEPLAYER_YTPLAYBACK : LOCALE_MOVIEBROWSER_SCAN_FOR_MOVIES, + CCW_PERCENT 50, + CCW_PERCENT 10, + show_mode == MB_SHOW_YT ? &ytparser.OnProgress : &OnProgress, + show_mode == MB_SHOW_YT ? NULL : &OnSetGlobalMax); loadBox.enableShadow(); loadBox.paint(); diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index 08aaedd21..07572e210 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -848,51 +848,70 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) } else if (actionKey == "progress_window"){ //classical - CProgressWindow pw0("Progress Single Test"); + CProgressWindow pw0("Test 1: Local Bar Classic"); pw0.paint(); - size_t max = 3; - for(size_t i = 0; i< max; i++){ + size_t max = 4; + for(size_t i = 0; i<= max; i++){ pw0.showStatus(i, max, to_string(i)); sleep(1); } pw0.hide(); - CProgressWindow pw1("Progress Local/Global Test"); + CProgressWindow pw1("Test 2: Local/Global Bars Classic"); pw1.paint(); - for(size_t i = 0; i< max; i++){ + for(size_t i = 1; i<= max; i++){ pw1.showGlobalStatus(i, max, to_string(i)); - for(size_t j = 0; j< max; j++){ + for(size_t j = 1; j<= max; j++){ pw1.showLocalStatus(j, max, to_string(j)); sleep(1); } } + sleep(1); pw1.hide(); //with signals - sigc::signal OnProgress0, OnProgress1; - CProgressWindow pw2("Progress Single Test -> single Signal", CCW_PERCENT 50, CCW_PERCENT 30, &OnProgress0); + sigc::signal OnProgress, OnProgress1; + CProgressWindow pw2("Test 3: Local Bar via Signal/Slot", CCW_PERCENT 50, CCW_PERCENT 30, &OnProgress); pw2.paint(); - for(size_t i = 0; i< max; i++){ - OnProgress0(i, max, to_string(i)); + for(size_t i = 0; i<= max; i++){ + OnProgress(i, max, to_string(i)); sleep(1); } + sleep(1); pw2.hide(); - OnProgress0.clear(); + OnProgress.clear(); OnProgress1.clear(); - CProgressWindow pw3("Progress Single Test -> dub Signal", CCW_PERCENT 50, CCW_PERCENT 20, NULL, &OnProgress0, &OnProgress1); + CProgressWindow pw3("Test 4: Local/Global via Signal/Slot", CCW_PERCENT 50, CCW_PERCENT 20, &OnProgress, &OnProgress1); pw3.paint(); - for(size_t i = 0; i< max; i++){ + for(size_t i = 1; i <= max; i++){ OnProgress1(i, max, to_string(i)); - for(size_t j = 0; j< max; j++){ - OnProgress0(j, max, to_string(j)); + for(size_t j = 1; j<= 7; j++){ + OnProgress(j, 7, to_string(j)); sleep(1); } } + sleep(1); pw3.hide(); + OnProgress.clear(); + //sigc::signal OnSetGlobalMax; + + CProgressWindowA pw4("Test 5, Local/Adaptive Global", CCW_PERCENT 50, CCW_PERCENT 20, &OnProgress, NULL/*&OnSetGlobalMax*/); + pw4.paint(); + //OnSetGlobalMax(max); + pw4.setGlobalMax(max); + for(size_t i = 1; i <= max; i++){ + for(size_t j = 1; j<= 8; j++){ + pw4.showStatus(j, 8, to_string(j)); + sleep(1); + } + } + sleep(1); + pw4.hide(); + return menu_return::RETURN_REPAINT; } else if (actionKey == "hintbox_test") diff --git a/src/gui/widget/progresswindow.cpp b/src/gui/widget/progresswindow.cpp index 19fd6568a..0c25cd43f 100644 --- a/src/gui/widget/progresswindow.cpp +++ b/src/gui/widget/progresswindow.cpp @@ -40,39 +40,37 @@ using namespace std; CProgressWindow::CProgressWindow(CComponentsForm *parent, const int &dx, const int &dy, - signal *statusSignal, signal *localSignal, signal *globalSignal) : CComponentsWindow(0, 0, dx, dy, string(), NEUTRINO_ICON_INFO, parent, CC_SHADOW_ON) { - Init(statusSignal, localSignal, globalSignal); + Init(NULL, localSignal, globalSignal, NULL); } CProgressWindow::CProgressWindow(const neutrino_locale_t title, const int &dx, const int &dy, - signal *statusSignal, signal *localSignal, signal *globalSignal) : CComponentsWindow(0, 0, dx, dy, g_Locale->getText(title), NEUTRINO_ICON_INFO, NULL, CC_SHADOW_ON) { - Init(statusSignal, localSignal, globalSignal); + Init(NULL, localSignal, globalSignal, NULL); } CProgressWindow::CProgressWindow(const std::string &title, const int &dx, const int &dy, - signal *statusSignal, signal *localSignal, signal *globalSignal) : CComponentsWindow(0, 0, dx, dy, title, NEUTRINO_ICON_INFO, NULL, CC_SHADOW_ON) { - Init(statusSignal, localSignal, globalSignal); + Init(NULL, localSignal, globalSignal, NULL); } void CProgressWindow::Init( signal *statusSignal, signal *localSignal, - signal *globalSignal) + signal *globalSignal, + signal *globalSet) { if (statusSignal) *statusSignal->connect(mem_fun(*this, &CProgressWindow::showStatus)); @@ -83,6 +81,13 @@ void CProgressWindow::Init( signal *statusSignal, global_progress = local_progress = 0; + if (globalSet) + *globalSet->connect(mem_fun(*this, &CProgressWindow::setGlobalMax)); + else + global_max = 0; + + internal_max = 0; + showFooter(false); //create status text object @@ -133,7 +138,7 @@ CProgressBar* CProgressWindow::getProgressItem() void CProgressWindow::initStatus(const unsigned int prog, const unsigned int max, const string &statusText, CProgressBar *pBar) { pBar->allowPaint(true); - pBar->setValues(prog, (int)max); + pBar->setValues(prog/* + (prog % 2)*/, (int)/*max + (*/max/* % 2)*/); if (!statusText.empty() && (cur_statusText != statusText)){ showStatusMessageUTF(statusText); cur_statusText = statusText; @@ -145,6 +150,13 @@ void CProgressWindow::initStatus(const unsigned int prog, const unsigned int max void CProgressWindow::showStatus(const unsigned int prog, const unsigned int max, const string &statusText) { showLocalStatus(prog, max, statusText); + + if(global_max > 1){ + global_progress ++; + internal_max = std::max((int)max, (int)internal_max); + internal_max -= (max != internal_max) ? internal_max/max : 0; + initStatus(global_progress, global_max*internal_max, statusText, global_bar); + } } void CProgressWindow::showGlobalStatus(const unsigned int prog, const unsigned int max, const string &statusText) @@ -245,4 +257,4 @@ void CProgressWindow::fitItems() int y_item = ccw_body->getCCItem(i)->getYPos() + h_height - OFFSET_INNER_MID; ccw_body->getCCItem(i)->setYPos(y_item); } -} \ No newline at end of file +} diff --git a/src/gui/widget/progresswindow.h b/src/gui/widget/progresswindow.h index fed2bd940..6a689e6ca 100644 --- a/src/gui/widget/progresswindow.h +++ b/src/gui/widget/progresswindow.h @@ -41,177 +41,56 @@ class CProgressWindow : public CComponentsWindow, public CMenuTarget unsigned int local_progress; std::string cur_statusText; int h_height; - void Init( sigc::signal *statusSignal, - sigc::signal *localSignal, - sigc::signal *globalSignal); CProgressBar* getProgressItem(); void initStatus(const unsigned int prog, const unsigned int max, const std::string &statusText, CProgressBar *pBar); void fitItems(); + protected: + size_t global_max, internal_max; + + void Init( sigc::signal *statusSignal, + sigc::signal *localSignal, + sigc::signal *globalSignal, + sigc::signal *globalSet); + public: /**CProgressWindow Constructor * @param[in] parent - * @li optional: expects type CComponentsForm * as possible parent object, default = NULL + * @li optional: expects type CComponentsForm * as parent object, default = NULL * @param[in] dx * @li optional: expects type const &int, width of window, default = 0, auto size with declared default values * @param[in] dy - * @li optional: expects type const &int, height of window, default = 0, auto size with declared default values - * @param[in] status_Signal - * @li optional: expects type sigc::signal, defines an optional signal container for - * current changing values. * @param[in] localSignal - * @li optional: expects type sigc::signal, defines an optional signal container for + * @li optional: expects pointer of to sigc::signal, defines an optional signal container for * current changing local values. * @param[in] globalSignal - * @li optional: expects type sigc::signal, defines an optional signal container for + * @li optional: expects pointer of to sigc::signal, defines an optional signal container for * current changing global values. - * - * @example - * void CFooClass::DoCount{ - * //Usage with classic init inside method: - * - * //Create a CProgressWindow object - * CProgressWindow progress; - * - * //set possible properties, eg. like here we dont't need a header - * status.showHeader(false); - * - * //paint window - * status.paint(); - * - * //set possible properties, like current status text - * status.showStatusMessageUTF("test progress"); - * - * //set current progress, call functions, methods or use a while, next loop or what ever - * status.showStatus(25) - * - * //finally remove window from screen - * status.hide(); - * } - * - * //That's it. Until now these steps are a classical way inside neutrino, but you can use proress window with signals too. - * //Working with signals have the advantage that the implementation could be more compactly, because - * //complex constructions within the classes are usually unnecessary, - * //beacuse of the signals can be installed where they directly catching the required values. See next example: - * - * class CFooClass - * { - * //Usage with signals: - * //declare a signal eg. in header file - * private: - * //other members... - * sigc::signal OnProgress; - * void DoCount(); - * //other members... - * public: - * //other members... - * void DoAnything(); - * //other members... - * }; - * - * //add the OnProgress signal into a counter methode - * void CFooClass::DoCount{ - * size_t max = 10 - * for (size_t i = 0; i < max; i++){ - * OnProgress(i, max, "Test"); - * } - * } - * - * void CFooClass::DoAnything{ - * //inside of methode which calls the progress define a CProgressWindow object and the counter method: - * //...any code - * CProgressWindow progress(NULL, 500, 150, &OnProgress); - * //paint window - * progress.paint(); // paint() - * - * //... - * - * DoCount(); - * - * //... - * - * //finally remove window from screen - * progress.hide(); - * } - * - * //Another and a recommended way to implement signals is to inherit prepared signals with - * //class CProgressSignals. This class contains prepared signals for implemantation and disconnetion of slots - * //is performed automatically. - * //See next example: - * class CFooClass : public CProgressSignals - * { - * private: - * //other members... - * void DoCount(); - * //other members... - * public: - * //other members... - * void DoAnything(); - * //other members... - * }; - * - * //add the OnGlobalProgress and OnLocalProgress signals into a counter methode - * void CFooClass::DoCount();{ - * size_t max = 10; - * for (size_t i = 0; i < max; i++){ - * OnGlobalProgress(i, max, "Test"); //visualize global progress - * for (size_t j = 0; j < max; j++){ - * OnLocalProgress(ij, max, "Test"); // visualize local progress - * } - * } - * } - * - * void CFooClass::DoAnything{ - * //inside of methode which calls the progress define a CProgressWindow object and the counter method: - * //...any code - * CProgressWindow progress(NULL, 500, 150, NULL, &OnLocalProgress, &OnGlobalProgress); - * progress.paint(); // paint window - * - * //... - * - * void DoCount(); - * - * //... - * - * //finally remove window from screen - * progress.hide(); - * } - * - * @note - * Don't use status_Signal at same time with localSignal and globalSignal. \n - * In This case please set prameter 'status_Signal' = NULL */ CProgressWindow(CComponentsForm *parent = NULL, const int &dx = PW_MIN_WIDTH, const int &dy = PW_MIN_HEIGHT, - sigc::signal *status_Signal = NULL, sigc::signal *localSignal = NULL, sigc::signal *globalSignal = NULL); - /**CProgressWindow Constructor - * @param[in] title - * @li expects type neutrino_locale_t as window title - * - * @see For other arguments and examples, see related constructor(s) + /**CProgressWindowA Constructor + * @see For common arguments and examples, see related constructor(s)\n + * For general parameters see basic class CProgressWindow! */ CProgressWindow(const neutrino_locale_t title, const int &dx = PW_MIN_WIDTH, const int &dy = PW_MIN_HEIGHT, - sigc::signal *status_Signal = NULL, sigc::signal *localSignal = NULL, sigc::signal *globalSignal = NULL); /**CProgressWindow Constructor - * @param[in] title - * @li expects type std::string as window title - * - * @see For other arguments and examples, see related constructor(s) + * @see For common arguments and examples, see related constructor(s)\n + * For general parameters see basic class CProgressWindow! */ CProgressWindow(const std::string &title, const int &dx = PW_MIN_WIDTH, const int &dy = PW_MIN_HEIGHT, - sigc::signal *status_Signal = NULL, sigc::signal *localSignal = NULL, sigc::signal *globalSignal = NULL); @@ -242,17 +121,6 @@ class CProgressWindow : public CComponentsWindow, public CMenuTarget */ virtual int exec( CMenuTarget* parent, const std::string & actionKey ); - /** - * Sets current progress value and show progress in window. - * @param[in] prog - * @li expects type unsigned int, describes current progress value - * @param[in] max - * @li optional: expects type unsigned int, describes maximal progress value, default = 100 - * @param[in] statusText - * @li optional: expects type std::string, describes current status text, default = empty - */ - void showStatus(const unsigned int prog, const unsigned int max = 100, const std::string &statusText = std::string()); - /** * Sets current local progressbar value and show progress in window. * @note For other arguments take a look to related method showStatus() @@ -273,6 +141,28 @@ class CProgressWindow : public CComponentsWindow, public CMenuTarget */ unsigned int getGlobalStatus(void); + /** + * Sets current progress value and shows a single progress bar inside window as default, but allows + * to show a global bar too. If you want to show a global bar, the global max value must be predefined with setGlobalMax() method. + * A defined global max value causes a gentle display of global progress. This assumes, the numbering fits to the scaned progress. + * @param[in] prog + * @li expects type unsigned int, describes current progress value + * @param[in] max + * @li optional: expects type unsigned int, describes maximal progress value, default = 100 + * @param[in] statusText + * @li optional: expects type std::string, describes current status text, default = empty + * + * @see setGlobalMax(), CProgressSignals::OnSetGlobalMax() + */ + void showStatus(const unsigned int prog, const unsigned int max = 100, const std::string &statusText = std::string()); + + /** + * Sets current maximal value for global progress in window. + * @param[in] global_Max + * @li expects type size_t + */ + void setGlobalMax(const size_t& global_Max){global_max = global_Max;} + /** * Sets current progress value and show progress in window. * @param[in] text @@ -288,6 +178,44 @@ class CProgressWindow : public CComponentsWindow, public CMenuTarget void paint(const bool &do_save_bg = true); }; +class CProgressWindowA : public CProgressWindow +{ + public: + /**CProgressWindowA Constructor + * @see For common arguments and examples, see related constructor(s)\n + * For general parameters see basic class CProgressWindow! + * + * @param[in] status_Signal + * @li optional: expects pointer of type sigc::signal, defines an optional signal container for + * current changing values. + * @param[in] globalSet + * @li optional: expects pointer of type sigc::signal, defines an optional signal container for global values. + */ + CProgressWindowA(const neutrino_locale_t title, + const int &dx = PW_MIN_WIDTH, + const int &dy = PW_MIN_HEIGHT, + sigc::signal *status_Signal = NULL, + sigc::signal *globalSet = NULL) + : CProgressWindow(title, dx, dy, NULL, NULL) + { + Init(status_Signal, NULL, NULL, globalSet); + }; + + /**CProgressWindowA Constructor + * @see For common arguments and examples, see related constructor(s)! + * For general parameters see basic class CProgressWindow! + */ + CProgressWindowA(const std::string &title, + const int &dx = PW_MIN_WIDTH, + const int &dy = PW_MIN_HEIGHT, + sigc::signal *status_Signal = NULL, + sigc::signal *globalSet = NULL) + : CProgressWindow(title, dx, dy, NULL, NULL) + { + Init(status_Signal, NULL, NULL, globalSet); + }; +}; + class CProgressSignals : public sigc::trackable { public: @@ -307,6 +235,183 @@ class CProgressSignals : public sigc::trackable * @see Take a look into examples to find in progressbar.h */ sigc::signal OnProgress, OnLocalProgress, OnGlobalProgress; + sigc::signal OnSetGlobalMax; }; #endif + +/**CProgressWindow usage with classic method:\n +* This is the general used method to implement progress bar windows. +* @example Progresswindow +* +* void CFooClass::DoCount +* { +* // Create a CProgressWindow object +* CProgressWindow progress; +* +* // set possible properties, eg. like here we dont't need a header +* status.showHeader(false); +* +* // paint window +* status.paint(); +* +* // set possible properties, like current status text +* status.showStatusMessageUTF("test progress"); +* +* // set current progress, call functions, methods or use a while, next loop or what ever +* status.showStatus(25) +* +* // finally remove window from screen +* status.hide(); +* } +* +* // ...That's it. Until now these steps are a classical way inside neutrino, but you can use progress window with signals too. +* // Working with signals have the advantage that the implementation could be more compactly, because +* // complex constructions within the classes are usually unnecessary, +* // beacuse of the signals can be installed where they directly catching the required values. See next examples: +* +* @see +* * Progresswindow:Signals:1\n +* * Progresswindow:Signals:2\n +* * Progresswindow:Adaptive +*/ + +/**CProgressWindow usage with signals +* @example Progresswindow:Signals:1 +* +* class CFooClass +* { +* //declare a signal eg. in header file +* private: +* // other members... +* sigc::signal OnProgress; +* void DoCount(); +* // other members... +* public: +* // other members... +* void DoAnything(); +* // other members... +* }; +* +* // add the 'OnProgress' signal into a counter methode +* void CFooClass::DoCount{ +* size_t max = 10 +* for (size_t i = 0; i < max; i++){ +* OnProgress(i, max, "Test"); +* } +* } +* +* void CFooClass::DoAnything{ +* // inside of methode which calls the progress define a CProgressWindow object and the counter method: +* // ...any code +* CProgressWindow progress(NULL, 500, 150, &OnProgress); +* // paint window +* progress.paint(); // paint() +* +* // ... +* +* DoCount(); +* +* // ... +* +* // finally remove window from screen +* progress.hide(); +* } +*/ + +/**CProgressWindow usage with inherited signals +* @example Progresswindow:Signals:2 +* +* // Another and a recommended way to implement signals is to inherit prepared signals with +* // 'class CProgressSignals'. This class contains prepared signals for implemantation and disconnetion of slots +* // is performed automatically. +* // See next example: +* class CFooClass : public CProgressSignals +* { +* private: +* // other members... +* void DoCount(); +* // other members... +* public: +* // other members... +* void DoAnything(); +* // other members... +* }; +* +* // add the 'OnGlobalProgress' and 'OnLocalProgress' signals into a counter methode +* void CFooClass::DoCount();{ +* size_t max = 10; +* for (size_t i = 0; i < max; i++){ +* OnGlobalProgress(i, max, "Test"); //visualize global progress +* for (size_t j = 0; j < max; j++){ +* OnLocalProgress(ij, max, "Test"); // visualize local progress +* } +* } +* } +* +* void CFooClass::DoAnything{ +* // inside of methode which calls the progress define a CProgressWindow object and the counter method: +* // ...any code +* CProgressWindow progress(NULL, 500, 150, NULL, &OnLocalProgress, &OnGlobalProgress); +* // paint window +* progress.paint(); +* +* // ... +* +* void DoCount(); +* +* // ... +* +* // finally remove window from screen +* progress.hide(); +* } +*/ + +/**CProgressWindow usage with adaptive global progress +* @example Progresswindow:Adaptive +* +* // Use this for local progress views with adaptive global status. +* // This allows an adjusted global progress with more 'smoother' progress view. Here the global progress +* // is calculated inside the progressbar object itself. This requires a call for the local progress and +* // an assignment of global maximum value. +* // Note: Global progressbar is only visible if global value > 1! +* +* class CFooClass +* { +* private: +* // other members... +* // If You want to use signals, declare signals or inherit 'class CProgressSignals' (e.g: 'class CFooClass : public CProgressSignals') +* sigc::signal OnProgress; +* sigc::signal OnSetGlobalMax; +* // other members... +* public: +* // other members... +* void DoCount(); +* // other members... +* }; +* +* void CFooClass::DoCount() +* { +* size_t max = 10 +* CProgressWindowA pw("Test", CCW_PERCENT 50, CCW_PERCENT 20, NULL, NULL); +* pw.paint(); +* +* // Set the maximal global value: +* // Here global value is set directly with 'setGlobalMax()' inside 'DoCount()', but for scanning for global +* // values it's also possible to use the 'OnSetGlobalMax()' signal +* // outside of counter methode in any other method. +* // An example for usage of OnSetGlobalMax() is to find in 'gui/moviebrowser/mp.cpp' +* // To see the visual difference to general progress take a look into test menu and try out Test 4 and 5. +* // Note: Without assigned global max value, no global bar is visible, means: Only local progress is showed! +* pw.setGlobalMax(max); +* +* for(size_t i = 1; i <= max; i++){ +* for(size_t j = 1; j<= 8; j++){ +* pw.showStatus(j, 8, to_string(j)); +* sleep(1); +* } +* } +* sleep(1); +* pw.hide(); +* } +*/