Skip to content
Permalink
Browse files

[oauth2] Show a list of directories searched for predefined configura…

…tion

files in the list tooltip/help text

Immediately gives users more clues about how to use these
files and where they must be placed
  • Loading branch information
nyalldawson committed Oct 24, 2018
1 parent b8361e4 commit 7b3f3cfafbc2ce84f086812d3b3061934ae1e5a1
@@ -700,24 +700,29 @@ QgsStringMap QgsAuthOAuth2Config::mapOAuth2Configs(
return configs;
}

QgsStringMap QgsAuthOAuth2Config::mappedOAuth2ConfigsCache( QObject *parent, const QString &extradir )
QStringList QgsAuthOAuth2Config::configLocations( const QString &extradir )
{
QgsStringMap configs;
bool ok = false;

// Load from default locations
QStringList configdirs;
QStringList dirs;
// in order of override preference, i.e. user over pkg dir
configdirs << QgsAuthOAuth2Config::oauth2ConfigsPkgDataDir()
<< QgsAuthOAuth2Config::oauth2ConfigsUserSettingsDir();
dirs << QgsAuthOAuth2Config::oauth2ConfigsPkgDataDir()
<< QgsAuthOAuth2Config::oauth2ConfigsUserSettingsDir();

if ( !extradir.isEmpty() )
{
// configs of similar IDs in this dir will override existing in standard dirs
configdirs << extradir;
dirs << extradir;
}
return dirs;
}

for ( const auto &configdir : qgis::as_const( configdirs ) )
QgsStringMap QgsAuthOAuth2Config::mappedOAuth2ConfigsCache( QObject *parent, const QString &extradir )
{
QgsStringMap configs;
bool ok = false;

// Load from default locations
const QStringList configdirs = configLocations( extradir );
for ( const auto &configdir : configdirs )
{
QFileInfo configdirinfo( configdir );
if ( !configdirinfo.exists() || !configdirinfo.isDir() )
@@ -748,7 +753,7 @@ QString QgsAuthOAuth2Config::oauth2ConfigsPkgDataDir()
// static
QString QgsAuthOAuth2Config::oauth2ConfigsUserSettingsDir()
{
return QgsApplication::qgisSettingsDirPath() + QStringLiteral( "/oauth2_configs" );
return QgsApplication::qgisSettingsDirPath() + QStringLiteral( "oauth2_configs" );
}

// static
@@ -218,6 +218,13 @@ class QgsAuthOAuth2Config : public QObject
ConfigFormat format = JSON,
bool *ok = nullptr );

/**
* Returns an ordered list of locations from which stored configuration files
* will be loaded. The list is in ascending order of precedence, so configuration
* files from later items will override those from earlier locations.
*/
static QStringList configLocations( const QString &extradir = QString() );

//! Load and parse standard directories of configs (e.g. JSON) to a mapped cache
static QgsStringMap mappedOAuth2ConfigsCache( QObject *parent, const QString &extradir = QString::null );

@@ -17,6 +17,7 @@

#include <QDir>
#include <QFileDialog>
#include <QDesktopServices>

#include "qgsapplication.h"
#include "qgsauthguiutils.h"
@@ -48,6 +49,13 @@ QgsAuthOAuth2Edit::QgsAuthOAuth2Edit( QWidget *parent )
setupConnections();

loadFromOAuthConfig( mOAuthConfigCustom.get() );
updatePredefinedLocationsTooltip();

pteDefinedDesc->setOpenLinks( false );
connect( pteDefinedDesc, &QTextBrowser::anchorClicked, this, [ = ]( const QUrl & url )
{
QDesktopServices::openUrl( url );
} );
}


@@ -496,6 +504,7 @@ void QgsAuthOAuth2Edit::definedCustomDirChanged( const QString &path )
bool ok = pinfo.exists() || pinfo.isDir();

leDefinedDirPath->setStyleSheet( ok ? QString() : QgsAuthGuiUtils::redTextStyleSheet() );
updatePredefinedLocationsTooltip();

if ( ok )
{
@@ -649,6 +658,7 @@ void QgsAuthOAuth2Edit::loadDefinedConfigs()
{
whileBlocking( lstwdgDefinedConfigs )->clear();
updateDefinedConfigsCache();
updatePredefinedLocationsTooltip();

QgsStringMap::const_iterator i = mDefinedConfigsCache.constBegin();
while ( i != mDefinedConfigsCache.constEnd() )
@@ -1139,3 +1149,30 @@ void QgsAuthOAuth2Edit::getSoftwareStatementConfig()
}
}

void QgsAuthOAuth2Edit::updatePredefinedLocationsTooltip()
{
const QStringList dirs = QgsAuthOAuth2Config::configLocations( leDefinedDirPath->text() );
QString locationList;
QString locationListHtml;
for ( const QString &dir : dirs )
{
if ( !locationList.isEmpty() )
locationList += '\n';
if ( locationListHtml.isEmpty() )
locationListHtml = QStringLiteral( "<ul>" );
locationList += QStringLiteral( "• %1" ).arg( dir );
locationListHtml += QStringLiteral( "<li><a href=\"%1\">%2</a></li>" ).arg( QUrl::fromLocalFile( dir ).toString(), dir );
}
if ( !locationListHtml.isEmpty() )
locationListHtml += QStringLiteral( "</ul>" );

QString tip = QStringLiteral( "<p>" ) + tr( "Defined configurations are JSON-formatted files, with a single configuration per file. "
"This allows configurations to be swapped out via filesystem tools without affecting user "
"configurations. It is recommended to use the Configure tab’s export function, then edit the "
"resulting file. See QGIS documentation for further details." ) + QStringLiteral( "</p><p>" ) +
tr( "Configurations files can be placed in the directories:" ) + QStringLiteral( "</p>" ) + locationListHtml;
pteDefinedDesc->setHtml( tip );

lstwdgDefinedConfigs->setToolTip( tr( "Configuration files can be placed in the directories:\n\n%1" ).arg( locationList ) );
}

@@ -151,6 +151,8 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi

QString currentDefinedConfig() const { return mDefinedId; }

void updatePredefinedLocationsTooltip();

std::unique_ptr<QgsAuthOAuth2Config> mOAuthConfigCustom;
QgsStringMap mDefinedConfigsCache;
QString mDefinedId;
@@ -75,7 +75,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabCustom">
<attribute name="title">
@@ -203,8 +203,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<height>516</height>
<width>406</width>
<height>441</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -632,7 +632,7 @@
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="3,1">
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="1,0">
<property name="spacing">
<number>0</number>
</property>
@@ -673,24 +673,10 @@
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="pteDefinedDesc">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="undoRedoEnabled">
<widget class="QTextBrowser" name="pteDefinedDesc">
<property name="openExternalLinks">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string>Defined configurations are JSON-formatted files, with a single configuration per file. This allows configurations to be swapped out via filesystem tools without affecting user configurations. It is recommended to use the Configure tab’s export function, then edit the resulting file. See QGIS documentation for further details.</string>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
@@ -854,7 +840,7 @@
<x>0</x>
<y>0</y>
<width>413</width>
<height>283</height>
<height>306</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">

0 comments on commit 7b3f3cf

Please sign in to comment.
You can’t perform that action at this time.