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

Client crash 3 #478

Merged
merged 4 commits into from
Jan 27, 2025
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
2 changes: 1 addition & 1 deletion src/gui/info/driveinfoclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DriveInfoClient : public DriveInfo {
}
inline qint64 lastErrorTimestamp() const { return _lastErrorTimestamp; }
inline void setLastErrorTimestamp(int newLastErrorTimestamp) { _lastErrorTimestamp = newLastErrorTimestamp; }
inline bool isBeingDeleted() const noexcept { return _isBeingDeleted; };
inline bool isBeingDeleted() const noexcept { return _isBeingDeleted; }
inline void setIsBeingDeleted(bool isDeletionOnGoing) noexcept { _isBeingDeleted = isDeletionOnGoing; }

void updateStatus(std::map<int, SyncInfoClient> &syncInfoMap);
Expand Down
56 changes: 31 additions & 25 deletions src/gui/parametersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,6 @@ void ParametersDialog::initUI() {
connect(this, &ParametersDialog::newBigFolder, _drivePreferencesWidget, &DrivePreferencesWidget::newBigFolderDiscovered);
}

void ParametersDialog::createErrorTabWidgetIfNeeded(int driveDbId) {
const auto &driveInfoMapIt = _gui->driveInfoMap().find(driveDbId);
if (driveInfoMapIt == _gui->driveInfoMap().end()) {
qCDebug(lcParametersDialog()) << "Drive not found in drive map for driveDbId=" << driveDbId;
return;
}

if (driveInfoMapIt->second.errorTabWidgetStackPosition() == 0) {
driveInfoMapIt->second.setErrorTabWidgetStackPosition(
_errorsStackedWidget->addWidget(new ErrorTabWidget(driveDbId, false, this)));
}
}

QByteArray ParametersDialog::contents(const QString &path) {
QFile file(path);
if (file.open(QFile::ReadOnly)) {
Expand Down Expand Up @@ -896,36 +883,41 @@ void ParametersDialog::onConfigRefreshed() {
bool driveHasSyncs = false;

for (const auto &[driveId, driveInfo]: _gui->driveInfoMap()) {
ErrorTabWidget *errorTabWidget = static_cast<ErrorTabWidget *>(
_errorsStackedWidget->widget(driveInfo.errorTabWidgetStackPosition())); // position changed
ErrorTabWidget *errorTabWidget =
static_cast<ErrorTabWidget *>(_errorsStackedWidget->widget(driveInfo.errorTabWidgetStackPosition()));

if (errorTabWidget == widget) {
driveIsFound = true;
std::map<int, SyncInfoClient> syncInfoMap;
_gui->loadSyncInfoMap(_gui->currentDriveDbId(), syncInfoMap);
driveHasSyncs = !syncInfoMap.empty();

++widgetIndex;
driveHasSyncs = this->driveHasSyncs(driveInfo.dbId());
break;
}
}

if (driveIsFound && driveHasSyncs) continue;
if (driveIsFound && driveHasSyncs) {
++widgetIndex;
continue;
}

// Remove widget
_errorsStackedWidget->removeWidget(widget);
delete widget;

for (auto &[driveId, driveInfo]: _gui->driveInfoMap()) {
const auto position = driveInfo.errorTabWidgetStackPosition();
if (position > widgetIndex) driveInfo.setErrorTabWidgetStackPosition(position - 1);
if (position == widgetIndex)
// Reset position of the removed widget
driveInfo.setErrorTabWidgetStackPosition(0);
else if (position > widgetIndex)
// Update position of the next widgets
driveInfo.setErrorTabWidgetStackPosition(position - 1);
}
}

// Create missing Drive level (SyncPal or Node) errors list
for (auto &[driveId, driveInfo]: _gui->driveInfoMap()) {
createErrorTabWidgetIfNeeded(driveInfo.dbId());
if (driveInfo.errorTabWidgetStackPosition() == 0) {
driveInfo.setErrorTabWidgetStackPosition(_errorsStackedWidget->addWidget(new ErrorTabWidget(driveId, false)));
if (driveInfo.errorTabWidgetStackPosition() == 0 && driveHasSyncs(driveInfo.dbId())) {
driveInfo.setErrorTabWidgetStackPosition(
_errorsStackedWidget->addWidget(new ErrorTabWidget(driveInfo.dbId(), false, this)));
}
refreshErrorList(driveId);
}
Expand Down Expand Up @@ -1152,6 +1144,13 @@ void ParametersDialog::onClearErrors(int driveDbId, bool autoResolved) {
}
}

if (!errorTabWidget) {
// Should never happen
assert(false);
qCDebug(lcParametersDialog()) << "Error widget not found for driveDbId=" << driveDbId;
return;
}

listWidgetToClear =
autoResolved ? errorTabWidget->autoResolvedErrorsListWidget() : errorTabWidget->unresolvedErrorsListWidget();
while (listWidgetToClear->count()) {
Expand Down Expand Up @@ -1259,4 +1258,11 @@ void ParametersDialog::refreshErrorList(int driveDbId) {
_drivePreferencesWidget->showErrorBanner(unresolvedErrorCount > 0);
}
}

bool ParametersDialog::driveHasSyncs(int driveDbId) const {
std::map<int, SyncInfoClient> syncInfoMap;
_gui->loadSyncInfoMap(driveDbId, syncInfoMap);
return !syncInfoMap.empty();
}

} // namespace KDC
2 changes: 1 addition & 1 deletion src/gui/parametersdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class ParametersDialog : public CustomDialog {
QString getSyncPalBackErrorText(const QString &err, ExitCause exitCause, bool userIsAdmin) const;
QString getErrorLevelNodeText(const ErrorInfo &errorInfo) const;

void createErrorTabWidgetIfNeeded(int driveDbId);
void refreshErrorList(int driveDbId);
bool driveHasSyncs(int driveDbId) const;

private slots:
void onExit();
Expand Down
Loading