Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some extra syncing details to the tray icon tooltip #7057

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,18 +1610,21 @@ void FolderMan::slotLeaveShare(const QString &localFile, const QByteArray &folde
}

void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
SyncResult::Status *status, bool *unresolvedConflicts)
SyncResult::Status *status,
bool *unresolvedConflicts,
ProgressInfo **const overallProgressInfo)
{
*status = SyncResult::Undefined;
*unresolvedConflicts = false;

const auto cnt = folders.count();

// if one folder: show the state of the one folder.
// if one folder: show the state of the one folder along with the sync status.
// if more folders:
// if one of them has an error -> show error
// if one is paused, but others ok, show ok
// do not show "problem" in the tray
// and do not show sync status
//
if (cnt == 1) {
const auto folder = folders.at(0);
Expand All @@ -1644,6 +1647,7 @@ void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
}
}
*unresolvedConflicts = syncResult.hasUnresolvedConflicts();
*overallProgressInfo = folder->syncEngine().progressInfo();
}
} else {
auto errorsSeen = false;
Expand Down Expand Up @@ -1710,8 +1714,7 @@ void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
}
}

QString FolderMan::trayTooltipStatusString(
SyncResult::Status syncStatus, bool hasUnresolvedConflicts, bool paused)
QString FolderMan::trayTooltipStatusString(SyncResult::Status syncStatus, bool hasUnresolvedConflicts, bool paused, ProgressInfo *const progress)
{
QString folderMessage;
switch (syncStatus) {
Expand All @@ -1725,6 +1728,35 @@ QString FolderMan::trayTooltipStatusString(
folderMessage = tr("Preparing for sync.");
break;
case SyncResult::SyncRunning:
if (progress && progress->status() == ProgressInfo::Propagation) {
const auto estimatedEta = progress->totalProgress().estimatedEta;
if (progress->totalSize() == 0) {
qint64 currentFile = progress->currentFile();
qint64 totalFileCount = qMax(progress->totalFiles(), currentFile);
if (progress->trustEta()) {
if (estimatedEta == 0) {
folderMessage = tr("Syncing %1 of %2 (A few seconds left)").arg(currentFile).arg(totalFileCount);
} else {
folderMessage =
tr("Syncing %1 of %2 (%3 left)").arg(currentFile).arg(totalFileCount).arg(Utility::durationToDescriptiveString1(estimatedEta));
}
} else {
folderMessage = tr("Syncing %1 of %2").arg(currentFile).arg(totalFileCount);
}
} else {
QString totalSizeStr = Utility::octetsToString(progress->totalSize());
if (progress->trustEta()) {
if (estimatedEta == 0) {
folderMessage = tr("Syncing %1 (A few seconds left)").arg(totalSizeStr, Utility::durationToDescriptiveString1(estimatedEta));
} else {
folderMessage = tr("Syncing %1 (%2 left)").arg(totalSizeStr, Utility::durationToDescriptiveString1(estimatedEta));
}
} else {
folderMessage = tr("Syncing %1").arg(totalSizeStr);
}
}
break;
}
folderMessage = tr("Sync is running.");
break;
case SyncResult::Success:
Expand Down
5 changes: 2 additions & 3 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef FOLDERMAN_H
#define FOLDERMAN_H

#include <QByteArray>

Check failure on line 19 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:19:10 [clang-diagnostic-error]

'QByteArray' file not found
#include <QObject>
#include <QQueue>
#include <QList>
Expand Down Expand Up @@ -137,11 +137,10 @@
bool startFromScratch(const QString &);

/// Produce text for use in the tray tooltip
static QString trayTooltipStatusString(SyncResult::Status syncStatus, bool hasUnresolvedConflicts, bool paused);
static QString trayTooltipStatusString(SyncResult::Status syncStatus, bool hasUnresolvedConflicts, bool paused, ProgressInfo *progress);

/// Compute status summarizing multiple folders
static void trayOverallStatus(const QList<Folder *> &folders,
SyncResult::Status *status, bool *unresolvedConflicts);
static void trayOverallStatus(const QList<Folder *> &folders, SyncResult::Status *status, bool *unresolvedConflicts, ProgressInfo **overallProgressInfo);

// Escaping of the alias which is used in QSettings AND the file
// system, thus need to be escaped.
Expand Down
45 changes: 10 additions & 35 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "theme.h"
#include "wheelhandler.h"
#include "syncconflictsmodel.h"
#include "syncengine.h"
#include "filedetails/datefieldbackend.h"
#include "filedetails/filedetails.h"
#include "filedetails/shareemodel.h"
Expand Down Expand Up @@ -383,7 +384,8 @@

SyncResult::Status overallStatus = SyncResult::Undefined;
bool hasUnresolvedConflicts = false;
FolderMan::trayOverallStatus(map.values(), &overallStatus, &hasUnresolvedConflicts);
ProgressInfo *overallProgressInfo = nullptr;

Check warning on line 387 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudgui.cpp:387:19 [cppcoreguidelines-init-variables]

variable 'overallProgressInfo' is not initialized
FolderMan::trayOverallStatus(map.values(), &overallStatus, &hasUnresolvedConflicts, &overallProgressInfo);

#ifdef BUILD_FILE_PROVIDER_MODULE
if (!problemFileProviderAccounts.isEmpty()) {
Expand Down Expand Up @@ -420,16 +422,16 @@
#endif
#ifdef Q_OS_WIN
// Windows has a 128-char tray tooltip length limit.
trayMessage = folderMan->trayTooltipStatusString(overallStatus, hasUnresolvedConflicts, false);
trayMessage = folderMan->trayTooltipStatusString(overallStatus, hasUnresolvedConflicts, false, overallProgressInfo);
#else
QStringList allStatusStrings;
const auto folders = map.values();
for (const auto folder : folders) {
QString folderMessage = FolderMan::trayTooltipStatusString(
folder->syncResult().status(),
folder->syncResult().hasUnresolvedConflicts(),
folder->syncPaused());
allStatusStrings += tr("Folder %1: %2").arg(folder->shortGuiLocalPath(), folderMessage);
QString folderMessage = FolderMan::trayTooltipStatusString(folder->syncResult().status(),
folder->syncResult().hasUnresolvedConflicts(),
folder->syncPaused(),
folder->syncEngine().progressInfo());
allStatusStrings += tr("%1: %2").arg(folder->shortGuiLocalPath(), folderMessage);
}
#ifdef BUILD_FILE_PROVIDER_MODULE
for (const auto &accountId : syncingFileProviderAccounts) {
Expand Down Expand Up @@ -502,7 +504,6 @@
{
Q_UNUSED(folder);

// FIXME: Lots of messages computed for nothing in this method, needs revisiting
if (progress.status() == ProgressInfo::Discovery) {
#if 0
if (!progress._currentDiscoveredRemoteFolder.isEmpty()) {
Expand All @@ -520,33 +521,7 @@
return;
}

if (progress.totalSize() == 0) {
qint64 currentFile = progress.currentFile();
qint64 totalFileCount = qMax(progress.totalFiles(), currentFile);
QString msg;
if (progress.trustEta()) {
msg = tr("Syncing %1 of %2 (%3 left)")
.arg(currentFile)
.arg(totalFileCount)
.arg(Utility::durationToDescriptiveString2(progress.totalProgress().estimatedEta));
} else {
msg = tr("Syncing %1 of %2")
.arg(currentFile)
.arg(totalFileCount);
}
//_actionStatus->setText(msg);
} else {
QString totalSizeStr = Utility::octetsToString(progress.totalSize());
QString msg;
if (progress.trustEta()) {
msg = tr("Syncing %1 (%2 left)")
.arg(totalSizeStr, Utility::durationToDescriptiveString2(progress.totalProgress().estimatedEta));
} else {
msg = tr("Syncing %1")
.arg(totalSizeStr);
}
//_actionStatus->setText(msg);
}
slotComputeOverallSyncStatus();

if (!progress._lastCompletedItem.isEmpty()) {

Expand Down
5 changes: 0 additions & 5 deletions src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,6 @@ void Systray::showTalkMessage(const QString &title, const QString &message, cons
#endif
}

void Systray::setToolTip(const QString &tip)
{
QSystemTrayIcon::setToolTip(tr("%1: %2").arg(Theme::instance()->appNameGUI(), tip));
}

bool Systray::syncIsPaused() const
{
return _syncIsPaused;
Expand Down
1 change: 0 additions & 1 deletion src/gui/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public slots:
void showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon = Information);
void showUpdateMessage(const QString &title, const QString &message, const QUrl &webUrl);
void showTalkMessage(const QString &title, const QString &message, const QString &replyTo, const QString &token, const OCC::AccountStatePtr &accountState);
void setToolTip(const QString &tip);

void createCallDialog(const OCC::Activity &callNotification, const OCC::AccountStatePtr accountState);
void createEditFileLocallyLoadingDialog(const QString &fileName);
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#pragma once

#include <cstdint>

Check failure on line 18 in src/libsync/syncengine.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/syncengine.h:18:10 [clang-diagnostic-error]

'cstdint' file not found

#include <QMutex>
#include <QThread>
Expand Down Expand Up @@ -78,6 +78,11 @@
[[nodiscard]] SyncOptions syncOptions() const { return _syncOptions; }
[[nodiscard]] bool ignoreHiddenFiles() const { return _ignore_hidden_files; }

[[nodiscard]] ProgressInfo *progressInfo() const
{
return _progressInfo.get();
}

[[nodiscard]] ExcludedFiles &excludedFiles() const { return *_excludedFiles; }
[[nodiscard]] SyncFileStatusTracker &syncFileStatusTracker() const { return *_syncFileStatusTracker; }

Expand Down
Loading