[Timer] Remove overriding Counter class methods 62/158062/2
authorKamil Lipiszko <k.lipiszko@samsung.com>
Fri, 27 Oct 2017 12:16:21 +0000 (14:16 +0200)
committerKamil Lipiszko <k.lipiszko@samsung.com>
Fri, 27 Oct 2017 12:27:57 +0000 (14:27 +0200)
Replaces all private time properties with duration provided by
parent Counter class.

Change-Id: Ib5f2e1a880796a9d769246ce8e3504d7097dca59

clock/inc/Model/Timer.h
clock/src/Model/Timer.cpp
clock/src/Presenter/TimerPresenter.cpp

index 215212b8fa2f2efa6f1e87181f459d494ea198dc..1e80010a90ffa5f2586aa7fa78525d22ae6dcd8c 100644 (file)
@@ -40,65 +40,12 @@ namespace model {
                Timer();
                ~Timer();
 
-               /**
-                * @brief Sets timer's amount of hours
-                *
-                * This value is added to the whole timer's countdown time.
-                * After it reaches 0, the timer's ring alarm is called.
-                *
-                * @param[in] hour The hour to be set
-                */
-               void SetHour(int hour);
-
-               /**
-                * @brief Sets timer's amount of minutes
-                *
-                * This value is added to the whole timer's countdown time.
-                * After it reaches 0, the timer's ring alarm is called.
-                *
-                * @param[in] minute The minute to be set
-                */
-               void SetMinute(int minute);
-
-               /**
-                * @brief Sets timer's amount of seconds
-                *
-                * This value is added to the whole timer's countdown time.
-                * After it reaches 0, the timer's ring alarm is called.
-                *
-                * @param[in] second The second to be set
-                */
-               void SetSecond(int second);
-
-               /**
-                * @brief Gets timer's hour
-                *
-                * @return Number of timer's hours
-                */
-               unsigned GetHour(void) const;
-
-               /**
-                * @brief Gets timer's minutes
-                *
-                * @return Number of timer's minutes
-                */
-               unsigned GetMinute(void) const;
-
-               /**
-                * @brief Gets timer's seconds
-                *
-                * @return Number of timer's seconds
-                */
-               unsigned GetSecond(void) const;
-
                /**
                 * @brief Sets total timer's countdown time
                 *
-                * @param[in] hour The timer's hour
-                * @param[in] minute The timer's minute
-                * @param[in] second The timer's second
+                * @param[in] time Time in seconds
                 */
-               void SetTime(int hour, int minute, int second);
+               void SetTime(seconds time);
 
                /**
                 * @brief Activates alarm after delay.
@@ -131,11 +78,9 @@ namespace model {
                 */
                seconds GetRemainingTime(void);
        private:
-               unsigned hour_;
-               unsigned minute_;
-               unsigned second_;
+               seconds remaining_time_ = seconds(0);
 
-               int alarm_id_;
+               int alarm_id_ = 0;
 
                static app_control_h CreateAppControl(void);
        };
index 97d34ab06546a402318671d3062ee52aed17b7a7..6e7a884e9ffa7d5def1c2f4e9ef6fdd2d652f012 100644 (file)
@@ -22,7 +22,7 @@
 
 namespace model {
 
-Timer::Timer() : hour_(0), minute_(0), second_(0), alarm_id_(0)
+Timer::Timer()
 {
 }
 
@@ -30,63 +30,14 @@ Timer::~Timer()
 {
 }
 
-void Timer::SetHour(int hour)
+void Timer::SetTime(seconds time)
 {
-       if (hour > 99)
-               hour = 0;
-       else if (hour < 0)
-               hour = 99;
-
-       hour_ = hour;
-}
-
-void Timer::SetMinute(int minute)
-{
-       if (minute > 59)
-               minute = 0;
-       else if (minute < 0)
-               minute = 59;
-
-       minute_ = minute;
-}
-
-void Timer::SetSecond(int second)
-{
-       if (second > 59)
-               second = 0;
-       else if (second < 0)
-               second = 59;
-
-       second_ = second;
-}
-
-void Timer::SetTime(int hour, int minute, int second)
-{
-       SetHour(hour);
-       SetMinute(minute);
-       SetSecond(second);
-}
-
-unsigned Timer::GetHour(void) const
-{
-       return hour_;
-}
-
-unsigned Timer::GetMinute(void) const
-{
-       return minute_;
-}
-
-unsigned Timer::GetSecond(void) const
-{
-       return second_;
+       remaining_time_ = time;
 }
 
 seconds Timer::GetRemainingTime(void)
 {
-       seconds time = seconds(hour_ * 3600 + minute_ * 60 + second_);
-
-       return time - GetTime();
+       return remaining_time_ - Counter::GetTime();
 }
 
 app_control_h Timer::CreateAppControl()
index 72391136d40b60a3f8de60bf73b623863423f875..26fa3da5b20a4d4c76b3e4ea784e38421ce32c45 100644 (file)
@@ -62,10 +62,7 @@ void TimerPresenter::StartButtonClicked()
        int hour = 0, minute = 0, second = 0;
 
        view_->GetTime(&hour, &minute, &second);
-
-       DBG("hour: %d min: %d src: %d", hour, minute, second);
-
-       model_->SetTime(hour, minute, second);
+       model_->SetTime(std::chrono::seconds(hour * 3600 + minute * 60 + second));
 
        if (!model_->Run())
                return;