2018-11-28 20:57:48 +01:00
|
|
|
#include "./syncthingdiractions.h"
|
2020-02-18 20:46:57 +01:00
|
|
|
#include "./syncthingfileitemactionstaticdata.h"
|
2018-11-28 20:57:48 +01:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingmodel/syncthingicons.h>
|
2018-11-28 20:57:48 +01:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingdir.h>
|
|
|
|
#include <syncthingconnector/utils.h>
|
2018-11-28 20:57:48 +01:00
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
2020-02-18 20:46:57 +01:00
|
|
|
SyncthingDirActions::SyncthingDirActions(const SyncthingDir &dir, const SyncthingFileItemActionStaticData *data, QObject *parent)
|
2018-11-28 20:57:48 +01:00
|
|
|
: QObject(parent)
|
|
|
|
, m_dirId(dir.id)
|
|
|
|
{
|
2021-10-16 21:20:12 +02:00
|
|
|
Q_UNUSED(data)
|
|
|
|
const auto &icons = commonForkAwesomeIcons();
|
2018-11-28 20:57:48 +01:00
|
|
|
m_infoAction.setSeparator(true);
|
2020-02-18 20:46:57 +01:00
|
|
|
m_infoAction.setIcon(icons.folder);
|
|
|
|
m_globalStatusAction.setIcon(icons.globe);
|
|
|
|
m_localStatusAction.setIcon(icons.home);
|
|
|
|
m_lastScanAction.setIcon(icons.clock);
|
|
|
|
m_rescanIntervalAction.setIcon(icons.refresh);
|
|
|
|
m_errorsAction.setIcon(icons.exclamationTriangle);
|
2018-11-28 20:57:48 +01:00
|
|
|
updateStatus(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingDirActions::updateStatus(const std::vector<SyncthingDir> &dirs)
|
|
|
|
{
|
|
|
|
for (const SyncthingDir &dir : dirs) {
|
|
|
|
if (updateStatus(dir)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_statusAction.setText(tr("Status: not available anymore"));
|
|
|
|
m_statusAction.setIcon(statusIcons().disconnected);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SyncthingDirActions::updateStatus(const SyncthingDir &dir)
|
|
|
|
{
|
|
|
|
if (dir.id != m_dirId) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-09-17 20:33:31 +02:00
|
|
|
m_infoAction.setText(tr("Folder info for %1").arg(dir.displayName()));
|
2018-11-28 20:57:48 +01:00
|
|
|
m_statusAction.setText(tr("Status: ") + dir.statusString());
|
|
|
|
if (dir.paused && dir.status != SyncthingDirStatus::OutOfSync) {
|
|
|
|
m_statusAction.setIcon(statusIcons().pause);
|
|
|
|
} else if (dir.isUnshared()) {
|
|
|
|
m_statusAction.setIcon(statusIcons().disconnected);
|
|
|
|
} else {
|
|
|
|
switch (dir.status) {
|
|
|
|
case SyncthingDirStatus::Unknown:
|
|
|
|
m_statusAction.setIcon(statusIcons().disconnected);
|
|
|
|
break;
|
|
|
|
case SyncthingDirStatus::Idle:
|
2020-12-31 02:13:32 +01:00
|
|
|
case SyncthingDirStatus::WaitingToClean:
|
|
|
|
case SyncthingDirStatus::Cleaning:
|
2018-11-28 20:57:48 +01:00
|
|
|
m_statusAction.setIcon(statusIcons().idling);
|
|
|
|
break;
|
2019-09-27 16:41:24 +02:00
|
|
|
case SyncthingDirStatus::WaitingToScan:
|
2018-11-28 20:57:48 +01:00
|
|
|
case SyncthingDirStatus::Scanning:
|
|
|
|
m_statusAction.setIcon(statusIcons().scanninig);
|
|
|
|
break;
|
2020-12-31 02:13:32 +01:00
|
|
|
case SyncthingDirStatus::WaitingToSync:
|
2019-09-27 16:32:54 +02:00
|
|
|
case SyncthingDirStatus::PreparingToSync:
|
2018-11-28 20:57:48 +01:00
|
|
|
case SyncthingDirStatus::Synchronizing:
|
|
|
|
m_statusAction.setIcon(statusIcons().sync);
|
|
|
|
break;
|
|
|
|
case SyncthingDirStatus::OutOfSync:
|
|
|
|
m_statusAction.setIcon(statusIcons().error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_globalStatusAction.setText(tr("Global: ") + directoryStatusString(dir.globalStats));
|
|
|
|
m_localStatusAction.setText(tr("Local: ") + directoryStatusString(dir.localStats));
|
|
|
|
m_lastScanAction.setText(tr("Last scan time: ") + agoString(dir.lastScanTime));
|
|
|
|
m_rescanIntervalAction.setText(tr("Rescan interval: %1 seconds").arg(dir.rescanInterval));
|
|
|
|
if (!dir.pullErrorCount) {
|
|
|
|
m_errorsAction.setVisible(false);
|
|
|
|
} else {
|
|
|
|
m_errorsAction.setVisible(true);
|
|
|
|
m_errorsAction.setText(tr("%1 item(s) out-of-sync", nullptr, trQuandity(dir.pullErrorCount)).arg(dir.pullErrorCount));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction *> &operator<<(QList<QAction *> &actions, SyncthingDirActions &dirActions)
|
|
|
|
{
|
|
|
|
return actions << &dirActions.m_infoAction << &dirActions.m_statusAction << &dirActions.m_globalStatusAction << &dirActions.m_localStatusAction
|
|
|
|
<< &dirActions.m_lastScanAction << &dirActions.m_rescanIntervalAction << &dirActions.m_errorsAction;
|
|
|
|
}
|