Skip to content

Commit

Permalink
Merge branch 'develop' into feature/98-break-ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/main.yml
#	CMakeLists.txt
#	CMakePresets.json
#	src/CMakeLists.txt
#	src/gui/activityDialog.ui
#	src/gui/activityWidget.ui
#	src/gui/customerDialog.ui
#	src/gui/mainWindow.cpp
#	src/gui/projectDialog.ui
#	src/gui/settingsDialog.ui
#	src/gui/timeSheetListWidgetItem.ui
  • Loading branch information
AlexandrePTJ committed Jun 30, 2024
2 parents c455164 + 4e827e0 commit a1a393c
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 255 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [0.11.1] - 2024-06-30

### Fixed
- Fix missing log directory at first startup (Thanks to @ensemblebd)
- Settings management


## [0.11.0] - 2024-05-22

### Fixed
- Fix combo selection after model rest (Thanks to @virtulis)
- Fix combo selection after model reset (Thanks to @virtulis)

## Added
- Template button to reload previous timesheet without starting it (Thanks to @poelzi)
Expand Down Expand Up @@ -185,7 +195,9 @@ Special thanks to @shrippen for its support through [sponsorship](https://github
Initial version.


[Unreleased]: https://github.com/AlexandrePTJ/kemai/compare/0.10.0...HEAD
[Unreleased]: https://github.com/AlexandrePTJ/kemai/compare/0.11.1...HEAD
[0.11.1]: https://github.com/AlexandrePTJ/kemai/compare/0.11.0...0.11.1
[0.11.0]: https://github.com/AlexandrePTJ/kemai/compare/0.10.0...0.11.0
[0.10.0]: https://github.com/AlexandrePTJ/kemai/compare/0.9.4...0.10.0
[0.9.4]: https://github.com/AlexandrePTJ/kemai/compare/0.9.3...0.9.4
[0.9.3]: https://github.com/AlexandrePTJ/kemai/compare/0.9.2...0.9.3
Expand Down
5 changes: 5 additions & 0 deletions src/client/kimaiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ void KimaiClient::setHost(const QString& host)
mD->host = host;
}

QString KimaiClient::host() const
{
return mD->host;
}

void KimaiClient::setLegacyAuth(const QString& username, const QString& token)
{
mD->username = username;
Expand Down
1 change: 1 addition & 0 deletions src/client/kimaiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class KimaiClient : public QObject
void setNetworkAccessManager(const std::shared_ptr<QNetworkAccessManager>& nam);

void setHost(const QString& host);
QString host() const;

void setLegacyAuth(const QString& username, const QString& token);
bool isUsingLegacyAuth() const;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/aboutDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -99,7 +99,7 @@
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand All @@ -123,10 +123,10 @@
<locale language="English" country="UnitedStates"/>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
<set>QDialogButtonBox::StandardButton::Close</set>
</property>
</widget>
</item>
Expand Down
116 changes: 63 additions & 53 deletions src/gui/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MainWindow::MainWindow() : mUi(std::make_unique<Ui::MainWindow>()), mNam(std::ma

mUpdater.setNetworkAccessManager(mNam);

auto settings = Settings::get();
const auto& settings = SettingsHelper::load();

/*
* Setup icon
Expand Down Expand Up @@ -166,7 +166,7 @@ MainWindow::MainWindow() : mUi(std::make_unique<Ui::MainWindow>()), mNam(std::ma
if (settings.kemai.checkUpdateAtStartup)
{
QTimer::singleShot(FirstRequestDelayMs, [&]() {
auto ignoreVersion = QVersionNumber::fromString(Settings::get().kemai.ignoredVersion);
auto ignoreVersion = QVersionNumber::fromString(SettingsHelper::load().kemai.ignoredVersion);
auto currentVersion = QVersionNumber::fromString(KEMAI_VERSION);
mUpdater.checkAvailableNewVersion(currentVersion >= ignoreVersion ? currentVersion : ignoreVersion, true);
});
Expand All @@ -191,19 +191,19 @@ void MainWindow::closeEvent(QCloseEvent* event)
mLoggerWidget.close();
}

auto settings = Settings::get();
auto settings = SettingsHelper::load();
if (settings.kemai.closeToSystemTray)
{
hide();
event->ignore();
}
settings.kemai.geometry = saveGeometry();
Settings::save(settings);
SettingsHelper::save(settings);
}

void MainWindow::hideEvent(QHideEvent* event)
{
auto settings = Settings::get();
auto settings = SettingsHelper::load();
if (settings.kemai.minimizeToSystemTray)
{
if (event->spontaneous() && isMinimized())
Expand All @@ -213,7 +213,7 @@ void MainWindow::hideEvent(QHideEvent* event)
}
}
settings.kemai.geometry = saveGeometry();
Settings::save(settings);
SettingsHelper::save(settings);
}

void MainWindow::createKemaiSession(const Settings::Profile& profile)
Expand All @@ -232,31 +232,39 @@ void MainWindow::createKemaiSession(const Settings::Profile& profile)
mStatusInstanceLabel.setText(tr("Not connected"));
}

auto settings = Settings::get();
if (settings.isReady())
// Ensure profile has all required infos
const auto haveHost = !profile.host.isEmpty();
const auto haveLegacyAuth = !profile.username.isEmpty() && !profile.token.isEmpty();
const auto haveAPIToken = !profile.apiToken.isEmpty();
const auto isProfileValidated = haveHost && (haveLegacyAuth || haveAPIToken);
if (!isProfileValidated)
{
auto kimaiClient = std::make_shared<KimaiClient>();
spdlog::error("Invalid profile. Check settings.");
return;
}

kimaiClient->setNetworkAccessManager(mNam);
kimaiClient->setHost(profile.host);
kimaiClient->setLegacyAuth(profile.username, profile.token);
kimaiClient->setAPIToken(profile.apiToken);
// Create session
auto kimaiClient = std::make_shared<KimaiClient>();

mSession = std::make_shared<KemaiSession>(kimaiClient);
connect(mSession.get(), &KemaiSession::currentTimeSheetChanged, this, &MainWindow::onCurrentTimeSheetChanged);
connect(mSession.get(), &KemaiSession::pluginsChanged, this, &MainWindow::onPluginsChanged);
connect(mSession.get(), &KemaiSession::versionChanged, this, &MainWindow::onSessionVersionChanged);
kimaiClient->setHost(profile.host);
kimaiClient->setLegacyAuth(profile.username, profile.token);
kimaiClient->setAPIToken(profile.apiToken);

mActivityWidget->setKemaiSession(mSession);
mSession = std::make_shared<KemaiSession>(kimaiClient);
connect(mSession.get(), &KemaiSession::currentTimeSheetChanged, this, &MainWindow::onCurrentTimeSheetChanged);
connect(mSession.get(), &KemaiSession::pluginsChanged, this, &MainWindow::onPluginsChanged);
connect(mSession.get(), &KemaiSession::versionChanged, this, &MainWindow::onSessionVersionChanged);

mSession->refreshCache();
mSession->refreshSessionInfos();
mSession->refreshCurrentTimeSheet();
mActivityWidget->setKemaiSession(mSession);

// Save profile connection
settings.kemai.lastConnectedProfile = profile.id;
Settings::save(settings);
}
mSession->refreshCache();
mSession->refreshSessionInfos();
mSession->refreshCurrentTimeSheet();

// Save profile connection
auto settings = SettingsHelper::load();
settings.kemai.lastConnectedProfile = profile.id;
SettingsHelper::save(settings);
}

void MainWindow::showSelectedView()
Expand Down Expand Up @@ -287,12 +295,14 @@ void MainWindow::setViewActionsEnabled(bool enable)

void MainWindow::updateProfilesMenu()
{
auto settings = Settings::get();
const auto& settings = SettingsHelper::load();

// Removes obsoletes profiles
// Removes previous profiles
for (auto action : mActGroupProfiles->actions())
{
if (!settings.findProfile(action->data().toUuid()).has_value())
auto it = std::find_if(settings.profiles.begin(), settings.profiles.end(),
[profileId = action->data().toUuid()](const auto& profile) { return profile.id == profileId; });
if (it != settings.profiles.end())
{
mProfileMenu->removeAction(action);
mActGroupProfiles->removeAction(action);
Expand Down Expand Up @@ -322,26 +332,26 @@ void MainWindow::updateProfilesMenu()

void MainWindow::processAutoConnect()
{
auto settings = Settings::get();
if (settings.profiles.isEmpty())
const auto& settings = SettingsHelper::load();
if (settings.profiles.empty())
{
return;
}

auto profile = settings.findProfile(settings.kemai.lastConnectedProfile);
if (!profile.has_value())
{
profile = settings.profiles.front();
}

for (auto& action : mActGroupProfiles->actions())
auto profileIt = std::find_if(settings.profiles.begin(), settings.profiles.end(),
[profileId = settings.kemai.lastConnectedProfile](const auto& profile) { return profile.id == profileId; });
if (profileIt != settings.profiles.end())
{
if (action->data().toUuid() == profile->id)
for (auto& action : mActGroupProfiles->actions())
{
action->setChecked(true);
if (action->data().toUuid() == profileIt->id)
{
action->setChecked(true);
}
}

createKemaiSession(*profileIt);
}
createKemaiSession(profile.value());
}

void MainWindow::onNamSslErrors(QNetworkReply* /*reply*/, const QList<QSslError>& errors)
Expand Down Expand Up @@ -403,10 +413,10 @@ void MainWindow::onSessionVersionChanged()
void MainWindow::onActionSettingsTriggered()
{
SettingsDialog settingsDialog(mDesktopEventsMonitor, this);
settingsDialog.setSettings(Settings::get());
settingsDialog.setSettings(SettingsHelper::load());
if (settingsDialog.exec() == QDialog::Accepted)
{
Settings::save(settingsDialog.settings());
SettingsHelper::save(settingsDialog.settings());

showSelectedView();
updateProfilesMenu();
Expand All @@ -426,10 +436,9 @@ void MainWindow::onActionCheckUpdateTriggered()

void MainWindow::onActionOpenHostTriggered()
{
auto settings = Settings::get();
if (settings.isReady())
if (mSession)
{
QDesktopServices::openUrl(QUrl::fromUserInput(settings.profiles.first().host));
QDesktopServices::openUrl(QUrl::fromUserInput(mSession->client()->host()));
}
}

Expand All @@ -452,7 +461,7 @@ void MainWindow::onSystemTrayActivated(QSystemTrayIcon::ActivationReason reason)
switch (reason)
{
case QSystemTrayIcon::Trigger: {
auto settings = Settings::get();
const auto& settings = SettingsHelper::load();
if (isVisible() && (settings.kemai.minimizeToSystemTray || settings.kemai.closeToSystemTray))
{
hide();
Expand Down Expand Up @@ -488,9 +497,9 @@ void MainWindow::onNewVersionCheckFinished(const VersionDetails& details)
break;

case QMessageBox::Ignore: {
auto settings = Settings::get();
auto settings = SettingsHelper::load();
settings.kemai.ignoredVersion = details.vn.toString();
Settings::save(settings);
SettingsHelper::save(settings);
}
break;

Expand Down Expand Up @@ -524,20 +533,21 @@ void MainWindow::onProfilesActionGroupTriggered(QAction* action)
{
if (action->isChecked())
{
auto settings = Settings::get();
auto settings = SettingsHelper::load();
auto profileId = action->data().toUuid();
auto profile = settings.findProfile(profileId);
if (profile.has_value())
auto profileIt =
std::find_if(settings.profiles.begin(), settings.profiles.end(), [profileId](const auto& profile) { return profile.id == profileId; });
if (profileIt != settings.profiles.end())
{
createKemaiSession(profile.value());
createKemaiSession(*profileIt);
}
}
}
}

void MainWindow::onDesktopIdleDetected()
{
spdlog::info("System is idle since {} minutes. Stop current TimeSheet.", Settings::get().events.idleDelayMinutes);
spdlog::info("System is idle since {} minutes. Stop current TimeSheet.", SettingsHelper::load().events.idleDelayMinutes);
mActivityWidget->stopCurrentTimeSheet();
}

Expand Down
Loading

0 comments on commit a1a393c

Please sign in to comment.