- fixed bad time displaying (minutes were decreased for 30 seconds earlier) + this should fix the postpone counter
This commit is contained in:
parent
21046d9c35
commit
3f8aa69945
@ -225,7 +225,10 @@ static QString secondsToText(int seconds)
|
|||||||
if (seconds < 60)
|
if (seconds < 60)
|
||||||
return QObject::tr("%1 seconds").arg(seconds);
|
return QObject::tr("%1 seconds").arg(seconds);
|
||||||
else
|
else
|
||||||
return QObject::tr("%1 minutes").arg(seconds / 60);
|
{
|
||||||
|
int minutes = int(float(seconds) / 60 + 0.5f);
|
||||||
|
return QObject::tr("%1 minutes").arg(minutes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createTrayIcon()
|
void MainWindow::createTrayIcon()
|
||||||
@ -317,59 +320,56 @@ void MainWindow::shiftTo(AppState newState)
|
|||||||
onUpdateUI();
|
onUpdateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onUpdateUI()
|
void MainWindow::onUpdateUI() {
|
||||||
{
|
int idle_milliseconds = 0;
|
||||||
int idle_milliseconds = 0;
|
switch (mState) {
|
||||||
switch (mState)
|
case AppState::None:
|
||||||
{
|
// Do nothing, app is not started
|
||||||
case AppState::None:
|
break;
|
||||||
// Do nothing, app is not started
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AppState::Idle:
|
case AppState::Idle:
|
||||||
// Detected idle, don't count this time as working
|
// Detected idle, don't count this time as working
|
||||||
// But check - maybe idle is over
|
// But check - maybe idle is over
|
||||||
idle_milliseconds = get_idle_time_dynamically();
|
idle_milliseconds = get_idle_time_dynamically();
|
||||||
if (idle_milliseconds < mAppConfig.idle_timeout * 60 * 1000)
|
if (idle_milliseconds < mAppConfig.idle_timeout * 60 * 1000) {
|
||||||
{
|
shiftTo(AppState::Counting);
|
||||||
shiftTo(AppState::Counting);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AppState::Break:
|
case AppState::Break:
|
||||||
// Break is active
|
// Break is active
|
||||||
if (mTrayIcon)
|
if (mTrayIcon)
|
||||||
mTrayIcon->setToolTip(QString());
|
mTrayIcon->setToolTip(QString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AppState::Counting:
|
case AppState::Counting:
|
||||||
// Working, break is closing
|
// Working, break is closing
|
||||||
// Check maybe it is idle ?
|
// Check maybe it is idle ?
|
||||||
if (!mIdleStart && mAppConfig.idle_timeout)
|
if (!mIdleStart && mAppConfig.idle_timeout) {
|
||||||
{
|
idle_milliseconds = get_idle_time_dynamically();
|
||||||
idle_milliseconds = get_idle_time_dynamically();
|
if (idle_milliseconds >= mAppConfig.idle_timeout * 60 * 1000) {
|
||||||
if (idle_milliseconds >= mAppConfig.idle_timeout * 60 * 1000)
|
shiftTo(AppState::Idle);
|
||||||
{
|
return;
|
||||||
shiftTo(AppState::Idle);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update tray icon
|
|
||||||
if (mTrayIcon)
|
|
||||||
{
|
|
||||||
auto remaining_milliseconds = mBreakStartTimer->remainingTime();
|
|
||||||
if (remaining_milliseconds < 60000)
|
|
||||||
mTrayIcon->setToolTip(tr("Less than a minute left until the next break."));
|
|
||||||
else
|
|
||||||
mTrayIcon->setToolTip(tr("There are %1 minutes left until the next break.").arg(msec2min(remaining_milliseconds)));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->mSkipButton->setVisible(mPostponeCount > 0);
|
// Update tray icon
|
||||||
|
if (mTrayIcon) {
|
||||||
|
auto remaining_milliseconds = mBreakStartTimer->remainingTime();
|
||||||
|
if (remaining_milliseconds < 60000)
|
||||||
|
mTrayIcon->setToolTip(
|
||||||
|
tr("Less than a minute left until the next break."));
|
||||||
|
else
|
||||||
|
mTrayIcon->setToolTip(
|
||||||
|
tr("There are %1 minutes left until the next break.")
|
||||||
|
.arg(msec2min(remaining_milliseconds)));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->mSkipButton->setVisible(mPostponeCount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onLongBreakNotify()
|
void MainWindow::onLongBreakNotify()
|
||||||
@ -400,15 +400,15 @@ void MainWindow::onLongBreakStart()
|
|||||||
|
|
||||||
// Start progress bar
|
// Start progress bar
|
||||||
mProgressTimer->start();
|
mProgressTimer->start();
|
||||||
|
|
||||||
|
// Update title immediate
|
||||||
|
onProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onLongBreakEnd()
|
void MainWindow::onLongBreakEnd()
|
||||||
{
|
{
|
||||||
// qDebug() << "Long break ends.";
|
// qDebug() << "Long break ends.";
|
||||||
|
|
||||||
// Reset postpone counter
|
|
||||||
mPostponeCount = 0;
|
|
||||||
|
|
||||||
// Prepare to next triggering
|
// Prepare to next triggering
|
||||||
ui->mProgressBar->setValue(0);
|
ui->mProgressBar->setValue(0);
|
||||||
|
|
||||||
@ -477,6 +477,7 @@ void MainWindow::onProgress()
|
|||||||
if (percents > 100)
|
if (percents > 100)
|
||||||
{
|
{
|
||||||
mProgressTimer->stop();
|
mProgressTimer->stop();
|
||||||
|
mPostponeCount = 0; // Reset postpone counter
|
||||||
shiftTo(AppState::Counting);
|
shiftTo(AppState::Counting);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -43,7 +43,7 @@ private:
|
|||||||
QTimer* mBreakStartTimer; // Main timer - triggers when break occurs
|
QTimer* mBreakStartTimer; // Main timer - triggers when break occurs
|
||||||
QTimer* mBreakNotifyTimer; // Timer to show notification from system tray
|
QTimer* mBreakNotifyTimer; // Timer to show notification from system tray
|
||||||
QTimer* mUpdateUITimer; // Update UI timer - triggers every minute to update UI and checks for idle
|
QTimer* mUpdateUITimer; // Update UI timer - triggers every minute to update UI and checks for idle
|
||||||
QTimer* mProgressTimer; // Break progress timer
|
QTimer* mProgressTimer; // Break progress timer - updates an UI
|
||||||
QSystemTrayIcon* mTrayIcon;
|
QSystemTrayIcon* mTrayIcon;
|
||||||
SettingsDialog* mSettingsDialog;
|
SettingsDialog* mSettingsDialog;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user