mobile: make list of local cloud cache directories available

This way QML can show those to the user.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-06-06 09:51:40 -07:00
parent 8b167c14ad
commit dd82149726
2 changed files with 27 additions and 1 deletions

View file

@ -403,6 +403,8 @@ void QMLManager::openLocalThenRemote(QString url)
updateAllGlobalLists(); updateAllGlobalLists();
setDiveListProcessing(false); setDiveListProcessing(false);
// this could have added a new local cache directory
emit cloudCacheListChanged();
} }
// Convenience function to accesss dive directly via its row. // Convenience function to accesss dive directly via its row.
@ -534,6 +536,9 @@ void QMLManager::finishSetup()
} }
m_initialized = true; m_initialized = true;
emit initializedChanged(); emit initializedChanged();
// this could have brought in new cache directories, so make sure QML
// calls our getter function again and doesn't show us outdated information
emit cloudCacheListChanged();
} }
QMLManager::~QMLManager() QMLManager::~QMLManager()
@ -2201,3 +2206,22 @@ void QMLManager::setDiveListProcessing(bool value)
} }
} }
QStringList QMLManager::cloudCacheList() const
{
QDir localCacheDir(QString("%1/cloudstorage/").arg(system_default_directory()));
QStringList dirs = localCacheDir.entryList().filter(QRegExp("...+"));
QStringList result;
foreach(QString dir, dirs) {
QString originsDir = QString("%1/cloudstorage/%2/.git/refs/remotes/origin/").arg(system_default_directory()).arg(dir);
QDir remote(originsDir);
if (dir == "localrepo") {
result << QString("localrepo[master]");
} else {
foreach(QString branch, remote.entryList().filter(QRegExp("...+"))) {
result << QString("%1[%2]").arg(dir).arg(branch);
}
}
}
return result;
}

View file

@ -40,6 +40,7 @@ class QMLManager : public QObject {
Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged) Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged)
Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged) Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged)
Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT) Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT)
Q_PROPERTY(QStringList cloudCacheList READ cloudCacheList NOTIFY cloudCacheListChanged)
Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged) Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
Q_PROPERTY(bool btEnabled MEMBER m_btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged) Q_PROPERTY(bool btEnabled MEMBER m_btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged)
@ -161,6 +162,7 @@ public:
QStringList divemasterList() const; QStringList divemasterList() const;
QStringList locationList() const; QStringList locationList() const;
QStringList cylinderInit() const; QStringList cylinderInit() const;
QStringList cloudCacheList() const;
Q_INVOKABLE void setStatusbarColor(QColor color); Q_INVOKABLE void setStatusbarColor(QColor color);
void btHostModeChange(QBluetoothLocalDevice::HostMode state); void btHostModeChange(QBluetoothLocalDevice::HostMode state);
QObject *qmlWindow; QObject *qmlWindow;
@ -303,6 +305,7 @@ signals:
void buddyListChanged(); void buddyListChanged();
void divemasterListChanged(); void divemasterListChanged();
void locationListChanged(); void locationListChanged();
void cloudCacheListChanged();
void waitingForPositionChanged(); void waitingForPositionChanged();
void pluggedInDeviceNameChanged(); void pluggedInDeviceNameChanged();
void showNonDiveComputersChanged(); void showNonDiveComputersChanged();
@ -316,7 +319,6 @@ signals:
void uploadFinish(bool success, const QString &text); void uploadFinish(bool success, const QString &text);
void uploadProgress(qreal percentage); void uploadProgress(qreal percentage);
private slots: private slots:
void uploadFinishSlot(bool success, const QString &text, const QByteArray &html); void uploadFinishSlot(bool success, const QString &text, const QByteArray &html);
}; };