27 #include <QDesktopServices> 28 #include <QRegularExpression> 29 #include <QNetworkProxy> 30 #include <QNetworkProxyFactory> 45 QStringList paths = settings.
value( QStringLiteral(
"help/helpSearchPath" ) ).toStringList();
46 if ( paths.isEmpty() )
55 QString helpPath, fullPath;
56 bool helpFound =
false;
58 Q_FOREACH (
const QString &path, paths )
60 if ( path.endsWith( QLatin1String(
"\\" ) ) || path.endsWith( QLatin1String(
"/" ) ) )
62 fullPath = path.left( path.size() - 1 );
69 Q_FOREACH (
const QString &var, scope->variableNames() )
71 QRegularExpression rx( QStringLiteral(
"(<!\\$\\$)*(\\$%1)" ).arg( var ) );
72 fullPath.replace( rx, scope->variable( var ).toString() );
74 fullPath.replace( QRegularExpression( QStringLiteral(
"(\\$\\$)" ) ), QStringLiteral(
"$" ) );
76 helpPath = QStringLiteral(
"%1/%2" ).arg( fullPath, key );
80 if ( helpPath.startsWith( QLatin1String(
"http" ) ) )
82 if ( !QgsHelp::urlExists( helpPath ) )
86 helpUrl = QUrl( helpPath );
90 QString filePath = helpPath.mid( 0, helpPath.lastIndexOf( QLatin1String(
"#" ) ) );
91 if ( !QFileInfo::exists( filePath ) )
95 helpUrl = QUrl::fromLocalFile( filePath );
96 int pos = helpPath.lastIndexOf( QLatin1String(
"#" ) );
99 helpUrl.setFragment( helpPath.mid( helpPath.lastIndexOf( QLatin1String(
"#" ) ) + 1, -1 ) );
107 return helpFound ? helpUrl : helpNotFound;
110 bool QgsHelp::urlExists(
const QString &url )
116 bool proxyEnabled = settings.
value( QStringLiteral(
"proxy/proxyEnabled" ),
false ).toBool();
120 QString proxyHost = settings.
value( QStringLiteral(
"proxy/proxyHost" ), QString() ).toString();
121 int proxyPort = settings.
value( QStringLiteral(
"proxy/proxyPort" ), QString() ).toString().toInt();
122 QString proxyUser = settings.
value( QStringLiteral(
"proxy/proxyUser" ), QString() ).toString();
123 QString proxyPassword = settings.
value( QStringLiteral(
"proxy/proxyPassword" ), QString() ).toString();
125 QString proxyTypeString = settings.
value( QStringLiteral(
"proxy/proxyType" ), QString() ).toString();
127 if ( proxyTypeString == QLatin1String(
"DefaultProxy" ) )
129 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
130 if ( !proxies.isEmpty() )
132 proxy = proxies.first();
137 QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
138 if ( proxyTypeString == QLatin1String(
"Socks5Proxy" ) )
140 proxyType = QNetworkProxy::Socks5Proxy;
142 else if ( proxyTypeString == QLatin1String(
"HttpProxy" ) )
144 proxyType = QNetworkProxy::HttpProxy;
146 else if ( proxyTypeString == QLatin1String(
"HttpCachingProxy" ) )
148 proxyType = QNetworkProxy::HttpCachingProxy;
150 else if ( proxyTypeString == QLatin1String(
"FtpCachingProxy" ) )
152 proxyType = QNetworkProxy::FtpCachingProxy;
154 proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
156 socket.setProxy( proxy );
159 socket.connectToHost( helpUrl.host(), 80 );
160 if ( socket.waitForConnected() )
162 socket.write(
"HEAD " + helpUrl.path().toUtf8() +
" HTTP/1.1\r\n" 163 "Host: " + helpUrl.host().toUtf8() +
"\r\n\r\n" );
164 if ( socket.waitForReadyRead() )
166 QByteArray bytes = socket.readAll();
167 if ( bytes.contains(
"200 OK" ) || bytes.contains(
"302 Found" ) || bytes.contains(
"301 Moved" ) )
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QUrl helpUrl(const QString &key)
Returns URI of the help topic for the given key.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
static QString pkgDataPath()
Returns the common root path of all application data directories.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.