Show relevant dirs when sync complete
This commit is contained in:
parent
b40fc773c2
commit
992617ccc3
|
@ -748,6 +748,7 @@ void SyncthingConnection::readDirs(const QJsonArray &dirs)
|
|||
}
|
||||
}
|
||||
m_dirs.swap(newDirs);
|
||||
m_syncedDirs.reserve(m_dirs.size());
|
||||
emit this->newDirs(m_dirs);
|
||||
}
|
||||
|
||||
|
@ -1133,7 +1134,6 @@ void SyncthingConnection::readEvents()
|
|||
|
||||
if(m_keepPolling) {
|
||||
requestEvents();
|
||||
// TODO: need to change the status somewhere else
|
||||
setStatus(SyncthingStatus::Idle);
|
||||
} else {
|
||||
setStatus(SyncthingStatus::Disconnected);
|
||||
|
@ -1456,15 +1456,19 @@ void SyncthingConnection::setStatus(SyncthingStatus status)
|
|||
switch(status) {
|
||||
case SyncthingStatus::Disconnected:
|
||||
case SyncthingStatus::Reconnecting:
|
||||
// don't consider synchronization finished in this this case
|
||||
m_syncedDirs.clear();
|
||||
break;
|
||||
default:
|
||||
// check whether at least one directory is scanning or synchronizing
|
||||
bool scanning = false;
|
||||
bool synchronizing = false;
|
||||
for(const SyncthingDir &dir : m_dirs) {
|
||||
for(SyncthingDir &dir : m_dirs) {
|
||||
if(dir.status == SyncthingDirStatus::Synchronizing) {
|
||||
if(find(m_syncedDirs.cbegin(), m_syncedDirs.cend(), &dir) == m_syncedDirs.cend()) {
|
||||
m_syncedDirs.push_back(&dir);
|
||||
}
|
||||
synchronizing = true;
|
||||
break;
|
||||
} else if(dir.status == SyncthingDirStatus::Scanning) {
|
||||
scanning = true;
|
||||
}
|
||||
|
@ -1484,10 +1488,16 @@ void SyncthingConnection::setStatus(SyncthingStatus status)
|
|||
}
|
||||
if(paused) {
|
||||
status = SyncthingStatus::Paused;
|
||||
// don't consider synchronization finished in this this case
|
||||
m_syncedDirs.clear();
|
||||
} else {
|
||||
status = SyncthingStatus::Idle;
|
||||
}
|
||||
}
|
||||
if(status != SyncthingStatus::Synchronizing) {
|
||||
m_completedDirs.clear();
|
||||
m_completedDirs.swap(m_syncedDirs);
|
||||
}
|
||||
}
|
||||
if(m_status != status) {
|
||||
emit statusChanged(m_status = status);
|
||||
|
|
|
@ -100,6 +100,7 @@ public:
|
|||
SyncthingDir *findDirInfo(const QString &dirId, int &row);
|
||||
SyncthingDev *findDevInfo(const QString &devId, int &row);
|
||||
SyncthingDev *findDevInfoByName(const QString &devName, int &row);
|
||||
const std::vector<SyncthingDir *> &completedDirs() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void loadSelfSignedCertificate();
|
||||
|
@ -207,6 +208,8 @@ private:
|
|||
bool m_hasConfig;
|
||||
bool m_hasStatus;
|
||||
std::vector<SyncthingDir> m_dirs;
|
||||
std::vector<SyncthingDir *> m_syncedDirs;
|
||||
std::vector<SyncthingDir *> m_completedDirs;
|
||||
std::vector<SyncthingDev> m_devs;
|
||||
ChronoUtilities::DateTime m_lastConnectionsUpdate;
|
||||
ChronoUtilities::DateTime m_lastFileTime;
|
||||
|
@ -431,6 +434,14 @@ inline const QList<QSslError> &SyncthingConnection::expectedSslErrors()
|
|||
return m_expectedSslErrors;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the directories which have been synchronized during the last synchronizing status().
|
||||
*/
|
||||
inline const std::vector<SyncthingDir *> &SyncthingConnection::completedDirs() const
|
||||
{
|
||||
return m_completedDirs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // SYNCTHINGCONNECTION_H
|
||||
|
|
|
@ -63,6 +63,7 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir
|
|||
SyncthingDir(const QString &id = QString(), const QString &label = QString(), const QString &path = QString());
|
||||
bool assignStatus(const QString &statusStr, ChronoUtilities::DateTime time);
|
||||
bool assignStatus(SyncthingDirStatus newStatus, ChronoUtilities::DateTime time);
|
||||
const QString displayName() const;
|
||||
|
||||
QString id;
|
||||
QString label;
|
||||
|
@ -99,6 +100,11 @@ inline SyncthingDir::SyncthingDir(const QString &id, const QString &label, const
|
|||
path(path)
|
||||
{}
|
||||
|
||||
inline const QString SyncthingDir::displayName() const
|
||||
{
|
||||
return label.isEmpty() ? id : label;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
||||
#endif // DATA_SYNCTHINGDIR_H
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
|
||||
using namespace std;
|
||||
using namespace Dialogs;
|
||||
using namespace Data;
|
||||
|
||||
|
@ -155,7 +156,21 @@ void TrayIcon::updateStatusIconAndText(SyncthingStatus status)
|
|||
break;
|
||||
default:
|
||||
if(m_status == SyncthingStatus::Synchronizing && Settings::values().notifyOn.syncComplete) {
|
||||
showMessage(QCoreApplication::applicationName(), tr("Synchronization complete"), QSystemTrayIcon::Information);
|
||||
const vector<SyncthingDir *> &completedDirs = connection.completedDirs();
|
||||
if(!completedDirs.empty()) {
|
||||
QString message;
|
||||
if(completedDirs.size() == 1) {
|
||||
message = tr("Synchronization of %1 complete").arg(completedDirs.front()->displayName());
|
||||
} else {
|
||||
QStringList names;
|
||||
names.reserve(static_cast<int>(completedDirs.size()));
|
||||
for(const SyncthingDir *dir : completedDirs) {
|
||||
names << dir->displayName();
|
||||
}
|
||||
message = tr("Synchronization of the following devices complete:\n") + names.join(QStringLiteral(", "));
|
||||
}
|
||||
showMessage(QCoreApplication::applicationName(), message, QSystemTrayIcon::Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_status = status;
|
||||
|
|
Loading…
Reference in New Issue