1 /* cclive 2 * Copyright (C) 2010-2013 Toni Gundogdu <legatvs@gmail.com> 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef cclive_progressbar_h 19 #define cclive_progressbar_h 20 21 #include <ccfile> 22 23 namespace cc 24 { 25 class file; 26 27 class progressbar 28 { 29 enum { default_term_width=80 }; 30 public: 31 enum mode { normal = 0, dotline, simple }; 32 public: 33 progressbar(const file&, const quvi::media&); 34 int update(double); 35 void finish(); 36 private: 37 void _normal(const std::stringstream& size_s, 38 const std::stringstream& rate_s, 39 const std::stringstream& eta_s, 40 const int percent, 41 const std::stringstream& percent_s); 42 43 void _dotline(const std::stringstream& size_s, 44 const std::stringstream& rate_s, 45 const std::stringstream& eta_s, 46 const std::stringstream& percent_s); 47 48 void _simple(const std::stringstream& size_s, 49 const std::stringstream& percent_s) const; 50 51 void _render_meter(std::stringstream& bar, 52 const int percent, 53 const size_t space_left); 54 private: 55 double _update_interval; 56 double _expected_bytes; 57 double _initial_bytes; 58 time_t _time_started; 59 time_t _last_update; 60 size_t _term_width; 61 int _dot_count; 62 double _count; 63 size_t _width; 64 file _file; 65 bool _done; 66 mode _mode; 67 }; 68 69 } // cclive namespace 70 71 #endif // cclive_progressbar_h 72 73 // vim: set ts=2 sw=2 tw=72 expandtab: 74