Apply changed status colors without restart

This commit is contained in:
Martchus 2019-05-19 21:51:55 +02:00
parent 96dc7a535c
commit 0e7cc8ba9b
12 changed files with 45 additions and 17 deletions

View File

@ -66,6 +66,9 @@ void SyncthingFileItemActionStaticData::initialize()
connect(&m_connection, &SyncthingConnection::statusChanged, this, &SyncthingFileItemActionStaticData::logConnectionStatus);
}
// use default icon settings
IconManager::instance().applySettings(StatusIconSettings());
m_initialized = true;
}

View File

@ -351,6 +351,11 @@ void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &, int index)
emit dataChanged(this->index(0, 0, modelIndex1), this->index(5, 0, modelIndex1), modelRoles4);
}
void SyncthingDeviceModel::handleStatusIconsChanged()
{
emit dataChanged(index(0, 0), index(static_cast<int>(m_devs.size()) - 1, 0), QVector<int>({ Qt::DecorationRole }));
}
QString SyncthingDeviceModel::devStatusString(const SyncthingDev &dev)
{
if (dev.paused) {

View File

@ -41,6 +41,7 @@ public Q_SLOTS:
private Q_SLOTS:
void devStatusChanged(const SyncthingDev &, int index);
void handleStatusIconsChanged() override;
private:
static QString devStatusString(const SyncthingDev &dev);

View File

@ -441,6 +441,11 @@ void SyncthingDirectoryModel::handleNewConfigAvailable()
endResetModel();
}
void SyncthingDirectoryModel::handleStatusIconsChanged()
{
emit dataChanged(index(0, 0), index(static_cast<int>(m_dirs.size()) - 1, 0), QVector<int>({ Qt::DecorationRole }));
}
QString SyncthingDirectoryModel::dirStatusString(const SyncthingDir &dir)
{
if (dir.paused && dir.status != SyncthingDirStatus::OutOfSync) {

View File

@ -44,6 +44,7 @@ private Q_SLOTS:
void dirStatusChanged(const SyncthingDir &dir, int index);
void handleConfigInvalidated() override;
void handleNewConfigAvailable() override;
void handleStatusIconsChanged() override;
private:
static QString dirStatusString(const SyncthingDir &dir);

View File

@ -260,16 +260,16 @@ FontAwesomeIcons::FontAwesomeIcons(const QColor &color, const QSize &size, int m
{
}
IconManager::IconManager(const StatusIconSettings *settings)
: m_statusIcons(settings ? *settings : StatusIconSettings())
IconManager::IconManager()
: m_statusIcons()
, m_fontAwesomeIconsForLightTheme(QColor(10, 10, 10), QSize(64, 64), 8)
, m_fontAwesomeIconsForDarkTheme(Qt::white, QSize(64, 64), 8)
{
}
IconManager &IconManager::instance(const StatusIconSettings *settingsForFirstTimeSetup)
IconManager &IconManager::instance()
{
static IconManager iconManager(settingsForFirstTimeSetup);
static IconManager iconManager;
return iconManager;
}

View File

@ -81,7 +81,8 @@ struct LIB_SYNCTHING_MODEL_EXPORT StatusIconSettings {
};
struct StatusIcons {
StatusIcons(const StatusIconSettings &settings = StatusIconSettings());
StatusIcons();
StatusIcons(const StatusIconSettings &settings);
QIcon disconnected;
QIcon idling;
QIcon scanninig;
@ -94,6 +95,10 @@ struct StatusIcons {
QIcon newItem;
};
inline StatusIcons::StatusIcons()
{
}
struct FontAwesomeIcons {
FontAwesomeIcons(const QColor &color, const QSize &size, int margin);
QIcon hashtag;
@ -117,17 +122,21 @@ struct FontAwesomeIcons {
QIcon tag;
};
class LIB_SYNCTHING_MODEL_EXPORT IconManager {
class LIB_SYNCTHING_MODEL_EXPORT IconManager : public QObject {
Q_OBJECT
public:
static IconManager &instance(const StatusIconSettings *settingsForFirstTimeSetup = nullptr);
static IconManager &instance();
void applySettings(const StatusIconSettings &settings);
const StatusIcons &statusIcons() const;
const FontAwesomeIcons &fontAwesomeIconsForLightTheme() const;
const FontAwesomeIcons &fontAwesomeIconsForDarkTheme() const;
Q_SIGNALS:
void statusIconsChanged();
private:
IconManager(const StatusIconSettings *settings = nullptr);
IconManager();
StatusIcons m_statusIcons;
FontAwesomeIcons m_fontAwesomeIconsForLightTheme;
@ -137,6 +146,7 @@ private:
inline void IconManager::applySettings(const StatusIconSettings &settings)
{
m_statusIcons = StatusIcons(settings);
emit statusIconsChanged();
}
inline const StatusIcons &IconManager::statusIcons() const

View File

@ -1,4 +1,5 @@
#include "./syncthingmodel.h"
#include "./syncthingicons.h"
#include "../connector/syncthingconnection.h"
@ -11,6 +12,7 @@ SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
{
connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated);
connect(&m_connection, &SyncthingConnection::newConfigApplied, this, &SyncthingModel::handleNewConfigAvailable);
connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &SyncthingModel::handleStatusIconsChanged);
}
const QVector<int> &SyncthingModel::colorRoles() const
@ -55,4 +57,8 @@ void SyncthingModel::handleNewConfigAvailable()
endResetModel();
}
void SyncthingModel::handleStatusIconsChanged()
{
}
} // namespace Data

View File

@ -27,6 +27,7 @@ protected:
private Q_SLOTS:
virtual void handleConfigInvalidated();
virtual void handleNewConfigAvailable();
virtual void handleStatusIconsChanged();
protected:
Data::SyncthingConnection &m_connection;

View File

@ -102,6 +102,7 @@ void SyncthingApplet::init()
connect(&m_dbusNotifier, &DBusStatusNotifier::showNotificationsRequested, this, &SyncthingApplet::showNotificationsDialog);
connect(&m_dbusNotifier, &DBusStatusNotifier::errorDetailsRequested, this, &SyncthingApplet::showInternalErrorsDialog);
connect(&m_dbusNotifier, &DBusStatusNotifier::webUiRequested, this, &SyncthingApplet::showWebUI);
connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &SyncthingApplet::connectionStatusChanged);
// restore settings
Settings::restore();

View File

@ -96,6 +96,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
connect(&connection, &SyncthingConnection::statusChanged, this, &TrayIcon::updateStatusIconAndText);
connect(&connection, &SyncthingConnection::newDevices, this, &TrayIcon::updateStatusIconAndText);
connect(&connection, &SyncthingConnection::devStatusChanged, this, &TrayIcon::updateStatusIconAndText);
connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &TrayIcon::updateStatusIconAndText);
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
connect(&m_dbusNotifier, &DBusStatusNotifier::connectRequested, &connection,
static_cast<void (SyncthingConnection::*)(void)>(&SyncthingConnection::connect));

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<width>538</width>
<height>167</height>
</rect>
</property>
@ -70,13 +70,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>Requires (so far) a restart to be applied.</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -96,7 +89,8 @@
<string>Restore previous settings</string>
</property>
<property name="icon">
<iconset theme="edit-undo"/>
<iconset theme="edit-undo">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>