Skip to content
Snippets Groups Projects
Commit aa375a7f authored by Page Magnier-Slimani's avatar Page Magnier-Slimani Committed by François-Simon Fauteux-Chapleau
Browse files

FileDialog: make a single instance filedialog

Modify the presentDialog method to account for single instance windows and implement a "hack" around the modality issues of Qt.

GitLab: #1905
Change-Id: I166bfc028939240955f20ec9b5777d6f282ccf78
parent 9b51f26e
No related branches found
No related tags found
No related merge requests found
......@@ -19,19 +19,17 @@ import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import net.jami.Models 1.1
import net.jami.Adapters 1.1
import net.jami.Enums 1.1
import net.jami.Helpers 1.1
import net.jami.Constants 1.1
import "mainview"
import "mainview/components"
import "wizardview"
import "commoncomponents"
import QWindowKit
import QtQuick.Dialogs
ApplicationWindow {
id: appWindow
......@@ -87,9 +85,11 @@ ApplicationWindow {
appContainer: fullscreenContainer
}
// Used to manage dynamic view loading and unloading.
property ViewManager viewManager: ViewManager {}
property ViewManager viewManager: ViewManager {
}
// Used to manage the view stack and the current view.
property ViewCoordinator viewCoordinator: ViewCoordinator {}
property ViewCoordinator viewCoordinator: ViewCoordinator {
}
// Used to prevent the window from being visible until the
// window geometry has been restored and the view stack has
......@@ -199,7 +199,6 @@ ApplicationWindow {
if (useFrameless) {
windowAgent.setup(appWindow);
}
mainViewLoader.active = true;
// Dbus error handler for Linux.
......@@ -216,10 +215,14 @@ ApplicationWindow {
"confirmLabel": JamiStrings.send,
"rejectLabel": JamiStrings.dontSend,
"textHAlign": Text.AlignLeft,
"textMaxWidth": 400,
"textMaxWidth": 400
});
dlg.accepted.connect(function () {
crashReporter.uploadLastReport();
});
dlg.rejected.connect(function () {
crashReporter.clearReports();
});
dlg.accepted.connect(function () { crashReporter.uploadLastReport(); });
dlg.rejected.connect(function () { crashReporter.clearReports(); });
}
}
......@@ -293,7 +296,7 @@ ApplicationWindow {
target: MainApplication
function onAboutToQuit() {
cleanupMainView()
cleanupMainView();
}
function onCloseRequested() {
......@@ -382,7 +385,7 @@ ApplicationWindow {
presentUpdateInfoDialog(JamiStrings.updateNotFound);
} else {
// Show a dialog describing that an update were found, and offering to install it.
presentUpdateConfirmInstallDialog()
presentUpdateConfirmInstallDialog();
}
}
......@@ -393,4 +396,20 @@ ApplicationWindow {
}
onClosing: appWindow.close()
// Capture the inputs to the main window while the File Dialog is open
// This is used to mitigate modality issues on Ubuntu 22.04 systems that use wayland.
Loader {
active: JamiQmlUtils.openFileDialogCount > 0
sourceComponent: Popup {
modal: true
visible: true
closePolicy: Popup.NoAutoClose
width: appWindow.width
height: appWindow.height
background: Rectangle {
color: "#80808080" // Semi-transparent grey
}
}
}
}
......@@ -49,13 +49,13 @@ QtObject {
// right side when not in RTL and should represent the main or content-type view.
readonly property var visibleViews: {
if (!currentView)
return []
return [];
if (isDualPane) {
if (isInSinglePaneMode)
return [currentView.rightPaneItem]
return [currentView.leftPaneItem, currentView.rightPaneItem]
return [currentView.rightPaneItem];
return [currentView.leftPaneItem, currentView.rightPaneItem];
}
return [currentView]
return [currentView];
}
// Aggregate this info and expose it as a single string for convenience.
// JSON indented by 2 spaces.
......@@ -69,7 +69,7 @@ QtObject {
}),
visibleViewWidths: visibleViews.map(function (view) {
return view && view.width || null;
}),
})
};
return JSON.stringify(info, null, 2);
}
......@@ -96,9 +96,10 @@ QtObject {
}
// Create, present, and return a dialog object.
function presentDialog(parent, path, props = {}) {
function presentDialog(parent, path, props = {}, singleInstance = false) {
// Open the dialog once the object is created
return viewManager.createUniqueView(path, parent, function (obj) {
let createFunc = singleInstance ? viewManager.createView : viewManager.createUniqueView;
return createFunc(path, parent, function (obj) {
const doneCb = function () {
viewManager.destroyView(path);
};
......
......@@ -27,6 +27,14 @@ FileDialog {
signal fileAccepted(string file)
signal filesAccepted(var files)
Component.onCompleted: {
JamiQmlUtils.openFileDialogCount++;
}
Component.onDestruction: {
JamiQmlUtils.openFileDialogCount--;
}
onAccepted: {
switch (fileMode) {
case FileDialog.OpenFile:
......
......@@ -66,7 +66,6 @@ Rectangle {
messageBar.fileContainer.filesToSendListModel.addToPending(restoredContent["files"][i]);
}
}
}
Connections {
......@@ -203,7 +202,7 @@ Rectangle {
var dlg = viewCoordinator.presentDialog(appWindow, "commoncomponents/JamiFileDialog.qml", {
"fileMode": JamiFileDialog.OpenFiles,
"nameFilters": [JamiStrings.allFiles]
});
}, true); // is a single instance
dlg.filesAccepted.connect(function (files) {
setFilePathsToSend(files);
});
......
......@@ -83,7 +83,8 @@ Item {
function onDonationCampaignSettingsChanged() {
// Changing any of the donation campaign settings will trigger a recompute
// of the banner visibility.
updateIsDonationBannerVisible(); }
updateIsDonationBannerVisible();
}
}
function updateIsDonationBannerVisible() {
......@@ -99,4 +100,7 @@ Item {
const now = new Date();
return isVisible && now < endDate && now >= startDate;
}
// Track if a fileDialog is opened. Is int to account for eventual future features including multiple FileDialog
property int openFileDialogCount: 0
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment