Commit 37efd0e1 authored by kh1's avatar kh1
Browse files

Implement online help filter.

The search for remote content, like stl::vector in cpp-reference,
google, bing, wikipedia etc...

Task-number: QTCREATORBUG-1375
Reviewed-by: ck
parent fff4203a
......@@ -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)
......
......@@ -44,6 +44,7 @@
#include "indexwindow.h"
#include "openpagesmanager.h"
#include "openpagesmodel.h"
#include "remotehelpfilter.h"
#include "searchwidget.h"
#include <coreplugin/actionmanager/actionmanager.h>
......@@ -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*)));
......
/**************************************************************************
**
** 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 <QtCore/QUrl>
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<Locator::FilterEntry> RemoteHelpFilter::matchesFor(const QString &pattern)
{
QList<Locator::FilterEntry> 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<void> &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
/**************************************************************************
**
** 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 <locator/ilocatorfilter.h>
#include <QtGui/QIcon>
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<Locator::FilterEntry> matchesFor(const QString &entry);
void accept(Locator::FilterEntry selection) const;
void refresh(QFutureInterface<void> &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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Help::Internal::RemoteFilterOptions</class>
<widget class="QDialog" name="Help::Internal::RemoteFilterOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>340</width>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
<string>Filter configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Prefix:</string>
</property>
<property name="buddy">
<cstring>shortcutEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="shortcutEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="limitCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Limit to prefix</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="add">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="remove">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Help::Internal::RemoteFilterOptions</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Help::Internal::RemoteFilterOptions</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment