diff --git a/src/plugins/help/help.pro b/src/plugins/help/help.pro index 706675e9fb4..890779e9b0e 100644 --- a/src/plugins/help/help.pro +++ b/src/plugins/help/help.pro @@ -26,6 +26,7 @@ HEADERS += \ openpagesmodel.h \ openpagesswitcher.h \ openpageswidget.h \ + remotehelpfilter.h \ searchwidget.h \ xbelsupport.h @@ -46,12 +47,14 @@ SOURCES += \ openpagesmodel.cpp \ openpagesswitcher.cpp \ openpageswidget.cpp \ + remotehelpfilter.cpp \ searchwidget.cpp \ xbelsupport.cpp FORMS += docsettingspage.ui \ filtersettingspage.ui \ - generalsettingspage.ui + generalsettingspage.ui \ + remotehelpfilter.ui RESOURCES += help.qrc include(../../shared/help/help.pri) diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 7b6b0af5303..d06e0ccda61 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -44,6 +44,7 @@ #include "indexwindow.h" #include "openpagesmanager.h" #include "openpagesmodel.h" +#include "remotehelpfilter.h" #include "searchwidget.h" #include @@ -300,6 +301,11 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)), this, SLOT(switchToHelpMode(QUrl))); + RemoteHelpFilter *remoteHelpFilter = new RemoteHelpFilter(); + addAutoReleasedObject(remoteHelpFilter); + connect(remoteHelpFilter, SIGNAL(linkActivated(QUrl)), this, + SLOT(switchToHelpMode(QUrl))); + QDesktopServices::setUrlHandler("qthelp", this, "handleHelpRequest"); connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)), this, SLOT(modeChanged(Core::IMode*))); diff --git a/src/plugins/help/remotehelpfilter.cpp b/src/plugins/help/remotehelpfilter.cpp new file mode 100644 index 00000000000..8fcbeae3eda --- /dev/null +++ b/src/plugins/help/remotehelpfilter.cpp @@ -0,0 +1,172 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "remotehelpfilter.h" + +#include + +namespace Help { + namespace Internal { + +RemoteFilterOptions::RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent) + : QDialog(parent) + , m_filter(filter) +{ + m_ui.setupUi(this); + m_ui.shortcutEdit->setText(m_filter->shortcutString()); + m_ui.limitCheck->setChecked(!m_filter->isIncludedByDefault()); + foreach (const QString &url, m_filter->remoteUrls()) { + QListWidgetItem *item = new QListWidgetItem(url); + m_ui.listWidget->addItem(item); + item->setFlags(item->flags() | Qt::ItemIsEditable); + } + + connect(m_ui.add, SIGNAL(clicked()), this, SLOT(addNewItem())); + connect(m_ui.remove, SIGNAL(clicked()), this, SLOT(removeItem())); +} + +void RemoteFilterOptions::addNewItem() +{ + QListWidgetItem *item = new QListWidgetItem(tr("Double click to edit item.")); + m_ui.listWidget->addItem(item); + item->setSelected(true); + item->setFlags(item->flags() | Qt::ItemIsEditable); + m_ui.listWidget->editItem(item); +} + +void RemoteFilterOptions::removeItem() +{ + if (QListWidgetItem *item = m_ui.listWidget->currentItem()) { + m_ui.listWidget->removeItemWidget(item); + delete item; + } +} + +// -- RemoteHelpFilter + +RemoteHelpFilter::RemoteHelpFilter() +{ + setIncludedByDefault(false); + setShortcutString(QLatin1String("r")); + m_remoteUrls.append(QLatin1String("http://www.bing.com/search?q=%1")); + m_remoteUrls.append(QLatin1String("http://www.google.com/search?q=%1")); + m_remoteUrls.append(QLatin1String("http://search.yahoo.com/search?p=%1")); + m_remoteUrls.append(QLatin1String("http://www.cplusplus.com/reference/stl/%1")); + m_remoteUrls.append(QLatin1String("http://en.wikipedia.org/w/index.php?search=%1")); +} + +RemoteHelpFilter::~RemoteHelpFilter() +{ +} + +QString RemoteHelpFilter::displayName() const +{ + return tr("Online documentation"); +} + +QString RemoteHelpFilter::id() const +{ + return QLatin1String("RemoteHelpFilter"); +} + +Locator::ILocatorFilter::Priority RemoteHelpFilter::priority() const +{ + return Medium; +} + +QList RemoteHelpFilter::matchesFor(const QString &pattern) +{ + QList entries; + foreach (const QString &url, m_remoteUrls) { + entries.append(Locator::FilterEntry(this, url.arg(pattern), QVariant(), + m_icon)); + } + return entries; +} + +void RemoteHelpFilter::accept(Locator::FilterEntry selection) const +{ + const QString &url = selection.displayName; + if (!url.isEmpty()) { + emit linkActivated(url); + } +} + +void RemoteHelpFilter::refresh(QFutureInterface &future) +{ + Q_UNUSED(future) + // Nothing to refresh +} + +QByteArray RemoteHelpFilter::saveState() const +{ + QByteArray value; + QDataStream out(&value, QIODevice::WriteOnly); + out << m_remoteUrls.join(QLatin1String("^")); + out << shortcutString(); + out << isIncludedByDefault(); + return value; +} + +bool RemoteHelpFilter::restoreState(const QByteArray &state) +{ + QDataStream in(state); + + QString value; + in >> value; + m_remoteUrls = value.split(QLatin1String("^"), QString::SkipEmptyParts); + + QString shortcut; + in >> shortcut; + setShortcutString(shortcut); + + bool defaultFilter; + in >> defaultFilter; + setIncludedByDefault(defaultFilter); + + return true; +} + +bool RemoteHelpFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) +{ + Q_UNUSED(needsRefresh) + RemoteFilterOptions optionsDialog(this, parent); + if (optionsDialog.exec() == QDialog::Accepted) { + m_remoteUrls.clear(); + setIncludedByDefault(!optionsDialog.m_ui.limitCheck->isChecked()); + setShortcutString(optionsDialog.m_ui.shortcutEdit->text().trimmed()); + for (int i = 0; i < optionsDialog.m_ui.listWidget->count(); ++i) + m_remoteUrls.append(optionsDialog.m_ui.listWidget->item(i)->text()); + return true; + } + return true; +} + + } // namespace Internal +} // namespace Help diff --git a/src/plugins/help/remotehelpfilter.h b/src/plugins/help/remotehelpfilter.h new file mode 100644 index 00000000000..2799ebe6c22 --- /dev/null +++ b/src/plugins/help/remotehelpfilter.h @@ -0,0 +1,90 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef REMOTEHELPFILTER_H +#define REMOTEHELPFILTER_H + +#include "ui_remotehelpfilter.h" + +#include + +#include + +namespace Help { + namespace Internal { + +class RemoteHelpFilter : public Locator::ILocatorFilter +{ + Q_OBJECT +public: + RemoteHelpFilter(); + ~RemoteHelpFilter(); + + // ILocatorFilter + QString displayName() const; + QString id() const; + Priority priority() const; + QList matchesFor(const QString &entry); + void accept(Locator::FilterEntry selection) const; + void refresh(QFutureInterface &future); + QByteArray saveState() const; + bool restoreState(const QByteArray &state); + bool openConfigDialog(QWidget *parent, bool &needsRefresh); + + QStringList remoteUrls() const { return m_remoteUrls; } + +signals: + void linkActivated(const QUrl &url) const; + +private: + QIcon m_icon; + QStringList m_remoteUrls; +}; + +class RemoteFilterOptions : public QDialog +{ + Q_OBJECT + friend class RemoteHelpFilter; + +public: + RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent = 0); + +private slots: + void addNewItem(); + void removeItem(); + +private: + RemoteHelpFilter *m_filter; + Ui::RemoteFilterOptions m_ui; +}; + + } // namespace Internal +} // namespace Help + +#endif // REMOTEHELPFILTER_H diff --git a/src/plugins/help/remotehelpfilter.ui b/src/plugins/help/remotehelpfilter.ui new file mode 100644 index 00000000000..1461573b081 --- /dev/null +++ b/src/plugins/help/remotehelpfilter.ui @@ -0,0 +1,157 @@ + + + Help::Internal::RemoteFilterOptions + + + + 0 + 0 + 340 + 179 + + + + Filter configuration + + + + + + + + + 0 + 0 + + + + Prefix: + + + shortcutEdit + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Limit to prefix + + + + + + + + + + + + + + + + + 21 + 21 + + + + + + + + + + + + + 21 + 21 + + + + - + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Help::Internal::RemoteFilterOptions + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Help::Internal::RemoteFilterOptions + reject() + + + 316 + 260 + + + 286 + 274 + + + + +