Perform inactive qquickwindow garbage collection when generating new file detail dialogs, raise existing dialog instead of always deleting

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2022-10-01 15:52:53 +02:00
parent d2552ba439
commit fb4bb95b91
No known key found for this signature in database
GPG Key ID: C839200C384636B0
2 changed files with 33 additions and 17 deletions

View File

@ -287,38 +287,52 @@ void Systray::destroyEditFileLocallyLoadingDialog()
bool Systray::raiseDialogs()
{
if(_dialogs.empty()) {
return raiseFileDetailDialogs();
}
bool Systray::raiseFileDetailDialogs(const QString &localPath)
{
if(_fileDetailDialogs.empty()) {
return false;
}
QVector<QQuickWindow*> liveDialogs;
auto it = _fileDetailDialogs.begin();
while (it != _fileDetailDialogs.end()) {
const auto dialog = *it;
auto liveDialog = dialog != nullptr;
for(const auto dialog : _dialogs) {
if(!dialog) {
continue;
} else if(!dialog->isVisible()) {
if (liveDialog && !dialog->isVisible()) {
destroyDialog(dialog);
liveDialog = false;
}
if (liveDialog && (localPath.isEmpty() || dialog->property("localPath").toString() == localPath)) {
dialog->show();
dialog->raise();
dialog->requestActivate();
++it;
continue;
}
liveDialogs.append(dialog);
dialog->show();
dialog->raise();
dialog->requestActivate();
it = _fileDetailDialogs.erase(it);
continue;
}
_dialogs = liveDialogs;
// If it is empty then we have raised no dialogs, so return false (and viceversa)
return !liveDialogs.empty();
return !_fileDetailDialogs.empty();
}
void Systray::createFileDetailsDialog(const QString &localPath)
{
if (raiseFileDetailDialogs(localPath)) {
qCDebug(lcSystray) << "Reopening an existing file details dialog for " << localPath;
return;
}
qCDebug(lcSystray) << "Opening new file details dialog for " << localPath;
if(!_trayEngine) {
if (!_trayEngine) {
qCWarning(lcSystray) << "Could not open file details dialog for" << localPath << "as no tray engine was available";
return;
}
@ -345,7 +359,7 @@ void Systray::createFileDetailsDialog(const QString &localPath)
return;
}
_dialogs.append(dialog);
_fileDetailDialogs.append(dialog);
dialog->show();
dialog->raise();

View File

@ -144,6 +144,8 @@ private slots:
void slotPauseAllFolders();
private:
// Argument allows user to specify a specific dialog to be raised
bool raiseFileDetailDialogs(const QString &localPath = {});
void setPauseOnAllFoldersHelper(bool pause);
static Systray *_instance;
@ -173,7 +175,7 @@ private:
QSet<qlonglong> _callsAlreadyNotified;
QPointer<QObject> _editFileLocallyLoadingDialog;
QVector<QQuickWindow*> _dialogs;
QVector<QQuickWindow*> _fileDetailDialogs;
};
} // namespace OCC