2016-11-02 21:05:32 +01:00
|
|
|
#include "./syncthingmodel.h"
|
2019-05-19 21:51:55 +02:00
|
|
|
#include "./syncthingicons.h"
|
2016-11-02 21:05:32 +01:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
2018-12-25 02:33:57 +01:00
|
|
|
|
2016-11-02 21:05:32 +01:00
|
|
|
namespace Data {
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
|
|
|
|
: QAbstractItemModel(parent)
|
|
|
|
, m_connection(connection)
|
2017-08-29 23:51:03 +02:00
|
|
|
, m_brightColors(false)
|
2017-05-01 03:34:43 +02:00
|
|
|
{
|
2018-12-25 02:33:57 +01:00
|
|
|
connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated);
|
|
|
|
connect(&m_connection, &SyncthingConnection::newConfigApplied, this, &SyncthingModel::handleNewConfigAvailable);
|
2021-10-16 21:20:12 +02:00
|
|
|
|
|
|
|
const auto &iconManager = IconManager::instance();
|
|
|
|
connect(&iconManager, &IconManager::statusIconsChanged, this, &SyncthingModel::handleStatusIconsChanged);
|
|
|
|
connect(&iconManager, &IconManager::forkAwesomeIconsChanged, this, &SyncthingModel::handleForkAwesomeIconsChanged);
|
2017-05-01 03:34:43 +02:00
|
|
|
}
|
2016-11-02 21:05:32 +01:00
|
|
|
|
2017-09-11 23:44:19 +02:00
|
|
|
const QVector<int> &SyncthingModel::colorRoles() const
|
|
|
|
{
|
|
|
|
static const QVector<int> colorRoles;
|
|
|
|
return colorRoles;
|
|
|
|
}
|
|
|
|
|
2021-10-16 21:20:12 +02:00
|
|
|
void SyncthingModel::invalidateTopLevelIndicies(const QVector<int> &affectedRoles)
|
2016-11-02 21:05:32 +01:00
|
|
|
{
|
2021-10-16 21:20:12 +02:00
|
|
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1), affectedRoles);
|
|
|
|
}
|
2019-02-27 20:41:50 +01:00
|
|
|
|
2021-10-16 21:20:12 +02:00
|
|
|
void SyncthingModel::invalidateNestedIndicies(const QVector<int> &affectedRoles)
|
|
|
|
{
|
|
|
|
for (auto i = 0, rows = rowCount(); i != rows; ++i) {
|
2019-02-27 20:41:50 +01:00
|
|
|
const auto parentIndex = index(i, 0);
|
|
|
|
const auto childRows = rowCount(parentIndex);
|
|
|
|
if (childRows > 0) {
|
|
|
|
emit dataChanged(index(0, 0, parentIndex), index(childRows - 1, columnCount(parentIndex) - 1), affectedRoles);
|
2017-09-11 23:44:19 +02:00
|
|
|
}
|
2016-11-02 21:05:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 21:20:12 +02:00
|
|
|
void SyncthingModel::setBrightColors(bool brightColors)
|
|
|
|
{
|
|
|
|
if (m_brightColors == brightColors) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_brightColors = brightColors;
|
|
|
|
|
|
|
|
if (const QVector<int> &affectedRoles = colorRoles(); !affectedRoles.isEmpty()) {
|
|
|
|
invalidateTopLevelIndicies(affectedRoles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 02:33:57 +01:00
|
|
|
void SyncthingModel::handleConfigInvalidated()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingModel::handleNewConfigAvailable()
|
|
|
|
{
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
2019-05-19 21:51:55 +02:00
|
|
|
void SyncthingModel::handleStatusIconsChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-16 21:20:12 +02:00
|
|
|
void SyncthingModel::handleForkAwesomeIconsChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:05:32 +01:00
|
|
|
} // namespace Data
|