Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.

Commit

Permalink
added support to show sync status of repo dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Skycoder42 committed Jul 13, 2018
1 parent 17d5748 commit 0f40797
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
69 changes: 55 additions & 14 deletions plugin/seafstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,45 @@ SeafStatus::SyncStatus SeafStatus::syncStatus(const QString &path)
ensureConnected();

auto repo = repoPath(path);
//TODO handle repository folder -> should show a global sync state of repo
if(!repo.isNull()) {
QDir repoDir(repo);
QDir repoDir{repo};
auto id = _repoIds.value(repo);
auto idString = id.toByteArray();
idString = idString.mid(1, idString.size() - 2);

GError *error = nullptr;
auto res = searpc_client_call__string(_client, "seafile_get_path_sync_status", &error, 3,
"string", idString.constData(),
"string", repoDir.relativeFilePath(path).toUtf8().constData(),
"int", QFileInfo(path).isDir());
if(error)
throw SeafException(error);
else {
auto status = mapStatus(res);
free(res);
return status;
if(repo == path) {
GError *error = nullptr;
auto taskObj = searpc_client_call__object (_client, "seafile_get_repo_sync_task", SEAFILE_TYPE_SYNC_TASK,
&error, 1,
"string", idString.constData());
auto task = SEAFILE_SYNC_TASK(taskObj);
if(error)
throw SeafException(error);
else {
if(QByteArray{seafile_sync_task_get_error(task)} != "Success") {
auto msg = QString::fromUtf8(seafile_sync_task_get_err_detail(task));
g_object_unref(taskObj);
throw SeafException{std::move(msg)};
} else {
auto status = mapRepoStatus(seafile_sync_task_get_state(task));
g_object_unref(taskObj);
return status;
}
}
} else {
GError *error = nullptr;
auto res = searpc_client_call__string(_client, "seafile_get_path_sync_status",
&error, 3,
"string", idString.constData(),
"string", repoDir.relativeFilePath(path).toUtf8().constData(),
"int", QFileInfo(path).isDir());
if(error)
throw SeafException(error);
else {
auto status = mapFileStatus(res);
free(res);
return status;
}
}
}

Expand Down Expand Up @@ -133,12 +154,14 @@ QString SeafStatus::repoPath(const QString &path)
for(auto it = _repoIds.constBegin(); it != _repoIds.constEnd(); it++) {
if(fullPath.startsWith(it.key()))
return it.key();
else if(QFileInfo{it.key()}.dir() == QDir{path})
return it.key();
}

return QString();
}

SeafStatus::SyncStatus SeafStatus::mapStatus(const QByteArray &text)
SeafStatus::SyncStatus SeafStatus::mapFileStatus(const QByteArray &text)
{
static const QHash<QByteArray, SeafStatus::SyncStatus> PathStatus {
{"none", None},
Expand All @@ -154,6 +177,24 @@ SeafStatus::SyncStatus SeafStatus::mapStatus(const QByteArray &text)
return PathStatus.value(text, Invalid);
}

SeafStatus::SyncStatus SeafStatus::mapRepoStatus(const QByteArray &text)
{
static const QHash<QByteArray, SeafStatus::SyncStatus> PathStatus {
{"synchronized", Synced},
{"committing", Syncing},
{"initializing", Syncing},
{"downloading", Syncing},
{"uploading", Syncing},
{"merging", Syncing},
{"waiting for sync", Paused},
{"relay not connected", Paused},
{"relay authenticating", Syncing},
{"auto sync is turned off", Paused},
{"cancel pendin", Paused}
};
return PathStatus.value(text, None);
}

QString SeafStatus::readSeafileIni()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
Expand Down
3 changes: 2 additions & 1 deletion plugin/seafstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ private slots:
QTimer *_conTimer;

QString repoPath(const QString &path);
SyncStatus mapStatus(const QByteArray &text);
SyncStatus mapFileStatus(const QByteArray &text);
SyncStatus mapRepoStatus(const QByteArray &text);
QString readSeafileIni();
};

Expand Down

0 comments on commit 0f40797

Please sign in to comment.