mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-03-28 14:56:19 +01:00
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
This commit is contained in:
parent
9b51f26e80
commit
aa375a7f89
5 changed files with 60 additions and 29 deletions
|
@ -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
|
||||
|
@ -63,7 +61,7 @@ ApplicationWindow {
|
|||
sourceComponent: GenericErrorsRow {
|
||||
id: genericError
|
||||
text: CurrentAccount.enabled ? JamiStrings.noNetworkConnectivity : JamiStrings.disabledAccount
|
||||
height: visible? JamiTheme.qwkTitleBarHeight : 0
|
||||
height: visible ? JamiTheme.qwkTitleBarHeight : 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -331,7 +334,7 @@ ApplicationWindow {
|
|||
});
|
||||
}
|
||||
|
||||
function presentUpdateConfirmInstallDialog(switchToBeta=false) {
|
||||
function presentUpdateConfirmInstallDialog(switchToBeta = false) {
|
||||
return viewCoordinator.presentDialog(appWindow, "commoncomponents/SimpleMessageDialog.qml", {
|
||||
"title": JamiStrings.updateDialogTitle,
|
||||
"infoText": switchToBeta ? JamiStrings.confirmBeta : JamiStrings.updateFound,
|
||||
|
@ -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.
|
||||
|
@ -64,12 +64,12 @@ QtObject {
|
|||
currentViewName: currentViewName,
|
||||
isDualPane: isDualPane,
|
||||
isInSinglePaneMode: isInSinglePaneMode,
|
||||
visibleViews: visibleViews.map(function(view) {
|
||||
return view && view.objectName || null;
|
||||
}),
|
||||
visibleViewWidths: visibleViews.map(function(view) {
|
||||
return view && view.width || null;
|
||||
}),
|
||||
visibleViews: visibleViews.map(function (view) {
|
||||
return view && view.objectName || null;
|
||||
}),
|
||||
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:
|
||||
|
|
|
@ -44,7 +44,7 @@ Rectangle {
|
|||
function updateMessageDraft() {
|
||||
// Store the current files that have not been sent, if any. Do the same for the message draft.
|
||||
var filePathDraft = [];
|
||||
while(messageBar.fileContainer.filesToSendCount > 0) {
|
||||
while (messageBar.fileContainer.filesToSendCount > 0) {
|
||||
var currentIndex = messageBar.fileContainer.filesToSendListModel.index(0, 0);
|
||||
var filePath = messageBar.fileContainer.filesToSendListModel.data(currentIndex, FilesToSend.FilePath);
|
||||
filePathDraft.push(filePath);
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue