- fix translations + cleanups in source code + fix the tray icon tooltip after interval change in settings + version switch to 0.0.8

This commit is contained in:
Dmytro Bogovych 2022-04-21 13:28:50 +03:00
parent 371a105f84
commit 3175b435a2
7 changed files with 199 additions and 48 deletions

View File

@ -4,6 +4,15 @@
// App version // App version
#define QBREAK_VERSION_MAJOR 0 #define QBREAK_VERSION_MAJOR 0
#define QBREAK_VERSION_MINOR 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 #endif // CONFIG_H

View File

@ -4,6 +4,7 @@
#include "settings.h" #include "settings.h"
#include "autostart.h" #include "autostart.h"
#include "aboutdlg.h" #include "aboutdlg.h"
#include "config.h"
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
@ -81,6 +82,9 @@ void MainWindow::init()
// Settings dialog // Settings dialog
mSettingsDialog = nullptr; mSettingsDialog = nullptr;
// No postpone attempts yet
mPostponeCount = 0;
// Timer // Timer
mTimer = new QTimer(this); mTimer = new QTimer(this);
mTimer->setTimerType(Qt::TimerType::CoarseTimer); mTimer->setTimerType(Qt::TimerType::CoarseTimer);
@ -96,16 +100,17 @@ void MainWindow::init()
mUpdateUITimer = new QTimer(this); mUpdateUITimer = new QTimer(this);
mUpdateUITimer->setTimerType(Qt::TimerType::CoarseTimer); mUpdateUITimer->setTimerType(Qt::TimerType::CoarseTimer);
mUpdateUITimer->setSingleShot(false); mUpdateUITimer->setSingleShot(false);
mUpdateUITimer->setInterval(std::chrono::minutes(1)); mUpdateUITimer->setInterval(std::chrono::seconds(INTERVAL_UPDATE_UI));
connect(mUpdateUITimer, SIGNAL(timeout()), this, SLOT(onUpdateUI())); connect(mUpdateUITimer, SIGNAL(timeout()), this, SLOT(onUpdateUI()));
mUpdateUITimer->start(); mUpdateUITimer->start();
mProgressTimer = new QTimer(this); mProgressTimer = new QTimer(this);
mProgressTimer->setInterval(std::chrono::milliseconds(1000)); mProgressTimer->setInterval(std::chrono::milliseconds(INTERVAL_UPDATE_PROGRESS));
mProgressTimer->setSingleShot(false); mProgressTimer->setSingleShot(false);
connect(mProgressTimer, SIGNAL(timeout()), this, SLOT(onProgress())); connect(mProgressTimer, SIGNAL(timeout()), this, SLOT(onProgress()));
connect(ui->mPostponeButton, SIGNAL(clicked()), this, SLOT(onLongBreakPostpone())); connect(ui->mPostponeButton, SIGNAL(clicked()), this, SLOT(onLongBreakPostpone()));
connect(ui->mSkipButton, SIGNAL(clicked()), this, SLOT(onLongBreakEnd()));
// Use the latest config // Use the latest config
applyConfig(); applyConfig();
@ -164,7 +169,8 @@ void MainWindow::test_1()
mAppConfig.window_on_top = true; mAppConfig.window_on_top = true;
mAppConfig.verbose = true; mAppConfig.verbose = true;
applyConfig();
onUpdateUI();
onLongBreakStart(); onLongBreakStart();
} }
@ -173,12 +179,13 @@ void MainWindow::test_2()
// 60 seconds test break // 60 seconds test break
mAppConfig.longbreak_length = 60; mAppConfig.longbreak_length = 60;
mAppConfig.longbreak_postpone_interval = 60; mAppConfig.longbreak_postpone_interval = 60;
mAppConfig.longbreak_interval = 60; mAppConfig.longbreak_interval = 240;
mAppConfig.window_on_top = true; mAppConfig.window_on_top = true;
mAppConfig.verbose = true; mAppConfig.verbose = true;
applyConfig(); applyConfig();
onUpdateUI();
} }
void MainWindow::showMe() void MainWindow::showMe()
@ -215,9 +222,9 @@ void MainWindow::hideMe()
static QString secondsToText(int seconds) static QString secondsToText(int seconds)
{ {
if (seconds < 60) if (seconds < 60)
return QString("%1s").arg(seconds); return QObject::tr("%1 seconds").arg(seconds);
else else
return QString("%1m %2s").arg(seconds / 60).arg(seconds % 60); return QObject::tr("%1 minutes").arg(seconds / 60);
} }
void MainWindow::createTrayIcon() void MainWindow::createTrayIcon()
@ -260,13 +267,15 @@ void MainWindow::onUpdateUI()
else else
if (mTimer->isActive()) if (mTimer->isActive())
{ {
auto remaining = std::chrono::duration_cast<std::chrono::minutes>(mTimer->remainingTimeAsDuration()); auto remaining_milliseconds = mTimer->remainingTime();
if (remaining.count() == 0) if (remaining_milliseconds == 0)
mTrayIcon->setToolTip(tr("Less than a minute left until the next break.")); mTrayIcon->setToolTip(tr("Less than a minute left until the next break."));
else 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() void MainWindow::onLongBreakNotify()
@ -274,7 +283,7 @@ void MainWindow::onLongBreakNotify()
mTrayIcon->showMessage(tr("New break"), mTrayIcon->showMessage(tr("New break"),
tr("New break will start in %1 secs").arg(Default_Notify_Length), tr("New break will start in %1 secs").arg(Default_Notify_Length),
getAppIcon(), getAppIcon(),
30000); INTERVAL_NOTIFICATION);
} }
void MainWindow::onLongBreakStart() void MainWindow::onLongBreakStart()
@ -297,6 +306,9 @@ 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);
@ -314,6 +326,8 @@ void MainWindow::onLongBreakEnd()
void MainWindow::onLongBreakPostpone() void MainWindow::onLongBreakPostpone()
{ {
qDebug() << "Long break postponed."; qDebug() << "Long break postponed.";
mPostponeCount++;
hideMe(); hideMe();
mProgressTimer->stop(); mProgressTimer->stop();
@ -368,6 +382,7 @@ void MainWindow::onSettings()
mAppConfig = app_settings::load(); mAppConfig = app_settings::load();
applyConfig(); applyConfig();
mSettingsDialog->hide(); mSettingsDialog->hide();
onUpdateUI();
}); });
connect(mSettingsDialog, &QDialog::rejected, [this]() connect(mSettingsDialog, &QDialog::rejected, [this]()

View File

@ -38,6 +38,7 @@ private:
SettingsDialog* mSettingsDialog; SettingsDialog* mSettingsDialog;
std::chrono::steady_clock::time_point mBreakStartTime; std::chrono::steady_clock::time_point mBreakStartTime;
app_settings::config mAppConfig; app_settings::config mAppConfig;
int mPostponeCount;
void init(); void init();
void loadConfig(); void loadConfig();
@ -58,6 +59,7 @@ public slots:
void onLongBreakStart(); void onLongBreakStart();
void onLongBreakPostpone(); void onLongBreakPostpone();
void onLongBreakEnd(); void onLongBreakEnd();
void onProgress(); void onProgress();
void onNextBreak(); void onNextBreak();
void onSettings(); void onSettings();

View File

@ -107,7 +107,7 @@
<widget class="QPushButton" name="mPostponeButton"> <widget class="QPushButton" name="mPostponeButton">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>150</width> <width>200</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -120,6 +120,47 @@
<property name="text"> <property name="text">
<string notr="true">Postpone for 10 minutes</string> <string notr="true">Postpone for 10 minutes</string>
</property> </property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="mSkipButton">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Skip this break</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -4,22 +4,27 @@
<context> <context>
<name>AboutDlg</name> <name>AboutDlg</name>
<message> <message>
<location filename="aboutdlg.ui" line="20"/> <location filename="aboutdlg.ui" line="26"/>
<source>Dialog</source> <source>Dialog</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="32"/> <location filename="aboutdlg.ui" line="32"/>
<source>TextLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="aboutdlg.ui" line="48"/>
<source>QBreak.</source> <source>QBreak.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="51"/> <location filename="aboutdlg.ui" line="67"/>
<source>Version</source> <source>Version</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="70"/> <location filename="aboutdlg.ui" line="86"/>
<source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source> <source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source>
<translation></translation> <translation></translation>
</message> </message>
@ -32,51 +37,69 @@
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="213"/> <location filename="mainwindow.ui" line="159"/>
<source>Skip this break</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="235"/>
<source>Start next break</source> <source>Start next break</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="216"/> <location filename="mainwindow.cpp" line="238"/>
<source>Settings</source> <source>Settings</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="219"/> <location filename="mainwindow.cpp" line="241"/>
<source>About</source> <source>About</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="222"/> <location filename="mainwindow.cpp" line="244"/>
<source>Exit</source> <source>Exit</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="250"/> <location filename="mainwindow.cpp" line="272"/>
<source>Less than a minute left until the next break.</source> <source>Less than a minute left until the next break.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="252"/> <location filename="mainwindow.cpp" line="274"/>
<source>There are %1 minutes left until the next break.</source> <source>There are %1 minutes left until the next break.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="259"/> <location filename="mainwindow.cpp" line="283"/>
<source>New break</source> <source>New break</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="260"/> <location filename="mainwindow.cpp" line="284"/>
<source>New break will start in %1 secs</source> <source>New break will start in %1 secs</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="269"/> <location filename="mainwindow.cpp" line="293"/>
<source>Postpone for </source> <source>Postpone for </source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>QObject</name>
<message>
<location filename="mainwindow.cpp" line="225"/>
<source>%1 seconds</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="227"/>
<source>%1 minutes</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsDialog</name> <name>SettingsDialog</name>
<message> <message>
@ -109,5 +132,10 @@
<source>Postpone time (minutes)</source> <source>Postpone time (minutes)</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<location filename="settingsdialog.ui" line="110"/>
<source>Preferred monitor</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -4,22 +4,27 @@
<context> <context>
<name>AboutDlg</name> <name>AboutDlg</name>
<message> <message>
<location filename="aboutdlg.ui" line="20"/> <location filename="aboutdlg.ui" line="26"/>
<source>Dialog</source> <source>Dialog</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="32"/> <location filename="aboutdlg.ui" line="32"/>
<source>TextLabel</source>
<translation></translation>
</message>
<message>
<location filename="aboutdlg.ui" line="48"/>
<source>QBreak.</source> <source>QBreak.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="51"/> <location filename="aboutdlg.ui" line="67"/>
<source>Version</source> <source>Version</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="70"/> <location filename="aboutdlg.ui" line="86"/>
<source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source> <source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source>
<translation></translation> <translation></translation>
</message> </message>
@ -32,51 +37,69 @@
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="213"/> <location filename="mainwindow.ui" line="159"/>
<source>Skip this break</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="235"/>
<source>Start next break</source> <source>Start next break</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="216"/> <location filename="mainwindow.cpp" line="238"/>
<source>Settings</source> <source>Settings</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="219"/> <location filename="mainwindow.cpp" line="241"/>
<source>About</source> <source>About</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="222"/> <location filename="mainwindow.cpp" line="244"/>
<source>Exit</source> <source>Exit</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="250"/> <location filename="mainwindow.cpp" line="272"/>
<source>Less than a minute left until the next break.</source> <source>Less than a minute left until the next break.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="252"/> <location filename="mainwindow.cpp" line="274"/>
<source>There are %1 minutes left until the next break.</source> <source>There are %1 minutes left until the next break.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="259"/> <location filename="mainwindow.cpp" line="283"/>
<source>New break</source> <source>New break</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="260"/> <location filename="mainwindow.cpp" line="284"/>
<source>New break will start in %1 secs</source> <source>New break will start in %1 secs</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="269"/> <location filename="mainwindow.cpp" line="293"/>
<source>Postpone for </source> <source>Postpone for </source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>QObject</name>
<message>
<location filename="mainwindow.cpp" line="225"/>
<source>%1 seconds</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="227"/>
<source>%1 minutes</source>
<translation></translation>
</message>
</context>
<context> <context>
<name>SettingsDialog</name> <name>SettingsDialog</name>
<message> <message>
@ -109,5 +132,10 @@
<source>Postpone time (minutes)</source> <source>Postpone time (minutes)</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<location filename="settingsdialog.ui" line="110"/>
<source>Preferred monitor</source>
<translation></translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -4,22 +4,27 @@
<context> <context>
<name>AboutDlg</name> <name>AboutDlg</name>
<message> <message>
<location filename="aboutdlg.ui" line="20"/> <location filename="aboutdlg.ui" line="26"/>
<source>Dialog</source> <source>Dialog</source>
<translation>О программе</translation> <translation>О программе</translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="32"/> <location filename="aboutdlg.ui" line="32"/>
<source>TextLabel</source>
<translation> </translation>
</message>
<message>
<location filename="aboutdlg.ui" line="48"/>
<source>QBreak.</source> <source>QBreak.</source>
<translation>QBreak.</translation> <translation>QBreak.</translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="51"/> <location filename="aboutdlg.ui" line="67"/>
<source>Version</source> <source>Version</source>
<translation>Версия</translation> <translation>Версия</translation>
</message> </message>
<message> <message>
<location filename="aboutdlg.ui" line="70"/> <location filename="aboutdlg.ui" line="86"/>
<source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source> <source>App to make breaks in work. Thanks to the authors of similar apps which inspired me to make this one.</source>
<translation>Приложение чтобы устраивать себе перерывы в работе. Спасибо авторам аналогичных приложений которые вдохновили меня сделать это приложение.</translation> <translation>Приложение чтобы устраивать себе перерывы в работе. Спасибо авторам аналогичных приложений которые вдохновили меня сделать это приложение.</translation>
</message> </message>
@ -32,51 +37,69 @@
<translation>QBreak</translation> <translation>QBreak</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="213"/> <location filename="mainwindow.ui" line="159"/>
<source>Skip this break</source>
<translation>Пропустить</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="235"/>
<source>Start next break</source> <source>Start next break</source>
<translation>Начать перерыв</translation> <translation>Начать перерыв</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="216"/> <location filename="mainwindow.cpp" line="238"/>
<source>Settings</source> <source>Settings</source>
<translation>Настройки</translation> <translation>Настройки</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="219"/> <location filename="mainwindow.cpp" line="241"/>
<source>About</source> <source>About</source>
<translation>О программе</translation> <translation>О программе</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="222"/> <location filename="mainwindow.cpp" line="244"/>
<source>Exit</source> <source>Exit</source>
<translation>Выход</translation> <translation>Выход</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="250"/> <location filename="mainwindow.cpp" line="272"/>
<source>Less than a minute left until the next break.</source> <source>Less than a minute left until the next break.</source>
<translation>До перерыва осталось меньше минуты.</translation> <translation>До перерыва осталось меньше минуты.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="252"/> <location filename="mainwindow.cpp" line="274"/>
<source>There are %1 minutes left until the next break.</source> <source>There are %1 minutes left until the next break.</source>
<translation>Осталось %1 минут до перерыва.</translation> <translation>Осталось %1 минут до перерыва.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="259"/> <location filename="mainwindow.cpp" line="283"/>
<source>New break</source> <source>New break</source>
<translation>Скоро перерыв</translation> <translation>Скоро перерыв</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="260"/> <location filename="mainwindow.cpp" line="284"/>
<source>New break will start in %1 secs</source> <source>New break will start in %1 secs</source>
<translation>Перерыв начнется через %1 секунд.</translation> <translation>Перерыв начнется через %1 секунд.</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="269"/> <location filename="mainwindow.cpp" line="293"/>
<source>Postpone for </source> <source>Postpone for </source>
<translation>Отложить на</translation> <translation>Отложить на</translation>
</message> </message>
</context> </context>
<context>
<name>QObject</name>
<message>
<location filename="mainwindow.cpp" line="225"/>
<source>%1 seconds</source>
<translation>%1 секунд</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="227"/>
<source>%1 minutes</source>
<translation>%1 минут</translation>
</message>
</context>
<context> <context>
<name>SettingsDialog</name> <name>SettingsDialog</name>
<message> <message>
@ -109,6 +132,11 @@
<source>Postpone time (minutes)</source> <source>Postpone time (minutes)</source>
<translation>Насколько можно отложить перерыв (в минутах)</translation> <translation>Насколько можно отложить перерыв (в минутах)</translation>
</message> </message>
<message>
<location filename="settingsdialog.ui" line="110"/>
<source>Preferred monitor</source>
<translation>Предпочитаемый монитор</translation>
</message>
<message> <message>
<source>Break interval (seconds)</source> <source>Break interval (seconds)</source>
<translation type="vanished">Промежуток между перерывами в секундах</translation> <translation type="vanished">Промежуток между перерывами в секундах</translation>