Skip to content

Commit e2dcb8e

Browse files
authored
Merge pull request #6062 from opengisch/hide_webdav_configuration_json
WebDAV cleanup and improvements
2 parents 5b67281 + e494184 commit e2dcb8e

File tree

6 files changed

+190
-37
lines changed

6 files changed

+190
-37
lines changed

images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<file>themes/qfield/nodpi/ic_ring_tool_white_24dp.svg</file>
138138
<file>themes/qfield/nodpi/ic_vertex_tool_white_24dp.svg</file>
139139
<file>themes/qfield/nodpi/ic_view_black_24dp.svg</file>
140+
<file>themes/qfield/nodpi/ic_wipe_white_24dp.svg</file>
140141
<file>themes/qfield/nodpi/ic_navigation_flag_purple_24dp.svg</file>
141142
<file>themes/qfield/nodpi/ic_bookmark_black_24dp.svg</file>
142143
<file>themes/qfield/nodpi/ic_legend_collapsed_state_24dp.svg</file>
Lines changed: 1 addition & 0 deletions
Loading

src/core/localfilesmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ void LocalFilesModel::reloadModel()
277277
// Skip project preview images
278278
continue;
279279
}
280+
else if ( item == QStringLiteral( "qfield_webdav_configuration.json" ) )
281+
{
282+
// Skip QField WebDAV configuration file
283+
continue;
284+
}
280285

281286
if ( SUPPORTED_PROJECT_EXTENSIONS.contains( suffix ) )
282287
{

src/core/webdavconnection.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,62 @@ void WebdavConnection::getWebdavItems()
444444
}
445445
}
446446

447+
void WebdavConnection::forgetHistory( const QString &url, const QString &username )
448+
{
449+
QgsAuthManager *authManager = QgsApplication::instance()->authManager();
450+
QgsAuthMethodConfigsMap configs = authManager->availableAuthMethodConfigs();
451+
QSettings settings;
452+
if ( !username.isEmpty() )
453+
{
454+
// Add a dummy value into the root of the server to avoid it being deleted due to empty group
455+
settings.setValue( QStringLiteral( "/qfield/webdavImports/%1/dummy" ).arg( QUrl::toPercentEncoding( url ) ), 1 );
456+
settings.beginGroup( QStringLiteral( "/qfield/webdavImports/%1/users/%2" ).arg( QUrl::toPercentEncoding( url ), QUrl::toPercentEncoding( username ) ) );
457+
settings.remove( "" );
458+
settings.endGroup();
459+
460+
for ( QgsAuthMethodConfig &config : configs )
461+
{
462+
if ( config.uri() == url )
463+
{
464+
authManager->loadAuthenticationConfig( config.id(), config, true );
465+
if ( config.config( QStringLiteral( "username" ) ) == username )
466+
{
467+
authManager->removeAuthenticationConfig( config.id() );
468+
}
469+
}
470+
}
471+
}
472+
else if ( !url.isEmpty() )
473+
{
474+
settings.beginGroup( QStringLiteral( "/qfield/webdavImports/%1" ).arg( QUrl::toPercentEncoding( url ) ) );
475+
settings.remove( "" );
476+
settings.endGroup();
477+
478+
for ( QgsAuthMethodConfig &config : configs )
479+
{
480+
if ( config.uri() == url )
481+
{
482+
authManager->removeAuthenticationConfig( config.id() );
483+
}
484+
}
485+
}
486+
else
487+
{
488+
settings.beginGroup( QStringLiteral( "/qfield/webdavImports" ) );
489+
const QStringList urls = settings.allKeys();
490+
settings.remove( "" );
491+
settings.endGroup();
492+
493+
for ( QgsAuthMethodConfig &config : configs )
494+
{
495+
if ( urls.contains( config.uri() ) )
496+
{
497+
authManager->removeAuthenticationConfig( config.id() );
498+
}
499+
}
500+
}
501+
}
502+
447503
QVariantMap WebdavConnection::importHistory()
448504
{
449505
// Collect imported folders

src/core/webdavconnection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ class WebdavConnection : public QObject
190190
*/
191191
Q_INVOKABLE static QVariantMap importHistory();
192192

193+
Q_INVOKABLE static void forgetHistory( const QString &url = QString(), const QString &username = QString() );
194+
193195
signals:
194196
void urlChanged();
195197
void usernameChanged();

src/qml/QFieldLocalDataPickerScreen.qml

Lines changed: 125 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,7 @@ Page {
11061106

11071107
property var importHistory: undefined
11081108

1109-
onAboutToShow: {
1110-
swipeDialog.currentIndex = 0;
1109+
function reloadHistory() {
11111110
if (webdavConnectionLoader.item) {
11121111
importHistory = webdavConnectionLoader.item.importHistory();
11131112
importWebdavUrlInput.model = [""].concat(Object.keys(importHistory["urls"]));
@@ -1125,34 +1124,43 @@ Page {
11251124
}
11261125
}
11271126

1127+
onAboutToShow: {
1128+
swipeDialog.currentIndex = 0;
1129+
reloadHistory();
1130+
}
1131+
1132+
TextMetrics {
1133+
id: importWebdavUrlLabelMetrics
1134+
font: importWebdavUrlLabel.font
1135+
text: importWebdavUrlLabel.text
1136+
}
1137+
11281138
SwipeView {
11291139
id: swipeDialog
11301140
width: mainWindow.width - 60 < importWebdavUrlLabelMetrics.width ? mainWindow.width - 60 : importWebdavUrlLabelMetrics.width
11311141
clip: true
1142+
interactive: false
11321143

1133-
Column {
1144+
GridLayout {
11341145
id: firstPage
1135-
width: childrenRect.width
1136-
height: childrenRect.height
1137-
spacing: 10
1138-
1139-
TextMetrics {
1140-
id: importWebdavUrlLabelMetrics
1141-
font: importWebdavUrlLabel.font
1142-
text: importWebdavUrlLabel.text
1143-
}
1146+
width: swipeDialog.width
1147+
rowSpacing: 10
1148+
columnSpacing: 5
1149+
columns: 2
11441150

11451151
Label {
11461152
id: importWebdavUrlLabel
1147-
width: mainWindow.width - 60 < importWebdavUrlLabelMetrics.width ? mainWindow.width - 60 : importWebdavUrlLabelMetrics.width
1153+
Layout.fillWidth: true
1154+
Layout.columnSpan: 2
11481155
text: qsTr("Type the WebDAV details below to import a remote folder:")
11491156
wrapMode: Text.WordWrap
11501157
font: Theme.defaultFont
11511158
color: Theme.mainTextColor
11521159
}
11531160

11541161
Label {
1155-
width: importWebdavUrlLabel.width
1162+
Layout.fillWidth: true
1163+
Layout.columnSpan: 2
11561164
text: qsTr("WebDAV server URL")
11571165
wrapMode: Text.WordWrap
11581166
font: Theme.defaultFont
@@ -1161,8 +1169,8 @@ Page {
11611169

11621170
ComboBox {
11631171
id: importWebdavUrlInput
1172+
Layout.fillWidth: true
11641173
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
1165-
width: importWebdavUrlLabel.width
11661174
editable: true
11671175

11681176
Connections {
@@ -1183,8 +1191,24 @@ Page {
11831191
}
11841192
}
11851193

1194+
QfToolButton {
1195+
bgcolor: "transparent"
1196+
iconSource: Theme.getThemeVectorIcon('ic_delete_forever_white_24dp')
1197+
iconColor: enabled ? Theme.mainTextColor : Theme.mainTextDisabledColor
1198+
enabled: importWebdavUrlInput.editText !== ""
1199+
1200+
onClicked: {
1201+
if (webdavConnectionLoader.item) {
1202+
webdavForgetConfirmationDialog.url = importWebdavUrlInput.editText;
1203+
webdavForgetConfirmationDialog.username = "";
1204+
webdavForgetConfirmationDialog.open();
1205+
}
1206+
}
1207+
}
1208+
11861209
Label {
1187-
width: importWebdavUrlLabel.width
1210+
Layout.fillWidth: true
1211+
Layout.columnSpan: 2
11881212
text: qsTr("User and password")
11891213
wrapMode: Text.WordWrap
11901214
font: Theme.defaultFont
@@ -1194,7 +1218,7 @@ Page {
11941218
ComboBox {
11951219
id: importWebdavUserInput
11961220
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
1197-
width: importWebdavUrlLabel.width
1221+
Layout.fillWidth: true
11981222
editable: true
11991223

12001224
Connections {
@@ -1209,10 +1233,25 @@ Page {
12091233
}
12101234
}
12111235

1236+
QfToolButton {
1237+
bgcolor: "transparent"
1238+
iconSource: Theme.getThemeVectorIcon('ic_delete_forever_white_24dp')
1239+
iconColor: enabled ? Theme.mainTextColor : Theme.mainTextDisabledColor
1240+
enabled: importWebdavUrlInput.editText !== "" && importWebdavUserInput.editText !== ""
1241+
1242+
onClicked: {
1243+
if (webdavConnectionLoader.item) {
1244+
webdavForgetConfirmationDialog.url = importWebdavUrlInput.editText;
1245+
webdavForgetConfirmationDialog.username = importWebdavUserInput.editText;
1246+
webdavForgetConfirmationDialog.open();
1247+
}
1248+
}
1249+
}
1250+
12121251
TextField {
12131252
id: importWebdavPasswordInput
12141253
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
1215-
width: importWebdavUrlLabel.width
1254+
Layout.fillWidth: true
12161255
rightPadding: leftPadding + (importWebdavShowPasswordInput.width - leftPadding)
12171256
placeholderText: text === "" && webdavConnectionLoader.item && webdavConnectionLoader.item.isPasswordStored ? qsTr("leave empty to use remembered") : ""
12181257
echoMode: TextInput.Password
@@ -1247,40 +1286,44 @@ Page {
12471286
}
12481287
}
12491288

1289+
Item {
1290+
}
1291+
12501292
CheckBox {
12511293
id: importWebdavStorePasswordCheck
1252-
width: importWebdavUrlLabel.width
1294+
Layout.fillWidth: true
1295+
Layout.columnSpan: 2
12531296
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
12541297
text: qsTr('Remember password')
12551298
font: Theme.defaultFont
12561299
checked: true
12571300
}
12581301

1259-
Row {
1260-
QfButton {
1261-
id: importWebdavFetchFoldersButton
1262-
anchors.verticalCenter: importWebdavFetchFoldersIndicator.verticalCenter
1263-
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
1264-
width: importWebdavUrlLabel.width - (importWebdavFetchFoldersIndicator.visible ? importWebdavFetchFoldersIndicator.width : 0)
1265-
text: !enabled ? qsTr("Fetching remote folders") : qsTr("Fetch remote folders")
1302+
QfButton {
1303+
id: importWebdavFetchFoldersButton
1304+
Layout.fillWidth: true
1305+
Layout.columnSpan: importWebdavFetchFoldersIndicator.visible ? 1 : 2
1306+
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
1307+
text: !enabled ? qsTr("Fetching remote folders") : qsTr("Fetch remote folders")
12661308

1267-
onClicked: {
1268-
webdavConnectionLoader.item.fetchAvailablePaths();
1269-
}
1309+
onClicked: {
1310+
webdavConnectionLoader.item.fetchAvailablePaths();
12701311
}
1312+
}
12711313

1272-
BusyIndicator {
1273-
id: importWebdavFetchFoldersIndicator
1274-
anchors.verticalCenter: importWebdavFetchFoldersButton.verticalCenter
1275-
width: 48
1276-
height: 48
1277-
visible: webdavConnectionLoader.item && webdavConnectionLoader.item.isFetchingAvailablePaths
1278-
running: visible
1279-
}
1314+
BusyIndicator {
1315+
id: importWebdavFetchFoldersIndicator
1316+
Layout.preferredWidth: 48
1317+
Layout.preferredHeight: 48
1318+
visible: webdavConnectionLoader.item && webdavConnectionLoader.item.isFetchingAvailablePaths
1319+
running: visible
12801320
}
12811321
}
12821322

12831323
Column {
1324+
width: swipeDialog.width
1325+
spacing: 10
1326+
12841327
Label {
12851328
width: importWebdavUrlLabel.width
12861329
visible: importWebdavPathInput.visible
@@ -1450,6 +1493,8 @@ Page {
14501493
width: importWebdavUrlLabel.width - (importWebdavRefreshFoldersIndicator.visible ? importWebdavRefreshFoldersIndicator.width : 0)
14511494
enabled: !webdavConnectionLoader.item || !webdavConnectionLoader.item.isFetchingAvailablePaths
14521495
bgcolor: "transparent"
1496+
borderColor: enabled ? Theme.secondaryTextColor : Theme.mainTextDisabledColor
1497+
color: enabled ? Theme.mainTextColor : Theme.mainTextDisabledColor
14531498
text: !enabled ? qsTr("Refreshing remote folders") : qsTr("Refresh remote folders")
14541499

14551500
onClicked: {
@@ -1481,6 +1526,49 @@ Page {
14811526
}
14821527
}
14831528

1529+
QfDialog {
1530+
id: webdavForgetConfirmationDialog
1531+
title: qsTr("Confirm")
1532+
focus: visible
1533+
parent: mainWindow.contentItem
1534+
1535+
property string url: ""
1536+
property string username: ""
1537+
1538+
Column {
1539+
width: childrenRect.width
1540+
height: childrenRect.height
1541+
spacing: 10
1542+
1543+
TextMetrics {
1544+
id: webdavForgetConfirmationMetrics
1545+
font: webdavForgetConfirmationLabel.font
1546+
text: webdavForgetConfirmationLabel.text
1547+
}
1548+
1549+
Label {
1550+
id: webdavForgetConfirmationLabel
1551+
width: mainWindow.width - 60 < webdavForgetConfirmationMetrics.width ? mainWindow.width - 60 : webdavForgetConfirmationMetrics.width
1552+
text: qsTr("You are about to remove a saved WebDAV item, proceed?")
1553+
wrapMode: Text.WordWrap
1554+
font: Theme.defaultFont
1555+
color: Theme.mainTextColor
1556+
}
1557+
}
1558+
1559+
onAccepted: {
1560+
if (webdavForgetConfirmationDialog.username != "") {
1561+
webdavConnectionLoader.item.forgetHistory(webdavForgetConfirmationDialog.url, webdavForgetConfirmationDialog.username);
1562+
} else {
1563+
webdavConnectionLoader.item.forgetHistory(webdavForgetConfirmationDialog.url);
1564+
}
1565+
importWebdavUrlInput.currentIndex = 0;
1566+
importWebdavUserInput.currentIndex = 0;
1567+
importWebdavPasswordInput.text = '';
1568+
importWebdavDialog.reloadHistory();
1569+
}
1570+
}
1571+
14841572
Connections {
14851573
target: iface
14861574

0 commit comments

Comments
 (0)