Beispiel #1
0
QUrl Docset::createPageUrl(const QString &path, const QString &fragment) const
{
    QString realPath;
    QString realFragment;

    if (fragment.isEmpty()) {
        const QStringList urlParts = path.split(QLatin1Char('#'));
        realPath = urlParts[0];
        if (urlParts.size() > 1)
            realFragment = urlParts[1];
    } else {
        realPath = path;
        realFragment = fragment;
    }

    static const QRegularExpression dashEntryRegExp(QLatin1String("<dash_entry_.*>"));
    realPath.remove(dashEntryRegExp);
    realFragment.remove(dashEntryRegExp);

    // Absolute file path is required here to handle relative path to the docset storage (see #806).
    QUrl url = QUrl::fromLocalFile(QDir(documentPath()).absoluteFilePath(realPath));
    if (!realFragment.isEmpty()) {
        if (realFragment.startsWith(QLatin1String("//apple_ref"))
                || realFragment.startsWith(QLatin1String("//dash_ref"))) {
            url.setFragment(realFragment, QUrl::DecodedMode);
        } else {
            url.setFragment(realFragment);
        }
    }

    return url;
}
Beispiel #2
0
QUrl ModelBaker::getFullOutputMappingURL() const {
    QUrl appendedURL = _outputMappingURL;
    appendedURL.setFragment(_outputURLSuffix.fragment());
    appendedURL.setQuery(_outputURLSuffix.query());
    appendedURL.setUserInfo(_outputURLSuffix.userInfo());
    return appendedURL;
}
Beispiel #3
0
		void HelpViewer::showHelp(const String& org_url, String entry)
		{
			String url = org_url;
			String fragment;

			if (url.has('#'))
			{
				url = url.before("#");
				fragment = org_url.after("#");
			}

			QUrl qurl = QUrl::fromLocalFile((base_dir_ + url).c_str());
			if (fragment != "") qurl.setFragment(fragment.c_str());
 			browser_->setSource(qurl);

 			QTextCursor ct = browser_->textCursor();
 			if (!ct.atStart()) 
 			{
 				ct.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
				browser_->setTextCursor(ct);
 			}

			if (entry != "") browser_->find(entry.c_str(), QTextDocument::FindCaseSensitively);

			if (!isVisible())
			{
				show();
				setFloating(true);
				showMaximized();
			}
		}
Beispiel #4
0
int Url::setFragment ( lua_State * L )// ( const QString & fragment )
{
	QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 );
	//QString* fragment = ValueInstaller2<QString>::check( L, 2 );
	lhs->setFragment( Util::toString( L, 2 ) );
	return 0;
}
Beispiel #5
0
void tst_QDesktopServices::openUrl_data()
{
    QTest::addColumn<QUrl>("data");
    QTest::addColumn<QString>("message");

    QUrl localFile = QUrl::fromLocalFile(QFINDTESTDATA("test.txt"));

    QTest::newRow("text-file")
            << localFile
            << "This should open test.txt in a text editor";

    localFile.setQuery("x=y");
    QTest::newRow("text-file-with-query")
            << localFile
            << "This should open test.txt in a text editor. Queries do not usually show up.";

    localFile.setQuery(QString());
    localFile.setFragment("top");
    QTest::newRow("text-file-with-fragment")
            << localFile
            << "This should open test.txt in a text editor. Fragments do not usually show up.";

    QTest::newRow("browser-plain")
            << QUrl("http://qt-project.org")
            << "This should open http://qt-project.org in the default web browser";

    QTest::newRow("search-url")
            << QUrl("http://google.com/search?q=Qt+Project")
            << "This should search \"Qt Project\" on Google";

    QTest::newRow("search-url-with-space")
            << QUrl("http://google.com/search?q=Qt Project")
            << "This should search \"Qt Project\" on Google";

    QTest::newRow("search-url-with-quotes")
            << QUrl("http://google.com/search?q=\"Qt+Project\"")
            << "This should search '\"Qt Project\"' on Google (including the quotes)";

    QTest::newRow("search-url-with-hashtag")
            << QUrl("http://google.com/search?q=%23qtproject")
            << "This should search \"#qtproject\" on Google. The # should appear in the Google search field";

    QTest::newRow("search-url-with-fragment")
            << QUrl("http://google.com/search?q=Qt+Project#top")
            << "This should search \"Qt Project\" on Google. There should be no # in the Google search field";

    // see QTBUG-32311
    QTest::newRow("search-url-with-slashes")
            << QUrl("http://google.com/search?q=/profile/5")
            << "This should search \"/profile/5\" on Google.";

    QTest::newRow("mail")
            << QUrl("mailto:[email protected]")
            << "This should open an email composer with the destination set to [email protected]";

    QTest::newRow("mail-subject")
            << QUrl("mailto:[email protected]?subject=[Development]%20Test%20Mail")
            << "This should open an email composer and tries to set the subject";
}
void QtWebKitHelpViewer::setSource(const QUrl &url)
{
    QUrl oldWithoutFragment = source();
    oldWithoutFragment.setFragment(QString());

    m_webView->load(url);

    // if the new url only changes the anchor,
    // then webkit does not send loadStarted nor loadFinished,
    // so we should do that manually in that case
    QUrl newWithoutFragment = url;
    newWithoutFragment.setFragment(QString());
    if (oldWithoutFragment == newWithoutFragment) {
        slotLoadStarted();
        slotLoadFinished();
    }
}
Beispiel #7
0
static const QUrl makeUrlFromCwd( const QString& u, const QString& ref = QString() )
{
    QUrl url = QUrl::fromLocalFile( QDir::currentPath() + QLatin1Char('/') + u) ;
    if ( !ref.isEmpty() )
        url.setFragment( ref );
    url.setPath(QDir::cleanPath( url.path() ) );
    return url;
}
Beispiel #8
0
QUrl QHelpDBReader::buildQUrl(const QString &ns, const QString &folder,
                              const QString &relFileName, const QString &anchor) const
{
    QUrl url;
    url.setScheme(QLatin1String("qthelp"));
    url.setAuthority(ns);
    url.setPath(QLatin1Char('/') + folder + QLatin1Char('/') + relFileName);
    url.setFragment(anchor);
    return url;
}
Future<void> GitCloneStep::perform(const ActionContext &ctxt)
{
	return async([this, ctxt](Notifier notifier)
	{
		QUrl url = m_url;
		url.setFragment(QString());
		Git::GitRepo *repo = notifier.await(Git::GitRepo::clone(ctxt.get<InstallContextItem>().buildDir, url));
		if (!url.fragment().isEmpty()) {
			notifier.await(repo->checkout(url.fragment()));
		}
	});
}
Beispiel #10
0
void MainWindow::openDocset(const QModelIndex &index)
{
    if (!index.sibling(index.row(), 1).data().isNull()) {
        QStringList url_l = index.sibling(index.row(), 1).data().toString().split('#');
        QUrl url = QUrl::fromLocalFile(url_l[0]);
        if (url_l.count() > 1)
            url.setFragment(url_l[1]);
        ui->webView->load(url);

        if (!m_treeViewClicked)
            ui->webView->focus();
        else
            m_treeViewClicked = false;
    }
}
Beispiel #11
0
SpriteDefinition *ResourceManager::requestSpriteDefinition(
        const QString &path, int variant)
{
    QUrl url = resolve(spritePath() + path);
    url.setFragment(QString::number(variant), QUrl::DecodedMode);

    SpriteDefinition *sprite = find<SpriteDefinition>(url);
    if (!sprite) {
        sprite = new SpriteDefinition(this, url, variant);
        mResources.insert(url, sprite);
        mResourceListModel->addResource(sprite);
    }

    sprite->incRef();
    return sprite;
}
Beispiel #12
0
/*!
    Given a URL, generates a unique enough filename (and subdirectory)
 */
QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url)
{
    QUrl cleanUrl = url;
    cleanUrl.setPassword(QString());
    cleanUrl.setFragment(QString());

    QCryptographicHash hash(QCryptographicHash::Sha1);
    hash.addData(cleanUrl.toEncoded());
    // convert sha1 to base36 form and return first 8 bytes for use as string
    QByteArray id =  QByteArray::number(*(qlonglong*)hash.result().data(), 36).left(8);
    // generates <one-char subdir>/<8-char filname.d>
    uint code = (uint)id.at(id.length()-1) % 16;
    QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
                             + QLatin1String(id) + CACHE_POSTFIX;

    return pathFragment;
}
void QWebViewImage::showGitTemplate( const std::string& templateName, const std::string& templateType, QMap<QString, int>* changedMetrics ) {
    // Create relative webview dir url
    QString appPath = QCoreApplication::applicationDirPath();
    QString webviewPath = appPath.append( "/../share/3dsoftviz/webview/index.html" );
    QUrl baseUrl = QUrl::fromLocalFile( webviewPath );

    // Set angular template type using query string
    if ( !templateType.empty() ) {

        // Fragment represents value after # hash in url. For example: http://something/index.html#<fragment>
        baseUrl.setFragment( QString::fromStdString( templateType ) );
    }

    qDebug() << "Webview url: " << baseUrl;

    // Set html and baseUrl working directory
//	_webView->setHtml( html.c_str(), baseUrl );
    _webView->setHtml( createGitHtml( changedMetrics ), baseUrl );
}
DownloadFaviconReply::DownloadFaviconReply(
        const DownloadFaviconRequest &request,
        QNetworkAccessManager *network, QObject *parent) :
    AbstractDownloadReply(network, parent)
{
    m_request = request;
    QUrl favIconUrl = request.url();
    favIconUrl.setPath("/favicon.ico");
    favIconUrl.setFragment(QString());
#if QT_VERSION >= 0x050000
    favIconUrl.setQuery(QUrlQuery());
#else
    favIconUrl.setQueryItems(QList<QPair<QString, QString> >());
#endif
    fetchUrl(favIconUrl,
             request.maxRetryCount(),
             request.maxRedirectCount(),
             true);
}
Beispiel #15
0
void MainWindow::openDocset(const QModelIndex &index)
{
    const QVariant urlStr = index.sibling(index.row(), 1).data();
    if (urlStr.isNull())
        return;

    /// TODO: Keep anchor separately from file address
    QStringList urlParts = urlStr.toString().split(QLatin1Char('#'));
    QUrl url = QUrl::fromLocalFile(urlParts[0]);
    if (urlParts.count() > 1)
        /// NOTE: QUrl::DecodedMode is a fix for #121. Let's hope it doesn't break anything.
        url.setFragment(urlParts[1], QUrl::DecodedMode);

    ui->webView->load(url);

    if (!m_treeViewClicked)
        ui->webView->focus();
    else
        m_treeViewClicked = false;
}
Beispiel #16
0
QUrl createUrl(const char *urlData, const http_parser_url &urlInfo)
{
    QUrl url;
    url.setScheme(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_SCHEMA));
    url.setHost(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_HOST));
    // Port is dealt with separately since it is available as an integer.
    url.setPath(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_PATH));
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    url.setQuery(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_QUERY));
#else
    if (HAS_URL_FIELD(urlInfo, UF_QUERY)) {
        url.setEncodedQuery(QByteArray(urlData + urlInfo.field_data[UF_QUERY].off,
                                       urlInfo.field_data[UF_QUERY].len));
    }
#endif
    url.setFragment(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_FRAGMENT));
    url.setUserInfo(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_USERINFO));

    if (HAS_URL_FIELD(urlInfo, UF_PORT))
        url.setPort(urlInfo.port);

    return url;
}
static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm)
{
    QUrl key;

    switch (proxy.type()) {
    case QNetworkProxy::Socks5Proxy:
        key.setScheme(QLatin1String("proxy-socks5"));
        break;

    case QNetworkProxy::HttpProxy:
    case QNetworkProxy::HttpCachingProxy:
        key.setScheme(QLatin1String("proxy-http"));
        break;

    case QNetworkProxy::FtpCachingProxy:
        key.setScheme(QLatin1String("proxy-ftp"));
        break;

    case QNetworkProxy::DefaultProxy:
    case QNetworkProxy::NoProxy:
        // shouldn't happen
        return QByteArray();

        // no default:
        // let there be errors if a new proxy type is added in the future
    }

    if (key.scheme().isEmpty())
        // proxy type not handled
        return QByteArray();

    key.setUserName(proxy.user());
    key.setHost(proxy.hostName());
    key.setPort(proxy.port());
    key.setFragment(realm);
    return "auth:" + key.toEncoded();
}
Beispiel #18
0
			void HistoryModel::Add (const HistoryItem& item)
			{
				int section = SectionNumber (item.DateTime_);
			
				while (section >= RootItem_->ChildCount ())
				{
					QList<QVariant> data;
					data << SectionName (RootItem_->ChildCount ())
						<< QString ("")
						<< QString ("");
					TreeItem *folder = new TreeItem (data, RootItem_);
					folder->ModifyData (0,
							FolderIconProxy_->icon (),
							Qt::DecorationRole);
					RootItem_->AppendChild (folder);
				}
			
				QList<QVariant> data;
				data << item.Title_
					<< item.URL_
					<< item.DateTime_;
			
				TreeItem *folder = RootItem_->Child (section);
			
				TreeItem *thisItem = new TreeItem (data, RootItem_->Child (section));
				folder->PrependChild (thisItem);
			
				QUrl url (item.URL_);
				url.setFragment (QString ());
				url.setPath (QString ());
				url.setQueryItems (QList<QPair<QString, QString> > ());
				QIcon icon = QWebSettings::iconForUrl (url);
				if (icon.isNull ())
					icon = UnknownURLProxy_->icon ();
				thisItem->ModifyData (0,
						icon, Qt::DecorationRole);
			}
void QWebViewImage::showTemplate( const std::string& templateName, Diluculum::LuaValueMap models, const std::string& templateType )
{
    qDebug() << templateName.c_str() << templateType.c_str();
	// Initialize lua interface to call slt2 renderer
	Lua::LuaInterface* lua = Lua::LuaInterface::getInstance();
	QString renderer[] = {"slt2_renderer", "render"};

	// Prepare parameters to be passed to template renderer
	Diluculum::LuaValueList params;
	params.push_back( templateName );
	params.push_back( models );

	// Call slt2 renderer
	std::string html = lua->callFunction( 2, renderer, params )[0].asString();
//    qDebug() << html.c_str();

	// Create relative webview dir url
	QString appPath = QCoreApplication::applicationDirPath();
	QString webviewPath = appPath.append( "/../share/3dsoftviz/webview/index.html" );
	QUrl baseUrl = QUrl::fromLocalFile( webviewPath );

	// Set angular template type using query string
	if ( !templateType.empty() ) {

		// Fragment represents value after # hash in url. For example: http://something/index.html#<fragment>
        baseUrl.setFragment( QString::fromStdString( templateType ) );
//        baseUrl.setFragment( "git" );
	}

    qDebug() << "Webview url: " << baseUrl;

	// Set html and baseUrl working directory
    _webView->setHtml( html.c_str(), baseUrl );

//    qDebug() << _webView->page()->currentFrame()->toHtml();
}
Beispiel #20
0
PageRunner::PageRunner(const QStringList& args)
    : QWebPage(0),
      out(stdout),
      err(stderr),
      view(new QWidget()) {

    QMap<QString, QString> settings = parseArguments(args);
    QStringList arguments = args.mid(settings.size() * 2);
    exportpdf = settings.value("export-pdf");
    exportpng = settings.value("export-png");
    url = QUrl(arguments[0]);
    nativeio = new NativeIO(this, QFileInfo(arguments[0]).dir(),
                            QDir::current());
    if (url.scheme() == "file" || url.isRelative()) {
        QFileInfo info(arguments[0]);
        url = QUrl::fromLocalFile(info.absoluteFilePath());
        if (!info.isReadable() || !info.isFile()) {
            QTextStream err(stderr);
            err << "Cannot read file '" + url.toString() + "'.\n";
            qApp->exit(1);
        }
    }
    nam = new NAM(this, QUrl(url).host(), QUrl(url).port());

    setNetworkAccessManager(nam);
    connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
    connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
            this, SLOT(slotInitWindowObjects()));
    sawJSError = false;

    setView(view);
    scriptMode = arguments[0].endsWith(".js");
    if (scriptMode) {
        QByteArray html = "'" + arguments[0].toUtf8().replace('\'', "\\'")
                + "'";
        for (int i = 1; i < arguments.length(); ++i) {
            html += ",'" + arguments[i].toUtf8().replace('\'', "\\'") + "'";
        }
        html = "<html>"
                "<head><title></title>"
                "<script>var arguments=[" + html + "];</script>"
                "<script src=\"" + QUrl::fromLocalFile(arguments[0]).toEncoded() + "\"></script>";
        // add runtime modification
        html += "<script>//<![CDATA[\n" + getRuntimeBindings() +
             "if (typeof(runtime) !== 'undefined' && typeof(nativeio) !== 'undefined') {\n"
             "    runtime.libraryPaths = function () {"
             "        /* convert to javascript array */"
             "        var p = nativeio.libraryPaths(),"
             "            a = [], i;"
             "        for (i in p) { a[i] = p[i]; }"
             "        return a;"
             "    };}//]]></script>";
        html += "</head><body></body></html>\n";
        QTemporaryFile tmp("XXXXXX.html");
        tmp.setAutoRemove(true);
        tmp.open();
        tmp.write(html);
        tmp.close();
        QFileInfo info(tmp.fileName());
        mainFrame()->load(QUrl::fromLocalFile(info.absoluteFilePath()));
    } else {
        // Make the url absolute. If it is not done here, QWebFrame will do
        // it, and it will lose the query and fragment part.
        QUrl absurl;
        if (url.isRelative()) {
            absurl = QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).absoluteFilePath());
            absurl.setQuery(url.query());
            absurl.setFragment(url.fragment());
        } else {
            absurl = url;
        }
        mainFrame()->load(absurl);
    }
}
void BrowserCopertine::moveToMese( const QString &mese )
{
    QUrl url = ui->MostraRiviste->source() ;
    url.setFragment( mese ) ;
    ui->MostraRiviste->setSource( url );
}
Beispiel #22
0
void QUrlProto::setFragment(const QString &fragment)
{
  QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
  if (item)
    item->setFragment(fragment);
}
Beispiel #23
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    settings("Zeal", "Zeal"),
    settingsDialog(zealList)
{
    trayIcon = nullptr;
    trayIconMenu = nullptr;

    // Use the platform-specific proxy settings
    QNetworkProxyFactory::setUseSystemConfiguration(true);

    // server for detecting already running instances
    localServer = new QLocalServer(this);
    connect(localServer, &QLocalServer::newConnection, [&]() {
        QLocalSocket *connection = localServer->nextPendingConnection();
        // Wait a little while the other side writes the bytes
        connection->waitForReadyRead();
        QString indata = connection->readAll();
        if(!indata.isEmpty()) {
            bringToFrontAndSearch(indata);
        }
    });
    QLocalServer::removeServer(serverName);  // remove in case previous instance crashed
    localServer->listen(serverName);

    // initialise icons
#if defined(WIN32) || defined(OSX)
    icon = qApp->style()->standardIcon(QStyle::SP_MessageBoxInformation);
#else
    icon = QIcon::fromTheme("edit-find");
#endif
    setWindowIcon(icon);
    if(settings.value("hidingBehavior", "systray").toString() == "systray")
        createTrayIcon();

    QKeySequence keySequence;
    if(settings.value("hotkey").isNull()) {
        keySequence = QKeySequence("Alt+Space");
    } else {
        keySequence = settings.value("hotkey").value<QKeySequence>();
    }

    // initialise key grabber
    connect(&nativeFilter, &ZealNativeEventFilter::gotHotKey, [&]() {
        if(!isVisible() || !isActiveWindow()) {
            bringToFront(true);
        } else {
            if(trayIcon) {
                hide();
            } else {
                showMinimized();
            }
        }
    });
    qApp->eventDispatcher()->installNativeEventFilter(&nativeFilter);
    setHotKey(keySequence);

    // initialise docsets
    docsets->initialiseDocsets();

    // initialise ui
    ui->setupUi(this);

    setupShortcuts();

    restoreGeometry(settings.value("geometry").toByteArray());
    ui->splitter->restoreState(settings.value("splitter").toByteArray());
    connect(ui->splitter, &QSplitter::splitterMoved, [=](int, int) {
        settings.setValue("splitter", ui->splitter->saveState());
    });
    ui->webView->settings()->setFontSize(QWebSettings::MinimumFontSize, settings.value("minFontSize").toInt());
    ZealNetworkAccessManager * zealNaManager = new ZealNetworkAccessManager();
    ui->webView->page()->setNetworkAccessManager(zealNaManager);

    // menu
    ui->action_Quit->setShortcut(QKeySequence::Quit);
    connect(ui->action_Quit, &QAction::triggered, [=]() { settings.setValue("geometry", saveGeometry()); });
    connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));

    connect(&settingsDialog, SIGNAL(refreshRequested()), this, SLOT(refreshRequest()));
    connect(&settingsDialog, SIGNAL(minFontSizeChanged(int)), this, SLOT(changeMinFontSize(int)));

    connect(ui->action_Options, &QAction::triggered, [=]() {
        settingsDialog.setHotKey(hotKey);
        nativeFilter.setEnabled(false);
        if(settingsDialog.exec()) {
            setHotKey(settingsDialog.hotKey());
            if(settings.value("hidingBehavior").toString() == "systray") {
                createTrayIcon();
            } else if(trayIcon) {
                trayIcon->deleteLater();
                trayIconMenu->deleteLater();
                trayIcon = nullptr;
                trayIconMenu = nullptr;
            }
        } else {
            // cancelled - restore previous value
            ui->webView->settings()->setFontSize(QWebSettings::MinimumFontSize, settings.value("minFontSize").toInt());
        }
        nativeFilter.setEnabled(true);
        ui->treeView->reset();
    });

    ui->action_Back->setShortcut(QKeySequence::Back);
    ui->action_Forward->setShortcut(QKeySequence::Forward);
    connect(ui->action_Back, &QAction::triggered, this, &MainWindow::back);
    connect(ui->action_Forward, &QAction::triggered, this, &MainWindow::forward);

    connect(ui->action_About, &QAction::triggered,
            [&]() { QMessageBox::about(this, "About Zeal",
                QString("This is Zeal ") + ZEAL_VERSION + " - a documentation browser.\n\n"
                "For details see http://zealdocs.org/"); });
    connect(ui->action_About_QT, &QAction::triggered,
            [&]() { QMessageBox::aboutQt(this); });
    displayViewActions();

    // treeView and lineEdit
    ui->lineEdit->setTreeView(ui->treeView);
    ui->lineEdit->setFocus();
    ui->treeView->setModel(&zealList);
    ui->treeView->setColumnHidden(1, true);
    ui->treeView->setItemDelegate(new ZealSearchItemDelegate(ui->treeView, ui->lineEdit, ui->treeView));
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) && defined(WIN32)
    // overriding subElementRect doesn't work with Qt 5.0.0, but is required to display
    // selected item frame correctly in Windows (for patch see https://codereview.qt-project.org/#change,46559)
    // This is a workaround for Qt < 5.1 - selecting whole rows leads to always rendering the frame.
    // (Only the frame is larger than the list item, which is different from default behaviour.)
    ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
#endif
    connect(ui->treeView, &QTreeView::clicked, [&](const QModelIndex& index) {
       ui->treeView->activated(index);
    });
    connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) {
        if(!index.sibling(index.row(), 1).data().isNull()) {
            QStringList url_l = index.sibling(index.row(), 1).data().toString().split('#');
            QUrl url = QUrl::fromLocalFile(url_l[0]);
            if(url_l.count() > 1) {
                url.setFragment(url_l[1]);
            }
            ui->webView->load(url);
        }
    });
    connect(ui->forwardButton, &QPushButton::clicked, this, &MainWindow::forward);
    connect(ui->backButton, &QPushButton::clicked, this, &MainWindow::back);

    connect(ui->webView, &SearchableWebView::urlChanged, [&](const QUrl &url) {
        QString urlPath = url.path();
        QString docsetName = getDocsetName(urlPath);
        QPixmap docsetMap = docsets->icon(docsetName).pixmap(32,32);

        // paint label with the icon
        ui->pageIcon->setPixmap(docsetMap);
        displayViewActions();
    });

    connect(ui->webView, &SearchableWebView::titleChanged, [&](const QString &title) {
        if (!title.isEmpty()) {
            ui->pageTitle->setText(title);
        }
    });

    connect(&zealSearch, &ZealSearchModel::queryCompleted, [&]() {
        ui->treeView->setModel(&zealSearch);
        ui->treeView->reset();
        ui->treeView->setColumnHidden(1, true);
        ui->treeView->setCurrentIndex(zealSearch.index(0, 0, QModelIndex()));
        ui->treeView->activated(ui->treeView->currentIndex());
    });
    connect(ui->lineEdit, &QLineEdit::textChanged, [&](const QString& text) {
        zealSearch.setQuery(text);
        if(text.isEmpty()) {
            ui->treeView->setModel(&zealList);
        }
    });
}
Beispiel #24
0
QUrl QgsHelp::helpUrl( const QString &key )
{
  QUrl helpNotFound = QUrl::fromLocalFile( QgsApplication::pkgDataPath() + "/doc/nohelp.html" );

  QgsSettings settings;
  QStringList paths = settings.value( QStringLiteral( "help/helpSearchPath" ) ).toStringList();
  if ( paths.isEmpty() )
  {
    return helpNotFound;
  }

  std::unique_ptr<QgsExpressionContextScope> scope( QgsExpressionContextUtils::globalScope() );

  QUrl helpUrl;
  QString helpPath, fullPath;
  bool helpFound = false;

  Q_FOREACH ( const QString &path, paths )
  {
    if ( path.endsWith( "\\" ) || path.endsWith( "/" ) )
    {
      fullPath = path.left( path.size() - 1 );
    }
    else
    {
      fullPath = path;
    }

    Q_FOREACH ( const QString &var, scope->variableNames() )
    {
      QRegularExpression rx( QStringLiteral( "(<!\\$\\$)*(\\$%1)" ).arg( var ) );
      fullPath.replace( rx, scope->variable( var ).toString() );
    }
    fullPath.replace( QRegularExpression( "(\\$\\$)" ), "$" );

    helpPath = QStringLiteral( "%1/%2" ).arg( fullPath, key );

    if ( helpPath.startsWith( QStringLiteral( "http" ) ) )
    {
      if ( !QgsHelp::urlExists( helpPath ) )
      {
        continue;
      }
      helpUrl = QUrl( helpPath );
    }
    else
    {
      QString filePath = helpPath.mid( 0, helpPath.lastIndexOf( "#" ) );
      if ( !QFileInfo::exists( filePath ) )
      {
        continue;
      }
      helpUrl = QUrl::fromLocalFile( filePath );
      int pos = helpPath.lastIndexOf( "#" );
      if ( pos != -1 )
      {
        helpUrl.setFragment( helpPath.mid( helpPath.lastIndexOf( "#" ) + 1, -1 ) );
      }
    }

    helpFound = true;
    break;
  }

  return helpFound ? helpUrl : helpNotFound;
}
static inline QByteArray authenticationKey(const QUrl &url, const QString &realm)
{
    QUrl copy = url;
    copy.setFragment(realm);
    return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery);
}