feat: dual time zones, autostart, tray icon, config relocation, tests
- Dual clock (primary/secondary time zone) with IANA picker, persisted in XML - AutoStartManager: macOS LaunchAgent (com.clouck.clock, RunAtLoad) - Tray icon: template image, light/dark adaptation, toggle + quit menu - ConfigManager: default path moved to QStandardPaths::AppConfigLocation - Qt Test suite (ConfigManager, AutoStartManager) wired into CTest - GitHub origin renamed to upstream; private Gitea repo as origin
This commit is contained in:
+55
-6
@@ -1,6 +1,10 @@
|
||||
#include "config_manager.h"
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimeZone>
|
||||
|
||||
ConfigManager::ConfigManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -8,9 +12,27 @@ ConfigManager::ConfigManager(QObject *parent)
|
||||
setDefaultValues();
|
||||
}
|
||||
|
||||
QString ConfigManager::defaultSettingsPath()
|
||||
{
|
||||
const QString configDirectory = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
if (configDirectory.isEmpty())
|
||||
{
|
||||
qWarning() << "No application configuration directory is available";
|
||||
return QString();
|
||||
}
|
||||
|
||||
return QDir(configDirectory).filePath("config.xml");
|
||||
}
|
||||
|
||||
bool ConfigManager::loadSettings(const QString &filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
const QString settingsPath = filename.isEmpty() ? defaultSettingsPath() : filename;
|
||||
if (settingsPath.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(settingsPath);
|
||||
if (!file.exists())
|
||||
{
|
||||
qDebug() << "Config file does not exist, using defaults";
|
||||
@@ -77,6 +99,14 @@ bool ConfigManager::loadSettings(const QString &filename)
|
||||
m_windowSize = QSize(width, height);
|
||||
}
|
||||
}
|
||||
else if (name == "PrimaryTimeZone")
|
||||
{
|
||||
m_primaryTimeZoneId = text;
|
||||
}
|
||||
else if (name == "SecondaryTimeZone")
|
||||
{
|
||||
m_secondaryTimeZoneId = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.skipCurrentElement();
|
||||
@@ -96,7 +126,20 @@ bool ConfigManager::loadSettings(const QString &filename)
|
||||
|
||||
bool ConfigManager::saveSettings(const QString &filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
const QString settingsPath = filename.isEmpty() ? defaultSettingsPath() : filename;
|
||||
if (settingsPath.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const QFileInfo fileInfo(settingsPath);
|
||||
if (!QDir().mkpath(fileInfo.absolutePath()))
|
||||
{
|
||||
qDebug() << "Cannot create configuration directory:" << fileInfo.absolutePath();
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(settingsPath);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
qDebug() << "Cannot open config file for writing:" << file.errorString();
|
||||
@@ -134,6 +177,9 @@ bool ConfigManager::saveSettings(const QString &filename)
|
||||
.arg(m_windowSize.height());
|
||||
writer.writeTextElement("WindowSize", sizeStr);
|
||||
|
||||
writer.writeTextElement("PrimaryTimeZone", m_primaryTimeZoneId);
|
||||
writer.writeTextElement("SecondaryTimeZone", m_secondaryTimeZoneId);
|
||||
|
||||
// Close root element
|
||||
writer.writeEndElement();
|
||||
|
||||
@@ -150,13 +196,14 @@ void ConfigManager::resetToDefaults()
|
||||
|
||||
bool ConfigManager::configExists(const QString &filename) const
|
||||
{
|
||||
return QFile::exists(filename);
|
||||
const QString settingsPath = filename.isEmpty() ? defaultSettingsPath() : filename;
|
||||
return !settingsPath.isEmpty() && QFile::exists(settingsPath);
|
||||
}
|
||||
|
||||
void ConfigManager::setDefaultValues()
|
||||
{
|
||||
m_fontColor = QColor(255, 255, 255); // White
|
||||
m_backgroundColor = QColor(0, 0, 0, 150); // Semi-transparent black
|
||||
m_fontColor = QColor(0, 255, 0);
|
||||
m_backgroundColor = QColor(0, 0, 0, 0);
|
||||
m_fontSize = 24;
|
||||
m_alwaysOnTop = true;
|
||||
|
||||
@@ -164,5 +211,7 @@ void ConfigManager::setDefaultValues()
|
||||
// Position will be set properly when widget is shown for the first time
|
||||
m_windowPosition = QPoint(-1, -1); // Special value indicating "not set yet"
|
||||
|
||||
m_windowSize = QSize(200, 80); // Default clock size
|
||||
m_windowSize = QSize(240, 160); // Default clock size
|
||||
m_primaryTimeZoneId = QString::fromUtf8(QTimeZone::systemTimeZoneId());
|
||||
m_secondaryTimeZoneId = QStringLiteral("America/Los_Angeles");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user