From 3175b435a26747313ecca0c8646280f958ecf129 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Thu, 21 Apr 2022 13:28:50 +0300 Subject: [PATCH] - fix translations + cleanups in source code + fix the tray icon tooltip after interval change in settings + version switch to 0.0.8 --- app/config.h | 11 +++++++++- app/mainwindow.cpp | 35 ++++++++++++++++++++++--------- app/mainwindow.h | 2 ++ app/mainwindow.ui | 43 +++++++++++++++++++++++++++++++++++++- app/strings.ts | 52 +++++++++++++++++++++++++++++++++++----------- app/strings_en.ts | 52 +++++++++++++++++++++++++++++++++++----------- app/strings_ru.ts | 52 +++++++++++++++++++++++++++++++++++----------- 7 files changed, 199 insertions(+), 48 deletions(-) diff --git a/app/config.h b/app/config.h index 6491b88..40a5ffc 100644 --- a/app/config.h +++ b/app/config.h @@ -4,6 +4,15 @@ // App version #define QBREAK_VERSION_MAJOR 0 #define QBREAK_VERSION_MINOR 0 -#define QBREAK_VERSION_SUFFIX 7 +#define QBREAK_VERSION_SUFFIX 8 + +// How often UI is updated - interval in seconds +#define INTERVAL_UPDATE_UI (60) + +// How often progress bar is updated - interval in milliseconds +#define INTERVAL_UPDATE_PROGRESS (1000) + +// How long notification is shown - in milliseconds +#define INTERVAL_NOTIFICATION (30000) #endif // CONFIG_H diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index bac524d..fc61310 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -4,6 +4,7 @@ #include "settings.h" #include "autostart.h" #include "aboutdlg.h" +#include "config.h" #include #include @@ -81,6 +82,9 @@ void MainWindow::init() // Settings dialog mSettingsDialog = nullptr; + // No postpone attempts yet + mPostponeCount = 0; + // Timer mTimer = new QTimer(this); mTimer->setTimerType(Qt::TimerType::CoarseTimer); @@ -96,16 +100,17 @@ void MainWindow::init() mUpdateUITimer = new QTimer(this); mUpdateUITimer->setTimerType(Qt::TimerType::CoarseTimer); mUpdateUITimer->setSingleShot(false); - mUpdateUITimer->setInterval(std::chrono::minutes(1)); + mUpdateUITimer->setInterval(std::chrono::seconds(INTERVAL_UPDATE_UI)); connect(mUpdateUITimer, SIGNAL(timeout()), this, SLOT(onUpdateUI())); mUpdateUITimer->start(); mProgressTimer = new QTimer(this); - mProgressTimer->setInterval(std::chrono::milliseconds(1000)); + mProgressTimer->setInterval(std::chrono::milliseconds(INTERVAL_UPDATE_PROGRESS)); mProgressTimer->setSingleShot(false); connect(mProgressTimer, SIGNAL(timeout()), this, SLOT(onProgress())); connect(ui->mPostponeButton, SIGNAL(clicked()), this, SLOT(onLongBreakPostpone())); + connect(ui->mSkipButton, SIGNAL(clicked()), this, SLOT(onLongBreakEnd())); // Use the latest config applyConfig(); @@ -164,7 +169,8 @@ void MainWindow::test_1() mAppConfig.window_on_top = true; mAppConfig.verbose = true; - + applyConfig(); + onUpdateUI(); onLongBreakStart(); } @@ -173,12 +179,13 @@ void MainWindow::test_2() // 60 seconds test break mAppConfig.longbreak_length = 60; mAppConfig.longbreak_postpone_interval = 60; - mAppConfig.longbreak_interval = 60; + mAppConfig.longbreak_interval = 240; mAppConfig.window_on_top = true; mAppConfig.verbose = true; applyConfig(); + onUpdateUI(); } void MainWindow::showMe() @@ -215,9 +222,9 @@ void MainWindow::hideMe() static QString secondsToText(int seconds) { if (seconds < 60) - return QString("%1s").arg(seconds); + return QObject::tr("%1 seconds").arg(seconds); else - return QString("%1m %2s").arg(seconds / 60).arg(seconds % 60); + return QObject::tr("%1 minutes").arg(seconds / 60); } void MainWindow::createTrayIcon() @@ -260,13 +267,15 @@ void MainWindow::onUpdateUI() else if (mTimer->isActive()) { - auto remaining = std::chrono::duration_cast(mTimer->remainingTimeAsDuration()); - if (remaining.count() == 0) + auto remaining_milliseconds = mTimer->remainingTime(); + if (remaining_milliseconds == 0) 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(remaining.count())); + mTrayIcon->setToolTip(tr("There are %1 minutes left until the next break.").arg(remaining_milliseconds / 1000 / 60)); } } + + ui->mSkipButton->setVisible(mPostponeCount > 0); } void MainWindow::onLongBreakNotify() @@ -274,7 +283,7 @@ void MainWindow::onLongBreakNotify() mTrayIcon->showMessage(tr("New break"), tr("New break will start in %1 secs").arg(Default_Notify_Length), getAppIcon(), - 30000); + INTERVAL_NOTIFICATION); } void MainWindow::onLongBreakStart() @@ -297,6 +306,9 @@ void MainWindow::onLongBreakEnd() { qDebug() << "Long break ends."; + // Reset postpone counter + mPostponeCount = 0; + // Prepare to next triggering ui->mProgressBar->setValue(0); @@ -314,6 +326,8 @@ void MainWindow::onLongBreakEnd() void MainWindow::onLongBreakPostpone() { qDebug() << "Long break postponed."; + mPostponeCount++; + hideMe(); mProgressTimer->stop(); @@ -368,6 +382,7 @@ void MainWindow::onSettings() mAppConfig = app_settings::load(); applyConfig(); mSettingsDialog->hide(); + onUpdateUI(); }); connect(mSettingsDialog, &QDialog::rejected, [this]() diff --git a/app/mainwindow.h b/app/mainwindow.h index 7a990d0..7240d2a 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -38,6 +38,7 @@ private: SettingsDialog* mSettingsDialog; std::chrono::steady_clock::time_point mBreakStartTime; app_settings::config mAppConfig; + int mPostponeCount; void init(); void loadConfig(); @@ -58,6 +59,7 @@ public slots: void onLongBreakStart(); void onLongBreakPostpone(); void onLongBreakEnd(); + void onProgress(); void onNextBreak(); void onSettings(); diff --git a/app/mainwindow.ui b/app/mainwindow.ui index b68676d..f10110e 100644 --- a/app/mainwindow.ui +++ b/app/mainwindow.ui @@ -107,7 +107,7 @@ - 150 + 200 0 @@ -120,6 +120,47 @@ Postpone for 10 minutes + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 10 + + + + + + + + + 200 + 0 + + + + + 300 + 16777215 + + + + Skip this break + + + true + diff --git a/app/strings.ts b/app/strings.ts index be16bb9..c507b7e 100644 --- a/app/strings.ts +++ b/app/strings.ts @@ -4,22 +4,27 @@ AboutDlg - + Dialog + TextLabel + + + + QBreak. - + Version - + App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one. @@ -32,51 +37,69 @@ - + + Skip this break + + + + Start next break - + Settings - + About - + Exit - + Less than a minute left until the next break. - + There are %1 minutes left until the next break. - + New break - + New break will start in %1 secs - + Postpone for + + QObject + + + %1 seconds + + + + + %1 minutes + + + SettingsDialog @@ -109,5 +132,10 @@ Postpone time (minutes) + + + Preferred monitor + + diff --git a/app/strings_en.ts b/app/strings_en.ts index be16bb9..73ee997 100644 --- a/app/strings_en.ts +++ b/app/strings_en.ts @@ -4,22 +4,27 @@ AboutDlg - + Dialog + TextLabel + + + + QBreak. - + Version - + App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one. @@ -32,51 +37,69 @@ - + + Skip this break + + + + Start next break - + Settings - + About - + Exit - + Less than a minute left until the next break. - + There are %1 minutes left until the next break. - + New break - + New break will start in %1 secs - + Postpone for + + QObject + + + %1 seconds + + + + + %1 minutes + + + SettingsDialog @@ -109,5 +132,10 @@ Postpone time (minutes) + + + Preferred monitor + + diff --git a/app/strings_ru.ts b/app/strings_ru.ts index aac12c4..3feaabe 100644 --- a/app/strings_ru.ts +++ b/app/strings_ru.ts @@ -4,22 +4,27 @@ AboutDlg - + Dialog О программе + TextLabel + + + + QBreak. QBreak. - + Version Версия - + App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one. Приложение чтобы устраивать себе перерывы в работе. Спасибо авторам аналогичных приложений которые вдохновили меня сделать это приложение. @@ -32,51 +37,69 @@ QBreak - + + Skip this break + Пропустить + + + Start next break Начать перерыв - + Settings Настройки - + About О программе - + Exit Выход - + Less than a minute left until the next break. До перерыва осталось меньше минуты. - + There are %1 minutes left until the next break. Осталось %1 минут до перерыва. - + New break Скоро перерыв - + New break will start in %1 secs Перерыв начнется через %1 секунд. - + Postpone for Отложить на + + QObject + + + %1 seconds + %1 секунд + + + + %1 minutes + %1 минут + + SettingsDialog @@ -109,6 +132,11 @@ Postpone time (minutes) Насколько можно отложить перерыв (в минутах) + + + Preferred monitor + Предпочитаемый монитор + Break interval (seconds) Промежуток между перерывами в секундах